diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/CardTemplateUnionBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/CardTemplateUnionBo.java index 4d08e0b..263d5d2 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/CardTemplateUnionBo.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/CardTemplateUnionBo.java @@ -146,4 +146,16 @@ public class CardTemplateUnionBo { */ @ApiModelProperty("先学后付(月付)") private LearnNowPayLaterPlanBo learnNowPayLaterMonthPay; + + /** + * 放心学旧合同 + */ + @ApiModelProperty("放心学旧合同") + private EasyLearnOldContractBo easyLearnOldContract; + + /** + * 放心学数币 + */ + @ApiModelProperty("放心学数币") + private EasyLearnDigitalCurrencyBo easyLearnDigitalCurrency; } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnDigitalCurrencyBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnDigitalCurrencyBo.java new file mode 100644 index 0000000..edfdfe7 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnDigitalCurrencyBo.java @@ -0,0 +1,31 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-19 9:44 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "EasyLearnDigitalCurrencyBo对象", description = "放心学数币参数") +public class EasyLearnDigitalCurrencyBo { + + /** + * 是否是数币活动 + */ + private Boolean isActivity; + + /** + * 活动码 + */ + private String activityCode; + + /** + * 活动描述 + */ + private String activityDesc; +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnOldContractBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnOldContractBo.java new file mode 100644 index 0000000..eb1f145 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/EasyLearnOldContractBo.java @@ -0,0 +1,37 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-19 9:36 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "EasyLearnOldContractBo对象", description = "放心学旧合同参数") +public class EasyLearnOldContractBo { + + /** + * 期数 + */ + @ApiModelProperty("期数") + private Integer stageNum; + + /** + * 押金 + */ + @ApiModelProperty("押金") + private BigDecimal deposit; + + /** + * 首期缓冲天数 + */ + @ApiModelProperty("首期缓冲天数") + private Integer firstBufferDay; +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java deleted file mode 100644 index fb9c8fb..0000000 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.cpop.jambox.business.controller.backstage; - -import com.cpop.core.base.R; -import com.cpop.jambox.business.bo.CardTemplateUnionBo; -import com.cpop.jambox.business.service.CardTemplateService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * 果酱-课卡模板 控制层。 - * - * @author DB - * @since 2023-09-27 - */ -@RestController -@Api(tags = "果酱-课卡模板接口") -@RequestMapping("/cardTemplate") -public class CardTemplateController { - - @Autowired - private CardTemplateService cardTemplateService; - - /** - * 添加课卡模板(整合) - * @author DB - * @since 2023/10/07 9:59 - * @param bo 请求参数 - */ - //@SimpleSignatureCheck - @ApiOperation(value = "添加课卡模板(整合)") - @PostMapping("/insertCardTemplateUnion") - public R insertCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) { - cardTemplateService.insertCardTemplateUnion(bo); - return R.ok(); - } - - /** - * 修改课卡模板(整合) - * @author DB - * @since 2023/10/07 9:59 - * @param bo 请求参数 - */ - //@SimpleSignatureCheck - @ApiOperation(value = "修改课卡模板(整合)") - @PostMapping("/updateCardTemplateUnion") - public R updateCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) { - cardTemplateService.updateCardTemplateUnion(bo); - return R.ok(); - } -} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java new file mode 100644 index 0000000..0d594f9 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java @@ -0,0 +1,82 @@ +package com.cpop.jambox.business.controller.mini; + +import com.cpop.core.annontation.SimpleSignatureCheck; +import com.cpop.core.base.R; +import com.cpop.core.utils.SpringUtils; +import com.cpop.jambox.business.bo.CardTemplateUnionBo; +import com.cpop.jambox.business.entity.CardTemplate; +import com.cpop.jambox.business.service.CardTemplateExtendService; +import com.cpop.jambox.business.service.CardTemplateService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.ibatis.annotations.Delete; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import static com.cpop.jambox.business.entity.table.CardTemplateExtendTableDef.CARD_TEMPLATE_EXTEND; +import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TEMPLATE; + +/** + * 果酱-课卡模板 控制层。 + * + * @author DB + * @since 2023-09-27 + */ +@RestController +@Api(tags = "果酱-课卡模板接口") +@RequestMapping("/mini/cardTemplate") +public class CardTemplateController { + + @Autowired + private CardTemplateService cardTemplateService; + + /** + * 添加课卡模板(整合) + * @author DB + * @since 2023/10/07 9:59 + * @param bo 请求参数 + */ + //@SimpleSignatureCheck + @ApiOperation(value = "添加课卡模板(整合)") + @PostMapping("/insertCardTemplateUnion") + public R insertCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) { + cardTemplateService.insertCardTemplateUnion(bo); + return R.ok(); + } + + /** + * 修改课卡模板(整合) + * @author DB + * @since 2023/10/07 9:59 + * @param bo 请求参数 + */ + //@SimpleSignatureCheck + @ApiOperation(value = "修改课卡模板(整合)") + @PutMapping("/updateCardTemplateUnion") + public R updateCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) { + cardTemplateService.updateCardTemplateUnion(bo); + return R.ok(); + } + + /** + * 删除课卡模板 + * @author DB + * @since 2024/1/19 + * @param oldId 旧主键id + * @return R + */ + @Deprecated + @ApiOperation(value = "删除课卡模板") + @DeleteMapping("/removeCardTemplateById/{oldId}") + public R removeCardTemplateById(@PathVariable String oldId) { + CardTemplate cardTemplate = cardTemplateService.queryChain().where(CARD_TEMPLATE.OLD_TEMPLATE_ID.eq(oldId)).one(); + cardTemplateService.updateChain() + .where(CARD_TEMPLATE.OLD_TEMPLATE_ID.eq(oldId)) + .remove(); + SpringUtils.getBean(CardTemplateExtendService.class).updateChain() + .where(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(cardTemplate.getId())) + .remove(); + return R.ok(); + } +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java index 8f3d9b1..524af37 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java @@ -4,6 +4,7 @@ import com.cpop.core.base.R; import com.cpop.jambox.business.service.CardTemplateService; import com.cpop.jambox.business.service.EasyLearnOrderService; import com.cpop.jambox.business.vo.LearnNowPayLaterPlanDetailVo; +import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -36,24 +37,25 @@ public class MiniEasyLearnController { */ @ApiOperation("获取支付分计划") @GetMapping("/getWxPayScorePlan") - public R getWxPayScorePlan(@ApiParam(value = "旧模板id",required = true) @RequestParam("oldTemplateId") String oldTemplateId, - @ApiParam(value = "是否月付(0否1是)",required = true) @RequestParam("isMonth") Boolean isMonth) { - LearnNowPayLaterPlanDetailVo vo = cardTemplateService.getWxPayScorePlan(oldTemplateId,isMonth); + public R getWxPayScorePlan(@ApiParam(value = "旧模板id", required = true) @RequestParam("oldTemplateId") String oldTemplateId, + @ApiParam(value = "是否月付(0否1是)", required = true) @RequestParam("isMonth") Boolean isMonth) { + LearnNowPayLaterPlanVo vo = cardTemplateService.getWxPayScorePlan(oldTemplateId, isMonth); return R.ok(vo); } /** * 获取支付分计划 + * + * @param oldTemplateId 旧模板id + * @param isMonth 是否月付 + * @return R * @author DB * @since 2024/1/18 - * @param oldTemplateId 旧模板id - * @param isMonth 是否月付 - * @return R */ @ApiOperation("创建用户签约计划") @PostMapping("/createUserSignPlans") - public R createUserSignPlans(@ApiParam(value = "旧模板id",required = true) @RequestParam("oldTemplateId") String oldTemplateId, - @ApiParam(value = "是否月付(0否1是)",required = true) @RequestParam("isMonth") Boolean isMonth) { + public R createUserSignPlans(@ApiParam(value = "旧模板id", required = true) @RequestParam("oldTemplateId") String oldTemplateId, + @ApiParam(value = "是否月付(0否1是)", required = true) @RequestParam("isMonth") Boolean isMonth) { return R.ok(); } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/CardTemplateService.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/CardTemplateService.java index 93e00c2..c587f7e 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/CardTemplateService.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/CardTemplateService.java @@ -3,6 +3,7 @@ package com.cpop.jambox.business.service; import com.cpop.jambox.business.bo.CardTemplateUnionBo; import com.cpop.jambox.business.entity.CardTemplate; import com.cpop.jambox.business.vo.LearnNowPayLaterPlanDetailVo; +import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.service.IService; @@ -49,5 +50,5 @@ public interface CardTemplateService extends IService { * @param isMonth 是否月付 * @return LearnNowPayLaterPlanDetailVo */ - LearnNowPayLaterPlanDetailVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth); + LearnNowPayLaterPlanVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth); } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java index 4277dc0..23b3417 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java @@ -4,6 +4,8 @@ import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.jambox.business.bo.CardTemplateUnionBo; +import com.cpop.jambox.business.bo.EasyLearnDigitalCurrencyBo; +import com.cpop.jambox.business.bo.EasyLearnOldContractBo; import com.cpop.jambox.business.entity.BrandExtend; import com.cpop.jambox.business.entity.CardTemplate; import com.cpop.jambox.business.entity.CardTemplateExtend; @@ -14,9 +16,13 @@ import com.cpop.jambox.business.service.CardTemplateExtendService; import com.cpop.jambox.business.service.CardTemplateService; import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.jambox.business.vo.LearnNowPayLaterPlanDetailVo; +import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo; import com.cpop.jambox.framework.tasks.LearnNowPayLaterTask; import com.cpop.system.business.entity.Store; +import com.cpop.system.business.entity.WxPayScoreDetail; import com.cpop.system.business.service.StoreService; +import com.cpop.system.business.service.WxPayScoreDetailService; +import com.cpop.system.business.service.WxPayScoreService; import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; @@ -27,12 +33,15 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; import static com.cpop.jambox.business.entity.table.CardTemplateExtendTableDef.CARD_TEMPLATE_EXTEND; import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TEMPLATE; import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND; +import static com.cpop.system.business.entity.table.WxPayScoreDetailTableDef.WX_PAY_SCORE_DETAIL; +import static com.cpop.system.business.entity.table.WxPayScoreTableDef.WX_PAY_SCORE; /** * 果酱-课卡模板 服务层实现。 @@ -90,15 +99,7 @@ public class CardTemplateServiceImpl extends ServiceImpl cardTemplateExtends = new ArrayList<>(); - //添加课卡模板拓展 - bo.getPayType().forEach(item->{ - //TODO: 新增模板拓展 - CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); - cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(item); - cardTemplateExtends.add(cardTemplateExtend); - }); - SpringUtils.getBean(CardTemplateExtendService.class).saveBatch(cardTemplateExtends); + saveTemplateExtend(cardTemplate,bo); //次付 if (bo.getPayType().contains(1)) { SpringUtils.getBean(LearnNowPayLaterTask.class).asyncCreateLearnNowPayLaterPlan(cardTemplate, bo.getLearnNowPayLaterPay(), 1); @@ -109,6 +110,51 @@ public class CardTemplateServiceImpl extends ServiceImpl cardTemplateExtends = new ArrayList<>(); + List payTypeList = bo.getPayType(); + //普通微信支付 + if (payTypeList.contains(0)){ + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(0); + cardTemplateExtends.add(cardTemplateExtend); + } + //放心学合约支付 + if (payTypeList.contains(2)){ + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + EasyLearnOldContractBo easyLearnOldContract = bo.getEasyLearnOldContract(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(2) + .setExtendParamOne(easyLearnOldContract.getStageNum().toString()) + .setExtendParamTwo(easyLearnOldContract.getDeposit().toString()) + .setExtendParamThree(easyLearnOldContract.getFirstBufferDay().toString()); + cardTemplateExtends.add(cardTemplateExtend); + } + //数字人民币支付 + if (payTypeList.contains(3)){ + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + EasyLearnDigitalCurrencyBo easyLearnDigitalCurrency = bo.getEasyLearnDigitalCurrency(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(3) + .setExtendParamOne(easyLearnDigitalCurrency.getIsActivity().toString()) + .setExtendParamTwo(easyLearnDigitalCurrency.getActivityCode()) + .setExtendParamThree(easyLearnDigitalCurrency.getActivityDesc()); + cardTemplateExtends.add(cardTemplateExtend); + } + //线下支付 + if (payTypeList.contains(4)){ + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(4); + cardTemplateExtends.add(cardTemplateExtend); + } + SpringUtils.getBean(CardTemplateExtendService.class).saveBatch(cardTemplateExtends); + } + /** * 修改课卡模板(整合) * @author DB @@ -122,10 +168,7 @@ public class CardTemplateServiceImpl extends ServiceImpl cardTemplateExtends = cardTemplateExtendService.list(QueryWrapper.create() .where(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(bo.getOldTemplateId()))); - //添加课卡模板拓展 - List filterPayType = bo.getPayType().stream().filter(item -> item != 1 && item != 5).collect(Collectors.toList()); - //TODO: 新增或修改模板拓展 - + updateTemplateExtend(cardTemplate, bo, cardTemplateExtends); //次付 List payTypeList = cardTemplateExtends.stream().map(CardTemplateExtend::getPayType).collect(Collectors.toList()); if (bo.getPayType().contains(1) && !payTypeList.contains(1)) { @@ -153,6 +196,83 @@ public class CardTemplateServiceImpl extends ServiceImpl cardTemplateExtends) { + List payTypeList = bo.getPayType(); + Map existExtends = cardTemplateExtends.stream().collect(Collectors.toMap(CardTemplateExtend::getPayType, item -> item)); + List removePayTypes = new ArrayList<>(); + //普通微信支付 + if (payTypeList.contains(0)) { + if (existExtends.get(0) == null) { + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(0); + cardTemplateExtends.add(cardTemplateExtend); + } + } else { + removePayTypes.add(0); + } + //放心学旧合约支付 + if (payTypeList.contains(2)) { + CardTemplateExtend cardTemplateExtend; + EasyLearnOldContractBo easyLearnOldContract = bo.getEasyLearnOldContract(); + if (existExtends.get(2) == null) { + cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(2) + .setExtendParamOne(easyLearnOldContract.getStageNum().toString()) + .setExtendParamTwo(easyLearnOldContract.getDeposit().toString()) + .setExtendParamThree(easyLearnOldContract.getFirstBufferDay().toString()); + } else { + cardTemplateExtend = existExtends.get(2); + cardTemplateExtend.setExtendParamOne(easyLearnOldContract.getStageNum().toString()) + .setExtendParamTwo(easyLearnOldContract.getDeposit().toString()) + .setExtendParamThree(easyLearnOldContract.getFirstBufferDay().toString()); + } + cardTemplateExtends.add(cardTemplateExtend); + } else { + removePayTypes.add(2); + } + //数字人民币支付 + if (payTypeList.contains(3)){ + CardTemplateExtend cardTemplateExtend; + EasyLearnDigitalCurrencyBo easyLearnDigitalCurrency = bo.getEasyLearnDigitalCurrency(); + if (existExtends.get(3) == null) { + cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(3) + .setExtendParamOne(easyLearnDigitalCurrency.getIsActivity().toString()) + .setExtendParamTwo(easyLearnDigitalCurrency.getActivityCode()) + .setExtendParamThree(easyLearnDigitalCurrency.getActivityDesc()); + } else { + cardTemplateExtend = existExtends.get(3); + cardTemplateExtend.setExtendParamOne(easyLearnDigitalCurrency.getIsActivity().toString()) + .setExtendParamTwo(easyLearnDigitalCurrency.getActivityCode()) + .setExtendParamThree(easyLearnDigitalCurrency.getActivityDesc()); + } + cardTemplateExtends.add(cardTemplateExtend); + } else { + removePayTypes.add(3); + } + //线下支付 + if (payTypeList.contains(4)) { + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()).setPayType(4); + cardTemplateExtends.add(cardTemplateExtend); + } else { + removePayTypes.add(4); + } + CardTemplateExtendService cardTemplateExtendService = SpringUtils.getBean(CardTemplateExtendService.class); + cardTemplateExtendService.saveBatch(cardTemplateExtends); + cardTemplateExtendService.updateChain() + .where(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(cardTemplate.getId())) + .and(CARD_TEMPLATE_EXTEND.PAY_TYPE.in(removePayTypes)) + .remove(); + } + /** * 获取支付分计划 * @author DB @@ -162,8 +282,20 @@ public class CardTemplateServiceImpl extends ServiceImpl detailVos = SpringUtils.getBean(WxPayScoreDetailService.class).listAs(QueryWrapper.create() + .where(WX_PAY_SCORE_DETAIL.SYS_WX_PAY_SCORE_ID.eq(vo.getId())), + LearnNowPayLaterPlanDetailVo.class); + vo.setPlanDetailList(detailVos); + return vo; } } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java index 9266ea4..1c9d2b0 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java @@ -25,20 +25,20 @@ public class LearnNowPayLaterPlanDetailVo { * 计划明细原支付金额(单位分) */ @ApiModelProperty("计划明细原支付金额(单位分)") - private Integer originalPrice; + private BigDecimal originalPrice; - public void setOriginalPrice(BigDecimal originalPrice) { - this.originalPrice = originalPrice.scaleByPowerOfTen(2).intValue(); + public void setOriginalPrice(Integer originalPrice) { + this.originalPrice = new BigDecimal(originalPrice).divide(BigDecimal.valueOf(100)); } /** * 计划明细实际支付金额(单位分) */ @ApiModelProperty("计划明细实际支付金额(单位分)") - private Long actualPrice; + private BigDecimal actualPrice; - public void setActualPrice(BigDecimal actualPrice) { - this.actualPrice = actualPrice.scaleByPowerOfTen(2).longValue(); + public void setActualPrice(Integer actualPrice) { + this.actualPrice = new BigDecimal(actualPrice).divide(BigDecimal.valueOf(100)); } /** diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanVo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanVo.java index ef453cb..7d14c17 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanVo.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanVo.java @@ -16,6 +16,12 @@ import java.util.List; @ApiModel("先学后付计划") public class LearnNowPayLaterPlanVo { + /** + * 主键 + */ + @ApiModelProperty("计划分主键") + private String id; + /** * 支付分计划名称 */ @@ -39,20 +45,20 @@ public class LearnNowPayLaterPlanVo { * 支付分计划原总金额(单位分) */ @ApiModelProperty("支付分计划原总金额") - private Integer totalOriginalPrice; + private BigDecimal totalOriginalPrice; - public void setTotalOriginalPrice(BigDecimal totalOriginalPrice) { - this.totalOriginalPrice = totalOriginalPrice.scaleByPowerOfTen(2).intValue(); + public void setTotalOriginalPrice(Integer totalOriginalPrice) { + this.totalOriginalPrice = new BigDecimal(totalOriginalPrice).divide(BigDecimal.valueOf(100)); } /** * 支付分计划实际扣费总金额(单位分) */ @ApiModelProperty("支付分计划实际扣费总金额(单位分)") - private Integer totalActualPrice; + private BigDecimal totalActualPrice; - public void setTotalActualPrice(BigDecimal totalActualPrice) { - this.totalActualPrice = totalActualPrice.scaleByPowerOfTen(2).intValue(); + public void setTotalActualPrice(Integer totalActualPrice) { + this.totalActualPrice = new BigDecimal(totalActualPrice).divide(BigDecimal.valueOf(100)); } /** diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java index 49635c4..2474e68 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java @@ -1,11 +1,15 @@ package com.cpop.jambox.framework.tasks; +import com.alibaba.fastjson.JSONArray; +import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.exception.ServiceException; import com.cpop.core.utils.SpringUtils; import com.cpop.jambox.business.bo.LearnNowPayLaterPlanBo; import com.cpop.jambox.business.entity.CardTemplate; +import com.cpop.jambox.business.entity.CardTemplateExtend; import com.cpop.jambox.business.service.CardTemplateExtendService; +import com.cpop.pay.framewok.config.wxPay.WxPayConfiguration; import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; import com.cpop.system.business.entity.WxPayScore; import com.cpop.system.business.entity.WxPayScoreDetail; @@ -17,11 +21,16 @@ import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PartnerPayScoreSignPlanService; import com.github.binarywang.wxpay.service.WxPayService; +import com.mybatisflex.core.datasource.DataSourceKey; +import com.mybatisflex.core.row.DbChain; +import com.mybatisflex.core.row.Row; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.Arrays; import java.util.List; import static com.cpop.jambox.business.entity.table.CardTemplateExtendTableDef.CARD_TEMPLATE_EXTEND; @@ -33,11 +42,15 @@ import static com.cpop.system.business.entity.table.WxPayScoreTableDef.WX_PAY_SC * @since 2024-01-17 18:18 */ @Component +@Slf4j public class LearnNowPayLaterTask { @Autowired private WxPayHandler wxPayHandler; + @Autowired + private WxPayConfiguration wxPayConfiguration; + /** * 异步创建先学后付计划 * @author DB @@ -59,13 +72,36 @@ public class LearnNowPayLaterTask { PartnerPayScoreSignPlanService partnerPayScoreSignPlanService = wxPayService.getPartnerPayScoreSignPlanService(); WxPartnerPayScoreSignPlanRequest planRequest = BeanUtils.mapToClass(bo,WxPartnerPayScoreSignPlanRequest.class); List payScorePlanDetailRequests = BeanUtils.mapToList(bo.getPlanDetailList(), PayScorePlanDetailRequest.class); + planRequest.setAppid(wxPayConfiguration.getProperties().getServiceAppId()); + planRequest.setSubMchid(subMchId); planRequest.setPlanDetailList(payScorePlanDetailRequests); planRequest.setMerchantPlanNo(wxPayScore.getId()); WxPartnerPayScoreSignPlanResult result; + CardTemplateExtendService cardTemplateExtendService = SpringUtils.getBean(CardTemplateExtendService.class); //设置商户侧计划 try { result = partnerPayScoreSignPlanService.createPlans(planRequest); } catch (WxPayException e) { + //删除计划开通 + try { + //查询旧表 + DataSourceKey.use("jambox"); + Row oldTemplate = DbChain.table("t_card_template") + .select("template_id as oldTemplateId") + .select("pay_type as payTypes") + .from("t_card_template") + .where("template_id = ?", cardTemplate.getOldTemplateId()) + .one(); + //移除 + List payTypes = Arrays.asList(oldTemplate.getString("payTypes").split(",")); + payTypes.remove(payType.toString()); + DbChain.table("t_card_template") + .set("pay_type", StringUtils.join(payTypes, ",")) + .where("template_id = ?", cardTemplate.getOldTemplateId()) + .update(); + } finally { + DataSourceKey.clear(); + } throw new ServiceException(e.getMessage()); } List wxPayScoreDetails = BeanUtils.mapToList(result.getPlanDetailList(), WxPayScoreDetail.class); @@ -79,12 +115,12 @@ public class LearnNowPayLaterTask { .set(WX_PAY_SCORE.OUT_PLAN_ID,result.getPlanId()) .where(WX_PAY_SCORE.ID.eq(wxPayScore.getId())) .update(); - //更新模板拓展 - SpringUtils.getBean(CardTemplateExtendService.class).updateChain() - .set(CARD_TEMPLATE_EXTEND.EXTEND_ID,wxPayScore.getId()) - .set(CARD_TEMPLATE_EXTEND.EXTEND_PARAM_ONE, true) - .where(CARD_TEMPLATE_EXTEND.PAY_TYPE.eq(payType)) - .and(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(cardTemplate.getId())) - .update(); + //模板拓展 + CardTemplateExtend cardTemplateExtend = new CardTemplateExtend(); + cardTemplateExtend.setTemplateId(cardTemplate.getId()) + .setExtendId(wxPayScore.getId()) + .setExtendParamOne("1") + .setPayType(payType); + cardTemplateExtendService.save(cardTemplateExtend); } } diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml index dc2e707..f792c14 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml +++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml @@ -31,7 +31,7 @@ spring: max-file-size: 1024MB max-request-size: 300MB profiles: - active: dev,core,mall,system + active: dev,mall,core,jambox,system,pay datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/Cpop-Mall/pom.xml b/Cpop-Mall/pom.xml index c97662d..afdee19 100644 --- a/Cpop-Mall/pom.xml +++ b/Cpop-Mall/pom.xml @@ -27,6 +27,10 @@ com.cpop Cpop-Jambox + + com.cpop + Cpop-Pay + diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java index 34d0bc3..1728e4c 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/mini/MiniProductController.java @@ -137,7 +137,7 @@ public class MiniProductController { public R> getCarouselList() { JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo(); List vos = carouselService.queryChain().where(CAROUSEL.BRAND_ID.eq(loginUserInfo.getString("brandId")) - .and(CAROUSEL.UP_STATUS.eq(true))).listAs(CarouselListVo.class); + .and(CAROUSEL.UP_STATUS.eq(true))).orderBy(CAROUSEL.ORDER_NO.asc()).listAs(CarouselListVo.class); return R.ok(vos); } } diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml index d1ec61d..6eda66c 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml @@ -4,7 +4,7 @@ cpop: profile: E:/Cpop/uploadPath jwt: #白名单 - whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxCp/*,/wxCp/portal/*/registerCode,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/*,/cardTemplate/insertCardTemplateUnion + whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxCp/*,/wxCp/portal/*/registerCode,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/*,/mini/cardTemplate/* gateway: rsa-keypair: # 公钥文件 diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml index 234e7f4..0902d5c 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-prod.yml @@ -4,7 +4,7 @@ cpop: profile: /root/cpop-union/cpop-oam/upload jwt: #白名单 - whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/*,/wxCp/*,/wxCp/portal/*/registerCode,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/* + whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/*,/wxCp/*,/wxCp/portal/*/registerCode,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/*,/mini/cardTemplate/* #拦截 gateway: rsa-keypair: @@ -73,4 +73,4 @@ wx: # 私钥证书 privateKeyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_key.pem # 私钥文件 - privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem + privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem \ No newline at end of file diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml index 8f005b9..d222961 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-test.yml @@ -4,7 +4,7 @@ cpop: profile: /root/cpop-union/cpop-mall/upload jwt: #白名单 - whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/*,/wxCp/portal/*/registerCode,/wxCp/*,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/* + whiteList: /websocket/*,/login,/getCaptcha,/profile/**,/doc.html,/webjars/**,/favicon.ico,/v2/api-docs/**,/swagger-resources,/wxOpen/receiveTicket,/wxOpen/*/callback,/wxOpen/bindOpenAccount/*,/wxCp/portal/*,/wxCp/portal/*/registerCode,/wxCp/*,/sysCommon/miniSyncBrandAndStore,/easyLearn/callback/*/*,/easyLearn/*,/mini/cardTemplate/* #拦截 gateway: rsa-keypair: @@ -12,10 +12,6 @@ cpop: publicKeyFile: /root/jambox-union/jambox-oam/script/secretKey/publicKey # 公钥文件 privateKeyFile: /root/jambox-union/jambox-oam/script/secretKey/privateKey - # 公钥文件 - #publicKeyFile: E:\Cpop\Cpop-Union\Cpop-Core\src\main\resources\static\keyPair\publicKey - # 公钥文件 - #privateKeyFile: E:\Cpop\Cpop-Union\Cpop-Core\src\main\resources\static\keyPair\privateKey # DataSource Config spring: @@ -98,10 +94,4 @@ wx: # 私钥证书 privateKeyPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_key.pem # 私钥文件 - privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem - # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) - #keyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.p12 - # 私钥证书 - #privateKeyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_key.pem - # 私钥文件 - #privateCertPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.pem \ No newline at end of file + privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem \ No newline at end of file diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml index 2163b9a..164a41d 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml @@ -31,7 +31,7 @@ spring: max-file-size: 1024MB max-request-size: 300MB profiles: - active: dev,core,jambox,pay + active: dev,oam,core,jambox,system,pay datasource: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopEasyLearnTest.java b/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopEasyLearnTest.java index 1481ca0..1acadc5 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopEasyLearnTest.java +++ b/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopEasyLearnTest.java @@ -12,11 +12,22 @@ import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.jambox.framework.constant.JamboxCloudUrl; import com.cpop.pay.framewok.config.wxPay.WxPayProperties; import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; +import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingBillV3Request; +import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingReceiverRequest; import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingRequest; +import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingBillV3Result; +import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingOrderAmountQueryV3Result; import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingResult; +import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingV3Result; +import com.github.binarywang.wxpay.bean.request.WxPayApplyTradeBillV3Request; +import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest; +import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryV3Request; import com.github.binarywang.wxpay.bean.request.WxPayPartnerOrderCloseV3Request; +import com.github.binarywang.wxpay.bean.result.WxPayApplyBillV3Result; +import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.ProfitSharingService; import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; @@ -29,6 +40,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.client.RestTemplate; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; @@ -44,7 +58,7 @@ import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EX * @since 2023-12-29 9:50 */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles({"dev", "core", "jambox"}) +@ActiveProfiles({"dev", "core", "jambox", "pay"}) public class CpopEasyLearnTest { @Autowired @@ -214,4 +228,79 @@ public class CpopEasyLearnTest { wxPayPartnerOrderCloseV3Request.setOutTradeNo("1745820005743910912"); wxPayService.closePartnerOrderV3(wxPayPartnerOrderCloseV3Request); } + + /** + * 查询未完结订单 + * @author DB + * @since 2024/1/19 + */ + @Test + public void downloadBill() throws WxPayException { + WxPayService wxPayService = wxPayHandler.getWxPayService(null, "1663310469"); + ProfitSharingService profitSharingService = wxPayService.getProfitSharingService(); + ProfitSharingBillV3Request profitSharingBillV3Request = new ProfitSharingBillV3Request(); + profitSharingBillV3Request.setSubMchId("1663310469"); + String date = "2024-01-17"; + profitSharingBillV3Request.setBillDate(date); + WxPayApplyTradeBillV3Request wxPayApplyTradeBillV3Request = new WxPayApplyTradeBillV3Request(); + wxPayApplyTradeBillV3Request.setBillDate(date); + wxPayApplyTradeBillV3Request.setBillType("ALL"); + WxPayApplyBillV3Result wxPayApplyBillV3Result = wxPayService.applyTradeBill(wxPayApplyTradeBillV3Request); + //ProfitSharingBillV3Result profitSharingBillV3Result = profitSharingService.profitSharingBill(profitSharingBillV3Request); + InputStream inputStream = wxPayService.downloadBill(wxPayApplyBillV3Result.getDownloadUrl()); + new File(""); + // 创建输出文件的路径 + String filePath = "D:\\Lost\\下载\\" + date + ".txt"; + // 将输入流中的内容写入文件 + try (OutputStream outputStream = Files.newOutputStream(Paths.get(filePath))) { + byte[] buffer = new byte[8192]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + System.out.println("内容成功写入文件"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void queryOrderAndSharing() throws WxPayException { + WxPayService wxPayService = wxPayHandler.getWxPayService(null, "1663310469"); + WxPayOrderQueryRequest wxPayOrderQueryRequest = new WxPayOrderQueryRequest(); + wxPayOrderQueryRequest.setTransactionId("4200001925202401173471747106"); + WxPayOrderQueryResult wxPayOrderQueryResult = wxPayService.queryOrder(wxPayOrderQueryRequest); + ProfitSharingService profitSharingService = wxPayService.getProfitSharingService(); + ProfitSharingV3Result profitSharingV3Result = profitSharingService.profitSharingQueryV3("105490200209170432", "4200002126202401189482541307", "1663310469"); + ProfitSharingOrderAmountQueryV3Result profitSharingOrderAmountQueryV3Result = profitSharingService.profitSharingUnsplitAmountQueryV3("4200001925202401173471747106"); + System.out.println(JSONObject.toJSONString(wxPayOrderQueryResult)); + System.out.println(JSONObject.toJSONString(profitSharingV3Result)); + } + + @Test + public void orderProfitSharing() throws WxPayException { + //固定商户信息 + Map mapReceiver = new HashMap<>(4); + mapReceiver.put("type", "MERCHANT_ID"); + mapReceiver.put("account", wxPayProperties.getSharingAccount()); + mapReceiver.put("amount", 900); + mapReceiver.put("description","分账到服务商"); + List> receivers = new ArrayList<>(); + receivers.add(mapReceiver); + //分账请求参数 + ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest(); + profitSharingRequest.setReceivers(JSONObject.toJSONString(receivers)); + profitSharingRequest.setOutOrderNo("105490200209170432"); + profitSharingRequest.setTransactionId("4200002126202401189482541307"); + profitSharingRequest.setSubMchId("1663310469"); + ProfitSharingResult profitSharingResult = wxPayService.getProfitSharingService().profitSharing(profitSharingRequest); + if (StringUtils.equals(profitSharingResult.getResultCode(), "SUCCESS")) { + //存入系统 + DbChain.table("cp_sys_profit_sharing") + .set("out_profit_sharing_id", profitSharingResult.getOrderId()) + .set("profit_sharing_status", 1) + .where("id = ?", profitSharingResult.getOutOrderNo()) + .update(); + } + } } diff --git a/Cpop-Oam/pom.xml b/Cpop-Oam/pom.xml index 5e2d5d8..df77285 100644 --- a/Cpop-Oam/pom.xml +++ b/Cpop-Oam/pom.xml @@ -27,6 +27,10 @@ com.cpop Cpop-System + + com.cpop + Cpop-Pay + com.github.binarywang diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DataImportServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DataImportServiceImpl.java index 6bb2e04..05fe893 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DataImportServiceImpl.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DataImportServiceImpl.java @@ -1,5 +1,6 @@ package com.cpop.oam.business.service.impl; +import cn.hutool.core.util.IdUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.exception.ExcelDataConvertException; @@ -12,10 +13,12 @@ import com.cpop.core.base.entity.PageDomain; import com.cpop.core.base.enums.SourceType; import com.cpop.core.base.exception.ServiceException; import com.cpop.core.handler.TencentCosHandler; +import com.cpop.core.service.RedisService; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.file.FileUploadUtils; import com.cpop.core.utils.file.FileUtils; import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.core.utils.uuid.IdUtils; import com.cpop.jambox.business.entity.StoreExtend; import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.jambox.framework.constant.JamboxCloudUrl; @@ -24,6 +27,7 @@ import com.cpop.oam.business.bo.DataImportPageBo; import com.cpop.oam.business.dto.DataImportDto; import com.cpop.oam.business.dto.DataImportParamsDto; import com.cpop.oam.business.vo.DataImportPageVo; +import com.cpop.oam.framework.constant.OamRedisConstant; import com.cpop.oam.framework.constant.WebHookKeyConstant; import com.cpop.system.business.vo.SysFileVo; import com.mybatisflex.core.paginate.Page; @@ -44,6 +48,7 @@ import java.io.IOException; import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.Lock; import static com.alibaba.excel.cache.Ehcache.BATCH_COUNT; import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND; @@ -103,9 +108,28 @@ public class DataImportServiceImpl extends ServiceImpl implements Ta @Override @Transactional(rollbackFor = Exception.class) public void claimTask(String id) { - // 查询任务 - Task task = this.getById(id); - // 进行中 接受时间 - task.setTaskStatus(2).setTaskReceiptTime(LocalDateTime.now()); - // 如果任务没有设置预期完成时间,则按照任务评级进行设置默认 - if (task.getExpectedCompletionDate() == null) { - // 获取任务评级 - String taskRating = task.getTaskRating(); - LocalDate now = LocalDate.now(); - String dictValue = DictUtils.getDictValue(OAM_TASK_RATING, taskRating); - task.setExpectedCompletionDate(now.plusDays(Integer.parseInt(dictValue.split(",")[1]))); - } - // 获取当前用户 - JSONObject loginUser = SecurityUtils.getInstance().getLoginUserInfo(); - if (!Constants.SUPER_ADMIN.equals(loginUser.getString("userName"))) { - // 获取当前员工 - Staff staff = SpringUtils.getBean(StaffService.class) - .getOne(QueryWrapper.create().where(STAFF.USER_ID.eq(loginUser.getString("userId")))); - task.setResponsibleStaffId(staff.getId()); - } - this.updateById(task); - // 添加主要负责人组 - TaskStaffGroup taskStaffGroup = new TaskStaffGroup(); - taskStaffGroup.setStaffId(task.getResponsibleStaffId()).setTaskId(id).setGradePoint(task.getTaskWeight()); - SpringUtils.getBean(TaskStaffGroupService.class).save(taskStaffGroup); - // 通知所有人 - try { - SpringUtils.getBean(WebHookSendHandler.class) - .webHookSendText(WebHookKeyConstant.PRODUCT_BOT, - Collections.singletonList(loginUser.getString("phoneNumber")), - "==========任务领取==========" + "\n" + task.getTaskContent(), - false); - } catch (IOException e) { - throw new ServiceException("发送任务领取通知失败!"); + //分布式锁进行幂等处理 + RedisService redisService = SpringUtils.getBean(RedisService.class); + //分布式锁进行幂等处理 + Lock userIdLock = redisService.distributedLock(OamRedisConstant.TASK_CLAIM_LOCK + id); + if (userIdLock.tryLock()) { + try { + // 查询任务 + Task task = this.getById(id); + if (task.getTaskStatus() == 2){ + throw new ServiceException("任务已领取,请刷新页面"); + } + // 进行中 接受时间 + task.setTaskStatus(2).setTaskReceiptTime(LocalDateTime.now()); + // 如果任务没有设置预期完成时间,则按照任务评级进行设置默认 + if (task.getExpectedCompletionDate() == null) { + // 获取任务评级 + String taskRating = task.getTaskRating(); + LocalDate now = LocalDate.now(); + String dictValue = DictUtils.getDictValue(OAM_TASK_RATING, taskRating); + task.setExpectedCompletionDate(now.plusDays(Integer.parseInt(dictValue.split(",")[1]))); + } + // 获取当前用户 + JSONObject loginUser = SecurityUtils.getInstance().getLoginUserInfo(); + if (!Constants.SUPER_ADMIN.equals(loginUser.getString("userName"))) { + // 获取当前员工 + Staff staff = SpringUtils.getBean(StaffService.class) + .getOne(QueryWrapper.create().where(STAFF.USER_ID.eq(loginUser.getString("userId")))); + task.setResponsibleStaffId(staff.getId()); + } + this.updateById(task); + // 添加主要负责人组 + TaskStaffGroup taskStaffGroup = new TaskStaffGroup(); + taskStaffGroup.setStaffId(task.getResponsibleStaffId()).setTaskId(id).setGradePoint(task.getTaskWeight()); + SpringUtils.getBean(TaskStaffGroupService.class).save(taskStaffGroup); + // 通知所有人 + try { + SpringUtils.getBean(WebHookSendHandler.class) + .webHookSendText(WebHookKeyConstant.PRODUCT_BOT, + Collections.singletonList(loginUser.getString("phoneNumber")), + "==========任务领取==========" + "\n" + task.getTaskContent(), + false); + } catch (IOException e) { + throw new ServiceException("发送任务领取通知失败!"); + } + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } finally { + //释放锁 + userIdLock.unlock(); + } + } else { + //获取锁失败,直接返回空 + throw new ServiceException("请勿重复领取"); } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/OamRedisConstant.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/OamRedisConstant.java new file mode 100644 index 0000000..e2859e4 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/OamRedisConstant.java @@ -0,0 +1,19 @@ +package com.cpop.oam.framework.constant; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-19 14:51 + */ +public interface OamRedisConstant { + + /** + * 数据导入幂等锁 + */ + String DATA_IMPORT_LOCK = "oam:dataImportLock:dataImport:"; + + /** + * 任务领取幂等锁 + */ + String TASK_CLAIM_LOCK = "oam:taskClaimLock:task:"; +} diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java index 454800d..908ef9c 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java @@ -85,4 +85,9 @@ public class WxPayProperties { * 服务id */ private String serviceId; + + /** + * 服务商模式下的子商户公众账号ID + */ + private String serviceAppId; } diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java index a5a3cea..821da72 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java @@ -141,49 +141,4 @@ public class WxPayHandler { return wxMchId; } - /** - * 创建支付分计划 - * @author DB - * @since 2024/1/8 - * @param wxPayService 微信支付 - * @param dto 先学后付计划 - * @return WxPartnerPayScoreSignPlanResult - */ - @Transactional(rollbackFor = Exception.class) - public WxPartnerPayScoreSignPlanResult createPayScorePlan(WxPayService wxPayService, LearnNowPayLaterPlanDto dto) { - Row row = Row.ofKey(RowKey.SNOW_FLAKE_ID); - row.set("sign_account", wxPayService.getConfig().getSubMchId()); - row.set("plan_name", dto.getPlanName()); - row.set("plan_duration", dto.getPlanDuration()); - row.set("deduction_quantity", dto.getDeductionQuantity()); - row.set("total_original_price", dto.getTotalOriginalPrice()); - row.set("total_actual_price", dto.getTotalActualPrice()); - row.set("plan_source", dto.getOrderSource().toString()); - //插入计划 - Db.insert("cp_sys_wx_pay_score", row); - PartnerPayScoreSignPlanService partnerPayScoreSignPlanService = wxPayService.getPartnerPayScoreSignPlanService(); - WxPartnerPayScoreSignPlanRequest planRequest = BeanUtils.mapToClass(dto, WxPartnerPayScoreSignPlanRequest.class); - planRequest.setMerchantPlanNo(row.getString("id")); - WxPartnerPayScoreSignPlanResult plans; - try { - plans = partnerPayScoreSignPlanService.createPlans(planRequest); - } catch (WxPayException e) { - throw new UtilException(e); - } - ArrayList detailRows = new ArrayList<>(); - //更新计划详情 - plans.getPlanDetailList().forEach(item -> { - Row detailRow = Row.ofKey(RowKey.SNOW_FLAKE_ID); - detailRow.set("sys_wx_pay_score_id", row.getString("id")); - detailRow.set("plan_detail_no", item.getPlanDetailNo()); - detailRow.set("original_price", item.getOriginalPrice()); - detailRow.set("actual_price", item.getActualPrice()); - detailRow.set("plan_discount_description", item.getPlanDiscountDescription()); - detailRow.set("plan_detail_name", item.getPlanDetailName()); - detailRows.add(detailRow); - }); - //批量插入 - Db.insertBatch("cp_sys_wx_pay_score_detail", detailRows); - return plans; - } } diff --git a/Cpop-Pay/src/main/resources/application-pay.yml b/Cpop-Pay/src/main/resources/application-pay.yml index 65fd4b0..df43d1e 100644 --- a/Cpop-Pay/src/main/resources/application-pay.yml +++ b/Cpop-Pay/src/main/resources/application-pay.yml @@ -13,3 +13,5 @@ wx: #分账服务商账号 sharing-account: 1618884922 sharing-account-name: 果酱盒子 + #服务商appid + service-app-id: wx1eb0e5fb7dac3c05 \ No newline at end of file