Min 1 år sedan
förälder
incheckning
56d1df54e4

+ 158 - 21
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -12,6 +12,15 @@ import com.management.platform.entity.vo.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.*;
 import com.management.platform.util.*;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFColor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -21,6 +30,8 @@ import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
@@ -4178,42 +4189,168 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
 
     @Override
     public HttpRespMsg exportPersonWorkHoursWorkTime(String deptId, String userId, String startDate, String endDate) {
-        HttpRespMsg msg=new HttpRespMsg();
         HttpRespMsg respMsg = getPersonWorkHoursWagesList(deptId, userId, startDate, endDate, -1, -1);
         Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
         HashMap resultMap= (HashMap) respMsg.data;
         List<User> mapList= (List<User>) resultMap.get("records");
         List<String> headerList= (List<String>) resultMap.get("header");
-        List<List<String>> dataList=new ArrayList<>();
-        List<String> titleList=new ArrayList<>();
-        titleList.add("部门名称");
-        titleList.add("人员");
-        titleList.addAll(headerList);
-        titleList.add("合计");
-        dataList.add(titleList);
+        Company company = companyMapper.selectById(companyId);
+        //1.创建一个workbook,对应一个excel文件
+        SXSSFWorkbook workBook = new SXSSFWorkbook();
+        //2.在workbook中添加一个sheet,对应Excel中的sheet
+        SXSSFSheet sheet = workBook.createSheet("人员工时工价表");
+        //设置每一列的列宽
+        sheet.setColumnWidth(0,256*15);
+        sheet.setColumnWidth(1,256*15);
+        //3.设置样式以及字体样式
+        //设置首行冻结
+        sheet.createFreezePane(0, 1);
+        sheet.setDefaultColumnWidth(16);
+        //设置字体样式
+        Font headFont = workBook.createFont();
+        headFont.setBold(true);
+        headFont.setFontHeightInPoints((short) 10);
+        headFont.setFontName("黑体");
+
+        Font titleFont = workBook.createFont();
+        titleFont.setBold(true);
+        titleFont.setFontHeightInPoints((short) 10);
+        titleFont.setFontName("黑体");
+
+        Font font = workBook.createFont();
+        font.setFontHeightInPoints((short) 10);
+        font.setFontName("宋体");
+
+        //设置单元格样式
+        XSSFCellStyle  headStyle = (XSSFCellStyle) 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);
+
+        //设置自定义颜色
+        XSSFColor xssfColor = new XSSFColor();
+        byte[] colorRgb = { (short)9, (byte) r, (byte) g, (byte) b };
+        xssfColor.setRGB(colorRgb);
+
+        headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
+        headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);// 填充模式(和背景颜色成对使用)
+        /*headStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());*/ //设置自带的颜色
+
+        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);//右边框
+        //行号
+        int rowNum = 0;
+        //第一行
+        SXSSFRow row0 = sheet.createRow(rowNum++);
+        row0.setHeight((short)500);
+        List<String> row_first =new ArrayList<>();
+        row_first.add("部门名称");
+        row_first.add("人员");
+        for(int i=0;i<headerList.size();i++){
+            if(i==0){
+                row_first.add(headerList.get(0));
+                continue;
+            }
+            row_first.add("");
+            row_first.add(headerList.get(i));
+        }
+        row_first.add("");
+        row_first.add("合计");
+        for (int i = 0; i < row_first.size(); i++) {
+            SXSSFCell tempCell = row0.createCell(i);
+            tempCell.setCellValue(row_first.get(i));
+            tempCell.setCellStyle(headStyle);
+        }
+        for(int i=1;i<=headerList.size();i++){
+            sheet.addMergedRegion(new CellRangeAddress(0, 0, 2+2*(i-1), 2+2*(i-1)+1));//日期
+        }
+        sheet.addMergedRegion(new CellRangeAddress(0,0,2+2*headerList.size(),2+2*headerList.size()+1));
+        List<String> list=new ArrayList<>();
         for (User user : mapList) {
-            List<String> itemMap=new ArrayList<>();
-            itemMap.add(user.getDepartmentCascade());
-            itemMap.add(user.getName());
+            list.add(user.getDepartmentCascade());
+            list.add(user.getName());
             for (String s : headerList) {
                 List<Map<String,Object>> itemList= user.getPersonWorkHoursWages();
                 Optional<Map<String, Object>> first = itemList.stream().filter(it -> it.get("crateDate").equals(s)).findFirst();
                 if(first.isPresent()){
                     BigDecimal bigDecimal=new BigDecimal(Double.valueOf(String.valueOf(first.get().get("workTime"))));
-//                    bigDecimal=bigDecimal.multiply(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    itemMap.add(bigDecimal.doubleValue()+"分钟" +first.get().get("cost")+"元");
+                    list.add(bigDecimal.doubleValue()+"分钟");
+                    list.add(first.get().get("cost")+"元");
                 }else {
-                    itemMap.add("");
+                    list.add("");
+                    list.add("");
                 }
             }
-            itemMap.add(user.getTotalResult());
-            dataList.add(itemMap);
+            list.add(user.getTotalResult().substring(0,user.getTotalResult().indexOf("分钟")+3));
+            list.add(user.getTotalResult().substring(user.getTotalResult().indexOf("分钟")+2));
         }
-        Company company = companyMapper.selectById(companyId);
-        String fileName=("人员工时工价表_")+company.getCompanyName()+System.currentTimeMillis();
-        String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName, dataList, path);
-        msg.setData(resp);
-        return msg;
+        int k=0;
+        for(int i = 0;i<mapList.size();i++){
+            SXSSFRow tempRow = sheet.createRow(rowNum++);
+            tempRow.setHeight((short)500);
+            for(int j=0;j<2+2*headerList.size()+2;j++){
+                SXSSFCell tempCell = tempRow.createCell(j);
+                String cellValue = "";
+                tempCell.setCellStyle(cellStyle);
+                if(k>=list.size()){
+                    continue;
+                }
+                cellValue=list.get(k);
+                tempCell.setCellValue(cellValue);
+                k++;
+            }
+        }
+
+        //导出excel
+        String result="系统提示:Excel文件导出成功!";
+        String title= "人员工时工价表_"+company.getCompanyName()+System.currentTimeMillis();
+        String fileName= title+".xlsx";
+        try {
+            File dir = null;
+            dir = new File(path);
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            FileOutputStream os = new FileOutputStream(path+fileName);//保存到本地
+            workBook.write(os);
+            os.flush();
+            os.close();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg.data ="/upload/"+fileName;
+        return httpRespMsg;
     }
 
     @Override

+ 4 - 4
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/ReportMapper.xml

@@ -155,7 +155,7 @@
     <select id="getPersonWorkHoursWagesDetail" resultType="java.util.Map">
         select r.cost,r.working_time,r.creator_id,ppt.total_progress as progress,DATE_FORMAT(r.create_date,'%Y%m%d') as createDate,pp.name as procedureName,(case  when pp.check_type=0 then '自检' when pp.check_type=1 then '互检' else '专检' end) as checkType,
         p.name as productName,DATE_FORMAT(plan.start_date,'%Y%m%d') as planStartDate,DATE_FORMAT(plan.end_date,'%Y%m%d') as planEndDate ,
-        plan.task_change_notice_num as taskName,plan.plan_type as planType,u.name as checkerName,u2.name as creatorName
+        plan.task_change_notice_num as taskName,plan.plan_type as planType,u.name as checkerName,u2.name as creatorName,plan.product_scheduling_num
         from report r
         left join prod_procedure pp on r.prod_procedure_id=pp.id
         left join plan_procedure_total ppt on ppt.prod_procedure_id=pp.id
@@ -261,7 +261,7 @@
                 and r.create_date between #{startDate} and #{endDate}
             </if>
             <if test="steelNum!=null and steelNum!=''">
-                JSON_CONTAINS(r.steel_num_array,CONCAT('"',#{steelNum},'"'))
+                and JSON_CONTAINS(r.steel_num_array,CONCAT('"',#{steelNum},'"'))
             </if>
         </where>
         order by r.create_date desc
@@ -331,7 +331,7 @@
             and b.foreman_id=#{foremanId}
         </if>
         <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
-            and (b.start_date &gt;= #{startDate} and b.end_date &lt;= #{endDate})
+            and b.start_date between #{startDate} and #{endDate}
         </if>
         <if test="list!=null and list.size()>0">
             and b.id in
@@ -368,7 +368,7 @@
             and b.foreman_id=#{foremanId}
         </if>
         <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
-            and (b.start_date &gt;= #{startDate} and b.end_date &lt;= #{endDate})
+            and b.start_date between #{startDate} and #{endDate}
         </if>
         group by b.id
         order by b.create_time desc ,a.id

+ 4 - 3
fhKeeper/formulahousekeeper/timesheet-workshop/src/views/statistic/index.vue

@@ -270,14 +270,15 @@
                 </template>
               </el-table-column>
               <el-table-column prop="productName" label="产品名称" width="180"></el-table-column>
+              <el-table-column prop="product_scheduling_num" label="排产工单号" width="180"></el-table-column>
               <el-table-column prop="procedureName" label="工序名称" width="180"></el-table-column>
-              <el-table-column prop="progress" label="进度" width="180">
+              <el-table-column prop="progress" label="进度" width="80">
                 <template slot-scope="scope">
                   {{scope.row.progress?scope.row.progress:0}}%
                 </template>
               </el-table-column>
-              <el-table-column prop="cost" label="工钱" width="180"></el-table-column>
-              <el-table-column prop="checkType" label="质检方式" width="180"></el-table-column>
+              <el-table-column prop="cost" label="工钱" width="80"></el-table-column>
+              <el-table-column prop="checkType" label="质检方式" width="80"></el-table-column>
               <el-table-column prop="checkerName" label="质检人" width="180"></el-table-column>
               <el-table-column prop="working_time" label="工作时长" width="180">
                 <template slot-scope="scope">