From 0a9ed7b7488de66a50799f79369d7806910ae00a Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期三, 23 八月 2023 15:56:59 +0800
Subject: [PATCH] 隐患二期

---
 src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyFacilityInspectionImpl.java |  147 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 122 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyFacilityInspectionImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyFacilityInspectionImpl.java
index 4ad71bd..0887581 100644
--- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyFacilityInspectionImpl.java
+++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyFacilityInspectionImpl.java
@@ -1,62 +1,159 @@
 package com.gk.hotwork.Service.ServiceImpl;
 
-
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
+
+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 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.gk.hotwork.Domain.CompanyInfo;
 import com.gk.hotwork.Domain.SafetyFacilityInspection;
+import com.gk.hotwork.Domain.SafetyFacilityProcessflow;
+import com.gk.hotwork.Domain.SafetyInspectionItemDeduction;
 import com.gk.hotwork.Domain.UserInfo;
+import com.gk.hotwork.Mapper.CompanyInfoMapper;
 import com.gk.hotwork.Mapper.SafetyFacilityInspectionMapper;
+import com.gk.hotwork.Mapper.SafetyFacilityProcessflowMapper;
+import com.gk.hotwork.Mapper.UserInfoMapper;
 import com.gk.hotwork.Service.SafetyFacilityInspectionService;
 
 @Service("SafetyFacilityInspectionService")
 @Transactional
-public class SafetyFacilityInspectionImpl extends ServiceImpl<SafetyFacilityInspectionMapper,SafetyFacilityInspection> implements SafetyFacilityInspectionService {
+public class SafetyFacilityInspectionImpl extends ServiceImpl<SafetyFacilityInspectionMapper, SafetyFacilityInspection>
+		implements SafetyFacilityInspectionService {
 
-	
-    @Autowired
-    private SafetyFacilityInspectionMapper safetyFacilityInspectionMapper;
+	@Autowired
+	private SafetyFacilityInspectionMapper safetyFacilityInspectionMapper;
+
+	@Autowired
+	private SafetyFacilityProcessflowMapper safetyFacilityProcessflowMapper;
+
+	@Autowired
+	private UserInfoMapper userInfoMapper;
+
+	@Autowired
+	private CompanyInfoMapper companyInfoMapper;
 
 	@Override
-	public IPage<SafetyFacilityInspection> selectPage(Page<SafetyFacilityInspection> page, Map<String, Object> filter, UserInfo user) {
-        IPage<SafetyFacilityInspection> res = safetyFacilityInspectionMapper.selectPages(page,filter);
-        return res;
+	public IPage<SafetyFacilityInspection> selectPage(Page<SafetyFacilityInspection> page, Map<String, Object> filter,
+			UserInfo user) {
+		Date date = new Date();
+
+		if (user.getType() == 3 ) {
+			filter.put("createBy", user.getUsername());
+		}
+		if (user.getType() == 4) {
+			filter.put("expert", user.getId());
+		}
+		if (user.getType() == 2) {
+			QueryWrapper<CompanyInfo> queryWrapper = new QueryWrapper<CompanyInfo>();
+			queryWrapper.eq("city", user.getCity());
+			queryWrapper.eq("province", user.getProvince());
+			List<CompanyInfo> list = companyInfoMapper.selectList(queryWrapper);
+			List<String> companyList = new ArrayList<String>();
+			for (CompanyInfo companyInfo : list) {
+				companyList.add(companyInfo.getCompany());
+			}
+			filter.put("company", companyList);
+		}
+		if("安科院".equals(user.getCompany())){
+			filter.remove("createBy");
+			filter.remove("company");
+		}
+
+		IPage<SafetyFacilityInspection> res = safetyFacilityInspectionMapper.selectPages(page, filter);
+		List<SafetyFacilityInspection> list = new ArrayList<SafetyFacilityInspection>();
+		for (SafetyFacilityInspection safetyFacilityInspection : res.getRecords()) {
+			if (safetyFacilityInspection.getProgress() == 10 && safetyFacilityInspection.getReviewTime() != null && safetyFacilityInspection.getReviewTime().before(date)) {
+				safetyFacilityInspection.setProgress(11);
+				this.updateById(safetyFacilityInspection);
+				SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+				flow.setCheckTime(new Date());
+				flow.setValidFlag(Byte.valueOf("1"));
+				flow.setCreateBy("SYSTEM");
+				flow.setUpdateTime(date);
+				flow.setCreateTime(date);
+				flow.setProgressName("评审中");
+				flow.setResult("预置时间到");
+				flow.setLinkInspectionId(safetyFacilityInspection.getId());
+				flow.setProcessBy(user.getRealname());
+				safetyFacilityProcessflowMapper.insert(flow);
+				safetyFacilityProcessflowMapper.modPending(safetyFacilityInspection.getId());
+			}
+
+			if (safetyFacilityInspection.getProgress() == 20 && safetyFacilityInspection.getExamineTime() != null && safetyFacilityInspection.getExamineTime().before(date)) {
+				safetyFacilityInspection.setProgress(21);
+				this.updateById(safetyFacilityInspection);
+				SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+				flow.setCheckTime(new Date());
+				flow.setValidFlag(Byte.valueOf("1"));
+				flow.setCreateBy("SYSTEM");
+				flow.setUpdateTime(date);
+				flow.setCreateTime(date);
+				flow.setProgressName("审查中");
+				flow.setResult("预置时间到");
+				flow.setLinkInspectionId(safetyFacilityInspection.getId());
+				flow.setProcessBy(user.getRealname());
+				safetyFacilityProcessflowMapper.insert(flow);
+				safetyFacilityProcessflowMapper.modPending(safetyFacilityInspection.getId());
+			}
+
+			if (safetyFacilityInspection.getExpert() != null) {
+				String[] expertIds = safetyFacilityInspection.getExpert().split(",");
+				String expertName = "";
+				List<UserInfo> temp = userInfoMapper.selectBatchIds(Arrays.asList(expertIds));
+				for (UserInfo userInfo : temp) {
+					expertName += "," + userInfo.getRealname();
+				}
+				safetyFacilityInspection.setExpertName(expertName.substring(1));
+			}
+			list.add(safetyFacilityInspection);
+		}
+		res.setRecords(list);
+		return res;
+
 	}
 
 	@Override
 	public void addOne(SafetyFacilityInspection param, UserInfo user) {
-        Date date = new Date();
-        String username = user.getRealname();
-        param.setValidFlag(Byte.valueOf("1"));
-        param.setCreateBy(username);
-        param.setUpdateTime(date);
-        param.setCreateTime(date);
-        param.setSubmitDate(date);
-        param.setProgress(Integer.valueOf(0));
-        this.save(param); 
+		Date date = new Date();
+		String username = user.getUsername();
+		param.setValidFlag(Byte.valueOf("1"));
+		param.setCreateBy(username);
+		param.setUpdateTime(date);
+		param.setCreateTime(date);
+		param.setSubmitDate(param.getSubmitDate() == null ? date : param.getSubmitDate());
+		param.setProgress(Integer.valueOf(0));
+		param.setCompany(param.getCompany() == null ? user.getCompany() : param.getCompany());
+		this.save(param);
 	}
 
 	@Override
 	public void modOne(SafetyFacilityInspection param, UserInfo user) {
-		// TODO Auto-generated method stub
-		
+		param.setUpdateTime(new Date());
+		this.updateById(param);
 	}
 
 	@Override
 	public void delOne(Long id, UserInfo user) {
-		// TODO Auto-generated method stub
-		
+		SafetyFacilityInspection object = safetyFacilityInspectionMapper.selectByPrimaryKey(id);
+		object.setValidFlag(Byte.valueOf("0"));
+		object.setUpdateTime(new Date());
+		this.updateById(object);
+
 	}
 
 	@Override
-	public SafetyFacilityInspection info(Long id, UserInfo user) {
-		// TODO Auto-generated method stub
-		return null;
+	public SafetyFacilityInspection selectByPrimaryKey(Long id, UserInfo user) {
+		return safetyFacilityInspectionMapper.selectByPrimaryKey(id);
 	}
-
 }

--
Gitblit v1.9.2