|
@@ -0,0 +1,552 @@
|
|
|
|
+package com.management.platform.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.management.platform.entity.*;
|
|
|
|
+import com.management.platform.mapper.SimpleFinanceMapper;
|
|
|
|
+import com.management.platform.mapper.SimpleProjectimeMapper;
|
|
|
|
+import com.management.platform.mapper.SimpleReportMapper;
|
|
|
|
+import com.management.platform.service.SimpleFinanceService;
|
|
|
|
+import com.management.platform.service.SimpleProjectimeService;
|
|
|
|
+import com.management.platform.service.SimpleReportService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import com.management.platform.util.UserNotFoundException;
|
|
|
|
+import org.apache.log4j.LogManager;
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author Seyason
|
|
|
|
+ * @since 2021-10-22
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@Transactional
|
|
|
|
+public class SimpleReportServiceImpl extends ServiceImpl<SimpleReportMapper, SimpleReport> implements SimpleReportService {
|
|
|
|
+ Logger logger = LogManager.getLogger(org.apache.logging.log4j.LogManager.ROOT_LOGGER_NAME);
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleFinanceService simpleFinanceService;
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleFinanceMapper simpleFinanceMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleReportMapper simpleReportMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleReportService simpleReportService;
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleProjectimeMapper simpleProjectimeMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ SimpleProjectimeService simpleProjectimeService;
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
|
+ private String path;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getByMonth(Integer companyId, String yearMonth) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<SimpleFinance> financeList = simpleFinanceMapper.selectList(new QueryWrapper<SimpleFinance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
|
+ msg.data = financeList;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg importData(Integer companyId, String yearMonth, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
|
+ //然后处理文件
|
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ OutputStream outputStream = null;
|
|
|
|
+ try {
|
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
|
+ int temp = 0;
|
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
|
+ }
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ //然后解析表格
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
|
+
|
|
|
|
+ //第二个表是员工薪资表
|
|
|
|
+
|
|
|
|
+ if (workbook.getNumberOfSheets() < 2) {
|
|
|
|
+ msg.setError("表格格式不正确,需要月度工时和月薪薪资两个sheet="+workbook.getNumberOfSheets());
|
|
|
|
+ } else {
|
|
|
|
+ //导入员工薪资表
|
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(1);
|
|
|
|
+ List<SimpleFinance> financeList = new ArrayList<SimpleFinance>();
|
|
|
|
+
|
|
|
|
+ //获取月成本列表
|
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String dateStr = yearMonth+"-01 00:00:00";
|
|
|
|
+ LocalDateTime startDate = LocalDateTime.parse(dateStr,df);
|
|
|
|
+ LocalDateTime endDate = LocalDateTime.parse(dateStr,df);
|
|
|
|
+ endDate = endDate.plusMonths(1);
|
|
|
|
+
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d");
|
|
|
|
+
|
|
|
|
+ //需要更新成本的人员数据
|
|
|
|
+ List<User> updateUserList = new ArrayList<>();
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
+ String startStr = yearMonth + "-01";
|
|
|
|
+ String endStr = yearMonth + "-31";
|
|
|
|
+ //获取人员该月份填写的日报的总时长
|
|
|
|
+ List<Map<String, Object>> userTimeList = null;
|
|
|
|
+
|
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
|
+
|
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
|
+ if (row == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //姓名 工资 奖金 津贴 养老保险 医疗保险 失业保险 住房公积金 其他
|
|
|
|
+ XSSFCell nameCell = row.getCell(0);
|
|
|
|
+ XSSFCell salaryCell = row.getCell(1);
|
|
|
|
+ XSSFCell bonusCell = row.getCell(2);
|
|
|
|
+ XSSFCell allowanceCell = row.getCell(3);
|
|
|
|
+ XSSFCell inOldCell = row.getCell(4);
|
|
|
|
+ XSSFCell inMedicalCell = row.getCell(5);
|
|
|
|
+ XSSFCell inJobCell = row.getCell(6);
|
|
|
|
+ XSSFCell houseFundCell = row.getCell(7);
|
|
|
|
+ XSSFCell otherCell = row.getCell(8);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
|
+ salaryCell.setCellType(CellType.STRING);
|
|
|
|
+ bonusCell.setCellType(CellType.STRING);
|
|
|
|
+ allowanceCell.setCellType(CellType.STRING);
|
|
|
|
+ inOldCell.setCellType(CellType.STRING);
|
|
|
|
+ inMedicalCell.setCellType(CellType.STRING);
|
|
|
|
+ inJobCell.setCellType(CellType.STRING);
|
|
|
|
+ houseFundCell.setCellType(CellType.STRING);
|
|
|
|
+ if (otherCell != null)otherCell.setCellType(CellType.STRING);
|
|
|
|
+
|
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
|
+ SimpleFinance finance = new SimpleFinance();
|
|
|
|
+ if (name.equals("姓名") && rowIndex == 0) {
|
|
|
|
+ //跳过第一行标题
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ finance.setCompanyId(companyId);
|
|
|
|
+ finance.setName(name);
|
|
|
|
+
|
|
|
|
+ BigDecimal total = new BigDecimal(0);
|
|
|
|
+ if (salaryCell != null) {
|
|
|
|
+ salaryCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = salaryCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setMonthCost(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (bonusCell != null) {
|
|
|
|
+ bonusCell.setCellType(CellType.STRING);
|
|
|
|
+ String bonusString = bonusCell.getStringCellValue();
|
|
|
|
+ BigDecimal bonus = bonusString != null ? new BigDecimal(bonusString.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setBonus(bonus);
|
|
|
|
+ total = total.add(bonus);
|
|
|
|
+ }
|
|
|
|
+ if (allowanceCell != null) {
|
|
|
|
+ allowanceCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = allowanceCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setAllowance(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ if (inJobCell != null) {
|
|
|
|
+ inJobCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = inJobCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setInsuranceLosejob(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ if (inMedicalCell != null) {
|
|
|
|
+ inMedicalCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = inMedicalCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setInsuranceMedical(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ if (inOldCell != null) {
|
|
|
|
+ inOldCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = inOldCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setInsuranceOld(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ if (houseFundCell != null) {
|
|
|
|
+ houseFundCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = houseFundCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setHouseFund(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ if (otherCell != null) {
|
|
|
|
+ otherCell.setCellType(CellType.STRING);
|
|
|
|
+ String item = otherCell.getStringCellValue();
|
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
|
+ finance.setOthers(value);
|
|
|
|
+ total = total.add(value);
|
|
|
|
+ }
|
|
|
|
+ finance.setTotalCost(total);
|
|
|
|
+
|
|
|
|
+ finance.setYmonth(yearMonth);
|
|
|
|
+ financeList.add(finance);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取日报列表
|
|
|
|
+ sheet = workbook.getSheetAt(0);
|
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
|
+ rowNum = sheet.getLastRowNum();
|
|
|
|
+ List<String> projectList = new ArrayList<>();
|
|
|
|
+ List<SimpleReport> reportList = new ArrayList<>();
|
|
|
|
+ int projectNameStartIndex = 4;
|
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
|
+ if (row == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (rowIndex == 0) {
|
|
|
|
+ //第一行是标题,获取项目名称
|
|
|
|
+ int pIndex = projectNameStartIndex;
|
|
|
|
+ while(pIndex < row.getLastCellNum() && row.getCell(pIndex).getCellTypeEnum() != CellType._NONE && row.getCell(pIndex).getCellTypeEnum() != CellType.BLANK) {
|
|
|
|
+ row.getCell(pIndex).setCellType(CellType.STRING);
|
|
|
|
+ String stringCellValue = row.getCell(pIndex).getStringCellValue();
|
|
|
|
+ projectList.add(stringCellValue);
|
|
|
|
+ pIndex++;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //数据行
|
|
|
|
+ for (int i=1;i<4+projectList.size(); i++) {
|
|
|
|
+ row.getCell(i).setCellType(CellType.STRING);
|
|
|
|
+ }
|
|
|
|
+ String reportDate = sdf.format(row.getCell(0).getDateCellValue());
|
|
|
|
+ String username = row.getCell(1).getStringCellValue();
|
|
|
|
+ String position = row.getCell(2).getStringCellValue();
|
|
|
|
+ String department = row.getCell(3).getStringCellValue();
|
|
|
|
+ List<SimpleProjectime> timeCostList = new ArrayList<SimpleProjectime>();
|
|
|
|
+ double totalTime = 0;
|
|
|
|
+ for (int i=4; i < 4 + projectList.size(); i++) {
|
|
|
|
+ String stringCellValue = row.getCell(i).getStringCellValue();
|
|
|
|
+ double time = 0;
|
|
|
|
+ if (!StringUtils.isEmpty(stringCellValue)) {
|
|
|
|
+ time = Double.parseDouble(stringCellValue);
|
|
|
|
+ totalTime += time;
|
|
|
|
+ SimpleProjectime item = new SimpleProjectime();
|
|
|
|
+ item.setProjectName(projectList.get(i-4));
|
|
|
|
+ item.setTimeCost(time);
|
|
|
|
+ timeCostList.add(item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ SimpleReport report = new SimpleReport();
|
|
|
|
+ report.setYmonth(yearMonth);
|
|
|
|
+ report.setUsername(username);
|
|
|
|
+ report.setCreatorId(token);
|
|
|
|
+ report.setCompanyId(companyId);
|
|
|
|
+ report.setDepartment(department);
|
|
|
|
+ report.setPosition(position);
|
|
|
|
+ report.setReportDate(LocalDate.parse(reportDate, DateTimeFormatter.ofPattern("yyyy/M/d")));
|
|
|
|
+ report.setTimeCost(totalTime);
|
|
|
|
+ //设置相关的项目时间表
|
|
|
|
+ report.setProjectimeList(timeCostList);
|
|
|
|
+ //添加到报告列表
|
|
|
|
+ reportList.add(report);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String[] notFoundNames = reportList.stream().filter(r->{
|
|
|
|
+ return !financeList.stream().filter(f->f.getName().equals(r.getUsername())).findAny().isPresent();
|
|
|
|
+ }).map(SimpleReport::getUsername).collect(Collectors.toList()).toArray(new String[0]);
|
|
|
|
+ if (notFoundNames.length > 0) {
|
|
|
|
+ msg.setError(convertNameArray(notFoundNames)+" 不存在于薪资表中,请检查后提交");
|
|
|
|
+ } else {
|
|
|
|
+ notFoundNames = financeList.stream().filter(r->{
|
|
|
|
+ return !reportList.stream().filter(f->f.getUsername().equals(r.getName())).findAny().isPresent();
|
|
|
|
+ }).map(SimpleFinance::getName).collect(Collectors.toList()).toArray(new String[0]);
|
|
|
|
+ if (notFoundNames.length > 0) {
|
|
|
|
+ msg.setError(convertNameArray(notFoundNames)+" 不存在于工时表中,请检查后提交");
|
|
|
|
+ } else {
|
|
|
|
+ //每个人的总工时不能为零
|
|
|
|
+ String[] names = reportList.stream().filter(r->r.getTimeCost() == 0).map(SimpleReport::getUsername).collect(Collectors.toList()).toArray(new String[0]);
|
|
|
|
+ if (names.length > 0) {
|
|
|
|
+ msg.setError(convertNameArray(names)+" 工时为零,请检查");
|
|
|
|
+ } else {
|
|
|
|
+ //人员检查通过,更新finance表中的时薪,方便后续计算
|
|
|
|
+ financeList.forEach(f->{
|
|
|
|
+ double userTotalTime = reportList.stream().filter(r->r.getUsername().equals(f.getName())).mapToDouble(SimpleReport::getTimeCost).sum();
|
|
|
|
+ f.setHourCost(f.getTotalCost().divide(new BigDecimal(userTotalTime), 2, BigDecimal.ROUND_UP));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ //批量插入
|
|
|
|
+ simpleFinanceService.remove(new QueryWrapper<SimpleFinance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
|
+ simpleFinanceService.saveBatch(financeList);
|
|
|
|
+ //插入工时报告表,先删除旧数据
|
|
|
|
+ QueryWrapper<SimpleReport> queryWrapper = new QueryWrapper<SimpleReport>().eq("company_id", companyId).eq("ymonth", yearMonth);
|
|
|
|
+ simpleReportMapper.delete(queryWrapper);
|
|
|
|
+ simpleReportService.saveBatch(reportList);
|
|
|
|
+ //再查询出来,进行项目工时存储
|
|
|
|
+ List<SimpleReport> queryList = simpleReportMapper.selectList(queryWrapper);
|
|
|
|
+ System.out.println("queryList size=="+queryList.size());
|
|
|
|
+ List<SimpleProjectime> allTimeList = new ArrayList<>();
|
|
|
|
+ reportList.forEach(r->{
|
|
|
|
+ Integer id = queryList.stream().filter(q -> q.getUsername().equals(r.getUsername())).findFirst().get().getId();
|
|
|
|
+ List<SimpleProjectime> timeList = r.getProjectimeList();
|
|
|
|
+ timeList.forEach(t->t.setSimpleId(id));
|
|
|
|
+ allTimeList.addAll(timeList);
|
|
|
|
+ });
|
|
|
|
+ simpleProjectimeService.saveBatch(allTimeList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("文件处理出错");
|
|
|
|
+ return msg;
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
|
+ return msg;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("发生其他错误");
|
|
|
|
+ return msg;
|
|
|
|
+ } finally {
|
|
|
|
+ //关闭流
|
|
|
|
+ try {
|
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
|
+ outputStream.close();
|
|
|
|
+ inputStream.close();
|
|
|
|
+ System.out.println("流已关闭");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+// file.deleteOnExit();//程序退出时删除临时文件
|
|
|
|
+ System.out.println(file.delete());
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg exportData(String yearMonth, Integer companyId, String type, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg timeCost = getTimeCost(yearMonth, companyId, type, request);
|
|
|
|
+ HashMap map = (HashMap)timeCost.data;
|
|
|
|
+ List<HashMap> costList = (List<HashMap>)map.get("costList");
|
|
|
|
+ List<List<String>> dataList = new ArrayList<>();
|
|
|
|
+ List<String> titleList = new ArrayList<>();
|
|
|
|
+ if ("按项目".equals(type)) {
|
|
|
|
+ titleList.add("项目");
|
|
|
|
+ } else if ("按岗位".equals(type)) {
|
|
|
|
+ titleList.add("岗位");
|
|
|
|
+ } else {
|
|
|
|
+ titleList.add("部门");
|
|
|
|
+ }
|
|
|
|
+ titleList.add("工时(h)");
|
|
|
|
+ titleList.add("成本(元)");
|
|
|
|
+ dataList.add(titleList);
|
|
|
|
+ //数据
|
|
|
|
+ double time = 0;
|
|
|
|
+ BigDecimal cost = new BigDecimal(0);
|
|
|
|
+ DecimalFormat df = new DecimalFormat("#.0");
|
|
|
|
+
|
|
|
|
+ for (HashMap item : costList) {
|
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
|
+ data.add((String)item.get("name"));
|
|
|
|
+ data.add(df.format((Double)item.get("workingTime")));
|
|
|
|
+ time += (double)item.get("workingTime");
|
|
|
|
+ BigDecimal costItem = (BigDecimal)item.get("cost");
|
|
|
|
+ costItem.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ data.add(costItem.toString());
|
|
|
|
+ cost = cost.add(costItem);
|
|
|
|
+ dataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ //合计
|
|
|
|
+ List<String> sumRow = new ArrayList<String>();
|
|
|
|
+ sumRow.add("合计");
|
|
|
|
+
|
|
|
|
+ sumRow.add(df.format(time));
|
|
|
|
+ cost.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ sumRow.add(cost.toString());
|
|
|
|
+
|
|
|
|
+ dataList.add(sumRow);
|
|
|
|
+ //生成excel文件导出
|
|
|
|
+ String fileName = yearMonth+"_"+type+"报表_"+System.currentTimeMillis();
|
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , dataList, path);
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ httpRespMsg.data = resp;
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getTimeCost(String yearMonth, Integer companyId, String type, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<SimpleReport> list = simpleReportService.list(new QueryWrapper<SimpleReport>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
|
+ if (list.size() == 0) {
|
|
|
|
+ HashMap map = new HashMap();
|
|
|
|
+ map.put("costList", new ArrayList<>());
|
|
|
|
+ map.put("totalMoneyCost", 0);
|
|
|
|
+ msg.data = map;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ List<Integer> collect = list.stream().map(SimpleReport::getId).collect(Collectors.toList());
|
|
|
|
+ List<SimpleProjectime> projectimeList = simpleProjectimeMapper.selectList(new QueryWrapper<SimpleProjectime>().in("simple_id", collect));
|
|
|
|
+ List<String> projectList = projectimeList.stream().map(SimpleProjectime::getProjectName).distinct().collect(Collectors.toList());
|
|
|
|
+ for (SimpleReport simpleReport : list) {
|
|
|
|
+ simpleReport.setProjectimeList(projectimeList.stream().filter(p->p.getSimpleId().equals(simpleReport.getId())).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ BigDecimal totalMoneyCost = new BigDecimal(0);
|
|
|
|
+ //按项目核算工时和成本
|
|
|
|
+ List<SimpleFinance> financeList = simpleFinanceMapper.selectList(new QueryWrapper<SimpleFinance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
|
+
|
|
|
|
+ int i=1;
|
|
|
|
+ List<HashMap> resultList = new ArrayList<>();
|
|
|
|
+ if ("按项目".equals(type)) {
|
|
|
|
+ //按项目分组
|
|
|
|
+ for (String name : projectList) {
|
|
|
|
+ HashMap<String, Object> item = new HashMap<>();
|
|
|
|
+ item.put("id", i);
|
|
|
|
+ item.put("name", name);
|
|
|
|
+ //工时
|
|
|
|
+ double workingTime = projectimeList.stream().filter(p->p.getProjectName().equals(name)).mapToDouble(SimpleProjectime::getTimeCost).sum();
|
|
|
|
+ item.put("workingTime", workingTime);
|
|
|
|
+ //成本
|
|
|
|
+ BigDecimal totalCost = new BigDecimal(0);
|
|
|
|
+ for (SimpleProjectime p : projectimeList) {
|
|
|
|
+ if (p.getProjectName().equals(name)) {
|
|
|
|
+ String username = list.stream().filter(report -> report.getId().equals(p.getSimpleId())).findFirst().get().getUsername();
|
|
|
|
+ BigDecimal hourCost = financeList.stream().filter(f -> f.getName().equals(username)).findFirst().get().getHourCost();
|
|
|
|
+ BigDecimal result = hourCost.multiply(new BigDecimal(p.getTimeCost()));
|
|
|
|
+ totalCost = totalCost.add(result);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ item.put("cost", totalCost);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(totalCost);
|
|
|
|
+ i++;
|
|
|
|
+ resultList.add(item);
|
|
|
|
+ }
|
|
|
|
+ } else if ("按岗位".equals(type)) {
|
|
|
|
+ //按岗位
|
|
|
|
+ List<String> posList = list.stream().map(SimpleReport::getPosition).distinct().collect(Collectors.toList());
|
|
|
|
+ for (String pos:posList) {
|
|
|
|
+ HashMap<String, Object> item = new HashMap<>();
|
|
|
|
+ item.put("id", i);
|
|
|
|
+ item.put("name", pos);
|
|
|
|
+ //工时
|
|
|
|
+ double workingTime = list.stream().filter(r->r.getPosition().equals(pos)).mapToDouble(SimpleReport::getTimeCost).sum();
|
|
|
|
+ item.put("workingTime", workingTime);
|
|
|
|
+ BigDecimal totalCost = new BigDecimal(0);
|
|
|
|
+ for (SimpleReport r : list) {
|
|
|
|
+ if (r.getPosition().equals(pos)) {
|
|
|
|
+ String username = r.getUsername();
|
|
|
|
+ BigDecimal hourCost = financeList.stream().filter(f -> f.getName().equals(username)).findFirst().get().getHourCost();
|
|
|
|
+ BigDecimal result = hourCost.multiply(new BigDecimal(r.getTimeCost()));
|
|
|
|
+ totalCost = totalCost.add(result);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ item.put("cost", totalCost);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(totalCost);
|
|
|
|
+ i++;
|
|
|
|
+ resultList.add(item);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //按部门
|
|
|
|
+ //按岗位
|
|
|
|
+ List<String> deptList = list.stream().map(SimpleReport::getDepartment).distinct().collect(Collectors.toList());
|
|
|
|
+ for (String dept:deptList) {
|
|
|
|
+ HashMap<String, Object> item = new HashMap<>();
|
|
|
|
+ item.put("id", i);
|
|
|
|
+ item.put("name", dept);
|
|
|
|
+ //工时
|
|
|
|
+ double workingTime = list.stream().filter(r->r.getDepartment().equals(dept)).mapToDouble(SimpleReport::getTimeCost).sum();
|
|
|
|
+ item.put("workingTime", workingTime);
|
|
|
|
+ BigDecimal totalCost = new BigDecimal(0);
|
|
|
|
+ for (SimpleReport r : list) {
|
|
|
|
+ if (r.getDepartment().equals(dept)) {
|
|
|
|
+ String username = r.getUsername();
|
|
|
|
+ BigDecimal hourCost = financeList.stream().filter(f -> f.getName().equals(username)).findFirst().get().getHourCost();
|
|
|
|
+ BigDecimal result = hourCost.multiply(new BigDecimal(r.getTimeCost()));
|
|
|
|
+ totalCost = totalCost.add(result);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ item.put("cost", totalCost);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(totalCost);
|
|
|
|
+ i++;
|
|
|
|
+ resultList.add(item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HashMap map = new HashMap();
|
|
|
|
+ map.put("costList", resultList);
|
|
|
|
+ map.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ msg.data = map;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getReportByMonth(Integer companyId, String yearMonth) {
|
|
|
|
+ List<SimpleReport> list = simpleReportService.list(new QueryWrapper<SimpleReport>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
|
+ List<String> projectList = new ArrayList<>();
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ List<Integer> collect = list.stream().map(SimpleReport::getId).collect(Collectors.toList());
|
|
|
|
+ List<SimpleProjectime> projectimeList = simpleProjectimeMapper.selectList(new QueryWrapper<SimpleProjectime>().in("simple_id", collect));
|
|
|
|
+ projectList = projectimeList.stream().map(SimpleProjectime::getProjectName).distinct().collect(Collectors.toList());
|
|
|
|
+ for (SimpleReport simpleReport : list) {
|
|
|
|
+ simpleReport.setProjectimeList(projectimeList.stream().filter(p->p.getSimpleId().equals(simpleReport.getId())).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HashMap map = new HashMap();
|
|
|
|
+ map.put("records", list);
|
|
|
|
+ map.put("projectList", projectList);
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.data = map;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String convertNameArray(String[] data) {
|
|
|
|
+ String s = "";
|
|
|
|
+ for (int i=0;i<data.length; i++) {
|
|
|
|
+ s += data[i];
|
|
|
|
+ if (i < data.length-1) {
|
|
|
|
+ s += ",";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return s;
|
|
|
|
+ }
|
|
|
|
+}
|