Kaynağa Gözat

Merge branch 'master' of http://47.100.37.243:10080/ZHOU/yunsu

# Conflicts:
#	cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java
5 yıl önce
ebeveyn
işleme
0ec0d2a4d4

+ 1 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/constant/Constant.java

@@ -32,6 +32,7 @@ public class Constant {
     public static final String PROJECT_PREFIX = "YMXM";//项目编号
     public static final String UPLOAD = "上传";//上传
     public static final String DOWNLOAD = "下载";//下载
+    public static final String APPROVAL = "审批";//审批
     public static final Integer UPDATE_AUTHORITY = 0;//修改权限
     public static final Integer DOWNLOAD_AUTHORITY = 1;//下载权限
     public static final Integer VIEW_AUTHORITY = 2;//浏览权限

+ 21 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldFileController.java

@@ -183,5 +183,26 @@ public class MouldFileController {
         }
         return msg;
     }
+
+    /**
+     * 文档下载日志的excel导出
+     * 参数:startTime 开始时间,endTime 结束时间,mouldId 模具id
+     *
+     * @return
+     */
+    @ApiOperation("文档下载日志的excel导出")
+    @RequestMapping(value = "/downloadFileListExcel",method = RequestMethod.POST)
+    @ResponseBody
+    public HttpRespMsg downloadFileListExcel(UserVO userVO, HttpServletResponse response){
+        HttpRespMsg msg = new HttpRespMsg();
+        try {
+            msg = mouldFileService.downloadFileListExcel(userVO,response);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return msg;
+    }
+
+
 }
 

+ 2 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/entity/vo/UserVO.java

@@ -29,6 +29,8 @@ public class UserVO extends User {
     private String ids;//模具ids
     private Integer partId;//零件id
     private List<Project> projects;
+    private String startTime;
+    private String endTime;
     /**
      * 图档类型0-2D,1-3D
      */

+ 1 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldFileService.java

@@ -30,4 +30,5 @@ public interface MouldFileService extends IService<MouldFile> {
     HttpRespMsg getListByUserAndProjectId(UserVO userVO, PageUtil page);
     HttpRespMsg dowloadFileList(UserVO userVO, HttpServletRequest request, HttpServletResponse response,String downloadPath,String path) throws IOException;
     HttpRespMsg addPartFile(UserVO userVO, String path, MultipartFile[] files);
+    HttpRespMsg downloadFileListExcel(UserVO userVO, HttpServletResponse response);
 }

+ 75 - 6
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldFileServiceImpl.java

@@ -10,10 +10,7 @@ import com.hssx.cloudmodel.entity.vo.UserVO;
 import com.hssx.cloudmodel.mapper.*;
 import com.hssx.cloudmodel.service.MouldFileService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.hssx.cloudmodel.util.FileUtil;
-import com.hssx.cloudmodel.util.HttpRespMsg;
-import com.hssx.cloudmodel.util.ListUtil;
-import com.hssx.cloudmodel.util.PageUtil;
+import com.hssx.cloudmodel.util.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -25,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -221,8 +219,6 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                             mould.setState(4+"");//4已报废状态
                             mouldMapper.updateById(mould);
                         }
-
-
                     } else {
                         mf.setState(1);
                     }
@@ -233,6 +229,17 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                 //添加审批记录
                 MouldOperationDynamics dynamics = new MouldOperationDynamics();
                 dynamics.setMouldId(oldData.getId());
+                dynamics.setBelongType(oldData.getBlongType());
+                dynamics.setFileId(oldData.getId());
+                if(null != oldData.getFileName2()){
+                    dynamics.setFileName(oldData.getFileName()+","+oldData.getFileName2());
+                }else{
+                    dynamics.setFileName(oldData.getFileName());
+                }
+                dynamics.setOperatorId(user.getId());
+                dynamics.setOperatorName(user.getUsername());
+                dynamics.setContent(Constant.APPROVAL);
+                mouldOperationDynamicsMapper.insert(dynamics);
             } else if (user.getSubordinateType() == 1) {
                 //生产方
                 if (isPass == 1) {
@@ -252,6 +259,20 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
                     mf.setState(-2);
                 }
                 mouldFileMapper.updateById(mf);
+                //添加审批记录
+                MouldOperationDynamics dynamics = new MouldOperationDynamics();
+                dynamics.setMouldId(oldData.getId());
+                dynamics.setBelongType(oldData.getBlongType());
+                dynamics.setFileId(oldData.getId());
+                if(null != oldData.getFileName2()){
+                    dynamics.setFileName(oldData.getFileName()+","+oldData.getFileName2());
+                }else{
+                    dynamics.setFileName(oldData.getFileName());
+                }
+                dynamics.setOperatorId(user.getId());
+                dynamics.setOperatorName(user.getUsername());
+                dynamics.setContent(Constant.APPROVAL);
+                mouldOperationDynamicsMapper.insert(dynamics);
             } else {
                 msg.setError("只有生产方和资产方才能审核, subordinteType = " + user.getSubordinateType() + ", 无效!");
             }
@@ -462,6 +483,54 @@ public class MouldFileServiceImpl extends ServiceImpl<MouldFileMapper, MouldFile
         return msg;
     }
 
+    @Override
+    public HttpRespMsg downloadFileListExcel(UserVO userVO, HttpServletResponse response) {
+        HttpRespMsg msg = new HttpRespMsg();
+        List<List<String>> list = new ArrayList<List<String>>();
+        //标题
+        List<String> titleList = new ArrayList<String>();
+        titleList.add("文件名");
+        titleList.add("下载者姓名");
+        titleList.add("文件类型");
+        titleList.add("下载时间");
+        list.add(titleList);
+        QueryWrapper<MouldOperationDynamics> qw = new QueryWrapper<MouldOperationDynamics>();
+        qw.eq("content",Constant.DOWNLOAD);
+        SimpleDateFormat dateSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        if(userVO.getStartTime() != null && userVO.getEndTime() != null){
+            qw.le("indate",userVO.getStartTime());
+            qw.ge("indate",userVO.getEndTime());
+        }
+        List<MouldOperationDynamics> mouldOperationDynamics = mouldOperationDynamicsMapper.selectList(qw);
+        for (MouldOperationDynamics dynamic : mouldOperationDynamics) {
+            List<String> rowList = new ArrayList<String>();
+            //文件名
+            rowList.add(dynamic.getFileName());
+            //操作者名字
+            rowList.add(dynamic.getOperatorName());
+            //文件类型
+            if(dynamic.getBelongType()==0){
+                rowList.add("模具文档");
+            }else if(dynamic.getBelongType()==1){
+                rowList.add("零件文档");
+            }else if(dynamic.getBelongType()==2){
+                rowList.add("试模验收");
+            }else if(dynamic.getBelongType()==3){
+                rowList.add("保养方案");
+            }else if(dynamic.getBelongType()==4){
+                rowList.add("模具更新");
+            }else if(dynamic.getBelongType()==5){
+                rowList.add("模具报废");
+            }
+            //下载时间
+            rowList.add(dateSdf.format(dynamic.getIndate()));
+        }
+        Mould mould = mouldMapper.selectById(userVO.getMouldId());
+        ExcelUtil.exportGeneralExcelByTitleAndList(response, mould.getModelNo()+mould.getModelName()+"-"+ dateSdf.format(new Date()), list);
+        msg.data = mould;
+        return msg;
+    }
+
 
     public Map<String, Object> feedBackDirectMultiDownload(HttpServletRequest request, HttpServletResponse response, String downloadPath, Mould vo, List<MouldFile> mouldFiles,String oldFilePath) throws IOException {
         //压缩文件初始设置

+ 143 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/util/ExcelUtil.java

@@ -0,0 +1,143 @@
+package com.hssx.cloudmodel.util;
+
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.util.List;
+
+public class ExcelUtil {
+    /**
+     * 简单Excel导出
+     * @param response
+     * @param title     标题
+     * @param list      数据
+     * @return
+     */
+    public static String exportGeneralExcelByTitleAndList(HttpServletResponse response, String title, List<List<String>> list) {
+        String result="系统提示:Excel文件导出成功!";
+        String fileName= title+".xls";
+        try {
+            response.reset();
+            response.setHeader("Content-disposition",
+                "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
+            //设置文件头编码格式
+            response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
+            response.setHeader("Cache-Control","no-cache");//设置头
+            response.setDateHeader("Expires", 0);//设置日期头
+            // 创建工作簿
+            HSSFWorkbook workBook = new HSSFWorkbook();
+            // 创建工作类
+            HSSFSheet sheet = workBook.createSheet();
+            sheet.setDefaultColumnWidth(16);
+            //设置字体样式
+            HSSFFont headFont = workBook.createFont();
+            headFont.setBold(true);
+            headFont.setFontHeightInPoints((short) 10);
+            headFont.setFontName("黑体");
+
+            HSSFFont titleFont = workBook.createFont();
+            titleFont.setBold(true);
+            titleFont.setFontHeightInPoints((short) 10);
+            titleFont.setFontName("黑体");
+
+            HSSFFont font = workBook.createFont();
+            font.setFontHeightInPoints((short) 10);
+            font.setFontName("宋体");
+
+            //设置单元格样式
+            CellStyle headStyle = workBook.createCellStyle();
+            headStyle.setFont(headFont);
+            headStyle.setAlignment(HorizontalAlignment.CENTER);
+            headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            headStyle.setWrapText(true);
+            headStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            headStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            headStyle.setBorderTop(BorderStyle.THIN);//上边框
+            headStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            String color = "c0c0c0";    //此处得到的color为16进制的字符串
+            //转为RGB码
+            int r = Integer.parseInt((color.substring(0,2)),16);   //转为16进制
+            int g = Integer.parseInt((color.substring(2,4)),16);
+            int b = Integer.parseInt((color.substring(4,6)),16);
+
+            //自定义cell颜色
+            HSSFPalette palette = workBook.getCustomPalette();
+            //这里的9是索引
+            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+
+            CellStyle titleStyle = workBook.createCellStyle();
+            titleStyle.setFont(titleFont);
+            titleStyle.setAlignment(HorizontalAlignment.CENTER);
+            titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);  //填充单元格
+            titleStyle.setFillForegroundColor((short)9);    //填色
+            titleStyle.setWrapText(true);
+            titleStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            titleStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            titleStyle.setBorderTop(BorderStyle.THIN);//上边框
+            titleStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            CellStyle cellStyle = workBook.createCellStyle();
+            cellStyle.setFont(font);
+            cellStyle.setAlignment(HorizontalAlignment.CENTER);
+            cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            cellStyle.setWrapText(true);
+            cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            cellStyle.setBorderTop(BorderStyle.THIN);//上边框
+            cellStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            if(list.size() > 0) {
+                //标题(如果需要在EXCEL内容最上面加标题,请打开下面的注释,修改start)
+                /*
+                HSSFRow titleRow = sheet.createRow(0);
+                titleRow.setHeightInPoints(30);
+                HSSFCell titleCell = titleRow.createCell(0);
+                titleCell.setCellStyle(headStyle);
+                titleCell.setCellValue(title);
+                //合并单元格
+                CellRangeAddress cellRangeAddress = new CellRangeAddress(0,0,0, list.get(0).size() - 1);
+                //加入合并单元格对象
+                sheet.addMergedRegion(cellRangeAddress);
+                //使用RegionUtil类为合并后的单元格添加边框
+			    RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress, sheet); // 下边框
+                RegionUtil.setBorderLeft(BorderStyle.THIN, cellRangeAddress, sheet); // 左边框
+                RegionUtil.setBorderRight(BorderStyle.THIN, cellRangeAddress, sheet); // 有边框
+                RegionUtil.setBorderTop(BorderStyle.THIN, cellRangeAddress, sheet); // 上边框
+                */
+                int start = 0;
+                for(List<String> rowList : list) {
+                    HSSFRow row = sheet.createRow(start);
+                    row.setHeightInPoints(24);
+                    for(int i = 0; i < rowList.size(); i++) {
+                        HSSFCell cell = row.createCell(i);
+                        if(start == 0) {
+                            cell.setCellStyle(titleStyle);
+                        }else {
+                            cell.setCellStyle(cellStyle);
+                        }
+                        cell.setCellValue(rowList.get(i));
+                    }
+                    start++;
+                }
+            }
+            OutputStream os = response.getOutputStream();
+            workBook.write(os);
+            os.flush();
+            os.close();
+        }catch(Exception e) {
+            System.out.println(result);
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+
+}