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/Controller/SafetyFacilityInspectionController.java |  819 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 776 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/gk/hotwork/Controller/SafetyFacilityInspectionController.java b/src/main/java/com/gk/hotwork/Controller/SafetyFacilityInspectionController.java
index 3a8f11f..741f2c3 100644
--- a/src/main/java/com/gk/hotwork/Controller/SafetyFacilityInspectionController.java
+++ b/src/main/java/com/gk/hotwork/Controller/SafetyFacilityInspectionController.java
@@ -1,68 +1,801 @@
 package com.gk.hotwork.Controller;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
-
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
 
+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.gk.hotwork.Config.attachment.FilePathConfig;
 import com.gk.hotwork.Controller.Base.BaseController;
+import com.gk.hotwork.Domain.CompanyInfo;
 import com.gk.hotwork.Domain.SafetyFacilityInspection;
-import com.gk.hotwork.Domain.SafetyInspectionItem;
+import com.gk.hotwork.Domain.SafetyFacilityProcessflow;
+import com.gk.hotwork.Domain.Enum.ResultCodes;
+import com.gk.hotwork.Domain.Exception.BusinessException;
 import com.gk.hotwork.Domain.Utils.FilterObject;
 import com.gk.hotwork.Domain.Utils.Msg;
+import com.gk.hotwork.Domain.Utils.PageInfo;
+import com.gk.hotwork.Domain.Utils.StringUtils;
+import com.gk.hotwork.Domain.query.CompanyQuery;
+import com.gk.hotwork.Service.CompanyService;
 import com.gk.hotwork.Service.SafetyFacilityInspectionService;
-
+import com.gk.hotwork.Service.SafetyFacilityProcessflowService;
+import com.gk.hotwork.Service.UserService;
+import freemarker.template.Template;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 
-
-@Api(tags = "安全设施审查流程")
+@Api(tags = "②安全设施审查流程")
 @RestController
 @RequestMapping("/safetyFacilityInspection")
-public class SafetyFacilityInspectionController extends BaseController{
+public class SafetyFacilityInspectionController extends BaseController {
 
-    @Autowired
-    private SafetyFacilityInspectionService safetyFacilityInspectionService;
-    
-    
-    @ApiOperation("分页")
-    @PostMapping("/page")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
-            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
-            @ApiImplicitParam(name = "progress",value = "进度进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
-            @ApiImplicitParam(name = "expert",value = "审查专家"),
-            @ApiImplicitParam(name = "submitDateStartTime",value = "开始时间"),
-            @ApiImplicitParam(name = "submitDateEndTime",value = "结束时间")
-    })
-    public Msg selectPage(@RequestBody FilterObject filterObject) {
-        Integer pageIndex = filterObject.getPageIndex();
-        Integer pageSize = filterObject.getPageSize();
-        IPage page = safetyFacilityInspectionService.selectPage(new Page<>(pageIndex, pageSize), filterObject.getFilter(), getUser());
-        return success(page);
-    }
-    
-    
-    @ApiOperation("/新增")
-    @PostMapping("/add")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "submitDate",value = "提交日期"),
-        @ApiImplicitParam(name = "type",value = "类别(1:安全设施设计审查,2:安全条件审查)"),
-        @ApiImplicitParam(name = "projectName",value = "项目名称"),
-        @ApiImplicitParam(name = "progress",value = "进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
-        @ApiImplicitParam(name = "expert",value = "审查专家"),
-        @ApiImplicitParam(name = "contact",value = "联系人"),
-        @ApiImplicitParam(name = "telephone",value = "联系电话")
-})
-    public Msg add(@RequestBody SafetyFacilityInspection param) {
-    	safetyFacilityInspectionService.addOne(param, this.getUser());
-        return success();
-    }
+	@Autowired
+	private SafetyFacilityInspectionService safetyFacilityInspectionService;
+
+	@Autowired
+	private SafetyFacilityProcessflowService safetyFacilityProcessflowService;
+
+	@Autowired
+	private UserService userService;
+
+	@Resource
+	private FilePathConfig filePathConfig;
+
+	@Autowired
+	private CompanyService companyService;
+	
+	@Autowired
+	private FreeMarkerConfigurer freeMarkerConfigurer;
+
+	@ApiOperation("审查项目分页列表")
+	@PostMapping("/page")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
+			@ApiImplicitParam(name = "pageSize", value = "每页行数"),
+			@ApiImplicitParam(name = "progress", value = "进度进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
+			@ApiImplicitParam(name = "expert", value = "审查专家"),
+			@ApiImplicitParam(name = "createBy", value = "企业用户姓名"),
+			@ApiImplicitParam(name = "type", value = "类别(1:安全设施设计审查,2:安全条件审查)"),
+			@ApiImplicitParam(name = "submitDateStartTime", value = "开始时间"),
+			@ApiImplicitParam(name = "submitDateEndTime", value = "结束时间") })
+	public Msg selectPage(@RequestBody FilterObject filterObject) {
+		Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
+		Integer pageSize = filterObject.getPageSize() == null ? 10 : filterObject.getPageSize();
+		Map<String, Object> map = filterObject.getFilter();
+		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+		try {
+			if (map.get("submitDateStartTime") != null && StringUtils.isNotBlank(map.get("submitDateStartTime").toString()))
+				map.put("submitDateStartTime", simpleDateFormat.format(simpleDateFormat.parse(map.get("submitDateStartTime").toString())));
+
+			if (map.get("submitDateEndTime") != null  && StringUtils.isNotBlank(map.get("submitDateEndTime").toString()))
+				map.put("submitDateEndTime", simpleDateFormat.format(simpleDateFormat.parse(map.get("submitDateEndTime").toString())));
+			
+			if (map.get("progress") != null  && StringUtils.isNotBlank(map.get("progress").toString()))
+				map.put("progress", Integer.valueOf(map.get("progress").toString()));
+			else
+				map.put("progress", null);
+			
+			IPage<SafetyFacilityInspection> page = safetyFacilityInspectionService.selectPage(new Page<>(pageIndex, pageSize), filterObject.getFilter(), getUser());
+			return success(page);
+		} catch (ParseException e) {
+			return failed(e.getMessage());
+		}
+
+	}
+
+	@ApiOperation("业务处理历史详情")
+	@PostMapping("/dealFlow")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
+			@ApiImplicitParam(name = "pageSize", value = "每页行数"),
+			@ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg dealFlow(@RequestBody FilterObject filterObject) {
+		Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
+		Integer pageSize = filterObject.getPageSize() == null ? 100 : filterObject.getPageSize();
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+		int progress = inspection.getProgress();
+
+		IPage<SafetyFacilityProcessflow> page = safetyFacilityProcessflowService.processflowPages(new Page<>(pageIndex, pageSize), filterObject.getFilter(), getUser());
+		List<SafetyFacilityProcessflow> list = new ArrayList<SafetyFacilityProcessflow>();
+		List<SafetyFacilityProcessflow> review = new ArrayList<SafetyFacilityProcessflow>();
+		List<SafetyFacilityProcessflow> examine = new ArrayList<SafetyFacilityProcessflow>();
+
+		String reviewFinalResolution = "";
+		String examineFinalResolution = "";
+
+		for (SafetyFacilityProcessflow flow : page.getRecords()) {
+			if ("资料提交".equals(flow.getProgressName()) || "待评审".equals(flow.getProgressName()) || "已受理".equals(flow.getProgressName()) || "待受理".equals(flow.getProgressName()))
+				list.add(flow);
+		}
+
+		if (progress > 20) { // 构建审查全流程
+			SafetyFacilityProcessflow inner = new SafetyFacilityProcessflow();
+			inner.setProgressName("审查开始");
+			inner.setCheckTime(inspection.getExamineTime());
+			examine.add(inner);
+
+			for (SafetyFacilityProcessflow flow : page.getRecords()) {
+				if ("通知补正".equals(flow.getProgressName()) || "企业补正".equals(flow.getProgressName()) || "审查通过".equals(flow.getProgressName()) || "审查否决".equals(flow.getProgressName())) {
+					examine.add(flow);
+				}
+				if ("审查否决".equals(flow.getProgressName()) || "审查通过".equals(flow.getProgressName())) {
+					examineFinalResolution = flow.getResolution();
+				}
+			}
+		}
+
+		if (progress > 10) { // 构建评审全流程
+			SafetyFacilityProcessflow inner = new SafetyFacilityProcessflow();
+			inner.setProgressName("评审开始");
+			inner.setCheckTime(inspection.getReviewTime());
+			review.add(inner);
+
+			for (SafetyFacilityProcessflow flow : page.getRecords()) {
+				if ("评审反馈".equals(flow.getProgressName()) || "企业反馈".equals(flow.getProgressName()) || "评审通过".equals(flow.getProgressName()) || "评审否决".equals(flow.getProgressName())) {
+					review.add(flow);
+				}
+				if ("评审通过".equals(flow.getProgressName()) || "评审否决".equals(flow.getProgressName())) {
+					reviewFinalResolution = flow.getResolution();
+				}
+			}
+		}
+
+		if (progress == 30) {
+			if (inspection.getType() == 1) {
+				SafetyFacilityProcessflow f1 = new SafetyFacilityProcessflow();
+				f1.setProgressName("评审通过");
+				f1.setResult("评审通过");
+				f1.setResolution(reviewFinalResolution);
+				f1.setChildFlow(review);
+				f1.setLinkInspectionId(inspectionId);
+				list.add(f1);
+			}
+
+			SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
+			f.setProgressName("审查通过");
+			f.setResult("耗时:" + inspection.getExamineTaketime());
+			f.setResolution("详情查看审查意见书");
+			f.setChildFlow(examine);
+			f.setLinkInspectionId(inspectionId);
+			list.add(f);
+
+			SafetyFacilityProcessflow ff = new SafetyFacilityProcessflow();
+			ff.setProgressName("已完成");
+			ff.setLinkInspectionId(inspectionId);
+			list.add(ff);
+		}
+		if (progress >= 20 && progress < 30) {
+			if (inspection.getType() == 1) {
+				SafetyFacilityProcessflow f1 = new SafetyFacilityProcessflow();
+				f1.setProgressName("评审通过");
+				f1.setResult("评审通过");
+				f1.setLinkInspectionId(inspectionId);
+				f1.setResolution(reviewFinalResolution);
+				f1.setChildFlow(review);
+				list.add(f1);
+			}
+
+			SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
+			if (progress == 20)
+				f.setProgressName("待审查");
+			if (progress == 21)
+				f.setProgressName("审查中");
+			if (progress == 29)
+				f.setProgressName("待企业补正");
+			if (progress == 22){
+				f.setProgressName("审查否决");
+				f.setResolution(examineFinalResolution);
+			}
+			f.setChildFlow(examine);
+			list.add(f);
+		}
+
+		if (progress > 10 && progress < 20) {
+			SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
+
+			if (progress == 11)
+				f.setProgressName("评审中");
+			if (progress == 19)
+				f.setProgressName("待企业反馈");
+			if (progress == 12){
+				f.setProgressName("评审否决");
+				f.setResolution(reviewFinalResolution);
+			}
+			f.setChildFlow(review);
+			list.add(f);
+		}
+
+		page.setRecords(list);
+		return success(page);
+	}
+
+	@ApiOperation("企业新增审查")
+	@PostMapping("/add")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "submitDate", value = "提交日期(可为空默认当前时间)", required = false),
+			@ApiImplicitParam(name = "type", value = "类别(1:安全设施设计审查,2:安全条件审查)"),
+			@ApiImplicitParam(name = "projectName", value = "项目名称"),
+			@ApiImplicitParam(name = "progress", required = false, value = "进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
+			@ApiImplicitParam(name = "expert", value = "审查专家", required = false),
+			@ApiImplicitParam(name = "contact", value = "联系人", required = false),
+			@ApiImplicitParam(name = "telephone", value = "联系电话", required = false),
+			@ApiImplicitParam(name = "company", value = "企业名称", required = false) })
+	public Msg add(@RequestBody SafetyFacilityInspection param) {
+		String genId = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() + "" + (int) (Math.random() * 900 + 100);
+		param.setId(Long.valueOf(genId));
+		Date date = new Date();
+		safetyFacilityInspectionService.addOne(param, this.getUser());
+
+		SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+		flow.setCheckTime(date);
+		flow.setProgressName("资料提交");
+		flow.setResult("资料提交");
+		flow.setResolution("开始");
+		flow.setLinkInspectionId(Long.valueOf(genId));
+		flow.setProcessBy(this.getUser().getRealname());
+		safetyFacilityProcessflowService.addOne(flow, this.getUser());
+
+		SafetyFacilityProcessflow flowd = new SafetyFacilityProcessflow();
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		c.add(Calendar.SECOND, 1);
+
+		flowd.setCheckTime(c.getTime());
+		flowd.setProgressName("待受理");
+		flowd.setLinkInspectionId(Long.valueOf(genId));
+		safetyFacilityProcessflowService.addOne(flowd, this.getUser());
+
+		return success();
+	}
+	
+	
+	@ApiOperation("删除审查项目")
+	@PostMapping("/delete")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg delete(@RequestBody FilterObject filterObject) {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());		
+		safetyFacilityInspectionService.delOne(inspectionId, this.getUser());
+		safetyFacilityProcessflowService.deleteBylinkInspectionId(inspectionId, this.getUser());
+		return success();
+	}
+
+	@ApiOperation("获取审查专家列表")
+	@PostMapping("/expert")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
+			@ApiImplicitParam(name = "pageSize", value = "每页行数") })
+	public Msg getExpert(@RequestParam(defaultValue = "0") Integer pageIndex,@RequestParam(defaultValue = "10") Integer pageSize, String realname) {
+		Msg msg = new Msg();
+		msg.setCode("200");
+		msg.setMessage("success");
+		PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
+		HashMap<String, Object> condition = new HashMap<String, Object>();
+		condition.put("job", "审查");
+		condition.put("company", "危化处");
+		if (StringUtils.isNotBlank(realname)) {
+			condition.put("realname", realname.trim());
+		}
+
+		pageInfo.setCondition(condition);
+		userService.selectExpertUserDataGrid(pageInfo);
+		msg.setResult(pageInfo);
+		return msg;
+	}
+
+	@ApiOperation("危化处业务处理")
+	@PostMapping("/dealCheck")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "acceptTime", value = "选择受理时间(默认当前时间)", required = false),
+			@ApiImplicitParam(name = "reviewTime", value = "自定义评审开始时间", required = false),
+			@ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg dealCheck(@RequestBody FilterObject filterObject) throws ParseException {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+		String acceptTimeString = null;
+		if (inspection.getProgress() == 0) {
+			if (inspection.getType() == 1) {
+				if (filterObject.getFilter().get("acceptTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("acceptTime").toString())) {
+					acceptTimeString = filterObject.getFilter().get("acceptTime").toString();
+					SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+					inspection.setAcceptTime(simpleDateFormat.parse(acceptTimeString));
+				} else
+					inspection.setAcceptTime(new Date());
+				inspection.setProgress(1);
+
+				SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+				flow.setCheckTime(new Date());
+				flow.setProgressName("已受理");
+				flow.setResult("选择受理时间");
+				flow.setLinkInspectionId(inspectionId);
+				flow.setProcessBy(this.getUser().getRealname());
+				safetyFacilityProcessflowService.addOne(flow, this.getUser());
+				safetyFacilityInspectionService.modOne(inspection, getUser());
+				safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
+			}
+			if (inspection.getType() == 2) {
+				Date date = new Date();
+				if (filterObject.getFilter().get("acceptTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("acceptTime").toString())) {
+					acceptTimeString = filterObject.getFilter().get("acceptTime").toString();
+					SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+					inspection.setAcceptTime(simpleDateFormat.parse(acceptTimeString));
+				} else
+					inspection.setAcceptTime(date);
+				inspection.setProgress(20);
+
+				SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+				flow.setCheckTime(date);
+				flow.setProgressName("已受理");
+				flow.setResult("选择受理时间");
+				flow.setLinkInspectionId(inspectionId);
+				flow.setProcessBy(this.getUser().getRealname());
+				safetyFacilityProcessflowService.addOne(flow, this.getUser());
+				safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
+
+				SafetyFacilityProcessflow flow1 = new SafetyFacilityProcessflow();
+				Calendar c = Calendar.getInstance();
+				c.setTime(date);
+				c.add(Calendar.SECOND, 1);
+				flow1.setProgressName("待审查");
+				flow1.setCheckTime(c.getTime());
+				flow1.setLinkInspectionId(inspectionId);
+				flow1.setProcessBy(this.getUser().getRealname());
+				safetyFacilityProcessflowService.addOne(flow1, this.getUser());			
+				safetyFacilityInspectionService.modOne(inspection, getUser());
+			}
+			return success();
+		}
+		if (inspection.getProgress() == 1) {
+			if (filterObject.getFilter().get("reviewTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("reviewTime").toString())) {
+				acceptTimeString = filterObject.getFilter().get("reviewTime").toString();
+				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+				inspection.setReviewTime(simpleDateFormat.parse(acceptTimeString));
+			} else
+				inspection.setReviewTime(new Date());
+			inspection.setProgress(10);
+
+			SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+			flow.setCheckTime(new Date());
+			flow.setProgressName("待评审");
+			flow.setResult("业务流转");
+			flow.setLinkInspectionId(inspectionId);
+			flow.setProcessBy(this.getUser().getRealname());
+			safetyFacilityProcessflowService.addOne(flow, this.getUser());
+
+			safetyFacilityInspectionService.modOne(inspection, getUser());
+
+			return success();
+
+		}
+		return failed("处理失败!");
+	}
+
+	@ApiOperation("业务处分配审查专家")
+	@PostMapping("/dealExamine")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true),
+			@ApiImplicitParam(name = "expert", value = "审查专家ID(多个ID中间逗号分隔)"),
+			@ApiImplicitParam(name = "examineTime", value = "审查开始时间") })
+	public Msg dealExamine(@RequestBody FilterObject filterObject) throws ParseException {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+
+		int currentprocess = inspection.getProgress();
+		if (currentprocess == 20) {
+
+			inspection.setProgress(21);
+			inspection.setExpert(filterObject.getFilter().get("expert") == null ? "" : filterObject.getFilter().get("expert").toString());
+
+			if (filterObject.getFilter().get("examineTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("examineTime").toString())) {
+				String examineTimeString = filterObject.getFilter().get("examineTime").toString();
+				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+				inspection.setExamineTime(simpleDateFormat.parse(examineTimeString));
+			} else
+				inspection.setExamineTime(new Date());
+
+			safetyFacilityInspectionService.modOne(inspection, this.getUser());
+			return success();
+		} else {
+			return failed("当前项目不在待审查状态,无法进行专家分配!");
+		}
+
+	}
+
+	@ApiOperation("专家审查")
+	@PostMapping("/expertExamine")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true),
+			@ApiImplicitParam(name = "result", required = true, value = "评审反馈结果(9:否决驳回,2:需补正,1:审查通过)"),
+			@ApiImplicitParam(name = "correctNo", required = false, value = "补正告知书编号"),
+			@ApiImplicitParam(name = "correctPDFPath", required = false, value = "补正告知书路径"),
+			@ApiImplicitParam(name = "emergency", value = "应急局通知人(多个ID中间逗号分隔)"),
+			@ApiImplicitParam(name = "resolution", value = "反馈意见") })
+	public Msg expertExamine(@RequestBody FilterObject filterObject) {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId, this.getUser());
+		int res = Integer.valueOf(filterObject.getFilter().get("result").toString());
+		int currentprocess = inspection.getProgress();
+		if (currentprocess == 20 || currentprocess == 21) {
+
+			SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+			flow.setCheckTime(new Date());
+			flow.setLinkInspectionId(inspectionId);
+			flow.setProcessBy(this.getUser().getRealname());
+			flow.setResolution(filterObject.getFilter().get("resolution") == null ? "" : filterObject.getFilter().get("resolution").toString());
+			if (res == 9) {
+				flow.setProgressName("审查否决");
+				flow.setResult("否决驳回");
+				inspection.setProgress(22);
+			}
+			if (res == 2) {
+				flow.setProgressName("通知补正");
+				inspection.setProgress(29);
+				String correctNo = filterObject.getFilter().get("correctNo") == null ? "" : filterObject.getFilter().get("correctNo").toString();
+				String newFilePath = filterObject.getFilter().get("correctPDFPath") == null ? "" : filterObject.getFilter().get("correctPDFPath").toString();
+				flow.setResolution(newFilePath);
+				flow.setResult(correctNo);
+				inspection.setCorrectpdf(newFilePath);
+			}
+			if (res == 1) {
+				flow.setProgressName("审查通过");
+				flow.setResult("审查通过完成");
+				inspection.setProgress(30);
+
+				Date begin = inspection.getExamineTime();
+
+				Calendar cal1 = Calendar.getInstance();
+				cal1.setTime(begin);
+				Calendar cal2 = Calendar.getInstance();
+				cal2.setTime(new Date());
+
+				Long diff = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 60000;
+				int day = diff.intValue() / 1440;
+				int hour = (diff.intValue() % 1440) / 60;
+				int min = (diff.intValue() % 1440) % 60;
+				inspection.setExamineTaketime(day + "天" + hour + "小时" + min + "分钟");
+
+				SimpleDateFormat pageno = new SimpleDateFormat("MMdd");
+				int dateno = Integer.valueOf(pageno.format(new Date())) / 2;
+				if (dateno < 100)
+					inspection.setExaminePageno("0" + dateno);
+				else
+					inspection.setExaminePageno("" + dateno);
+			}
+
+			safetyFacilityProcessflowService.addOne(flow, this.getUser());
+			safetyFacilityInspectionService.modOne(inspection, this.getUser());
+
+			return success();
+		} else {
+			return failed("当前项目状态异常无法进行审查!");
+		}
+
+	}
+
+	@ApiOperation("专家审查上传补正告知书")
+	@PostMapping("/uploadCorrectPDF")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "上传补正告知书(PDF)文件") })
+	public Msg uploadCorrectPDF(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
+		if (file.getSize() > 1024 * 1024 * 2) {
+			return failed("文件超过2M无法上传");
+		}
+
+		String path = filePathConfig.getModule().get("correctPDF");
+		String dcPath = filePathConfig.getDcPath();
+		String originalFilename = file.getOriginalFilename();
+		LocalDateTime now = LocalDateTime.now();
+		File newFile = null;
+
+		try {
+			String key = UUID.randomUUID().toString().replace("-", "");
+			String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
+			path = path.replace("/", File.separator);
+			String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd"));
+			String newFilePath = modulePath + File.separator + key + suffix;
+			String localPath = dcPath + newFilePath;
+			newFile = new File(localPath);
+			if (!newFile.exists() && !newFile.mkdirs()) {
+				return failed("文件上传路径不存在!");
+			}
+			file.transferTo(newFile);
+			return success(newFilePath);
+		} catch (IOException e) {
+			if (newFile != null && newFile.exists()) {
+				newFile.delete();
+			}
+			return failed("文件上传异常!");
+		}
+	}
+
+	@ApiOperation("补正告知书下载")
+	@PostMapping("/downCorrectPDF")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "filename", value = "补正告知书文件名", required = true),
+			@ApiImplicitParam(name = "correctNo", value = "补正告知书编号") })
+	public void downCorrectPDF(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
+		if (filterObject.getFilter().get("filename") == null)
+			return;
+		String filepath = filterObject.getFilter().get("filename").toString();
+		String correctNo = filterObject.getFilter().get("correctNo") == null ? "" : filterObject.getFilter().get("correctNo").toString();
+		response.reset();
+		response.addHeader("Access-Control-Allow-Origin", "*");
+		response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
+		response.setContentType("application/octet-stream; charset=UTF-8");
+		response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("补正告知书" + correctNo + ".pdf", StandardCharsets.UTF_8.name()));
+		response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+		String dcPath = filePathConfig.getDcPath();
+		File file = new File(dcPath + filepath);
+		if (!file.exists()) {
+			throw new BusinessException(ResultCodes.FILE_NOT_EXISIST);
+		}
+		response.addHeader("Content-Length", "" + file.length());
+		FileInputStream inputStream = new FileInputStream(file);
+		byte[] b = new byte[inputStream.available()];
+		inputStream.read(b);
+		ServletOutputStream outputStream = response.getOutputStream();
+		outputStream.write(b);
+		outputStream.flush();
+		inputStream.close();
+	}
+
+	@ApiOperation("审查意见书预览")
+	@PostMapping("/viewExamineFile")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public void viewExamineFile(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return;
+		Template template = freeMarkerConfigurer.getConfiguration().getTemplate("ReviewHtml.ftl", "UTF-8");
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+		Map<String, Object> map = new HashMap<String, Object>();
+		map.put("year", String.valueOf(LocalDate.now().getYear()));
+		map.put("pageno", "0001");
+		map.put("company", inspection.getCompany());
+		map.put("projectName", inspection.getProjectName());
+		map.put("contact", inspection.getContact());
+		map.put("telephone", inspection.getTelephone());
+
+		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
+		map.put("submitDate", simpleDateFormat.format(new Date()));
+
+		String duplicate = "";
+		if (inspection.getCompany() != null) {
+			duplicate = companyService.selectByName(inspection.getCompany()).getCity();
+		}
+		map.put("duplicate", duplicate + "应急管理局");
+		response.setContentType("text/html;charset=utf-8");
+		template.process(map, response.getWriter());
+	}
+
+	@ApiOperation("审查意见书下载")
+	@PostMapping("/downExamineFile")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public void downExamineFile(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return;
+		Template template = freeMarkerConfigurer.getConfiguration().getTemplate("ReviewHtml.ftl", "UTF-8");
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId, this.getUser());
+
+		Map<String, Object> map = new HashMap<String, Object>();
+		SimpleDateFormat year = new SimpleDateFormat("yyyy");
+		map.put("year", year.format(inspection.getCreateTime()));
+		map.put("pageno", inspection.getExaminePageno());
+		map.put("company", inspection.getCompany());
+		map.put("projectName", inspection.getProjectName());
+		map.put("contact", inspection.getContact());
+		map.put("telephone", inspection.getTelephone());
+
+		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
+		map.put("submitDate", simpleDateFormat.format(new Date()));
+
+		String duplicate = "";
+		if (inspection.getCompany() != null) {
+			duplicate = companyService.selectByName(inspection.getCompany()).getCity();
+		}
+		map.put("duplicate", duplicate + "应急管理局");
+		response.setHeader("content-Type", "application/msword");
+		String fileName = URLEncoder.encode("审查意见书", "UTF-8");
+		response.setCharacterEncoding("UTF-8");
+		response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".doc");
+		template.process(map, response.getWriter());
+	}
+
+	@ApiOperation("安科院评审反馈")
+	@PostMapping("/reviewFeedback")
+	@ApiImplicitParams({
+			@ApiImplicitParam(name = "result", required = true, value = "评审反馈结果(9:否决驳回,2:需问题反馈,1:通过并流转到业务处室)"),
+			@ApiImplicitParam(name = "resolution", value = "反馈意见"),
+			@ApiImplicitParam(name = "reviewTime", value = "评审开始时间", required = true),
+			@ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg reviewFeedback(@RequestBody FilterObject filterObject) throws ParseException {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+		if (filterObject.getFilter().get("result") == null)
+			return failed("评审反馈结果不能为空");
+		if (filterObject.getFilter().get("reviewTime") == null)
+			return failed("请选择评审开始时间");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		int res = Integer.valueOf(filterObject.getFilter().get("result").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+
+		int currentprocess = inspection.getProgress();
+		String timeString = filterObject.getFilter().get("reviewTime").toString();
+		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+		inspection.setReviewTime(simpleDateFormat.parse(timeString));
+
+		if (currentprocess == 10 || currentprocess == 11) {
+			SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+			Date date = new Date();
+			flow.setCheckTime(date);
+			flow.setLinkInspectionId(inspectionId);
+			flow.setProcessBy(this.getUser().getRealname());
+			flow.setResolution(filterObject.getFilter().get("resolution") == null ? "" : filterObject.getFilter().get("resolution").toString());
+			if (res == 9) {
+				flow.setProgressName("评审否决");
+				flow.setResult("否决驳回");
+				inspection.setProgress(12);
+			}
+			if (res == 2) {
+				flow.setProgressName("评审反馈");
+				flow.setResult("需问题反馈");
+				inspection.setProgress(19);
+			}
+			if (res == 1) {
+				flow.setProgressName("评审通过");
+				flow.setResult("通过并流转到业务处室");
+				inspection.setProgress(20);
+			}
+
+			safetyFacilityProcessflowService.addOne(flow, this.getUser());
+			safetyFacilityInspectionService.modOne(inspection, this.getUser());
+			safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
+
+			if (res == 1) {
+				SafetyFacilityProcessflow flow1 = new SafetyFacilityProcessflow();
+				Calendar c = Calendar.getInstance();
+				c.setTime(date);
+				c.add(Calendar.SECOND, 1);
+				flow1.setProgressName("待审查");
+				flow1.setCheckTime(c.getTime());
+				flow1.setLinkInspectionId(inspectionId);
+				flow1.setProcessBy(this.getUser().getRealname());
+				safetyFacilityProcessflowService.addOne(flow1, this.getUser());
+			}
+
+			return success();
+		} else {
+			return failed("当前项目不在评审环节,不能进行评审!");
+		}
+
+	}
+
+	@ApiOperation("企业提交反馈")
+	@PostMapping("/companySubmission")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg companySubmission(@RequestBody FilterObject filterObject) {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+
+		int currentprocess = inspection.getProgress();
+		if (currentprocess == 19) {
+			SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+			flow.setCheckTime(new Date());
+			flow.setLinkInspectionId(inspectionId);
+			flow.setProcessBy(this.getUser().getRealname());
+			flow.setProgressName("企业反馈");
+			flow.setResult("已线下提交反馈资料");
+			safetyFacilityProcessflowService.addOne(flow, this.getUser());
+
+			inspection.setProgress(11);
+			safetyFacilityInspectionService.modOne(inspection, this.getUser());
+			return success();
+		} else {
+			return failed("当前项目不在待提交反馈状态,企业无法提交反馈!");
+		}
+	}
+
+	@ApiOperation("获取审查项目对应的当地(市、州)级应急局所有人")
+	@PostMapping("/getEmergencyInfo")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
+			@ApiImplicitParam(name = "pageSize", value = "每页行数"),
+			@ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg getEmergencyInfo(@RequestBody FilterObject filterObject) {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+
+		String duplicate = null;
+		if (inspection.getCompany() != null) {
+			duplicate = companyService.selectByName(inspection.getCompany()).getCity();
+		} else {
+			return failed("当前安全审查项目没有归属地!");
+		}
+		Msg msg = new Msg();
+		msg.setCode("200");
+		msg.setMessage("success");
+
+		Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
+		Integer pageSize = filterObject.getPageSize() == null ? 10 : filterObject.getPageSize();
+		PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
+		HashMap<String, Object> condition = new HashMap<String, Object>();
+		condition.put("company", duplicate);
+		pageInfo.setCondition(condition);
+		userService.selectSuperviseUserDataGrid(pageInfo);
+		msg.setResult(pageInfo);
+		return msg;
+	}
+
+	@ApiOperation("企业提交补正")
+	@PostMapping("/companySubcorrect")
+	@ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
+	public Msg companySubcorrect(@RequestBody FilterObject filterObject) {
+		if (filterObject.getFilter().get("linkInspectionId") == null)
+			return failed("安全审查项目ID不能为空");
+
+		Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
+		SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
+
+		int currentprocess = inspection.getProgress();
+		if (currentprocess == 29) {
+			SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
+			flow.setCheckTime(new Date());
+			flow.setLinkInspectionId(inspectionId);
+			flow.setProcessBy(this.getUser().getRealname());
+			flow.setProgressName("企业补正");
+			flow.setResult("已线下提交补正材料");
+			safetyFacilityProcessflowService.addOne(flow, this.getUser());
+
+			inspection.setProgress(21);
+			safetyFacilityInspectionService.modOne(inspection, this.getUser());
+			return success();
+		} else {
+			return failed("当前项目不在待提交补正状态,企业无法提交补正!");
+		}
+	}
+
 }

--
Gitblit v1.9.2