bobol
9 months ago
40 changed files with 456 additions and 1905 deletions
@ -0,0 +1,18 @@ |
|||
package com.lzbi.bill.domain; |
|||
|
|||
import com.alibaba.excel.metadata.data.CellData; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 读取公式数据 |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
@EqualsAndHashCode |
|||
public class CellDataReadFormulaData { |
|||
private CellData<String> string; |
|||
} |
@ -0,0 +1,113 @@ |
|||
package com.lzbi.bill.listener; |
|||
|
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import cn.hutool.json.JSONArray; |
|||
import cn.hutool.json.JSONConfig; |
|||
import cn.hutool.json.JSONUtil; |
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.metadata.CellExtra; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.lzbi.draft.domain.vo.ProductionDailySheetVO; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author LWB |
|||
* @Description excel读取的监听器 |
|||
* 有个很重要的点 ExcelReadListener监听器 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去 |
|||
* 所以,如果需要传入spring管理的对象,要么按照文档中的说明,直接使用构造器传参进来,要么使用ThreadLocal线程级别的变量工具传参 |
|||
* 实际应用中,可能会需要传入很多的spring管理的对象,或者其他上下文参数,遇到这种情况,建议使用ThreadLocal来传递参数,简单,便捷,无需重复修改构造器 |
|||
* 如果是简单的传递个别上下文参数,也可以选用构造器传参的方式 |
|||
*/ |
|||
@Slf4j |
|||
public class CellDataReadFormulaListener implements ReadListener<Map<Integer, String>> { |
|||
|
|||
/** |
|||
* excel所有的sheet-row-cell数据 |
|||
*/ |
|||
private List<ProductionDailySheetVO> list; |
|||
|
|||
/** |
|||
* 每个sheet页的所有行 |
|||
*/ |
|||
private List<List<String>> rows; |
|||
|
|||
/** |
|||
* sheet页的号 |
|||
*/ |
|||
private Integer sheetNo; |
|||
|
|||
/** |
|||
* 行的长度 |
|||
*/ |
|||
private Integer rowLength; |
|||
|
|||
public CellDataReadFormulaListener () { |
|||
this.list = new ArrayList<>(); |
|||
} |
|||
|
|||
public List<ProductionDailySheetVO> getList() { |
|||
return list; |
|||
} |
|||
|
|||
@Override |
|||
public void onException(Exception exception, AnalysisContext context) throws Exception { |
|||
ReadListener.super.onException(exception, context); |
|||
} |
|||
|
|||
@Override |
|||
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { |
|||
ReadListener.super.invokeHead(headMap, context); |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(Map<Integer, String> data, AnalysisContext context) { |
|||
if (null != data) { |
|||
List<String> cells = new ArrayList<>(); |
|||
data.forEach((k, v) -> { |
|||
if ("系统指标名称".equals(v)) { |
|||
rowLength = data.size(); |
|||
} |
|||
}); |
|||
if (null != rowLength) { |
|||
for (int i = 0; i < rowLength; i++) { |
|||
if (StringUtils.isNotBlank(data.get(i))) { |
|||
cells.add(data.get(i)); |
|||
} else { |
|||
cells.add(""); |
|||
} |
|||
} |
|||
this.rows.add(cells); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void extra(CellExtra extra, AnalysisContext context) { |
|||
ReadListener.super.extra(extra, context); |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
if (CollectionUtil.isNotEmpty(this.rows)) { |
|||
JSONArray data = JSONUtil.parseArray(JSONUtil.toJsonStr(this.rows)); |
|||
list.add(new ProductionDailySheetVO(context.readSheetHolder().getSheetNo(), context.readSheetHolder().getSheetName(), data)); |
|||
} |
|||
this.rows = null; |
|||
this.rowLength = null; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasNext(AnalysisContext context) { |
|||
if (!context.readSheetHolder().getSheetNo().equals(this.sheetNo)) { |
|||
this.sheetNo = context.readSheetHolder().getSheetNo(); |
|||
this.rows = new ArrayList<>(); |
|||
} |
|||
return ReadListener.super.hasNext(context); |
|||
} |
|||
} |
@ -1,97 +0,0 @@ |
|||
package com.lzbi.wechat.controller; |
|||
|
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.wechat.service.DeptService; |
|||
import com.lzbi.wechat.service.TargetService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
@RequestMapping("/wechat/biz") |
|||
public class BizController { |
|||
|
|||
@Autowired |
|||
@Qualifier("wechatDeptService") |
|||
private DeptService deptService; |
|||
|
|||
@Autowired |
|||
private TargetService targetService; |
|||
|
|||
/** |
|||
* 获取自己所在部门 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/dept/self/list") |
|||
public AjaxResult getSelfDeptList() { |
|||
return AjaxResult.success(deptService.getSelfDeptList()); |
|||
} |
|||
|
|||
/** |
|||
* 获取下属部门列表 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/dept/children") |
|||
public AjaxResult getDeptChildren(@RequestParam("deptId") Long deptId) { |
|||
return AjaxResult.success(deptService.getDeptChildren(deptId)); |
|||
} |
|||
|
|||
/** |
|||
* 获取供热面积 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/heatRadiatingArea") |
|||
public AjaxResult getHeatRadiatingArea(@RequestParam("deptId") Long deptId, @RequestParam("date") String date) { |
|||
return AjaxResult.success(targetService.getHeatRadiatingArea(deptId, date)); |
|||
} |
|||
|
|||
/** |
|||
* 获取公司指标值 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/comany/target") |
|||
public AjaxResult getComanyTarget(@RequestParam("deptId") Long deptId, @RequestParam("date") String date) { |
|||
return AjaxResult.success(targetService.getComanyTarget(deptId, date)); |
|||
} |
|||
|
|||
/** |
|||
* 获取热源指标值 |
|||
* @param type 1、单日指标,2、累计指标 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/heatSource/target") |
|||
public AjaxResult getHeatSourceTarget(@RequestParam("deptId") Long deptId, @RequestParam("date") String date, @RequestParam("type") String type) { |
|||
return AjaxResult.success(targetService.getHeatSourceTarget(deptId, date, type)); |
|||
} |
|||
|
|||
/** |
|||
* 获取换热站参数 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/heatExchangeStation/params") |
|||
public AjaxResult getHeatExchangeStationParams(@RequestParam("deptId") Long deptId, @RequestParam("date") String date) { |
|||
return AjaxResult.success(targetService.getHeatExchangeStationParams(deptId)); |
|||
} |
|||
|
|||
/** |
|||
* 获取完成率 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/finishingRate") |
|||
public AjaxResult getFinishingRate(@RequestParam("deptId") Long deptId) { |
|||
return AjaxResult.success(targetService.getFinishingRate(deptId)); |
|||
} |
|||
|
|||
/** |
|||
* 获取完成率 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/finishingRateLine") |
|||
public AjaxResult getFinishingRateLine(@RequestParam("deptId") Long deptId, @RequestParam("date") String date) { |
|||
return AjaxResult.success(targetService.finishingRateLine(deptId)); |
|||
} |
|||
|
|||
} |
@ -1,33 +0,0 @@ |
|||
package com.lzbi.wechat.controller; |
|||
|
|||
import com.lzbi.common.constant.Constants; |
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.common.core.domain.model.LoginBody; |
|||
import com.lzbi.wechat.service.LoginService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
@RequestMapping("/wechat/biz/login") |
|||
public class LoginController { |
|||
|
|||
@Autowired |
|||
private LoginService loginService; |
|||
|
|||
/** |
|||
* 登录方法 |
|||
* |
|||
* @param loginBody 登录信息 |
|||
* @return 结果 |
|||
*/ |
|||
@PostMapping("/username") |
|||
public AjaxResult login(@RequestBody LoginBody loginBody) |
|||
{ |
|||
// 生成令牌
|
|||
return loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), |
|||
loginBody.getUuid()); |
|||
} |
|||
} |
@ -1,54 +0,0 @@ |
|||
package com.lzbi.wechat.controller; |
|||
|
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.wechat.domain.req.CodeLoginReq; |
|||
import com.lzbi.wechat.domain.req.PhoneNumberLoginReq; |
|||
import com.lzbi.wechat.domain.req.PhoneNumberReq; |
|||
import com.lzbi.wechat.service.WechatService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* 微信服务相关接口控制器 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/wechat/server") |
|||
public class WechatController { |
|||
|
|||
@Autowired |
|||
private WechatService wechatService; |
|||
|
|||
/** |
|||
* 登录凭证登录 |
|||
* @param codeLoginReq |
|||
* @return |
|||
*/ |
|||
@PostMapping("/codeLogin") |
|||
public AjaxResult codeLogin(@Validated @RequestBody CodeLoginReq codeLoginReq) { |
|||
return AjaxResult.success("操作成功", wechatService.codeLogin(codeLoginReq)); |
|||
} |
|||
|
|||
/** |
|||
* 获取手机号 |
|||
* @param phoneNumberReq |
|||
* @return |
|||
*/ |
|||
@PostMapping("/phoneNumber") |
|||
public AjaxResult getPhoneNumber(@Validated @RequestBody PhoneNumberReq phoneNumberReq) { |
|||
return AjaxResult.success("操作成功", wechatService.getPhoneNumber(phoneNumberReq)); |
|||
} |
|||
|
|||
/** |
|||
* 手机号登录 |
|||
* @param phoneNumberLoginReq |
|||
* @return |
|||
*/ |
|||
@PostMapping("/phoneNumberLogin") |
|||
public AjaxResult phoneNumberLogin(@Validated @RequestBody PhoneNumberLoginReq phoneNumberLoginReq) { |
|||
return AjaxResult.success("操作成功", wechatService.phoneNumberLogin(phoneNumberLoginReq)); |
|||
} |
|||
} |
@ -1,30 +0,0 @@ |
|||
package com.lzbi.wechat.domain; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 微信用户关系实体类 |
|||
*/ |
|||
@Data |
|||
public class SysWechat { |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
private Long id; |
|||
/** |
|||
* 微信用户唯一标识 |
|||
*/ |
|||
private String openId; |
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
private String phone; |
|||
|
|||
public SysWechat() {} |
|||
|
|||
public SysWechat(String openId, String phone) { |
|||
this.openId = openId; |
|||
this.phone = phone; |
|||
} |
|||
} |
@ -1,31 +0,0 @@ |
|||
package com.lzbi.wechat.domain.dto; |
|||
|
|||
import com.lzbi.wechat.domain.vo.TargetVO; |
|||
import lombok.Data; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class ParamsContrastDTO { |
|||
|
|||
/** |
|||
* 内部参数模板编码 |
|||
*/ |
|||
private String paramsModelCode; |
|||
/** |
|||
* 外部参数编码 |
|||
*/ |
|||
private String paramsCode; |
|||
/** |
|||
* 值 |
|||
*/ |
|||
private Double value; |
|||
|
|||
public static Map<String, ParamsContrastDTO> listTransitionMap(List<ParamsContrastDTO> list) { |
|||
Map<String, ParamsContrastDTO> map = new HashMap<>(); |
|||
list.forEach(obj -> map.put(obj.getParamsModelCode(), obj)); |
|||
return map; |
|||
} |
|||
} |
@ -1,37 +0,0 @@ |
|||
package com.lzbi.wechat.domain.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 查询指标值 |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class TargetModelValueDTO { |
|||
|
|||
/** |
|||
* 指标模板编码列表 |
|||
*/ |
|||
private List<String> targetModelCodeList; |
|||
/** |
|||
* 部门id |
|||
*/ |
|||
private Long deptId; |
|||
/** |
|||
* 年 |
|||
*/ |
|||
private String year; |
|||
/** |
|||
* 月 |
|||
*/ |
|||
private String month; |
|||
/** |
|||
* 日 |
|||
*/ |
|||
private String day; |
|||
} |
@ -1,18 +0,0 @@ |
|||
package com.lzbi.wechat.domain.req; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 微信授权登录请求参数 |
|||
*/ |
|||
@Data |
|||
public class CodeLoginReq { |
|||
|
|||
/** |
|||
* 登录时获取的 code,可通过wx.login获取 |
|||
*/ |
|||
@NotBlank(message = "登录凭证不能为空") |
|||
private String code; |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.lzbi.wechat.domain.req; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 手机号登录请求参数 |
|||
*/ |
|||
@Data |
|||
public class PhoneNumberLoginReq { |
|||
|
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
private String phone; |
|||
/** |
|||
* 微信用户唯一标识 |
|||
*/ |
|||
private String openId; |
|||
} |
@ -1,18 +0,0 @@ |
|||
package com.lzbi.wechat.domain.req; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 获取手机号请求参数 |
|||
*/ |
|||
@Data |
|||
public class PhoneNumberReq { |
|||
|
|||
/** |
|||
* 手机号获取凭证 |
|||
*/ |
|||
@NotBlank(message = "手机号获取凭证不能为空") |
|||
private String code; |
|||
} |
@ -1,14 +0,0 @@ |
|||
package com.lzbi.wechat.domain.resp; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 获取接口调用凭据 |
|||
*/ |
|||
@Data |
|||
public class WechatAccessTokenResp extends WechatBaseResp { |
|||
|
|||
private String access_token; |
|||
|
|||
private Long expires_in; |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.lzbi.wechat.domain.resp; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 微信接口返回值 |
|||
*/ |
|||
@Data |
|||
public class WechatBaseResp { |
|||
|
|||
/** |
|||
* 错误码 |
|||
*/ |
|||
private Integer errcode; |
|||
/** |
|||
* 错误信息 |
|||
*/ |
|||
private String errmsg; |
|||
} |
@ -1,23 +0,0 @@ |
|||
package com.lzbi.wechat.domain.resp; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 微信登录凭证登录返回值 |
|||
*/ |
|||
@Data |
|||
public class WechatCodeLoginResp extends WechatBaseResp { |
|||
|
|||
/** |
|||
* 会话密钥 |
|||
*/ |
|||
private String session_key; |
|||
/** |
|||
* 用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台账号下会返回 |
|||
*/ |
|||
private String unionid; |
|||
/** |
|||
* 用户唯一标识 |
|||
*/ |
|||
private String openid; |
|||
} |
@ -1,28 +0,0 @@ |
|||
package com.lzbi.wechat.domain.resp; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 获取手机号返回值 |
|||
*/ |
|||
@Data |
|||
public class WechatPhoneNumberResp extends WechatBaseResp { |
|||
|
|||
/** |
|||
* 手机号信息 |
|||
*/ |
|||
private PhoneInfo phone_info; |
|||
|
|||
/** |
|||
* 手机号信息 |
|||
*/ |
|||
@Data |
|||
public static class PhoneInfo { |
|||
|
|||
private String phoneNumber; |
|||
|
|||
private String purePhoneNumber; |
|||
|
|||
private String countryCode; |
|||
} |
|||
} |
@ -1,28 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class ChildDeptVO { |
|||
|
|||
/** |
|||
* 部门id |
|||
*/ |
|||
private Object deptId; |
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
private String deptName; |
|||
/** |
|||
* 一次网供温 |
|||
*/ |
|||
private Double temperatureSupply; |
|||
/** |
|||
* 一次网回温 |
|||
*/ |
|||
private Double temperatureComeBack; |
|||
} |
@ -1,14 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 登录凭证登录返回值 |
|||
*/ |
|||
@Data |
|||
public class CodeLoginVO { |
|||
|
|||
private String token; |
|||
|
|||
private String openId; |
|||
} |
@ -1,19 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 部门返回值 |
|||
*/ |
|||
@Data |
|||
public class DeptVO { |
|||
|
|||
/** |
|||
* 部门id |
|||
*/ |
|||
private Long value; |
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
private String label; |
|||
} |
@ -1,22 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class FinishingRateVO { |
|||
|
|||
/** |
|||
* 指标怕名称列表 |
|||
*/ |
|||
private List<String> names; |
|||
/** |
|||
* 指标值列表 |
|||
*/ |
|||
private List<Double> values; |
|||
} |
@ -1,25 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
/** |
|||
* 指标返回值 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class TargetPlanVO extends TargetVO { |
|||
|
|||
/** |
|||
* 指标模板编码 |
|||
*/ |
|||
private String targetCode; |
|||
/** |
|||
* 值 |
|||
*/ |
|||
Double value; |
|||
} |
@ -1,36 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
/** |
|||
* 指标返回值 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class TargetResultVO extends TargetVO { |
|||
|
|||
/** |
|||
* 指标名称 |
|||
*/ |
|||
private String targetName; |
|||
/** |
|||
* 指标单位 |
|||
*/ |
|||
private String targetUnit; |
|||
/** |
|||
* 值 |
|||
*/ |
|||
private Double value; |
|||
|
|||
public TargetResultVO (String targetCode, String targetName, String targetUnit, Double value) { |
|||
super(targetCode); |
|||
this.targetName = targetName; |
|||
this.targetUnit = targetUnit; |
|||
this.value = value; |
|||
} |
|||
} |
@ -1,16 +0,0 @@ |
|||
package com.lzbi.wechat.domain.vo; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class TargetVO { |
|||
|
|||
/** |
|||
* 指标模板编码 |
|||
*/ |
|||
private String targetCode; |
|||
} |
@ -1,45 +0,0 @@ |
|||
package com.lzbi.wechat.mapper; |
|||
|
|||
import com.lzbi.wechat.domain.SysWechat; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
/** |
|||
* 微信用户关系数据访问层 |
|||
*/ |
|||
public interface SysWechatMapper { |
|||
|
|||
/** |
|||
* 查询微信用户关系 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
SysWechat selectSysWechatById(@Param("id") Long id); |
|||
|
|||
/** |
|||
* 查询微信用户关系 |
|||
* @param openId |
|||
* @return |
|||
*/ |
|||
SysWechat selectWechatByOpenId(@Param("openId") String openId); |
|||
|
|||
/** |
|||
* 增加微信用户关系 |
|||
* @param sysWechat |
|||
* @return |
|||
*/ |
|||
int insertSysWechat(SysWechat sysWechat); |
|||
|
|||
/** |
|||
* 修改微信用户关系 |
|||
* @param sysWechat |
|||
* @return |
|||
*/ |
|||
int updateSysWechat(SysWechat sysWechat); |
|||
|
|||
/** |
|||
* 删除微信用户关系 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
int deleteSysWechat(@Param("id") Long id); |
|||
} |
@ -1,139 +0,0 @@ |
|||
package com.lzbi.wechat.service; |
|||
|
|||
import com.lzbi.asset.domain.DcBaseAssetInfo; |
|||
import com.lzbi.asset.mapper.DcBaseAssetInfoMapper; |
|||
import com.lzbi.asset.mapper.DcBusiWorkReadConfigMapper; |
|||
import com.lzbi.common.config.IotServerApiConfig; |
|||
import com.lzbi.common.constant.BizConstants; |
|||
import com.lzbi.common.core.domain.entity.SysDept; |
|||
import com.lzbi.common.core.domain.entity.SysRole; |
|||
import com.lzbi.common.core.domain.entity.SysUser; |
|||
import com.lzbi.common.core.domain.model.LoginUser; |
|||
import com.lzbi.common.utils.SecurityUtils; |
|||
import com.lzbi.system.service.ISysDeptService; |
|||
import com.lzbi.wechat.domain.dto.ParamsContrastDTO; |
|||
import com.lzbi.wechat.domain.vo.ChildDeptVO; |
|||
import com.lzbi.wechat.domain.vo.DeptVO; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Slf4j |
|||
@Service("wechatDeptService") |
|||
public class DeptService { |
|||
|
|||
@Autowired |
|||
private ISysDeptService sysDeptService; |
|||
|
|||
@Resource |
|||
private DcBaseAssetInfoMapper dcBaseAssetInfoMapper; |
|||
|
|||
@Resource |
|||
private DcBusiWorkReadConfigMapper dcBusiWorkReadConfigMapper; |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
@Autowired |
|||
private IotServerApiConfig iotServerApiConfig; |
|||
|
|||
public List<DeptVO> getSelfDeptList() { |
|||
List<DeptVO> list = new ArrayList<>(); |
|||
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|||
SysUser sysUser = loginUser.getUser(); |
|||
List<SysRole> roles = sysUser.getRoles(); |
|||
List<Long> roleIds = roles.stream().map(SysRole::getRoleId).collect(Collectors.toList()); |
|||
List<SysDept> sysDepts = sysDeptService.selectDeptListByRoleIds(roleIds); |
|||
if (!CollectionUtils.isEmpty(sysDepts)) { |
|||
list = sysDepts.stream().filter(sysDept -> { |
|||
if (BizConstants.DcDeptAttr.COMANY.equals(sysDept.getOrgType())) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
}).map(sysDept -> { |
|||
DeptVO deptVO = new DeptVO(); |
|||
deptVO.setValue(sysDept.getDeptId()); |
|||
deptVO.setLabel(sysDept.getDeptName()); |
|||
return deptVO; |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
public List<ChildDeptVO> getDeptChildren(Long deptId) { |
|||
List<ChildDeptVO> list = new ArrayList<>(); |
|||
SysDept selfDept = sysDeptService.selectDeptById(deptId); |
|||
String orgType = selfDept.getOrgType(); |
|||
if (BizConstants.DcDeptAttr.COMANY.equals(orgType)) { |
|||
SysDept params = new SysDept(); |
|||
params.setParentId(deptId); |
|||
params.setOrgType(BizConstants.DcDeptAttr.HEAT_SOURCE); |
|||
List<SysDept> sysDeptList = sysDeptService.selectDeptList(params); |
|||
if (!CollectionUtils.isEmpty(sysDeptList)) { |
|||
list = sysDeptList.stream().map(item -> { |
|||
ChildDeptVO childDeptVO = new ChildDeptVO(); |
|||
childDeptVO.setDeptId(item.getDeptId()); |
|||
childDeptVO.setDeptName(item.getDeptName()); |
|||
childDeptVO.setTemperatureSupply(80D); |
|||
childDeptVO.setTemperatureComeBack(53D); |
|||
return childDeptVO; |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
getHeatSourceParamsValue(deptId); |
|||
} else { |
|||
DcBaseAssetInfo params = new DcBaseAssetInfo(); |
|||
params.setOrgId(deptId); |
|||
params.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); |
|||
List<DcBaseAssetInfo> assetInfoList = dcBaseAssetInfoMapper.selectDcBaseAssetInfoList(params); |
|||
if (!CollectionUtils.isEmpty(assetInfoList)) { |
|||
list = assetInfoList.stream().map(item -> { |
|||
ChildDeptVO childDeptVO = new ChildDeptVO(); |
|||
childDeptVO.setDeptId(item.getAssetCode()); |
|||
childDeptVO.setDeptName(item.getAssetName()); |
|||
childDeptVO.setTemperatureSupply(80D); |
|||
childDeptVO.setTemperatureComeBack(53D); |
|||
return childDeptVO; |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
/** |
|||
* 查询热源参数值 |
|||
* @param deptId |
|||
* @return |
|||
*/ |
|||
public Map<Long, Map<String, Double>> getHeatSourceParamsValue (Long deptId) { |
|||
Long userId = SecurityUtils.getUserId(); |
|||
List<String> targetModelCodeList = new ArrayList<>(); |
|||
targetModelCodeList.add("101"); |
|||
targetModelCodeList.add("102"); |
|||
DcBaseAssetInfo assetParams = new DcBaseAssetInfo(); |
|||
assetParams.setOrgId(deptId); |
|||
assetParams.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); |
|||
assetParams.setAssetType(BizConstants.DcAssetType.REPORT); |
|||
List<ParamsContrastDTO> paramsContrastDTOList = dcBusiWorkReadConfigMapper.selectDcBusiWorkReadConfigByAssetTarget(targetModelCodeList, assetParams); |
|||
if (!CollectionUtils.isEmpty(paramsContrastDTOList)) { |
|||
List<String> paramsCodeList = paramsContrastDTOList.stream().map(ParamsContrastDTO::getParamsCode).collect(Collectors.toList()); |
|||
Map<Long, Map<Object, List<String>>> req = new HashMap<>(); |
|||
Map<Object, List<String>> deptMap = new HashMap<>(); |
|||
deptMap.put(deptId, paramsCodeList); |
|||
req.put(userId, deptMap); |
|||
String resp = restTemplate.postForObject(iotServerApiConfig.getParamsValue(), req, String.class); |
|||
log.info("参数值:{}", resp); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
@ -1,181 +0,0 @@ |
|||
package com.lzbi.wechat.service; |
|||
|
|||
import com.lzbi.common.constant.CacheConstants; |
|||
import com.lzbi.common.constant.Constants; |
|||
import com.lzbi.common.constant.UserConstants; |
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.common.core.domain.entity.SysUser; |
|||
import com.lzbi.common.core.domain.model.LoginUser; |
|||
import com.lzbi.common.core.redis.RedisCache; |
|||
import com.lzbi.common.exception.ServiceException; |
|||
import com.lzbi.common.exception.user.*; |
|||
import com.lzbi.common.utils.DateUtils; |
|||
import com.lzbi.common.utils.MessageUtils; |
|||
import com.lzbi.common.utils.StringUtils; |
|||
import com.lzbi.common.utils.ip.IpUtils; |
|||
import com.lzbi.framework.manager.AsyncManager; |
|||
import com.lzbi.framework.manager.factory.AsyncFactory; |
|||
import com.lzbi.framework.security.context.AuthenticationContextHolder; |
|||
import com.lzbi.framework.web.service.TokenService; |
|||
import com.lzbi.system.service.ISysConfigService; |
|||
import com.lzbi.system.service.ISysUserService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.security.authentication.AuthenticationManager; |
|||
import org.springframework.security.authentication.BadCredentialsException; |
|||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|||
import org.springframework.security.core.Authentication; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
@Service |
|||
public class LoginService { |
|||
|
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Resource |
|||
private AuthenticationManager authenticationManager; |
|||
|
|||
@Autowired |
|||
private RedisCache redisCache; |
|||
|
|||
@Autowired |
|||
private ISysUserService userService; |
|||
|
|||
@Autowired |
|||
private ISysConfigService configService; |
|||
|
|||
/** |
|||
* 登录验证 |
|||
* |
|||
* @param username 用户名 |
|||
* @param password 密码 |
|||
* @param code 验证码 |
|||
* @param uuid 唯一标识 |
|||
* @return 结果 |
|||
*/ |
|||
public AjaxResult login(String username, String password, String code, String uuid) |
|||
{ |
|||
AjaxResult ajax = AjaxResult.success(); |
|||
// 验证码校验
|
|||
validateCaptcha(username, code, uuid); |
|||
// 登录前置校验
|
|||
loginPreCheck(username, password); |
|||
// 用户验证
|
|||
Authentication authentication = null; |
|||
try |
|||
{ |
|||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); |
|||
AuthenticationContextHolder.setContext(authenticationToken); |
|||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
|||
authentication = authenticationManager.authenticate(authenticationToken); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
if (e instanceof BadCredentialsException) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); |
|||
throw new UserPasswordNotMatchException(); |
|||
} |
|||
else |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); |
|||
throw new ServiceException(e.getMessage()); |
|||
} |
|||
} |
|||
finally |
|||
{ |
|||
AuthenticationContextHolder.clearContext(); |
|||
} |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
|||
LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
|||
SysUser user = loginUser.getUser(); |
|||
recordLoginInfo(loginUser.getUserId()); |
|||
// 生成token
|
|||
String token = tokenService.createToken(loginUser); |
|||
ajax.put(Constants.TOKEN, token); |
|||
ajax.put("nickName", user.getNickName()); |
|||
ajax.put("phone", user.getPhonenumber()); |
|||
return ajax; |
|||
} |
|||
|
|||
/** |
|||
* 校验验证码 |
|||
* |
|||
* @param username 用户名 |
|||
* @param code 验证码 |
|||
* @param uuid 唯一标识 |
|||
* @return 结果 |
|||
*/ |
|||
public void validateCaptcha(String username, String code, String uuid) |
|||
{ |
|||
boolean captchaEnabled = configService.selectCaptchaEnabled(); |
|||
if (captchaEnabled) |
|||
{ |
|||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); |
|||
String captcha = redisCache.getCacheObject(verifyKey); |
|||
redisCache.deleteObject(verifyKey); |
|||
if (captcha == null) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); |
|||
throw new CaptchaExpireException(); |
|||
} |
|||
if (!code.equalsIgnoreCase(captcha)) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); |
|||
throw new CaptchaException(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 登录前置校验 |
|||
* @param username 用户名 |
|||
* @param password 用户密码 |
|||
*/ |
|||
public void loginPreCheck(String username, String password) |
|||
{ |
|||
// 用户名或密码为空 错误
|
|||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); |
|||
throw new UserNotExistsException(); |
|||
} |
|||
// 密码如果不在指定范围内 错误
|
|||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH |
|||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); |
|||
throw new UserPasswordNotMatchException(); |
|||
} |
|||
// 用户名不在指定范围内 错误
|
|||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH |
|||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); |
|||
throw new UserPasswordNotMatchException(); |
|||
} |
|||
// IP黑名单校验
|
|||
String blackStr = configService.selectConfigByKey("sys.login.blackIPList"); |
|||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
|||
{ |
|||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked"))); |
|||
throw new BlackListException(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 记录登录信息 |
|||
* |
|||
* @param userId 用户ID |
|||
*/ |
|||
public void recordLoginInfo(Long userId) |
|||
{ |
|||
SysUser sysUser = new SysUser(); |
|||
sysUser.setUserId(userId); |
|||
sysUser.setLoginIp(IpUtils.getIpAddr()); |
|||
sysUser.setLoginDate(DateUtils.getNowDate()); |
|||
userService.updateUserProfile(sysUser); |
|||
} |
|||
} |
@ -1,62 +0,0 @@ |
|||
package com.lzbi.wechat.service; |
|||
|
|||
import com.lzbi.wechat.domain.SysWechat; |
|||
import com.lzbi.wechat.mapper.SysWechatMapper; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
/** |
|||
* 微信用户关系业务访问层 |
|||
*/ |
|||
@Service |
|||
public class SysWechatService { |
|||
|
|||
@Resource |
|||
private SysWechatMapper sysWechatMapper; |
|||
|
|||
/** |
|||
* 查询微信用户关系 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public SysWechat selectWechatById(Long id) { |
|||
return sysWechatMapper.selectSysWechatById(id); |
|||
} |
|||
|
|||
/** |
|||
* 查询微信用户关系 |
|||
* @param openId |
|||
* @return |
|||
*/ |
|||
public SysWechat selectWechatByOpenId(String openId) { |
|||
return sysWechatMapper.selectWechatByOpenId(openId); |
|||
} |
|||
|
|||
/** |
|||
* 增加微信用户关系 |
|||
* @param sysWechat |
|||
* @return |
|||
*/ |
|||
public int insertWechat(SysWechat sysWechat) { |
|||
return sysWechatMapper.insertSysWechat(sysWechat); |
|||
} |
|||
|
|||
/** |
|||
* 修改微信用户关系 |
|||
* @param sysWechat |
|||
* @return |
|||
*/ |
|||
public int updateWechat(SysWechat sysWechat) { |
|||
return sysWechatMapper.updateSysWechat(sysWechat); |
|||
} |
|||
|
|||
/** |
|||
* 删除微信用户关系 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public int deleteWechat(Long id) { |
|||
return sysWechatMapper.deleteSysWechat(id); |
|||
} |
|||
} |
@ -1,245 +0,0 @@ |
|||
package com.lzbi.wechat.service; |
|||
|
|||
import com.lzbi.asset.mapper.DcBaseAssetInfoMapper; |
|||
import com.lzbi.common.constant.BizConstants; |
|||
import com.lzbi.common.constant.TargetModelCodeConstants; |
|||
import com.lzbi.draft.mapper.DcBusiTargetDraftDaynewMapper; |
|||
import com.lzbi.draft.mapper.DcBusiTargetDraftMonthMapper; |
|||
import com.lzbi.system.service.ISysDeptService; |
|||
import com.lzbi.targetFolder.mapper.DcBaseAssetTargetMapper; |
|||
import com.lzbi.wechat.domain.dto.TargetModelValueDTO; |
|||
import com.lzbi.wechat.domain.vo.TargetPlanVO; |
|||
import com.lzbi.wechat.domain.vo.TargetResultVO; |
|||
import com.lzbi.wechat.domain.vo.TargetVO; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.text.DecimalFormat; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class TargetService { |
|||
|
|||
@Autowired |
|||
private ISysDeptService sysDeptService; |
|||
|
|||
@Resource |
|||
private DcBaseAssetInfoMapper dcBaseAssetInfoMapper; |
|||
|
|||
@Resource |
|||
private DcBaseAssetTargetMapper dcBaseAssetTargetMapper; |
|||
|
|||
@Resource |
|||
private DcBusiTargetDraftDaynewMapper dcBusiTargetDraftDaynewMapper; |
|||
|
|||
@Resource |
|||
private DcBusiTargetDraftMonthMapper dcBusiTargetDraftMonthMapper; |
|||
|
|||
private TargetModelValueDTO buildeTargetModelValueDTO(List<String> targetModelCodeList, Long deptId, String date) { |
|||
String year = null; |
|||
String month = null; |
|||
String day = null; |
|||
if (StringUtils.isNotBlank(date)) { |
|||
String[] arr = date.split("-"); |
|||
if (arr.length == 3) { |
|||
year = arr[0]; |
|||
month = arr[1]; |
|||
day = arr[2]; |
|||
} else { |
|||
throw new RuntimeException("日期格式不正确"); |
|||
} |
|||
} |
|||
return new TargetModelValueDTO(targetModelCodeList, deptId, year, month, day); |
|||
} |
|||
|
|||
public Double getHeatRadiatingArea(Long deptId, String date) { |
|||
List<String> targetModelCodeList = new ArrayList<>(); |
|||
targetModelCodeList.add(TargetModelCodeConstants.总开栓面积); |
|||
TargetModelValueDTO targetModelValueDTO = buildeTargetModelValueDTO(targetModelCodeList, deptId, date); |
|||
List<TargetResultVO> targetResultVOList = dcBusiTargetDraftDaynewMapper.selectDayTargetModelValue(targetModelValueDTO); |
|||
Double result = null; |
|||
if (!CollectionUtils.isEmpty(targetResultVOList)) { |
|||
result = targetResultVOList.get(0).getValue(); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
public Map<String, TargetResultVO> getComanyTarget(Long deptId, String date) { |
|||
List<String> targetModelCodeList = new ArrayList<>(); |
|||
targetModelCodeList.add(TargetModelCodeConstants.总产热量); |
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网补水量); |
|||
targetModelCodeList.add(TargetModelCodeConstants.从大唐补一次网水量); |
|||
targetModelCodeList.add(TargetModelCodeConstants.总厂用电量); |
|||
targetModelCodeList.add(TargetModelCodeConstants.生产用标煤总量); |
|||
targetModelCodeList.add(TargetModelCodeConstants.热耗率); |
|||
TargetModelValueDTO targetModelValueDTO = buildeTargetModelValueDTO(targetModelCodeList, deptId, date); |
|||
List<TargetResultVO> targetResultVOList = dcBusiTargetDraftDaynewMapper.selectDayTargetModelValue(targetModelValueDTO); |
|||
Map<String, TargetResultVO> map = listTransitionMap(targetResultVOList); |
|||
TargetResultVO onceWater = map.get(TargetModelCodeConstants.一次网补水量); |
|||
TargetResultVO onceWater2 = map.get(TargetModelCodeConstants.从大唐补一次网水量); |
|||
if (null != onceWater.getValue() && null != onceWater2.getValue()) { |
|||
onceWater.setValue(onceWater.getValue() + onceWater2.getValue()); |
|||
} |
|||
map.remove(TargetModelCodeConstants.从大唐补一次网水量); |
|||
map.put(TargetModelCodeConstants.一次网补水量, onceWater); |
|||
return map; |
|||
} |
|||
|
|||
public Map<String, TargetResultVO> getHeatSourceTarget(Long deptId, String date, String type) { |
|||
List<String> targetModelCodeList = new ArrayList<>(); |
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网补水量); // 一次网水耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.从大唐补一次网水量); // 一次网水耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.总厂用电量); // 一次网电耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.生产用标煤总量); // 一次网煤耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.总产热量); // 总产热量
|
|||
targetModelCodeList.add(TargetModelCodeConstants.汽炉产汽量); // 总产气量
|
|||
targetModelCodeList.add(TargetModelCodeConstants.发电量); // 总发电量
|
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗水量); // 二次网总水耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗电量); // 二次网总电耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网供水温度); // 一次网供温
|
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网回水温度); // 一次网回温
|
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网耗水率); // 一次网水单耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.热源厂电耗率); // 一次网电单耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.单位面积耗标煤); // 一次网煤单耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗水率); // 二次网水单耗
|
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗电率); // 二次网电单耗
|
|||
TargetModelValueDTO targetModelValueDTO = buildeTargetModelValueDTO(targetModelCodeList, deptId, date); |
|||
Map<String, TargetResultVO> map; |
|||
if (BizConstants.TargetType.DAY.equals(type)) { |
|||
List<TargetResultVO> targetResultVOList = dcBusiTargetDraftDaynewMapper.selectDayTargetModelValue(targetModelValueDTO); |
|||
map = listTransitionMap(targetResultVOList); |
|||
} else { |
|||
List<TargetResultVO> targetResultVOList = dcBusiTargetDraftDaynewMapper.selectTotalTargetModelValue(targetModelValueDTO); |
|||
map = listTransitionMap(targetResultVOList); |
|||
} |
|||
TargetResultVO targetResultVO1 = map.get(TargetModelCodeConstants.一次网补水量); |
|||
TargetResultVO targetResultVO2 = map.get(TargetModelCodeConstants.从大唐补一次网水量); |
|||
if (null != targetResultVO1.getValue() && null != targetResultVO2.getValue()) { |
|||
targetResultVO1.setValue(targetResultVO1.getValue() + targetResultVO2.getValue()); |
|||
} else if (null == targetResultVO1.getValue() && null != targetResultVO2.getValue()) { |
|||
targetResultVO1.setValue(targetResultVO2.getValue()); |
|||
} |
|||
map.remove(TargetModelCodeConstants.从大唐补一次网水量); |
|||
return map; |
|||
} |
|||
|
|||
public Map<String, TargetResultVO> getHeatExchangeStationParams(Long deptId) { |
|||
Map<String, TargetResultVO> map = new HashMap<>(); |
|||
map.put("014", new TargetResultVO("014", "一次网回压", "Mpa", 14123123D)); |
|||
map.put("013", new TargetResultVO("013", "一次网供压", "Mpa", 2697D)); |
|||
map.put("011", new TargetResultVO("011", "一次网供温", "°C", 16791D)); |
|||
map.put("012", new TargetResultVO("012", "一次网回温", "°C", 11679D)); |
|||
map.put("007", new TargetResultVO("007", "瞬时流量", "m³/h", 8971D)); |
|||
map.put("008", new TargetResultVO("008", "瞬时热量", "kcal", 14123123D)); |
|||
map.put("009", new TargetResultVO("009", "累计热量", "kcal", 2697D)); |
|||
map.put("047", new TargetResultVO("047", "二次网供水压力", "Mpa", 16791D)); |
|||
map.put("048", new TargetResultVO("048", "二次网回水压力", "Mpa", 11679D)); |
|||
map.put("045", new TargetResultVO("045", "二次网供水温", "°C", 8971D)); |
|||
map.put("046", new TargetResultVO("046", "二次网回水温", "°C", 8971D)); |
|||
map.put("001", new TargetResultVO("001", "电调阀开度给定", "%", 14123123D)); |
|||
map.put("002", new TargetResultVO("002", "电调阀开度反馈", "%", 2697D)); |
|||
map.put("015", new TargetResultVO("015", "水箱水位计", "GJ", 16791D)); |
|||
map.put("004", new TargetResultVO("004", "电调阀控制模式选择", "GJ", 11679D)); |
|||
map.put("003", new TargetResultVO("003", "电调阀远控/就地", "°C", 8971D)); |
|||
map.put("044", new TargetResultVO("044", "二次网压差设定", "%", 14123123D)); |
|||
map.put("019", new TargetResultVO("019", "一次网管道泵上电", "", 2697D)); |
|||
map.put("020", new TargetResultVO("020", "一次网管道泵下电", "", 16791D)); |
|||
map.put("005", new TargetResultVO("005", "二次网供温设定", "", 16791D)); |
|||
map.put("018", new TargetResultVO("018", "一次网管道泵远控/就地", "", 16791D)); |
|||
map.put("021", new TargetResultVO("021", "一次网管道泵启动", "", 16791D)); |
|||
map.put("010", new TargetResultVO("010", "热量累计清零", "kwh", 16791D)); |
|||
map.put("017", new TargetResultVO("017", "总电表", "°C", 16791D)); |
|||
map.put("006", new TargetResultVO("006", "二次网供回水平均温设定", "m³", 16791D)); |
|||
map.put("031", new TargetResultVO("031", "水表(累计补水量)", "%", 16791D)); |
|||
map.put("023", new TargetResultVO("023", "一次网管道泵频率给定", "%", 16791D)); |
|||
map.put("028", new TargetResultVO("028", "一次网混水电调阀开度给定", "%", 16791D)); |
|||
map.put("029", new TargetResultVO("029", "一次网混水电调阀开度反馈", "", 16791D)); |
|||
map.put("035", new TargetResultVO("035", "补水泵1#故障状态", "m³", 16791D)); |
|||
map.put("032", new TargetResultVO("032", "水表(累计补水量清零)", "", 16791D)); |
|||
map.put("036", new TargetResultVO("036", "补水泵2#故障状态", "", 16791D)); |
|||
map.put("037", new TargetResultVO("037", "循环泵远控/就地选择", "", 16791D)); |
|||
map.put("038", new TargetResultVO("038", "循环泵1#/2#泵选择", "", 16791D)); |
|||
map.put("039", new TargetResultVO("039", "循环泵控制模式选择", "", 16791D)); |
|||
map.put("025", new TargetResultVO("025", "一次网管道泵运行/停止状态", "", 16791D)); |
|||
map.put("026", new TargetResultVO("026", "一次网管道泵故障状态", "", 16791D)); |
|||
map.put("027", new TargetResultVO("027", "一次网混水电调阀远控/就地", "", 16791D)); |
|||
map.put("033", new TargetResultVO("033", "补水泵1#运行/停止状态", "", 16791D)); |
|||
map.put("034", new TargetResultVO("034", "补水泵2#运行/停止状态", "", 16791D)); |
|||
map.put("040", new TargetResultVO("040", "循环泵变频上电", "", 16791D)); |
|||
map.put("041", new TargetResultVO("041", "循环泵变频下电", "", 16791D)); |
|||
map.put("042", new TargetResultVO("042", "循环泵变频启动", "", 16791D)); |
|||
map.put("043", new TargetResultVO("043", "循环泵变频停止", "", 16791D)); |
|||
map.put("022", new TargetResultVO("022", "一次网管道泵停止", "", 16791D)); |
|||
map.put("030", new TargetResultVO("030", "水表(瞬时补水量)", "m³", 16791D)); |
|||
map.put("066", new TargetResultVO("066", "一次网管道泵启/停", "", 16791D)); |
|||
map.put("024", new TargetResultVO("024", "一次网管道泵频率反馈", "", 16791D)); |
|||
return map; |
|||
} |
|||
|
|||
public List<List<Object>> getFinishingRate(Long deptId) { |
|||
List<List<Object>> list = new ArrayList<>(); |
|||
List<String> targetModelCodeList = new ArrayList<>(); |
|||
targetModelCodeList.add(TargetModelCodeConstants.一次网耗水率); |
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗水率); |
|||
targetModelCodeList.add(TargetModelCodeConstants.热源厂电耗率); |
|||
targetModelCodeList.add(TargetModelCodeConstants.二次网耗电率); |
|||
targetModelCodeList.add(TargetModelCodeConstants.单位面积耗标煤); |
|||
TargetModelValueDTO targetModelValueDTO = buildeTargetModelValueDTO(targetModelCodeList, deptId, null); |
|||
List<TargetResultVO> targetResultVOList = dcBusiTargetDraftDaynewMapper.selectTotalTargetModelValue(targetModelValueDTO); |
|||
List<TargetPlanVO> targetPlanVOList = dcBusiTargetDraftMonthMapper.selectTotalTargetModelPlanValue(targetModelValueDTO); |
|||
Map<String, TargetResultVO> targetValueMap = null; |
|||
Map<String, Double> targetPlanValueMap = null; |
|||
if (!CollectionUtils.isEmpty(targetResultVOList)) { |
|||
targetValueMap = listTransitionMap(targetResultVOList); |
|||
} |
|||
if (!CollectionUtils.isEmpty(targetPlanVOList)) { |
|||
targetPlanValueMap = targetPlanVOList.stream().collect(Collectors.toMap(TargetPlanVO::getTargetCode, TargetPlanVO::getValue)); |
|||
} |
|||
if (null == targetValueMap || null == targetPlanValueMap) { |
|||
throw new RuntimeException("无数据"); |
|||
} |
|||
List<Object> names = new ArrayList<>(); |
|||
names.add("name"); |
|||
List<Object> values = new ArrayList<>(); |
|||
values.add("总完成率"); |
|||
DecimalFormat decimalFormat = new DecimalFormat("#0.00"); |
|||
for (String targetModelCode : targetModelCodeList) { |
|||
TargetResultVO targetResultVO = targetValueMap.get(targetModelCode); |
|||
Double value = targetResultVO.getValue(); |
|||
Double planValue = targetPlanValueMap.get(targetModelCode); |
|||
if (null == planValue) { |
|||
continue; |
|||
} |
|||
names.add(targetResultVO.getTargetName()); |
|||
values.add(decimalFormat.format((value / planValue) * 100)); |
|||
} |
|||
list.add(names); |
|||
list.add(values); |
|||
return list; |
|||
} |
|||
|
|||
public List<List<Object>> finishingRateLine(Long deptId) { |
|||
List<List<Object>> list = new ArrayList<>(); |
|||
List<Object> list1 = Arrays.asList("product", "2012", "2013", "2014", "2015", "2016", "2017"); |
|||
List<Object> list2 = Arrays.asList("Milk Tea", 56.5, 82.1, 88.7, 70.1, 53.4, 85.1); |
|||
List<Object> list3 = Arrays.asList("Matcha Latte", 51.1, 51.4, 55.1, 53.3, 73.8, 68.7); |
|||
List<Object> list4 = Arrays.asList("Cheese Cocoa", 40.1, 62.2, 69.5, 36.4, 45.2, 32.5); |
|||
List<Object> list5 = Arrays.asList("Walnut Brownie", 25.2, 37.1, 41.2, 18, 33.9, 49.1); |
|||
list.add(list1); |
|||
list.add(list2); |
|||
list.add(list3); |
|||
list.add(list4); |
|||
list.add(list5); |
|||
return list; |
|||
} |
|||
|
|||
private <T extends TargetVO> Map<String, T> listTransitionMap(List<T> list) { |
|||
Map<String, T> map = new HashMap<>(); |
|||
list.forEach(obj -> map.put(obj.getTargetCode(), obj)); |
|||
return map; |
|||
} |
|||
} |
@ -1,161 +0,0 @@ |
|||
package com.lzbi.wechat.service; |
|||
|
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.lzbi.common.config.WechatConfig; |
|||
import com.lzbi.common.core.domain.entity.SysUser; |
|||
import com.lzbi.common.core.domain.model.LoginUser; |
|||
import com.lzbi.common.exception.ServiceException; |
|||
import com.lzbi.framework.web.service.SysLoginService; |
|||
import com.lzbi.framework.web.service.SysPermissionService; |
|||
import com.lzbi.framework.web.service.TokenService; |
|||
import com.lzbi.system.service.ISysUserService; |
|||
import com.lzbi.wechat.domain.SysWechat; |
|||
import com.lzbi.wechat.domain.resp.WechatAccessTokenResp; |
|||
import com.lzbi.wechat.domain.resp.WechatCodeLoginResp; |
|||
import com.lzbi.wechat.domain.resp.WechatPhoneNumberResp; |
|||
import com.lzbi.wechat.domain.req.CodeLoginReq; |
|||
import com.lzbi.wechat.domain.req.PhoneNumberLoginReq; |
|||
import com.lzbi.wechat.domain.req.PhoneNumberReq; |
|||
import com.lzbi.wechat.domain.vo.CodeLoginVO; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.ObjectUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpEntity; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 微信服务业务逻辑层 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
public class WechatService { |
|||
|
|||
@Autowired |
|||
private WechatConfig wechatConfig; |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
@Autowired |
|||
private SysWechatService sysWechatService; |
|||
|
|||
@Autowired |
|||
private ISysUserService sysUserService; |
|||
|
|||
@Autowired |
|||
private SysLoginService sysLoginService; |
|||
|
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Autowired |
|||
private SysPermissionService permissionService; |
|||
|
|||
/** |
|||
* 登录凭证登录 |
|||
* |
|||
* @param codeLoginReq |
|||
* @return |
|||
*/ |
|||
public CodeLoginVO codeLogin(CodeLoginReq codeLoginReq) { |
|||
CodeLoginVO codeLoginVO = new CodeLoginVO(); |
|||
// 微信登录凭证登录请求,获取到open_id
|
|||
Map<String, Object> params = new HashMap<>(); |
|||
params.put("appid", wechatConfig.getAppId()); |
|||
params.put("secret", wechatConfig.getAppSecret()); |
|||
params.put("js_code", codeLoginReq.getCode()); |
|||
params.put("grant_type", "authorization_code"); |
|||
WechatCodeLoginResp resp = restTemplate.getForObject(wechatConfig.getCode2Session(), WechatCodeLoginResp.class, params); |
|||
if (ObjectUtils.isNotEmpty(resp) && 0L == resp.getErrcode()) { |
|||
String openid = resp.getOpenid(); |
|||
codeLoginVO.setOpenId(openid); |
|||
// 根据open_id到数据库中查询sysWechat信息
|
|||
SysWechat sysWechat = sysWechatService.selectWechatByOpenId(openid); |
|||
// 查询到了的话,执行登录操作,返回token
|
|||
if (ObjectUtils.isNotEmpty(sysWechat)) { |
|||
SysUser sysUser = sysUserService.selectUserByPhonenumber(sysWechat.getPhone()); |
|||
if (ObjectUtils.isNotEmpty(sysUser)) { |
|||
String token = this.getToken(sysUser); |
|||
codeLoginVO.setToken(token); |
|||
} |
|||
} |
|||
} else { |
|||
log.error("调用微信服务小程序登录接口时失败,{}, {}", resp.getErrcode(), resp.getErrmsg()); |
|||
throw new ServiceException(resp.getErrmsg(), resp.getErrcode()); |
|||
} |
|||
return codeLoginVO; |
|||
} |
|||
|
|||
@Transactional(rollbackFor = Exception.class) |
|||
public String phoneNumberLogin(PhoneNumberLoginReq phoneNumberLoginReq) { |
|||
// 微信和用户信息绑定
|
|||
SysWechat sysWechat = new SysWechat(phoneNumberLoginReq.getOpenId(), phoneNumberLoginReq.getPhone()); |
|||
int i = sysWechatService.insertWechat(sysWechat); |
|||
if (i > 0) { |
|||
// 获取token
|
|||
SysUser sysUser = sysUserService.selectUserByPhonenumber(sysWechat.getPhone()); |
|||
if (ObjectUtils.isNotEmpty(sysUser)) { |
|||
return this.getToken(sysUser); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 获取手机号 |
|||
* @param phoneNumberReq |
|||
* @return |
|||
*/ |
|||
public String getPhoneNumber(PhoneNumberReq phoneNumberReq) { |
|||
// 获取接口调用凭据
|
|||
Map<String, Object> getAccessTokenParams = new HashMap<>(); |
|||
getAccessTokenParams.put("appid", wechatConfig.getAppId()); |
|||
getAccessTokenParams.put("secret", wechatConfig.getAppSecret()); |
|||
getAccessTokenParams.put("grant_type", "client_credential"); |
|||
WechatAccessTokenResp wechatAccessTokenResp = restTemplate.getForObject(wechatConfig.getAccessToken(), WechatAccessTokenResp.class, getAccessTokenParams); |
|||
if (ObjectUtils.isNotEmpty(wechatAccessTokenResp) && null == wechatAccessTokenResp.getErrcode()) { |
|||
// 获取手机号
|
|||
String accessToken = wechatAccessTokenResp.getAccess_token(); |
|||
Map<String, Object> getPhoneNumberParams = new HashMap<>(); |
|||
getPhoneNumberParams.put("access_token", accessToken); |
|||
HttpHeaders headers = new HttpHeaders(); |
|||
headers.setContentType(MediaType.APPLICATION_JSON); |
|||
Map<String, Object> getPhoneNumberBody = new HashMap<>(); |
|||
getPhoneNumberBody.put("code", phoneNumberReq.getCode()); |
|||
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(getPhoneNumberBody), headers); |
|||
WechatPhoneNumberResp resp = restTemplate.postForObject(wechatConfig.getPhoneNumber(), entity, WechatPhoneNumberResp.class, getPhoneNumberParams); |
|||
if (ObjectUtils.isNotEmpty(resp) && 0L == resp.getErrcode()) { |
|||
if (null != resp.getPhone_info()) { |
|||
return resp.getPhone_info().getPurePhoneNumber(); |
|||
} |
|||
} else { |
|||
log.error("调用微信服务获取手机号接口时失败,{}, {}", resp.getErrcode(), resp.getErrmsg()); |
|||
throw new ServiceException(resp.getErrmsg(), resp.getErrcode()); |
|||
} |
|||
} else { |
|||
log.error("调用微信服务获取access_token接口时失败,{}, {}", wechatAccessTokenResp.getErrcode(), wechatAccessTokenResp.getErrmsg()); |
|||
throw new ServiceException(wechatAccessTokenResp.getErrmsg(), wechatAccessTokenResp.getErrcode()); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 获取token |
|||
* @param sysUser |
|||
* @return |
|||
*/ |
|||
private String getToken(SysUser sysUser) { |
|||
LoginUser loginUser = new LoginUser(sysUser.getUserId(), sysUser.getDeptId(), sysUser, permissionService.getMenuPermission(sysUser)); |
|||
sysLoginService.recordLoginInfo(loginUser.getUserId()); |
|||
// 生成token
|
|||
return tokenService.createToken(loginUser); |
|||
} |
|||
|
|||
} |
@ -1,149 +0,0 @@ |
|||
package com.lzbi.wechat.webSocket; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.websocket.*; |
|||
import javax.websocket.server.PathParam; |
|||
import javax.websocket.server.ServerEndpoint; |
|||
import java.io.IOException; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
|
|||
/** |
|||
* @ClassName HeatSourceServer |
|||
* @Description 热源列表服务 |
|||
* @Author lienbo |
|||
* @Date 2024/01/25 16:06 |
|||
* @Version V1.0 |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
@ServerEndpoint("/ws/heatSourceList/{userId}/{deptId}") |
|||
public class HeatSourceServer { |
|||
|
|||
/** |
|||
* 静态变量,用来记录当前在线连接数,线程安全的类。 |
|||
*/ |
|||
private static AtomicInteger onlineSessionClientCount = new AtomicInteger(0); |
|||
|
|||
/** |
|||
* 存放所有在线的客户端 |
|||
*/ |
|||
private static Map<Long, Session> onlineSessionClientMap = new ConcurrentHashMap<>(); |
|||
|
|||
/** |
|||
* 存放所有在线的用户和要查询的组织id |
|||
*/ |
|||
private static Map<Long, Long> onlineUserDeptMap = new ConcurrentHashMap<>(); |
|||
|
|||
/** |
|||
* 连接建立成功调用的方法。由前端<code>new WebSocket</code>触发 |
|||
* |
|||
* @param userId 每次页面建立连接时传入到服务端的id,比如用户id等。可以自定义。 |
|||
* @param deptId 公司ID |
|||
* @param session 与某个客户端的连接会话,需要通过它来给客户端发送消息 |
|||
*/ |
|||
@OnOpen |
|||
public void onOpen(@PathParam("userId") Long userId, @PathParam("deptId") Long deptId, Session session) { |
|||
log.info("连接建立中 ==> session_id = {},userId = {},deptId = {}", session.getId(), userId, deptId); |
|||
onlineUserDeptMap.put(userId, deptId); |
|||
onlineSessionClientMap.put(userId, session); |
|||
//在线数加1
|
|||
onlineSessionClientCount.incrementAndGet(); |
|||
sendToOne(userId, "hello " + userId + " 您已连接成功"); |
|||
log.info("连接建立成功,当前在线数为:{} ==> 开始监听新连接:session_id = {}, sid = {},。", onlineSessionClientCount, session.getId(), userId); |
|||
} |
|||
|
|||
/** |
|||
* 连接关闭调用的方法。由前端<code>socket.close()</code>触发 |
|||
* |
|||
* @param userId |
|||
* @param session |
|||
*/ |
|||
@OnClose |
|||
public void onClose(@PathParam("userId") Long userId, Session session) { |
|||
// 从 Map中移除
|
|||
onlineSessionClientMap.remove(userId); |
|||
//在线数减1
|
|||
onlineSessionClientCount.decrementAndGet(); |
|||
log.info("连接关闭成功,当前在线数为:{} ==> 关闭该连接信息:session_id = {}, userId = {},。", onlineSessionClientCount, session.getId(), userId); |
|||
} |
|||
|
|||
/** |
|||
* 收到客户端消息后调用的方法。由前端<code>socket.send</code>触发 |
|||
* * 当服务端执行toSession.getAsyncRemote().sendText(xxx)后,前端的socket.onmessage得到监听。 |
|||
* |
|||
* @param message |
|||
* @param session |
|||
*/ |
|||
@OnMessage |
|||
public void onMessage(String message, Session session) throws IOException { |
|||
log.info("服务端收到客户端消息 ==>, message = {}", message); |
|||
session.getBasicRemote().sendText(message); |
|||
} |
|||
|
|||
/** |
|||
* 发生错误调用的方法 |
|||
* |
|||
* @param session |
|||
* @param error |
|||
*/ |
|||
@OnError |
|||
public void onError(Session session, Throwable error) { |
|||
log.error("WebSocket发生错误,错误信息为:" + error.getMessage()); |
|||
error.printStackTrace(); |
|||
} |
|||
|
|||
/** |
|||
* 功能描述: 发送移除黑名单消息 |
|||
* @param userId |
|||
* @Author: lienbo |
|||
* @Date: 2023/8/27 23:19 |
|||
* @return: void |
|||
*/ |
|||
public void sendRemoveBlackList(Long userId) { |
|||
log.info("发送移除黑名单消息 ==>, userId = {}", userId); |
|||
this.sendToOne(userId, "remove"); |
|||
} |
|||
|
|||
/** |
|||
* 群发消息 |
|||
* |
|||
* @param message 消息 |
|||
*/ |
|||
private void sendToAll(String message) { |
|||
// 遍历在线map集合
|
|||
onlineSessionClientMap.forEach((userId, toSession) -> { |
|||
log.info("服务端给客户端群发消息 ==> userId = {}, message = {}", userId, message); |
|||
toSession.getAsyncRemote().sendText(message); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 指定发送消息 |
|||
* |
|||
* @param userId |
|||
* @param message |
|||
*/ |
|||
private void sendToOne(Long userId, String message) { |
|||
// 通过sid查询map中是否存在
|
|||
Session toSession = onlineSessionClientMap.get(userId); |
|||
if (toSession == null) { |
|||
log.error("服务端给客户端发送消息 ==> userId = {} 不存在, message = {}", userId, message); |
|||
return; |
|||
} |
|||
// 异步发送
|
|||
log.info("服务端给客户端发送消息 ==> userId = {}, message = {}", userId, message); |
|||
toSession.getAsyncRemote().sendText(message); |
|||
/* |
|||
// 同步发送
|
|||
try { |
|||
toSession.getBasicRemote().sendText(message); |
|||
} catch (IOException e) { |
|||
log.error("发送消息失败,WebSocket IO异常"); |
|||
e.printStackTrace(); |
|||
}*/ |
|||
} |
|||
} |
@ -1,26 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.lzbi.wechat.mapper.SysWechatMapper"> |
|||
|
|||
<select id="selectSysWechatById" resultType="com.lzbi.wechat.domain.SysWechat"> |
|||
select id, phone, app_id from sys_wechat where id = #{id} |
|||
</select> |
|||
|
|||
<select id="selectWechatByOpenId" resultType="com.lzbi.wechat.domain.SysWechat"> |
|||
select id, phone, app_id from sys_wechat where open_id = #{openId} |
|||
</select> |
|||
|
|||
<insert id="insertSysWechat" parameterType="com.lzbi.wechat.domain.SysWechat"> |
|||
insert into sys_wechat (open_id, phone) values (#{openId}, #{phone}) |
|||
</insert> |
|||
|
|||
<update id="updateSysWechat"> |
|||
update sys_wechat set open_id = #{openId}, phone = #{phone} where id = #{id} |
|||
</update> |
|||
|
|||
<delete id="deleteSysWechat"> |
|||
delete from sys_wechat where id = #{id} |
|||
</delete> |
|||
</mapper> |
Loading…
Reference in new issue