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

- 在 CardCtrl 中添加 createManagementCard 方法,实现创建管理卡的功能- 在 SeClientCardMapper 中添加 checkCardAddrExists 方法,用于检查卡片地址是否存在
- 优化了卡片地址存在性校验逻辑,排除了已挂失的卡片- 新增 CreateManagementCardDto 类,用于创建管理卡的请求参数
4个文件已修改
1个文件已添加
363 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientCardMapper.java 46 ●●●●● 补丁 | 查看 | 原始文档 | 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 105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-terminal/src/main/java/com/dy/pipIrrTerminal/card/CardSv.java 114 ●●●●● 补丁 | 查看 | 原始文档 | 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,6 +195,7 @@
    /**
     * 更新实体卡剩余金额
     *
     * @param id
     * @param money
     */
@@ -183,6 +203,7 @@
    /**
     *当前余额总量(物理卡)
     *
     * @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,6 +243,7 @@
    /**
     * 获取指定时间段内水卡充值总计
     *
     * @param timeStart
     * @param timeStop
     * @return
@@ -227,6 +252,7 @@
    /**
     * 获取指定时间段内水卡消费总计
     *
     * @param timeStart
     * @param timeStop
     * @return
@@ -235,6 +261,7 @@
    /**
     * 依据水卡地址将最后一条无效状态的指定操作记录改为有效
     *
     * @param cardAddr
     * @param operateType
     * @return
@@ -243,6 +270,7 @@
    /**
     * 充值机用根据订单号将水卡改为有效
     *
     * @param orderNumber
     * @return
     */
@@ -250,6 +278,7 @@
    /**
     * 根据水卡ID获取原水卡ID,补卡通知中使用
     *
     * @param cardId
     * @return
     */
@@ -257,6 +286,7 @@
    /**
     * 充值机用根据补卡的订单号将挂失水卡余额置零
     *
     * @param orderNumber
     * @return
     */
@@ -264,6 +294,7 @@
    /**
     * 充值机用获取农户水卡信息
     *
     * @param cardAddr
     * @return
     */
@@ -271,6 +302,7 @@
    /**
     * 获取已挂失水卡列表记录数量
     *
     * @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,15 +180,18 @@
    /**
     * 补扣
     *
     * @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) {
@@ -201,15 +211,18 @@
    /**
     * 返还
     *
     * @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) {
@@ -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,6 +260,7 @@
    /**
     * 读取卡信息
     *
     * @param cardAddr
     * @return
     */
@@ -266,17 +281,14 @@
    /**
     * 根据指定条件获取水卡列表,终端应用程序使用
     *
     * @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()
@@ -292,17 +304,14 @@
    /**
     * 获取已挂失的水卡列表,终端应用程序使用
     *
     * @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()
@@ -318,17 +327,14 @@
    /**
     * 根据水卡编号获取卡信息
     *
     * @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()
@@ -344,4 +350,43 @@
            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:可以充值
     */
@@ -101,6 +107,7 @@
    /**
     * 根据水卡编号判断该卡是否可以挂失
     *
     * @param po
     * @return true:可以报失
     */
@@ -136,6 +143,7 @@
    /**
     * 根据水卡编号判断该卡是否可以解锁
     *
     * @param po
     * @return
     */
@@ -167,8 +175,10 @@
        map.put("content", card);
        return map;
    }
    /**
     * 根据水卡编号判断该卡是否可以补卡
     *
     * @param po
     * @return true:可以补卡
     */
@@ -212,6 +222,7 @@
    /**
     * 根据水卡编号判断该卡是否可以注销
     *
     * @param po
     * @return
     */
@@ -246,6 +257,7 @@
    /**
     * 根据水卡编号判断该卡是否可以补扣
     *
     * @param po
     * @return
     */
@@ -280,6 +292,7 @@
    /**
     * 根据水卡编号判断该卡是否可以返还
     *
     * @param po
     * @return
     */
@@ -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
     */
@@ -525,6 +541,7 @@
    /**
     * 充值
     *
     * @param po
     * @return
     */
@@ -617,6 +634,7 @@
    /**
     * 补卡
     *
     * @param po
     * @return
     */
@@ -661,6 +679,7 @@
    /**
     * 挂失
     *
     * @param po
     * @return
     */
@@ -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
     */
@@ -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
     */
@@ -828,6 +851,7 @@
    /**
     * 补扣
     *
     * @param po
     * @return
     */
@@ -880,6 +904,7 @@
    /**
     * 返还
     *
     * @param po
     * @return
     */
@@ -931,6 +956,7 @@
    /**
     * 操作回调
     *
     * @param po
     * @return
     */
@@ -1084,6 +1110,7 @@
    /**
     * 如果补卡时退还了金额,清空挂失卡余额
     *
     * @param orderNumber
     */
    public Integer emptyCardBalance(String orderNumber) {
@@ -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,6 +1201,7 @@
    /**
     * 读取水卡信息
     *
     * @param cardAddr
     * @return
     */
@@ -1189,6 +1221,7 @@
    /**
     * 根据指定条件获取水卡列表
     *
     * @param vo 查询条件
     * @return 水卡列表
     */
@@ -1214,6 +1247,7 @@
    /**
     * 获取已挂失的水卡列表
     *
     * @param vo 查询条件
     * @return 已挂失的水卡列表
     */
@@ -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;
}