|
|
@@ -26,6 +26,9 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.client.entity.CorpsAddr;
|
|
|
+import org.springblade.client.entity.CorpsAttn;
|
|
|
+import org.springblade.client.entity.CorpsDesc;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
@@ -409,6 +412,183 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, PjCorpsDe
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 小程序客户详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R getDetails() {
|
|
|
+ PjCorpsAttn corpsAttn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsAttn::getUserId, AuthUtil.getUserId()));
|
|
|
+ if (ObjectUtils.isNotNull(corpsAttn)) {
|
|
|
+ PjCorpsDesc corpsDesc = baseMapper.getCorpId(corpsAttn.getPid());
|
|
|
+ if (ObjectUtils.isNotNull(corpsDesc)) {
|
|
|
+ PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAddr::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsAddr::getPid, corpsDesc.getId())
|
|
|
+ .eq(PjCorpsAddr::getDefaultAddres, "1"));
|
|
|
+ corpsDesc.setAttn(corpsAttn.getCname());
|
|
|
+ corpsDesc.setTel(corpsAttn.getTel());
|
|
|
+ corpsDesc.setAddr(corpsAddr.getBelongtoarea());
|
|
|
+ corpsDesc.setDetails(corpsAddr.getDetailedAddress());
|
|
|
+ return R.data(corpsDesc);
|
|
|
+ } else {
|
|
|
+ CorpsDesc corpsDesc1 = new CorpsDesc();
|
|
|
+ R<User> res = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ corpsDesc1.setTel(res.getData().getPhone());
|
|
|
+ }
|
|
|
+ return R.data(corpsDesc1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CorpsDesc corpsDesc1 = new CorpsDesc();
|
|
|
+ R<User> res = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ corpsDesc1.setTel(res.getData().getPhone());
|
|
|
+ }
|
|
|
+ return R.data(corpsDesc1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小程序新增或修改 客户详情
|
|
|
+ * @param corpsDesc
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R saveCorpsDesc(PjCorpsDesc corpsDesc) {
|
|
|
+ Long userId = SecureUtil.getUserId();
|
|
|
+ Long deptId = Long.valueOf(AuthUtil.getDeptId());
|
|
|
+ String deptName = sysClient.getDept(Long.valueOf(AuthUtil.getDeptId())).getData().getFullName();
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ //保存客户信息
|
|
|
+ corpsDesc.setCorpType("KH");
|
|
|
+ if (StringUtils.isBlank(corpsDesc.getCname())) {
|
|
|
+ return R.data(200, "error", "客户名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ PjCorpsDesc pjCorpsDesc = baseMapper.selectCorpsDescCname(corpsDesc.getCname(), AuthUtil.getTenantId());
|
|
|
+ if (ObjectUtils.isNotNull(pjCorpsDesc)) {
|
|
|
+ pjCorpsDesc.setSalesCompanyId(deptId);
|
|
|
+ pjCorpsDesc.setSalesCompanyName(deptName);
|
|
|
+ baseMapper.updateById(pjCorpsDesc);
|
|
|
+
|
|
|
+ PjCorpsAttn corpsAttn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsAttn::getPid, pjCorpsDesc.getId())
|
|
|
+ .eq(PjCorpsAttn::getTel, corpsDesc.getTel()));
|
|
|
+ if (ObjectUtils.isNotNull(corpsAttn)) {
|
|
|
+ corpsAttn.setCname(corpsDesc.getAttn());
|
|
|
+ corpsAttn.setTel(corpsDesc.getTel());
|
|
|
+ corpsAttn.setSalesCompanyId(deptId);
|
|
|
+ corpsAttn.setSalesCompanyName(deptName);
|
|
|
+ corpsAttnService.updateById(corpsAttn);
|
|
|
+ } else {
|
|
|
+ //保存客户联系人信息
|
|
|
+ PjCorpsAttn corpsAttn1 = new PjCorpsAttn();
|
|
|
+ User user = userClient.loginByAccount("", corpsDesc.getTel(), "4", AuthUtil.getTenantId());
|
|
|
+ if (ObjectUtils.isNotNull(user)) {
|
|
|
+ corpsAttn1.setUserId(user.getId());
|
|
|
+ }
|
|
|
+ corpsAttn1.setCname(corpsDesc.getAttn());
|
|
|
+ corpsAttn1.setTel(corpsDesc.getTel());
|
|
|
+ corpsAttn1.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAttn1.setPid(pjCorpsDesc.getId());
|
|
|
+ corpsAttn1.setCreateTime(new Date());
|
|
|
+ corpsAttn1.setCreateUser(AuthUtil.getUserId());
|
|
|
+ corpsAttn1.setSalesCompanyId(deptId);
|
|
|
+ corpsAttn1.setSalesCompanyName(deptName);
|
|
|
+ corpsAttnService.save(corpsAttn1);
|
|
|
+ }
|
|
|
+
|
|
|
+ PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAddr::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsAddr::getPid, pjCorpsDesc.getId())
|
|
|
+ .eq(PjCorpsAddr::getDefaultAddres, "1")
|
|
|
+ .eq(PjCorpsAddr::getTel, corpsDesc.getTel()));
|
|
|
+ if (ObjectUtils.isNotNull(corpsAddr)) {
|
|
|
+ corpsAddr.setContacts(corpsDesc.getAttn());
|
|
|
+ corpsAddr.setTel(corpsDesc.getTel());
|
|
|
+ corpsAddr.setBelongtoarea(corpsDesc.getAddr());
|
|
|
+ corpsAddr.setDetailedAddress(corpsDesc.getDetails());
|
|
|
+ corpsAddr.setSalesCompanyId(deptId);
|
|
|
+ corpsAddr.setSalesCompanyName(deptName);
|
|
|
+ corpsAddrService.updateById(corpsAddr);
|
|
|
+ } else {
|
|
|
+ //保存客户地址信息
|
|
|
+ PjCorpsAddr corpsAddr1 = new PjCorpsAddr();
|
|
|
+ corpsAddr1.setContacts(corpsDesc.getAttn());
|
|
|
+ corpsAddr1.setTel(corpsDesc.getTel());
|
|
|
+ corpsAddr1.setBelongtoarea(corpsDesc.getAddr());
|
|
|
+ corpsAddr1.setDetailedAddress(corpsDesc.getDetails());
|
|
|
+ corpsAddr1.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAddr1.setPid(pjCorpsDesc.getId());
|
|
|
+ corpsAddr1.setCreateTime(new Date());
|
|
|
+ corpsAddr1.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAddr1.setCreateUser(AuthUtil.getUserId());
|
|
|
+ corpsAddr1.setSalesCompanyId(deptId);
|
|
|
+ corpsAddr1.setSalesCompanyName(deptName);
|
|
|
+ corpsAddr.setDefaultAddres("1");
|
|
|
+ corpsAddrService.save(corpsAddr1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (null == corpsDesc.getId()) {
|
|
|
+ corpsDesc.setTenantId(SecureUtil.getTenantId());
|
|
|
+ corpsDesc.setCreateDept(Long.valueOf(SecureUtil.getDeptId()));
|
|
|
+ corpsDesc.setCreateTime(date);
|
|
|
+ corpsDesc.setCreateUser(userId);
|
|
|
+ corpsDesc.setPriceSystem("售价1");
|
|
|
+ corpsDesc.setSalesCompanyId(deptId);
|
|
|
+ corpsDesc.setSalesCompanyName(deptName);
|
|
|
+ baseMapper.insert(corpsDesc);
|
|
|
+ Long pId = corpsDesc.getId();
|
|
|
+ String tenantId = corpsDesc.getTenantId();
|
|
|
+
|
|
|
+ //保存客户联系人信息
|
|
|
+ PjCorpsAttn corpsAttn = new PjCorpsAttn();
|
|
|
+ User user = userClient.loginByAccount("", corpsDesc.getTel(), "4", AuthUtil.getTenantId());
|
|
|
+ if (ObjectUtils.isNotNull(user)) {
|
|
|
+ corpsAttn.setUserId(user.getId());
|
|
|
+ }
|
|
|
+ corpsAttn.setCname(corpsDesc.getAttn());
|
|
|
+ corpsAttn.setTel(corpsDesc.getTel());
|
|
|
+ corpsAttn.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAttn.setPid(corpsDesc.getId());
|
|
|
+ corpsAttn.setCreateTime(new Date());
|
|
|
+ corpsAttn.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAttn.setCreateUser(AuthUtil.getUserId());
|
|
|
+ corpsAttn.setSalesCompanyId(deptId);
|
|
|
+ corpsAttn.setSalesCompanyName(deptName);
|
|
|
+ corpsAttnService.save(corpsAttn);
|
|
|
+
|
|
|
+ //保存客户地址信息
|
|
|
+ PjCorpsAddr corpsAddr = new PjCorpsAddr();
|
|
|
+ corpsAddr.setContacts(corpsDesc.getAttn());
|
|
|
+ corpsAddr.setTel(corpsDesc.getTel());
|
|
|
+ corpsAddr.setBelongtoarea(corpsDesc.getAddr());
|
|
|
+ corpsAddr.setDetailedAddress(corpsDesc.getDetails());
|
|
|
+ corpsAddr.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAddr.setPid(corpsDesc.getId());
|
|
|
+ corpsAddr.setCreateTime(new Date());
|
|
|
+ corpsAddr.setTenantId(AuthUtil.getTenantId());
|
|
|
+ corpsAddr.setCreateUser(AuthUtil.getUserId());
|
|
|
+ corpsAddr.setDefaultAddres("1");
|
|
|
+ corpsAddrService.save(corpsAddr);
|
|
|
+ //保存客户与类别对应关系
|
|
|
+ this.saveOrUpdateTypeDesc(corpsDesc, userId, pId, date, tenantId);
|
|
|
+ } else {
|
|
|
+ corpsDesc.setUpdateTime(new Date());
|
|
|
+ corpsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ baseMapper.updateById(corpsDesc);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return R.data(corpsDesc);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据客户名和类型查询客户
|
|
|
*
|
|
|
* @param cname
|
|
|
@@ -425,6 +605,8 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, PjCorpsDe
|
|
|
return baseMapper.selectOne(new QueryWrapper<>(corpsDesc));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 保存客户联系人信息
|
|
|
*
|