| @@ -1,12 +1,19 @@ | |||
| package com.iformall.schedule; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.domain.po.WxMsgCallback; | |||
| import com.iformall.domain.po.WxMsgConfig; | |||
| import com.iformall.domain.po.WxMsgModel; | |||
| import com.iformall.enums.EnumMsgModelStatus; | |||
| import com.iformall.enums.EnumMsgSendStatus; | |||
| import com.iformall.mapper.WxMsgCallbackMapper; | |||
| import com.iformall.mapper.WxMsgConfigMapper; | |||
| import com.iformall.mapper.WxMsgModelMapper; | |||
| import com.iformall.service.WxMsgCallbackService; | |||
| import com.iformall.sms.EnumSMSChannel; | |||
| import com.iformall.sms.SMSFactory; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -15,6 +22,7 @@ import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -26,7 +34,13 @@ public class WxMsgModelSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxMsgModelMapper WxMsgModelMapper; | |||
| WxMsgModelMapper wxMsgModelMapper; | |||
| @Autowired | |||
| WxMsgCallbackMapper wxMsgCallbackMapper; | |||
| @Autowired | |||
| WxMsgCallbackService wxMsgCallbackService; | |||
| @Autowired | |||
| WxMsgConfigMapper wxMsgConfigMapper; | |||
| @@ -36,7 +50,7 @@ public class WxMsgModelSchedule { | |||
| public void querySmsTemplate() { | |||
| WxMsgModel msgModel = new WxMsgModel(); | |||
| msgModel.setStatus(EnumMsgModelStatus.AUDITING.getCode()); | |||
| List<WxMsgModel> aliYunList = WxMsgModelMapper.findAliYunList(msgModel); | |||
| List<WxMsgModel> aliYunList = wxMsgModelMapper.findAliYunList(msgModel); | |||
| if(!aliYunList.isEmpty()){ | |||
| Map<String, List<WxMsgModel>> collect = aliYunList.stream().collect(groupingBy(WxMsgModel::getTenantId)); | |||
| for (String tenantId:collect.keySet()) { | |||
| @@ -62,7 +76,7 @@ public class WxMsgModelSchedule { | |||
| updModel.setStatus(templateStatus.intValue() == 1?EnumMsgModelStatus.SUCCESS.getCode():EnumMsgModelStatus.FAIL.getCode()); | |||
| updModel.setReason(reason); | |||
| updModel.setModelCode(templateCode); | |||
| WxMsgModelMapper.updateByCode(updModel); | |||
| wxMsgModelMapper.updateByCode(updModel); | |||
| } | |||
| } | |||
| }catch (Exception e){ | |||
| @@ -74,9 +88,46 @@ public class WxMsgModelSchedule { | |||
| } | |||
| } | |||
| } | |||
| @Async | |||
| @Scheduled(cron = "0 */30 * * * ?") // | |||
| public void querySendDetails() { | |||
| WxMsgCallback msgCallback = new WxMsgCallback(); | |||
| msgCallback.setStatus(EnumMsgSendStatus.MSG_SENDING.getCode()); | |||
| String before5dayStr = DateUtils.getTimeBefore(4, new Date()); | |||
| Date before5day = DateUtils.stringToDate(before5dayStr); | |||
| msgCallback.setCreateStartTime(before5day);//近5天的短信 | |||
| List<WxMsgCallback> list = wxMsgCallbackMapper.findList(msgCallback); | |||
| if(!list.isEmpty()){ | |||
| Map<String, List<WxMsgCallback>> collect = list.stream().collect(groupingBy(WxMsgCallback::getTenantId)); | |||
| for (String tenantId:collect.keySet()) { | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(tenantId); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0){ | |||
| logger.error("您还未接入短信运营商,请联系平台管理员"); | |||
| }else{ | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| List<WxMsgCallback> wxMsgCallbacks = collect.get(tenantId); | |||
| for (WxMsgCallback callback:wxMsgCallbacks) { | |||
| try{ | |||
| String result = SMSFactory.querySendDetails(wxMsgConfig,callback.getPhone(),callback.getBatchNo(),callback.getCreatetime()); | |||
| if(StringUtils.isNotBlank(result)){ | |||
| Map<String,String> map = JSON.parseObject(result, Map.class); | |||
| String smsChannel = map.get("smsChannel"); | |||
| if(EnumSMSChannel.ALIYUN.name().equals(smsChannel)){ | |||
| wxMsgCallbackService.receivemsgAliyun(map); | |||
| } | |||
| } | |||
| }catch (Exception e){ | |||
| logger.error("查询模板审核状态失败"+e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| @@ -47,4 +48,7 @@ public class WxMsgCallback extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value = "业务ID", name = "businessId") | |||
| private Long businessId; | |||
| @TableField(exist = false) | |||
| private Date createStartTime; | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| package com.iformall.domain.po; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import java.util.Date; | |||
| @@ -59,6 +62,39 @@ public class WxProfitSharingReceiver extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value = "0,不使用 1,使用", name = "isUse") | |||
| private Integer isUse; | |||
| @io.swagger.annotations.ApiModelProperty(value = "进件状态", name = "ttImportStatus") | |||
| private String ttImportStatus; | |||
| @TableField(exist = false) | |||
| private Integer wxImportStatus; | |||
| @TableField(exist = false) | |||
| private Integer alipayImportStatus; | |||
| @TableField(exist = false) | |||
| private Integer hzImportStatus; | |||
| private QueryMerchantResult getMerchantResult(){ | |||
| QueryMerchantResult queryMerchantResult = null; | |||
| try{ | |||
| if(StringUtils.isNotBlank(this.ttImportStatus)) { | |||
| queryMerchantResult = JSON.parseObject(this.ttImportStatus, QueryMerchantResult.class); | |||
| } | |||
| }catch(Exception e){} | |||
| if(queryMerchantResult == null){ | |||
| queryMerchantResult = new QueryMerchantResult(); | |||
| } | |||
| return queryMerchantResult; | |||
| } | |||
| public Integer getWxImportStatus(){ | |||
| return getMerchantResult().getWx(); | |||
| } | |||
| public Integer getAlipayImportStatus(){ | |||
| return getMerchantResult().getAlipay(); | |||
| } | |||
| public Integer getHzImportStatus(){ | |||
| return getMerchantResult().getHz(); | |||
| } | |||
| @io.swagger.annotations.ApiModelProperty(value = "进件页面", name = "ttImportUrl") | |||
| private String ttImportUrl; | |||
| @@ -295,6 +295,7 @@ public class DouYinPayHelper { | |||
| QueryMerchantResult result = new QueryMerchantResult(); | |||
| result.setWx(jsonObject.getInteger("wx")); | |||
| result.setAlipay(jsonObject.getInteger("alipay")); | |||
| result.setHz(jsonObject.getInteger("hz")); | |||
| return result; | |||
| }else { | |||
| log.error("queryMerchantStatus reponse error. request: "+JSON.toJSONString(map)+" response:"+response); | |||
| @@ -7,4 +7,6 @@ public class QueryMerchantResult { | |||
| private Integer wx;//微信渠道进件状态,0-未进件、1-进件成功、2-进件失败、3-审核中、4-冻结中 | |||
| private Integer alipay;//支付宝渠道进件状态,0-未进件、1-进件成功、2-进件失败、3-审核中 | |||
| private Integer hz;//抖音支付(合众)渠道进件状态,0-未进件、1-进件成功、2-进件失败、3-审核中 | |||
| } | |||
| @@ -401,16 +401,21 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| wxRentContract.setMerchantId(id); | |||
| long countRentContract = wxRentContractMapper.selectList(new QueryWrapper<>(wxRentContract)).parallelStream(). | |||
| filter(c -> EnumRentContractStatus.getValidStatus().contains(c.getStatus())).count(); | |||
| if(countRentContract > 0){ | |||
| throw new MallinkException(ErrorCode.SHOP_CONTRACT_HAS_CONNECT.getCode(),"存在租赁合同"); | |||
| } | |||
| //是否有物业合同 | |||
| WxPropertyContract wxPropertyContract = new WxPropertyContract(); | |||
| wxPropertyContract.setMerchantId(id); | |||
| long countPropertyContract = wxPropertyContractMapper.selectList(new QueryWrapper<>(wxPropertyContract)).parallelStream(). | |||
| filter(c -> EnumRentContractStatus.getValidStatus().contains(c.getStatus())).count(); | |||
| //商户状态停用-没有租赁合同和物业合同才允许停用 | |||
| if (countRentContract == 0 || countPropertyContract == 0){ | |||
| wxMerchant.setStatus(EnumMerchantStatus.NOT_VALID.getCode()); | |||
| wxMerchantMapper.updateById(wxMerchant); | |||
| // if (countRentContract == 0 || countPropertyContract == 0){ | |||
| // wxMerchant.setStatus(EnumMerchantStatus.NOT_VALID.getCode()); | |||
| // wxMerchantMapper.updateById(wxMerchant); | |||
| // } | |||
| if(countPropertyContract > 0){ | |||
| throw new MallinkException(ErrorCode.SHOP_CONTRACT_HAS_CONNECT.getCode(),"存在物业合同"); | |||
| } | |||
| //解绑商铺-没有租赁合同或物业合同才可以 | |||
| if (countRentContract == 0 || countPropertyContract == 0) { | |||
| @@ -1,5 +1,7 @@ | |||
| package com.iformall.sms; | |||
| import java.util.Date; | |||
| public interface SMSExcutor { | |||
| String sendMsg(String secret, String bid, String publickey,String phone, String signature, | |||
| @@ -12,4 +14,6 @@ public interface SMSExcutor { | |||
| String querySmsTemplate(String templateCode); | |||
| String querySendDetail(String phone, String bizId, Date sendDate); | |||
| } | |||
| @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| import javax.annotation.PostConstruct; | |||
| import java.util.Date; | |||
| @Component | |||
| public class SMSFactory { | |||
| @@ -68,4 +69,8 @@ public class SMSFactory { | |||
| return getSendExcutor(wxMsgConfig).querySmsTemplate(templateCode); | |||
| } | |||
| public static String querySendDetails(WxMsgConfig wxMsgConfig, String phone, String bizId, Date sendDate) { | |||
| return getSendExcutor(wxMsgConfig).querySendDetail(phone, bizId, sendDate); | |||
| } | |||
| } | |||
| @@ -8,15 +8,20 @@ import com.aliyuncs.dysmsapi.model.v20170525.*; | |||
| import com.aliyuncs.exceptions.ClientException; | |||
| import com.aliyuncs.profile.DefaultProfile; | |||
| import com.aliyuncs.profile.IClientProfile; | |||
| import com.iformall.sms.EnumSMSChannel; | |||
| import com.iformall.sms.SMSExcutor; | |||
| import com.iformall.sms.SMSResult; | |||
| import com.iformall.sms.aliyun.bean.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Component; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @Component | |||
| @Slf4j | |||
| @@ -79,6 +84,41 @@ public class AliyunSMS implements SMSExcutor { | |||
| return null; | |||
| } | |||
| @Override | |||
| public String querySendDetail(String phone, String bizId, Date sendDate) { | |||
| Query query = new Query(); | |||
| query.setPhoneNumber(phone); | |||
| query.setBizId(bizId); | |||
| query.setSendDate(sendDate); | |||
| query.setPageSize(10L); | |||
| query.setCurrentPage(1L); | |||
| QuerySendDetailsResponse querySendDetailsResponse = this.querySendDetails(query); | |||
| //获取返回结果 | |||
| if(querySendDetailsResponse.getCode() != null && querySendDetailsResponse.getCode().equals("OK") | |||
| && querySendDetailsResponse.getSmsSendDetailDTOs() != null | |||
| && !querySendDetailsResponse.getSmsSendDetailDTOs().isEmpty()){ | |||
| QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO = querySendDetailsResponse.getSmsSendDetailDTOs().get(0); | |||
| long sendStatus = smsSendDetailDTO.getSendStatus().longValue(); | |||
| String outId = smsSendDetailDTO.getOutId(); | |||
| String errCode = smsSendDetailDTO.getErrCode(); | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("smsChannel", EnumSMSChannel.ALIYUN.name()); | |||
| if(sendStatus == 2l){//1:等待回执。2:发送失败。3:发送成功。 | |||
| map.put("success","false"); | |||
| }else if(sendStatus == 3l){ | |||
| map.put("success","true"); | |||
| }else{ | |||
| return null; | |||
| } | |||
| map.put("biz_id",bizId); | |||
| map.put("out_id",outId); | |||
| map.put("err_msg",errCode); | |||
| return JSON.toJSONString(map); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 发送短信 | |||
| * @param sms | |||
| @@ -12,10 +12,7 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Set; | |||
| import java.util.TreeMap; | |||
| import java.util.*; | |||
| @Component | |||
| public class WiwideUtil implements SMSExcutor { | |||
| @@ -41,6 +38,11 @@ public class WiwideUtil implements SMSExcutor { | |||
| return null; | |||
| } | |||
| @Override | |||
| public String querySendDetail(String phone, String bizId, Date sendDate) { | |||
| return null; | |||
| } | |||
| public static String addTemplate(String secret, String bid, String publickey, String signature, String content, String notifyUrl, String verifysms) { | |||
| //请求api数据排序 | |||
| TreeMap<String, String> message = new TreeMap<>(); | |||
| @@ -77,7 +77,10 @@ | |||
| <if test=" null != createtime "> | |||
| and `createtime` = #{createtime} | |||
| </if> | |||
| </if> | |||
| <if test="createStartTime != null"> | |||
| AND `createtime` >= #{createStartTime} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -18,13 +18,14 @@ | |||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||
| <result column="parameter" jdbcType="VARCHAR" property="parameter" /> | |||
| <result column="tt_import_status" jdbcType="VARCHAR" property="ttImportStatus" /> | |||
| <result column="tt_import_url" jdbcType="VARCHAR" property="ttImportUrl" /> | |||
| <result column="tt_balance_url" jdbcType="VARCHAR" property="ttBalanceUrl" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`receiver_type`,`receiver_account`,`receiver_comments`,`create_time`,`update_time`,`sharing_type`,`bank_no`,`true_name`,`bank_code`,`status`,`parameter`,`is_use` | |||
| ,`tt_import_url`,`tt_balance_url` | |||
| ,`tt_import_status`,`tt_import_url`,`tt_balance_url` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -101,6 +102,15 @@ | |||
| and `is_use` = #{isUse} | |||
| </if> | |||
| <if test=" null != wxImportStatus"> | |||
| and `tt_import_status` -> '$.wx' = #{wxImportStatus} | |||
| </if> | |||
| <if test=" null != alipayImportStatus"> | |||
| and `tt_import_status` -> '$.alipay' = #{alipayImportStatus} | |||
| </if> | |||
| <if test=" null != hzImportStatus"> | |||
| and `tt_import_status` -> '$.hz' = #{hzImportStatus} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||