|
@@ -4,14 +4,21 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.sop.business.bean.result.SysCustomResult;
|
|
|
import com.qmth.sop.business.entity.SysCustom;
|
|
|
+import com.qmth.sop.business.entity.SysCustomAddr;
|
|
|
import com.qmth.sop.business.entity.SysUser;
|
|
|
import com.qmth.sop.business.mapper.SysCustomMapper;
|
|
|
+import com.qmth.sop.business.service.SysCustomAddrService;
|
|
|
import com.qmth.sop.business.service.SysCustomService;
|
|
|
import com.qmth.sop.business.service.SysLevelRoleService;
|
|
|
+import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.sop.common.enums.FieldUniqueEnum;
|
|
|
import com.qmth.sop.common.enums.ProductTypeEnum;
|
|
|
+import com.qmth.sop.common.util.ResultUtil;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -33,6 +40,9 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
|
|
|
@Resource
|
|
|
SysLevelRoleService sysLevelRoleService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ SysCustomAddrService sysCustomAddrService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询列表
|
|
|
*
|
|
@@ -43,28 +53,47 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
|
|
|
public IPage<SysCustomResult> query(Page<Map> iPage, ProductTypeEnum type, Long managerId, String name, Long levelId) {
|
|
|
IPage<SysCustomResult> sysCustomResultIPage = this.baseMapper.query(iPage, Objects.nonNull(type) ? type.name() : null, Objects.nonNull(managerId) ? managerId : null, name, Objects.nonNull(levelId) ? levelId : null);
|
|
|
sysCustomResultIPage.getRecords().forEach(e -> {
|
|
|
- e.setRoleList(sysLevelRoleService.getList(e.getId()));
|
|
|
+ e.setRoleList(sysLevelRoleService.getList(e.getLevelId()));
|
|
|
+ e.setAddrList(sysCustomAddrService.list(new QueryWrapper<SysCustomAddr>().lambda().eq(SysCustomAddr::getCustomId,e.getId())));
|
|
|
});
|
|
|
return sysCustomResultIPage;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public void add(SysCustom sysCustom) {
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- sysCustom.setCreateId(sysUser.getId());
|
|
|
- sysCustom.setCreateTime(System.currentTimeMillis());
|
|
|
- this.saveOrUpdate(sysCustom);
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增修改客户表
|
|
|
+ *
|
|
|
+ * @param sysCustom
|
|
|
+ */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void update(SysCustom sysCustom) {
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- sysCustom.setUpdateId(sysUser.getId());
|
|
|
- sysCustom.setUpdateTime(System.currentTimeMillis());
|
|
|
- this.saveOrUpdate(sysCustom);
|
|
|
+ public boolean saveCustom(SysCustomResult sysCustom) {
|
|
|
+ try {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ if (Objects.isNull(sysCustom.getId())) {// 新增
|
|
|
+ sysCustom.insertInfo(sysUser.getId());
|
|
|
+ } else { // 修改
|
|
|
+ sysCustom.updateInfo(sysUser.getId());
|
|
|
+ sysCustomAddrService.remove(new QueryWrapper<SysCustomAddr>().lambda().eq(SysCustomAddr::getCustomId,sysCustom.getId()));
|
|
|
+ }
|
|
|
+ sysCustom.getAddrList().forEach(e->{
|
|
|
+ e.setCustomId(sysCustom.getId());
|
|
|
+ sysCustomAddrService.saveOrUpdate(e);
|
|
|
+ });
|
|
|
+ return saveOrUpdate(sysCustom);
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+ throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
+ } else if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -75,4 +104,5 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|