|
@@ -0,0 +1,226 @@
|
|
|
|
|
+package com.zhongshu.card.server.core.service.pay;
|
|
|
|
|
+
|
|
|
|
|
+import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
|
|
+import com.github.microservice.pay.client.model.AccountModel;
|
|
|
|
|
+import com.github.microservice.pay.client.model.PayProductParameter;
|
|
|
|
|
+import com.github.microservice.pay.client.model.chinaSenseless.ChinaSenselessSignRet;
|
|
|
|
|
+import com.github.microservice.pay.client.product.senseless.chinaumsSenseless.conf.ChinaumsSenselessConf;
|
|
|
|
|
+import com.github.microservice.pay.client.ret.ResultState;
|
|
|
|
|
+import com.github.microservice.pay.client.service.PayProductAccountService;
|
|
|
|
|
+import com.github.microservice.pay.client.service.product.SenselessPayService;
|
|
|
|
|
+import com.github.microservice.types.payment.PaymentType;
|
|
|
|
|
+import com.zhongshu.card.client.model.pay.ChinaumsSenselessUserSignInfoModel;
|
|
|
|
|
+import com.zhongshu.card.client.model.pay.UnionApplySignParam;
|
|
|
|
|
+import com.zhongshu.card.client.type.ContractState;
|
|
|
|
|
+import com.zhongshu.card.server.core.dao.pay.ChinaumsSenselessUserSignInfoDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.pay.ChinaumsSenselessUserSignInfo;
|
|
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
|
|
+import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
|
|
+import io.micrometer.common.util.StringUtils;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.poi.util.StringUtil;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import picocli.CommandLine;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class ChinaumsSenselessPayService extends SuperService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ OrgPayAccountService orgPayAccountService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ChinaumsSenselessUserSignInfoDao chinaumsSenselessUserSignInfoDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ SenselessPayService senselessPayService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ PayProductAccountService payProductAccountService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 银联申请签约
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public Object signApply(UnionApplySignParam param){
|
|
|
|
|
+
|
|
|
|
|
+ String projectOid = param.getProjectOid();
|
|
|
|
|
+ String userId = param.getUserId();
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isBlank(userId)){
|
|
|
|
|
+ userId = getCurrentUserId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isBlank(projectOid)){
|
|
|
|
|
+ projectOid = getCurrentProjectOid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取银联支付产品账户及需要签约的商户号
|
|
|
|
|
+ String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
|
|
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
|
|
|
|
|
+ if (!accountModelResultContent.getState().equals(ResultState.Success)){
|
|
|
|
|
+ return accountModelResultContent;
|
|
|
|
|
+ }
|
|
|
|
|
+ ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
|
|
|
|
|
+ String mid = conf.getMchId();
|
|
|
|
|
+
|
|
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMid(userId, mid);
|
|
|
|
|
+ param.setContractNo(CommonUtil.UUID());
|
|
|
|
|
+
|
|
|
|
|
+ if (userSignInfo!=null && userSignInfo.getContractState()!=null){
|
|
|
|
|
+ switch (userSignInfo.getContractState()){
|
|
|
|
|
+ case SIGNED -> {//已签约
|
|
|
|
|
+ return ResultContent.buildFail("签约已完成,请勿重复请求");
|
|
|
|
|
+ }
|
|
|
|
|
+ case UNSIGNED, RESCISSION -> {//未签约,已解约
|
|
|
|
|
+ return signApply(param, accountName, userId, mid);
|
|
|
|
|
+ }
|
|
|
|
|
+ case DELETING_CONTRACT, APPLY -> {
|
|
|
|
|
+ return ResultContent.buildFail("正在签约中,请等待银行返回结果");
|
|
|
|
|
+ }
|
|
|
|
|
+ case UNKNOWN ->{
|
|
|
|
|
+ return ResultContent.buildFail("未知状态,请联系管理人员");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return signApply(param, accountName, userId, mid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ResultContent.buildFail("数据不存在,请联系管理员");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Object signApply(UnionApplySignParam param, String accountName, String userId, String mid) {
|
|
|
|
|
+ PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
|
|
|
|
|
+ payProductParameter.setAccountName(accountName);
|
|
|
|
|
+ payProductParameter.setMeta(BeanUtil.bean2Map(param));
|
|
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<Object> signApplyResultContent = senselessPayService.signApply(payProductParameter);
|
|
|
|
|
+ if (signApplyResultContent.getState().equals(ResultState.Success)){
|
|
|
|
|
+ Object content = signApplyResultContent.getContent();
|
|
|
|
|
+ Map<String, Object> resultMap = BeanUtil.bean2Map(content);
|
|
|
|
|
+ String errCode = (String) resultMap.get("errCode");
|
|
|
|
|
+ if ("SUCCESS".equals(errCode)){
|
|
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = new ChinaumsSenselessUserSignInfo();
|
|
|
|
|
+ userSignInfo.setUserId(userId);
|
|
|
|
|
+ userSignInfo.setContractNo(param.getContractNo());
|
|
|
|
|
+ userSignInfo.setContractState(ContractState.APPLY);
|
|
|
|
|
+ userSignInfo.setMid(mid);
|
|
|
|
|
+ userSignInfo.setRelateSsn((String) resultMap.get("relateSsn"));
|
|
|
|
|
+ userSignInfo.setCqpMpAppId((String) resultMap.get("cqpMpAppId"));
|
|
|
|
|
+ userSignInfo.setCqpMpPath((String) resultMap.get("cqpMpPath"));
|
|
|
|
|
+ chinaumsSenselessUserSignInfoDao.save(userSignInfo);
|
|
|
|
|
+ return signApplyResultContent;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return ResultContent.buildFail((String) resultMap.get("errMsg"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildFail("银联请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解约
|
|
|
|
|
+ */
|
|
|
|
|
+ public Object signCancel(String userId, String projectOid) {
|
|
|
|
|
+ if (StringUtils.isBlank(userId)){
|
|
|
|
|
+ userId = getCurrentUserId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isBlank(projectOid)){
|
|
|
|
|
+ projectOid = getCurrentProjectOid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取银联支付产品账户及需要签约的商户号
|
|
|
|
|
+ String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
|
|
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
|
|
|
|
|
+ if (!accountModelResultContent.getState().equals(ResultState.Success)){
|
|
|
|
|
+ return accountModelResultContent;
|
|
|
|
|
+ }
|
|
|
|
|
+ ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
|
|
|
|
|
+ String mid = conf.getMchId();
|
|
|
|
|
+
|
|
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMid(userId, mid);
|
|
|
|
|
+ if (userSignInfo==null){
|
|
|
|
|
+ return ResultContent.buildFail("用户与该商户未签约");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (userSignInfo.getContractState()==null){
|
|
|
|
|
+ return ResultContent.buildFail("签约状态数据异常");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (userSignInfo.getContractState().equals(ContractState.RESCISSION)){
|
|
|
|
|
+ return ResultContent.buildFail("当前已经处于解约状态");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (userSignInfo.getContractState().equals(ContractState.SIGNED)){
|
|
|
|
|
+ PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
|
|
|
|
|
+ payProductParameter.setAccountName(accountName);
|
|
|
|
|
+ payProductParameter.setMeta(Map.of("contractId", userSignInfo.getContractId()));
|
|
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<Object> objectResultContent = senselessPayService.signCancel(payProductParameter);
|
|
|
|
|
+ if (objectResultContent.getState().equals(ResultState.Success)){
|
|
|
|
|
+ userSignInfo.setContractState(ContractState.DELETING_CONTRACT);
|
|
|
|
|
+ chinaumsSenselessUserSignInfoDao.save(userSignInfo);
|
|
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildFail("解约失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ResultContent.buildFail("当前状态不可解约,请稍后再试");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Object queryUserSignInfo(String userId, String projectOid){
|
|
|
|
|
+ if (StringUtils.isBlank(userId)){
|
|
|
|
|
+ userId = getCurrentUserId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isBlank(projectOid)){
|
|
|
|
|
+ projectOid = getCurrentProjectOid();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取银联支付产品账户及需要签约的商户号
|
|
|
|
|
+ String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
|
|
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
|
|
|
|
|
+ if (!accountModelResultContent.getState().equals(ResultState.Success)){
|
|
|
|
|
+ return accountModelResultContent;
|
|
|
|
|
+ }
|
|
|
|
|
+ ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
|
|
|
|
|
+ String mid = conf.getMchId();
|
|
|
|
|
+
|
|
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMid(userId, mid);
|
|
|
|
|
+ if (userSignInfo==null){
|
|
|
|
|
+ ChinaumsSenselessUserSignInfoModel model = new ChinaumsSenselessUserSignInfoModel();
|
|
|
|
|
+ model.setUserId(userId);
|
|
|
|
|
+ model.setContractState(ContractState.UNSIGNED);
|
|
|
|
|
+ return ResultContent.buildContent(model);
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultContent.buildContent(toUserSignModel(userSignInfo));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private ChinaumsSenselessUserSignInfoModel toUserSignModel(ChinaumsSenselessUserSignInfo userSignInfo){
|
|
|
|
|
+ ChinaumsSenselessUserSignInfoModel model = new ChinaumsSenselessUserSignInfoModel();
|
|
|
|
|
+ if (userSignInfo!=null){
|
|
|
|
|
+ BeanUtils.copyProperties(userSignInfo, model);
|
|
|
|
|
+ }
|
|
|
|
|
+ return model;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void handleSignRetMessage(ChinaSenselessSignRet chinaSenselessSignRet){
|
|
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = chinaumsSenselessUserSignInfoDao.findTopByContractNo(chinaSenselessSignRet.getContractNo());
|
|
|
|
|
+ if (userSignInfo == null){
|
|
|
|
|
+ log.info("签约通知回调:找不到签约用户信息 contractNo:{}", chinaSenselessSignRet.getContractNo());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ userSignInfo.setContractState(ContractState.valueOf(chinaSenselessSignRet.getContractState()));
|
|
|
|
|
+ userSignInfo.setContractId(chinaSenselessSignRet.getContractId());
|
|
|
|
|
+ userSignInfo.setContractSignedTime(chinaSenselessSignRet.getContractSignedTime());
|
|
|
|
|
+ userSignInfo.setContractExpiredTime(chinaSenselessSignRet.getContractExpiredTime());
|
|
|
|
|
+ userSignInfo.setAcpId(chinaSenselessSignRet.getAcpId());
|
|
|
|
|
+ chinaumsSenselessUserSignInfoDao.save(userSignInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|