|
@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.sunxung.factoring.component.exception.ValidatorException;
|
|
|
import com.sunxung.factoring.component.util.CodeUtil;
|
|
|
import com.sunxung.factoring.component.util.ElectronicSignatureUtil;
|
|
|
+import com.sunxung.factoring.component.util.StringUtil;
|
|
|
import com.sunxung.factoring.entity.entprise.Enterprise;
|
|
|
import com.sunxung.factoring.entity.financing.contract.ElectronicPersonInfo;
|
|
|
import com.sunxung.factoring.entity.financing.contract.SysCustomer;
|
|
|
+import com.sunxung.factoring.entity.tradingPlatform.Platform;
|
|
|
import com.sunxung.factoring.mapper.financing.contract.SysCustomerMapper;
|
|
|
import com.sunxung.factoring.service.entprise.IEnterpriseService;
|
|
|
import com.sunxung.factoring.service.financing.contract.IElectronicPersonInfoService;
|
|
|
import com.sunxung.factoring.service.financing.contract.ISysCustomerService;
|
|
|
+import com.sunxung.factoring.service.tradingPlatform.PlatformService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -36,6 +39,9 @@ public class SysCustomerServiceImpl extends ServiceImpl<SysCustomerMapper, SysCu
|
|
|
@Autowired
|
|
|
private IElectronicPersonInfoService electronicPersonInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PlatformService platformService;
|
|
|
+
|
|
|
@Override
|
|
|
public SysCustomer getByName(String companyName) {
|
|
|
return baseMapper.getByName(companyName);
|
|
@@ -45,7 +51,12 @@ public class SysCustomerServiceImpl extends ServiceImpl<SysCustomerMapper, SysCu
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void add(SysCustomer sysCustomer) {
|
|
|
//是否存在该供应商
|
|
|
- SysCustomer customer = getOne(new QueryWrapper<SysCustomer>().eq("ent_business_id", sysCustomer.getEntBusinessId()).eq("account_type", sysCustomer.getAccountType()).last("LIMIT 1"));
|
|
|
+ SysCustomer customer;
|
|
|
+ if (sysCustomer.getEntBusinessId() != null) {
|
|
|
+ customer = getOne(new QueryWrapper<SysCustomer>().eq("ent_business_id", sysCustomer.getEntBusinessId()).eq("account_type", sysCustomer.getAccountType()).last("LIMIT 1"));
|
|
|
+ } else {
|
|
|
+ customer = lambdaQuery().eq(SysCustomer::getPlatformId, sysCustomer.getPlatformId()).eq(SysCustomer::getAccountType, sysCustomer.getAccountType()).one();
|
|
|
+ }
|
|
|
if (customer != null) {
|
|
|
throw new ValidatorException(CodeUtil.FAIL, "已经存在该企业信息,请勿重复添加");
|
|
|
}
|
|
@@ -62,45 +73,83 @@ public class SysCustomerServiceImpl extends ServiceImpl<SysCustomerMapper, SysCu
|
|
|
}
|
|
|
|
|
|
if (sysCustomer.getId() == null) {
|
|
|
-
|
|
|
- String openId = getOpenId(sysCustomer);
|
|
|
- //法大大认证
|
|
|
- String customerId = null;
|
|
|
- String authUrl = null;
|
|
|
- //添加身份信息
|
|
|
-
|
|
|
- String idType = sysCustomer.getElectronicPersonInfo() == null ? "" : sysCustomer.getElectronicPersonInfo().getCardTypeId();
|
|
|
- String idNumber = sysCustomer.getElectronicPersonInfo() == null ? "" : sysCustomer.getElectronicPersonInfo().getSocialCreditCode();
|
|
|
if (sysCustomer.getAccountType().equals("1")) {
|
|
|
- customerId = ElectronicSignatureUtil.registerAccount(openId, sysCustomer.getAccountType());
|
|
|
- String authResult = ElectronicSignatureUtil.getAuthUrl(sysCustomer.getAccountType(), customerId, null);
|
|
|
- JSONObject authJson = (JSONObject) JSONObject.parse(authResult);
|
|
|
- authUrl = authJson.getString("authUrl");
|
|
|
- } else if (sysCustomer.getAccountType().equals("2")) {
|
|
|
- String authResult = ElectronicSignatureUtil.getAuthUrl(sysCustomer.getAccountType(), openId, null);
|
|
|
- JSONObject authJson = (JSONObject) JSONObject.parse(authResult);
|
|
|
- authUrl = authJson.getString("authUrl");
|
|
|
- customerId = authJson.getString("customerId");
|
|
|
- }
|
|
|
+ String openId = getOpenId(sysCustomer);
|
|
|
+ //法大大认证
|
|
|
+ String customerId = null;
|
|
|
+ String authUrl = null;
|
|
|
+ //添加身份信息
|
|
|
|
|
|
- if (authUrl == null || customerId == null) {
|
|
|
- throw new ValidatorException(CodeUtil.FAIL, "生成认证链接出错");
|
|
|
+ String idType = sysCustomer.getElectronicPersonInfo() == null ? "" : sysCustomer.getElectronicPersonInfo().getCardTypeId();
|
|
|
+ String idNumber = sysCustomer.getElectronicPersonInfo() == null ? "" : sysCustomer.getElectronicPersonInfo().getSocialCreditCode();
|
|
|
+ if (sysCustomer.getAccountType().equals("1")) {
|
|
|
+ customerId = ElectronicSignatureUtil.registerAccount(openId, sysCustomer.getAccountType());
|
|
|
+ String authResult = ElectronicSignatureUtil.getAuthUrl(sysCustomer.getAccountType(), customerId, null);
|
|
|
+ JSONObject authJson = (JSONObject) JSONObject.parse(authResult);
|
|
|
+ authUrl = authJson.getString("authUrl");
|
|
|
+ if (authUrl == null || customerId == null) {
|
|
|
+ throw new ValidatorException(CodeUtil.FAIL, "生成认证链接出错");
|
|
|
+ }
|
|
|
+ String shortUrl = ElectronicSignatureUtil.shortUrl(null, authUrl);
|
|
|
+ sysCustomer.setShortAuthUrl(shortUrl);
|
|
|
+ sysCustomer.setShortAuthUrlCreate(new Date());
|
|
|
+ sysCustomer.setFddCustomerId(customerId);
|
|
|
+ sysCustomer.setAuthStatus(false);
|
|
|
+ sysCustomer.setAuthUrl(authUrl);
|
|
|
+ //开启自动签署
|
|
|
+ String transactionId = UUID.randomUUID().toString().trim().replaceAll("-", "").toUpperCase();
|
|
|
+ String beforeAutoSignUrl = ElectronicSignatureUtil.beforeAutoSign(transactionId, customerId, customerId);
|
|
|
+ String shortAutoSignUrl = ElectronicSignatureUtil.shortUrl(null, beforeAutoSignUrl);
|
|
|
+ sysCustomer.setShortAutoSignUrl(shortAutoSignUrl);
|
|
|
+ sysCustomer.setShortAutoSignUrlCreate(new Date());
|
|
|
+ sysCustomer.setTransactionId(transactionId);
|
|
|
+ sysCustomer.setAutoSignStatus(0);
|
|
|
+ sysCustomer.setAutoSignUrl(beforeAutoSignUrl);
|
|
|
+ }
|
|
|
+ } else if (sysCustomer.getAccountType().equals("2")) {
|
|
|
+ String shortUrl = null;
|
|
|
+ String customerId = null;
|
|
|
+ String authUrl = null;
|
|
|
+ String shortAutoSignUrl = null;
|
|
|
+ String transactionId = null;
|
|
|
+ String beforeAutoSignUrl = null;
|
|
|
+ Boolean authStatus = null;
|
|
|
+ Integer autoSignStatus = 0;
|
|
|
+ Date shortAuthUrlCreate = new Date();
|
|
|
+ Date shortAutoSignUrlCreate = new Date();
|
|
|
+ if (sysCustomer.getEntBusinessId() != null) {
|
|
|
+ Enterprise enterprise = enterpriseService.getById(sysCustomer.getEntBusinessId());
|
|
|
+ shortUrl = enterprise.getShortAuthUrl();
|
|
|
+ customerId = enterprise.getFddCustomerId();
|
|
|
+ authUrl = enterprise.getAuthUrl();
|
|
|
+ shortAutoSignUrl = enterprise.getShortAutoSignUrl();
|
|
|
+ beforeAutoSignUrl = enterprise.getAutoSignUrl();
|
|
|
+ authStatus = enterprise.getAuthStatus();
|
|
|
+ autoSignStatus = enterprise.getAutoSignStatus();
|
|
|
+ } else if (sysCustomer.getPlatformId() != null) {
|
|
|
+ Platform platform = platformService.getById(sysCustomer.getPlatformId());
|
|
|
+ shortUrl = platform.getShortAuthUrl();
|
|
|
+ customerId = platform.getFddCustomerId();
|
|
|
+ authUrl = platform.getAuthUrl();
|
|
|
+ shortAutoSignUrl = platform.getShortAutoSignUrl();
|
|
|
+ beforeAutoSignUrl = platform.getAutoSignUrl();
|
|
|
+ authStatus = platform.getAuthStatus() == 0 ? false : true;
|
|
|
+ autoSignStatus = platform.isAutoSignStatus() == true ? 1 : 0;
|
|
|
+ shortAuthUrlCreate = platform.getShortAuthUrlCreate();
|
|
|
+ shortAutoSignUrlCreate = platform.getShortAutoSignUrlCreate();
|
|
|
+ }
|
|
|
+ sysCustomer.setShortAuthUrl(shortUrl);
|
|
|
+ sysCustomer.setShortAuthUrlCreate(shortAuthUrlCreate);
|
|
|
+ sysCustomer.setFddCustomerId(customerId);
|
|
|
+ sysCustomer.setAuthStatus(authStatus);
|
|
|
+ sysCustomer.setAuthUrl(authUrl);
|
|
|
+ //开启自动签署
|
|
|
+ sysCustomer.setShortAutoSignUrl(shortAutoSignUrl);
|
|
|
+ sysCustomer.setShortAutoSignUrlCreate(shortAutoSignUrlCreate);
|
|
|
+ sysCustomer.setTransactionId(transactionId);
|
|
|
+ sysCustomer.setAutoSignStatus(autoSignStatus);
|
|
|
+ sysCustomer.setAutoSignUrl(beforeAutoSignUrl);
|
|
|
}
|
|
|
- String shortUrl = ElectronicSignatureUtil.shortUrl(null, authUrl);
|
|
|
- sysCustomer.setShortAuthUrl(shortUrl);
|
|
|
- sysCustomer.setShortAuthUrlCreate(new Date());
|
|
|
- sysCustomer.setFddCustomerId(customerId);
|
|
|
- sysCustomer.setAuthStatus(false);
|
|
|
- sysCustomer.setAuthUrl(authUrl);
|
|
|
- //开启自动签署
|
|
|
- String transactionId = UUID.randomUUID().toString().trim().replaceAll("-", "").toUpperCase();
|
|
|
- String beforeAutoSignUrl = ElectronicSignatureUtil.beforeAutoSign(transactionId, customerId, customerId);
|
|
|
- String shortAutoSignUrl = ElectronicSignatureUtil.shortUrl(null, beforeAutoSignUrl);
|
|
|
- sysCustomer.setShortAutoSignUrl(shortAutoSignUrl);
|
|
|
- sysCustomer.setShortAutoSignUrlCreate(new Date());
|
|
|
- sysCustomer.setTransactionId(transactionId);
|
|
|
- sysCustomer.setAutoSignStatus(0);
|
|
|
- sysCustomer.setAutoSignUrl(beforeAutoSignUrl);
|
|
|
// 保存记录
|
|
|
saveOrUpdate(sysCustomer);
|
|
|
}
|