先学后付该迁移支付

This commit is contained in:
DB 2024-01-19 18:32:24 +08:00
parent 04b930504d
commit 792ac276c9
26 changed files with 601 additions and 202 deletions

View File

@ -146,4 +146,16 @@ public class CardTemplateUnionBo {
*/
@ApiModelProperty("先学后付(月付)")
private LearnNowPayLaterPlanBo learnNowPayLaterMonthPay;
/**
* 放心学旧合同
*/
@ApiModelProperty("放心学旧合同")
private EasyLearnOldContractBo easyLearnOldContract;
/**
* 放心学数币
*/
@ApiModelProperty("放心学数币")
private EasyLearnDigitalCurrencyBo easyLearnDigitalCurrency;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Void> 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<Void> updateCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) {
cardTemplateService.updateCardTemplateUnion(bo);
return R.ok();
}
}

View File

@ -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<Void> 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<Void> updateCardTemplateUnion(@RequestBody @Validated CardTemplateUnionBo bo) {
cardTemplateService.updateCardTemplateUnion(bo);
return R.ok();
}
/**
* 删除课卡模板
* @author DB
* @since 2024/1/19
* @param oldId 旧主键id
* @return R<Void>
*/
@Deprecated
@ApiOperation(value = "删除课卡模板")
@DeleteMapping("/removeCardTemplateById/{oldId}")
public R<Void> 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();
}
}

View File

@ -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<LearnNowPayLaterPlanDetailVo> 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<LearnNowPayLaterPlanVo> 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<LearnNowPayLaterPlanDetailVo>
* @author DB
* @since 2024/1/18
* @param oldTemplateId 旧模板id
* @param isMonth 是否月付
* @return R<LearnNowPayLaterPlanDetailVo>
*/
@ApiOperation("创建用户签约计划")
@PostMapping("/createUserSignPlans")
public R<Void> createUserSignPlans(@ApiParam(value = "旧模板id",required = true) @RequestParam("oldTemplateId") String oldTemplateId,
@ApiParam(value = "是否月付(0否1是)",required = true) @RequestParam("isMonth") Boolean isMonth) {
public R<Void> createUserSignPlans(@ApiParam(value = "旧模板id", required = true) @RequestParam("oldTemplateId") String oldTemplateId,
@ApiParam(value = "是否月付(0否1是)", required = true) @RequestParam("isMonth") Boolean isMonth) {
return R.ok();
}

View File

@ -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<CardTemplate> {
* @param isMonth 是否月付
* @return LearnNowPayLaterPlanDetailVo
*/
LearnNowPayLaterPlanDetailVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth);
LearnNowPayLaterPlanVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth);
}

View File

@ -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<CardTemplateMapper, Car
cardTemplate.setStoreId(store.getId()).setBrandId(store.getBrandId());
}
this.save(cardTemplate);
List<CardTemplateExtend> 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<CardTemplateMapper, Car
}
}
/**
* 插入模板拓展
* @author DB
* @since 2024/1/19
* @param cardTemplate 模板
* @param bo 请求
*/
private void saveTemplateExtend(CardTemplate cardTemplate, CardTemplateUnionBo bo) {
List<CardTemplateExtend> cardTemplateExtends = new ArrayList<>();
List<Integer> 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<CardTemplateMapper, Car
CardTemplateExtendService cardTemplateExtendService = SpringUtils.getBean(CardTemplateExtendService.class);
List<CardTemplateExtend> cardTemplateExtends = cardTemplateExtendService.list(QueryWrapper.create()
.where(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(bo.getOldTemplateId())));
//添加课卡模板拓展
List<Integer> filterPayType = bo.getPayType().stream().filter(item -> item != 1 && item != 5).collect(Collectors.toList());
//TODO: 新增或修改模板拓展
updateTemplateExtend(cardTemplate, bo, cardTemplateExtends);
//次付
List<Integer> 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<CardTemplateMapper, Car
}
}
/**
* 更新模板拓展
* @author DB
* @since 2024/1/19
* @param cardTemplate 模板
* @param bo 请求
*/
private void updateTemplateExtend(CardTemplate cardTemplate, CardTemplateUnionBo bo, List<CardTemplateExtend> cardTemplateExtends) {
List<Integer> payTypeList = bo.getPayType();
Map<Integer, CardTemplateExtend> existExtends = cardTemplateExtends.stream().collect(Collectors.toMap(CardTemplateExtend::getPayType, item -> item));
List<Integer> 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<CardTemplateMapper, Car
* @return LearnNowPayLaterPlanDetailVo
*/
@Override
public LearnNowPayLaterPlanDetailVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth) {
return null;
public LearnNowPayLaterPlanVo getWxPayScorePlan(String oldTemplateId, Boolean isMonth) {
CardTemplate cardTemplate = this.queryChain().where(CARD_TEMPLATE.OLD_TEMPLATE_ID.eq(oldTemplateId)).one();
CardTemplateExtendService cardTemplateExtendService = SpringUtils.getBean(CardTemplateExtendService.class);
CardTemplateExtend cardTemplateExtend = cardTemplateExtendService.getOne(QueryWrapper.create()
.where(CARD_TEMPLATE_EXTEND.TEMPLATE_ID.eq(cardTemplate.getId()))
.and(CARD_TEMPLATE_EXTEND.PAY_TYPE.eq(isMonth ? 5 : 1)));
LearnNowPayLaterPlanVo vo = SpringUtils.getBean(WxPayScoreService.class).getOneAs(QueryWrapper.create()
.where(WX_PAY_SCORE.ID.eq(cardTemplateExtend.getExtendId())),
LearnNowPayLaterPlanVo.class);
List<LearnNowPayLaterPlanDetailVo> 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;
}
}

View File

@ -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));
}
/**

View File

@ -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));
}
/**

View File

@ -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<PayScorePlanDetailRequest> 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<String> 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<WxPayScoreDetail> 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);
}
}

View File

@ -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

View File

@ -27,6 +27,10 @@
<groupId>com.cpop</groupId>
<artifactId>Cpop-Jambox</artifactId>
</dependency>
<dependency>
<groupId>com.cpop</groupId>
<artifactId>Cpop-Pay</artifactId>
</dependency>
</dependencies>

View File

@ -137,7 +137,7 @@ public class MiniProductController {
public R<List<CarouselListVo>> getCarouselList() {
JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo();
List<CarouselListVo> 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);
}
}

View File

@ -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:
# 公钥文件

View File

@ -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

View File

@ -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
privateCertPath: /root/cpop-union/cpop-oam/script/secretKey/wxPay_cert.pem

View File

@ -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

View File

@ -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<String, Object> mapReceiver = new HashMap<>(4);
mapReceiver.put("type", "MERCHANT_ID");
mapReceiver.put("account", wxPayProperties.getSharingAccount());
mapReceiver.put("amount", 900);
mapReceiver.put("description","分账到服务商");
List<Map<String, Object>> 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();
}
}
}

View File

@ -27,6 +27,10 @@
<groupId>com.cpop</groupId>
<artifactId>Cpop-System</artifactId>
</dependency>
<dependency>
<groupId>com.cpop</groupId>
<artifactId>Cpop-Pay</artifactId>
</dependency>
<!--企业微信-->
<dependency>
<groupId>com.github.binarywang</groupId>

View File

@ -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<DataImportMapper, DataImp
*/
@Override
public void importNow(String id) {
//读取数据
DataImport dataImport = this.getById(id);
importNow(dataImport);
//分布式锁进行幂等处理
RedisService redisService = SpringUtils.getBean(RedisService.class);
//分布式锁进行幂等处理
Lock userIdLock = redisService.distributedLock(OamRedisConstant.DATA_IMPORT_LOCK + id);
if (userIdLock.tryLock()) {
try {
//读取数据
DataImport dataImport = this.getById(id);
if (dataImport.getImportStatus()) {
throw new ServiceException("数据已导入,请刷新页面");
}
importNow(dataImport);
} catch (Exception e) {
throw new ServiceException(e.getMessage());
} finally {
//释放锁
userIdLock.unlock();
}
} else {
//获取锁失败直接返回空
throw new ServiceException("请勿重复导入");
}
}
/**
@ -152,7 +176,7 @@ public class DataImportServiceImpl extends ServiceImpl<DataImportMapper, DataImp
public void invoke(DataImportDto dataImportDto, AnalysisContext analysisContext) {
//检查手机号
if (StringUtils.isBlank(dataImportDto.getPhone())) {
throw new ServiceException("手机号为空!");
dataImportDto.setPhone(IdUtil.getSnowflakeNextIdStr());
}
//课卡类型
if (StringUtils.isBlank(dataImportDto.getCardType())) {
@ -184,7 +208,7 @@ public class DataImportServiceImpl extends ServiceImpl<DataImportMapper, DataImp
}
//课卡名称
if (StringUtils.isBlank(dataImportDto.getCardName())) {
throw new ServiceException("课卡名称不能为空");
throw new ServiceException(String.format("第%s行课卡名称为空,请核实", analysisContext.readRowHolder().getRowIndex() + 1));
}
//停卡时剩余天数
if (dataImportDto.getStopCardRemainingDays() == null) {
@ -222,6 +246,8 @@ public class DataImportServiceImpl extends ServiceImpl<DataImportMapper, DataImp
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
throw new ServiceException("" + (excelDataConvertException.getRowIndex() + 1) + "行,第" + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,数据为:" + excelDataConvertException.getCellData());
} else {
throw new ServiceException(exception.getMessage());
}
}
}).sheet().doRead();

View File

@ -15,6 +15,7 @@ import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.oam.business.bo.*;
import com.cpop.oam.business.entity.DataImport;
import com.cpop.oam.business.entity.Staff;
import com.cpop.oam.business.entity.Task;
import com.cpop.oam.business.entity.TaskStaffGroup;
@ -25,6 +26,7 @@ import com.cpop.oam.business.service.TaskStaffGroupService;
import com.cpop.oam.business.service.TaskWorkOrderService;
import com.cpop.oam.business.vo.*;
import com.cpop.oam.framework.constant.OamConfigKey;
import com.cpop.oam.framework.constant.OamRedisConstant;
import com.cpop.oam.framework.constant.WebHookKeyConstant;
import com.cpop.oam.framework.enums.OamConfigEnum;
import com.cpop.system.business.entity.DictData;
@ -48,6 +50,7 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER;
@ -244,40 +247,59 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> 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("请勿重复领取");
}
}

View File

@ -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:";
}

View File

@ -85,4 +85,9 @@ public class WxPayProperties {
* 服务id
*/
private String serviceId;
/**
* 服务商模式下的子商户公众账号ID
*/
private String serviceAppId;
}

View File

@ -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<Row> 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;
}
}

View File

@ -13,3 +13,5 @@ wx:
#分账服务商账号
sharing-account: 1618884922
sharing-account-name: 果酱盒子
#服务商appid
service-app-id: wx1eb0e5fb7dac3c05