From dc3a3b4993c8a205a7932328d149bd7cfc94cf06 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期日, 27 四月 2025 10:36:00 +0800 Subject: [PATCH] @Value注解增加默认值 --- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/activeCard/ActiveCardCtrl.java | 332 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 332 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/activeCard/ActiveCardCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/activeCard/ActiveCardCtrl.java new file mode 100644 index 0000000..2121d22 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/activeCard/ActiveCardCtrl.java @@ -0,0 +1,332 @@ +package com.dy.pipIrrSell.activeCard; + +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.daoBa.BaSettingsMapper; +import com.dy.pipIrrGlobal.pojoSe.SeActiveCard; +import com.dy.pipIrrGlobal.pojoSe.SeClientCard; +import com.dy.pipIrrGlobal.util.Constant; +import com.dy.pipIrrGlobal.voSe.VoActiveCard; +import com.dy.pipIrrSell.cardOperate.enums.OperateTypeENUM; +import com.dy.pipIrrSell.clientCard.CardStateENUM; +import com.dy.pipIrrSell.clientCard.ClientCardSv; +import com.dy.pipIrrSell.clientCard.LastOperateENUM; +import com.dy.pipIrrSell.recharge.DtoRecharge; +import com.dy.pipIrrSell.recharge.RechargeCtrl; +import com.dy.pipIrrSell.recharge.RechargeSv; +import com.dy.pipIrrSell.result.SellResultCode; +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 io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +/** + * @author ZhuBaoMin + * @date 2023/12/5 20:06 + * @LastEditTime 2023/12/5 20:06 + * @Description + */ + +@Slf4j +@Tag(name = "寮�鍗$鐞�", description = "寮�鍗℃搷浣�") +@RestController +@RequestMapping(path="activecard") +@RequiredArgsConstructor +public class ActiveCardCtrl { + private final ActiveCardSv activeCardSv; + private final ClientCardSv clientCardSv; + private final RechargeCtrl rechargeCtrl; + private final RechargeSv rechargeSv; + private final BaSettingsMapper baSettingsMapper; + + + //@Value("${projectCode.ym}") + //private Integer projectCode; + + /** + * 鑾峰彇寮�鍗¤褰� + * @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 = VoActiveCard.class))} + ) + }) + @GetMapping(path = "/getActiveCards") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoActiveCard>>> getActiveCards(QueryVo vo){ + try { + QueryResultVo<List<VoActiveCard>> res = activeCardSv.getActiveCards(vo); + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 寮�鍗℃搷浣� + * @param po + * @param bindingResult + * @return + */ + @Operation(summary = "寮�鍗�", description = "鏂板紑鍐滄埛鍗�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "add_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()); + } + + /** + * 鑾峰彇5绾ц鏀垮尯鍒掍覆areaCode + * provinceId 鐪佺骇鍖哄垝浠g爜 + * cityId 甯傜骇鍖哄垝浠g爜 + * countryId 鍘跨骇鍖哄垝浠g爜 + * townId 闀囩骇鍖哄垝浠g爜 + * villageId 鏉戠骇鍖哄垝浠g爜 + */ + //VoAreaCode voAreaCode = activeCardSv.getAreaCodeByNum(po.getClientNum()); + //if(voAreaCode == null) { + // return BaseResponseUtils.buildFail(SellResultCode.AREA_CODE_MISTAKE.getMessage()); + //} + //String provinceId = voAreaCode.getProvinceId(); + //String cityId = voAreaCode.getCityId(); + //String countryId = voAreaCode.getCountryId(); + //String townId = voAreaCode.getTownId(); + //String villageId = voAreaCode.getVillageId(); + //String areaCode = provinceId + cityId + countryId + townId + villageId; + + String areaCode = String.valueOf(activeCardSv.getAreaCodeByNum(po.getClientNum())); + + /** + * 鏍规嵁琛屾斂鍖哄垝涓诧紙areaCode锛夊湪姘村崱琛ㄤ腑閽堝姘村崱缂栧彿锛坈ardNum锛夎繘琛屾ā绯婃煡璇� + * 濡傛灉4浣嶉『搴忓彿宸茬粡杈惧埌鏈�澶у�硷紝鎻愮ず鐢ㄦ埛鑱旂郴绯荤粺绠$悊鍛� + * 濡傛灉4浣嶉『搴忓彿鏈揪鍒版渶澶у�硷紝鍒欏姞1 + * cardNum涓烘柊鐨勫崱鍙� + */ + String cardNum = Optional.ofNullable(activeCardSv.getCardNumOfMax(areaCode)).orElse(""); + if(cardNum != null && cardNum.trim().length() > 0) { + Integer number = Integer.parseInt(cardNum.substring(12)); + number = number + 1; + if(number > 9999) { + return BaseResponseUtils.buildFail(SellResultCode.CARD_NUMBER_OVERRUN.getMessage()); + } + cardNum = cardNum.substring(0, 12) + String.format("%04d", number); + } else { + cardNum = areaCode + "0001"; + } + + + /** + * cardAddr 姘村崱鍦板潃锛堜粎浠呭啓鍏ワ紝鏃犱笟鍔★級 + * clientNum 鍐滄埛缂栧彿 + * cardCost 鍗$墖璐圭敤 + * amount 鍏呭�奸噾棰� + * reissueAmount 琛ュ崱閲戦锛岃ˉ鍗℃椂浣跨敤 + * paymentId 鏀粯鏂瑰紡缂栧彿 + * remarks 澶囨敞 + * operator 鎿嶄綔浜虹紪鍙� + * activeTime 寮�鍗℃椂闂� + */ + String cardAddr = po.getCardAddr(); + String clientNum = po.getClientNum(); + //Long clientId = po.getClientId(); + + Integer cardCost = po.getCardCost(); + Float amount = po.getAmount(); + Long paymentId = po.getPaymentId(); + String remarks = po.getRemarks(); + Long operator = po.getOperator(); + Date createTime = new Date(); + + /** + * 鏍规嵁鍐滄埛缂栧彿鑾峰彇鍐滄埛ID + */ + Long clientId = activeCardSv.getClientIdByNum(clientNum); + + /** + * 娣诲姞鍐滄埛鍗¤褰� + */ + SeClientCard seClientCard = new SeClientCard(); + seClientCard.setCardaddr(cardAddr); + seClientCard.setCardnum(cardNum); + //seClientCard.setClientnum(clientNum); + seClientCard.setClientid(clientId); + seClientCard.setMoney(0f); + seClientCard.setState(CardStateENUM.NORMAL.getCode()); + seClientCard.setCreatedt(createTime); + seClientCard.setLastoper(LastOperateENUM.ACTIVE.getCode()); + + Long cardId = Optional.ofNullable(clientCardSv.add(seClientCard)).orElse(0L) ; + if(cardId == 0) { + return BaseResponseUtils.buildFail(SellResultCode.ACTIVE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); + } + + /** + * 娣诲姞寮�鍗¤褰� + */ + SeActiveCard activeCard = new SeActiveCard(); + //activeCard.setCardnum(cardNum); + //activeCard.setClientnum(clientNum); + + activeCard.setCardid(cardId); + activeCard.setClientid(clientId); + activeCard.setCardcost(cardCost); + activeCard.setPaymentid(paymentId); + activeCard.setOperatetype(OperateTypeENUM.ACTIVE.getCode()); + activeCard.setRemarks(remarks); + activeCard.setOperator(operator); + activeCard.setOperatedt(createTime); + Long rec = Optional.ofNullable(activeCardSv.add(activeCard)).orElse(0L); + if(rec == 0) { + return BaseResponseUtils.buildFail(SellResultCode.ACTIVE_FAIL_WRITE_ACTIVE_CARD_ERROR.getMessage()); + } + + /** + * 濡傛灉鎿嶄綔浜哄憳寮�鍗℃椂杈撳叆浜嗗厖鍊奸噾棰濓紝鍒欏紑鍗″悗璋冪敤鍏呭�煎姛鑳� + */ + po.setCardNum(Long.parseLong(cardNum)); + if(amount != null && amount > 0) { + po.setClientId(clientId); + DtoRecharge dtoRecharge = RechargeDtoMapper.INSTANCT.po2vo(po); + dtoRecharge.setMoney(0f); + dtoRecharge.setGift(0f); + dtoRecharge.setPrice(0f); + BaseResponse<Boolean> job = rechargeCtrl.addRecharge(dtoRecharge); + if(!job.getCode().equals("0001")) { + return BaseResponseUtils.buildFail(SellResultCode.ACTIVE_FAIL_RECHARGE_EXCEPTION.getMessage()); + } + } + + Map map = new HashMap(); + if(amount != null && amount > 0) { + Long rechargeId = rechargeSv.selectIdByCardId(cardId); + map.put("orderNumber",rechargeId+"");//杩斿洖鍏呭�糏D + }else { + map.put("orderNumber",rec+"");//杩斿洖寮�鍗D + } + String projectNo = baSettingsMapper.getItemValue("projectNo"); + Integer projectNo1 = Integer.valueOf(projectNo); + String projectNo3 = String.format("%02x", projectNo1); + map.put("projectNo", projectNo3); + map.put("cardNum", cardNum); + return BaseResponseUtils.buildSuccess(map) ; + } + + @Operation(summary = "琛ュ崱", description = "琛ュ崱") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "add_reissue", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> add_reissue(@RequestBody @Valid DtoActiveCard po, BindingResult bindingResult){ + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + + /** + * cardId 姘村崱缂栧彿锛堥潪浼犲叆鍙傛暟锛岀敱cardNum鍙嶆煡锛屾洿鏂版按鍗¤〃鐢級 + * cardNum 姘村崱缂栧彿 + //* clientNum 鍐滄埛缂栧彿锛堥潪浼犲叆鍙傛暟锛岀敱cardNum鍙嶆煡锛屾坊鍔犺ˉ鍗′娇鐢級 + * clientId 鍐滄埛ID锛堥潪浼犲叆鍙傛暟锛岀敱cardNum鍙嶆煡锛屾坊鍔犺ˉ鍗′娇鐢級 + * cardCost 鍗$墖璐圭敤 + * reissueAmount 琛ュ崱閲戦锛岃ˉ鍗℃椂浣跨敤 + * paymentId 鏀粯鏂瑰紡缂栧彿 + * remarks 澶囨敞 + * operator 鎿嶄綔浜虹紪鍙� + * activeTime 琛ュ崱鏃堕棿 + */ + Long cardId = 0L; + Long cardNum = po.getCardNum(); + //String clientNum = ""; + Long clientId = 0L; + Integer cardCost = po.getCardCost(); + Float reissueAmount = po.getReissueAmount(); + Long paymentId = po.getPaymentId(); + String remarks = po.getRemarks(); + Long operator = po.getOperator(); + Date replaceTime = new Date(); + + /** + * 渚濇嵁姘村崱缂栧彿鑾峰彇姘村崱琛ㄤ富閿強鍐滄埛缂栧彿 + */ + Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); + if(map == null || map.size() <= 0) { + return BaseResponseUtils.buildFail(SellResultCode.CARD_NUMBER_ERROR.getMessage()); + } + cardId = Long.parseLong(map.get("cardId").toString()); + //clientNum = map.get("clientNum").toString(); + clientId = Long.parseLong(map.get("clientId").toString()); + + /** + * 淇敼鍐滄埛鍗′俊鎭細 + * 琛ュ崱鏃堕棿 + * 鏈�鍚庢搷浣滅被鍨�-2 + */ + SeClientCard seClientCard = new SeClientCard(); + seClientCard.setId(cardId); + seClientCard.setReplacedt(replaceTime); + seClientCard.setLastoper(LastOperateENUM.REPLACE.getCode()); + Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); + if(rec_updateClientCard == 0) { + return BaseResponseUtils.buildFail(SellResultCode.REPLACE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); + } + + /** + * 娣诲姞琛ュ崱璁板綍 + */ + SeActiveCard activeCard = new SeActiveCard(); + //activeCard.setCardnum(cardNum); + //activeCard.setClientnum(clientNum); + activeCard.setCardid(cardId); + activeCard.setClientid(clientId); + activeCard.setCardcost(cardCost); + activeCard.setPaymentid(paymentId); + activeCard.setReissueamount(reissueAmount); + activeCard.setOperatetype(OperateTypeENUM.REISSUE.getCode()); + activeCard.setRemarks(remarks); + activeCard.setOperator(operator); + activeCard.setOperatedt(replaceTime); + Long rec = Optional.ofNullable(activeCardSv.add(activeCard)).orElse(0L); + if(rec == 0) { + return BaseResponseUtils.buildFail(SellResultCode.REPLACE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); + } + + return BaseResponseUtils.buildSuccess(true) ; + } +} -- Gitblit v1.8.0