package com.gk.hotwork.Service.ServiceImpl;
|
|
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.gk.hotwork.Domain.*;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Mapper.*;
|
import com.gk.hotwork.Service.SafetySelfInspectionService;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service("SafetySelfInspectionService")
|
@Transactional
|
public class SafetySelfInspectionImpl extends ServiceImpl<SafetySelfInspectionMapper,SafetySelfInspection> implements SafetySelfInspectionService {
|
|
@Autowired
|
private SafetySelfInspectionMapper safetySelfInspectionMapper;
|
@Autowired
|
private SafetySelfInspectionItemMapper safetySelfInspectionItemMapper;
|
@Autowired
|
private SafetySelfInspectionItemDeductionMapper safetySelfInspectionItemDeductionMapper;
|
@Autowired
|
private SafetyInspectionItemDeductionMapper safetyInspectionItemDeductionMapper;
|
/**
|
* @Description: 分页
|
*/
|
@Override
|
public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
|
IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
|
return res;
|
}
|
|
|
/**
|
* @Description: 新增
|
*/
|
@Override
|
public void addOne(SafetySelfInspection param, UserInfo user) {
|
requiredVerification(param);
|
|
Date date = new Date();
|
String username = user.getRealname();
|
param.setValidFlag(Boolean.TRUE);
|
param.setUpdateBy(username);
|
param.setCreateBy(username);
|
param.setUpdateTime(date);
|
param.setCreateTime(date);
|
this.save(param);
|
|
if (CollectionUtils.isNotEmpty(param.getItemList())) {
|
for (SafetySelfInspectionItem safetySelfInspectionItem : param.getItemList()) {
|
safetySelfInspectionItem.setValidFlag(Boolean.TRUE);
|
safetySelfInspectionItem.setUpdateBy(username);
|
safetySelfInspectionItem.setCreateBy(username);
|
safetySelfInspectionItem.setUpdateTime(date);
|
safetySelfInspectionItem.setCreateTime(date);
|
safetySelfInspectionItem.setSafetySelfInspectionId(param.getId());
|
safetySelfInspectionItemMapper.insert(safetySelfInspectionItem);
|
}
|
}
|
}
|
|
/**
|
* @Description: 修改
|
*/
|
@Override
|
public void modOne(SafetySelfInspection param, UserInfo user) {
|
selectVerification(param.getId());
|
requiredVerification(param);
|
//更新主表
|
Date date = new Date();
|
String username = user.getRealname();
|
param.setUpdateTime(date);
|
param.setUpdateBy(username);
|
this.updateById(param);
|
//更新检查项表
|
//1.新增新的元素
|
//2.删除旧的不存在的元素
|
List<SafetySelfInspectionItem> oldFileList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId(param.getId());
|
List<SafetySelfInspectionItem> newFileList = param.getItemList();
|
|
List<Long> oldIdList = new ArrayList<>();
|
List<Long> newIdList = new ArrayList<>();
|
|
for (SafetySelfInspectionItem oldSafetySelfInspectionItem :oldFileList ){
|
oldIdList.add(oldSafetySelfInspectionItem.getId());
|
}
|
for (SafetySelfInspectionItem newSafetySelfInspectionItem :newFileList ){
|
if (newSafetySelfInspectionItem.getId()==null){
|
//1.添加新增的元素
|
newSafetySelfInspectionItem.setValidFlag(Boolean.TRUE);
|
newSafetySelfInspectionItem.setUpdateBy(username);
|
newSafetySelfInspectionItem.setCreateBy(username);
|
newSafetySelfInspectionItem.setUpdateTime(date);
|
newSafetySelfInspectionItem.setCreateTime(date);
|
newSafetySelfInspectionItem.setSafetySelfInspectionId(param.getId());
|
safetySelfInspectionItemMapper.insert(newSafetySelfInspectionItem);
|
}else{
|
newIdList.add(newSafetySelfInspectionItem.getId());
|
}
|
}
|
//2.删除不存在的元素
|
List<Long> diffList = getDif(oldIdList,newIdList);
|
if (CollectionUtils.isNotEmpty(diffList)){
|
for (Long id : diffList){
|
safetySelfInspectionItemMapper.deleteById(id,username,date);
|
}
|
}
|
}
|
|
public List<Long> getDif(List<Long> oldIdList , List<Long> newIdList ){
|
ArrayList<Long> dif = new ArrayList<>();
|
//查找出oldIdList表中不包含newIdList的元素
|
for (Long id : oldIdList) {
|
if (!(newIdList.contains(id))) {
|
dif.add(id);
|
}
|
}
|
return dif;
|
}
|
|
/**
|
* @Description: 删除
|
*/
|
@Override
|
public void delOne(Long id, UserInfo user) {
|
selectVerification(id);
|
|
SafetySelfInspection delOne = new SafetySelfInspection();
|
delOne.setId(id);
|
delOne.setUpdateTime(new Date());
|
delOne.setUpdateBy(user.getRealname());
|
delOne.setValidFlag(Boolean.FALSE);
|
this.updateById(delOne);
|
}
|
|
@Override
|
public SafetySelfInspection infoOne(Long id, UserInfo user) {
|
SafetySelfInspection safetySelfInspection=selectVerification(id);
|
//组装检查项
|
List<SafetySelfInspectionItem> itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id);
|
if(CollectionUtils.isNotEmpty(itemList)){
|
//组装扣分项
|
for (SafetySelfInspectionItem safetySelfInspectionItem : itemList){
|
if (safetySelfInspectionItem.getSafetyInspectionItemResult()==null){
|
//根据检查项id获取原始扣分项
|
List<SafetyInspectionItemDeduction> safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId());
|
if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){
|
List<SafetySelfInspectionItemDeduction> oldSafetySelfInspectionItemDeductionList=new ArrayList<>();
|
for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){
|
SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction();
|
safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId());
|
safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName());
|
safetySelfInspectionItemDeduction.setPoint(0);
|
oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction);
|
}
|
safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList);
|
}else{
|
safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>());
|
}
|
}else if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(1)){
|
//根据自查清单记录的检查项id获取其扣分项
|
List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId());
|
if (CollectionUtils.isNotEmpty(selfDeductionList)){
|
safetySelfInspectionItem.setSelfDeductionList(selfDeductionList);
|
}
|
}
|
}
|
safetySelfInspection.setItemList(itemList);
|
}else{
|
safetySelfInspection.setItemList(new ArrayList<>());
|
}
|
return safetySelfInspection;
|
}
|
|
@Override
|
public SafetySelfInspectionItem itemInfoOne(Long id, UserInfo user){
|
SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id);
|
List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId());
|
if (CollectionUtils.isNotEmpty(selfDeductionList)){
|
safetySelfInspectionItem.setSelfDeductionList(selfDeductionList);
|
}else{
|
//根据自查清单检查项里的检查项表去找原有的扣分项
|
List<SafetyInspectionItemDeduction> safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId());
|
if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){
|
List<SafetySelfInspectionItemDeduction> oldSafetySelfInspectionItemDeductionList=new ArrayList<>();
|
for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){
|
SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction();
|
safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId());
|
safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName());
|
safetySelfInspectionItemDeduction.setPoint(0);
|
oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction);
|
}
|
safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList);
|
}else{
|
safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>());
|
}
|
}
|
return safetySelfInspectionItem;
|
}
|
|
@Override
|
public void modItemInfo(SafetySelfInspectionItem param, UserInfo user) {
|
Date date = new Date();
|
String username = user.getRealname();
|
param.setUpdateTime(date);
|
param.setUpdateBy(username);
|
safetySelfInspectionItemMapper.updateById(param);
|
if (param.getSafetyInspectionItemResult()==0){
|
//否决--删除扣分记录
|
safetySelfInspectionItemDeductionMapper.delBySafetySelfInspectionItemId(param.getId(),username,date);
|
}else{
|
//扣分
|
List<SafetySelfInspectionItemDeduction> list = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(param.getId());
|
if (CollectionUtils.isEmpty(list)){
|
//新增扣分记录
|
for (SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction : param.getSelfDeductionList()){
|
safetySelfInspectionItemDeduction.setValidFlag(Boolean.TRUE);
|
safetySelfInspectionItemDeduction.setUpdateBy(username);
|
safetySelfInspectionItemDeduction.setCreateBy(username);
|
safetySelfInspectionItemDeduction.setUpdateTime(date);
|
safetySelfInspectionItemDeduction.setCreateTime(date);
|
safetySelfInspectionItemDeduction.setSafetySelfInspectionItemId(param.getId());
|
safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetySelfInspectionItemDeduction.getSafetyInspectionItemDeductionId());
|
safetySelfInspectionItemDeductionMapper.insert(safetySelfInspectionItemDeduction);
|
}
|
}else{
|
//更新扣分记录
|
for (SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction : param.getSelfDeductionList()){
|
safetySelfInspectionItemDeduction.setUpdateBy(username);
|
safetySelfInspectionItemDeduction.setUpdateTime(date);
|
safetySelfInspectionItemDeductionMapper.updateById(safetySelfInspectionItemDeduction);
|
}
|
}
|
}
|
}
|
|
@Override
|
public void finish(Long id, UserInfo user) {
|
SafetySelfInspection safetySelfInspection=selectVerification(id);
|
Date date = new Date();
|
String username = user.getRealname();
|
safetySelfInspection.setStatus(2);
|
safetySelfInspection.setUpdateTime(date);
|
safetySelfInspection.setUpdateBy(username);
|
safetySelfInspectionMapper.updateById(safetySelfInspection);
|
}
|
|
|
/**
|
* 查询验证
|
* 验证对象存在
|
*/
|
public SafetySelfInspection selectVerification(Long id) {
|
if (id == null) throw new BusinessException("id传参不能为空");
|
SafetySelfInspection SafetySelfInspection = this.getById(id);
|
if (SafetySelfInspection == null) throw new BusinessException("找不到对应实体");
|
return SafetySelfInspection;
|
}
|
|
/**
|
* 操作验证
|
* 验证必填项
|
*/
|
public void requiredVerification(SafetySelfInspection param) {
|
if (StringUtils.isBlank(param.getInspectionName())) throw new BusinessException("请填写自查清单名称");
|
if (param.getInspectionTime() == null) throw new BusinessException("请选择自查时间");
|
if (param.getInspector() == null) throw new BusinessException("请选择自查人员");
|
if (CollectionUtils.isEmpty(param.getItemList())) {
|
throw new BusinessException("请选择检查项");
|
}
|
}
|
}
|