|
|
|
@ -1,12 +1,15 @@ |
|
|
|
|
package com.daqing.financial.crms.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.daqing.financial.crms.dao.CompanyCustomerDao; |
|
|
|
|
import com.daqing.financial.crms.dao.CustomerAppletDao; |
|
|
|
|
import com.daqing.financial.crms.dao.CustomerDao; |
|
|
|
|
import com.daqing.financial.crms.dao.PersonalCustomerDao; |
|
|
|
|
import com.daqing.financial.crms.mapper.CrmsCustomerRelatedMapper; |
|
|
|
|
import com.daqing.financial.crms.model.request.CompanyAppletRequest; |
|
|
|
|
import com.daqing.financial.crms.model.request.CompanyCustomerRequest; |
|
|
|
|
import com.daqing.financial.crms.model.request.PersonalCustomerRequest; |
|
|
|
|
import com.daqing.financial.crms.model.request.PersonalAppletRequest; |
|
|
|
|
import com.daqing.financial.crms.service.CustomerAppletService; |
|
|
|
|
import com.daqing.financial.crms.service.CustomerService; |
|
|
|
|
import com.daqing.financial.crms.service.ICrmsCustomerRelatedService; |
|
|
|
@ -15,7 +18,6 @@ import com.daqing.framework.domain.crms.CrmsCustomerRelated; |
|
|
|
|
import com.daqing.framework.domain.crms.CustomerEntity; |
|
|
|
|
import com.daqing.framework.domain.crms.PersonalCustomerEntity; |
|
|
|
|
import com.daqing.framework.domain.crms.ext.CrmsConstant; |
|
|
|
|
import com.daqing.framework.domain.crms.ext.CustomerPersonalTOI; |
|
|
|
|
import com.daqing.framework.domain.crms.ext.CustomerPersonalTOU; |
|
|
|
|
import com.daqing.framework.domain.crms.response.CrmsCode; |
|
|
|
|
import com.daqing.framework.exception.ExceptionCast; |
|
|
|
@ -30,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
@ -49,34 +52,37 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
@Autowired |
|
|
|
|
private PersonalCustomerDao personalCustomerDao; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private CustomerService customerService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private CompanyCustomerDao companyCustomerDao; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ICrmsCustomerRelatedService crmsCustomerRelatedService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private CrmsCustomerRelatedMapper crmsCustomerRelatedMapper; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 录入(认证)个人类型客户数据 |
|
|
|
|
*/ |
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
public Boolean savePersonal(CustomerPersonalTOI customerPersonalTOI) { |
|
|
|
|
if (customerPersonalTOI.getName() != null && customerPersonalTOI.getName().length() != 0) { |
|
|
|
|
public Boolean savePersonal(PersonalAppletRequest personalAppletRequest) { |
|
|
|
|
if (this.getBaseMapper().getCustomerStatus(Integer.parseInt(this.getUserId()), 0) > 0) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_APPLET_EXIST); |
|
|
|
|
} |
|
|
|
|
if (personalAppletRequest.getName() != null && personalAppletRequest.getName().length() != 0) { |
|
|
|
|
// 客户姓名判重
|
|
|
|
|
List<String> names = customerDao.listCustomerName(0); // 个人类型客户名称
|
|
|
|
|
for (String name : names) { |
|
|
|
|
if (customerPersonalTOI.getName().equals(name)) { |
|
|
|
|
if (personalAppletRequest.getName().equals(name)) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_NAME_REPETITION); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CustomerEntity customerEntity = new CustomerEntity(); |
|
|
|
|
PersonalCustomerEntity personalCustomerEntity = new PersonalCustomerEntity(); |
|
|
|
|
BeanUtils.copyProperties(customerPersonalTOI, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(customerPersonalTOI, personalCustomerEntity); |
|
|
|
|
BeanUtils.copyProperties(personalAppletRequest, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(personalAppletRequest, personalCustomerEntity); |
|
|
|
|
// 设置客户编号
|
|
|
|
|
String code = customerDao.getCodeByType(CrmsConstant.CustomerType.PERSONAL_CUSTOMER.getType()); |
|
|
|
|
if (code == null || code.length() == 0) { |
|
|
|
@ -88,9 +94,8 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
customerEntity.setMotifyTime(new Date()); |
|
|
|
|
customerEntity.setType(CrmsConstant.CustomerType.PERSONAL_CUSTOMER.getType()); |
|
|
|
|
boolean customer = customerDao.saveCustomer(customerEntity); |
|
|
|
|
personalCustomerEntity.setCustomerId(customerEntity.getId()); |
|
|
|
|
// 将自增的客户id返回给工作台
|
|
|
|
|
customerPersonalTOI.setManager(customerEntity.getId()); |
|
|
|
|
personalCustomerEntity.setCustomerId(customerEntity.getId()); |
|
|
|
|
boolean personal = personalCustomerDao.savePersonalCustomer(personalCustomerEntity); |
|
|
|
|
Boolean user = this.getBaseMapper().saveCustomerIdAndUserId(customerEntity.getId().intValue(), Integer.parseInt(this.getUserId()), 0); |
|
|
|
|
return customer && personal && user; |
|
|
|
@ -101,20 +106,23 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
*/ |
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
public Boolean saveCompany(CompanyCustomerRequest companyCustomerReq) { |
|
|
|
|
public Boolean saveCompany(CompanyAppletRequest companyAppletRequest) { |
|
|
|
|
if (this.getBaseMapper().getCustomerStatus(Integer.parseInt(this.getUserId()), 1) > 0) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_APPLET_EXIST); |
|
|
|
|
} |
|
|
|
|
// 客户名称判重
|
|
|
|
|
if (companyCustomerReq.getName() != null && companyCustomerReq.getName().length() != 0) { |
|
|
|
|
if (companyAppletRequest.getName() != null && companyAppletRequest.getName().length() != 0) { |
|
|
|
|
List<String> names = customerDao.listCustomerName(1); // 企业类型客户名称
|
|
|
|
|
for (String name : names) { |
|
|
|
|
if (companyCustomerReq.getName().equals(name)) { |
|
|
|
|
if (companyAppletRequest.getName().equals(name)) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_NAME_REPETITION); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CustomerEntity customerEntity = new CustomerEntity(); |
|
|
|
|
CompanyCustomerEntity companyCustomerEntity = new CompanyCustomerEntity(); |
|
|
|
|
BeanUtils.copyProperties(companyCustomerReq, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(companyCustomerReq, companyCustomerEntity); |
|
|
|
|
BeanUtils.copyProperties(companyAppletRequest, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(companyAppletRequest, companyCustomerEntity); |
|
|
|
|
// 设置客户编号
|
|
|
|
|
String code = customerDao.getCodeByType(CrmsConstant.CustomerType.COMPANY_CUSTOMER.getType()); |
|
|
|
|
if (code == null || code.length() == 0) { |
|
|
|
@ -124,17 +132,16 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
customerEntity.setCode(PromptSuccess.COMPANY_CODE + String.format("%04d", (codeNumber + 1))); |
|
|
|
|
customerEntity.setMotifyTime(new Date()); |
|
|
|
|
customerEntity.setCreateTime(new Date()); |
|
|
|
|
customerEntity.setManager(companyCustomerReq.getManager()); |
|
|
|
|
customerEntity.setType(CrmsConstant.CustomerType.COMPANY_CUSTOMER.getType()); |
|
|
|
|
boolean customer = customerDao.saveCustomer(customerEntity); |
|
|
|
|
companyCustomerEntity.setCustomerId(customerEntity.getId()); |
|
|
|
|
int company = companyCustomerDao.insert(companyCustomerEntity); |
|
|
|
|
// 绑定客户信息和客户的用户信息
|
|
|
|
|
Boolean user = this.getBaseMapper().saveCustomerIdAndUserId(customerEntity.getId().intValue(), Integer.parseInt(this.getUserId()), 1); |
|
|
|
|
if (companyCustomerReq.getIsExistRelated() == 1) {//有关联人的情况下才绑定关联关系
|
|
|
|
|
if (companyAppletRequest.getIsExistRelated() == 1) {//有关联人的情况下才绑定关联关系
|
|
|
|
|
//绑定关联关系
|
|
|
|
|
List<CrmsCustomerRelated> relatedList = new ArrayList<>(); |
|
|
|
|
List<Integer> intList = companyCustomerReq.getRelatedId(); |
|
|
|
|
List<Integer> intList = companyAppletRequest.getRelatedId(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < intList.size(); i++) { |
|
|
|
|
CrmsCustomerRelated crmsCustomerRelated = new CrmsCustomerRelated(); |
|
|
|
@ -179,43 +186,120 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
* 查看认证的详情 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public ResponseResult getCustomer(Integer type) { |
|
|
|
|
|
|
|
|
|
public Object getCustomer(Integer type) { |
|
|
|
|
String userId = this.getUserId(); |
|
|
|
|
Integer customerId = this.getBaseMapper().getCustomerId(Integer.parseInt(userId), type); |
|
|
|
|
|
|
|
|
|
return customerService.queryCustomerById((long) customerId); |
|
|
|
|
if (customerId == null) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_APPLET_IS_NULL); |
|
|
|
|
} |
|
|
|
|
// 员工基本信息
|
|
|
|
|
CustomerEntity customer = customerDao.queryCustomerById((long) customerId); |
|
|
|
|
// 判断该客户的类型
|
|
|
|
|
if (type == 0) { |
|
|
|
|
PersonalAppletRequest personalAppletRequest = new PersonalAppletRequest(); |
|
|
|
|
PersonalCustomerEntity personalCustomerEntity = personalCustomerDao.queryPersonalCustomerById((long) customerId); |
|
|
|
|
BeanUtils.copyProperties(customer, personalAppletRequest); |
|
|
|
|
BeanUtils.copyProperties(personalCustomerEntity, personalAppletRequest); |
|
|
|
|
return personalAppletRequest; |
|
|
|
|
} |
|
|
|
|
if (type == 1) { |
|
|
|
|
CompanyAppletRequest companyAppletRequest = new CompanyAppletRequest(); |
|
|
|
|
CompanyCustomerEntity companyCustomerEntity = companyCustomerDao.selectOne(new QueryWrapper<CompanyCustomerEntity>() |
|
|
|
|
.eq("customer_id", (long) customerId)); |
|
|
|
|
BeanUtils.copyProperties(customer, companyAppletRequest); |
|
|
|
|
BeanUtils.copyProperties(companyCustomerEntity, companyAppletRequest); |
|
|
|
|
return companyAppletRequest; |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改个人类型的认证信息 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean updatePersonal(PersonalCustomerRequest personalCustomerRequest) { |
|
|
|
|
public Boolean updatePersonal(PersonalAppletRequest personalAppletRequest) { |
|
|
|
|
Integer customerId = this.getBaseMapper().getCustomerId(Integer.parseInt(this.getUserId()), 0); |
|
|
|
|
if (customerId == null) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_APPLET_IS_NULL); |
|
|
|
|
} |
|
|
|
|
personalCustomerRequest.setId((long) customerId); |
|
|
|
|
personalCustomerRequest.setType(0); |
|
|
|
|
CustomerPersonalTOU customerPersonalTOU = new CustomerPersonalTOU(); |
|
|
|
|
BeanUtils.copyProperties(personalCustomerRequest, customerPersonalTOU); |
|
|
|
|
return customerService.updateCustomerPersonal(customerPersonalTOU); |
|
|
|
|
// 客户名称判重,注意判断是否与原来相同
|
|
|
|
|
if (personalAppletRequest.getName() != null && personalAppletRequest.getName().length() != 0) { |
|
|
|
|
String customerName = customerDao.getNameByCustomerId((long) customerId); |
|
|
|
|
if (!personalAppletRequest.getName().equals(customerName)) { |
|
|
|
|
List<String> names = customerDao.listCustomerName(0); |
|
|
|
|
for (String name : names) { |
|
|
|
|
if (personalAppletRequest.getName().equals(name)) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_NAME_REPETITION); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CustomerEntity customerEntity = new CustomerEntity(); |
|
|
|
|
PersonalCustomerEntity personalCustomerEntity = new PersonalCustomerEntity(); |
|
|
|
|
BeanUtils.copyProperties(personalAppletRequest, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(personalAppletRequest, personalCustomerEntity); |
|
|
|
|
customerEntity.setId((long) customerId); |
|
|
|
|
customerEntity.setMotifyTime(new Date()); |
|
|
|
|
boolean customer = this.getBaseMapper().updateCustomer(customerEntity); |
|
|
|
|
personalCustomerEntity.setCustomerId(customerEntity.getId()); |
|
|
|
|
boolean personal = personalCustomerDao.updatePersonalCustomer(personalCustomerEntity); |
|
|
|
|
return customer && personal; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改企业类型的认证信息 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Boolean updateCompany(CompanyCustomerRequest companyCustomerRequest) { |
|
|
|
|
public Boolean updateCompany(CompanyAppletRequest companyAppletRequest) { |
|
|
|
|
Integer customerId = this.getBaseMapper().getCustomerId(Integer.parseInt(this.getUserId()), 1); |
|
|
|
|
if (customerId == null) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_APPLET_IS_NULL); |
|
|
|
|
} |
|
|
|
|
companyCustomerRequest.setId((long) customerId); |
|
|
|
|
companyCustomerRequest.setType(1); |
|
|
|
|
// 客户名称判重,注意判断是否与原来相同
|
|
|
|
|
if (companyAppletRequest.getName() != null && companyAppletRequest.getName().length() != 0) { |
|
|
|
|
String customerName = customerDao.getNameByCustomerId((long) customerId); |
|
|
|
|
if (!companyAppletRequest.getName().equals(customerName)) { |
|
|
|
|
List<String> names = customerDao.listCustomerName(1); |
|
|
|
|
for (String name : names) { |
|
|
|
|
if (companyAppletRequest.getName().equals(name)) { |
|
|
|
|
ExceptionCast.cast(CrmsCode.CUSTOMER_NAME_REPETITION); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CustomerEntity customerEntity = new CustomerEntity(); |
|
|
|
|
CompanyCustomerEntity companyCustomerEntity = new CompanyCustomerEntity(); |
|
|
|
|
BeanUtils.copyProperties(companyAppletRequest, customerEntity); |
|
|
|
|
BeanUtils.copyProperties(companyAppletRequest, companyCustomerEntity); |
|
|
|
|
customerEntity.setId((long) customerId); |
|
|
|
|
customerEntity.setMotifyTime(new Date()); |
|
|
|
|
boolean customer = this.getBaseMapper().updateCustomer(customerEntity); |
|
|
|
|
companyCustomerEntity.setCustomerId(customerEntity.getId()); |
|
|
|
|
int company = companyCustomerDao.update(companyCustomerEntity, new QueryWrapper<CompanyCustomerEntity>() |
|
|
|
|
.eq("customer_id", companyCustomerEntity.getCustomerId())); |
|
|
|
|
|
|
|
|
|
//根据企业id删除关联关系
|
|
|
|
|
crmsCustomerRelatedMapper.delete(new QueryWrapper<CrmsCustomerRelated>().eq("customer_id", companyCustomerEntity.getId())); |
|
|
|
|
|
|
|
|
|
//绑定关联关系
|
|
|
|
|
List<CrmsCustomerRelated> relatedList = new ArrayList<>(); |
|
|
|
|
List<Integer> intList = companyAppletRequest.getRelatedId(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < intList.size(); i++) { |
|
|
|
|
CrmsCustomerRelated crmsCustomerRelated = new CrmsCustomerRelated(); |
|
|
|
|
Integer integer = intList.get(i); |
|
|
|
|
crmsCustomerRelated.setCustomerId(companyCustomerEntity.getId().intValue());//企业id
|
|
|
|
|
crmsCustomerRelated.setRelatedId(integer);//关联人/企业id
|
|
|
|
|
relatedList.add(crmsCustomerRelated); |
|
|
|
|
} |
|
|
|
|
if (relatedList.size() > 0) { |
|
|
|
|
crmsCustomerRelatedService.insertCustomerRelated(relatedList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return customerService.updateCompanyNew(companyCustomerRequest); |
|
|
|
|
if (customer && company > 0) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -223,12 +307,13 @@ public class CustomerAppletServiceImpl extends ServiceImpl<CustomerAppletDao, Cu |
|
|
|
|
* 获取当前登录用户信息 |
|
|
|
|
*/ |
|
|
|
|
private String getUserId() { |
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
|
/*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
|
String token = request.getHeader("token"); |
|
|
|
|
String userId = RedisUtil.get("dq:token:" + token); |
|
|
|
|
if (userId == null || userId.length() == 0) { |
|
|
|
|
ExceptionCast.cast(CommonCode.GET_LOGIN_USER_FAIL); |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
String userId = "63"; |
|
|
|
|
return userId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|