|  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClient; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.SeManagerCard; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.util.AmountToChinese; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoActiveCard; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoOperate; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoRecharge; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoReissueCard; | 
|---|
|  |  |  | import com.dy.pipIrrSell.cardOperate.converter.RechargeDtoMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voRm.VoExpend; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.*; | 
|---|
|  |  |  | import com.dy.pipIrrSell.cardOperate.dto.*; | 
|---|
|  |  |  | import com.dy.pipIrrSell.cardOperate.enums.OperateTypeENUM; | 
|---|
|  |  |  | import com.dy.pipIrrSell.cardOperate.qo.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "水卡操作管理", description = "水卡各种操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="card") | 
|---|
|  |  |  | @RequestMapping(path = "card") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class CardOperateCtrl { | 
|---|
|  |  |  | private final CardOperateSv cardOperateSv; | 
|---|
|  |  |  | private final ClientCardSv clientCardSv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${project.divisionCode}") | 
|---|
|  |  |  | private String divisionCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${project.projectNo}") | 
|---|
|  |  |  | private Integer projectNo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 开卡 | 
|---|
|  |  |  | * @param po 开卡传入对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po            开卡传入对象 | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return 水卡编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "active", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_active(@RequestBody @Valid DtoActiveCard po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_active(@RequestBody @Valid ActiveCard po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 依据水卡地址判断该卡是否可以开卡,未开过卡或不是正常状态、挂失状态的可开卡 | 
|---|
|  |  |  | if (!cardOperateSv.canActiveCard(po.getCardAddr())) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.ACTIVE_FAIL_CARD_ESIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long clientId = po.getClientId(); | 
|---|
|  |  |  | // 获取5级行政区划串areaCode | 
|---|
|  |  |  | String areaCode = cardOperateSv.getAreaCodeByNum(po.getClientNum()); | 
|---|
|  |  |  | if(areaCode.trim().length() == 0) { | 
|---|
|  |  |  | Long areaCodeL = cardOperateSv.getAreaCodeById(clientId); | 
|---|
|  |  |  | if (areaCodeL == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.AREA_CODE_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // p206V1_0_1协议,将前6位行政区划改为100000 | 
|---|
|  |  |  | if(po.getProtocol().trim().equals("p206V1_0_1")) { | 
|---|
|  |  |  | areaCode = "100000" + areaCode.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String areaCode = String.valueOf(areaCodeL); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据行政区划串(areaCode)在水卡表中针对水卡编号(cardNum)进行模糊查询 | 
|---|
|  |  |  | * 如果4位顺序号已经达到最大值,提示用户联系系统管理员 | 
|---|
|  |  |  | * 如果4位顺序号未达到最大值,则加1 | 
|---|
|  |  |  | * 如果顺序号已经达到最大值,提示用户联系系统管理员 | 
|---|
|  |  |  | * 如果顺序号未达到最大值,则加1 | 
|---|
|  |  |  | * cardNum为新的卡号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String cardNum = Optional.ofNullable(cardOperateSv.getCardNumOfMax(areaCode)).orElse(""); | 
|---|
|  |  |  | if(cardNum != null && cardNum.trim().length() > 0) { | 
|---|
|  |  |  | if (cardNum != null && cardNum.trim().length() > 0) { | 
|---|
|  |  |  | Integer number = Integer.parseInt(cardNum.substring(12)); | 
|---|
|  |  |  | number = number + 1; | 
|---|
|  |  |  | if(number > 65535) { | 
|---|
|  |  |  | if (number > 65535) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = cardNum.substring(0, 12) + String.format("%05d", number); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * cardAddr         水卡地址(仅仅写入,无业务) | 
|---|
|  |  |  | * clientNum        农户编号 | 
|---|
|  |  |  | * cardCost         卡片费用 | 
|---|
|  |  |  | * originalCardId   原水卡ID | 
|---|
|  |  |  | * amount           充值金额,充值接口为输入参数,补卡接口为原卡退还金额 | 
|---|
|  |  |  | * reissueAmount    补卡金额,补卡时使用 | 
|---|
|  |  |  | * paymentId        支付方式编号 | 
|---|
|  |  |  | 
|---|
|  |  |  | * operator         操作人编号 | 
|---|
|  |  |  | * activeTime       开卡时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String protocol = po.getProtocol(); | 
|---|
|  |  |  | String cardAddr = po.getCardAddr(); | 
|---|
|  |  |  | String clientNum = po.getClientNum(); | 
|---|
|  |  |  | Integer cardCost = po.getCardCost(); | 
|---|
|  |  |  | Long originalCardId = po.getOriginalCardId(); | 
|---|
|  |  |  | Float amount = po.getAmount(); | 
|---|
|  |  |  | 
|---|
|  |  |  | Date activeTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据农户编号获取农户ID | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Long clientId = cardOperateSv.getClientIdByNum(clientNum); | 
|---|
|  |  |  | if(clientId == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CLIENT_NUM_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加农户卡记录,退还金额作为当前余额 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setProtocol(protocol); | 
|---|
|  |  |  | seClientCard.setCardaddr(cardAddr); | 
|---|
|  |  |  | seClientCard.setCardnum(cardNum); | 
|---|
|  |  |  | seClientCard.setClientid(clientId); | 
|---|
|  |  |  | seClientCard.setMoney(amount); | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.NORMAL.getCode()); | 
|---|
|  |  |  | if(originalCardId != null) { | 
|---|
|  |  |  | // 开卡时卡片状态为无效 | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.INVALID.getCode()); | 
|---|
|  |  |  | if (originalCardId != null) { | 
|---|
|  |  |  | // 补卡 | 
|---|
|  |  |  | seClientCard.setOriginalCardId(originalCardId); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.REPLACE.getCode()); | 
|---|
|  |  |  | seClientCard.setReplacedt(activeTime); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 开新卡 | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.ACTIVE.getCode()); | 
|---|
|  |  |  | seClientCard.setCreatedt(activeTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | seClientCard.setCreatedt(activeTime); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.ACTIVE.getCode()); | 
|---|
|  |  |  | Long cardId = Optional.ofNullable(clientCardSv.add(seClientCard)).orElse(0L) ; | 
|---|
|  |  |  | if(cardId == 0) { | 
|---|
|  |  |  | Long cardId = Optional.ofNullable(clientCardSv.add(seClientCard)).orElse(0L); | 
|---|
|  |  |  | if (cardId == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.ACTIVE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加开卡记录,退还金额作为充值金额 | 
|---|
|  |  |  | * 添加开卡操作记录,退还金额作为充值金额 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeCardOperate seCardOperate = new SeCardOperate(); | 
|---|
|  |  |  | seCardOperate.setCardId(cardId); | 
|---|
|  |  |  | seCardOperate.setClientId(clientId); | 
|---|
|  |  |  | seCardOperate.setMoney(amount); | 
|---|
|  |  |  | seCardOperate.setMoney(0f); | 
|---|
|  |  |  | seCardOperate.setCardCost(cardCost); | 
|---|
|  |  |  | seCardOperate.setPaymentId(paymentId); | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.ACTIVE.getCode()); | 
|---|
|  |  |  | if (originalCardId != null) { | 
|---|
|  |  |  | // 补卡 | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.REISSUE.getCode()); | 
|---|
|  |  |  | seCardOperate.setNoTradeAmount(amount); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 开新卡 | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.ACTIVE.getCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(activeTime); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 1); | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.ACTIVE_FAIL_WRITE_ACTIVE_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 如果操作人员开卡时输入了充值金额,则开卡后调用充值功能 | 
|---|
|  |  |  | * 补卡除外,补卡的退还金额是从挂失卡中转移过来的,没有实际金钱交易 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | po.setCardNum(Long.parseLong(cardNum)); | 
|---|
|  |  |  | if(amount != null && amount > 0 && originalCardId == null) { | 
|---|
|  |  |  | po.setClientId(clientId); | 
|---|
|  |  |  | DtoRecharge dtoRecharge = RechargeDtoMapper.INSTANCT.po2vo(po); | 
|---|
|  |  |  | if (amount != null && amount > 0 && originalCardId == null) { | 
|---|
|  |  |  | DtoRecharge dtoRecharge = new DtoRecharge(); | 
|---|
|  |  |  | dtoRecharge.setCardNum(Long.parseLong(cardNum)); | 
|---|
|  |  |  | dtoRecharge.setAmount(amount); | 
|---|
|  |  |  | dtoRecharge.setPaymentId(paymentId); | 
|---|
|  |  |  | dtoRecharge.setRemarks(remarks); | 
|---|
|  |  |  | dtoRecharge.setOperator(operator); | 
|---|
|  |  |  | dtoRecharge.setMoney(0f); | 
|---|
|  |  |  | dtoRecharge.setGift(0f); | 
|---|
|  |  |  | dtoRecharge.setPrice(0f); | 
|---|
|  |  |  | BaseResponse<Boolean> job = cardOperateSv.addRecharge(dtoRecharge); | 
|---|
|  |  |  | if(!job.getCode().equals("0001")) { | 
|---|
|  |  |  | if (!job.getCode().equals("0001")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.ACTIVE_FAIL_RECHARGE_EXCEPTION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(po.getProtocol().trim().equals("p206V1_0_1")) { | 
|---|
|  |  |  | cardNum = cardNum.substring(6,12) + cardNum.substring(13); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map map = new HashMap(); | 
|---|
|  |  |  | map.put("projectNo", String.format("%02x", Integer.parseInt(cardOperateSv.getProjectNo()))); | 
|---|
|  |  |  | map.put("orderNumber", cardId); | 
|---|
|  |  |  | map.put("projectNo", String.format("%02x", projectNo)); | 
|---|
|  |  |  | map.put("orderNumber", rec); | 
|---|
|  |  |  | map.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 补卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "reissue", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_reissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_reissue(@RequestBody @Valid DtoReissue po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * operator         操作人编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String protocol; | 
|---|
|  |  |  | String cardAddr = po.getCardAddr(); | 
|---|
|  |  |  | String clientNum = ""; | 
|---|
|  |  |  | Long clientId = 0L; | 
|---|
|  |  |  | Long cardNum = po.getCardNum(); | 
|---|
|  |  |  | Long cardId = 0L; | 
|---|
|  |  |  | Integer cardCost = Optional.ofNullable(po.getCardCost()).orElse(0); | 
|---|
|  |  |  | 
|---|
|  |  |  | Long paymentId = po.getPaymentId(); | 
|---|
|  |  |  | String remarks = po.getRemarks(); | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | String protocol = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | protocol = "p206V1_0_1"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断当前水卡是否为挂失状态且未补卡,仅已经挂失且未补卡的可以补卡 | 
|---|
|  |  |  | if(!cardOperateSv.isLostAndUnreplaced(cardNum)) { | 
|---|
|  |  |  | if (!cardOperateSv.isLostAndUnreplaced(cardNum)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入了退还金额,需要判断老卡(被挂失的水卡)挂失时是否已经退款,无论退款多少都提示用户挂失时已退款 | 
|---|
|  |  |  | if(reissueAmount != null) { | 
|---|
|  |  |  | if (reissueAmount != null && reissueAmount > 0) { | 
|---|
|  |  |  | Double tradeAmount = cardOperateSv.getTradeAmountByCardNo(cardNum); | 
|---|
|  |  |  | if(tradeAmount != null) { | 
|---|
|  |  |  | if (tradeAmount != null && tradeAmount > 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.THE_FEE_CANNOT_BE_REFUNDED.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | clientNum = map.get("clientNum").toString(); | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | clientId = Long.parseLong(map.get("clientId").toString()); | 
|---|
|  |  |  | protocol = map.get("protocol").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 如果是补卡调用的开卡且转移了退还金额,需修改挂失卡余额为0 | 
|---|
|  |  |  | * 通知补卡成功时再处理 | 
|---|
|  |  |  | if(reissueAmount != null) { | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setMoney(0f); | 
|---|
|  |  |  | cardOperateSv.updateClientCard(seClientCard); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | if(reissueAmount != null) { | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setMoney(0f); | 
|---|
|  |  |  | cardOperateSv.updateClientCard(seClientCard); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加开卡记录,退还金额冲到新卡中 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DtoActiveCard dtoActiveCard = new DtoActiveCard(); | 
|---|
|  |  |  | dtoActiveCard.setProtocol(protocol); | 
|---|
|  |  |  | dtoActiveCard.setCardAddr(cardAddr); | 
|---|
|  |  |  | dtoActiveCard.setClientNum(clientNum); | 
|---|
|  |  |  | dtoActiveCard.setOriginalCardId(cardId); | 
|---|
|  |  |  | //dtoActiveCard.setOriginalCardId(cardNum); | 
|---|
|  |  |  | dtoActiveCard.setCardCost(cardCost); | 
|---|
|  |  |  | dtoActiveCard.setAmount(reissueAmount); | 
|---|
|  |  |  | dtoActiveCard.setPaymentId(paymentId); | 
|---|
|  |  |  | dtoActiveCard.setRemarks(remarks); | 
|---|
|  |  |  | dtoActiveCard.setOperator(operator); | 
|---|
|  |  |  | BaseResponse<java.lang.Boolean> baseResponse_addActive = add_active(dtoActiveCard, null); | 
|---|
|  |  |  | ActiveCard activeCard = new ActiveCard(); | 
|---|
|  |  |  | activeCard.setProtocol(protocol); | 
|---|
|  |  |  | activeCard.setCardAddr(cardAddr); | 
|---|
|  |  |  | activeCard.setClientId(clientId); | 
|---|
|  |  |  | activeCard.setOriginalCardId(cardId); | 
|---|
|  |  |  | activeCard.setCardCost(cardCost); | 
|---|
|  |  |  | activeCard.setAmount(reissueAmount); | 
|---|
|  |  |  | activeCard.setPaymentId(paymentId); | 
|---|
|  |  |  | activeCard.setRemarks(remarks); | 
|---|
|  |  |  | activeCard.setOperator(operator); | 
|---|
|  |  |  | BaseResponse<java.lang.Boolean> baseResponse_addActive = add_active(activeCard, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!baseResponse_addActive.getCode().equals("0001")) { | 
|---|
|  |  |  | if (!baseResponse_addActive.getCode().equals("0001")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.REPLACE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject job_content = (JSONObject) JSON.toJSON( baseResponse_addActive.getContent()); | 
|---|
|  |  |  | JSONObject job_content = (JSONObject) JSON.toJSON(baseResponse_addActive.getContent()); | 
|---|
|  |  |  | cardNum = job_content.getLong("cardNum"); | 
|---|
|  |  |  | String orderNumber = job_content.getString("orderNumber"); | 
|---|
|  |  |  | String projectNo = job_content.getString("projectNo"); | 
|---|
|  |  |  | 
|---|
|  |  |  | map_response.put("projectNo", projectNo); | 
|---|
|  |  |  | map_response.put("orderNumber", orderNumber); | 
|---|
|  |  |  | map_response.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response) ; | 
|---|
|  |  |  | map_response.put("protocol", protocol); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 充值 | 
|---|
|  |  |  | * @param po 充值传输对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po            充值传输对象 | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "recharge", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_recharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_recharge(@RequestBody @Valid DtoRecharge po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return cardOperateSv.addRecharge(po); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 销卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "cancel", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_cancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_cancel(@RequestBody @Valid DtoCancel po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | Long clientId = 0L; | 
|---|
|  |  |  | Long cardNum = po.getCardNum(); | 
|---|
|  |  |  | Float refund = po.getRefund(); | 
|---|
|  |  |  | Byte refundType = po.getRefundType(); | 
|---|
|  |  |  | Long refundType = po.getRefundType(); | 
|---|
|  |  |  | String remarks = po.getRemarks(); | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Date cancelTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证水卡状态是否支持当前操作 | 
|---|
|  |  |  | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); | 
|---|
|  |  |  | if(stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | if (stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | clientId = Long.parseLong(map.get("clientId").toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改农户卡信息: | 
|---|
|  |  |  | * 修改农户卡信息,通知时再处理 | 
|---|
|  |  |  | *      注销时间 | 
|---|
|  |  |  | *      最后操作类型-4 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setCanceldt(cancelTime); | 
|---|
|  |  |  | seClientCard.setMoney(0f); | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.CANCELLED.getCode()); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.CANCEL.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CANCEL_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setCanceldt(cancelTime); | 
|---|
|  |  |  | seClientCard.setMoney(0f); | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.CANCELLED.getCode()); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.CANCEL.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CANCEL_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加注销记录 | 
|---|
|  |  |  | * 添加注销操作记录 | 
|---|
|  |  |  | * 支付方式为现金 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeCardOperate seCardOperate = new SeCardOperate(); | 
|---|
|  |  |  | seCardOperate.setCardId(cardId); | 
|---|
|  |  |  | seCardOperate.setClientId(clientId); | 
|---|
|  |  |  | seCardOperate.setTradeAmount(-refund); | 
|---|
|  |  |  | seCardOperate.setPaymentId(1L); | 
|---|
|  |  |  | seCardOperate.setPaymentId(refundType); | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.CANCEL.getCode()); | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(cancelTime); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CANCEL_FAIL_WRITE_CANCELL_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | Map map_response = new HashMap(); | 
|---|
|  |  |  | map_response.put("projectNo", String.format("%02x", projectNo)); | 
|---|
|  |  |  | map_response.put("orderNumber", rec); | 
|---|
|  |  |  | map_response.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 挂失 | 
|---|
|  |  |  | * 挂失,不需要二次通知 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "loss", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_loss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_loss(@RequestBody @Valid DtoLoss po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Date lossTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证水卡状态是否支持当前操作 | 
|---|
|  |  |  | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); | 
|---|
|  |  |  | if(stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | if (stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | *  状态 | 
|---|
|  |  |  | *  最后操作类型-6 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setMoney(money); | 
|---|
|  |  |  | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.LOSS.getCode()); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.LOSS.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | if (rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.LOSS_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加挂失记录 | 
|---|
|  |  |  | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(lossTime); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 2); | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.LOSS_FAIL_WRITE_LOSS_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | Map map_response = new HashMap(); | 
|---|
|  |  |  | map_response.put("projectNo", String.format("%02x", projectNo)); | 
|---|
|  |  |  | map_response.put("orderNumber", rec); | 
|---|
|  |  |  | map_response.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 冲正 | 
|---|
|  |  |  | * 冲正,2024-09-30 作废,冲正功能由充值功能代替 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "reversal", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_reversal(@RequestBody @Valid DtoReversal po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_reversal(@RequestBody @Valid DtoReversal po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Date reversalTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证水卡状态是否支持当前操作 | 
|---|
|  |  |  | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); | 
|---|
|  |  |  | if(stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | if (stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改农户卡信息: | 
|---|
|  |  |  | *      挂失时间 | 
|---|
|  |  |  | *      最后操作类型-4 | 
|---|
|  |  |  | *      冲正时间 | 
|---|
|  |  |  | *      最后操作类型-7 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | 
|---|
|  |  |  | seClientCard.setMoney(cardBalance); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.REVERSAL.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | if (rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(reversalTime); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 2); | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.REVERSAL_FAIL_WRITE_REVERSAL_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | Map map_response = new HashMap(); | 
|---|
|  |  |  | map_response.put("projectNo", String.format("%02x", projectNo)); | 
|---|
|  |  |  | map_response.put("orderNumber", rec); | 
|---|
|  |  |  | map_response.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 补扣 | 
|---|
|  |  |  | * 补扣、反写 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "refund", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_refund(@RequestBody @Valid DtoRefund po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_refund(@RequestBody @Valid DtoRefund po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * clientId         农户编号(非传入参数,由cardNum反查) | 
|---|
|  |  |  | * cardNum          水卡编号 | 
|---|
|  |  |  | * money            卡片余额 | 
|---|
|  |  |  | * refund           补扣余额 | 
|---|
|  |  |  | * refund           补扣余额/反写金额 | 
|---|
|  |  |  | * remarks          备注 | 
|---|
|  |  |  | * operator         操作人编号 | 
|---|
|  |  |  | * refundTime       补扣时间 | 
|---|
|  |  |  | * operateType      操作类型:1-补扣,2-反写 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Long cardId = 0L; | 
|---|
|  |  |  | Long clientId = 0L; | 
|---|
|  |  |  | 
|---|
|  |  |  | Float refund = po.getRefund(); | 
|---|
|  |  |  | String remarks = po.getRemarks(); | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Date refundTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  | Integer operateType = po.getOperateType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证水卡状态是否支持当前操作 | 
|---|
|  |  |  | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); | 
|---|
|  |  |  | if(stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | if (stateName.length() == 0 || !stateName.equals("正常")) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | clientId = Long.parseLong(map.get("clientId").toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改农户卡信息: | 
|---|
|  |  |  | *      挂失时间 | 
|---|
|  |  |  | *      最后操作类型-4 | 
|---|
|  |  |  | * 修改农户卡信息,通知时处理 | 
|---|
|  |  |  | *      补扣时间 | 
|---|
|  |  |  | *      最后操作类型-5 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setRefunddt(refundTime); | 
|---|
|  |  |  | seClientCard.setMoney(money + refund); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.REFUND.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeClientCard seClientCard = new SeClientCard(); | 
|---|
|  |  |  | seClientCard.setId(cardId); | 
|---|
|  |  |  | seClientCard.setRefunddt(refundTime); | 
|---|
|  |  |  | seClientCard.setMoney(money + refund); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.REFUND.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加补扣记录 | 
|---|
|  |  |  | * 添加补扣操作记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SeCardOperate seCardOperate = new SeCardOperate(); | 
|---|
|  |  |  | seCardOperate.setCardId(cardId); | 
|---|
|  |  |  | seCardOperate.setClientId(clientId); | 
|---|
|  |  |  | seCardOperate.setMoney(money); | 
|---|
|  |  |  | //seCardOperate.setNoTradeAmount(refund); | 
|---|
|  |  |  | if(operateType == 1) { | 
|---|
|  |  |  | // 补扣 | 
|---|
|  |  |  | seCardOperate.setMoney(money); | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.REFUND.getCode()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | // 反写 | 
|---|
|  |  |  | seCardOperate.setMoney(refund); | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.WRITE_BACK.getCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //seCardOperate.setMoney(money); | 
|---|
|  |  |  | seCardOperate.setRefundAmount(refund); | 
|---|
|  |  |  | seCardOperate.setOperateType(OperateTypeENUM.REFUND.getCode()); | 
|---|
|  |  |  | //seCardOperate.setOperateType(OperateTypeENUM.REFUND.getCode()); | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(refundTime); | 
|---|
|  |  |  | seCardOperate.setOperateDt(new Date()); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 1); | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.REFUND_FAIL_WRITE_REFUND_ERROR.getMessage()); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | if(operateType == 1) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.REFUND_FAIL_WRITE_REFUND_ERROR.getMessage()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.WRITE_BACK_FAIL_WRITE_BACK_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 解锁 | 
|---|
|  |  |  | * 解锁,不需要二次通知 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "unlock", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add_unlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | public BaseResponse<Boolean> add_unlock(@RequestBody @Valid DtoUnlock po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | Long operator = po.getOperator(); | 
|---|
|  |  |  | Date unlockTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | String cardNumS = String.valueOf(cardNum).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = Long.valueOf(cardNumS); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断当前水卡是否为挂失状态且未补卡,仅已经挂失其未补卡的可以解锁 | 
|---|
|  |  |  | if(!cardOperateSv.isLostAndUnreplaced(cardNum)) { | 
|---|
|  |  |  | if (!cardOperateSv.isLostAndUnreplaced(cardNum)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 依据水卡编号获取水卡表主键及农户编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
|---|
|  |  |  | if(map == null || map.size() <= 0) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardId = Long.parseLong(map.get("cardId").toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | seClientCard.setState(CardStateENUM.NORMAL.getCode()); | 
|---|
|  |  |  | seClientCard.setLastoper(LastOperateENUM.UNLOCK.getCode()); | 
|---|
|  |  |  | Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
|---|
|  |  |  | if(rec_updateClientCard == 0) { | 
|---|
|  |  |  | if (rec_updateClientCard == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.UNLOCK_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | seCardOperate.setRemarks(remarks); | 
|---|
|  |  |  | seCardOperate.setOperator(operator); | 
|---|
|  |  |  | seCardOperate.setOperateDt(unlockTime); | 
|---|
|  |  |  | seCardOperate.setOperateValid((byte) 2); | 
|---|
|  |  |  | Long rec = Optional.ofNullable(cardOperateSv.add(seCardOperate)).orElse(0L); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.UNLOCK_FAIL_WRITE_UNLOCK_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | Map map_response = new HashMap(); | 
|---|
|  |  |  | map_response.put("projectNo", String.format("%02x", projectNo)); | 
|---|
|  |  |  | map_response.put("orderNumber", rec); | 
|---|
|  |  |  | map_response.put("cardNum", cardNum); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_response); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作执行回调 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "call_back", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> callBack(@RequestBody @Valid CallBack po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String cardAddr = po.getCardAddr(); | 
|---|
|  |  |  | Integer operateType = po.getOperateType(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 此时无需判断卡片状态 | 
|---|
|  |  |  | Long cardId = cardOperateSv.getCardIdByAddr(cardAddr); | 
|---|
|  |  |  | if (cardId == null || cardId.equals(0)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("您指定的水卡不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (operateType == 1) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 开卡操作执行通知 | 
|---|
|  |  |  | *  1.依据水卡地址将最后一条无效状态的指定操作记录改为有效 | 
|---|
|  |  |  | *  2.依据水卡ID将最后一条无效状态的水卡记录改为有效 | 
|---|
|  |  |  | *  3.如果开卡同步充值 | 
|---|
|  |  |  | *      修改充值操作记录为有效 | 
|---|
|  |  |  | *      修改充值历史记录为有效 | 
|---|
|  |  |  | *      修改水卡表的操作信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Integer rec_card = Optional.ofNullable(cardOperateSv.turnCardValidByAddr(cardAddr, operateType)).orElse(0); | 
|---|
|  |  |  | Integer rec_ope = Optional.ofNullable(cardOperateSv.turnOperateValidByCardId(cardId, operateType)).orElse(0); | 
|---|
|  |  |  | if (rec_card == 0 || rec_ope == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("不存在未生效的水卡"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Boolean isMergeRecharge = cardOperateSv.isMergeRecharge(cardId); | 
|---|
|  |  |  | if (isMergeRecharge) { | 
|---|
|  |  |  | cardOperateSv.turnOperateValidByCardId(cardId, 2); | 
|---|
|  |  |  | cardOperateSv.turnRechargeHistoryValidByCardId(cardId); | 
|---|
|  |  |  | cardOperateSv.updateCard(cardId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (operateType == 2) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 充值操作执行通知 | 
|---|
|  |  |  | *  1.操作记录改为有效-cardId | 
|---|
|  |  |  | *  2.充值历史记录改为有效-cardId | 
|---|
|  |  |  | *  3.休水卡表的操作信息及余额-cardId、(mondy、amount、gift从充值历史表中获取) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer rec_ope = Optional.ofNullable(cardOperateSv.turnOperateValidByCardId(cardId, operateType)).orElse(0); | 
|---|
|  |  |  | Integer rec_recharge = cardOperateSv.turnRechargeHistoryValidByCardId(cardId); | 
|---|
|  |  |  | if (rec_recharge == 0 || rec_ope == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("不存在未生效的水卡"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardOperateSv.updateCard(cardId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (operateType == 3) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 销卡操作执行通知 | 
|---|
|  |  |  | *  1.操作记录改为有效-cardId | 
|---|
|  |  |  | *  2.修改水卡表的记录及余额(0) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | cardOperateSv.turnOperateValidByCardId(cardId, operateType); | 
|---|
|  |  |  | cardOperateSv.updateCancels(operateType, cardId); | 
|---|
|  |  |  | } else if (operateType == 4) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 补卡操作执行通知 | 
|---|
|  |  |  | *  1.新水卡记录改为有效-cardId | 
|---|
|  |  |  | *  2.开卡操作记录改为有效-cardId | 
|---|
|  |  |  | *  3.如果存在退还金额 | 
|---|
|  |  |  | *      清空原卡余额 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Integer rec_card = Optional.ofNullable(cardOperateSv.turnCardValidByAddr(cardAddr, operateType)).orElse(0); | 
|---|
|  |  |  | Integer rec_ope = Optional.ofNullable(cardOperateSv.turnOperateValidByCardId(cardId, operateType)).orElse(0); | 
|---|
|  |  |  | if (rec_card == 0 || rec_ope == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("不存在未生效的水卡"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardOperateSv.emptyCardBalance(operateType, cardId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (operateType == 5) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 补扣操作执行通知 | 
|---|
|  |  |  | *  1.操作记录改为有效 | 
|---|
|  |  |  | *  2.修改水卡表的操作信息及余额-从操作记录中取money、refund | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | cardOperateSv.turnOperateValidByCardId(cardId, operateType); | 
|---|
|  |  |  | cardOperateSv.updateRefund(operateType, cardId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (operateType == 10) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 反写操作执行通知 | 
|---|
|  |  |  | *  1.操作记录改为有效 | 
|---|
|  |  |  | *  2.修改水卡表的操作信息及余额-从操作记录中取money | 
|---|
|  |  |  | *  说明:返还操作记录中的money就是反写金额 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | cardOperateSv.turnOperateValidByCardId(cardId, operateType); | 
|---|
|  |  |  | cardOperateSv.updateWriteBack(operateType, cardId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建管理卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "create_manager_card", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> createManagerCard(@RequestBody @Valid ManagerCard po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据行政区划串(divisionCode)在管理卡表中针对卡片编号(cardNum)进行模糊查询 | 
|---|
|  |  |  | * 如果顺序号已经达到最大值,提示用户联系系统管理员 | 
|---|
|  |  |  | * 如果顺序号未达到最大值,则加1 | 
|---|
|  |  |  | * cardNum为新的卡号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String cardNum = Optional.ofNullable(cardOperateSv.getManagerCardNumOfMax(divisionCode)).orElse(""); | 
|---|
|  |  |  | if (cardNum != null && cardNum.trim().length() > 0) { | 
|---|
|  |  |  | Integer number = Integer.parseInt(cardNum.substring(12)); | 
|---|
|  |  |  | number = number + 1; | 
|---|
|  |  |  | if (number > 65535) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cardNum = cardNum.substring(0, 12) + String.format("%05d", number); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | cardNum = divisionCode + "00001"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SeManagerCard seManagerCard = new SeManagerCard(); | 
|---|
|  |  |  | seManagerCard.setCardAddr(po.getCardAddr()); | 
|---|
|  |  |  | seManagerCard.setCardNum(cardNum); | 
|---|
|  |  |  | seManagerCard.setCardType(po.getCardType()); | 
|---|
|  |  |  | seManagerCard.setCreateTime(new Date()); | 
|---|
|  |  |  | seManagerCard.setRemarks(po.getRemarks()); | 
|---|
|  |  |  | Long managerCardId = cardOperateSv.addManagerCard(seManagerCard); | 
|---|
|  |  |  | if (managerCardId == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.CREATE_MANAGER_CARD_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(cardNum); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //Map map = new HashMap(); | 
|---|
|  |  |  | //map.put("cardNum", cardNum); | 
|---|
|  |  |  | //return BaseResponseUtils.buildSuccess(map) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取充值记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/getRecharges") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoRecharge>>> get(QoRecharge vo){ | 
|---|
|  |  |  | // 如果传入的是10位的水卡编号,升为17位水卡编号 | 
|---|
|  |  |  | if(vo != null && vo.getCardNum() != null) { | 
|---|
|  |  |  | String cardNumS = String.valueOf(vo.getCardNum()).trim(); | 
|---|
|  |  |  | if(cardNumS.length() == 10) { | 
|---|
|  |  |  | cardNumS = "100000" + cardNumS.substring(0,6) + "0" + cardNumS.substring(6); | 
|---|
|  |  |  | vo.setCardNum(Long.parseLong(cardNumS)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoRecharge>>> get(QoRecharge vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoRecharge>> res = cardOperateSv.getRecharges(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取充值记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取充值记录,管理平台充值列表使用,APP未使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/getRechargesNew") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoRechargeNew>>> getRechargesNew(QoRecharge vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoRechargeNew>> res = cardOperateSv.getRechargesNew(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取充值记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取返还记录,管理平台充值列表使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/refunds") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoRefund>>> getRefunds(QoRecharge vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoRefund>> res = cardOperateSv.getRefunds(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取返还记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取水卡消费记录,管理平台使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/expends") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoExpend>>> getExpends(QoRecharge vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoExpend>> res = cardOperateSv.getExpends(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 = BaClient.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "getTransactions") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Map> getOperates(QoTransaction vo){ | 
|---|
|  |  |  | public BaseResponse<Map> getOperates(QoTransaction vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Map res = cardOperateSv.getTransactions(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(cardOperateSv.getTransactions(vo)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询交易记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据指定条件获取开卡记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/getActiveCards") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoActiveCard>>> getActiveCards(QoActiveCard vo){ | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoActiveCard>>> getActiveCards(QoActiveCard vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoActiveCard>> res = cardOperateSv.getActiveCards(vo); | 
|---|
|  |  |  | if(res.itemTotal == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SellResultCode.No_ActiveCards.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            if(res.itemTotal == 0) { | 
|---|
|  |  |  | //                return BaseResponseUtils.buildErrorMsg(SellResultCode.No_ActiveCards.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取开卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据指定条件获取补卡记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/getReissueCards") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoReissueCard>>> getReissueCards(QoReissueCard vo){ | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoReissueCard>>> getReissueCards(QoReissueCard vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoReissueCard>> res = cardOperateSv.getReissueCards(vo); | 
|---|
|  |  |  | if(res.itemTotal == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SellResultCode.No_ReissueCards.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            if(res.itemTotal == 0) { | 
|---|
|  |  |  | //                return BaseResponseUtils.buildErrorMsg(SellResultCode.No_ReissueCards.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取补卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 根据指定条件获取通用操作记录 | 
|---|
|  |  |  | * 注销、挂失、冲正、解锁通用 | 
|---|
|  |  |  | * 注销-3,挂失-6,冲正-7,解锁-8 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/getOptions") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoOperate>>> getCommonOperations(QoCommonOperate vo){ | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoOperate>>> getCommonOperations(QoCommonOperate vo) { | 
|---|
|  |  |  | // 验证操作类型是否正确 | 
|---|
|  |  |  | Integer operateType = Optional.ofNullable(vo.getOperateType()).orElse(0); | 
|---|
|  |  |  | if(operateType != 3 && operateType != 6 && operateType != 7 && operateType != 8) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SellResultCode.PARAMS_ERROR.getMessage()); | 
|---|
|  |  |  | if (operateType != 3 && operateType != 6 && operateType != 7 && operateType != 8) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(SellResultCode.PARAMS_ERROR.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoOperate>> res = cardOperateSv.getCommonOperations(vo); | 
|---|
|  |  |  | if(res.itemTotal == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SellResultCode.No_CANCELS.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            if(res.itemTotal == 0) { | 
|---|
|  |  |  | //                return BaseResponseUtils.buildErrorMsg(SellResultCode.No_CANCELS.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取开卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据指定条件获取收据列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/get_receipts") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Map> getReceipts(QoReceipt vo){ | 
|---|
|  |  |  | public BaseResponse<Map> getReceipts(QoReceipt vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Map res = Optional.ofNullable(cardOperateSv.getReceipts(vo)).orElse(new HashMap()); | 
|---|
|  |  |  | if(res.size() == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SellResultCode.No_RECEIPTS.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(cardOperateSv.getReceipts(vo)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取电子钱包账户记录", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 金额转大写 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param amount | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | AmountToChinese amountToChinese = new AmountToChinese(); | 
|---|
|  |  |  | String chinese = amountToChinese.toChinese(amount); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(chinese) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(chinese); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|