|
@@ -19,6 +19,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.web.core.BaseController;
|
|
import org.dromara.common.web.core.BaseController;
|
|
|
import org.dromara.risk.domain.bo.RiskPersonnelBo;
|
|
import org.dromara.risk.domain.bo.RiskPersonnelBo;
|
|
|
import org.dromara.risk.domain.bo.RiskPersonnelCertBo;
|
|
import org.dromara.risk.domain.bo.RiskPersonnelCertBo;
|
|
|
|
|
+import org.dromara.risk.domain.vo.RiskPersonnelCertVo;
|
|
|
import org.dromara.risk.domain.vo.RiskPersonnelVo;
|
|
import org.dromara.risk.domain.vo.RiskPersonnelVo;
|
|
|
import org.dromara.risk.service.IRiskPersonnelService;
|
|
import org.dromara.risk.service.IRiskPersonnelService;
|
|
|
import org.dromara.risk.service.IRiskPersonnelCertService;
|
|
import org.dromara.risk.service.IRiskPersonnelCertService;
|
|
@@ -104,6 +105,11 @@ public class RiskPersonnelController extends BaseController {
|
|
|
/**
|
|
/**
|
|
|
* 保存人员信息(含证书列表),适用于新增和修改
|
|
* 保存人员信息(含证书列表),适用于新增和修改
|
|
|
* 请求体格式: { personnel: {...}, certList: [...] }
|
|
* 请求体格式: { personnel: {...}, certList: [...] }
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 修改分支:人员 update;该人员下所有 cert <b>物理删</b>(绕开 @TableLogic 软删) + 重新 insert。
|
|
|
|
|
+ * 这样既能保证 cert id 走 AUTO_INCREMENT(不冲突),又避免软删垃圾累积。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 前端 certBo <b>不传 id</b>(让后端 insert 走 AUTO_INCREMENT 分配新 id)。
|
|
|
*/
|
|
*/
|
|
|
@SaCheckPermission("risk:personnel:add")
|
|
@SaCheckPermission("risk:personnel:add")
|
|
|
@Log(title = "人员信息", businessType = BusinessType.INSERT)
|
|
@Log(title = "人员信息", businessType = BusinessType.INSERT)
|
|
@@ -117,20 +123,12 @@ public class RiskPersonnelController extends BaseController {
|
|
|
java.util.Map<String, Object> map = (java.util.Map<String, Object>) payload.get("personnel");
|
|
java.util.Map<String, Object> map = (java.util.Map<String, Object>) payload.get("personnel");
|
|
|
BeanUtil.fillBeanWithMap(map, personnel, true);
|
|
BeanUtil.fillBeanWithMap(map, personnel, true);
|
|
|
}
|
|
}
|
|
|
- // 新增
|
|
|
|
|
- if (personnel.getId() == null) {
|
|
|
|
|
- personnelService.insertByBo(personnel);
|
|
|
|
|
- } else {
|
|
|
|
|
- // 修改
|
|
|
|
|
- personnelService.updateByBo(personnel);
|
|
|
|
|
- // 先删除该人员下的所有证书
|
|
|
|
|
- certService.deleteByPersonnelId(personnel.getId());
|
|
|
|
|
- }
|
|
|
|
|
- // 批量插入证书
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 解析 certList(公共逻辑,新增/修改都用)
|
|
|
|
|
+ java.util.List<RiskPersonnelCertBo> certBos = new java.util.ArrayList<>();
|
|
|
Object certObj = payload.get("certList");
|
|
Object certObj = payload.get("certList");
|
|
|
if (certObj instanceof java.util.List) {
|
|
if (certObj instanceof java.util.List) {
|
|
|
java.util.List<?> rawList = (java.util.List<?>) certObj;
|
|
java.util.List<?> rawList = (java.util.List<?>) certObj;
|
|
|
- java.util.List<RiskPersonnelCertBo> certBos = new java.util.ArrayList<>();
|
|
|
|
|
for (Object o : rawList) {
|
|
for (Object o : rawList) {
|
|
|
if (o instanceof java.util.Map) {
|
|
if (o instanceof java.util.Map) {
|
|
|
RiskPersonnelCertBo bo = org.springframework.beans.BeanUtils
|
|
RiskPersonnelCertBo bo = org.springframework.beans.BeanUtils
|
|
@@ -138,20 +136,42 @@ public class RiskPersonnelController extends BaseController {
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
java.util.Map<String, Object> m = (java.util.Map<String, Object>) o;
|
|
java.util.Map<String, Object> m = (java.util.Map<String, Object>) o;
|
|
|
BeanUtil.fillBeanWithMap(m, bo, true);
|
|
BeanUtil.fillBeanWithMap(m, bo, true);
|
|
|
|
|
+ // 清空 id,强制走 AUTO_INCREMENT(避免与软删残留主键冲突)
|
|
|
|
|
+ bo.setId(null);
|
|
|
// certName 必填,缺失时回退到 certType,再缺失则用默认名
|
|
// certName 必填,缺失时回退到 certType,再缺失则用默认名
|
|
|
if (cn.hutool.core.util.StrUtil.isBlank(bo.getCertName())) {
|
|
if (cn.hutool.core.util.StrUtil.isBlank(bo.getCertName())) {
|
|
|
- if (cn.hutool.core.util.StrUtil.isNotBlank(bo.getCertType())) {
|
|
|
|
|
- bo.setCertName(bo.getCertType());
|
|
|
|
|
- } else {
|
|
|
|
|
- bo.setCertName("岗位证书");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ bo.setCertName(cn.hutool.core.util.StrUtil.isNotBlank(bo.getCertType())
|
|
|
|
|
+ ? bo.getCertType() : "岗位证书");
|
|
|
}
|
|
}
|
|
|
certBos.add(bo);
|
|
certBos.add(bo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (!certBos.isEmpty()) {
|
|
|
|
|
- certService.insertBatchByBo(personnel.getId(), certBos);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 区分新增/修改(用前端传入的 id 是否为空判断)
|
|
|
|
|
+ boolean isUpdate = personnel.getId() != null;
|
|
|
|
|
+
|
|
|
|
|
+ if (isUpdate) {
|
|
|
|
|
+ // 修改:人员 update
|
|
|
|
|
+ personnelService.updateByBo(personnel);
|
|
|
|
|
+ // 物理删该人员下所有 cert(绕开 @TableLogic 软删,避免主键残留)
|
|
|
|
|
+ java.util.List<RiskPersonnelCertVo> existing =
|
|
|
|
|
+ certService.queryListByPersonnelId(personnel.getId());
|
|
|
|
|
+ java.util.List<Long> existingIds = new java.util.ArrayList<>();
|
|
|
|
|
+ for (RiskPersonnelCertVo e : existing) {
|
|
|
|
|
+ if (e.getId() != null) existingIds.add(e.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!existingIds.isEmpty()) {
|
|
|
|
|
+ certService.deleteByIdsPhysically(existingIds);
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 新增
|
|
|
|
|
+ personnelService.insertByBo(personnel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 插入 cert(走 AUTO_INCREMENT,无论新增/修改都这么干)
|
|
|
|
|
+ if (!certBos.isEmpty()) {
|
|
|
|
|
+ certService.insertBatchByBo(personnel.getId(), certBos);
|
|
|
}
|
|
}
|
|
|
return R.ok(personnel.getId());
|
|
return R.ok(personnel.getId());
|
|
|
}
|
|
}
|