package com.gk.hotwork.Controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.gk.hotwork.Controller.Base.BaseController; import com.gk.hotwork.Domain.*; import com.gk.hotwork.Domain.Utils.*; import com.gk.hotwork.Domain.Vo.SelfCheckVo; import com.gk.hotwork.Service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @Api(tags = "巡检接口") @RestController public class PatrolController extends BaseController{ @Value("${patrolPath}") private String patrolPath; //配置文件配置的物理保存地址 @Value("${patrolUrl}") private String patrolUrl; //配置文件配置的url @Autowired SelfCheckService selfCheckService; @Autowired UserService userService; @Autowired ExcelExportService excelExportService; @GetMapping("/getSelfCheck") @ApiOperation(value = "根据类型获取检查内容",response = Msg.class) public Msg getSelfCheck(SelfCheckInfo selfCheck){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); List selfChecks = selfCheckService.selectByType(selfCheck.getType()); if (selfChecks.size() > 0) { msg.setResult(selfChecks); return msg; }else { msg.setCode("999"); msg.setMessage("未找到该检查内容"); return msg; } } @ApiOperation(value = "上传图片",notes = "上传图片") @ApiImplicitParams({ @ApiImplicitParam(paramType="query",name = "files",value = "文件"), }) @PostMapping("/uploadPic") @ResponseBody public Msg uploadPic(StandardMultipartHttpServletRequest req){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); MultiValueMap multipartFiles = req.getMultiFileMap(); MultipartFile picFile = multipartFiles.get("files").get(0); if (null == picFile){ msg.setCode("404"); msg.setMessage("上传文件为空"); }else { try { String picmame = UploadUtil.uploadFile(picFile,patrolPath); msg.setResult(patrolUrl+picmame); }catch (Exception e){ e.printStackTrace(); msg.setCode("500"); msg.setMessage("上传失败"); } } return msg; } @GetMapping("/selfCheck") @ApiOperation(value = "获取自定义检查内容",response = Msg.class) @ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex",value = "当前页码"), @ApiImplicitParam(name = "pageSize",value = "每页行数"), @ApiImplicitParam(name = "sort",value = "排序规则"), @ApiImplicitParam(name = "order",value = "排序字段"), @ApiImplicitParam(name = "type",value = "检查类型"), @ApiImplicitParam(name = "tasktype",value = "作业类型"), @ApiImplicitParam(name = "content",value = "检查内容"), }) public Msg getSelfCheckList(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order, String tasktype, String type,String content){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order); HashMap condition = new HashMap(); if (StringUtils.isNotBlank(tasktype)) { condition.put("tasktype", tasktype.trim()); } if (StringUtils.isNotBlank(type)) { condition.put("type", type.trim()); } if (StringUtils.isNotBlank(content)) { condition.put("content", content.trim()); } pageInfo.setCondition(condition); selfCheckService.selectDataGrid(pageInfo); msg.setResult(pageInfo); return msg; } @PostMapping("/addselfCheck") @ApiOperation(value = "添加自定义检查内容",response = Msg.class) public Msg addSelfCheckList(@RequestBody SelfCheckInfo selfCheckInfo){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); if (StringUtils.isBlank(selfCheckInfo.getTasktype())){ msg.setCode("999"); msg.setMessage("作业类型不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getType())){ msg.setCode("999"); msg.setMessage("检查类型不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getContent())){ msg.setCode("999"); msg.setMessage("检查内容不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getStandard())){ msg.setCode("999"); msg.setMessage("参考判断不能为空"); return msg; } selfCheckInfo.setCreatedby(getUser().getRealname()); selfCheckInfo.setModifiedby(getUser().getRealname()); selfCheckInfo.setCreateddate(new Date()); selfCheckInfo.setModifieddate(new Date()); selfCheckInfo.setIsdel((byte)0); selfCheckService.save(selfCheckInfo); return msg; } @PostMapping("/putselfCheck") @ApiOperation(value = "修改自定义检查内容",response = Msg.class) public Msg editSelfCheckList(@RequestBody SelfCheckInfo selfCheckInfo){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); if (StringUtils.isBlank(selfCheckInfo.getTasktype())){ msg.setCode("999"); msg.setMessage("作业类型不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getType())){ msg.setCode("999"); msg.setMessage("检查类型不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getContent())){ msg.setCode("999"); msg.setMessage("检查内容不能为空"); return msg; }else if (StringUtils.isBlank(selfCheckInfo.getStandard())){ msg.setCode("999"); msg.setMessage("参考判断不能为空"); return msg; } selfCheckInfo.setModifiedby(getUser().getRealname()); selfCheckInfo.setModifieddate(new Date()); selfCheckService.updateById(selfCheckInfo); return msg; } @PostMapping("/delselfCheck") @ApiOperation(value = "删除自定义检查内容",response = Msg.class) public Msg delSelfCheckList(@RequestBody JSONObject jsonObject){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); Long id = jsonObject.getLong("id"); SelfCheckInfo selfCheckInfo = selfCheckService.getById(id); if (selfCheckInfo != null){ selfCheckInfo.setIsdel((byte)1); selfCheckInfo.setModifiedby(getUser().getRealname()); selfCheckInfo.setModifieddate(new Date()); selfCheckService.updateById(selfCheckInfo); return msg; }else { msg.setCode("999"); msg.setMessage("未找到检查内容"); return msg; } } @PostMapping("/selfChecks") @ApiOperation(value = "删除自定义检查内容",response = Msg.class) public Msg bashDelSelfCheckList(@RequestBody JSONObject jsonObject){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); JSONArray ids = jsonObject.getJSONArray("ids"); List idList = ids.toJavaList(Long.class); List selfCheckInfoList = selfCheckService.selectByIds(idList); if (selfCheckInfoList != null && selfCheckInfoList.size() > 0){ for (SelfCheckInfo selfCheckInfo : selfCheckInfoList) { selfCheckInfo.setIsdel((byte)1); selfCheckInfo.setModifiedby(getUser().getRealname()); selfCheckInfo.setModifieddate(new Date()); selfCheckService.updateById(selfCheckInfo); } return msg; }else { msg.setCode("999"); msg.setMessage("未找到检查内容"); return msg; } } @PostMapping("/importSelfCheck") @ApiOperation(value = "导入自定义检查内容",response = Msg.class) @ApiImplicitParams({ @ApiImplicitParam(name = "file",value = "文件",required = true), }) public Msg addSelfCheckList(MultipartFile file){ Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("success"); String filesave =""; try { SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" ); if (file == null) { msg.setCode("404"); msg.setMessage("未找到上传文件"); return msg; } long size = file.getSize(); if(0 == size) { msg.setCode("404"); msg.setMessage("上传文件大小为空"); return msg; } if(!FileOptUtils.isDirExists(patrolPath)){ msg.setCode("500"); msg.setMessage("发生错误或不为目录"); return msg; } filesave = patrolPath + getUser().getRealname() + "_" + sdf.format(new Date()) +".xlsx"; file.transferTo(new File(filesave)); InputStream in = new FileInputStream(filesave); String name = file.getOriginalFilename(); Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx")? true:false; BooleanReason blret = excelExportService.imporSelfCheckExcel(in,getUser().getRealname(),isExcel2007); if(blret.getValue().equals(false)) { msg.setCode("500"); msg.setMessage(blret.getResultmsg()); return msg; } } catch (Exception e) { e.printStackTrace(); msg.setCode("500"); msg.setMessage("导入发生错误"); return msg; } return msg; } }