|
@@ -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
|