فهرست منبع

考勤报表导出加颜色。

zhengqiang 5 سال پیش
والد
کامیت
969d22d0c0
1فایلهای تغییر یافته به همراه32 افزوده شده و 19 حذف شده
  1. 32 19
      web/src/main/java/com/jpsoft/smart/modules/business/controller/WorkAttendanceController.java

+ 32 - 19
web/src/main/java/com/jpsoft/smart/modules/business/controller/WorkAttendanceController.java

@@ -14,12 +14,14 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.business.entity.WorkAttendance;
 import com.jpsoft.smart.modules.business.service.WorkAttendanceService;
 import com.jpsoft.smart.schduled.UnmeasureTemperatureAlarmTask;
+import com.sun.corba.se.spi.orbutil.threadpool.Work;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 import org.joda.time.DateTime;
@@ -308,8 +310,8 @@ public class WorkAttendanceController {
     @RequestMapping(value = "exportXls",method = RequestMethod.POST)
     @ApiImplicitParams({
             @ApiImplicitParam(name="companyId",value = "单位编号",required = true,paramType = "form"),
-            @ApiImplicitParam(name="name",value = "用户姓名",required = true,paramType = "form"),
-            @ApiImplicitParam(name="jobNumber",value = "工号",required = true,paramType = "form"),
+            @ApiImplicitParam(name="name",value = "用户姓名",required = false,paramType = "form"),
+            @ApiImplicitParam(name="jobNumber",value = "工号",required = false,paramType = "form"),
             @ApiImplicitParam(name = "startDate",value = "开始时间", required = true,paramType="form"),
             @ApiImplicitParam(name = "endDate",value = "截止时间", required = true,paramType="form"),
             @ApiImplicitParam(name = "subject",value = "subject", required = false,paramType="form")
@@ -360,7 +362,13 @@ public class WorkAttendanceController {
             int startRowIndex = 3;
 
             Font redFont = wb.createFont();
-            redFont.setColor(Font.COLOR_RED);
+            redFont.setColor(IndexedColors.RED.index);
+
+            Font greenFont = wb.createFont();
+            greenFont.setColor(IndexedColors.GREEN.index);
+
+            Font greyFont = wb.createFont();
+            greyFont.setColor(IndexedColors.BLUE_GREY.index);
 
             for (int i = 0; i < personMapList.size(); i++) {
                 Row row = sheet.createRow(startRowIndex + i);
@@ -424,30 +432,34 @@ public class WorkAttendanceController {
                                 sb.append("下班");
                             }
 
-                            if (WorkAttendance.SUCCESS.equals(item.getResult())) {
-                                sb.append("打卡");
-                            } else if (WorkAttendance.LATE.equals(item.getResult())) {
-                                sb.append("迟到");
-                            } else if (WorkAttendance.LEAVE_EARLY.equals(item.getResult())) {
-                                sb.append("早退");
-                            }
+                            String status = item.getResult();
 
-                            Map<String, Integer> pos = null;
+                            Map<String, Object> pos = new HashMap<>();
 
-                            if (WorkAttendance.MISSING.equals(item.getResult())) {
-                                pos = new HashMap<>();
+                            if (WorkAttendance.MISSING.equals(status)) {
                                 pos.put("start", sb.length() - 2);
                                 sb.append("缺卡");
+                                pos.put("font", redFont);
+                            } else if (WorkAttendance.SUCCESS.equals(status)) {
+                                pos.put("start", sb.length() - 2);
+                                sb.append("打卡");
+                                pos.put("font", greenFont);
+                            } else if (WorkAttendance.LEAVE_EARLY.equals(status)) {
+                                pos.put("start", sb.length() - 2);
+                                sb.append("早退");
+                                pos.put("font", greyFont);
+                            } else if (WorkAttendance.LATE.equals(status)) {
+                                pos.put("start", sb.length() - 2);
+                                sb.append("迟到");
+                                pos.put("font", greyFont);
                             }
 
                             if (item.getRecordTime() != null) {
                                 sb.append(" " + sdf.format(item.getRecordTime()));
-
-                                if (pos != null) {
-                                    pos.put("end", sb.length());
-                                    posList.add(pos);
-                                }
                             }
+
+                            pos.put("end", sb.length());
+                            posList.add(pos);
                         }
 
                         HSSFRichTextString sText = new HSSFRichTextString(sb.toString());
@@ -455,8 +467,9 @@ public class WorkAttendanceController {
                         for (Map map : posList) {
                             int start = Integer.valueOf(map.get("start").toString());
                             int end = Integer.valueOf(map.get("end").toString());
+                            Font font = (Font)map.get("font");
 
-                            sText.applyFont(start, end, redFont);
+                            sText.applyFont(start, end, font);
                         }
 
                         row.createCell(dayStartColIndex + j).setCellValue(sText);