From 026447959141110afd24d18b61da953c62aa2209 Mon Sep 17 00:00:00 2001 From: zhubaomin <470473919@qq.com> Date: 星期三, 23 四月 2025 12:23:55 +0800 Subject: [PATCH] 各轮灌组开阀时间提前2分钟,第一组除外 --- pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardSv.java | 573 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 573 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardSv.java new file mode 100644 index 0000000..a0912b9 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/virtualCard/VirtualCardSv.java @@ -0,0 +1,573 @@ +package com.dy.pipIrrWechat.virtualCard; + +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; +import com.dy.pipIrrGlobal.daoPr.PrIntakeVcMapper; +import com.dy.pipIrrGlobal.daoSe.*; +import com.dy.pipIrrGlobal.pojoIr.IrPlanOperate; +import com.dy.pipIrrGlobal.pojoPr.PrIntakeVc; +import com.dy.pipIrrGlobal.pojoSe.*; +import com.dy.pipIrrGlobal.voPr.VoIntakeSimple; +import com.dy.pipIrrGlobal.voSe.VoOrders; +import com.dy.pipIrrGlobal.voSe.VoRechargeProfile; +import com.dy.pipIrrGlobal.voSe.VoVcRecharge; +import com.dy.pipIrrGlobal.voSe.VoVirtualCard; +import com.dy.pipIrrWechat.irrigatePlan.enums.OperateTypeENUM; +import com.dy.pipIrrWechat.result.WechatResultCode; +import com.dy.pipIrrWechat.virtualCard.dto.DtoRegist; +import com.dy.pipIrrWechat.virtualCard.dto.DtoVirtualCard; +import com.dy.pipIrrWechat.virtualCard.enums.LastOperateENUM; +import com.dy.pipIrrWechat.virtualCard.enums.OrderStateENUM; +import com.dy.pipIrrWechat.virtualCard.qo.QoVcRecharge; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * @author ZhuBaoMin + * @date 2024-07-15 9:39 + * @LastEditTime 2024-07-15 9:39 + * @Description + */ + +@Slf4j +@Service +public class VirtualCardSv { + @Autowired + private SeVirtualCardMapper seVirtualCardMapper; + + @Autowired + private SeVcRechargeMapper seVcRechargeMapper; + + @Autowired + private SeVcRefundMapper seVcRefundMapper; + + @Autowired + private SeVcRefundItemMapper seVcRefundItemMapper; + + @Autowired + private SeClientMapper seClientMapper; + + @Autowired + private SeVcOperateMapper seVcOperateMapper; + + @Autowired + private SeRechargeProfileMapper seRechargeProfileMapper; + + @Autowired + private PrIntakeMapper prIntakeMapper; + + @Autowired + private PrIntakeVcMapper prIntakeVcMapper; + + @Value("${vc.alarmValue}") + private Integer alarmValue; + + /** + * 鏍规嵁鍐滄埛ID鑾峰彇5绾ц鏀垮尯鍒掍唬鐮侊紝娉ㄥ唽铏氭嫙鍗′娇鐢� + * + * @param clientId 鍐滄埛ID + * @return 5绾ц鏀垮尯鍒掍唬鐮� + */ + public Long getAreaCodeById(Long clientId) { + return seClientMapper.getAreaCodeById(clientId); + } + + /** + * 鑾峰彇鍐滄埛鍏ㄩ儴铏氭嫙鍗� + * + * @return + */ + public List<VoVirtualCard> getVCs(Long clientId) { + return seVirtualCardMapper.getVCs(alarmValue, clientId); + } + + /** + * 鏍规嵁铏氭嫙鍗D鑾峰彇铏氭嫙鍗″璞� + * + * @param vcId + * @return + */ + public VoVirtualCard getVcById(Long vcId) { + return seVirtualCardMapper.getVcById(vcId); + } + + /** + * 娉ㄥ唽铏氭嫙鍗� + * + * @param po + * @return + */ + public Long insertVirtualCard(SeVirtualCard po) { + seVirtualCardMapper.insert(po); + return po.getId(); + } + + /** + * 鏍规嵁鍐滄埛ID鍙婅櫄鎷熷崱ID鑾峰彇姝e父鐘舵�佺殑铏氭嫙鍗″璞� + * + * @param clientId + * @param vcId + * @return + */ + public SeVirtualCard getVcByClientIdAndVcId(Long clientId, Long vcId) { + return seVirtualCardMapper.getVcByClientIdAndVcId(clientId, vcId); + } + + /** + * 鏍规嵁铏氭嫙鍗D娉ㄩ攢铏氭嫙鍗� + * + * @param clientId + * @param vcId + * @return + */ + public Integer cancelVc(Long clientId, Long vcId) { + return seVirtualCardMapper.cancelVc(clientId, vcId); + } + + /** + * 鏍规嵁琛屾斂鍖哄垝涓叉ā绯婃煡璇㈣櫄鎷熷崱缂栧彿锛屾敞鍐岃櫄鎷熷崱浣跨敤 + * + * @param areaCode + * @return + */ + String getVcCardNumOfMax(String areaCode) { + return seVirtualCardMapper.getVcCardNumOfMax(areaCode); + } + + /** 搴熷純 + * 楠岃瘉鍐滄埛鏄惁鎷ユ湁鎸囧畾鍚嶇О鐨勮櫄鎷熷崱 + * @param po + * @return + */ + //public Integer getRecordCountByName(DtoRegist po) { + // return seVirtualCardMapper.getRecordCountByName(po.getClientId(), po.getVcName()); + //} + + /** + * 淇敼铏氭嫙鍗� + * 鍏呭�笺�佹秷璐广�佺敵璇烽��娆俱�佸鏍搁��娆炬椂闇�瑕佷慨鏀硅櫄鎷熷崱鐨勶細浣欓銆佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂� + * + * @param po + * @return + */ + public Integer updateVirtualCard(SeVirtualCard po) { + return seVirtualCardMapper.updateByPrimaryKeySelective(po); + } + + /** + * 鏍规嵁铏氭嫙鍗$紪鍙疯幏鍙栬櫄鎷熷崱瀵硅薄 + * + * @param virtualId + * @return + */ + public SeVirtualCard selectVirtuCardById(Long virtualId) { + return seVirtualCardMapper.selectByPrimaryKey(virtualId); + } + + /** + * 娣诲姞铏氭嫙鍗″厖鍊艰褰� + * JSAPI涓嬪崟鍚庣敓鎴愰儴鍒嗗厖鍊艰褰� + * + * @param po + * @return -1锛氳櫄鎷熷崱涓嶅瓨鍦紝0锛氭坊鍔犲厖鍊艰褰曞け璐� + */ + //public BaseResponse<Boolean> insertVCRecharge(DtoVirtualCard po) { + public Long insertVCRecharge(DtoVirtualCard po) { + String orderNumber = po.getOrderNumber(); + Long virtualId = po.getVirtualId(); + Long clientId = po.getClientId(); + Double rechargeAmount = po.getRechargeAmount(); + + // 楠岃瘉璇ヨ櫄鎷熷崱璐︽埛鏄惁瀛樺湪骞跺彇鍑哄綋鍓嶈处鎴蜂綑棰� + SeVirtualCard seVirtualCard = seVirtualCardMapper.selectByPrimaryKey(virtualId); + + if (seVirtualCard == null) { + return -1L; + } + Double money = seVirtualCard.getMoney(); + + // 娣诲姞鍏呭�艰褰� + SeVcRecharge seVcRecharge = new SeVcRecharge(); + seVcRecharge.setVcId(virtualId); + seVcRecharge.setClientId(clientId); + seVcRecharge.setMoney(money); + seVcRecharge.setOrderNumber(orderNumber); + seVcRecharge.setRechargeAmount(rechargeAmount); + seVcRecharge.setOrderTime(new Date()); + seVcRecharge.setOrderState(OrderStateENUM.NON_PAYMENT.getCode()); + seVcRechargeMapper.insert(seVcRecharge); + Long rechargeId = seVcRecharge.getId(); + if (rechargeId == null) { + return 0L; + } + return rechargeId; + } + + /** + * 鏍规嵁璁㈠崟鍙疯幏鍙栬櫄鎷熷崱鍏呭�煎璞� + * + * @param orderNumber + * @return + */ + public SeVcRecharge getVCRechargeByorderNumber(String orderNumber) { + return seVcRechargeMapper.getVCRechargeByorderNumber(orderNumber); + } + + /** + * 淇敼铏氭嫙鍗″厖鍊艰褰� + * 寰俊鏀粯閫氱煡鍚庯細 + * 1. 鏇存柊鍏呭�艰〃锛氬厖鍊煎悗浣欓銆佹敮浠樺畬鎴愭椂闂淬�佽鍗曠姸鎬� + * 2. 鏇存柊铏氭嫙鍗¤〃锛氳处鎴蜂綑棰濄�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂� + * + * @param orderNumber 璁㈠崟缂栧彿 + * @return + */ + @Transactional(rollbackFor = Exception.class) + public BaseResponse<Boolean> updateVCRecharge(String orderNumber, Date rechargeTime) { + SeVcRecharge seVcRecharge = seVcRechargeMapper.getVCRechargeByorderNumber(orderNumber); + if (seVcRecharge == null) { + return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_NOT_EXIST.getMessage()); + } + + Long virtualId = seVcRecharge.getVcId(); + Double money = seVcRecharge.getMoney(); + Double rechargeAmount = seVcRecharge.getRechargeAmount(); + Double afterRrecharge = money + rechargeAmount; + + seVcRecharge.setAfterRecharge(afterRrecharge); + seVcRecharge.setRechargeTime(rechargeTime); + seVcRecharge.setOrderState(OrderStateENUM.PAID.getCode()); + Integer rec = seVcRechargeMapper.updateByPrimaryKeySelective(seVcRecharge); + if (rec == null) { + return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_FAIL.getMessage()); + } + + SeVirtualCard seVirtualCard = seVirtualCardMapper.selectByPrimaryKey(virtualId); + if (seVirtualCard == null) { + return BaseResponseUtils.buildFail(WechatResultCode.VIRTUAL_CARD_NOT_EXIST.getMessage()); + } + seVirtualCard.setMoney(afterRrecharge); + seVirtualCard.setLastOperate(LastOperateENUM.RECHARGE.getCode()); + seVirtualCard.setLastOperateTime(new Date()); + Integer rec2 = seVirtualCardMapper.updateByPrimaryKeySelective(seVirtualCard); + if (rec2 == null) { + return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_FAIL.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + /** + * 淇敼铏氭嫙鍗″厖鍊艰褰曪紙搴熷純锛� + * 寰俊灏忕▼搴忔敮浠橀�氱煡鍚庝慨鏀癸細浣欓銆佸厖鍊煎悗浣欓銆佸厖鍊煎畬鎴愭椂闂� + * + * @param po + * @return + */ + public Integer updateVCRecharge(SeVcRecharge po) { + return seVcRechargeMapper.updateByPrimaryKeySelective(po); + } + + /** + * 鏍规嵁铏氭嫙鍗″彿鑾峰彇璁㈠崟鍒楄〃 + * + * @param virtualId + * @return + */ + public List<VoOrders> selectOrders(Long virtualId) { + List<VoOrders> rsVo = seVcRechargeMapper.getOrders(virtualId); + return rsVo; + } + + /** + * 鏍规嵁閫�娆綢D鑾峰彇閫�娆惧璞� + * + * @param refundId + * @return + */ + public SeVcRefund selectRefundByRefundId(Long refundId) { + return seVcRefundMapper.selectByPrimaryKey(refundId); + } + + /** + * 娣诲姞閫�娆剧敵璇� + * + * @param po + * @return + */ + public Long addRefund(SeVcRefund po) { + seVcRefundMapper.insert(po); + return po.getId(); + } + + /** + * 淇敼閫�娆捐褰� + * + * @param po + * @return + */ + public Integer updateRefund(SeVcRefund po) { + return seVcRefundMapper.updateByPrimaryKeySelective(po); + } + + /** + * 鏍规嵁璁㈠崟鍙疯幏鍙栧叾鍚勭瑪閫�娆鹃噾棰� + * + * @param orderNumber + * @return + */ + public List<Integer> selectRefundAmount(String orderNumber) { + List<Integer> rsVo = seVcRefundMapper.getRefundAmount(orderNumber); + return rsVo; + } + + /** + * 娣诲姞閫�娆惧垎椤� + * + * @param po + * @return + */ + public Long addRefundItem(SeVcRefundItem po) { + seVcRefundItemMapper.insert(po); + return po.getRefundId(); + } + + /** + * 缂栬緫閫�娆惧垎椤� + * + * @param po + * @return + */ + public Integer updateRefundItem(SeVcRefundItem po) { + return seVcRefundItemMapper.updateByPrimaryKeySelective(po); + } + + /** + * 鏍规嵁璁㈠崟鍙风敓鎴愰��娆惧崟鍙� + * + * @param orderNumber + * @return + */ + public String generateRefundNumber(String orderNumber) { + String refundNumber = seVcRefundItemMapper.getLastRefundNumber(orderNumber); + if (refundNumber == null) { + refundNumber = orderNumber + "01"; + return refundNumber; + } + + String a = String.format("%02d", (Integer.parseInt(refundNumber.substring(29, 30).trim()) + 1)); + return a; + } + + /** + * 鏍规嵁璁㈠崟鍙疯幏鍙栧厖鍊奸噾棰濓紝璋冪敤閫�娆剧敵璇锋帴鍙d娇鐢� + * + * @param orderNumber + * @return + */ + public Double getRechargeAmountByOrderNumber(String orderNumber) { + return seVcRechargeMapper.getRechargeAmountByOrderNumber(orderNumber); + + } + + /** + * 鏍规嵁閫�娆鹃�氱煡鎺ュ彛杩斿洖鐨勯��娆惧崟鍙峰弽鏌ラ��娆綢D锛屾煡璇㈣閫�娆綢D涓嬫湭閫�娆捐褰曟暟閲� + * + * @param refundNumber + * @return + */ + public Integer getNoRefundedCount(String refundNumber) { + return seVcRefundItemMapper.getNoRefundedCount(refundNumber); + } + + /** + * 鏍规嵁閫�娆惧崟鍙疯幏鍙栭��娆綢D锛岄��娆鹃�氱煡鍚庢洿鏂伴��娆捐〃鎵�闇� + * + * @param refundNumber + * @return + */ + public Long getRefundIdByRefundNumber(String refundNumber) { + return seVcRefundItemMapper.getRefundIdByRefundNumber(refundNumber); + } + + /** + * 鑾峰彇铏氭嫙鍗″厖鍊艰褰� + * + * @param dtoVcRecharge + * @return + */ + public QueryResultVo<List<VoVcRecharge>> getVcRechargeRecords(QoVcRecharge dtoVcRecharge) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(dtoVcRecharge); + Long itemTotal = seVirtualCardMapper.getRechargeRecordCount(params); + + QueryResultVo<List<VoVcRecharge>> rsVo = new QueryResultVo<>(); + rsVo.pageSize = dtoVcRecharge.pageSize; + rsVo.pageCurr = dtoVcRecharge.pageCurr; + + rsVo.calculateAndSet(itemTotal, params); + rsVo.obj = seVirtualCardMapper.getVcRechargeRecords(params); + + return rsVo; + } + + /** + * 娣诲姞铏氭嫙鍗℃搷浣滆褰� + * + * @param po + * @return + */ + public Long insertVcOperate(SeVcOperate po) { + seVcOperateMapper.insert(po); + return po.getId(); + } + + /** + * 鑾峰彇铏氭嫙鍗″父鐢ㄥ厖鍊奸噾棰濋厤缃� + * + * @return + */ + public List<VoRechargeProfile> gerRechargeProfiles() { + return seRechargeProfileMapper.gerRechargeProfiles(); + } + + /** + * 娉ㄥ唽铏氭嫙鍗� + * + * @param clientId + * @return + */ + public Map addVC(Long clientId, Double money) { + // 鑾峰彇5绾ц鏀垮尯鍒掍覆areaCode + Long areaCodeL = getAreaCodeById(clientId); + if (areaCodeL == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", WechatResultCode.AREA_CODE_MISTAKE.getMessage()); + map.put("content", null); + return map; + } + String areaCode = String.valueOf(areaCodeL); + + /** + * 鏍规嵁琛屾斂鍖哄垝涓诧紙areaCode锛夊湪铏氭嫙鍗¤〃涓拡瀵硅櫄鎷熷崱缂栧彿锛坴cNum锛夎繘琛屾ā绯婃煡璇� + * 濡傛灉5浣嶉『搴忓彿宸茬粡杈惧埌鏈�澶у�硷紝鎻愮ず鐢ㄦ埛鑱旂郴绯荤粺绠$悊鍛� + * 濡傛灉5浣嶉『搴忓彿鏈揪鍒版渶澶у�硷紝鍒欏姞1 + * cardNum涓烘柊鐨勫崱鍙� + */ + String vcNum = Optional.ofNullable(getVcCardNumOfMax(areaCode)).orElse(""); + if (vcNum != null && vcNum.trim().length() > 0) { + Integer number = Integer.parseInt(vcNum.substring(12)); + number = number + 1; + if (number > 65535) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", WechatResultCode.CARD_NUMBER_OVERRUN.getMessage()); + map.put("content", null); + return map; + } + vcNum = vcNum.substring(0, 12) + String.format("%05d", number); + } else { + vcNum = areaCode + "00001"; + } + + // 鐢熸垚铏氭嫙鍗¤褰� + SeVirtualCard seVirtualCard = new SeVirtualCard(); + seVirtualCard.setVcNum(Long.parseLong(vcNum)); + seVirtualCard.setClientId(clientId); + seVirtualCard.setMoney(money); + seVirtualCard.setState((byte) 1); + seVirtualCard.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode()); + seVirtualCard.setLastOperateTime(new Date()); + seVirtualCard.setInUse((byte) 0); + seVirtualCard.setCreateTime(new Date()); + Long vcId = insertVirtualCard(seVirtualCard); + if (vcId == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); + map.put("content", null); + return map; + } + + // 鐢熸垚铏氭嫙鍗℃搷浣滆褰曪紝娉ㄥ唽铏氭嫙鍗℃搷浣滀汉涓哄啘鎴� + SeVcOperate seVcOperate = new SeVcOperate(); + seVcOperate.setVcId(vcId); + seVcOperate.setClientId(clientId); + seVcOperate.setOperateType(LastOperateENUM.OPEN_ACCOUNT.getCode()); + seVcOperate.setOperator(clientId); + seVcOperate.setOperateTime(new Date()); + Long vcOperateId = insertVcOperate(seVcOperate); + if (vcOperateId == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); + map.put("content", null); + return map; + } + + Map map = new HashMap<>(); + map.put("success", true); + map.put("msg", "铏氭嫙鍗℃敞鍐屾垚鍔�"); + map.put("content", vcId); + return map; + } + + /** + * 鑾峰彇鏈粦瀹氳櫄鎷熷崱鐨勫彇姘村彛鍒楄〃锛岀粰鍙栨按鍙g粦铏氭嫙鍗′娇鐢� + * + * @return + */ + public Map linkVcToIntake(Long clientId) { + // 楠岃瘉鏄惁瀛樺湪鍙栨按鍙f湭缁戣櫄鎷熷崱 + List<VoIntakeSimple> list = prIntakeMapper.getNotLinkVcIntakes(); + if (list == null || list.size() == 0) { + Map map = new HashMap<>(); + map.put("success", true); + map.put("msg", "鎵�鏈夊彇姘村彛閮藉尮閰嶄簡铏氭嫙鍗�"); + map.put("content", null); + return map; + } + + // 閬嶅巻鎵�鏈夋湭缁戣櫄鎷熷崱鐨勫彇姘村彛 + for (VoIntakeSimple voIntakeSimple : list) { + Long intakeId = voIntakeSimple.getIntakeId(); + + // 鍒涘缓铏氭嫙鍗� + Map map_result = addVC(clientId, 100000D); + if (map_result.get("success").equals(false)) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", "鐏岃櫄鎷熷崱娉ㄥ唽澶辫触"); + map.put("content", null); + return map; + } + Long vcId = (Long) map_result.get("content"); + + // 鍙栨按鍙g粦铏氭嫙鍗� + PrIntakeVc intakeVc = new PrIntakeVc(); + intakeVc.setIntakeId(intakeId); + intakeVc.setVcId(vcId); + Integer result = prIntakeVcMapper.insert(intakeVc); + + if (result == null) { + Map map = new HashMap<>(); + map.put("success", false); + map.put("msg", "鍙栨按鍙g粦铏氭嫙鍗″け璐�"); + map.put("content", null); + return map; + } + } + Map map = new HashMap<>(); + map.put("success", true); + map.put("msg", "鍙栨按鍙g粦铏氭嫙鍗℃垚鍔�"); + map.put("content", null); + return map; + } +} \ No newline at end of file -- Gitblit v1.8.0