Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
3 文件已重命名
8个文件已添加
15个文件已修改
New file |
| | |
| | | package com.dy.common.webFilter; |
| | | |
| | | import com.dy.common.multiDataSource.DataSourceContext; |
| | | import jakarta.servlet.*; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-19 11:02 |
| | | * @LastEditTime 2024-06-19 11:02 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | public class WXDataSourceNameSetFilter implements Filter { |
| | | @Override |
| | | public void init(FilterConfig filterConfig) throws ServletException { |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| | | HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; |
| | | String wxDataSourceName = httpRequest.getHeader("tag"); |
| | | if(wxDataSourceName != null && wxDataSourceName.trim().length() > 0){ |
| | | log.info("微信开发,设置数据源名称为:" + wxDataSourceName); |
| | | //把组织单位标签作为数据源名称 |
| | | DataSourceContext.set(wxDataSourceName); |
| | | } else { |
| | | log.info("用户未选择数据源"); |
| | | } |
| | | |
| | | filterChain.doFilter(servletRequest, servletResponse); |
| | | } |
| | | |
| | | @Override |
| | | public void destroy() { |
| | | } |
| | | } |
| | |
| | | @ColumnWidth(30) |
| | | private Date findDt; |
| | | |
| | | @Schema(title = "在线状态") |
| | | @ExcelProperty("在线状态") |
| | | @ColumnWidth(6) |
| | | private String onlineState; |
| | | // @Schema(title = "在线状态") |
| | | // @ExcelProperty("在线状态") |
| | | // @ColumnWidth(6) |
| | | // private String onlineState; |
| | | |
| | | /** |
| | | * 是否在线 |
| | | */ |
| | | private Boolean isOnLine; |
| | | |
| | | |
| | | @Schema(title = "通讯协议") |
| | | @ExcelProperty("通讯协议") |
| | | @ColumnWidth(10) |
| | | private String protocol; |
| | | |
| | | @Schema(title = "备注") |
| | | @ExcelProperty("备注") |
| | | @ColumnWidth(10) |
| | | private String remarks; |
| | | } |
| | |
| | | #name: ym |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | # url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | # url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | username: root |
| | | password: dysql,;.abc!@# |
| | | druid: |
| | |
| | | |
| | | pipIrr: |
| | | global: |
| | | dev: true #是否开发阶段,true或false |
| | | dev: false #是否开发阶段,true或false |
| | | dsName: ym #开发阶段,设置临时的数据库名称 |
| | | mw: |
| | | webPort: 8070 |
| | |
| | | SELECT |
| | | COUNT(*) AS recordCount |
| | | FROM pr_controller con |
| | | LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id |
| | | INNER JOIN pr_intake inta ON con.intakeId = inta.id |
| | | LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id |
| | | INNER JOIN pr_intake inta ON con.intakeId = inta.id |
| | | left JOIN JSON_TABLE( |
| | | <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',--> |
| | | #{onLineMap}, |
| | | '$[*]' COLUMNS( |
| | | rtuAddr VARCHAR(20) PATH '$.rtuAddr', |
| | | isOnLine BOOLEAN PATH '$.isOnLine' |
| | | ) |
| | | ) rtus ON con.rtuAddr = rtus.rtuAddr |
| | | <where> |
| | | AND con.deleted = 0 |
| | | |
| | | <if test = "id != null and id > 0"> |
| | | AND con.id = ${id} |
| | | </if> |
| | | |
| | | <if test = "rtuAddr != null and rtuAddr !=''"> |
| | | AND con.rtuAddr like CONCAT('%',#{rtuAddr},'%') |
| | | </if> |
| | | |
| | | <if test="isOnLine != null and isOnLine !='' "> |
| | | AND rtus.isOnLine = #{isOnLine} |
| | | </if> |
| | | <if test = "bindNumber != null and bindNumber > 0"> |
| | | AND (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) = ${bindNumber} |
| | | </if> |
| | |
| | | CAST(con.id AS char) AS id, |
| | | con.rtuAddr AS rtuAddr, |
| | | inta.name AS intakeName, |
| | | "在线" AS onlineState, |
| | | con.protocol, |
| | | inta.remarks, |
| | | rtus.isOnLine, |
| | | (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) AS bindNumber, |
| | | con.findDt AS findDt |
| | | FROM pr_controller con |
| | | LEFT JOIN pr_intake_controller ic ON ic.controllerId = con.id |
| | | INNER JOIN pr_intake inta ON con.intakeId = inta.id |
| | | left JOIN JSON_TABLE( |
| | | <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',--> |
| | | #{onLineMap}, |
| | | '$[*]' COLUMNS( |
| | | rtuAddr VARCHAR(20) PATH '$.rtuAddr', |
| | | isOnLine BOOLEAN PATH '$.isOnLine' |
| | | ) |
| | | ) rtus ON con.rtuAddr = rtus.rtuAddr |
| | | <where> |
| | | AND con.deleted = 0 |
| | | |
| | | <if test = "id != null and id > 0"> |
| | | AND con.id = ${id} |
| | | </if> |
| | | |
| | | <if test = "rtuAddr != null and rtuAddr !=''"> |
| | | AND con.rtuAddr like CONCAT('%',#{rtuAddr},'%') |
| | | </if> |
| | | |
| | | <if test="isOnLine != null and isOnLine !='' "> |
| | | AND rtus.isOnLine = #{isOnLine} |
| | | </if> |
| | | <if test = "bindNumber != null and bindNumber > 0"> |
| | | AND (SELECT COUNT(*) FROM pr_intake_controller WHERE controllerId = con.id AND intakeId = inta.id AND operateType = 1) = ${bindNumber} |
| | | </if> |
| | |
| | | datasource: #配置数据源 |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driver-class-name: com.mysql.cj.jdbc.Driver |
| | | # url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | # url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull |
| | | username: root |
| | | password: dysql,;.abc!@# |
| | | druid: |
| | |
| | | } |
| | | //return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("获取开卡记录异常", e); |
| | | log.error("获取控制器记录异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; |
| | | import com.dy.pipIrrGlobal.daoPr.PrIntakeControllerMapper; |
| | |
| | | import com.dy.pipIrrGlobal.pojoPr.PrController; |
| | | import com.dy.pipIrrGlobal.pojoPr.PrIntakeController; |
| | | import com.dy.pipIrrGlobal.voPr.VoController; |
| | | import com.dy.pipIrrGlobal.voPr.VoOnLineIntake; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.util.UriComponentsBuilder; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send"; |
| | | |
| | | |
| | | /** |
| | | * 根据指定获取控制器记录 |
| | |
| | | * @return |
| | | */ |
| | | public QueryResultVo<List<VoController>> getControllers(QueryVo queryVo) { |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = prControllerMapper.getRecordCount(params); |
| | | Command com = new Command(); |
| | | com.id = Command.defaultId; |
| | | com.code = "LCD0001"; |
| | | com.type = "innerCommand"; |
| | | |
| | | QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); |
| | | rsVo.pageSize = queryVo.pageSize; |
| | | rsVo.pageCurr = queryVo.pageCurr; |
| | | JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = prControllerMapper.getControllers(params); |
| | | if (response != null && response.getString("code").equals("0001")) { |
| | | JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); |
| | | HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); |
| | | |
| | | return rsVo; |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("rtuAddr", entry.getKey()); |
| | | jsonObject.put("isOnLine", entry.getValue()); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | queryVo.setOnLineMap(jsonArray.toJSONString()); |
| | | |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = prControllerMapper.getRecordCount(params); |
| | | |
| | | QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); |
| | | rsVo.pageSize = queryVo.pageSize; |
| | | rsVo.pageCurr = queryVo.pageCurr; |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = prControllerMapper.getControllers(params); |
| | | return rsVo; |
| | | } else { |
| | | QueryResultVo<List<VoController>> rsVo = new QueryResultVo<>(); |
| | | return rsVo; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public Integer addController(PrController po) { |
| | | int rows = prControllerMapper.insert(po); |
| | | if(rows == 0) { |
| | | if (rows == 0) { |
| | | return 0; |
| | | } |
| | | PrIntakeController addPrIntakeController = new PrIntakeController(); |
| | |
| | | addPrIntakeController.setOperatedt(po.getOperateDt()); |
| | | addPrIntakeController.setRemarks("绑定"); |
| | | int rec = prIntakeControllerMapper.insert(addPrIntakeController); |
| | | if(rec == 0) { |
| | | if (rec == 0) { |
| | | return 0; |
| | | } |
| | | return 1 ; |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 根据控制器编号物理删除控制 |
| | | *2024-6-7 |
| | | * 2024-6-7 |
| | | * |
| | | * @param controllerId |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据主键查询控制器列表 |
| | | *2024-6-7 |
| | | * 2024-6-7 |
| | | * |
| | | * @param controllerId |
| | | * @return |
| | | */ |
| | | public PrController getByControllerId(Long controllerId) { |
| | | return prControllerMapper.selectByPrimaryKey(controllerId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送命令 |
| | | * |
| | | * @return |
| | | */ |
| | | protected BaseResponse sendCom2Mw(Command com) { |
| | | String url = UriComponentsBuilder.fromUriString(mwUrlSendCom) |
| | | .build() |
| | | .toUriString(); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers); |
| | | ResponseEntity<BaseResponse> response = null; |
| | | try { |
| | | // 通过Post方式调用接口 |
| | | response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return response.getBody(); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.dy.common.webUtil.QueryConditionVo; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.Max; |
| | | import jakarta.validation.constraints.Min; |
| | | import lombok.*; |
| | | |
| | | /** |
| | |
| | | @Schema(description = "控制器地址") |
| | | private String rtuAddr; |
| | | |
| | | @Schema(description = "在线状态") |
| | | public Integer onlineState; |
| | | // @Schema(description = "在线状态") |
| | | // public Integer onlineState; |
| | | |
| | | @Schema(description = "绑定数量") |
| | | public Integer bindNumber; |
| | | |
| | | /** |
| | | * 中间件返回的RTU在线情况对象数组 |
| | | */ |
| | | private String onLineMap; |
| | | |
| | | /** |
| | | * 是否在线 |
| | | */ |
| | | @Max(value = 1,message = "是否在线仅允许为真或假") |
| | | @Min(value = 0,message = "是否在线仅允许为真或假") |
| | | private Boolean isOnLine; |
| | | } |
| | |
| | | package com.dy.pipIrrSell.client; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; |
| | | import com.aliyuncs.exceptions.ClientException; |
| | | import com.dy.common.aop.SsoAop; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | |
| | | import com.dy.common.webUtil.ResultCodeMsg; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaClient; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeClient; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeOpenId; |
| | | import com.dy.pipIrrGlobal.voSe.VoClient; |
| | | import com.dy.pipIrrGlobal.voSe.VoClientWechat; |
| | | import com.dy.pipIrrSell.client.dto.CodeVerifyDTO; |
| | | import com.dy.pipIrrSell.result.SellResultCode; |
| | | import com.dy.pipIrrSell.sms.AliyunSmsSv; |
| | | import com.dy.pipIrrSell.sms.RandomCode; |
| | | import com.dy.pipIrrSell.util.RestTemplateUtil; |
| | | import com.dy.pipIrrSell.wechatpay.PayInfo; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.media.Content; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @RequiredArgsConstructor |
| | | public class ClientCtrl { |
| | | private final ClientSv clientSv; |
| | | private final AliyunSmsSv aliyunSmsSv; |
| | | //private final RedisUtils redisUtils; |
| | | private final RestTemplateUtil restTemplateUtil; |
| | | |
| | | private final String privateCertFileName = PayInfo.privateCertFileName; |
| | | private final String appid = PayInfo.appid; |
| | | private final String secret = PayInfo.secret; |
| | | private final String mchid = PayInfo.mchid; |
| | | private final String schema = PayInfo.schema; |
| | | private final String signType = PayInfo.signType; |
| | | private final String description = PayInfo.description; |
| | | private final String loginUrl = PayInfo.loginUrl; |
| | | private final String notifyUrl = PayInfo.notifyUrl; |
| | | private final String grantType = PayInfo.grantType; |
| | | |
| | | /** |
| | | * 获取农户列表 |
| | |
| | | map.put("projectNo",projectNo3); |
| | | return BaseResponseUtils.buildSuccess(map); |
| | | } |
| | | |
| | | /** |
| | | * 发送验证码 |
| | | * @param phoneNumber |
| | | * @return |
| | | */ |
| | | @Operation(summary = "发送验证码", description = "发送验证码") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "send_sms") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> sendSms(@RequestParam(name = "phoneNumber", required = true) String phoneNumber) throws ClientException { |
| | | if(phoneNumber == null || phoneNumber.length() <= 0) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.PHONE_NUMBER_CANNOT_BE_NULL.getMessage()); |
| | | } |
| | | |
| | | // 生成6位验证码并转为Json格式 |
| | | String securityCode = String.valueOf(RandomCode.genCode()); |
| | | JSONObject param = new JSONObject(); |
| | | param.put("code", securityCode); |
| | | String templateParam = param.toJSONString(); |
| | | |
| | | //redisUtils.set(phoneNumber, securityCode, 60); |
| | | |
| | | // 获取当前时间戳并延后3分钟 |
| | | Long timestamp = System.currentTimeMillis(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(timestamp); |
| | | calendar.add(Calendar.SECOND, 180); |
| | | Long expires = calendar.getTimeInMillis(); |
| | | |
| | | SeCodeVerify codeVerify = new SeCodeVerify(); |
| | | codeVerify.setPhoneNumber(phoneNumber); |
| | | codeVerify.setSecurityCode(securityCode); |
| | | codeVerify.setExpires(expires); |
| | | clientSv.addCodeVerify(codeVerify); |
| | | |
| | | SendSmsResponse response = aliyunSmsSv.sendSms(phoneNumber, templateParam); |
| | | if (response.getCode().equals("OK")) { |
| | | // 发送成功处理逻辑 |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } else { |
| | | // 发送失败处理逻辑 |
| | | return BaseResponseUtils.buildFail(SellResultCode.SECURITY_CODE_SEND_FAIL.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验验证码 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | @Operation(summary = "校验验证码", description = "校验验证码") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,false:失败(BaseResponse.content)", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "verify", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> verify(@RequestBody @Valid CodeVerifyDTO po, BindingResult bindingResult) throws IOException { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | String phoneNumber = po.getPhoneNumber(); |
| | | String securityCode = po.getSecurityCode(); |
| | | String code = po.getCode(); |
| | | |
| | | // 进行手机号、验证码、过期时间校验 |
| | | SeCodeVerify codeVerify = clientSv.getCodeVerify(phoneNumber); |
| | | if(codeVerify == null) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.NO_SECURITY_CODE_FOR_PHONE.getMessage()); |
| | | } |
| | | |
| | | if(!codeVerify.getSecurityCode().equals(securityCode)) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.SECURITY_CODE_ERROR.getMessage()); |
| | | } |
| | | |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > codeVerify.getExpires() ) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.VALIDATION_TIMEOUT.getMessage()); |
| | | } |
| | | |
| | | // 校验通过,进行登录凭证校验 |
| | | Map<String, Object> queryParams = new HashMap<>(); |
| | | queryParams.put("appid", appid); |
| | | queryParams.put("secret", secret); |
| | | queryParams.put("js_code", code); |
| | | queryParams.put("grant_type", grantType); |
| | | Map<String, String> headerParams = new HashMap<>(); |
| | | JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams); |
| | | |
| | | if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) { |
| | | return BaseResponseUtils.buildFail("登录凭证校验失败"); |
| | | } |
| | | String openid = job.getString("openid"); |
| | | String sessionKey = job.getString("session_key"); |
| | | |
| | | Long clientId = clientSv.getClientIdByPhone(phoneNumber); |
| | | String SessionId = ""; |
| | | if(clientId != null) { |
| | | // 添加微信用户账户记录 |
| | | SeOpenId seOpenId = new SeOpenId(); |
| | | seOpenId.setClientId(clientId); |
| | | seOpenId.setOpenId(openid); |
| | | seOpenId.setSessionKey(sessionKey); |
| | | seOpenId.setCreateTime(new Date()); |
| | | //Long SessionId = clientSv.addOpenId(seOpenId); |
| | | Long rec = clientSv.addOpenId(seOpenId); |
| | | if(rec != null) { |
| | | SessionId = String.valueOf(rec); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(SessionId); |
| | | |
| | | } else { |
| | | return BaseResponseUtils.buildError(SellResultCode.PHONE_NUMBER_IS_ERROR.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取农户基本信息,小程序首页使用 |
| | | * @param sessionId |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/simple_info") |
| | | @SsoAop() |
| | | public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){ |
| | | try { |
| | | VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询农户异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 登录凭证登录 |
| | | * @param code 临时登录凭证 |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/code_login") |
| | | @SsoAop() |
| | | public BaseResponse<VoClientWechat> codeLogin(@RequestParam String code) throws IOException { |
| | | |
| | | // 登录凭证校验 |
| | | Map<String, Object> queryParams = new HashMap<>(); |
| | | queryParams.put("appid", appid); |
| | | queryParams.put("secret", secret); |
| | | queryParams.put("js_code", code); |
| | | queryParams.put("grant_type", grantType); |
| | | Map<String, String> headerParams = new HashMap<>(); |
| | | JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams); |
| | | |
| | | String openId = job.getString("openid"); |
| | | if(openId == null) { |
| | | return BaseResponseUtils.buildFail(SellResultCode.LOGIN_FAIL.getMessage()); |
| | | } |
| | | |
| | | try { |
| | | VoClientWechat res = clientSv.getSimpleClientInfo(null, openId); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询农户异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper; |
| | | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCodeVerifyMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeClient; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeOpenId; |
| | | import com.dy.pipIrrGlobal.voSe.VoClient; |
| | | import com.dy.pipIrrGlobal.voSe.VoClientWechat; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private BaDistrictMapper baDistrictMapper; |
| | | |
| | | @Autowired |
| | | private SeCodeVerifyMapper seCodeVerifyMapper; |
| | | private BaSettingsMapper baSettingsMapper; |
| | | |
| | | @Autowired |
| | | private SeOpenIdMapper seOpenIdMapper; |
| | | |
| | | @Autowired |
| | | private BaSettingsMapper baSettingsMapper; |
| | | |
| | | /** |
| | | * 根据指定条件获取农户数据 |
| | |
| | | return seClientMapper.insertSelective(po); |
| | | } |
| | | |
| | | /** |
| | | * 添加验证码记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Integer addCodeVerify(SeCodeVerify po) { |
| | | return seCodeVerifyMapper.insert(po); |
| | | } |
| | | |
| | | /** |
| | | * 根据手机号获取验证码验证对象 |
| | | * @param phoneNumber |
| | | * @return |
| | | */ |
| | | public SeCodeVerify getCodeVerify(String phoneNumber) { |
| | | return seCodeVerifyMapper.getCodeVerify(phoneNumber); |
| | | } |
| | | /** |
| | | * 根据6位区划串模糊查询农户编号 |
| | | * @param district6 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据配置项获取配置项值 |
| | | * @param itemName |
| | | * @return |
| | | */ |
| | | public String getItemValue(String itemName) { |
| | | return baSettingsMapper.getItemValue(itemName); |
| | | } |
| | | |
| | | /** |
| | | * 根据电话号码获取农户ID |
| | | * @param phoneNumber |
| | | * @return |
| | |
| | | seOpenIdMapper.insert(po); |
| | | //return po.getClientId(); |
| | | return po.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 根据配置项获取配置项值 |
| | | * @param itemName |
| | | * @return |
| | | */ |
| | | public String getItemValue(String itemName) { |
| | | return baSettingsMapper.getItemValue(itemName); |
| | | } |
| | | |
| | | /** |
| | | * 获取农户基本信息,小程序首页使用 |
| | | * @param sessionId |
| | | * @return |
| | | */ |
| | | public VoClientWechat getSimpleClientInfo(Long sessionId, String openId) { |
| | | return seClientMapper.getSimpleClientInfo(sessionId, openId); |
| | | } |
| | | } |
| | |
| | | No_TRADE_SUMMARIES(100001, "没有符合条件的交易汇总记录"), |
| | | No_TRADE_DETAILS(100001, "没有符合条件的交易明细"), |
| | | |
| | | /** |
| | | * 微信用户 |
| | | */ |
| | | PHONE_NUMBER_CANNOT_BE_NULL(20001, "手机号不能为空"), |
| | | SECURITY_CODE_SEND_FAIL(20001, "验证码发送失败"), |
| | | VERIFY_PARAMS_INCOMPLETE(20001, "验证参数不完整"), |
| | | CODE_VERIFY_FAIL(20001, "验证码校验失败"), |
| | | |
| | | NO_SECURITY_CODE_FOR_PHONE(20002, "该手机号未发送验证码"), |
| | | SECURITY_CODE_ERROR(20003, "验证码错误"), |
| | | VALIDATION_TIMEOUT(20004, "验证超时"), |
| | | PHONE_NUMBER_IS_ERROR(20004, "手机号错误,非注册农户"), |
| | | |
| | | /** |
| | | * 小程序 |
| | | */ |
| | | LOGIN_FAIL(20004, "登录失败"); |
| | | PHONE_NUMBER_IS_ERROR(20004, "手机号错误,非注册农户"); |
| | | |
| | | private final Integer code; |
| | | private final String message; |
New file |
| | |
| | | package com.dy.pipIrrWechat.client; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; |
| | | import com.aliyuncs.exceptions.ClientException; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeOpenId; |
| | | import com.dy.pipIrrGlobal.voSe.VoClientWechat; |
| | | import com.dy.pipIrrSell.wechatpay.PayInfo; |
| | | import com.dy.pipIrrWechat.client.dto.CodeLoginDTO; |
| | | import com.dy.pipIrrWechat.client.dto.CodeVerifyDTO; |
| | | import com.dy.pipIrrWechat.result.WechatResultCode; |
| | | import com.dy.pipIrrWechat.sms.AliyunSmsSv; |
| | | import com.dy.pipIrrWechat.sms.RandomCode; |
| | | import com.dy.pipIrrWechat.util.RestTemplateUtil; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.validation.Valid; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-19 14:21 |
| | | * @LastEditTime 2024-06-19 14:21 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "农户数据操作", description = "农户数据操作") |
| | | @RestController |
| | | @RequestMapping(path="client") |
| | | @RequiredArgsConstructor |
| | | public class ClientCtrl { |
| | | private final ClientSv clientSv; |
| | | private final AliyunSmsSv aliyunSmsSv; |
| | | private final RestTemplateUtil restTemplateUtil; |
| | | private final String privateCertFileName = PayInfo.privateCertFileName; |
| | | private final String appid = PayInfo.appid; |
| | | private final String secret = PayInfo.secret; |
| | | private final String mchid = PayInfo.mchid; |
| | | private final String schema = PayInfo.schema; |
| | | private final String signType = PayInfo.signType; |
| | | private final String description = PayInfo.description; |
| | | private final String loginUrl = PayInfo.loginUrl; |
| | | private final String notifyUrl = PayInfo.notifyUrl; |
| | | private final String grantType = PayInfo.grantType; |
| | | |
| | | /** |
| | | * 登录凭证登录 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | @PostMapping(path = "code_login", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | public BaseResponse<JSONObject> codeLogin(@RequestBody @Valid CodeLoginDTO po, BindingResult bindingResult) throws IOException { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | String code = po.getCode(); |
| | | |
| | | // 登录凭证校验 |
| | | Map<String, Object> queryParams = new HashMap<>(); |
| | | queryParams.put("appid", appid); |
| | | queryParams.put("secret", secret); |
| | | queryParams.put("js_code", code); |
| | | queryParams.put("grant_type", grantType); |
| | | Map<String, String> headerParams = new HashMap<>(); |
| | | JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams); |
| | | |
| | | if(job.containsKey("errmsg ")) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.INVALID_CODE.getMessage()); |
| | | } |
| | | |
| | | String openId = job.getString("openid"); |
| | | if(openId == null) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.LOGIN_FAIL.getMessage()); |
| | | } |
| | | |
| | | try { |
| | | JSONObject job_client = new JSONObject(); |
| | | VoClientWechat res = clientSv.getSimpleClientInfo(null, openId); |
| | | if(res != null) { |
| | | job_client.put("client", res); |
| | | } else { |
| | | VoClientWechat voClientWechat = new VoClientWechat(); |
| | | job_client.put("client", voClientWechat); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(job_client); |
| | | } catch (Exception e) { |
| | | log.error("查询农户异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送验证码 |
| | | * @param phoneNumber |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "send_sms") |
| | | public BaseResponse<Boolean> sendSms(@RequestParam(name = "phoneNumber", required = true) String phoneNumber) throws ClientException { |
| | | if(phoneNumber == null || phoneNumber.length() <= 0) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.PHONE_NUMBER_CANNOT_BE_NULL.getMessage()); |
| | | } |
| | | |
| | | // 生成6位验证码并转为Json格式 |
| | | String securityCode = String.valueOf(RandomCode.genCode()); |
| | | JSONObject param = new JSONObject(); |
| | | param.put("code", securityCode); |
| | | String templateParam = param.toJSONString(); |
| | | |
| | | //redisUtils.set(phoneNumber, securityCode, 60); |
| | | |
| | | // 获取当前时间戳并延后3分钟 |
| | | Long timestamp = System.currentTimeMillis(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(timestamp); |
| | | calendar.add(Calendar.SECOND, 180); |
| | | Long expires = calendar.getTimeInMillis(); |
| | | |
| | | SeCodeVerify codeVerify = new SeCodeVerify(); |
| | | codeVerify.setPhoneNumber(phoneNumber); |
| | | codeVerify.setSecurityCode(securityCode); |
| | | codeVerify.setExpires(expires); |
| | | clientSv.addCodeVerify(codeVerify); |
| | | |
| | | SendSmsResponse response = aliyunSmsSv.sendSms(phoneNumber, templateParam); |
| | | if (response.getCode().equals("OK")) { |
| | | // 发送成功处理逻辑 |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } else { |
| | | // 发送失败处理逻辑 |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.SECURITY_CODE_SEND_FAIL.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验验证码 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | @PostMapping(path = "verify", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public BaseResponse<Boolean> verify(@RequestBody @Valid CodeVerifyDTO po, BindingResult bindingResult) throws IOException { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | String phoneNumber = po.getPhoneNumber(); |
| | | String securityCode = po.getSecurityCode(); |
| | | String code = po.getCode(); |
| | | |
| | | // 进行手机号、验证码、过期时间校验 |
| | | SeCodeVerify codeVerify = clientSv.getCodeVerify(phoneNumber); |
| | | if(codeVerify == null) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.NO_SECURITY_CODE_FOR_PHONE.getMessage()); |
| | | } |
| | | |
| | | if(!codeVerify.getSecurityCode().equals(securityCode)) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.SECURITY_CODE_ERROR.getMessage()); |
| | | } |
| | | |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > codeVerify.getExpires() ) { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.VALIDATION_TIMEOUT.getMessage()); |
| | | } |
| | | |
| | | // 校验通过,进行登录凭证校验 |
| | | Map<String, Object> queryParams = new HashMap<>(); |
| | | queryParams.put("appid", appid); |
| | | queryParams.put("secret", secret); |
| | | queryParams.put("js_code", code); |
| | | queryParams.put("grant_type", grantType); |
| | | Map<String, String> headerParams = new HashMap<>(); |
| | | JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams); |
| | | |
| | | if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) { |
| | | return BaseResponseUtils.buildErrorMsg("登录凭证校验失败"); |
| | | } |
| | | String openid = job.getString("openid"); |
| | | String sessionKey = job.getString("session_key"); |
| | | |
| | | Long clientId = clientSv.getClientIdByPhone(phoneNumber); |
| | | String SessionId = ""; |
| | | if(clientId != null) { |
| | | // 添加微信用户账户记录 |
| | | SeOpenId seOpenId = new SeOpenId(); |
| | | seOpenId.setClientId(clientId); |
| | | seOpenId.setOpenId(openid); |
| | | seOpenId.setSessionKey(sessionKey); |
| | | seOpenId.setCreateTime(new Date()); |
| | | //Long SessionId = clientSv.addOpenId(seOpenId); |
| | | Long rec = clientSv.addOpenId(seOpenId); |
| | | if(rec != null) { |
| | | SessionId = String.valueOf(rec); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(SessionId); |
| | | |
| | | } else { |
| | | return BaseResponseUtils.buildErrorMsg(WechatResultCode.PHONE_NUMBER_IS_ERROR.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取农户基本信息,小程序首页使用 |
| | | * @param sessionId |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/simple_info") |
| | | public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){ |
| | | try { |
| | | VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询农户异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrWechat.client; |
| | | |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCodeVerifyMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeOpenId; |
| | | import com.dy.pipIrrGlobal.voSe.VoClientWechat; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-19 14:25 |
| | | * @LastEditTime 2024-06-19 14:25 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class ClientSv { |
| | | @Autowired |
| | | private SeClientMapper seClientMapper; |
| | | @Autowired |
| | | private SeCodeVerifyMapper seCodeVerifyMapper; |
| | | @Autowired |
| | | private SeOpenIdMapper seOpenIdMapper; |
| | | |
| | | /** |
| | | * 根据电话号码获取农户ID |
| | | * @param phoneNumber |
| | | * @return |
| | | */ |
| | | public Long getClientIdByPhone(String phoneNumber) { |
| | | return seClientMapper.getClientIdByPhone(phoneNumber); |
| | | } |
| | | |
| | | /** |
| | | * 添加微信用户账户记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Long addOpenId(SeOpenId po) { |
| | | seOpenIdMapper.insert(po); |
| | | //return po.getClientId(); |
| | | return po.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 添加验证码记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Integer addCodeVerify(SeCodeVerify po) { |
| | | return seCodeVerifyMapper.insert(po); |
| | | } |
| | | |
| | | /** |
| | | * 根据手机号获取验证码验证对象 |
| | | * @param phoneNumber |
| | | * @return |
| | | */ |
| | | public SeCodeVerify getCodeVerify(String phoneNumber) { |
| | | return seCodeVerifyMapper.getCodeVerify(phoneNumber); |
| | | } |
| | | |
| | | /** |
| | | * 获取农户基本信息,小程序首页使用 |
| | | * @param sessionId |
| | | * @return |
| | | */ |
| | | public VoClientWechat getSimpleClientInfo(Long sessionId, String openId) { |
| | | return seClientMapper.getSimpleClientInfo(sessionId, openId); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrWechat.client.dto; |
| | | |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-19 15:57 |
| | | * @LastEditTime 2024-06-19 15:57 |
| | | * @Description |
| | | */ |
| | | |
| | | @Data |
| | | public class CodeLoginDTO { |
| | | /** |
| | | * 临时登录凭证 |
| | | */ |
| | | @NotBlank(message = "临时登录凭证不能为空") |
| | | private String code; |
| | | } |
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/dto/CodeVerifyDTO.java |
| | |
| | | package com.dy.pipIrrSell.client.dto; |
| | | package com.dy.pipIrrWechat.client.dto; |
| | | |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.Data; |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/get") |
| | | @SsoAop() |
| | | //@SsoAop() |
| | | public BaseResponse<List<VoUnclosedValve>> getUnclosedValves(@RequestParam Long operator){ |
| | | try { |
| | | List<VoUnclosedValve> res = commandSv.getUnclosedValves(operator); |
| | |
| | | package com.dy.pipIrrWechat.config; |
| | | |
| | | import com.dy.common.webFilter.DevOfDataSourceNameSetFilter; |
| | | import com.dy.common.webFilter.UserTokenFilter; |
| | | import com.dy.common.webFilter.WXDataSourceNameSetFilter; |
| | | import jakarta.servlet.Filter; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | */ |
| | | @Configuration |
| | | public class WebFilterConfiguration { |
| | | |
| | | @Value("${pipIrr.global.dev}") |
| | | public String isDevStage ;//是否为开发阶段 |
| | | @Value("${pipIrr.global.dsName}") |
| | | public String dsName ;//开发阶段的数据源名称 |
| | | |
| | | /** |
| | | * DevOfDataSourceNameSetFilter与UserTokenFilter只能一个被配置上, |
| | | * 所以他们的order都是1 |
| | | */ |
| | | private static final int order_UserTokenFilter = 1 ;//与下面 |
| | | private static final int order_DevOfDataSourceNameSetFilter = 1 ; |
| | | |
| | | |
| | | @Bean |
| | | public FilterRegistrationBean<? extends Filter> RegFilter() { |
| | | FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>(); |
| | | if(this.isDevStage != null && !this.isDevStage.trim().equals("") && this.isDevStage.trim().equalsIgnoreCase("true")){ |
| | | filterRegistrationBean.setFilter(new DevOfDataSourceNameSetFilter()); |
| | | filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则 |
| | | filterRegistrationBean.addInitParameter("dataSourceName",dsName);//设置init参数 |
| | | filterRegistrationBean.setName("DevOfDataSourceNameSetFilter");//设置过滤器名称 |
| | | filterRegistrationBean.setOrder(order_DevOfDataSourceNameSetFilter);//执行次序 |
| | | }else{ |
| | | filterRegistrationBean.setFilter(new UserTokenFilter()); |
| | | filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则 |
| | | filterRegistrationBean.setName("UserTokenFilter");//设置过滤器名称 |
| | | filterRegistrationBean.setOrder(order_UserTokenFilter);//执行次序 |
| | | } |
| | | filterRegistrationBean.setFilter(new WXDataSourceNameSetFilter()); |
| | | filterRegistrationBean.addUrlPatterns("/*");//配置过滤规则 |
| | | filterRegistrationBean.setName("WXDataSourceNameSetFilter");//设置过滤器名称 |
| | | filterRegistrationBean.setOrder(1);//执行次序 |
| | | |
| | | return filterRegistrationBean; |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.pipIrrWechat.intake; |
| | | |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.voPr.VoOnLineIntake; |
| | | import com.dy.pipIrrWechat.intake.qo.OnLineIntakesQO; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-20 8:37 |
| | | * @LastEditTime 2024-06-20 8:37 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "取水口数据操作", description = "取水口数据操作") |
| | | @RestController |
| | | @RequestMapping(path="intake") |
| | | @RequiredArgsConstructor |
| | | public class IntakeCtrl { |
| | | private final IntakeSv intakeSv; |
| | | |
| | | /** |
| | | * 获取取水口列表(在线和不在线) |
| | | * @param qo |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "all_intakes") |
| | | public BaseResponse<QueryResultVo<List<VoOnLineIntake>>> getAllIntakes(OnLineIntakesQO qo) { |
| | | try { |
| | | QueryResultVo<List<VoOnLineIntake>> res = intakeSv.selectOnLineIntakes(qo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询取水口异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据操作员获取常用取水口(在线和不在线) |
| | | * @param operator |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "used_intakes") |
| | | public BaseResponse<List<VoOnLineIntake>> getUsedIntakes(Long operator) { |
| | | try { |
| | | List<VoOnLineIntake> res = intakeSv.getUsedIntakes(operator); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询取水口异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrWechat.intake; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; |
| | | import com.dy.pipIrrGlobal.voPr.VoOnLineIntake; |
| | | import com.dy.pipIrrWechat.intake.qo.OnLineIntakesQO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.util.UriComponentsBuilder; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-20 8:37 |
| | | * @LastEditTime 2024-06-20 8:37 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class IntakeSv { |
| | | @Autowired |
| | | private PrIntakeMapper prIntakeMapper; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ; |
| | | |
| | | /** |
| | | * 获取取水口列表 |
| | | * @return |
| | | */ |
| | | public QueryResultVo<List<VoOnLineIntake>> selectOnLineIntakes(OnLineIntakesQO qo) { |
| | | Command com = new Command() ; |
| | | com.id = Command.defaultId; |
| | | com.code = "LCD0001"; |
| | | com.type = "innerCommand"; |
| | | |
| | | JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); |
| | | |
| | | if(response != null && response.getString("code").equals("0001")) { |
| | | JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); |
| | | HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); |
| | | |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("rtuAddr", entry.getKey()); |
| | | jsonObject.put("isOnLine", entry.getValue()); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | |
| | | qo.setOnLineMap(jsonArray.toJSONString()); |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ; |
| | | Long itemTotal = prIntakeMapper.getOnLineIntakesCount(params); |
| | | |
| | | QueryResultVo<List<VoOnLineIntake>> rsVo = new QueryResultVo<>() ; |
| | | rsVo.pageSize = qo.pageSize ; |
| | | rsVo.pageCurr = qo.pageCurr ; |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = prIntakeMapper.getOnLineIntakes(params); |
| | | return rsVo; |
| | | } else { |
| | | QueryResultVo<List<VoOnLineIntake>> rsVo = new QueryResultVo<>(); |
| | | return rsVo; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据操作员获取常用取水口 |
| | | * @param operator |
| | | * @return |
| | | */ |
| | | public List<VoOnLineIntake> getUsedIntakes(Long operator) { |
| | | Command com = new Command() ; |
| | | com.id = Command.defaultId; |
| | | com.code = "LCD0001"; |
| | | com.type = "innerCommand"; |
| | | JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com)); |
| | | |
| | | if(response != null && response.getString("code").equals("0001")) { |
| | | JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap"); |
| | | HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class); |
| | | |
| | | JSONArray jsonArray = new JSONArray(); |
| | | for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("rtuAddr", entry.getKey()); |
| | | jsonObject.put("isOnLine", entry.getValue()); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | return prIntakeMapper.getUsedIntakes(jsonArray.toJSONString(), operator); |
| | | } else { |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送命令 |
| | | * @return |
| | | */ |
| | | protected BaseResponse sendCom2Mw(Command com){ |
| | | String url = UriComponentsBuilder.fromUriString(mwUrlSendCom) |
| | | .build() |
| | | .toUriString(); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers); |
| | | ResponseEntity<BaseResponse> response = null; |
| | | try { |
| | | // 通过Post方式调用接口 |
| | | response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return response.getBody(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrWechat.intake.qo; |
| | | |
| | | import com.dy.common.webUtil.QueryConditionVo; |
| | | import jakarta.validation.constraints.Max; |
| | | import jakarta.validation.constraints.Min; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-06-20 8:53 |
| | | * @LastEditTime 2024-06-20 8:53 |
| | | * @Description |
| | | */ |
| | | |
| | | @Data |
| | | public class OnLineIntakesQO extends QueryConditionVo { |
| | | /** |
| | | * 中间件返回的RTU在线情况对象数组 |
| | | */ |
| | | private String onLineMap; |
| | | |
| | | /** |
| | | * 取水口编号 |
| | | */ |
| | | private String intakeNum; |
| | | |
| | | /** |
| | | * 是否在线 |
| | | */ |
| | | @Max(value = 1,message = "是否在线仅允许为真或假") |
| | | @Min(value = 0,message = "是否在线仅允许为真或假") |
| | | private Boolean isOnLine; |
| | | } |
| | |
| | | /** |
| | | * RTU |
| | | */ |
| | | RTU_NOT_EXIST(20001, "阀控器不存在"); |
| | | RTU_NOT_EXIST(20001, "阀控器不存在"), |
| | | //RTU_ADDR_CANNOT_BE_NULL(20002, "阀控器地址不能为空"); |
| | | |
| | | /** |
| | | * 微信用户 |
| | | */ |
| | | PHONE_NUMBER_CANNOT_BE_NULL(20001, "手机号不能为空"), |
| | | SECURITY_CODE_SEND_FAIL(20001, "验证码发送失败"), |
| | | VERIFY_PARAMS_INCOMPLETE(20001, "验证参数不完整"), |
| | | CODE_VERIFY_FAIL(20001, "验证码校验失败"), |
| | | |
| | | NO_SECURITY_CODE_FOR_PHONE(20002, "该手机号未发送验证码"), |
| | | SECURITY_CODE_ERROR(20003, "验证码错误"), |
| | | VALIDATION_TIMEOUT(20004, "验证超时"), |
| | | PHONE_NUMBER_IS_ERROR(20004, "手机号错误,非注册农户"), |
| | | INVALID_CODE(20004, "无效的临时登录凭证"), |
| | | LOGIN_FAIL(20004, "登录失败"); |
| | | |
| | | private final Integer code; |
| | | private final String message; |
| | | } |
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/AliyunSmsSv.java |
| | |
| | | package com.dy.pipIrrSell.sms; |
| | | package com.dy.pipIrrWechat.sms; |
| | | |
| | | import com.aliyuncs.DefaultAcsClient; |
| | | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; |
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/sms/RandomCode.java |
| | |
| | | package com.dy.pipIrrSell.sms; |
| | | package com.dy.pipIrrWechat.sms; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
New file |
| | |
| | | package com.dy.pipIrrWechat.util; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-03-06 13:47 |
| | | * @LastEditTime 2024-03-06 13:47 |
| | | * @Description |
| | | */ |
| | | |
| | | @Component |
| | | public class RestTemplateUtil { |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | //@Qualifier("RestTemplateWithCert") |
| | | //@Resource |
| | | //private RestTemplate restTemplate; |
| | | |
| | | public JSONObject get(String url, Map<String, Object> queryParams) throws IOException { |
| | | return get(url, queryParams, new HashMap<>(1)); |
| | | } |
| | | |
| | | public JSONObject get(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException { |
| | | String tempUrl = setParamsByAppendUrl(queryParams, url); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headerParams.forEach(headers::add); |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class); |
| | | return JSONObject.parseObject(response.getBody()); |
| | | } |
| | | |
| | | public JSONObject getHeaders(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException { |
| | | String tempUrl = setParamsByAppendUrl(queryParams, url); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headerParams.forEach(headers::add); |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("headers", response.getHeaders()); |
| | | jsonObject.put("body", response.getBody()); |
| | | return jsonObject; |
| | | } |
| | | |
| | | public JSONObject get2(String url, Map<String, Object> queryParams, Map<String, String> headerParams) throws IOException { |
| | | String tempUrl = setParamsByPath(queryParams, url); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headerParams.forEach(headers::add); |
| | | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(null, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(tempUrl, HttpMethod.GET, httpEntity, String.class, queryParams); |
| | | return JSONObject.parseObject(response.getBody()); |
| | | } |
| | | |
| | | public JSONObject post(String url, String json, Map<String, String> headerParams) { |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headerParams.forEach(headers::add); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | headers.add("Accept", MediaType.APPLICATION_JSON.toString()); |
| | | HttpEntity<String> httpEntity = new HttpEntity<>(json, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); |
| | | return JSONObject.parseObject(response.getBody()); |
| | | } |
| | | |
| | | private String setParamsByPath(Map<String, Object> queryParams, String url) { |
| | | // url?id={id}&name={name} |
| | | if (queryParams == null || queryParams.isEmpty()) { |
| | | return url; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | try { |
| | | for (Map.Entry<String, Object> entry : queryParams.entrySet()) { |
| | | sb.append("&").append(entry.getKey()).append("=").append("{").append(entry.getKey()).append("}"); |
| | | } |
| | | if (!url.contains("?")) { |
| | | sb.deleteCharAt(0).insert(0, "?"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return url + sb; |
| | | } |
| | | |
| | | private String setParamsByAppendUrl(Map<String, Object> queryParams, String url) { |
| | | // url?id=1&name=zzc |
| | | if (queryParams == null || queryParams.isEmpty()) { |
| | | return url; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | try { |
| | | for (Map.Entry<String, Object> entry : queryParams.entrySet()) { |
| | | sb.append("&").append(entry.getKey()).append("="); |
| | | sb.append(entry.getValue()); |
| | | } |
| | | if (!url.contains("?")) { |
| | | sb.deleteCharAt(0).insert(0, "?"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return url + sb; |
| | | } |
| | | |
| | | } |
| | |
| | | idSuffix: ${pipIrr.wechat.idSuffix} |
| | | #ConfigListener中应用 |
| | | #configFileNames: config-global.xml,config-demo.xml |
| | | #阿里短信服务 |
| | | aliyun: |
| | | sms: |
| | | sms-access-key-id: LTAI5tPCmHqfyJ9YnoPorEwt |
| | | sms-access-key-secret: sU2CoLdNgcjnf5uPPU2dY7NNGNvOIX |
| | | sms-template-code: SMS_460776024 |
| | | sms-sign-name: 大禹节水 |