package com.dy.pipIrrTerminal.card; 
 | 
  
 | 
import com.dy.common.aop.SsoAop; 
 | 
import com.dy.common.webUtil.BaseResponse; 
 | 
import com.dy.common.webUtil.BaseResponseUtils; 
 | 
import com.dy.common.webUtil.QueryResultVo; 
 | 
import com.dy.common.webUtil.ResultCodeMsg; 
 | 
import com.dy.pipIrrGlobal.voSe.*; 
 | 
import com.dy.pipIrrTerminal.card.dto.*; 
 | 
import com.dy.pipIrrTerminal.card.qo.QoCards; 
 | 
import com.dy.pipIrrTerminal.card.qo.QoLostCards; 
 | 
import com.dy.pipIrrTerminal.card.qo.QoTransaction; 
 | 
import io.swagger.v3.oas.annotations.Operation; 
 | 
import io.swagger.v3.oas.annotations.media.Content; 
 | 
import io.swagger.v3.oas.annotations.media.Schema; 
 | 
import io.swagger.v3.oas.annotations.responses.ApiResponse; 
 | 
import io.swagger.v3.oas.annotations.responses.ApiResponses; 
 | 
import jakarta.validation.Valid; 
 | 
import lombok.RequiredArgsConstructor; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.springframework.http.MediaType; 
 | 
import org.springframework.validation.BindingResult; 
 | 
import org.springframework.web.bind.annotation.*; 
 | 
  
 | 
import java.util.List; 
 | 
import java.util.Map; 
 | 
import java.util.Objects; 
 | 
  
 | 
/** 
 | 
 * @author ZhuBaoMin 
 | 
 * @date 2025-05-08 10:15 
 | 
 * @LastEditTime 2025-05-08 10:15 
 | 
 * @Description 
 | 
 */ 
 | 
  
 | 
@Slf4j 
 | 
@RestController 
 | 
@RequestMapping(path = "card") 
 | 
@RequiredArgsConstructor 
 | 
public class CardCtrl { 
 | 
    private final CardSv cardSv; 
 | 
  
 | 
    /** 
 | 
     * 开卡(含充值) 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termActiveCard", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoTermActiveCard> termActiveCard(@RequestBody @Valid ActiveCard po, 
 | 
            BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
        // 检查卡片地址是否已存在 
 | 
        if (cardSv.isCardAddrExists(po.getCardAddr())) { 
 | 
            return BaseResponseUtils.buildErrorMsg("该卡片地址已存在,请使用其他卡"); 
 | 
        } 
 | 
        Map map_result = cardSv.activeOrReissueTermCard(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 充值 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termRecharge", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoTermCommon> termRecharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.addRecharge(po, null); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 挂失 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termReportLoss", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<Boolean> termReportLoss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.reportLoss(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 解锁 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termUnlock", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<Boolean> termUnlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.unlock(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 补卡 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termReissue", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoTermCommon> termReissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.reissue(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 销卡 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termCancel", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoTermCommon> termCancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.cancel(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 补扣 
 | 
     *  
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termRepay", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoRepaySupplement> termRepay(@RequestBody @Valid DtoRepaySupplement po, 
 | 
            BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        if (po.getRepayMorny() == null || po.getRepayMorny() <= 0) { 
 | 
            return BaseResponseUtils.buildErrorMsg("补扣金额不能为空且需大于0"); 
 | 
        } 
 | 
  
 | 
        if (po.getRepayMorny() > po.getBalance()) { 
 | 
            return BaseResponseUtils.buildErrorMsg("补扣金额不能大于补扣前余额"); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.repay(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 返还 
 | 
     *  
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "supplement", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoRepaySupplement> supplement(@RequestBody @Valid DtoRepaySupplement po, 
 | 
            BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        if (po.getSupplementMoney() == null || po.getSupplementMoney() <= 0) { 
 | 
            return BaseResponseUtils.buildErrorMsg("返还金额不能为空且需大于0"); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.supplement(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 操作执行回调 
 | 
     * 
 | 
     * @param po 
 | 
     * @param bindingResult 
 | 
     * @return 
 | 
     */ 
 | 
    @PostMapping(path = "termCallBack", consumes = MediaType.APPLICATION_JSON_VALUE) 
 | 
    @SsoAop() 
 | 
    public BaseResponse<Boolean> termCallBack(@RequestBody @Valid DtoCallBack po, BindingResult bindingResult) { 
 | 
        if (bindingResult != null && bindingResult.hasErrors()) { 
 | 
            return BaseResponseUtils 
 | 
                    .buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); 
 | 
        } 
 | 
  
 | 
        Map map_result = cardSv.callBack(po); 
 | 
        if (map_result.get("success").equals(false)) { 
 | 
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); 
 | 
        } 
 | 
        return BaseResponseUtils.buildSuccess(map_result.get("content")); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 读取卡信息 
 | 
     *  
 | 
     * @param cardAddr 
 | 
     * @return 
 | 
     */ 
 | 
    @GetMapping(path = "readCard") 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoTermCard> readCard(@RequestParam String cardAddr) { 
 | 
        try { 
 | 
            VoTermCard voTermCard = cardSv.readCard(cardAddr); 
 | 
            if (voTermCard == null) { 
 | 
                return BaseResponseUtils.buildNonExist(); 
 | 
            } 
 | 
            return BaseResponseUtils.buildSuccess(voTermCard); 
 | 
        } catch (Exception e) { 
 | 
            log.error("查询农户异常", e); 
 | 
            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)) }) 
 | 
    }) 
 | 
    @GetMapping(path = "getcards") 
 | 
    @SsoAop() 
 | 
    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()); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取已挂失的水卡列表,终端应用程序使用 
 | 
     *  
 | 
     * @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)) }) 
 | 
    }) 
 | 
    @GetMapping(path = "getlostcards") 
 | 
    @SsoAop() 
 | 
    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()); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 根据水卡编号获取卡信息 
 | 
     *  
 | 
     * @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)) }) 
 | 
    }) 
 | 
    @GetMapping(path = "getcardbycardnum") 
 | 
    @SsoAop() 
 | 
    public BaseResponse<VoCardByClientNum> getCardByCardNum(@RequestParam String cardNum) { 
 | 
        try { 
 | 
            VoCardByClientNum res = cardSv.getCardByCardNum(cardNum); 
 | 
            if (res == null) { 
 | 
                return BaseResponseUtils.buildFail("未找到对应的卡信息"); 
 | 
            } 
 | 
            return BaseResponseUtils.buildSuccess(res); 
 | 
        } catch (Exception e) { 
 | 
            log.error("根据水卡编号查询卡信息异常", e); 
 | 
            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()); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 根据指定条件获取交易明细 
 | 
     * 
 | 
     * @param vo 
 | 
     * @return 
 | 
     */ 
 | 
    @GetMapping(path = "getTransactions") 
 | 
    @SsoAop() 
 | 
    public BaseResponse<Map> getOperates(QoTransaction vo) { 
 | 
        try { 
 | 
            return BaseResponseUtils.buildSuccess(cardSv.getTransactions(vo)); 
 | 
        } catch (Exception e) { 
 | 
            log.error("查询交易记录异常", e); 
 | 
            return BaseResponseUtils.buildException(e.getMessage()); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    @GetMapping(path = "/getOperateRecords") 
 | 
    @SsoAop() 
 | 
    public BaseResponse<List<Map<String, Object>>> getOperateRecordsAndMoney(QoCards qo){ 
 | 
        try { 
 | 
            Long cardNum = qo.getCardNum(); 
 | 
            String cardAddr = qo.getCardAddr(); 
 | 
            if (cardNum == null && cardAddr == null) { 
 | 
                return BaseResponseUtils.buildErrorMsg("请输入卡号或卡地址"); 
 | 
            } 
 | 
            Map map = cardSv.getOperateRecordsAndMoney(cardNum, cardAddr); 
 | 
            return BaseResponseUtils.buildSuccess(map); 
 | 
        } catch (Exception e) { 
 | 
            log.error("查询操作记录异常", e); 
 | 
            return BaseResponseUtils.buildException(e.getMessage()) ; 
 | 
        } 
 | 
    } 
 | 
} 
 |