|
@@ -0,0 +1,521 @@
|
|
|
+package com.qr.database.controller;
|
|
|
+
|
|
|
+import cn.afterturn.easypoi.entity.ImageEntity;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.qr.database.config.GlobalConstant;
|
|
|
+import com.qr.database.config.properties.GlobalProperties;
|
|
|
+import com.qr.database.model.Product;
|
|
|
+import com.qr.database.model.ProductDel;
|
|
|
+import com.qr.database.model.ProductExport;
|
|
|
+import com.qr.database.service.IFlowService;
|
|
|
+import com.qr.database.service.IProductService;
|
|
|
+import com.qr.database.service.IUnitService;
|
|
|
+import com.qr.database.tips.ReturnResult;
|
|
|
+import com.qr.database.utils.*;
|
|
|
+import com.qr.database.utils.qr.ImgQrTool;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping("/qr/product")
|
|
|
+public class ProductController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(ProductController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IProductService productService;
|
|
|
+ @Autowired
|
|
|
+ private IUnitService unitService;
|
|
|
+ @Autowired
|
|
|
+ private IFlowService flowService;
|
|
|
+ @Autowired
|
|
|
+ private ExportExcelUtil exportExcelUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
+ @RequestMapping("/imports")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult imports(@NotNull(message = "上传文件不能为空") @RequestPart(value = "file", required = false) MultipartFile picture, @RequestAttribute("attrCompanyId") Long companyId) throws Exception {
|
|
|
+ List<Product> imports = ExcelUtil.imports(picture.getInputStream(), Product.class);
|
|
|
+ Iterator<Product> iterator = imports.iterator();
|
|
|
+ Date date = new Date();
|
|
|
+ int ok = 0;
|
|
|
+ int fall = 0;
|
|
|
+ LinkedList<Product> standards = new LinkedList<>();
|
|
|
+ LinkedList<Long> okList = new LinkedList<>();
|
|
|
+ String uuid = CommonUtil.getUUID();
|
|
|
+ HashMap<String, Object> stringIntegerHashMap = new HashMap<>();
|
|
|
+ Map<String, String> list = unitService.flagAndUnitCode();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Product next = iterator.next();
|
|
|
+ next.setStatus(1);
|
|
|
+ next.setCreateTime(date);
|
|
|
+ next.setCompanyId(companyId);
|
|
|
+ boolean add = productService.add(next, list);
|
|
|
+ if (add) {
|
|
|
+ ok++;
|
|
|
+ okList.add(next.getId());
|
|
|
+ } else {
|
|
|
+ fall++;
|
|
|
+ standards.add(next);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ok >= 1) {
|
|
|
+ redisTemplate.opsForValue().set(GlobalConstant.OK_NEWS + uuid, okList, 8, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ if (fall >= 1) {
|
|
|
+ redisTemplate.opsForValue().set(GlobalConstant.FALL_NEWS + uuid, standards, 8, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ stringIntegerHashMap.put("ok", ok);
|
|
|
+ stringIntegerHashMap.put("fall", fall);
|
|
|
+ stringIntegerHashMap.put("id", uuid);
|
|
|
+ stringIntegerHashMap.put("flag", "product");
|
|
|
+ return ReturnResult.success(stringIntegerHashMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/fall/{id}")
|
|
|
+ public String export(@PathVariable("id") String id, ModelMap modelMap) {
|
|
|
+ Object o = redisTemplate.opsForValue().get(GlobalConstant.FALL_NEWS + id);
|
|
|
+ LinkedList<Product> list = null;
|
|
|
+ if (o != null) {
|
|
|
+ list = (LinkedList) o;
|
|
|
+ } else {
|
|
|
+ list = new LinkedList<>();
|
|
|
+ }
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
+ stringObjectHashMap.put("maplist", list);
|
|
|
+ return exportExcelUtil.export(modelMap, "product.xlsx", "产品导入出错数据", stringObjectHashMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/ok/{id}")
|
|
|
+ public void export(@PathVariable("id") String id, HttpServletResponse response) throws IOException {
|
|
|
+ Object o = redisTemplate.opsForValue().get(GlobalConstant.OK_NEWS + id);
|
|
|
+ List<Map<String, Object>> parms = new LinkedList<Map<String, Object>>();
|
|
|
+ if (o != null) {
|
|
|
+ List<Map<String, Object>> id1 = productService.listMaps(new QueryWrapper<Product>().select("BATCH_NO \"batchNo\"", "QR_DATA \"qrData\"").in("ID", (LinkedList) o));
|
|
|
+ for (Map<String, Object> map : id1) {
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
+ stringObjectHashMap.put("fileName", map.get("batchNo") + ".png");
|
|
|
+ stringObjectHashMap.put("data", ImgQrTool.Base64ToImage(String.valueOf(map.get("qrData"))));
|
|
|
+ parms.add(stringObjectHashMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String("产品二维码.zip".getBytes(), "iso-8859-1"));
|
|
|
+ ZipUtil.batchDataToZIP(parms, response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/deli")
|
|
|
+ public ModelAndView deli(@NotNull(message = "上传文件不能为空") @RequestPart(value = "file", required = false) MultipartFile picture, ModelAndView modelAndView) throws Exception {
|
|
|
+ List<ProductDel> imports = ExcelUtil.imports(picture.getInputStream(), ProductDel.class);
|
|
|
+ Iterator<ProductDel> iterator = imports.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ProductDel next = iterator.next();
|
|
|
+ if (StringUtils.isBlank(next.getBatchNo())) {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ modelAndView.setViewName("productImportDel");
|
|
|
+ modelAndView.addObject("param", imports);
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/exporti")
|
|
|
+ public ModelAndView exporti(@NotNull(message = "上传文件不能为空") @RequestPart(value = "file", required = false) MultipartFile picture, ModelAndView modelAndView) throws Exception {
|
|
|
+ List<ProductDel> imports = ExcelUtil.imports(picture.getInputStream(), ProductDel.class);
|
|
|
+ Iterator<ProductDel> iterator = imports.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ProductDel next = iterator.next();
|
|
|
+ if (StringUtils.isBlank(next.getBatchNo())) {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ modelAndView.setViewName("productImportExport");
|
|
|
+ modelAndView.addObject("param", imports);
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/del")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult del(@RequestParam("pDel") List<String> pDel, @RequestParam("delDoc") List<Integer> delDoc, @RequestParam("delType") Integer delType) {
|
|
|
+ List<Product> batch_no = productService.list(new QueryWrapper<Product>().in("BATCH_NO", pDel));
|
|
|
+ for (Product product : batch_no) {
|
|
|
+ productService.del(product, delDoc, delType);
|
|
|
+ }
|
|
|
+ return ReturnResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/exportAll")
|
|
|
+ public void exportAll(@RequestParam("batchNo") List<String> batchNo, @RequestParam("docType") List<Integer> docType, HttpServletResponse response) throws IOException {
|
|
|
+ List<ProductExport> list = productService.selectListByBatchNo(batchNo);
|
|
|
+ List<Map<String, Object>> parms = new LinkedList<>();
|
|
|
+ for (Integer d : docType) {
|
|
|
+ if (d == 1) {
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
+ stringObjectHashMap.put("maplist", list);
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ExportExcelUtil.export(stringObjectHashMap, "product.xlsx", baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品表格.xlsx");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ } else if (d == 2) {
|
|
|
+ List<Map<String, Object>> parms1 = new LinkedList<>();
|
|
|
+ for (ProductExport product : list) {
|
|
|
+ String surveyReport = product.getSurveyReport();
|
|
|
+ if (StringUtils.isNotBlank(surveyReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(surveyReport));
|
|
|
+ }
|
|
|
+ String outgoingReport = product.getOutgoingReport();
|
|
|
+ if (StringUtils.isNotBlank(outgoingReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(outgoingReport));
|
|
|
+ }
|
|
|
+ String intoPerReport = product.getIntoPerReport();
|
|
|
+ if (StringUtils.isNotBlank(intoPerReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(intoPerReport));
|
|
|
+ }
|
|
|
+ String intoSizeReport = product.getIntoSizeReport();
|
|
|
+ if (StringUtils.isNotBlank(intoSizeReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(intoSizeReport));
|
|
|
+ }
|
|
|
+ String thirdpartyPerReport = product.getThirdpartyPerReport();
|
|
|
+ if (StringUtils.isNotBlank(thirdpartyPerReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(thirdpartyPerReport));
|
|
|
+ }
|
|
|
+ String thirdpartySizeReport = product.getThirdpartySizeReport();
|
|
|
+ if (StringUtils.isNotBlank(thirdpartySizeReport)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(thirdpartySizeReport));
|
|
|
+ }
|
|
|
+ String certification = product.getCertification();
|
|
|
+ if (StringUtils.isNotBlank(certification)) {
|
|
|
+ parms1.add(ZipUtil.getZipMap(certification));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ZipUtil.batchFileToZIP(parms1, baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品文档.zip");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ } else if (d == 3) {
|
|
|
+ List<Map<String, Object>> parms1 = new LinkedList<>();
|
|
|
+ for (ProductExport product : list) {
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ Map<String, Object> map = BeanUtils.convert2Map(product);
|
|
|
+ ImageEntity image = new ImageEntity();
|
|
|
+ image.setHeight(150);
|
|
|
+ image.setWidth(120);
|
|
|
+ image.setData(ImgQrTool.Base64ToImage(String.valueOf(map.get("qrData"))));
|
|
|
+ image.setType(ImageEntity.Data);
|
|
|
+ map.put("qrDataImg", image);
|
|
|
+ String certification = product.getCertification();
|
|
|
+ map.put("certificationName", certification == null ? " " : certification.substring(11));
|
|
|
+ ExportExcelUtil.exportDocx(map, "sendVerification.docx", baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ stringObjectHashMap1.put("fileName", "送验单-" + product.getBatchMarking() + product.getBatchNo() + ".docx");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ parms1.add(stringObjectHashMap1);
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ZipUtil.batchDataToZIP(parms1, baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品送验单.zip");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ } else if (d == 4) {
|
|
|
+ List<Map<String, Object>> parms1 = new LinkedList<>();
|
|
|
+ for (ProductExport product : list) {
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ Map<String, Object> map = BeanUtils.convert2Map(product);
|
|
|
+ ImageEntity image = new ImageEntity();
|
|
|
+ image.setHeight(150);
|
|
|
+ image.setWidth(120);
|
|
|
+ image.setData(ImgQrTool.Base64ToImage(String.valueOf(map.get("qrData"))));
|
|
|
+ image.setType(ImageEntity.Data);
|
|
|
+ map.put("qrDataImg", image);
|
|
|
+ String certification = product.getCertification();
|
|
|
+ map.put("certificationName", certification == null ? " " : certification.substring(11));
|
|
|
+ ExportExcelUtil.exportDocx(map, "stockOut.docx", baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ stringObjectHashMap1.put("fileName", "出库单-" + product.getBatchMarking() + product.getBatchNo() + ".docx");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ parms1.add(stringObjectHashMap1);
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ZipUtil.batchDataToZIP(parms1, baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品出库单.zip");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ } else if (d == 5) {
|
|
|
+ List<Map<String, Object>> parms1 = new LinkedList<>();
|
|
|
+ for (ProductExport product : list) {
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ Map<String, Object> map = BeanUtils.convert2Map(product);
|
|
|
+ ImageEntity image = new ImageEntity();
|
|
|
+ image.setHeight(150);
|
|
|
+ image.setWidth(120);
|
|
|
+ image.setData(ImgQrTool.Base64ToImage(String.valueOf(map.get("qrData"))));
|
|
|
+ image.setType(ImageEntity.Data);
|
|
|
+ map.put("qrDataImg", image);
|
|
|
+ ExportExcelUtil.exportDocx(map, "godownEntry.docx", baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ stringObjectHashMap1.put("fileName", "入库单-" + product.getBatchMarking() + product.getBatchNo() + ".docx");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ parms1.add(stringObjectHashMap1);
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ZipUtil.batchDataToZIP(parms1, baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品入库单.zip");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ } else if (d == 6) {
|
|
|
+ List<Map<String, Object>> parms1 = new LinkedList<Map<String, Object>>();
|
|
|
+ for (ProductExport product : list) {
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
+ stringObjectHashMap.put("fileName", product.getBatchNo() + ".png");
|
|
|
+ stringObjectHashMap.put("data", ImgQrTool.Base64ToImage(String.valueOf(product.getQrData())));
|
|
|
+ parms1.add(stringObjectHashMap);
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ ZipUtil.batchDataToZIP(parms1, baos);
|
|
|
+ HashMap<String, Object> stringObjectHashMap1 = new HashMap<>();
|
|
|
+ parms.add(stringObjectHashMap1);
|
|
|
+ stringObjectHashMap1.put("fileName", "产品二维码.zip");
|
|
|
+ stringObjectHashMap1.put("data", baos.toByteArray());
|
|
|
+ baos.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String("产品数据.zip".getBytes(), "iso-8859-1"));
|
|
|
+ ZipUtil.batchDataToZIP(parms, response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/importDoc")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public ReturnResult importDoc(@NotNull(message = "上传文件不能为空") @RequestPart(value = "file", required = false) MultipartFile picture, @RequestAttribute("attrUserId") Long userId) throws Exception {
|
|
|
+ String fileName = picture.getOriginalFilename().substring(0, picture.getOriginalFilename().lastIndexOf("."));
|
|
|
+ String originalFilename = picture.getOriginalFilename();
|
|
|
+ if (originalFilename.startsWith("HGZ")) {
|
|
|
+ originalFilename = originalFilename.substring(4, originalFilename.lastIndexOf("-"));
|
|
|
+ } else {
|
|
|
+ originalFilename = originalFilename.substring(originalFilename.indexOf("-", 5) + 1, originalFilename.lastIndexOf("."));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(originalFilename)) {
|
|
|
+ String fileSavePath = GlobalProperties.getFileUploadPath() + "productDoc" + File.separator;
|
|
|
+ String upload = FileUtil.upload(picture, fileSavePath, picture.getOriginalFilename());
|
|
|
+ if (upload == null) {
|
|
|
+ return ReturnResult.fail(480, "文件上传失败");
|
|
|
+ }
|
|
|
+ String filePathName = "productDoc" + File.separator + picture.getOriginalFilename();
|
|
|
+ Product product = new Product();
|
|
|
+ Product batch_no1 = productService.getOne(new QueryWrapper<Product>().eq("BATCH_NO", originalFilename).eq("STATUS", 1));
|
|
|
+ int docType = 0;
|
|
|
+ if (Pattern.matches(GlobalConstant.SURVEY_REPORT_REGEX, fileName)) {
|
|
|
+ product.setSurveyReport(filePathName);
|
|
|
+ product.setSurveyReportUserId(userId);
|
|
|
+ product.setSurveyReportTime(new Date());
|
|
|
+ docType = 1;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.OUTGOING_REPORT_REGEX, fileName)) {
|
|
|
+ product.setOutgoingReport(filePathName);
|
|
|
+ product.setOutgoingReportUserId(userId);
|
|
|
+ product.setOutgoingReportTime(new Date());
|
|
|
+ docType = 2;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.THIRDPARTY_SIZE_REPORT_REGEX, fileName)) {
|
|
|
+ product.setThirdpartySizeReport(filePathName);
|
|
|
+ product.setThirdpartySizeReportUserId(userId);
|
|
|
+ product.setThirdpartySizeReportTime(new Date());
|
|
|
+ docType = 3;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.THIRDPARTY_PER_REPORT_REGEX, fileName)) {
|
|
|
+ product.setThirdpartyPerReport(filePathName);
|
|
|
+ product.setThirdpartyPerReportUserId(userId);
|
|
|
+ product.setThirdpartyPerReportTime(new Date());
|
|
|
+ docType = 4;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.INTO_SIZE_REPORT_REGEX, fileName)) {
|
|
|
+ product.setIntoSizeReport(filePathName);
|
|
|
+ product.setIntoSizeReportUserId(userId);
|
|
|
+ product.setIntoSizeReportTime(new Date());
|
|
|
+ docType = 5;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.INTO_PER_REPORT_REGEX, fileName)) {
|
|
|
+ product.setIntoPerReport(filePathName);
|
|
|
+ product.setIntoPerReportUserId(userId);
|
|
|
+ product.setIntoPerReportTime(new Date());
|
|
|
+ docType = 6;
|
|
|
+ } else if (Pattern.matches(GlobalConstant.CERTIFICATION, fileName)) {
|
|
|
+ product.setCertification(filePathName);
|
|
|
+ product.setCertificationUserId(userId);
|
|
|
+ product.setCertificationTime(new Date());
|
|
|
+ docType = 7;
|
|
|
+ } else {
|
|
|
+ FileUtil.deleteFile(filePathName);
|
|
|
+ return ReturnResult.fail("命名不正确");
|
|
|
+ }
|
|
|
+ boolean batch_no = product.update(new UpdateWrapper<Product>().eq("BATCH_NO", originalFilename).eq("STATUS", 1));
|
|
|
+ if (batch_no) {
|
|
|
+ productService.shenqianErrUpdate(originalFilename);
|
|
|
+ productService.delFile(batch_no1, Lists.newArrayList(docType));
|
|
|
+ return ReturnResult.success();
|
|
|
+ }
|
|
|
+ FileUtil.deleteFile(filePathName);
|
|
|
+ }
|
|
|
+ return ReturnResult.fail("批号不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 子合格证上传
|
|
|
+ *
|
|
|
+ * @param picture
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @RequestMapping("/importSubCertification")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public ReturnResult importSubCertification(@NotNull(message = "上传文件不能为空") @RequestPart(value = "file", required = false) MultipartFile picture, @RequestAttribute("attrUserId") Long userId) throws Exception {
|
|
|
+ String fileName = picture.getOriginalFilename().substring(0, picture.getOriginalFilename().lastIndexOf("."));
|
|
|
+ String originalFilename = picture.getOriginalFilename();
|
|
|
+ originalFilename = originalFilename.substring(4, originalFilename.lastIndexOf("-"));
|
|
|
+ Product product = new Product();
|
|
|
+ if (StringUtils.isNotBlank(originalFilename)) {
|
|
|
+ String fileSavePath = GlobalProperties.getFileUploadPath() + "productDoc" + File.separator + "sub" + File.separator;
|
|
|
+ String upload = FileUtil.upload(picture, fileSavePath, picture.getOriginalFilename());
|
|
|
+ if (upload == null) {
|
|
|
+ return ReturnResult.fail(480, "文件上传失败");
|
|
|
+ }
|
|
|
+ String filePathName = "productDoc" + File.separator + "sub" + File.separator + picture.getOriginalFilename();
|
|
|
+ if (Pattern.matches(GlobalConstant.CERTIFICATION, fileName)) {
|
|
|
+ product.setSubCertification(filePathName);
|
|
|
+ product.setSubCertificationUserId(userId);
|
|
|
+ product.setSubCertificationTime(new Date());
|
|
|
+ } else {
|
|
|
+ FileUtil.deleteFile(filePathName);
|
|
|
+ return ReturnResult.fail("命名不正确");
|
|
|
+ }
|
|
|
+ Product batch_no1 = productService.getOne(new QueryWrapper<Product>().eq("BATCH_NO", originalFilename).eq("STATUS", 1));
|
|
|
+ boolean batch_no = product.update(new UpdateWrapper<Product>().eq("BATCH_NO", originalFilename).eq("STATUS", 1));
|
|
|
+ if (batch_no) {
|
|
|
+ productService.shenqianErrUpdate(originalFilename);
|
|
|
+ productService.delFile(batch_no1, Lists.newArrayList(8));
|
|
|
+ return ReturnResult.success();
|
|
|
+ }
|
|
|
+ FileUtil.deleteFile(filePathName);
|
|
|
+ }
|
|
|
+ return ReturnResult.fail("批号不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/detail/{id}")
|
|
|
+ public ModelAndView detail(@PathVariable("id") String id, ModelAndView modelAndView) {
|
|
|
+ Product detail = productService.detail(id);
|
|
|
+ modelAndView.addObject("product", detail);
|
|
|
+ modelAndView.setViewName("productDetail");
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/saveData")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult saveData(Product detail) {
|
|
|
+ Long shipmentsAmount = detail.getShipmentsAmount();
|
|
|
+ if (shipmentsAmount != null) {
|
|
|
+ detail.setShipmentsAmount(detail.getProductionAmount() - shipmentsAmount);
|
|
|
+ }
|
|
|
+ detail.updateById();
|
|
|
+ return ReturnResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/preview/{id}/{docType}")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult preview(@PathVariable("id") String id, @PathVariable("docType") Integer docType) {
|
|
|
+ Product byId = productService.getById(id);
|
|
|
+ if (byId != null) {
|
|
|
+ String uuid = CommonUtil.getUUID();
|
|
|
+ ReturnResult returnResult = new ReturnResult(300, "1", uuid);
|
|
|
+ redisTemplate.opsForValue().set(uuid, returnResult, 10, TimeUnit.MINUTES);
|
|
|
+ PreviewUtil previewUtil = new PreviewUtil(uuid, byId, docType);
|
|
|
+ previewUtil.start();
|
|
|
+ return returnResult;
|
|
|
+ }
|
|
|
+ return ReturnResult.fail("数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/previewGet/{id}")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult previewGet(@PathVariable("id") String id) {
|
|
|
+ try {
|
|
|
+ Object o = redisTemplate.opsForValue().get(id);
|
|
|
+ if (o != null) {
|
|
|
+ return (ReturnResult) o;
|
|
|
+ }
|
|
|
+ return new ReturnResult(303, "");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn(e.getMessage(), e);
|
|
|
+ return new ReturnResult(400, "连接失败,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/previewDel/{id}")
|
|
|
+ @ResponseBody
|
|
|
+ public ReturnResult previewDel(@PathVariable("id") String id) {
|
|
|
+ redisTemplate.delete(id);
|
|
|
+ return ReturnResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 产品详情文件预览生成完成
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/previewFinish/{id}")
|
|
|
+ public ModelAndView previewFinish(@PathVariable("id") String id, ModelAndView modelAndView) {
|
|
|
+ modelAndView.addObject("param", redisTemplate.opsForValue().get(id));
|
|
|
+ modelAndView.setViewName("productDocPreview");
|
|
|
+ new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ redisTemplate.delete(id);
|
|
|
+ }
|
|
|
+ }.start();
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/startShenQian")
|
|
|
+ public ModelAndView startShenQian(ModelAndView modelAndView, @RequestParam("batchNos") List<String> batchNos) {
|
|
|
+ modelAndView.setViewName("productStartShenQian");
|
|
|
+ Map<String, Object> flowSelect = flowService.getFlowSelect(null);
|
|
|
+ modelAndView.addObject("param", batchNos);
|
|
|
+ modelAndView.addObject("flowSelect", flowSelect);
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+}
|