diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingReceiverApplySchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingReceiverApplySchedule.java new file mode 100644 index 000000000..beca18fe0 --- /dev/null +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingReceiverApplySchedule.java @@ -0,0 +1,50 @@ +package com.iformall.schedule; + +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxProfitSharingReceiverApply; +import com.iformall.enums.EnumSharingReceiverApplyStatus; +import com.iformall.enums.EnumSharingReceiverApplymentState; +import com.iformall.mapper.WxProfitSharingReceiverApplyMapper; +import com.iformall.service.WxProfitSharingReceiverApplyService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class SharingReceiverApplySchedule { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxProfitSharingReceiverApplyMapper wxProfitSharingReceiverApplyMapper; + + @Autowired + private WxProfitSharingReceiverApplyService wxProfitSharingReceiverApplyService; + + @Async + @Scheduled(cron = "0 22 */1 * * ?")// 每小时的22分钟 + public void sharingOrderRedoSchedule() { + WxProfitSharingReceiverApply receiverApply = new WxProfitSharingReceiverApply(); + receiverApply.setStatus(EnumSharingReceiverApplyStatus.PROFIT_RECEIVER_APPLY_STATUS_VALID.getCode()); + receiverApply.setApplymentStates(EnumSharingReceiverApplymentState.getNeedSyncList()); + List needSyncList = wxProfitSharingReceiverApplyMapper.findListByApplymentState(receiverApply); + if(!needSyncList.isEmpty()){ + for (WxProfitSharingReceiverApply apply:needSyncList){ + try{ + ResultData resultData = wxProfitSharingReceiverApplyService.handApplymentStates(apply); + if(resultData.code != 200){ + logger.error("同步进件状态异常{}"+apply.getId()); + } + }catch(Exception e){ + logger.error("同步进件状态异常{}"+apply.getId()+"---"+e.getMessage()); + } + } + } + } + +} \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiverApply.java b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiverApply.java index 0a4e4943d..ac0767955 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiverApply.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingReceiverApply.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.util.Date; +import java.util.List; @TableName(value = "wx_profit_sharing_receiver_apply") @Data @@ -74,6 +75,10 @@ public class WxProfitSharingReceiverApply extends TenantEntity { private String applymentId; @io.swagger.annotations.ApiModelProperty(value="EnumSharingReceiverApplymentState 申请状态",name="applymentState") private Integer applymentState; + + @TableField(exist = false) + private List applymentStates; + @io.swagger.annotations.ApiModelProperty(value="申请状态描述",name="applymentStateDesc") private String applymentStateDesc; @io.swagger.annotations.ApiModelProperty(value="EnumSharingReceiverSignState 签约状态",name="signState") diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplymentState.java b/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplymentState.java index 889d97f2e..d3a747965 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplymentState.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumSharingReceiverApplymentState.java @@ -1,5 +1,7 @@ package com.iformall.enums; +import com.github.binarywang.wxpay.bean.applyment.enums.ApplymentStateEnum; + import java.util.ArrayList; import java.util.List; @@ -16,16 +18,16 @@ import java.util.List; */ public enum EnumSharingReceiverApplymentState { - APPLYMENT_STATE_EDITTING(1,"APPLYMENT_STATE_EDITTING","编辑中"), + APPLYMENT_STATE_EDITTING(1,ApplymentStateEnum.APPLYMENT_STATE_EDITTING,"编辑中"), // APPLYMENT_STATE_CHECKING(2, "CHECKING", "资料校验中"), - APPLYMENT_STATE_AUDITING(3, "APPLYMENT_STATE_AUDITING", "审核中"), - APPLYMENT_STATE_REJECTED(4, "APPLYMENT_STATE_REJECTED", "已驳回"), - APPLYMENT_STATE_TO_BE_CONFIRMED(5, "APPLYMENT_STATE_TO_BE_CONFIRMED", "待账户验证"), - APPLYMENT_STATE_TO_BE_SIGNED(6, "APPLYMENT_STATE_TO_BE_SIGNED", "待签约"), - APPLYMENT_STATE_SIGNING(7, "APPLYMENT_STATE_SIGNING", "开通权限中"), - APPLYMENT_STATE_FINISHED(8, "APPLYMENT_STATE_FINISHED", "完成"), + APPLYMENT_STATE_AUDITING(3, ApplymentStateEnum.APPLYMENT_STATE_AUDITING,"审核中"), + APPLYMENT_STATE_REJECTED(4, ApplymentStateEnum.APPLYMENT_STATE_REJECTED,"已驳回"), + APPLYMENT_STATE_TO_BE_CONFIRMED(5, ApplymentStateEnum.APPLYMENT_STATE_TO_BE_CONFIRMED,"待账户验证"), + APPLYMENT_STATE_TO_BE_SIGNED(6, ApplymentStateEnum.APPLYMENT_STATE_TO_BE_SIGNED,"待签约"), + APPLYMENT_STATE_SIGNING(7, ApplymentStateEnum.APPLYMENT_STATE_SIGNING,"开通权限中"), + APPLYMENT_STATE_FINISHED(8, ApplymentStateEnum.APPLYMENT_STATE_FINISHED,"完成"), // APPLYMENT_STATE_FROZEN(9, "FROZEN", "已冻结"), - APPLYMENT_STATE_CANCELED(10, "APPLYMENT_STATE_CANCELED", "已作废"), + APPLYMENT_STATE_CANCELED(10, ApplymentStateEnum.APPLYMENT_STATE_CANCELED,"已作废"), ; public static EnumSharingReceiverApplymentState getEnum(Integer code) { @@ -37,9 +39,9 @@ public enum EnumSharingReceiverApplymentState { return null; } - public static EnumSharingReceiverApplymentState getEnum(String codeStr) { + public static EnumSharingReceiverApplymentState getEnum(ApplymentStateEnum applymentStateEnum) { for (EnumSharingReceiverApplymentState value : values()) { - if (value.getCodeStr().equals(codeStr)) { + if (value.getApplymentStateEnum().equals(applymentStateEnum)) { return value; } } @@ -47,12 +49,12 @@ public enum EnumSharingReceiverApplymentState { } private Integer code; - private String codeStr; + private ApplymentStateEnum applymentStateEnum; private String message; - EnumSharingReceiverApplymentState(Integer code, String codeStr, String message) { + EnumSharingReceiverApplymentState(Integer code, ApplymentStateEnum applymentStateEnum, String message) { this.code = code; - this.codeStr = codeStr; + this.applymentStateEnum = applymentStateEnum; this.message = message; } @@ -60,8 +62,8 @@ public enum EnumSharingReceiverApplymentState { return code; } - public String getCodeStr() { - return codeStr; + public ApplymentStateEnum getApplymentStateEnum() { + return applymentStateEnum; } public String getMessage() { @@ -78,4 +80,17 @@ public enum EnumSharingReceiverApplymentState { list.add(EnumSharingReceiverApplymentState.APPLYMENT_STATE_REJECTED.getCode()); return list; } + + /** + * 获取需要同步的状态 + */ + public static List getNeedSyncList(){ + List list = new ArrayList<>(); + list.add(EnumSharingReceiverApplymentState.APPLYMENT_STATE_AUDITING.getCode()); + list.add(EnumSharingReceiverApplymentState.APPLYMENT_STATE_TO_BE_CONFIRMED.getCode()); + list.add(EnumSharingReceiverApplymentState.APPLYMENT_STATE_TO_BE_SIGNED.getCode()); + list.add(EnumSharingReceiverApplymentState.APPLYMENT_STATE_SIGNING.getCode()); + return list; + } + } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverApplyMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverApplyMapper.java index 4da269e0d..ec99954a4 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverApplyMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxProfitSharingReceiverApplyMapper.java @@ -10,4 +10,6 @@ public interface WxProfitSharingReceiverApplyMapper extends CommonMapper findList(WxProfitSharingReceiverApply apply); + List findListByApplymentState(WxProfitSharingReceiverApply apply); + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverApplyService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverApplyService.java index 3fccba588..34b877d34 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverApplyService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverApplyService.java @@ -26,4 +26,6 @@ public interface WxProfitSharingReceiverApplyService { ResultData applyment(WxProfitSharingReceiverApply receiverAdd); + ResultData handApplymentStates(WxProfitSharingReceiverApply apply); + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java index 6c2a026ef..21fcc7581 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverApplyServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.binarywang.wxpay.bean.applyment.ApplymentStateQueryResult; import com.github.binarywang.wxpay.bean.applyment.WxPayApplyment4SubCreateRequest; import com.github.binarywang.wxpay.bean.applyment.WxPayApplymentCreateResult; import com.github.binarywang.wxpay.bean.applyment.enums.SalesScenesTypeEnum; @@ -18,15 +19,13 @@ import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.*; import com.iformall.mapper.WxProfitSharingReceiverApplyMapper; -import com.iformall.service.WxAppinfoService; -import com.iformall.service.WxMerchantService; -import com.iformall.service.WxPayAccountService; -import com.iformall.service.WxProfitSharingReceiverApplyService; +import com.iformall.service.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.*; @@ -39,6 +38,9 @@ public class WxProfitSharingReceiverApplyServiceImpl implements WxProfitSharingR @Autowired WxProfitSharingReceiverApplyMapper wxProfitSharingReceiverApplyMapper; + @Autowired + WxProfitSharingReceiverService wxProfitSharingReceiverService; + @Autowired WxAppinfoService wxAppinfoService; @@ -131,20 +133,70 @@ public class WxProfitSharingReceiverApplyServiceImpl implements WxProfitSharingR ResultData result = this.applyment4subApplyment(receiverApply); if(result.code == 200){ - WxProfitSharingReceiverApply receiverUpd = new WxProfitSharingReceiverApply(); - receiverUpd.updateTenantInfo(receiverApply); - receiverUpd.setId(receiverApply.getId()); - receiverUpd.setApplymentId((String) result.data); - receiverUpd.setApplymentState(EnumSharingReceiverApplymentState.APPLYMENT_STATE_AUDITING.getCode()); - receiverUpd.setApplymentStateDesc(EnumSharingReceiverApplymentState.APPLYMENT_STATE_AUDITING.getMessage()); - receiverUpd.setUpdateTime(new Date()); - wxProfitSharingReceiverApplyMapper.updateById(receiverUpd); + WxProfitSharingReceiverApply receiverApplyUpd = new WxProfitSharingReceiverApply(); + receiverApplyUpd.updateTenantInfo(receiverApply); + receiverApplyUpd.setId(receiverApply.getId()); + receiverApplyUpd.setApplymentId((String) result.data); + receiverApplyUpd.setApplymentState(EnumSharingReceiverApplymentState.APPLYMENT_STATE_AUDITING.getCode()); + receiverApplyUpd.setApplymentStateDesc(EnumSharingReceiverApplymentState.APPLYMENT_STATE_AUDITING.getMessage()); + receiverApplyUpd.setUpdateTime(new Date()); + wxProfitSharingReceiverApplyMapper.updateById(receiverApplyUpd); return result; }else{ return result; } } + @Override + @Transactional(rollbackFor = {Exception.class}) + public ResultData handApplymentStates(WxProfitSharingReceiverApply receiverApply) { + if(receiverApply == null || !EnumSharingReceiverApplymentState.getNeedSyncList().contains(receiverApply.getApplymentState())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "该状态无需同步"); + } + WxPayService wxPayService = wxPayAccountService.getWxPayService(receiverApply.getTenantId()); + try { + ApplymentStateQueryResult applymentStateQueryResult = wxPayService.getApplyment4SubService().queryApplyStatusByBusinessCode(receiverApply.getOutRequestNo()); + EnumSharingReceiverApplymentState enumApplymentState = EnumSharingReceiverApplymentState.getEnum(applymentStateQueryResult.getApplymentState()); + if(enumApplymentState != null && !enumApplymentState.getCode().equals(receiverApply.getApplymentState())){ + WxProfitSharingReceiverApply receiverApplyUpd = new WxProfitSharingReceiverApply(); + receiverApplyUpd.updateTenantInfo(receiverApply); + receiverApplyUpd.setId(receiverApply.getId()); + if(enumApplymentState.equals(EnumSharingReceiverApplymentState.APPLYMENT_STATE_FINISHED)){ + receiverApplyUpd.setSubMchid(applymentStateQueryResult.getSubMchid()); + } + receiverApplyUpd.setSignUrl(applymentStateQueryResult.getSignUrl()); + receiverApplyUpd.setApplymentState(enumApplymentState.getCode()); + receiverApplyUpd.setApplymentStateDesc(applymentStateQueryResult.getApplymentStateMsg()); + if(enumApplymentState.equals(EnumSharingReceiverApplymentState.APPLYMENT_STATE_REJECTED)){ + receiverApplyUpd.setAuditDetail(JSON.toJSONString(applymentStateQueryResult.getAuditDetail())); + } + receiverApplyUpd.setUpdateTime(new Date()); + wxProfitSharingReceiverApplyMapper.updateById(receiverApplyUpd); + if(enumApplymentState.equals(EnumSharingReceiverApplymentState.APPLYMENT_STATE_FINISHED)){ + WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(receiverApply, receiverApply.getMerchantId(), EnumAppPlat.WX, EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2); + WxProfitSharingReceiver receiverUpd = new WxProfitSharingReceiver(); + receiverUpd.updateTenantInfo(receiverApply); + if(receiver != null){ + receiverUpd.setId(receiver.getId()); + receiverUpd.setReceiverAccount(receiverApplyUpd.getSubMchid()); + }else{ + receiverUpd.setPlat(EnumAppPlat.WX.getCode()); + receiverUpd.setMerchantId(receiverApply.getMerchantId()); + receiverUpd.setReceiverType(EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_MERCHANT_ID.getCode()); + receiverUpd.setReceiverAccount(receiverApplyUpd.getSubMchid()); + receiverUpd.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT_v2.getCode()); + receiverUpd.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + } + wxProfitSharingReceiverService.saveOrUpdate(receiverUpd); + } + } + return new ResultData(); + } catch (WxPayException e) { + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); + } + } + //------------------------------------------------------------------------------------------------------------------ diff --git a/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverApplyMapper.xml b/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverApplyMapper.xml index 5866540a2..79f4e0f67 100644 --- a/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverApplyMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxProfitSharingReceiverApplyMapper.xml @@ -115,6 +115,13 @@ and `status` = #{status} + + and `applyment_state` in + + #{idItem} + + + and id in @@ -130,6 +137,12 @@ from wx_profit_sharing_receiver_apply - + +