zuojincheng
7 天以前 169efb6680990457812e24fe038c9d251fac4ec3
feat(card): 添加创建管理卡功能并优化卡片地址校验

- 在 CardCtrl 中添加 createManagementCard 方法,实现创建管理卡的功能- 在 SeClientCardMapper 中添加 checkCardAddrExists 方法,用于检查卡片地址是否存在
- 优化了卡片地址存在性校验逻辑,排除了已挂失的卡片- 新增 CreateManagementCardDto 类,用于创建管理卡的请求参数
4个文件已修改
1个文件已添加
481 ■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientCardMapper.java 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientCardMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardCtrl.java 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java 192 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/dto/CreateManagementCardDto.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientCardMapper.java
@@ -35,6 +35,7 @@
    /**
     * 依据水卡地址获取水卡编号(12月19日废弃)
     * 2024-06-30取消废弃,恢复使用
     *
     * @param cardAddr
     * @return
     */
@@ -42,6 +43,7 @@
    /**
     * 根据水卡编号获取水卡表主键(12月19日添加后废弃)
     *
     * @param cardNum 16位水卡编号
     * @return 水卡表主键
     */
@@ -49,6 +51,7 @@
    /**
     * 根据行政区划串模块查询水卡编号
     *
     * @param areaCode
     * @return
     */
@@ -56,6 +59,7 @@
    /**
     * 根据水卡编号获取水卡表主键及农户编号
     *
     * @param cardNum
     * @return
     */
@@ -63,6 +67,7 @@
    /**
     * 根据水卡编号获取水卡对应的农户id和姓名
     *
     * @param cardAddr
     * @param cardNum
     * @return
@@ -71,6 +76,7 @@
    /**
     * 得到水卡对象
     *
     * @param cardAddr
     * @param cardNum
     * @return
@@ -79,6 +85,7 @@
    /**
     * 根据农户主键获取水卡列表(物理卡+虚拟卡)
     *
     * @param clientId
     * @return
     */
@@ -86,6 +93,7 @@
    /**
     * 根据水卡编号获取操作记录列表
     *
     * @param cardNum 水卡编号
     * @return 水卡操作记录列表
     */
@@ -93,6 +101,7 @@
    /**
     * 根据水卡编号获取余额
     *
     * @param cardNum 水卡编号
     * @return 余额
     */
@@ -100,6 +109,7 @@
    /**
     * 根据水卡编号获取充值总额
     *
     * @param cardNum
     * @return
     */
@@ -107,6 +117,7 @@
    /**
     * 根据水卡编号获取卡片状态
     *
     * @param cardNum
     * @return
     */
@@ -114,6 +125,7 @@
    /**
     * 根据指定条件获取水卡列表记录数,应用程序使用
     *
     * @param params
     * @return
     */
@@ -121,6 +133,7 @@
    /**
     * 根据指定条件获取水卡列表,应用程序使用
     *
     * @param params
     * @return
     */
@@ -128,18 +141,21 @@
    /**
     * 获取已挂失,未补卡的记录数量,应用程序使用
     *
     * @return
     */
    Long getUnreplacedRecordCount();
    /**
     * 获取已挂失,未补卡的记录,应用程序使用
     *
     * @return
     */
    List<VoCards> getUnreplaced(Map<?, ?> params);
    /**
     * 根据指定水卡编号获取挂失记录数量(补卡、解锁使用)
     *
     * @param cardNum
     * @return
     */
@@ -147,6 +163,7 @@
    /**
     * 根据指定水卡编号获取已补卡数量(补卡、解锁使用)
     *
     * @param cardNum 水卡编号
     * @return 符合条件记录数,最多一条
     */
@@ -154,6 +171,7 @@
    /**
     * 根据农户姓名和手机号获取水卡列表记录数,应用程序使用
     *
     * @param params
     * @return
     */
@@ -161,14 +179,15 @@
    /**
     * 根据农户姓名和手机号获取水卡列表,应用程序使用
     *
     * @param params
     * @return
     */
    List<VoCards2> getCardsByClientNameAndPhone(Map<?, ?> params);
    /**
     * 根据农户ID查询正常状态的水卡列表,小程序使用
     *
     * @param clientId
     * @return
     */
@@ -176,13 +195,15 @@
    /**
     * 更新实体卡剩余金额
     *
     * @param id
     * @param money
     */
    void updateMoney(@Param("id")Long id , @Param("money")Double money);
    void updateMoney(@Param("id") Long id, @Param("money") Double money);
    /**
     *当前余额总量(物理卡)
     * 当前余额总量(物理卡)
     *
     * @param
     * @return
     */
@@ -190,6 +211,7 @@
    /**
     * 根据水卡地址获取水卡数量,用来判断该卡是否允许开卡,无效卡片排除在外
     *
     * @param cardAddr
     * @return
     */
@@ -197,14 +219,15 @@
    /**
     * 根据水卡地址获取指定状态的水卡数量,用来判断该卡是否允许开卡
     *
     * @param cardAddr
     * @return
     */
    Long getCountByCardAddrAndState(String cardAddr);
    /**
     * 获取指定时间段水卡使用情况记录数量
     *
     * @param params
     * @return
     */
@@ -212,6 +235,7 @@
    /**
     * 获取指定时间段水卡使用情况:充值合计、消费合计、余额
     *
     * @param params
     * @return
     */
@@ -219,37 +243,42 @@
    /**
     * 获取指定时间段内水卡充值总计
     *
     * @param timeStart
     * @param timeStop
     * @return
     */
    Float getTotalRecharge(@Param("timeStart")String timeStart, @Param("timeStop")String timeStop);
    Float getTotalRecharge(@Param("timeStart") String timeStart, @Param("timeStop") String timeStop);
    /**
     * 获取指定时间段内水卡消费总计
     *
     * @param timeStart
     * @param timeStop
     * @return
     */
    Float getTotalConsumption(@Param("timeStart")String timeStart, @Param("timeStop")String timeStop);
    Float getTotalConsumption(@Param("timeStart") String timeStart, @Param("timeStop") String timeStop);
    /**
     * 依据水卡地址将最后一条无效状态的指定操作记录改为有效
     *
     * @param cardAddr
     * @param operateType
     * @return
     */
    Integer turnCardValidByAddr(@Param("cardAddr")String cardAddr, @Param("operateType")Integer operateType);
    Integer turnCardValidByAddr(@Param("cardAddr") String cardAddr, @Param("operateType") Integer operateType);
    /**
     * 充值机用根据订单号将水卡改为有效
     *
     * @param orderNumber
     * @return
     */
    Integer turnCardValidByOrderNumber(@Param("orderNumber")String orderNumber);
    Integer turnCardValidByOrderNumber(@Param("orderNumber") String orderNumber);
    /**
     * 根据水卡ID获取原水卡ID,补卡通知中使用
     *
     * @param cardId
     * @return
     */
@@ -257,20 +286,23 @@
    /**
     * 充值机用根据补卡的订单号将挂失水卡余额置零
     *
     * @param orderNumber
     * @return
     */
    Integer emptyCardBalance(@Param("orderNumber")String orderNumber);
    Integer emptyCardBalance(@Param("orderNumber") String orderNumber);
    /**
     * 充值机用获取农户水卡信息
     *
     * @param cardAddr
     * @return
     */
    VoTermCard getTermCardInfo(@Param("cardAddr")String cardAddr);
    VoTermCard getTermCardInfo(@Param("cardAddr") String cardAddr);
    /**
     * 获取已挂失水卡列表记录数量
     *
     * @param params
     * @return
     */
@@ -278,6 +310,7 @@
    /**
     * 获取已挂失水卡列表
     *
     * @param params
     * @return
     */
@@ -285,8 +318,17 @@
    /**
     * 根据水卡编号获取卡信息
     *
     * @param cardNum
     * @return
     */
    VoCardByClientNum getCardByCardNum(@Param("cardNum") String cardNum);
    /**
     * 检查卡地址是否已存在(管理卡表 + 农户水卡表)
     *
     * @param cardAddr 卡地址
     * @return 存在的记录数量
     */
    Long checkCardAddrExists(@Param("cardAddr") String cardAddr);
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientCardMapper.xml
@@ -864,4 +864,20 @@
    ORDER BY card.createDt DESC
    LIMIT 1
  </select>
  <!--检查卡地址是否已存在(管理卡表 + 农户水卡表)-->
  <select id="checkCardAddrExists" resultType="java.lang.Long">
    SELECT COUNT(*) AS totalCount FROM (
      -- 检查管理卡表中的所有记录
      SELECT card_addr FROM se_management_card
      WHERE card_addr = #{cardAddr}
      UNION ALL
      -- 检查农户水卡表中正常(1)和挂失(3)状态的记录
      SELECT cardAddr FROM se_client_card
      WHERE cardAddr = #{cardAddr}
        AND state IN (1, 3)
    ) AS combined_result
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardCtrl.java
@@ -48,9 +48,11 @@
     */
    @PostMapping(path = "termActiveCard", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoTermActiveCard> termActiveCard(@RequestBody @Valid ActiveCard po, BindingResult bindingResult) {
    public BaseResponse<VoTermActiveCard> termActiveCard(@RequestBody @Valid ActiveCard po,
            BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.activeOrReissueTermCard(po);
@@ -72,7 +74,8 @@
    @SsoAop()
    public BaseResponse<VoTermCommon> termRecharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.addRecharge(po, null);
@@ -94,7 +97,8 @@
    @SsoAop()
    public BaseResponse<Boolean> termReportLoss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.reportLoss(po);
@@ -116,7 +120,8 @@
    @SsoAop()
    public BaseResponse<Boolean> termUnlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.unlock(po);
@@ -138,7 +143,8 @@
    @SsoAop()
    public BaseResponse<VoTermCommon> termReissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.reissue(po);
@@ -160,7 +166,8 @@
    @SsoAop()
    public BaseResponse<VoTermCommon> termCancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.cancel(po);
@@ -173,22 +180,25 @@
    /**
     * 补扣
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "termRepay", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoRepaySupplement> termRepay(@RequestBody @Valid DtoRepaySupplement po, BindingResult bindingResult) {
    public BaseResponse<VoRepaySupplement> termRepay(@RequestBody @Valid DtoRepaySupplement po,
            BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(po.getRepayMorny()  == null || po.getRepayMorny() <= 0) {
        if (po.getRepayMorny() == null || po.getRepayMorny() <= 0) {
            return BaseResponseUtils.buildErrorMsg("补扣金额不能为空且需大于0");
        }
        if(po.getRepayMorny() > po.getBalance()) {
        if (po.getRepayMorny() > po.getBalance()) {
            return BaseResponseUtils.buildErrorMsg("补扣金额不能大于补扣前余额");
        }
@@ -201,18 +211,21 @@
    /**
     * 返还
     *
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "supplement", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<VoRepaySupplement> supplement(@RequestBody @Valid DtoRepaySupplement po, BindingResult bindingResult) {
    public BaseResponse<VoRepaySupplement> supplement(@RequestBody @Valid DtoRepaySupplement po,
            BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(po.getSupplementMoney() == null || po.getSupplementMoney() <= 0) {
        if (po.getSupplementMoney() == null || po.getSupplementMoney() <= 0) {
            return BaseResponseUtils.buildErrorMsg("返还金额不能为空且需大于0");
        }
@@ -234,7 +247,8 @@
    @SsoAop()
    public BaseResponse<Boolean> termCallBack(@RequestBody @Valid DtoCallBack po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        Map map_result = cardSv.callBack(po);
@@ -246,93 +260,85 @@
    /**
     * 读取卡信息
     *
     * @param cardAddr
     * @return
     */
    @GetMapping(path = "readCard")
    @SsoAop()
    public BaseResponse<VoTermCard> readCard(@RequestParam String cardAddr){
    public BaseResponse<VoTermCard> readCard(@RequestParam String cardAddr) {
        try {
            VoTermCard voTermCard = cardSv.readCard(cardAddr);
            if(voTermCard == null) {
            if (voTermCard == null) {
                return BaseResponseUtils.buildNonExist();
            }
            return BaseResponseUtils.buildSuccess(voTermCard);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 根据指定条件获取水卡列表,终端应用程序使用
     *
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页水卡记录", description = "返回一页水卡数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页水卡数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCards.class))}
            )
            @ApiResponse(responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, description = "返回一页水卡数据(BaseResponse.content:QueryResultVo[{}])", content = {
                    @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = VoCards.class)) })
    })
    @GetMapping(path = "getcards")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoCards>>> getcards(QoCards vo){
    public BaseResponse<QueryResultVo<List<VoCards>>> getcards(QoCards vo) {
        try {
            QueryResultVo<List<VoCards>> res = cardSv.getCards(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询水卡异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 获取已挂失的水卡列表,终端应用程序使用
     *
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页已挂失水卡记录", description = "返回一页已挂失水卡数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页已挂失水卡数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCards.class))}
            )
            @ApiResponse(responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, description = "返回一页已挂失水卡数据(BaseResponse.content:QueryResultVo[{}])", content = {
                    @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = VoCards.class)) })
    })
    @GetMapping(path = "getlostcards")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoCards>>> getLostCards(QoLostCards vo){
    public BaseResponse<QueryResultVo<List<VoCards>>> getLostCards(QoLostCards vo) {
        try {
            QueryResultVo<List<VoCards>> res = cardSv.getLostCards(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询已挂失水卡异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 根据水卡编号获取卡信息
     *
     * @param cardNum 水卡编号
     * @return
     */
    @Operation(summary = "根据水卡编号获取卡信息", description = "根据水卡编号获取对应的卡信息")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回卡信息(BaseResponse.content:VoCardByClientNum)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = VoCardByClientNum.class))}
            )
            @ApiResponse(responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, description = "返回卡信息(BaseResponse.content:VoCardByClientNum)", content = {
                    @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = VoCardByClientNum.class)) })
    })
    @GetMapping(path = "getcardbycardnum")
    @SsoAop()
    public BaseResponse<VoCardByClientNum> getCardByCardNum(@RequestParam String cardNum){
    public BaseResponse<VoCardByClientNum> getCardByCardNum(@RequestParam String cardNum) {
        try {
            VoCardByClientNum res = cardSv.getCardByCardNum(cardNum);
            if (res == null) {
@@ -341,7 +347,46 @@
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("根据水卡编号查询卡信息异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
    /**
     * 创建管理卡
     *
     * @param dto           创建管理卡参数
     * @param bindingResult 参数验证结果
     * @return 创建结果
     */
    @Operation(summary = "创建管理卡", description = "创建充值机用管理卡")
    @ApiResponses(value = {
            @ApiResponse(responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, description = "创建成功,返回订单号", content = {
                    @Content(mediaType = MediaType.APPLICATION_JSON_VALUE) })
    })
    @PostMapping(path = "createManagementCard", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<String> createManagementCard(@RequestBody @Valid CreateManagementCardDto dto,
            BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        // 验证卡片类型是否在允许范围内
        if (dto.getCardType() < 2 || dto.getCardType() > 10) {
            return BaseResponseUtils.buildErrorMsg("卡片类型必须在2-10之间");
        }
        // 检查卡片地址是否已存在
        if (cardSv.isCardAddrExists(dto.getCardAddr())) {
            return BaseResponseUtils.buildErrorMsg("该卡片地址已存在,请使用其他地址");
        }
        Map<String, Object> result = cardSv.createManagementCard(dto);
        if ((Boolean) result.get("success")) {
            return BaseResponseUtils.buildSuccess((String) result.get("content"));
        } else {
            return BaseResponseUtils.buildErrorMsg(result.get("msg").toString());
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java
@@ -6,6 +6,7 @@
import com.dy.pipIrrGlobal.daoSe.*;
import com.dy.pipIrrGlobal.pojoSe.SeCardOperate;
import com.dy.pipIrrGlobal.pojoSe.SeClientCard;
import com.dy.pipIrrGlobal.pojoSe.SeManagementCard;
import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory;
import com.dy.pipIrrGlobal.voSe.*;
import com.dy.pipIrrTerminal.card.dto.*;
@@ -54,11 +55,15 @@
    @Autowired
    private SeManagerCardMapper seManagerCardMapper;
    @Autowired
    private SeManagementCardMapper seManagementCardMapper;
    @Value("${project.projectNo}")
    private Integer projectNo;
    /**
     * 根据水卡地址判断该卡是否可以开卡
     *
     * @param cardAddr
     * @return true:可以开卡
     */
@@ -80,6 +85,7 @@
    /**
     * 根据水卡编号判断该卡是否可以充值
     *
     * @param po
     * @return true:可以充值
     */
@@ -90,7 +96,7 @@
        String stateName = Optional.ofNullable(seClientCardMapper.getCardStateByCardNum(po.getCardNum())).orElse("");
        // 单独充值时卡片必须为正常
        if((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("正常")) {
        if ((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("正常")) {
            map.put("msg", stateName + ", " + "水卡状态不支持当前操作");
            return map;
        }
@@ -101,6 +107,7 @@
    /**
     * 根据水卡编号判断该卡是否可以挂失
     *
     * @param po
     * @return true:可以报失
     */
@@ -111,7 +118,7 @@
        Long cardNum = po.getCardNum();
        String stateName = seClientCardMapper.getCardStateByCardNum(cardNum);
        if(stateName == null || stateName.equals("") || !stateName.equals("正常")) {
        if (stateName == null || stateName.equals("") || !stateName.equals("正常")) {
            map.put("msg", stateName + ", " + "水卡状态不支持当前操作");
            return map;
        }
@@ -127,7 +134,7 @@
        CardSimple card = new CardSimple();
        card.setCardId(Long.parseLong(map_card.get("cardId").toString()));
        card.setClientId(Long.parseLong(map_card.get("clientId").toString()));
        //card.setProtocol(map_card.get("protocol").toString());
        // card.setProtocol(map_card.get("protocol").toString());
        map.put("success", true);
        map.put("content", card);
@@ -136,6 +143,7 @@
    /**
     * 根据水卡编号判断该卡是否可以解锁
     *
     * @param po
     * @return
     */
@@ -167,8 +175,10 @@
        map.put("content", card);
        return map;
    }
    /**
     * 根据水卡编号判断该卡是否可以补卡
     *
     * @param po
     * @return true:可以补卡
     */
@@ -180,7 +190,7 @@
        Long cardNum = po.getCardNum();
        Integer lostCount = seClientCardMapper.getLostCount(cardNum);
        Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum);
        if(lostCount == 0 || replacedCount > 0) {
        if (lostCount == 0 || replacedCount > 0) {
            map.put("msg", "水卡未挂失或已补卡,不能补卡");
            return map;
        }
@@ -212,6 +222,7 @@
    /**
     * 根据水卡编号判断该卡是否可以注销
     *
     * @param po
     * @return
     */
@@ -222,7 +233,7 @@
        Long cardNum = po.getCardNum();
        String stateName = seClientCardMapper.getCardStateByCardNum(cardNum);
        if(stateName == null || stateName.equals("") || !stateName.equals("正常")) {
        if (stateName == null || stateName.equals("") || !stateName.equals("正常")) {
            map.put("msg", stateName + ", " + "水卡状态不支持当前操作");
            return map;
        }
@@ -246,6 +257,7 @@
    /**
     * 根据水卡编号判断该卡是否可以补扣
     *
     * @param po
     * @return
     */
@@ -256,7 +268,7 @@
        Long cardNum = po.getCardNum();
        String stateName = seClientCardMapper.getCardStateByCardNum(cardNum);
        if(stateName == null || stateName.equals("") || !stateName.equals("正常")) {
        if (stateName == null || stateName.equals("") || !stateName.equals("正常")) {
            map.put("msg", stateName + ", " + "水卡状态不支持当前操作");
            return map;
        }
@@ -280,6 +292,7 @@
    /**
     * 根据水卡编号判断该卡是否可以返还
     *
     * @param po
     * @return
     */
@@ -290,7 +303,7 @@
        Long cardNum = po.getCardNum();
        String stateName = seClientCardMapper.getCardStateByCardNum(cardNum);
        if(stateName == null || stateName.equals("") || !stateName.equals("正常")) {
        if (stateName == null || stateName.equals("") || !stateName.equals("正常")) {
            map.put("msg", stateName + ", " + "水卡状态不支持当前操作");
            return map;
        }
@@ -314,6 +327,7 @@
    /**
     * 根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用
     *
     * @param clientId
     * @return
     */
@@ -435,6 +449,7 @@
    /**
     * 开卡附加充值
     *
     * @param po
     * @param cardNum
     * @return
@@ -468,6 +483,7 @@
    /**
     * 激活或补卡
     *
     * @param po
     * @return
     */
@@ -485,7 +501,7 @@
        }
        Map map_cardNum = generateCardNum(po.getClientId());
        if(map_cardNum.get("success").equals(false)) {
        if (map_cardNum.get("success").equals(false)) {
            map.put("msg", map_cardNum.get("msg").toString());
            return map;
        }
@@ -493,14 +509,14 @@
        String orderNo = generateOrderNo();
        Map map_addCardAndOperate = addCardAndOperate(po, cardNum, orderNo);
        if(map_addCardAndOperate.get("success").equals(false)) {
        if (map_addCardAndOperate.get("success").equals(false)) {
            map.put("msg", map_addCardAndOperate.get("msg").toString());
            return map;
        }
        if (amount != null && amount > 0 && originalCardId == null) {
            Map map_plusRecharge = plusRecharge(po, cardNum, orderNo);
            if(map_plusRecharge.get("success").equals(false)) {
            if (map_plusRecharge.get("success").equals(false)) {
                map.put("msg", map_plusRecharge.get("msg").toString());
                return map;
            }
@@ -525,6 +541,7 @@
    /**
     * 充值
     *
     * @param po
     * @return
     */
@@ -535,7 +552,7 @@
        map.put("content", null);
        Map map_canRecharge = canRecharge(po);
        if(map_canRecharge.get("success").equals(false)) {
        if (map_canRecharge.get("success").equals(false)) {
            map.put("msg", map_canRecharge.get("msg").toString());
            return map;
        }
@@ -550,7 +567,7 @@
        }
        Long cardId = Long.parseLong(map_cardAndClient.get("cardId").toString());
        Long clientId = Long.parseLong(map_cardAndClient.get("clientId").toString());
        if(orderNo == null || orderNo.length() <= 0) {
        if (orderNo == null || orderNo.length() <= 0) {
            orderNo = generateOrderNo();
        }
@@ -617,6 +634,7 @@
    /**
     * 补卡
     *
     * @param po
     * @return
     */
@@ -627,7 +645,7 @@
        map.put("content", null);
        Map map_canReissue = canReissue(po);
        if(map_canReissue.get("success").equals(false)) {
        if (map_canReissue.get("success").equals(false)) {
            map.put("msg", map_canReissue.get("msg").toString());
            return map;
        }
@@ -661,6 +679,7 @@
    /**
     * 挂失
     *
     * @param po
     * @return
     */
@@ -671,7 +690,7 @@
        map.put("content", null);
        Map map_canReportLoss = canReportLoss(po);
        if(map_canReportLoss.get("success").equals(false)) {
        if (map_canReportLoss.get("success").equals(false)) {
            map.put("msg", map_canReportLoss.get("msg").toString());
            return map;
        }
@@ -688,7 +707,8 @@
        seClientCard.setLossdtdt(new Date());
        seClientCard.setState(CardStateENUM.LOSS.getCode());
        seClientCard.setLastoper(LastOperateENUM.LOSS.getCode());
        Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0);
        Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard))
                .orElse(0);
        if (rec_updateClientCard == 0) {
            map.put("msg", "挂失失败-农户卡修改异常");
            return map;
@@ -718,6 +738,7 @@
    /**
     * 解锁
     *
     * @param po
     * @return
     */
@@ -728,7 +749,7 @@
        map.put("content", null);
        Map map_canUnlock = canUnlock(po);
        if(map_canUnlock.get("success").equals(false)) {
        if (map_canUnlock.get("success").equals(false)) {
            map.put("msg", map_canUnlock.get("msg").toString());
            return map;
        }
@@ -738,8 +759,8 @@
        /**
         * 修改农户卡信息:
         *      挂失时间
         *      最后操作类型-4
         * 挂失时间
         * 最后操作类型-4
         */
        SeClientCard seClientCard = new SeClientCard();
        seClientCard.setId(cardId);
@@ -747,7 +768,8 @@
        seClientCard.setMoney(po.getMoney());
        seClientCard.setState(CardStateENUM.NORMAL.getCode());
        seClientCard.setLastoper(LastOperateENUM.UNLOCK.getCode());
        Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0);
        Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard))
                .orElse(0);
        if (rec_updateClientCard == 0) {
            map.put("msg", "解锁失败-农户卡修改异常");
            return map;
@@ -779,6 +801,7 @@
    /**
     * 销卡
     *
     * @param po
     * @return
     */
@@ -789,8 +812,8 @@
        map.put("content", null);
        String orderNo = generateOrderNo();
        Map map_canCancel  = canCancel(po);
        if(map_canCancel.get("success").equals(false)) {
        Map map_canCancel = canCancel(po);
        if (map_canCancel.get("success").equals(false)) {
            map.put("msg", map_canCancel.get("msg").toString());
            return map;
        }
@@ -828,6 +851,7 @@
    /**
     * 补扣
     *
     * @param po
     * @return
     */
@@ -840,8 +864,8 @@
        Date operateTime = new Date();
        Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0);
        Map map_canRepay  = canRepay(po);
        if(map_canRepay.get("success").equals(false)) {
        Map map_canRepay = canRepay(po);
        if (map_canRepay.get("success").equals(false)) {
            map.put("msg", map_canRepay.get("msg").toString());
            return map;
        }
@@ -880,6 +904,7 @@
    /**
     * 返还
     *
     * @param po
     * @return
     */
@@ -892,8 +917,8 @@
        Date operateTime = new Date();
        Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0);
        Map map_canSupplement  = canSupplement(po);
        if(map_canSupplement.get("success").equals(false)) {
        Map map_canSupplement = canSupplement(po);
        if (map_canSupplement.get("success").equals(false)) {
            map.put("msg", map_canSupplement.get("msg").toString());
            return map;
        }
@@ -931,6 +956,7 @@
    /**
     * 操作回调
     *
     * @param po
     * @return
     */
@@ -950,15 +976,15 @@
            return map;
        }
        if(operateType == 1) {
        if (operateType == 1) {
            /**
             * 开卡操作执行通知
             *  1.依据订单号将无效状态的操作记录改为有效
             *  2.依据水卡ID将无效状态的水卡记录改为有效
             *  3.如果开卡同步充值
             *      修改充值操作记录为有效
             *      修改充值历史记录为有效
             *      修改水卡表的操作信息
             * 1.依据订单号将无效状态的操作记录改为有效
             * 2.依据水卡ID将无效状态的水卡记录改为有效
             * 3.如果开卡同步充值
             * 修改充值操作记录为有效
             * 修改充值历史记录为有效
             * 修改水卡表的操作信息
             */
            Integer rec_ope = turnOperateValidByOrderNumber(orderNumber);
            Integer rec_card = turnCardValidByOrderNumber(orderNumber);
@@ -967,10 +993,10 @@
                return map;
            }
            if(isMergeRecharge(cardId)) {
            if (isMergeRecharge(cardId)) {
                turnOperateValidByOrderNumber(orderNumber + "p");
                turnRechargeHistoryValidByOrderNumber(orderNumber);
                updateCard(cardId, orderNumber+"p");
                updateCard(cardId, orderNumber + "p");
            }
        } else if (operateType == 2) {
            /**
@@ -981,8 +1007,8 @@
             */
            turnOperateValidByOrderNumber(orderNumber + "p");
            turnRechargeHistoryValidByOrderNumber(orderNumber);
            updateCard(cardId, orderNumber+"p");
        }else if (operateType == 3) {
            updateCard(cardId, orderNumber + "p");
        } else if (operateType == 3) {
            /**
             * 销卡操作执行通知
             * 1. 操作记录改为有效
@@ -1002,7 +1028,7 @@
             * 1. 新水卡记录改为有效
             * 2. 开卡操作记录改为有效
             * 3. 如果存在退还金额
             *     清空原卡余额
             * 清空原卡余额
             */
            Integer rec_card = turnCardValidByOrderNumber(orderNumber);
            Integer rec_ope = turnOperateValidByOrderNumber(orderNumber);
@@ -1084,12 +1110,13 @@
    /**
     * 如果补卡时退还了金额,清空挂失卡余额
     *
     * @param orderNumber
     */
    public Integer emptyCardBalance(String orderNumber) {
        Integer rec_empty = 0;
        Float noTradeAmount = seCardOperateMapper.getNoTradeAmount(orderNumber);
        if(noTradeAmount != null && noTradeAmount > 0) {
        if (noTradeAmount != null && noTradeAmount > 0) {
            rec_empty = seClientCardMapper.emptyCardBalance(orderNumber);
        }
        return rec_empty;
@@ -1097,6 +1124,7 @@
    /**
     * 修改注销水卡表的记录及余额(0)
     *
     * @param orderNumber
     * @return
     */
@@ -1114,6 +1142,7 @@
    /**
     * 修改补扣水卡表记录及余额
     *
     * @param cardId
     * @param orderNumber
     * @return
@@ -1135,6 +1164,7 @@
    /**
     * 修改返还水卡表记录及余额
     *
     * @param cardId
     * @param orderNumber
     * @return
@@ -1156,6 +1186,7 @@
    /**
     * 判断指定水卡是否为挂失状态且无补卡记录
     *
     * @param cardNum
     * @return
     */
@@ -1170,17 +1201,18 @@
    /**
     * 读取水卡信息
     *
     * @param cardAddr
     * @return
     */
    public VoTermCard readCard(String cardAddr) {
        VoTermCard voTermCard = seClientCardMapper.getTermCardInfo(cardAddr);
        if(voTermCard != null) {
        if (voTermCard != null) {
            return voTermCard;
        }
        VoTermCard voTermManagerCard = seManagerCardMapper.getTermManagerCardInfo(cardAddr);
        if(voTermManagerCard != null) {
        if (voTermManagerCard != null) {
            return voTermManagerCard;
        }
@@ -1189,6 +1221,7 @@
    /**
     * 根据指定条件获取水卡列表
     *
     * @param vo 查询条件
     * @return 水卡列表
     */
@@ -1214,6 +1247,7 @@
    /**
     * 获取已挂失的水卡列表
     *
     * @param vo 查询条件
     * @return 已挂失的水卡列表
     */
@@ -1222,7 +1256,7 @@
        params.put("pageCurr", vo.pageCurr);
        params.put("pageSize", vo.pageSize);
        params.put("state", 2); // 挂失状态
        Long itemTotal = seClientCardMapper.getLostCardsCount(params);
        QueryResultVo<List<VoCards>> rsVo = new QueryResultVo<>();
@@ -1243,10 +1277,86 @@
    /**
     * 根据水卡编号获取卡信息
     *
     * @param cardNum 水卡编号
     * @return 卡信息
     */
    public VoCardByClientNum getCardByCardNum(String cardNum) {
        return seClientCardMapper.getCardByCardNum(cardNum);
    }
    /**
     * 创建管理卡
     *
     * @param dto 创建管理卡DTO
     * @return 创建结果
     */
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> createManagementCard(CreateManagementCardDto dto) {
        Map<String, Object> result = new HashMap<>();
        result.put("success", false);
        try {
            // 检查卡地址是否已存在
            if (isCardAddrExists(dto.getCardAddr())) {
                result.put("msg", "创建失败-此卡地址已存在");
                return result;
            }
            // 参考termActiveCard逻辑:生成订单号
            String orderNo = generateOrderNo();
            // 参考termActiveCard逻辑:生成唯一ID,使用时间戳
            Long id = System.currentTimeMillis();
            Date createTime = new Date();
            // 构建管理卡对象
            SeManagementCard managementCard = SeManagementCard.builder()
                    .id(id)
                    .protocol(dto.getProtocol())
                    .cardAddr(dto.getCardAddr())
                    .securityCode(dto.getSecurityCode())
                    .cardType(dto.getCardType())
                    .createTime(createTime)
                    .orderNo(orderNo)
                    .districtCode(dto.getDistrictCode())
                    .projectNo(dto.getProjectNo() != null ? dto.getProjectNo() : this.projectNo)
                    .ip(dto.getIp())
                    .domain(dto.getDomain())
                    .openClostTime(dto.getOpenClostTime())
                    .remarks(dto.getRemarks())
                    .build();
            // 插入数据库
            int insertResult = seManagementCardMapper.insertSelective(managementCard);
            if (insertResult > 0) {
                result.put("success", true);
                result.put("content", orderNo); // 返回订单号
                result.put("msg", "请求成功");
            } else {
                result.put("msg", "管理卡创建失败-数据库插入异常");
            }
        } catch (Exception e) {
            log.error("创建管理卡异常: {}", e.getMessage(), e);
            result.put("msg", "管理卡创建失败: " + e.getMessage());
        }
        return result;
    }
    /**
     * 检查卡片地址是否已存在
     *
     * @param cardAddr 卡片地址
     * @return true-已存在,false-不存在
     */
    public boolean isCardAddrExists(String cardAddr) {
        // 使用一次查询检查两个表中是否存在该卡地址
        // 1. 管理卡表:所有记录都检查
        // 2. 农户水卡表:只检查正常(1)和挂失(3)状态的记录
        Long totalCount = seClientCardMapper.checkCardAddrExists(cardAddr);
        return totalCount != null && totalCount > 0;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/dto/CreateManagementCardDto.java
New file
@@ -0,0 +1,82 @@
package com.dy.pipIrrTerminal.card.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
 * @author ZhuBaoMin
 * @date 2025-01-20
 * @Description 创建管理卡DTO
 */
@Data
@Schema(name = "创建管理卡DTO")
public class CreateManagementCardDto {
    /**
     * 通讯协议
     */
    @NotBlank(message = "通讯协议不能为空")
    @Schema(description = "通讯协议", example = "RS485")
    private String protocol;
    /**
     * 卡片地址
     */
    @NotBlank(message = "卡片地址不能为空")
    @Schema(description = "卡片地址", example = "001")
    private String cardAddr;
    /**
     * 识别码
     */
    @NotBlank(message = "识别码不能为空")
    @Schema(description = "识别码", example = "123456")
    private String securityCode;
    /**
     * 卡片类型
     * 2-设置区域表号卡,3-取数卡,4-检查卡,5-测试卡,6-清零卡,7-IP设置卡,8-域名设置卡,9-GPS卡,10-时间配置卡
     */
    @NotNull(message = "卡片类型不能为空")
    @Schema(description = "卡片类型", example = "2", allowableValues = { "2", "3", "4", "5", "6", "7", "8", "9", "10" })
    private Byte cardType;
    /**
     * 5级行政区划编码
     */
    @Schema(description = "5级行政区划编码", example = "110101")
    private String districtCode;
    /**
     * 项目编码
     */
    @Schema(description = "项目编码", example = "1001")
    private Integer projectNo;
    /**
     * IP地址
     */
    @Schema(description = "IP地址", example = "192.168.1.100")
    private String ip;
    /**
     * 域名
     */
    @Schema(description = "域名", example = "example.com")
    private String domain;
    /**
     * 开关阀时间
     */
    @Schema(description = "开关阀时间(秒)", example = "30")
    private Integer openClostTime;
    /**
     * 备注信息
     */
    @Schema(description = "备注信息", example = "管理卡备注")
    private String remarks;
}