|
@@ -0,0 +1,529 @@
|
|
|
+package com.management.platform.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.service.FinanceImportService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.service.FinanceService;
|
|
|
+import com.management.platform.service.ReportService;
|
|
|
+import com.management.platform.service.UserService;
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.UserNotFoundException;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2022-03-22
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FinanceImportServiceImpl extends ServiceImpl<FinanceImportMapper, FinanceImport> implements FinanceImportService {
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private FinanceImportMapper financeImportMapper;
|
|
|
+ @Resource
|
|
|
+ private DepartmentMapper departmentMapper;
|
|
|
+ @Resource
|
|
|
+ private FinanceMapper financeMapper;
|
|
|
+ @Resource
|
|
|
+ private TimeTypeMapper timeTypeMapper;
|
|
|
+ @Resource
|
|
|
+ private FinanceTblcuscolMapper financeTblcuscolMapper;
|
|
|
+ @Resource
|
|
|
+ private ReportMapper reportMapper;
|
|
|
+ @Resource
|
|
|
+ private FinanceService financeService;
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+ @Resource
|
|
|
+ private ReportService reportService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public HttpRespMsg submitImport(Integer companyId, String yearMonth, Boolean syncUserCost, Boolean syncHistoryReport, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ //检查当月是否已经存在审核通过的
|
|
|
+ FinanceImport oldItem = financeImportMapper.selectOne(new QueryWrapper<FinanceImport>().eq("company_id", companyId).eq("ymonth", yearMonth).orderByDesc("indate").last("limit 1"));
|
|
|
+ if (oldItem != null) {
|
|
|
+ if (oldItem.getState() == 1) {
|
|
|
+ msg.setError(yearMonth+"月薪资已审核通过,无法上传。");
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ if (oldItem.getState() == 0) {
|
|
|
+ String[] fname = oldItem.getServerName().split("\\/");
|
|
|
+ File oldFile = new File(new File(path, fname[0]), fname[1]);
|
|
|
+ oldFile.delete();
|
|
|
+ financeImportMapper.deleteById(oldItem.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //然后处理文件
|
|
|
+ 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();
|
|
|
+ //然后解析表格, 进行数据格式校验
|
|
|
+ Workbook wb = WorkbookFactory.create(new FileInputStream(file));
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ //要插入的账号列表
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ List<Finance> financeList = new ArrayList<Finance>();
|
|
|
+ //需要更新成本的人员数据
|
|
|
+ List<User> updateUserList = new ArrayList<>();
|
|
|
+
|
|
|
+ String startStr = yearMonth + "-01";
|
|
|
+ String endStr = yearMonth + "-31";
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //姓名 工资 奖金 津贴 养老保险 医疗保险 失业保险 (新增工伤保险) 住房公积金 其他; 可能有自定义的项
|
|
|
+ Cell nameCell = row.getCell(0);
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ Finance finance = new Finance();
|
|
|
+
|
|
|
+ if (name.equals("姓名") && rowIndex == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ finance.setName(name);
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(name)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ finance.setUserId(first.get().getId());
|
|
|
+ //如果需要更新员工成本
|
|
|
+ if (syncUserCost || syncHistoryReport) {
|
|
|
+ //设置人员总id
|
|
|
+ User localUser = new User();
|
|
|
+ localUser.setId(finance.getUserId());
|
|
|
+ updateUserList.add(localUser);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("用户["+name+"]不存在,请在组织结构中添加该成员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ finance.setYmonth(yearMonth);
|
|
|
+ financeList.add(finance);
|
|
|
+ }
|
|
|
+ if (financeList.size() == 0) {
|
|
|
+ msg.setError("请填写数据再上传");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果有必要,更新该月份的日报相关的成本
|
|
|
+ if (syncHistoryReport) {
|
|
|
+ List<Report> reportList = reportMapper.selectSimpleTime(companyId, startStr, endStr);
|
|
|
+ if (reportList.size() > 0) {
|
|
|
+ for (Report r : reportList) {
|
|
|
+ Optional<User> first = updateUserList.stream().filter(u -> u.getId().equals(r.getCreatorId())).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ String notFillUser = userMapper.selectById(r.getCreatorId()).getName();
|
|
|
+ System.out.println("缺少[" + notFillUser + "]的薪资成本, 请修改数据重新上传");
|
|
|
+ throw new UserNotFoundException("缺少[" + notFillUser + "]的薪资成本, 请修改数据重新上传");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("文件处理出错");
|
|
|
+ return msg;
|
|
|
+ } catch (UserNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError(e.getMessage());
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存导入记录
|
|
|
+ String originName = fileName;
|
|
|
+ System.out.println("fileName=="+originName);
|
|
|
+ String[] names = originName.split("\\.");
|
|
|
+ String destFileName = names[0] + "_"+System.currentTimeMillis()+"."+names[1];
|
|
|
+ String financeFolder = "finance";
|
|
|
+ File dir = new File(path, financeFolder);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ File destFile = new File(dir, destFileName);
|
|
|
+ try {
|
|
|
+ multipartFile.transferTo(destFile);
|
|
|
+// FileUtils.copyFile(new File(multipartFile.getOriginalFilename()), destFile);
|
|
|
+ FinanceImport log = new FinanceImport();
|
|
|
+ log.setCompanyId(companyId);
|
|
|
+ log.setFileName(originName);
|
|
|
+ log.setServerName(financeFolder+"/"+destFileName);
|
|
|
+ log.setUserId(user.getId());
|
|
|
+ log.setUserName(user.getName());
|
|
|
+ log.setYmonth(yearMonth);
|
|
|
+ log.setRecoverMonthcost(syncUserCost?1:0);
|
|
|
+ log.setRecoverReport(syncHistoryReport?1:0);
|
|
|
+ financeImportMapper.insert(log);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ System.out.println("删除临时文件:"+file.delete());
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg list(Integer companyId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ List<FinanceImport> all = financeImportMapper.selectList(new QueryWrapper<FinanceImport>().eq("company_id", companyId).orderByDesc("indate"));
|
|
|
+ List<FinanceImport> pendingList = all.stream().filter(a->a.getState() == 0).collect(Collectors.toList());
|
|
|
+ List<FinanceImport> passList = all.stream().filter(a->a.getState() == 1).collect(Collectors.toList());
|
|
|
+ List<FinanceImport> rejectList = all.stream().filter(a->a.getState() == 2).collect(Collectors.toList());
|
|
|
+ List<FinanceImport> cancelList = all.stream().filter(a->a.getState() == -1).collect(Collectors.toList());
|
|
|
+ HashMap map = new HashMap();
|
|
|
+ map.put("pendingList", pendingList);
|
|
|
+ map.put("passList", passList);
|
|
|
+ map.put("rejectList", rejectList);
|
|
|
+ map.put("cancelList", cancelList);
|
|
|
+ msg.data = map;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public HttpRespMsg agree(Integer id, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ FinanceImport curItem = new FinanceImport();
|
|
|
+ curItem.setId(id);
|
|
|
+ curItem.setState(1);
|
|
|
+ User auditor = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ curItem.setAuditorId(auditor.getId());
|
|
|
+ curItem.setAuditorName(auditor.getName());
|
|
|
+
|
|
|
+ FinanceImport oldItem = financeImportMapper.selectById(id);
|
|
|
+ if (oldItem == null) {
|
|
|
+ msg.setError("该数据不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (oldItem.getState() == 0) {
|
|
|
+ //读取文件进行更新
|
|
|
+ oldItem.getServerName();
|
|
|
+ String[] fname = oldItem.getServerName().split("\\/");
|
|
|
+ File oldFile = new File(new File(path, fname[0]), fname[1]);
|
|
|
+ FinanceImport financeImport = oldItem;
|
|
|
+ //然后处理文件
|
|
|
+ try {
|
|
|
+ //然后解析表格
|
|
|
+ Workbook wb = WorkbookFactory.create(new FileInputStream(oldFile));
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ //要插入的账号列表
|
|
|
+ Integer companyId = financeImport.getCompanyId();
|
|
|
+ String yearMonth = financeImport.getYmonth();
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ List<Finance> financeList = new ArrayList<Finance>();
|
|
|
+ List<Finance> oldFinanceList = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ //获取月成本列表
|
|
|
+ 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);
|
|
|
+
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ BigDecimal monthHours = timeType.getMonthDays().multiply(new BigDecimal(timeType.getAllday()));
|
|
|
+
|
|
|
+ //需要更新成本的人员数据
|
|
|
+ List<User> updateUserList = new ArrayList<>();
|
|
|
+
|
|
|
+ String startStr = yearMonth + "-01";
|
|
|
+ String endStr = yearMonth + "-31";
|
|
|
+ //获取人员该月份填写的日报的总时长
|
|
|
+ List<Map<String, Object>> userTimeList = null;
|
|
|
+ if (financeImport.getRecoverMonthcost()==1 || financeImport.getRecoverReport()==1) {
|
|
|
+ userTimeList = reportMapper.getUserWorkingTimeByRange(companyId, startStr, endStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FinanceTblcuscol> cusColList = financeTblcuscolMapper.selectList(new QueryWrapper<FinanceTblcuscol>().eq("company_id", companyId));
|
|
|
+
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //姓名 工资 奖金 津贴 养老保险 医疗保险 失业保险 (新增工伤保险) 住房公积金 其他; 可能有自定义的项
|
|
|
+ Cell nameCell = row.getCell(0);
|
|
|
+ Cell salaryCell = row.getCell(1);
|
|
|
+ Cell bonusCell = row.getCell(2);
|
|
|
+ Cell allowanceCell = row.getCell(3);
|
|
|
+ Cell inOldCell = row.getCell(4);
|
|
|
+ Cell inMedicalCell = row.getCell(5);
|
|
|
+ Cell inJobCell = row.getCell(6);
|
|
|
+ Cell injuryCell = row.getCell(7);
|
|
|
+
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ Finance finance = new Finance();
|
|
|
+
|
|
|
+ if (name.equals("姓名") && rowIndex == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Cell houseFundCell = row.getCell(8);
|
|
|
+ Cell field1 = cusColList.size() > 0?row.getCell(9):null;
|
|
|
+ Cell field2 = cusColList.size() > 1?row.getCell(10):null;
|
|
|
+ Cell field3 = cusColList.size() > 2?row.getCell(11):null;
|
|
|
+
|
|
|
+ if (field1 != null)field1.setCellType(CellType.STRING);
|
|
|
+ if (field2 != null)field2.setCellType(CellType.STRING);
|
|
|
+ if (field3 != null)field3.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ finance.setCompanyId(companyId);
|
|
|
+ finance.setName(name);
|
|
|
+
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(name)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ finance.setUserId(first.get().getId());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //按姓名做匹配
|
|
|
+ Optional<Finance> matchItem = oldFinanceList.stream().filter(o -> o.getName().equals(finance.getName())).findFirst();
|
|
|
+ if (matchItem.isPresent()) {
|
|
|
+ finance.setId(matchItem.get().getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 (injuryCell != null) {
|
|
|
+ injuryCell.setCellType(CellType.STRING);
|
|
|
+ String item = injuryCell.getStringCellValue();
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
+ finance.setInsuranceInjury(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 (field1 != null) {
|
|
|
+ field1.setCellType(CellType.STRING);
|
|
|
+ String item = field1.getStringCellValue();
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
+ finance.setCustomField1(value);
|
|
|
+ total = total.add(value);
|
|
|
+ }
|
|
|
+ if (field2 != null) {
|
|
|
+ field2.setCellType(CellType.STRING);
|
|
|
+ String item = field2.getStringCellValue();
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
+ finance.setCustomField2(value);
|
|
|
+ total = total.add(value);
|
|
|
+ }
|
|
|
+ if (field3 != null) {
|
|
|
+ field3.setCellType(CellType.STRING);
|
|
|
+ String item = field3.getStringCellValue();
|
|
|
+ BigDecimal value = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
+ finance.setCustomField3(value);
|
|
|
+ total = total.add(value);
|
|
|
+ }
|
|
|
+ finance.setTotalCost(total);
|
|
|
+
|
|
|
+ //如果需要更新员工成本
|
|
|
+ if (financeImport.getRecoverMonthcost()==1 || financeImport.getRecoverReport()==1) {
|
|
|
+ //设置人员总成本,计算时薪
|
|
|
+ User localUser = new User();
|
|
|
+ localUser.setId(finance.getUserId());
|
|
|
+ localUser.setMonthCost(total);
|
|
|
+ for (int i=0;i<userTimeList.size(); i++) {
|
|
|
+ Map<String, Object> map = userTimeList.get(i);
|
|
|
+ if (map.get("creatorId").equals(finance.getUserId())) {
|
|
|
+ double time = (Double)map.get("workingTime");
|
|
|
+ localUser.setCost(total.divide(new BigDecimal(time), 6, BigDecimal.ROUND_HALF_UP));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateUserList.add(localUser);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("用户["+name+"]不存在,请在组织结构中添加该成员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ finance.setYmonth(yearMonth);
|
|
|
+ financeList.add(finance);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (financeList.size() == 0) {
|
|
|
+ msg.setError("请填写数据再上传");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ //批量插入
|
|
|
+ financeService.saveOrUpdateBatch(financeList);
|
|
|
+ if (financeImport.getRecoverMonthcost()==1) {
|
|
|
+ userService.updateBatchById(updateUserList);
|
|
|
+ }
|
|
|
+ //检查是否有删除的,需要删除掉
|
|
|
+ List<Integer> readyForDelete = new ArrayList<>();
|
|
|
+ oldFinanceList.forEach(old->{
|
|
|
+ boolean exists = false;
|
|
|
+ if (financeList.stream().filter(f->f.getName().equals(old.getName())).findAny().isPresent()) {
|
|
|
+ exists = true;
|
|
|
+ }
|
|
|
+ if (!exists) {
|
|
|
+ readyForDelete.add(old.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (readyForDelete.size() > 0) {
|
|
|
+ financeService.removeByIds(readyForDelete);
|
|
|
+ }
|
|
|
+ //如果有必要,更新该月份的日报相关的成本
|
|
|
+ if (financeImport.getRecoverReport()==1) {
|
|
|
+
|
|
|
+ List<Report> reportList = reportMapper.selectSimpleTime(companyId, startStr, endStr);
|
|
|
+ if (reportList.size() > 0) {
|
|
|
+ for (Report r : reportList) {
|
|
|
+ Optional<User> first = updateUserList.stream().filter(u -> u.getId().equals(r.getCreatorId())).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ String notFillUser = userMapper.selectById(r.getCreatorId()).getName();
|
|
|
+ System.out.println("缺少[" + notFillUser + "]的薪资成本, 请修改数据重新上传");
|
|
|
+ throw new UserNotFoundException("缺少[" + notFillUser + "]的薪资成本, 请修改数据重新上传");
|
|
|
+ }
|
|
|
+ BigDecimal hourCost = first.get().getCost();
|
|
|
+ r.setCost(hourCost.multiply(new BigDecimal(r.getWorkingTime())));
|
|
|
+ r.setCreatorId(null);
|
|
|
+ r.setWorkingTime(null);
|
|
|
+ }
|
|
|
+ //批量更新日报的成本
|
|
|
+ reportService.updateBatchById(reportList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ financeImportMapper.updateById(curItem);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("文件处理出错");
|
|
|
+ return msg;
|
|
|
+ } catch (UserNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError(e.getMessage());
|
|
|
+ return msg;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
+ return msg;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("发生其他错误");
|
|
|
+ return msg;
|
|
|
+ } finally {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError("只有待审核状态才可以操作");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|