|
@@ -10,10 +10,7 @@ import com.management.platform.entity.vo.DepartmentVO;
|
|
|
import com.management.platform.entity.vo.UserMonthWork;
|
|
|
import com.management.platform.entity.vo.WorktimeItem;
|
|
|
import com.management.platform.mapper.*;
|
|
|
-import com.management.platform.service.DepartmentService;
|
|
|
-import com.management.platform.service.ReportProfessionProgressService;
|
|
|
-import com.management.platform.service.ReportService;
|
|
|
-import com.management.platform.service.WxCorpInfoService;
|
|
|
+import com.management.platform.service.*;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.ListUtil;
|
|
@@ -23,7 +20,7 @@ import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
-import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
@@ -124,6 +121,8 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
private PpMembsMapper ppMembsMapper;
|
|
|
@Resource
|
|
|
private StagesMapper stagesMapper;
|
|
|
+ @Resource
|
|
|
+ private UserSalaryService userSalaryService;
|
|
|
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
@@ -1570,7 +1569,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg importData(Integer companyId, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg importData(Integer companyId,Integer withCheckIn, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String token = request.getHeader("TOKEN");
|
|
|
//然后处理文件
|
|
@@ -1589,24 +1588,23 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
|
//然后解析表格
|
|
|
- XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
|
|
|
|
|
|
- //导入员工薪资表
|
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/M/d");
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d");
|
|
|
//获取公司全部成员
|
|
|
List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
//由于第一行需要指明列对应的标题
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
List<String> projectList = new ArrayList<>();
|
|
|
List<Project> allProjectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
List<Report> reportList = new ArrayList<>();
|
|
|
- int projectNameStartIndex = 2;
|
|
|
+ int projectNameStartIndex = (withCheckIn==null?2:5);
|
|
|
|
|
|
for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
- XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
|
continue;
|
|
|
}
|
|
@@ -1636,10 +1634,10 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
} else {
|
|
|
//数据行
|
|
|
- for (int i=1;i<2+projectList.size(); i++) {
|
|
|
+ for (int i=1;i<projectNameStartIndex+projectList.size(); i++) {
|
|
|
row.getCell(i).setCellType(CellType.STRING);
|
|
|
}
|
|
|
- String reportDate = sdf.format(row.getCell(0).getDateCellValue());
|
|
|
+ String reportDate = withCheckIn == null?sdf.format(row.getCell(0).getDateCellValue()):row.getCell(0).getStringCellValue();
|
|
|
String username = row.getCell(1).getStringCellValue().trim();
|
|
|
//检查人员是否存在
|
|
|
Optional<User> any = allUserList.stream().filter(u -> u.getName().equals(username)).findAny();
|
|
@@ -1650,25 +1648,30 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
User reportCreator = any.get();
|
|
|
List<SimpleProjectime> timeCostList = new ArrayList<SimpleProjectime>();
|
|
|
double totalTime = 0;
|
|
|
- for (int i=2; i < 2 + projectList.size(); i++) {
|
|
|
+ for (int i=projectNameStartIndex; i < projectNameStartIndex + projectList.size(); i++) {
|
|
|
String stringCellValue = row.getCell(i).getStringCellValue();
|
|
|
double time = 0;
|
|
|
- String pName = projectList.get(i-2);
|
|
|
+ String pName = projectList.get(i-projectNameStartIndex);
|
|
|
Project project = allProjectList.stream().filter(p -> p.getProjectName().equals(pName)).findFirst().get();
|
|
|
|
|
|
if (!StringUtils.isEmpty(stringCellValue)) {
|
|
|
time = Double.parseDouble(stringCellValue);
|
|
|
- totalTime += time;
|
|
|
- Report report = new Report();
|
|
|
- report.setCompanyId(companyId);
|
|
|
- report.setCreatorId(reportCreator.getId());
|
|
|
- report.setProjectId(project.getId());
|
|
|
- report.setReportTimeType(1);
|
|
|
- report.setWorkingTime(time);
|
|
|
- report.setState(1);//导入的直接算审核通过
|
|
|
- report.setCreateDate(LocalDate.parse(reportDate, dtf));
|
|
|
- report.setCost(reportCreator.getCost().multiply(new BigDecimal(time)));
|
|
|
- reportList.add(report);
|
|
|
+ if (time > 0) {
|
|
|
+ totalTime += time;
|
|
|
+ Report report = new Report();
|
|
|
+ report.setCompanyId(companyId);
|
|
|
+ report.setCreatorId(reportCreator.getId());
|
|
|
+ report.setProjectId(project.getId());
|
|
|
+ report.setReportTimeType(1);
|
|
|
+ report.setWorkingTime(time);
|
|
|
+ report.setState(0);//导入的直接算审核通过
|
|
|
+ report.setCreateDate(LocalDate.parse(reportDate, dtf));
|
|
|
+ report.setCost(reportCreator.getCost().multiply(new BigDecimal(time)));
|
|
|
+ reportList.add(report);
|
|
|
+ } else if (time < 0) {
|
|
|
+ msg.setError(username + "的工时存在负数,请检查修改");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|
|
|
//检查个人总工时不能为0
|
|
|
if (totalTime == 0) {
|
|
@@ -1902,39 +1905,92 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg saveProjectTime(Integer companyId, List<Report> reportList) {
|
|
|
+ public HttpRespMsg saveProjectTime(Integer companyId, List<Report> reportList, JSONArray userReportArray) {
|
|
|
//如果当天该员工已有报告,要删除
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
if (reportList.size() > 0) {
|
|
|
for (Report report : reportList) {
|
|
|
- reportMapper.delete(new QueryWrapper<Report>().eq("create_date", report.getCreateDate()).eq("creator_id", report.getCreatorId()));
|
|
|
+ reportMapper.delete(new QueryWrapper<Report>()
|
|
|
+ .eq("create_date", report.getCreateDate())
|
|
|
+ .eq("creator_id", report.getCreatorId()));
|
|
|
}
|
|
|
|
|
|
-// //计算人员的成本
|
|
|
-// TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
-// for (Report report : reportList) {
|
|
|
-// //获取一下信息
|
|
|
-// if (report.getWorkingTime() <= 0.0) {
|
|
|
-// httpRespMsg.setError("工作时长必须大于零");
|
|
|
-// return httpRespMsg;
|
|
|
-// }
|
|
|
-// //检查是否存在计算加班工资的情况
|
|
|
-// if (!timeType.getPayOvertime()) {
|
|
|
-// //不能超过最多时间,超过的话,等比例核算
|
|
|
-// if (totalWorkTime > timeType.getAllday()) {
|
|
|
-// BigDecimal cost;
|
|
|
-// if (hourCost == null) {
|
|
|
-// cost = userList.stream().filter(u -> u.getId().equals(report.getCreatorId())).findFirst().get().getCost().multiply(new BigDecimal(timeType.getAllday()))
|
|
|
-// .multiply(new BigDecimal(report.getWorkingTime())).divide(new BigDecimal(totalWorkTime), RoundingMode.HALF_UP);
|
|
|
+ //计算人员的成本
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ for (int i=0;i<userReportArray.size(); i++) {
|
|
|
+ String userId = userReportArray.getJSONObject(i).getString("userId");
|
|
|
+ userIds.add(userId);
|
|
|
+ }
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", userIds));
|
|
|
+
|
|
|
+// for (User subsUser : userList) {
|
|
|
+// BigDecimal tempCost = new BigDecimal(0);
|
|
|
+// if (subsUser.getCostApplyDate() != null) {
|
|
|
+// //检查有效期
|
|
|
+// if (subsUser.getCostApplyDate().compareTo(dtf.format(now)) > 0) {
|
|
|
+// //取上一个历史成本
|
|
|
+// List<UserSalary> list = userSalaryService.list(new QueryWrapper<UserSalary>().eq("user_id", subsUser.getId()).orderByDesc("indate").last("limit 2"));
|
|
|
+// if (list.size() > 1) {
|
|
|
+// tempCost = list.get(1).getCost();
|
|
|
// } else {
|
|
|
-// cost = hourCost.multiply(new BigDecimal(timeType.getAllday()))
|
|
|
-// .multiply(new BigDecimal(report.getWorkingTime())).divide(new BigDecimal(totalWorkTime), RoundingMode.HALF_UP);
|
|
|
+// //没有记录,又没有达到预设的起效时间,则默认为0
|
|
|
+// tempCost = new BigDecimal(0);
|
|
|
// }
|
|
|
-// report.setCost(cost);
|
|
|
+// } else {
|
|
|
+// tempCost = subsUser.getCost();
|
|
|
// }
|
|
|
+// } else {
|
|
|
+// tempCost = subsUser.getCost();
|
|
|
// }
|
|
|
//
|
|
|
+// if (tempCost == null) {
|
|
|
+// tempCost = new BigDecimal(0);
|
|
|
+// }
|
|
|
+// //设置好时薪
|
|
|
+// subsUser.setCost(tempCost);
|
|
|
// }
|
|
|
+
|
|
|
+ for (Report report : reportList) {
|
|
|
+ //获取一下信息
|
|
|
+ if (report.getWorkingTime() <= 0.0) {
|
|
|
+ httpRespMsg.setError("工作时长必须大于零");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //获取员工当天总工作时长
|
|
|
+ JSONObject userDayReport = null;
|
|
|
+ for (int i=0;i<userReportArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = userReportArray.getJSONObject(i);
|
|
|
+ if (jsonObject.getString("createDate").equals(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(report.getCreateDate()))
|
|
|
+ && jsonObject.getString("userId").equals(report.getCreatorId())) {
|
|
|
+ userDayReport = jsonObject;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal hourCost = null;
|
|
|
+ double totalWorkTime = userDayReport.getDouble("totalFillTime");
|
|
|
+ //检查是否存在计算加班工资的情况
|
|
|
+ if (!timeType.getPayOvertime()) {
|
|
|
+ //不能超过最多时间,超过的话,等比例核算
|
|
|
+ if (totalWorkTime > timeType.getAllday()) {
|
|
|
+ BigDecimal cost;
|
|
|
+ if (hourCost == null) {
|
|
|
+ cost = userList.stream().filter(u -> u.getId().equals(report.getCreatorId())).findFirst().get().getCost().multiply(new BigDecimal(timeType.getAllday()))
|
|
|
+ .multiply(new BigDecimal(report.getWorkingTime())).divide(new BigDecimal(totalWorkTime), RoundingMode.HALF_UP);
|
|
|
+ } else {
|
|
|
+ cost = hourCost.multiply(new BigDecimal(timeType.getAllday()))
|
|
|
+ .multiply(new BigDecimal(report.getWorkingTime())).divide(new BigDecimal(totalWorkTime), RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ report.setCost(cost);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //直接时薪乘以小时
|
|
|
+ BigDecimal cost = userList.stream().filter(u -> u.getId().equals(report.getCreatorId())).findFirst().get().getCost()
|
|
|
+ .multiply(new BigDecimal(report.getWorkingTime()));
|
|
|
+ report.setCost(cost);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
reportService.saveBatch(reportList);
|
|
|
}
|
|
|
|