|
@@ -1,13 +1,22 @@
|
|
|
package com.sooka.sponest.data.housingconstruction.service.impl;
|
|
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
+import com.ruoyi.common.core.utils.uuid.IdUtils;
|
|
|
+import com.ruoyi.common.security.utils.SecurityUtils;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.CenterdataTHousingconstructionAttach;
|
|
|
import com.sooka.sponest.data.housingconstruction.domain.CenterdataTHousingconstructionSafetyinspectionrecords;
|
|
|
+import com.sooka.sponest.data.housingconstruction.domain.CenterdataTHousingconstructionSafetyinspectionrecordsdetail;
|
|
|
+import com.sooka.sponest.data.housingconstruction.mapper.CenterdataTHousingconstructionAttachMapper;
|
|
|
import com.sooka.sponest.data.housingconstruction.mapper.CenterdataTHousingconstructionSafetyinspectionrecordsMapper;
|
|
|
+import com.sooka.sponest.data.housingconstruction.mapper.CenterdataTHousingconstructionSafetyinspectionrecordsdetailMapper;
|
|
|
import com.sooka.sponest.data.housingconstruction.service.ICenterdataTHousingconstructionSafetyinspectionrecordsService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.sql.Array;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 住建-安全检查记录Service业务层处理
|
|
@@ -18,30 +27,41 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class CenterdataTHousingconstructionSafetyinspectionrecordsServiceImpl implements ICenterdataTHousingconstructionSafetyinspectionrecordsService {
|
|
|
@Autowired
|
|
|
- private CenterdataTHousingconstructionSafetyinspectionrecordsMapper centerdataTHousingconstructionSafetyinspectionrecordsMapper;
|
|
|
+ private CenterdataTHousingconstructionSafetyinspectionrecordsMapper recordsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CenterdataTHousingconstructionSafetyinspectionrecordsdetailMapper detailMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CenterdataTHousingconstructionAttachMapper attachMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
- * 查询住建-安全检查记录
|
|
|
+ * 查询住建-安全检查记录列表
|
|
|
*
|
|
|
- * @param id 住建-安全检查记录主键
|
|
|
+ * @param centerdataTHousingconstructionSafetyinspectionrecords 住建-安全检查记录
|
|
|
* @return 住建-安全检查记录
|
|
|
*/
|
|
|
@Override
|
|
|
- public CenterdataTHousingconstructionSafetyinspectionrecords selectCenterdataTHousingconstructionSafetyinspectionrecordsById(Long id) {
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.selectCenterdataTHousingconstructionSafetyinspectionrecordsById(id);
|
|
|
+ public List<CenterdataTHousingconstructionSafetyinspectionrecords> selectCenterdataTHousingconstructionSafetyinspectionrecordsList(CenterdataTHousingconstructionSafetyinspectionrecords centerdataTHousingconstructionSafetyinspectionrecords) {
|
|
|
+ return recordsMapper.selectCenterdataTHousingconstructionSafetyinspectionrecordsList(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 查询住建-安全检查记录列表
|
|
|
+ * 查询住建-安全检查记录
|
|
|
*
|
|
|
- * @param centerdataTHousingconstructionSafetyinspectionrecords 住建-安全检查记录
|
|
|
+ * @param id 住建-安全检查记录主键
|
|
|
* @return 住建-安全检查记录
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<CenterdataTHousingconstructionSafetyinspectionrecords> selectCenterdataTHousingconstructionSafetyinspectionrecordsList(CenterdataTHousingconstructionSafetyinspectionrecords centerdataTHousingconstructionSafetyinspectionrecords) {
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.selectCenterdataTHousingconstructionSafetyinspectionrecordsList(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
+ public CenterdataTHousingconstructionSafetyinspectionrecords selectCenterdataTHousingconstructionSafetyinspectionrecordsById(String id) {
|
|
|
+ return recordsMapper.queryRedordDetails(id);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 新增住建-安全检查记录
|
|
|
*
|
|
@@ -50,41 +70,166 @@ public class CenterdataTHousingconstructionSafetyinspectionrecordsServiceImpl im
|
|
|
*/
|
|
|
@Override
|
|
|
public int insertCenterdataTHousingconstructionSafetyinspectionrecords(CenterdataTHousingconstructionSafetyinspectionrecords centerdataTHousingconstructionSafetyinspectionrecords) {
|
|
|
- centerdataTHousingconstructionSafetyinspectionrecords.setCreateTime(DateUtils.getNowDate());
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.insertCenterdataTHousingconstructionSafetyinspectionrecords(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
+ //生成记录id
|
|
|
+ String recordId = IdUtils.fastSimpleUUID();
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setId(recordId);
|
|
|
+ //设置创建数据信息
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setCreateTime(nowDate);
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setCreateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setUpdateTime(nowDate);
|
|
|
+ //写入安全检查记录明细
|
|
|
+ addDetailList(centerdataTHousingconstructionSafetyinspectionrecords.getDetailList(), recordId);
|
|
|
+ //写入安全检查记录
|
|
|
+ return recordsMapper.insertCenterdataTHousingconstructionSafetyinspectionrecords(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入安全检查明细表
|
|
|
+ * @param detailList 检查记录明细集合
|
|
|
+ * @param recordId 检查记录id
|
|
|
+ */
|
|
|
+ private void addDetailList(List<CenterdataTHousingconstructionSafetyinspectionrecordsdetail> detailList, String recordId){
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ detailList.forEach(detail->{
|
|
|
+ //生成记录明细id
|
|
|
+ String uuid = IdUtils.fastSimpleUUID();
|
|
|
+ //设置记录明细id
|
|
|
+ detail.setId(uuid);
|
|
|
+ //设置记录id
|
|
|
+ detail.setRecordId(recordId);
|
|
|
+ //设置创建信息
|
|
|
+ detail.setCreateTime(nowDate);
|
|
|
+ detail.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ detail.setCreateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ detail.setUpdateTime(nowDate);
|
|
|
+ //将记录明细表中的附件写入到附件表中
|
|
|
+ addAttachToList(detail.getAttachList(), uuid);
|
|
|
+ });
|
|
|
+ //写入安全检查记录明细
|
|
|
+ detailMapper.insertList(detailList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入附件表
|
|
|
+ * @param attachList 附件集合
|
|
|
+ * @param detailId 业务数据id
|
|
|
+ */
|
|
|
+ private void addAttachToList(List<CenterdataTHousingconstructionAttach> attachList, String detailId){
|
|
|
+ if(attachList != null && !attachList.isEmpty()){
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ attachList.forEach(attach->{
|
|
|
+ //设置业务数据id
|
|
|
+ attach.setBusId(detailId);
|
|
|
+ //设置创建信息
|
|
|
+ attach.setCreateTime(nowDate);
|
|
|
+ });
|
|
|
+ attachMapper.insertAttachByList(attachList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 修改住建-安全检查记录
|
|
|
- *
|
|
|
* @param centerdataTHousingconstructionSafetyinspectionrecords 住建-安全检查记录
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateCenterdataTHousingconstructionSafetyinspectionrecords(CenterdataTHousingconstructionSafetyinspectionrecords centerdataTHousingconstructionSafetyinspectionrecords) {
|
|
|
+ //设置修改数据信息
|
|
|
centerdataTHousingconstructionSafetyinspectionrecords.setUpdateTime(DateUtils.getNowDate());
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.updateCenterdataTHousingconstructionSafetyinspectionrecords(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setUpdateBy(SecurityUtils.getUserId().toString());
|
|
|
+ centerdataTHousingconstructionSafetyinspectionrecords.setUpdateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ //获取旧数据
|
|
|
+ CenterdataTHousingconstructionSafetyinspectionrecords oldRecords = recordsMapper.queryRedordDetails(centerdataTHousingconstructionSafetyinspectionrecords.getId());
|
|
|
+
|
|
|
+ //比较新旧数据, 属性值不相同则修改。
|
|
|
+ editDetailList(centerdataTHousingconstructionSafetyinspectionrecords.getDetailList(),oldRecords.getDetailList());
|
|
|
+
|
|
|
+ //基本信息禁止修改,只写入修改时间,修改人,修改人id
|
|
|
+ return recordsMapper.updateCenterdataTHousingconstructionSafetyinspectionrecords(centerdataTHousingconstructionSafetyinspectionrecords);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 比较新旧记录
|
|
|
+ * 如果新纪录和旧纪录相同,则不执行修改
|
|
|
+ */
|
|
|
+ private void editDetailList(List<CenterdataTHousingconstructionSafetyinspectionrecordsdetail> detailList, List<CenterdataTHousingconstructionSafetyinspectionrecordsdetail> oldDetailList){
|
|
|
+ // 将 oldDetailList 转换为 Map,方便快速查找
|
|
|
+ Map<String, CenterdataTHousingconstructionSafetyinspectionrecordsdetail> oldDetailMap = oldDetailList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ detail -> detail.getId() + "-" + detail.getItemId(),
|
|
|
+ Function.identity()
|
|
|
+ ));
|
|
|
+
|
|
|
+ for (CenterdataTHousingconstructionSafetyinspectionrecordsdetail newDetail : detailList) {
|
|
|
+ String key = newDetail.getId() + "-" + newDetail.getItemId();
|
|
|
+ CenterdataTHousingconstructionSafetyinspectionrecordsdetail oldDetail = oldDetailMap.get(key);
|
|
|
+ if (oldDetail != null) {
|
|
|
+ if (!Objects.equals(newDetail.getStandardStatus(), oldDetail.getStandardStatus()) ||
|
|
|
+ !Objects.equals(newDetail.getRemark(), oldDetail.getRemark())) {
|
|
|
+ updateDetail(newDetail);
|
|
|
+ }
|
|
|
+ editAttachList(newDetail.getAttachList(), oldDetail.getAttachList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新安全检查记录数据
|
|
|
+ * @param detail
|
|
|
+ */
|
|
|
+ private void updateDetail(CenterdataTHousingconstructionSafetyinspectionrecordsdetail detail) {
|
|
|
+ detail.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ detail.setUpdateBy(SecurityUtils.getUserId().toString());
|
|
|
+ detail.setUpdateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ detailMapper.updateCenterdataTHousingconstructionSafetyinspectionrecordsdetail(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 替换附件信息
|
|
|
+ */
|
|
|
+ private void editAttachList(List<CenterdataTHousingconstructionAttach> attachList, List<CenterdataTHousingconstructionAttach> oldAttachList){
|
|
|
+ //旧数据中附件集合不是null, 并且不是空集合, 则执行删除就附件
|
|
|
+ if(oldAttachList != null && !oldAttachList.isEmpty()){
|
|
|
+ // 从 oldAttachList 中提取 ID,并删除旧附件
|
|
|
+ List<Long> idList = oldAttachList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(CenterdataTHousingconstructionAttach::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ attachMapper.deleteCenterdataTHousingconstructionAttachByIds(idList.toArray(new Long[0]));
|
|
|
+ }
|
|
|
+
|
|
|
+ //新数据中的附件集合不是null, 并且不是空集合, 则执行写入附件
|
|
|
+ if(attachList != null && !attachList.isEmpty()){
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ attachList.forEach(attach->{
|
|
|
+ attach.setCreateTime(nowDate);
|
|
|
+ });
|
|
|
+ //写入新附件
|
|
|
+ attachMapper.insertAttachByList(attachList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除住建-安全检查记录
|
|
|
- *
|
|
|
* @param ids 需要删除的住建-安全检查记录主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int deleteCenterdataTHousingconstructionSafetyinspectionrecordsByIds(Long[] ids) {
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.deleteCenterdataTHousingconstructionSafetyinspectionrecordsByIds(ids);
|
|
|
+ return recordsMapper.deleteCenterdataTHousingconstructionSafetyinspectionrecordsByIds(ids);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除住建-安全检查记录信息
|
|
|
- *
|
|
|
* @param id 住建-安全检查记录主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int deleteCenterdataTHousingconstructionSafetyinspectionrecordsById(Long id) {
|
|
|
- return centerdataTHousingconstructionSafetyinspectionrecordsMapper.deleteCenterdataTHousingconstructionSafetyinspectionrecordsById(id);
|
|
|
+ return recordsMapper.deleteCenterdataTHousingconstructionSafetyinspectionrecordsById(id);
|
|
|
}
|
|
|
}
|