|
|
@@ -34,8 +34,10 @@ import com.fs.his.config.StoreConfig;
|
|
|
import com.fs.his.domain.FsInquiryOrder;
|
|
|
import com.fs.his.domain.FsStoreOrder;
|
|
|
import com.fs.his.domain.FsStorePayment;
|
|
|
+import com.fs.his.domain.SysRedpacketConfigMore;
|
|
|
import com.fs.his.dto.InquiryConfigDTO;
|
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
|
+import com.fs.his.mapper.SysRedpacketConfigMoreMapper;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
import com.fs.hisStore.domain.FsStorePaymentScrm;
|
|
|
@@ -89,6 +91,9 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
private CompanyMapper companyMapper;
|
|
|
@Autowired
|
|
|
private CompanyConfigMapper companyConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysRedpacketConfigMoreMapper sysRedpacketConfigMoreMapper;
|
|
|
@Autowired
|
|
|
private ICompanyMiniappService companyMiniappService;
|
|
|
@Autowired
|
|
|
@@ -284,63 +289,44 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R checkMchTransferStatusByBatchID(String batchId, Long companyId, String appId) {
|
|
|
- // 获取配置信息
|
|
|
- CourseConfig courseConfig = JSONUtil.toBean(configService.selectConfigByKey("course.config"), CourseConfig.class);
|
|
|
-
|
|
|
- String json;
|
|
|
- RedPacketConfig config = new RedPacketConfig();
|
|
|
- // 根据红包模式获取配置
|
|
|
- switch (courseConfig.getRedPacketMode()){
|
|
|
- case 1:
|
|
|
- json = configService.selectConfigByKey("redPacket.config");
|
|
|
- config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- json = companyConfigService.selectRedPacketConfigByKey(companyId);
|
|
|
- //如果分公司配置为空就走总后台的配置
|
|
|
- if (StringUtils.isEmpty(json)){
|
|
|
- json = configService.selectConfigByKey("redPacket.config");
|
|
|
- }
|
|
|
- config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new UnsupportedOperationException("当前红包模式不支持!");
|
|
|
+ public R checkMchTransferStatusByBatchID(String batchId, Long companyId, String appId, String mchId) {
|
|
|
+ // 参数校验
|
|
|
+ if (StringUtils.isEmpty(batchId)) {
|
|
|
+ return R.error("批次号不能为空");
|
|
|
}
|
|
|
-
|
|
|
- //创建微信订单
|
|
|
- WxPayConfig payConfig = new WxPayConfig();
|
|
|
- // 如果是应用app
|
|
|
- String appJson = configService.selectConfigByKey("app.config");
|
|
|
- AppConfig app = JSONUtil.toBean(appJson, AppConfig.class);
|
|
|
- if(StringUtils.equals(app.getAppId(),appId)){
|
|
|
- json = configService.selectConfigByKey("his.AppRedPacket");
|
|
|
- AppRedPacketConfig appRedPacketConfig = JSONUtil.toBean(json, AppRedPacketConfig.class);
|
|
|
- BeanUtils.copyProperties(appRedPacketConfig,payConfig);
|
|
|
- }else {
|
|
|
- BeanUtils.copyProperties(config,payConfig);
|
|
|
+ if (companyId == null) {
|
|
|
+ return R.error("公司ID不能为空");
|
|
|
}
|
|
|
+ if (StringUtils.isEmpty(appId)) {
|
|
|
+ return R.error("appId不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取红包配置
|
|
|
+ RedPacketConfig config = getRedPacketConfig(companyId, mchId);
|
|
|
|
|
|
+ // 构建微信支付配置
|
|
|
+ WxPayConfig payConfig = buildWxPayConfig(appId, config);
|
|
|
|
|
|
WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
wxPayService.setConfig(payConfig);
|
|
|
- TransferService transferService=wxPayService.getTransferService();
|
|
|
+ TransferService transferService = wxPayService.getTransferService();
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>(2);
|
|
|
+ map.put("status", "待确认");
|
|
|
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("status","待确认"); //
|
|
|
if (config.getIsNew() != null && config.getIsNew() == 1) {
|
|
|
try {
|
|
|
- TransferBillsGetResult queryRedPacketResult = transferService.getBillsByTransferBillNo(batchId);
|
|
|
- logger.info("FsCourseRedPacketLog-batchId:{},【红包处理】查询批次结果:{}",batchId,queryRedPacketResult.toString());
|
|
|
- if(("SUCCESS").equals(queryRedPacketResult.getState())){
|
|
|
- map.put("status","success");
|
|
|
- }else if(("FAIL").equals(queryRedPacketResult.getState())){
|
|
|
- map.put("status","fail");
|
|
|
+ TransferBillsGetResult result = transferService.getBillsByTransferBillNo(batchId);
|
|
|
+ logger.info("FsCourseRedPacketLog-batchId:{},【红包处理】查询批次结果:{}", batchId, result.toString());
|
|
|
+ if ("SUCCESS".equals(result.getState())) {
|
|
|
+ map.put("status", "success");
|
|
|
+ } else if ("FAIL".equals(result.getState())) {
|
|
|
+ map.put("status", "fail");
|
|
|
}
|
|
|
return R.ok(map);
|
|
|
} catch (WxPayException e) {
|
|
|
- logger.error(e.getMessage());
|
|
|
- return R.error(e.getMessage());
|
|
|
+ logger.error("查询转账批次状态异常, batchId:{}, error:{}", batchId, e.getMessage(), e);
|
|
|
+ return R.error("查询转账状态失败:" + e.getMessage());
|
|
|
}
|
|
|
} else {
|
|
|
QueryTransferBatchesRequest request = new QueryTransferBatchesRequest();
|
|
|
@@ -348,20 +334,72 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
request.setNeedQueryDetail(false);
|
|
|
|
|
|
try {
|
|
|
- QueryTransferBatchesResult queryTransferBatchesResult = transferService.transferBatchesBatchId(request);
|
|
|
- logger.info("FsCourseRedPacketLog-batchId,【红包处理】查询批次结果:{}",batchId,queryTransferBatchesResult.toString());
|
|
|
- if(("FINISHED").equals(queryTransferBatchesResult.getTransferBatch().getBatchStatus())){
|
|
|
- map.put("status","success");
|
|
|
- }else if(("CLOSED").equals(queryTransferBatchesResult.getTransferBatch().getBatchStatus())){
|
|
|
- map.put("status","fail");
|
|
|
+ QueryTransferBatchesResult result = transferService.transferBatchesBatchId(request);
|
|
|
+ logger.info("FsCourseRedPacketLog-batchId:{},【红包处理】查询批次结果:{}", batchId, result.toString());
|
|
|
+ if ("FINISHED".equals(result.getTransferBatch().getBatchStatus())) {
|
|
|
+ map.put("status", "success");
|
|
|
+ } else if ("CLOSED".equals(result.getTransferBatch().getBatchStatus())) {
|
|
|
+ map.put("status", "fail");
|
|
|
}
|
|
|
return R.ok(map);
|
|
|
} catch (WxPayException e) {
|
|
|
- logger.error(e.getMessage());
|
|
|
- return R.error(e.getMessage());
|
|
|
+ logger.error("查询转账批次状态异常, batchId:{}, error:{}", batchId, e.getMessage(), e);
|
|
|
+ return R.error("查询转账状态失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取红包配置
|
|
|
+ */
|
|
|
+ private RedPacketConfig getRedPacketConfig(Long companyId, String mchId) {
|
|
|
+ RedPacketConfig config = new RedPacketConfig();
|
|
|
+ if (StringUtils.isNotEmpty(mchId)) {
|
|
|
+ SysRedpacketConfigMore sysRedpacketConfigMore = sysRedpacketConfigMoreMapper.selectSysRedpacketConfigMoreByMchId(mchId);
|
|
|
+ BeanUtils.copyProperties(sysRedpacketConfigMore, config);
|
|
|
+ // 设置回调地址,在notifyUrl末尾拼接companyId
|
|
|
+ String notifyUrl = sysRedpacketConfigMore.getNotifyUrl();
|
|
|
+ if (StringUtils.isNotEmpty(notifyUrl)) {
|
|
|
+ config.setNotifyUrl(notifyUrl + "/" + companyId);
|
|
|
}
|
|
|
+ return config;
|
|
|
}
|
|
|
|
|
|
+ // 根据红包模式获取配置
|
|
|
+ CourseConfig courseConfig = JSONUtil.toBean(configService.selectConfigByKey("course.config"), CourseConfig.class);
|
|
|
+ String json;
|
|
|
+ switch (courseConfig.getRedPacketMode()) {
|
|
|
+ case 1:
|
|
|
+ json = configService.selectConfigByKey("redPacket.config");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ json = companyConfigService.selectRedPacketConfigByKey(companyId);
|
|
|
+ // 如果分公司配置为空就走总后台的配置
|
|
|
+ if (StringUtils.isEmpty(json)) {
|
|
|
+ json = configService.selectConfigByKey("redPacket.config");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new UnsupportedOperationException("当前红包模式不支持!");
|
|
|
+ }
|
|
|
+ return JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建微信支付配置
|
|
|
+ */
|
|
|
+ private WxPayConfig buildWxPayConfig(String appId, RedPacketConfig config) {
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ String appJson = configService.selectConfigByKey("app.config");
|
|
|
+ AppConfig app = JSONUtil.toBean(appJson, AppConfig.class);
|
|
|
+ if (StringUtils.equals(app.getAppId(), appId)) {
|
|
|
+ String json = configService.selectConfigByKey("his.AppRedPacket");
|
|
|
+ AppRedPacketConfig appRedPacketConfig = JSONUtil.toBean(json, AppRedPacketConfig.class);
|
|
|
+ BeanUtils.copyProperties(appRedPacketConfig, payConfig);
|
|
|
+ } else {
|
|
|
+ BeanUtils.copyProperties(config, payConfig);
|
|
|
+ }
|
|
|
+ return payConfig;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -408,63 +446,59 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
|
|
|
@Override
|
|
|
public R changeMerchant(CompanyVO companyVO) {
|
|
|
- // 长春张磊的不允许换 自用交易写死
|
|
|
- if("20".equals(companyVO.getCompanyId().toString())){
|
|
|
- return R.error("该公司不允许换商户!");
|
|
|
+
|
|
|
+ // 通过商户号查询SysRedpacketConfigMore表获取配置
|
|
|
+ String redPacketMerchant = companyVO.getRedPacketMerchant();
|
|
|
+ if(StringUtils.isEmpty(redPacketMerchant)){
|
|
|
+ return R.error("商户号不能为空!");
|
|
|
+ }
|
|
|
+ SysRedpacketConfigMore sysRedpacketConfigMore = sysRedpacketConfigMoreMapper.selectSysRedpacketConfigMoreByMchId(redPacketMerchant);
|
|
|
+ if(sysRedpacketConfigMore == null){
|
|
|
+ return R.error("该商户不存在");
|
|
|
}
|
|
|
|
|
|
- CompanyConfig companyConfig =companyConfigMapper.selectCompanyConfigByKey(companyVO.getCompanyId(),"redPacket:config");
|
|
|
-
|
|
|
- String updateKey=REDIS_KEY_PREFIX + companyVO.getCompanyId();
|
|
|
- // 小艾的商户
|
|
|
- if("1103448555".equals(companyVO.getRedPacketMerchant())){
|
|
|
- String redisKey = REDIS_KEY_PREFIX + 20;
|
|
|
- String json = redisTemplate.opsForValue().get(redisKey);
|
|
|
- if(json!=null){
|
|
|
- RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
- String url = config.getNotifyUrl();
|
|
|
- url=url.substring(0,url.lastIndexOf("/")+1)+companyVO.getCompanyId();
|
|
|
- config.setNotifyUrl(url);
|
|
|
- redisTemplate.opsForValue().set(updateKey,JSONUtil.toJsonStr(config));
|
|
|
-
|
|
|
- if(companyConfig!=null){
|
|
|
- // 更新数据库
|
|
|
- CompanyConfig updateConfig= new CompanyConfig();
|
|
|
- updateConfig.setCompanyId(companyVO.getCompanyId());
|
|
|
- updateConfig.setConfigId(companyConfig.getConfigId());
|
|
|
- updateConfig.setConfigValue(JSONUtil.toJsonStr(config));
|
|
|
- companyConfigMapper.updateCompanyConfig(updateConfig);
|
|
|
- }else {
|
|
|
- CompanyConfig save=new CompanyConfig();
|
|
|
- save.setCompanyId(companyVO.getCompanyId());
|
|
|
- save.setConfigKey("redPacket:config");
|
|
|
- save.setConfigValue(JSONUtil.toJsonStr(config));
|
|
|
- save.setConfigType("N");
|
|
|
- companyConfigMapper.insertCompanyConfig( save);
|
|
|
- }
|
|
|
- }
|
|
|
- }else if("1700010711".equals(companyVO.getRedPacketMerchant())){
|
|
|
- if(redisCache.getCacheObject(updateKey) != null){
|
|
|
- redisCache.deleteObject(updateKey);
|
|
|
- if(companyConfig!=null){
|
|
|
- // 更新数据库
|
|
|
- CompanyConfig updateConfig= new CompanyConfig();
|
|
|
- updateConfig.setCompanyId(companyVO.getCompanyId());
|
|
|
- updateConfig.setConfigId(companyConfig.getConfigId());
|
|
|
- updateConfig.setConfigValue("");
|
|
|
- companyConfigMapper.updateCompanyConfig(updateConfig);
|
|
|
- }else {
|
|
|
- CompanyConfig save=new CompanyConfig();
|
|
|
- save.setCompanyId(companyVO.getCompanyId());
|
|
|
- save.setConfigKey("redPacket:config");
|
|
|
- save.setConfigValue("");
|
|
|
- save.setConfigType("N");
|
|
|
- companyConfigMapper.insertCompanyConfig( save);
|
|
|
- }
|
|
|
- }
|
|
|
+ String updateKey = REDIS_KEY_PREFIX + companyVO.getCompanyId();
|
|
|
+ CompanyConfig companyConfig = companyConfigMapper.selectCompanyConfigByKey(companyVO.getCompanyId(),"redPacket:config");
|
|
|
|
|
|
+ // 构建RedPacketConfig
|
|
|
+ RedPacketConfig config = new RedPacketConfig();
|
|
|
+ config.setAppId(sysRedpacketConfigMore.getAppId());
|
|
|
+ config.setMiniappId(sysRedpacketConfigMore.getMiniappId());
|
|
|
+ config.setMchId(sysRedpacketConfigMore.getMchId());
|
|
|
+ config.setMchKey(sysRedpacketConfigMore.getMchKey());
|
|
|
+ config.setKeyPath(sysRedpacketConfigMore.getKeyPath());
|
|
|
+ config.setPrivateKeyPath(sysRedpacketConfigMore.getPrivateKeyPath());
|
|
|
+ config.setPrivateCertPath(sysRedpacketConfigMore.getPrivateCertPath());
|
|
|
+ config.setApiV3Key(sysRedpacketConfigMore.getApiV3Key());
|
|
|
+ config.setPublicKeyId(sysRedpacketConfigMore.getPublicKeyId());
|
|
|
+ config.setPublicKeyPath(sysRedpacketConfigMore.getPublicKeyPath());
|
|
|
+ config.setIsNew(sysRedpacketConfigMore.getIsNew());
|
|
|
+
|
|
|
+ // 设置回调地址,在notifyUrl末尾拼接companyId
|
|
|
+ String notifyUrl = sysRedpacketConfigMore.getNotifyUrl();
|
|
|
+ if(StringUtils.isNotEmpty(notifyUrl)){
|
|
|
+ notifyUrl = notifyUrl + "/" + companyVO.getCompanyId();
|
|
|
+ }
|
|
|
+ config.setNotifyUrl(notifyUrl);
|
|
|
+ config.setNotifyUrlScrm(sysRedpacketConfigMore.getNotifyUrlScrm());
|
|
|
+
|
|
|
+ // 更新Redis缓存
|
|
|
+ redisTemplate.opsForValue().set(updateKey, JSONUtil.toJsonStr(config));
|
|
|
+
|
|
|
+ // 更新/新增数据库配置
|
|
|
+ if(companyConfig != null){
|
|
|
+ CompanyConfig updateConfig = new CompanyConfig();
|
|
|
+ updateConfig.setCompanyId(companyVO.getCompanyId());
|
|
|
+ updateConfig.setConfigId(companyConfig.getConfigId());
|
|
|
+ updateConfig.setConfigValue(JSONUtil.toJsonStr(config));
|
|
|
+ companyConfigMapper.updateCompanyConfig(updateConfig);
|
|
|
}else {
|
|
|
- return R.error("该商户不存在");
|
|
|
+ CompanyConfig save = new CompanyConfig();
|
|
|
+ save.setCompanyId(companyVO.getCompanyId());
|
|
|
+ save.setConfigKey("redPacket:config");
|
|
|
+ save.setConfigValue(JSONUtil.toJsonStr(config));
|
|
|
+ save.setConfigType("N");
|
|
|
+ companyConfigMapper.insertCompanyConfig(save);
|
|
|
}
|
|
|
|
|
|
return R.ok();
|
|
|
@@ -1981,7 +2015,7 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
}
|
|
|
|
|
|
if(!StringUtils.isEmpty(redLogs.getBatchId())){
|
|
|
- R result=checkMchTransferStatusByBatchID(redLogs.getBatchId(),redLogs.getCompanyId(),redLogs.getAppId());
|
|
|
+ R result=checkMchTransferStatusByBatchID(redLogs.getBatchId(),redLogs.getCompanyId(),redLogs.getAppId(),redLogs.getMchId());
|
|
|
if("200".equals(String.valueOf(result.get("code")))){
|
|
|
FsCourseRedPacketLog update = new FsCourseRedPacketLog();
|
|
|
update.setUpdateTime(new Date());
|