package com.newfiber.api.pc.controller.zhz; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.newfiber.api.config.FileVisitProperty; import com.newfiber.api.core.annotation.SysLog; import com.newfiber.api.core.commons.*; import com.newfiber.api.core.utils.ExportExcel; import com.newfiber.api.pc.model.entity.DiscussionInfo; import com.newfiber.api.pc.model.entity.DiscussionInfoDTO; import com.newfiber.api.pc.model.entity.DiscussionUser; import com.newfiber.api.pc.service.DiscussionInfoService; import com.newfiber.api.pc.service.DiscussionUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.*; /** * 会商实体类控制层 * @ClassName DiscussionInfoController * @Description TODO * @Author 张鸿志 * @Date 2021年6月3日17:50:03 17:50 * Version 1.0 **/ @RestController @RequestMapping("/discussioninfo") @Api(value = "DiscussionInfoController",tags = "会商实体类控制层") public class DiscussionInfoController { @Autowired private DiscussionInfoService discussionInfoService; @Autowired private DiscussionUserService discussionUserService; @Autowired private FileVisitProperty fileVisitProperty; @Value("${xnFile.pic}") private String filePic; @Value("${xnFile.path}") private String filePath; @PostMapping("/save") @ApiOperation("保存会商纪要") @SysLog(actionType = "1",value = "保存会商纪要") public ResultObj saveDiscussion( @Valid @RequestBody DiscussionInfo discussionInfo){ return new ResultObj(ResultCode.OK,discussionInfoService.saveDiscussion(discussionInfo)); } @PostMapping("/selectPage") @ApiOperation("分页查询会商记录") @SysLog(actionType = "4",value = "分页查询会商记录") public ResultObj<PageResultObject<DiscussionInfo>> selectPage(@RequestBody PageRequestObject<DiscussionInfoDTO> pageRequestObject){ return new ResultObj<>(ResultCode.OK,discussionInfoService.queryPage(pageRequestObject)); } @PostMapping("/update") @ApiOperation("修改会商记录") @SysLog(actionType = "3",value = "修改会商记录") public ResultObj updateDiscussion(@Valid @RequestBody DiscussionInfo discussionInfo){ return new ResultObj(ResultCode.OK,discussionInfoService.updateDiscussion(discussionInfo)); } @PostMapping("/delete") @ApiOperation("删除会商记录") @SysLog(actionType = "2",value = "删除会商记录") public ResultObj delete(@RequestParam Integer id){ if(StringUtils.isEmpty(id)){ throw new CustomException(ResultCode.PARAM_NULL); } if(discussionInfoService.deleteById(id)){ EntityWrapper<DiscussionUser> wrapper = new EntityWrapper(); wrapper.eq("discussion_info_id",id+""); if(discussionUserService.delete(wrapper)){ return ResultObj.ok("删除成功"); } } return ResultObj.error("删除失败!"); } @PostMapping(value = "/download", produces = "application/json;charset=utf-8") @SysLog(actionType = "4",value = "下载会商记录") public void download(HttpServletResponse response,@RequestBody DiscussionInfoDTO infoDTO, OutputStream out) throws IOException { response.setHeader("Access-Control-Allow-Origin", "*"); List<String> headers = new ArrayList<>(); headers.add("会商主题"); headers.add("会商形式"); headers.add("会商地点"); headers.add("会商类型"); headers.add("会商内容"); headers.add("会商分工"); try { List<DiscussionInfo> discussionInfos = discussionInfoService.queryData(infoDTO); List<List> result = new ArrayList<>(); for (DiscussionInfo discussionInfo : discussionInfos) { List<String> strs = new ArrayList<>(); strs.add(discussionInfo.getDiscussionTheme()); strs.add(discussionInfo.getDiscussionFromName()); strs.add(discussionInfo.getDiscussionAddr()); strs.add(discussionInfo.getDiscussionTypeName()); strs.add(discussionInfo.getDiscussionContent()); strs.add(discussionInfo.getDiscussionDivisionName()); result.add(strs); } ExportExcel excel = new ExportExcel(); excel.exportExcel3("防汛会商", headers, result, out, response,(new Date()).toString()); } catch (Exception e) { e.printStackTrace(); } } @PostMapping("/uploadFile") @ApiOperation("上传文件-返回文件路径") @SysLog(actionType = "1",value = "上传pdf文件-返回路径") public ResultObj<Map<String,Object>> addFile(@RequestParam("file") MultipartFile multipartFile) throws Exception{ String filename = multipartFile.getOriginalFilename(); String suffix = filename.substring(filename.lastIndexOf(".")); if(suffix.equalsIgnoreCase(".pdf")|suffix.equalsIgnoreCase(".doc")|suffix.equalsIgnoreCase(".docx")){ Calendar instance = Calendar.getInstance(); String yearMonth = instance.get(Calendar.YEAR) + File.separator +(instance.get(Calendar.MARCH) + 1) + File.separator; File file = new File(filePath +yearMonth , filename); if(!file.getParentFile().exists()){ file.getParentFile().mkdirs(); } try{ multipartFile.transferTo(file); }catch (IOException e){ e.printStackTrace(); } Map<String,Object> map = new HashMap<>(); map.put("filePath",yearMonth+filename); map.put("fileName",filename); map.put("realPath",fileVisitProperty.getWebFile()+yearMonth+filename); return new ResultObj(ResultCode.OK,map); }else{ return new ResultObj(500,"必须上传pdf文件!"); } } }