|
|
@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
@@ -29,11 +30,11 @@ import org.springblade.los.basic.corps.entity.*;
|
|
|
import org.springblade.los.basic.corps.mapper.CorpsMapper;
|
|
|
import org.springblade.los.basic.corps.service.*;
|
|
|
import org.springblade.los.basic.corps.vo.BCorpsVO;
|
|
|
-import org.springblade.system.entity.Dept;
|
|
|
import org.springblade.system.feign.ISysClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -84,6 +85,8 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R submit(BCorps bCorps) {
|
|
|
String deptId = "";
|
|
|
String deptName = "";
|
|
|
@@ -95,6 +98,14 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
deptName = String.join(",", res.getData());
|
|
|
}
|
|
|
}
|
|
|
+ long cname = baseMapper.selectCount(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getCnName, bCorps.getCnName())
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
+ long uscc = baseMapper.selectCount(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getUscc, bCorps.getUscc())
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
//首字母为空
|
|
|
if (null == bCorps.getInitials() || "".equals(bCorps.getInitials())) {
|
|
|
//获得名称首字母
|
|
|
@@ -102,14 +113,29 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
bCorps.setInitials(initials.substring(0, 1));
|
|
|
}
|
|
|
if (bCorps.getId() == null) {
|
|
|
+ if (cname > 0) {
|
|
|
+ throw new RuntimeException("中文名称不允许重复");
|
|
|
+ }
|
|
|
+ if (uscc > 0) {
|
|
|
+ throw new RuntimeException("统一社会信用代码不允许重复");
|
|
|
+ }
|
|
|
bCorps.setCreateTime(new Date());
|
|
|
bCorps.setCreateUser(AuthUtil.getUserId());
|
|
|
bCorps.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ bCorps.setDeptName(AuthUtil.getUserName());
|
|
|
+ bCorps.setDeptId(AuthUtil.getDeptId());
|
|
|
+ bCorps.setBranchId(deptId);
|
|
|
bCorps.setCreateDept(deptId);
|
|
|
bCorps.setCreateDeptName(deptName);
|
|
|
}
|
|
|
} else {
|
|
|
+ if (cname > 1) {
|
|
|
+ throw new RuntimeException("中文名称不允许重复");
|
|
|
+ }
|
|
|
+ if (uscc > 1) {
|
|
|
+ throw new RuntimeException("统一社会信用代码不允许重复");
|
|
|
+ }
|
|
|
bCorps.setUpdateUser(AuthUtil.getUserId());
|
|
|
bCorps.setUpdateUserName(AuthUtil.getUserName());
|
|
|
}
|
|
|
@@ -134,12 +160,13 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
bCorpsTypes.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
bCorpsTypes.setCreateDept(deptId);
|
|
|
+ bCorpsTypes.setBranchId(deptId);
|
|
|
bCorpsTypes.setCreateDeptName(deptName);
|
|
|
}
|
|
|
bCorpsTypesList.add(bCorpsTypes);
|
|
|
}
|
|
|
if (bCorpsTypesList.size() > 0) {
|
|
|
- bCorpsTypesService.delete(bCorps.getCorpId(), AuthUtil.getTenantId());
|
|
|
+ bCorpsTypesService.delete(bCorps.getId(), AuthUtil.getTenantId());
|
|
|
bCorpsTypesService.saveBatch(bCorpsTypesList);
|
|
|
}
|
|
|
}
|
|
|
@@ -153,6 +180,7 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
item.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
item.setCreateDept(deptId);
|
|
|
+ item.setBranchId(deptId);
|
|
|
item.setCreateDeptName(deptName);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -172,6 +200,7 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
item.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
item.setCreateDept(deptId);
|
|
|
+ item.setBranchId(deptId);
|
|
|
item.setCreateDeptName(deptName);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -190,6 +219,7 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
item.setCreateUser(AuthUtil.getUserId());
|
|
|
item.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ item.setBranchId(deptId);
|
|
|
item.setCreateDept(deptId);
|
|
|
item.setCreateDeptName(deptName);
|
|
|
}
|
|
|
@@ -209,6 +239,7 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
item.setCreateUser(AuthUtil.getUserId());
|
|
|
item.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ item.setBranchId(deptId);
|
|
|
item.setCreateDept(deptId);
|
|
|
item.setCreateDeptName(deptName);
|
|
|
}
|
|
|
@@ -247,6 +278,7 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
item.setCreateUser(AuthUtil.getUserId());
|
|
|
item.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ item.setBranchId(deptId);
|
|
|
item.setCreateDept(deptId);
|
|
|
item.setCreateDeptName(deptName);
|
|
|
}
|
|
|
@@ -300,6 +332,8 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public R<List<BCorps>> importBCorps(List<BCorpsExcel> excelList) {
|
|
|
String deptId = "";
|
|
|
String deptName = "";
|
|
|
@@ -314,43 +348,104 @@ public class BCorpsServiceImpl extends ServiceImpl<CorpsMapper, BCorps> implemen
|
|
|
List<BCorps> bCorpsList = new ArrayList<>();
|
|
|
for (BCorpsExcel item : excelList) {
|
|
|
BCorps bCorps = new BCorps();
|
|
|
- BeanUtil.copy(item, bCorps);
|
|
|
- if (ObjectUtils.isNotNull(bCorps.getAdminProfiles())) {
|
|
|
- bCorps.setAdminProfiles(userClient.selectUserByNames(bCorps.getAdminProfiles()));
|
|
|
+ if (ObjectUtils.isNull(item.getCode())) {
|
|
|
+ throw new RuntimeException("单位编码" + item.getCode() + "不能为空");
|
|
|
}
|
|
|
- if (ObjectUtils.isNotNull(bCorps.getSalesName())) {
|
|
|
- List<User> userList = userClient.userInfoByName(bCorps.getSalesName(), AuthUtil.getTenantId());
|
|
|
- if (ObjectUtils.isNotNull(userList) && userList.size() > 0) {
|
|
|
- bCorps.setSalesId(userList.get(0).getId());
|
|
|
- }
|
|
|
+ if (ObjectUtils.isNull(item.getCnName())) {
|
|
|
+ throw new RuntimeException("中文名称" + item.getCnName() + "不能为空");
|
|
|
}
|
|
|
- if (ObjectUtils.isNotNull(bCorps.getDeptName())) {
|
|
|
- R<Dept> resDept = sysClient.getDeptIByName(bCorps.getDeptName(), AuthUtil.getTenantId());
|
|
|
- if (resDept.isSuccess() && ObjectUtils.isNotNull(resDept.getData())) {
|
|
|
- bCorps.setDeptId(resDept.getData().getId());
|
|
|
- }
|
|
|
+ if (ObjectUtils.isNull(item.getUscc())) {
|
|
|
+ throw new RuntimeException("统一社会信用代码" + item.getUscc() + "不能为空");
|
|
|
}
|
|
|
- //首字母为空
|
|
|
- if (null == bCorps.getInitials() || "".equals(bCorps.getInitials())) {
|
|
|
- //获得名称首字母
|
|
|
- String initials = getSpells(bCorps.getCnName());
|
|
|
- bCorps.setInitials(initials.substring(0, 1));
|
|
|
- }
|
|
|
- if (bCorps.getId() == null) {
|
|
|
+ BCorps corps = baseMapper.selectOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getCnName, item.getCnName())
|
|
|
+ .eq(BCorps::getUscc, item.getUscc())
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
+ long cname = baseMapper.selectCount(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getCnName, item.getCnName())
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
+ long uscc = baseMapper.selectCount(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getUscc, item.getUscc())
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
+ if (corps == null) {
|
|
|
+ BeanUtil.copy(item, bCorps);
|
|
|
+ if (cname > 0) {
|
|
|
+ throw new RuntimeException("中文名称" + bCorps.getCnName() + "不允许重复");
|
|
|
+ }
|
|
|
+ if (uscc > 0) {
|
|
|
+ throw new RuntimeException("统一社会信用代码" + bCorps.getUscc() + "不允许重复");
|
|
|
+ }
|
|
|
bCorps.setCreateTime(new Date());
|
|
|
bCorps.setCreateUser(AuthUtil.getUserId());
|
|
|
bCorps.setCreateUserName(AuthUtil.getUserName());
|
|
|
if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ bCorps.setDeptName(AuthUtil.getUserName());
|
|
|
+ bCorps.setDeptId(AuthUtil.getDeptId());
|
|
|
bCorps.setCreateDept(deptId);
|
|
|
+ bCorps.setBranchId(deptId);
|
|
|
bCorps.setCreateDeptName(deptName);
|
|
|
}
|
|
|
} else {
|
|
|
+ if (cname > 1) {
|
|
|
+ throw new RuntimeException("中文名称" + bCorps.getCnName() + "不允许重复");
|
|
|
+ }
|
|
|
+ if (uscc > 1) {
|
|
|
+ throw new RuntimeException("统一社会信用代码" + bCorps.getUscc() + "不允许重复");
|
|
|
+ }
|
|
|
bCorps.setUpdateUser(AuthUtil.getUserId());
|
|
|
bCorps.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ BeanUtil.copy(corps, bCorps);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getAdminProfiles())) {
|
|
|
+ bCorps.setAdminProfiles(userClient.selectUserByNames(item.getAdminProfiles()));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getSalesName())) {
|
|
|
+ List<User> userList = userClient.userInfoByName(item.getSalesName(), AuthUtil.getTenantId());
|
|
|
+ if (ObjectUtils.isNotNull(userList) && userList.size() > 0) {
|
|
|
+ bCorps.setSalesId(userList.get(0).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //首字母为空
|
|
|
+ if (null == bCorps.getInitials() || "".equals(bCorps.getInitials())) {
|
|
|
+ //获得名称首字母
|
|
|
+ String initials = getSpells(bCorps.getCnName());
|
|
|
+ bCorps.setInitials(initials.substring(0, 1));
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(bCorps);
|
|
|
+ //客户类别对应
|
|
|
+ if (ObjectUtils.isNotNull(item.getCorpTypeName())) {
|
|
|
+ List<BCorpsTypeDefine> bCorpsTypeDefineList = bCorpsTypeDefineService.list(new LambdaQueryWrapper<BCorpsTypeDefine>()
|
|
|
+ .eq(BCorpsTypeDefine::getIsDeleted, 0)
|
|
|
+ .eq(BCorpsTypeDefine::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply(ObjectUtils.isNotNull(item.getCorpTypeName()), "find_in_set(cn_name,'" + item.getCorpTypeName() + "')"));
|
|
|
+ if (bCorpsTypeDefineList.size() > 0) {
|
|
|
+ bCorps.setCorpTypeName(bCorpsTypeDefineList.stream().map(BCorpsTypeDefine::getCnName).collect(Collectors.joining()));
|
|
|
+ List<Long> ids = bCorpsTypeDefineList.stream().map(BCorpsTypeDefine::getId).collect(Collectors.toList());
|
|
|
+ List<BCorpsTypes> bCorpsTypesList = new ArrayList<>();
|
|
|
+ for (Long id : ids) {
|
|
|
+ BCorpsTypes bCorpsTypes = new BCorpsTypes();
|
|
|
+ bCorpsTypes.setCorpId(bCorps.getId());
|
|
|
+ bCorpsTypes.setCorpTypeId(id);
|
|
|
+ bCorpsTypes.setCreateTime(new Date());
|
|
|
+ bCorpsTypes.setCreateUser(AuthUtil.getUserId());
|
|
|
+ bCorpsTypes.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ bCorpsTypes.setCreateDept(deptId);
|
|
|
+ bCorpsTypes.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ bCorpsTypesList.add(bCorpsTypes);
|
|
|
+ }
|
|
|
+ if (bCorpsTypesList.size() > 0) {
|
|
|
+ bCorpsTypesService.delete(bCorps.getId(), AuthUtil.getTenantId());
|
|
|
+ bCorpsTypesService.saveBatch(bCorpsTypesList);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
bCorpsList.add(bCorps);
|
|
|
}
|
|
|
- this.saveOrUpdateBatch(bCorpsList);
|
|
|
return R.data(bCorpsList);
|
|
|
}
|
|
|
|