| @@ -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<WxProfitSharingReceiverApply> 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()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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<Integer> applymentStates; | |||
| @io.swagger.annotations.ApiModelProperty(value="申请状态描述",name="applymentStateDesc") | |||
| private String applymentStateDesc; | |||
| @io.swagger.annotations.ApiModelProperty(value="EnumSharingReceiverSignState 签约状态",name="signState") | |||
| @@ -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<Integer> getNeedSyncList(){ | |||
| List<Integer> 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; | |||
| } | |||
| } | |||
| @@ -10,4 +10,6 @@ public interface WxProfitSharingReceiverApplyMapper extends CommonMapper<WxProfi | |||
| List<WxProfitSharingReceiverApply> findList(WxProfitSharingReceiverApply apply); | |||
| List<WxProfitSharingReceiverApply> findListByApplymentState(WxProfitSharingReceiverApply apply); | |||
| } | |||
| @@ -26,4 +26,6 @@ public interface WxProfitSharingReceiverApplyService { | |||
| ResultData applyment(WxProfitSharingReceiverApply receiverAdd); | |||
| ResultData handApplymentStates(WxProfitSharingReceiverApply apply); | |||
| } | |||
| @@ -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()); | |||
| } | |||
| } | |||
| //------------------------------------------------------------------------------------------------------------------ | |||
| @@ -115,6 +115,13 @@ | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != applymentStates "> | |||
| and `applyment_state` in | |||
| <foreach collection="applymentStates" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -130,6 +137,12 @@ | |||
| from wx_profit_sharing_receiver_apply | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="findListByApplymentState" parameterType="com.iformall.domain.po.WxProfitSharingReceiverApply" resultMap="BaseResultMap"> | |||
| select | |||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`plat`,`out_request_no`,`applyment_id`,`applyment_state` | |||
| from wx_profit_sharing_receiver_apply | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| </mapper> | |||