487 lines
17 KiB
Java
487 lines
17 KiB
Java
package com.zcloud.controller.app;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import javax.management.RuntimeErrorException;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
import org.springframework.web.servlet.ModelAndView;
|
||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||
|
||
import com.zcloud.controller.base.BaseController;
|
||
import com.zcloud.entity.Page;
|
||
import com.zcloud.util.Const;
|
||
import com.zcloud.util.DateUtil;
|
||
import com.zcloud.util.FileDownload;
|
||
import com.zcloud.util.FileUpload;
|
||
import com.zcloud.util.Jurisdiction;
|
||
import com.zcloud.util.ObjectExcelRead;
|
||
import com.zcloud.util.ObjectExcelView;
|
||
import com.zcloud.util.PathUtil;
|
||
import com.zcloud.util.Smb;
|
||
import com.zcloud.util.Tools;
|
||
import com.zcloud.entity.PageData;
|
||
import com.zcloud.service.bus.IdentificationPartsService;
|
||
import com.zcloud.service.bus.RiskPointService;
|
||
import com.zcloud.service.bus.RiskUnitService;
|
||
import com.zcloud.service.system.DepartmentService;
|
||
|
||
/**
|
||
* 说明:辨识部位
|
||
* 作者:luoxiaobao
|
||
* 时间:2020-12-30
|
||
* 官网:www.zcloudchina.com
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/app/identificationparts")
|
||
public class AppIdentificationPartsController extends BaseController {
|
||
|
||
@Autowired
|
||
private IdentificationPartsService identificationpartsService;
|
||
@Autowired
|
||
private RiskUnitService riskunitService;
|
||
@Autowired
|
||
private RiskPointService riskpointService;
|
||
@Autowired
|
||
private DepartmentService departmentService;
|
||
/**新增
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/add")
|
||
@RequiresPermissions("identificationparts:add")
|
||
@ResponseBody
|
||
public Object add() throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
pd.put("IDENTIFICATIONPARTS_ID", this.get32UUID()); //主键
|
||
|
||
pd.put("CREATOR", Jurisdiction.getUsername()); //添加人
|
||
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
|
||
pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人
|
||
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
pd.put("ISDELETE", "0"); //是否删除 1-是 0-否
|
||
identificationpartsService.save(pd);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**获取风险点下拉框选项
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/getSelect")
|
||
@ResponseBody
|
||
public Object getPointSelect() throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业
|
||
List<PageData> unitList = riskunitService.listAll(pd);
|
||
map.put("unitList", unitList);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**删除
|
||
* @param out
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/delete")
|
||
@RequiresPermissions("identificationparts:del")
|
||
@ResponseBody
|
||
public Object delete() throws Exception{
|
||
Map<String,String> map = new HashMap<String,String>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
pd.put("CHECK_IDENTIFICATION_ID", pd.get("IDENTIFICATIONPARTS_ID"));
|
||
List<PageData> list = riskpointService.listAll(pd);
|
||
if(list!=null && list.size()>0) {
|
||
map.put("result", "fail"); //返回结果
|
||
return map;
|
||
}
|
||
pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人
|
||
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
|
||
identificationpartsService.delete(pd);
|
||
map.put("result", errInfo); //返回结果
|
||
return map;
|
||
}
|
||
|
||
/**修改
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/edit")
|
||
@RequiresPermissions("identificationparts:edit")
|
||
@ResponseBody
|
||
public Object edit() throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人
|
||
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
|
||
identificationpartsService.edit(pd);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**列表
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/list")
|
||
@RequiresPermissions("identificationparts:list")
|
||
@ResponseBody
|
||
public Object list(Page page) throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
|
||
if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim());
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
page.setPd(pd);
|
||
List<PageData> varList = identificationpartsService.list(page); //列出IdentificationParts列表
|
||
map.put("varList", varList);
|
||
map.put("page", page);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**列表
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/listAll")
|
||
@ResponseBody
|
||
public Object listAll(Page page) throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业
|
||
List<PageData> partsList = identificationpartsService.listAll(pd);
|
||
map.put("partsList", partsList);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**列表
|
||
* @param page
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/listAllByIdens")
|
||
@ResponseBody
|
||
public Object listAllByIdens(Page page) throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
String DATA_IDS = pd.getString("IDS");
|
||
if(Tools.notEmpty(DATA_IDS)){
|
||
String ArrayDATA_IDS[] = DATA_IDS.split(",");
|
||
pd.put("ArrayDATA_IDS", ArrayDATA_IDS);
|
||
List<PageData> varList = identificationpartsService.listAllByIdens(pd);
|
||
errInfo = "success";
|
||
map.put("varList", varList);
|
||
}else{
|
||
errInfo = "fail";
|
||
}
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业
|
||
List<PageData> partsList = identificationpartsService.listAll(pd);
|
||
map.put("partsList", partsList);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**去修改页面获取数据
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/goEdit")
|
||
@ResponseBody
|
||
public Object goEdit() throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
List<PageData> arrList = riskpointService.findByPartsId(pd);
|
||
String ACCIDENTS_NAME = "";
|
||
if(arrList.size()>0){
|
||
for(PageData arr:arrList){
|
||
if(Tools.isEmpty(ACCIDENTS_NAME)){
|
||
ACCIDENTS_NAME =ACCIDENTS_NAME + arr.getString("ACCIDENTS_NAME");
|
||
}else {
|
||
ACCIDENTS_NAME =ACCIDENTS_NAME +","+ arr.getString("ACCIDENTS_NAME");
|
||
}
|
||
}
|
||
}
|
||
String[] a = ACCIDENTS_NAME.split(",");
|
||
pd = identificationpartsService.findById(pd); //根据ID读取
|
||
pd.put("ACCIDENTS_NAME",ACCIDENTS_NAME);
|
||
map.put("pd", pd);
|
||
map.put("result", errInfo);
|
||
return map;
|
||
}
|
||
|
||
/**批量删除
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/deleteAll")
|
||
@RequiresPermissions("identificationparts:del")
|
||
@ResponseBody
|
||
public Object deleteAll() throws Exception{
|
||
Map<String,Object> map = new HashMap<String,Object>();
|
||
String errInfo = "success";
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
String DATA_IDS = pd.getString("DATA_IDS");
|
||
if(Tools.notEmpty(DATA_IDS)){
|
||
String ArrayDATA_IDS[] = DATA_IDS.split(",");
|
||
for (String id : ArrayDATA_IDS) {
|
||
PageData iden = new PageData();
|
||
iden.put("CHECK_IDENTIFICATION_ID", id);
|
||
List<PageData> list = riskpointService.listAll(iden);
|
||
if(list!=null && list.size()>0) {
|
||
continue;
|
||
}
|
||
pd.put("IDENTIFICATIONPARTS_ID", id);
|
||
pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人
|
||
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
|
||
identificationpartsService.delete(pd);
|
||
}
|
||
// identificationpartsService.deleteAll(ArrayDATA_IDS);
|
||
errInfo = "success";
|
||
}else{
|
||
errInfo = "fail";
|
||
}
|
||
map.put("result", errInfo); //返回结果
|
||
return map;
|
||
}
|
||
|
||
/**导出到excel
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/excel")
|
||
// @RequiresPermissions("toExcel")
|
||
public ModelAndView exportExcel() throws Exception{
|
||
ModelAndView mv = new ModelAndView();
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
Map<String,Object> dataMap = new HashMap<String,Object>();
|
||
List<String> titles = new ArrayList<String>();
|
||
titles.add("所属企业"); //2
|
||
titles.add("风险点(单元)"); //2
|
||
titles.add("辨识部位"); //1
|
||
dataMap.put("titles", titles);
|
||
List<PageData> varOList = identificationpartsService.listAll(pd);
|
||
List<PageData> varList = new ArrayList<PageData>();
|
||
for(int i=0;i<varOList.size();i++){
|
||
PageData vpd = new PageData();
|
||
vpd.put("var1", varOList.get(i).getString("CORP_NAME")); //1
|
||
vpd.put("var2", varOList.get(i).getString("RISKUNITNAME")); //2
|
||
vpd.put("var3", varOList.get(i).getString("PARTSNAME")); //6
|
||
varList.add(vpd);
|
||
}
|
||
dataMap.put("varList", varList);
|
||
ObjectExcelView erv = new ObjectExcelView();
|
||
mv = new ModelAndView(erv,dataMap);
|
||
return mv;
|
||
}
|
||
|
||
/**导出到excel
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/excelModel")
|
||
// @RequiresPermissions("toExcel")
|
||
public void exportExcelModel(HttpServletResponse response) throws Exception{
|
||
|
||
FileDownload.fileDownload(response, PathUtil.getProjectpath() + Const.FILEPATHFILE + "identificationpartsExcelTemplate.xls", "identificationpartsExcelTemplate.xls");
|
||
}
|
||
|
||
/**从EXCEL导入到数据库
|
||
* @param file
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/readExcel")
|
||
@RequiresPermissions("fromExcel")
|
||
@SuppressWarnings("unchecked")
|
||
@ResponseBody
|
||
@Transactional
|
||
public Object readExcel(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception{
|
||
Map<String,String> map = new HashMap<String,String>();
|
||
String errInfo = "success";
|
||
StringBuffer errorStr = new StringBuffer();
|
||
if (null != file && !file.isEmpty()) {
|
||
String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase();
|
||
if (!"xls".equals(suffixName)) {
|
||
errInfo = "fail";
|
||
map.put("result", errInfo);
|
||
map.put("msg", "文件格式不正确!");
|
||
return map;
|
||
}
|
||
// String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + "identificationparts/"+DateUtil.getDays()+"/";
|
||
// String fileName = FileUpload.fileUp(file, filePath, this.get32UUID());//执行上传
|
||
String ffile = "identificationparts/"+DateUtil.getDays()+"/";
|
||
String filePath = Const.FILEURL + Const.FILEPATHFILE + ffile;
|
||
String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
||
Smb.sshSftp(file, fileName,Const.FILEPATHFILE + ffile);
|
||
List<PageData> listPd = (List)ObjectExcelRead.readExcel(filePath, fileName, 1, 0, 0); //执行读EXCEL操作,读出的数据导入List 2:从第3行开始;0:从第A列开始;0:第0个sheet
|
||
/**
|
||
*
|
||
* 所属部门 风险点(单元) 辨识部位
|
||
*/
|
||
|
||
List<PageData> saveList = new ArrayList<>();
|
||
try {
|
||
if(listPd.size()>0) {
|
||
List<String> header = new ArrayList<>();
|
||
header.add("所属部门");header.add("风险点(单元)");header.add("辨识部位");
|
||
PageData pdCorpId = new PageData();
|
||
pdCorpId.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
pdCorpId.put("ISDELETE", "0");
|
||
List<PageData> departAll =departmentService.listAll(pdCorpId);
|
||
Map<String,Object> departMapAll = new HashMap<>();
|
||
for (PageData pageData : departAll) {
|
||
departMapAll.put(pageData.getString("NAME"), pageData);
|
||
}
|
||
List<PageData> riskunitListAll =riskunitService.listAll(pdCorpId);
|
||
Map<String, Object> riskunitMapAll = new HashMap<>();
|
||
for (PageData pageData : riskunitListAll) {
|
||
riskunitMapAll.put(pageData.getString("DEPARTMENT_ID")+pageData.getString("RISKUNITNAME"), pageData);
|
||
}
|
||
|
||
List<PageData> identiListAll =identificationpartsService.listAll(pdCorpId);
|
||
Map<String, Object> identiMapAll = new HashMap<>();
|
||
for (PageData pageData : identiListAll) {
|
||
identiMapAll.put(pageData.getString("RISK_UNIT_ID")+pageData.getString("PARTSNAME"), pageData);
|
||
}
|
||
Map<String, Object> hasAgain = new HashMap<>();
|
||
int succeeNum = 1;
|
||
for(PageData lpd:listPd) {
|
||
succeeNum++;
|
||
|
||
for(int i=0;i<header.size();i++) {
|
||
if(!lpd.containsKey("var"+i)) {
|
||
errorStr.append("第"+succeeNum+"行的\""+header.get(i)+"\"无数据;\n");
|
||
continue;
|
||
}
|
||
if(Tools.isEmpty(lpd.get("var"+i))) {
|
||
errorStr.append("第"+succeeNum+"行的\""+header.get(i)+"\"无数据;\n");
|
||
continue;
|
||
}
|
||
}
|
||
|
||
String departVar = Tools.isEmpty(lpd.get("var0"))?"":Tools.excelHandle(lpd.get("var0"));
|
||
String riskNameVar = Tools.isEmpty(lpd.get("var1"))?"":Tools.excelHandle(lpd.get("var1"));
|
||
String checkNameVar =Tools.isEmpty(lpd.get("var2"))?"":Tools.excelHandle(lpd.get("var2"));
|
||
if(hasAgain.containsKey(departVar+riskNameVar+checkNameVar)) {
|
||
errorStr.append("第"+succeeNum+"行的"+"数据重复;\n");
|
||
continue;
|
||
}
|
||
hasAgain.put(departVar+riskNameVar+checkNameVar, "1");
|
||
if(!departMapAll.containsKey(departVar)) {
|
||
errorStr.append("第"+succeeNum+"行:"+"未找到名称为\""+departVar+"\"的"+header.get(0)+";\n");
|
||
continue;
|
||
}
|
||
PageData depart = (PageData) departMapAll.get(departVar);
|
||
if(!riskunitMapAll.containsKey(depart.getString("DEPARTMENT_ID")+riskNameVar)) {
|
||
errorStr.append("第"+succeeNum+"行:"+"在"+departVar+"部门下未找到名称为\""+riskNameVar+"\"的"+header.get(1)+";\n");
|
||
continue;
|
||
}
|
||
PageData risk = (PageData) riskunitMapAll.get(depart.getString("DEPARTMENT_ID")+riskNameVar);
|
||
if(identiMapAll.containsKey(risk.get("RISKUNIT_ID")+checkNameVar)) {
|
||
errorStr.append("第"+succeeNum+"行:"+"发现已经存在\""+riskNameVar+"-"+checkNameVar+"\"的"+header.get(2)+";\n");
|
||
continue;
|
||
}else {
|
||
System.out.println(succeeNum);
|
||
}
|
||
|
||
PageData identificationparts = new PageData();
|
||
identificationparts.put("RISK_UNIT_ID", risk.get("RISKUNIT_ID"));
|
||
identificationparts.put("PARTSNAME", checkNameVar);
|
||
identificationparts.put("IDENTIFICATIONPARTS_ID", this.get32UUID());
|
||
identificationparts.put("ISDELETE", "0");
|
||
identificationparts.put("CREATOR", Jurisdiction.getUsername());
|
||
identificationparts.put("CREATTIME", DateUtil.date2Str(new Date()));
|
||
identificationparts.put("OPERATOR",Jurisdiction.getUsername());
|
||
identificationparts.put("OPERATTIME", DateUtil.date2Str(new Date()));
|
||
identificationparts.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
|
||
saveList.add(identificationparts);
|
||
|
||
}
|
||
if(Tools.isEmpty(errorStr.toString())) {
|
||
for (PageData pageData : saveList) {
|
||
identificationpartsService.save(pageData);
|
||
}
|
||
errorStr.append("成功导入"+saveList.size()+"条数据!");
|
||
}else {
|
||
errInfo = "fail";
|
||
}
|
||
|
||
}else {
|
||
map.put("result", "error"); //返回结果
|
||
map.put("resultStr", "Excel数据未空,请检查数据后,重新上传!");
|
||
return map;
|
||
}
|
||
}catch (Exception e) {
|
||
map.put("result", "error"); //返回结果
|
||
map.put("resultStr", e.toString());
|
||
return map;
|
||
}
|
||
}
|
||
map.put("result", errInfo); //返回结果
|
||
map.put("resultStr", errorStr.toString());
|
||
return map;
|
||
}
|
||
|
||
|
||
/**判断同一个风险单元辨识部位名称是否重复
|
||
* @param
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping(value="/hasName")
|
||
@ResponseBody
|
||
public Object hasName() throws Exception{
|
||
Map<String, Object> map = new HashMap<>();
|
||
PageData pd = new PageData();
|
||
pd = this.getPageData();
|
||
String errInfo = "success";
|
||
PageData identificationparts = new PageData();
|
||
|
||
identificationparts.put("RISKUNIT_ID", pd.getString("RISK_UNIT_ID"));
|
||
identificationparts.put("CHECK_NAME",pd.getString("name"));
|
||
List<PageData> list = identificationpartsService.listAll(identificationparts);
|
||
if(list.size()>0) {
|
||
errInfo = "fail";
|
||
}
|
||
map.put("result", errInfo); //返回结果
|
||
map.put("count", list.size());
|
||
return map;
|
||
}
|
||
}
|