package com.hssx.cloudmodel.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.hssx.cloudmodel.entity.MouldFile; import com.hssx.cloudmodel.entity.ProjectFile; import com.hssx.cloudmodel.entity.User; import com.hssx.cloudmodel.entity.vo.UserVO; import com.hssx.cloudmodel.service.MouldFileService; import com.hssx.cloudmodel.service.MouldService; import com.hssx.cloudmodel.service.UserService; import com.hssx.cloudmodel.util.HttpRespMsg; import com.hssx.cloudmodel.util.PageUtil; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.URLEncoder; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** *
* 前端控制器 *
* * @author 吴涛涛 * @since 2019-08-07 */ @Controller @RequestMapping("/mouldfile") public class MouldFileController { @Value("${upload.path}") private String path; @Value("${download.path}") private String downloadPath; @Autowired private MouldFileService mouldFileService; @Autowired private UserService userService; /** * 模具文档的上传 * 参数: token 用户身份凭证, * mouldId 模具id , * belongType 文档类型(0-模具文档 1-零件文档 2-试模验收 3-保养方案 4-模具更新 5-模具报废), * 注:blongType 为 1 时需要多传 partId 零件id * belongType 为3 以下的file和dwgType参数均不需要传递 * file 文件信息,dwgType 图档类型0-2D,1-3D(上传零件文档和模具文档时传该参数) * * @return */ @ApiOperation("模具文档的上传") @RequestMapping("/uploadFile") @ResponseBody public HttpRespMsg uploadFile(@RequestParam(required = false) MultipartFile file, @RequestParam(required = false) MultipartFile file2, @RequestParam(required = false) Integer belongType, HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception { // System.out.println("开始上传文件" + "file+" + file.getOriginalFilename()); System.out.println("belongType" + belongType); if (null == belongType) { belongType = 0; } HttpRespMsg msg = new HttpRespMsg(); msg = mouldFileService.addFile(userVO, belongType, file, file2, path); return msg; } /** * 模具更新前的检查操作 * 参数: token 用户身份凭证, * mouldId 模具id , * * @return */ @ApiOperation("模具更新前的检查操作") @RequestMapping("/mouldUpdateCheck") @ResponseBody public HttpRespMsg mouldUpdateCheck(UserVO userVO) { HttpRespMsg msg = new HttpRespMsg(); msg = mouldFileService.mouldUpdateCheck(userVO); return msg; } /** * 零件文档的批量上传(文件命名规则:零件编号+2D/3D 如 LJ001+2D.dwg) * 参数: token 用户身份凭证, * mouldId 模具id ,files 多文件数组 * * @return */ @ApiOperation("零件文档的批量上传") @RequestMapping("/uploadPartFileList") @ResponseBody public HttpRespMsg uploadFile(@RequestParam("file") MultipartFile[] files, UserVO userVO) throws Exception { HttpRespMsg msg = new HttpRespMsg(); msg = mouldFileService.addPartFile(userVO, path, files); return msg; } @ApiOperation("模具文档的审核") @RequestMapping("/check") @ResponseBody public HttpRespMsg check(@RequestParam Integer mouldFileId, @RequestParam Integer isPass, HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception { HttpRespMsg msg = new HttpRespMsg(); msg = mouldFileService.check(mouldFileId, isPass, userVO); return msg; } /** * 模具文档的列表 * 参数: token 用户身份凭证,mouldId 模具id, type文档类型:0-模具文档,1-零件文档 * * @return */ @ApiOperation("模具文档的列表") @RequestMapping("/list") @ResponseBody public HttpRespMsg list(@RequestParam Integer mouldId, @RequestParam Integer blongType, UserVO userVO) { HttpRespMsg msg = mouldFileService.getFileList(mouldId, blongType, userVO); return msg; } /** * 模具文档的列表 * 参数: token 用户身份凭证,mouldId 模具id, type文档类型:0-模具文档,1-零件文档 * * @return */ @ApiOperation("模具所有类型的文档列表") @RequestMapping("/allList") @ResponseBody public HttpRespMsg allList(@RequestParam Integer mouldId, UserVO userVO) { HttpRespMsg msg = mouldFileService.getAllFileList(mouldId, userVO); return msg; } /** * 模具文档的下载 * 参数: token 用户身份凭证,id 项目id * * @return */ @ApiOperation("模具所有类型文档的下载") @RequestMapping("/dowloadFile") @ResponseBody public HttpRespMsg dowloadFile(MouldFile mouldFile, String token) { HttpRespMsg msg = mouldFileService.dowloadFile(mouldFile, token); return msg; } /** * 模具文档的删除 * 参数: id 文档id * * @return */ @ApiOperation("项目文档的删除") @RequestMapping("/delFile") @ResponseBody public HttpRespMsg delFile(MouldFile mouldFile) { HttpRespMsg msg = mouldFileService.delFile(mouldFile); return msg; } /** * 文档批量下载列表 * 参数: token 用户身份凭证,pageSize ,pageNum,keyName(筛选搜索关键词) * * @return */ @ApiOperation("文档批量下载列表") @RequestMapping("/fileList") @ResponseBody public HttpRespMsg fileList(UserVO userVO, PageUtil page) { HttpRespMsg msg = new HttpRespMsg(); msg = mouldFileService.getListByUserAndProjectId(userVO, page); return msg; } /** * 文档勾选批量下载 * 参数: ids 模具ids 如“1,2,3” * * @return */ @ApiOperation("文档勾选批量下载") @RequestMapping(value = "/downloadfileList", method = RequestMethod.POST) @ResponseBody public HttpRespMsg downloadfileList(UserVO userVO, HttpServletRequest request, HttpServletResponse response) { HttpRespMsg msg = new HttpRespMsg(); try { msg = mouldFileService.dowloadFileList(userVO, request, response, downloadPath, path); } catch (IOException e) { e.printStackTrace(); } return msg; } /** * 文档下载日志的excel导出 * 参数:startTime 开始时间,endTime 结束时间,mouldId 模具id * * @return */ @ApiOperation("文档下载日志的excel导出") @RequestMapping(value = "/downloadFileListExcel") @ResponseBody public HttpRespMsg downloadFileListExcel(UserVO userVO, HttpServletResponse response) { HttpRespMsg msg = new HttpRespMsg(); try { msg = mouldFileService.downloadFileListExcel(userVO, response,downloadPath); } catch (Exception e) { e.printStackTrace(); } return msg; } }