Administrator
2024-06-20 57f9815260b6d23c5a626efa9f75fb2ead989da6
2024-06-20 朱宝民 迁移2个微信小程序接口
1个文件已修改
3个文件已添加
244 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -8,8 +8,6 @@
import com.dy.pipIrrGlobal.pojoBa.BaClient;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.voSe.VoClient;
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;
@@ -42,18 +40,6 @@
public class ClientCtrl {
    private final ClientSv clientSv;
    //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;
    /**
     * 获取农户列表
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
New file
@@ -0,0 +1,63 @@
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());
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
New file
@@ -0,0 +1,134 @@
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();
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/qo/OnLineIntakesQO.java
New file
@@ -0,0 +1,33 @@
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;
}