|
@@ -279,20 +279,25 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
List<Integer> ids = null;
|
|
|
if (deptId != null) {
|
|
|
- //找到该部门的所有子部门
|
|
|
- List<Department> allDepts = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- Optional<Department> first = allDepts.stream().filter(d -> d.getDepartmentId().equals(deptId)).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- Department department = first.get();
|
|
|
- //递归获取全部子部门
|
|
|
- List<Department> deptList = getSubDepts(department, allDepts);
|
|
|
- deptList.add(department);
|
|
|
- ids = deptList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ if (deptId == 0) {
|
|
|
+ //未分配的情况
|
|
|
+ ids = new ArrayList<>();
|
|
|
+ ids.add(0);
|
|
|
+ } else {
|
|
|
+ //找到该部门的所有子部门
|
|
|
+ List<Department> allDepts = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ Optional<Department> first = allDepts.stream().filter(d -> d.getDepartmentId().equals(deptId)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Department department = first.get();
|
|
|
+ //递归获取全部子部门
|
|
|
+ List<Department> deptList = getSubDepts(department, allDepts);
|
|
|
+ deptList.add(department);
|
|
|
+ ids = deptList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
nameList = reportMapper.getReportNameByDateAndDept(date,
|
|
|
ids, targetUid, companyId);
|
|
|
-
|
|
|
if (nameList.size() > 0) {
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
nameList.forEach(n->{
|
|
@@ -520,69 +525,43 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
@Override
|
|
|
public HttpRespMsg editReport(List<Report> reportList, String date, List<User> userList, BigDecimal hourCost, Integer companyId) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
- List<Integer> idList = new ArrayList<>();
|
|
|
-
|
|
|
TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
double totalWorkTime = 0;
|
|
|
for (Report report : reportList) {
|
|
|
totalWorkTime +=report.getWorkingTime();
|
|
|
}
|
|
|
- for (Report report : reportList) {
|
|
|
- //获取一下信息
|
|
|
- if (report.getWorkingTime() <= 0.0) {
|
|
|
- httpRespMsg.setError("工作时长必须大于零");
|
|
|
- return httpRespMsg;
|
|
|
+
|
|
|
+ //删除不在本次更新名单中的老记录
|
|
|
+ if (date != null && !date.contains("@")) {
|
|
|
+ //取到已有记录的id集合
|
|
|
+ List<Integer> idList = reportList.stream().filter(r->r.getId() != null).map(Report::getId).collect(Collectors.toList());
|
|
|
+ if (idList.size() > 0) {
|
|
|
+ reportMapper.delete(new QueryWrapper<Report>()
|
|
|
+ .eq("create_date", date)
|
|
|
+ .eq("creator_id", reportList.get(0).getCreatorId())
|
|
|
+ .notIn("id", idList));
|
|
|
}
|
|
|
- if (report.getId() == null) {
|
|
|
- //检查是否存在计算加班工资的情况
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- if (reportMapper.insert(report) == 0) {
|
|
|
- httpRespMsg.setError("操作失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- //只操作没有审核通过的
|
|
|
- if (reportMapper.selectById(report.getId()).getState() != 1) {
|
|
|
- //检查是否存在计算加班工资的情况
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- if (reportMapper.updateById(report) == 0) {
|
|
|
- httpRespMsg.setError("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Report report : reportList) {
|
|
|
+ //检查是否存在计算加班工资的情况,,重新计算当日薪酬
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
- idList.add(report.getId());
|
|
|
- }
|
|
|
- if (idList.size() > 0 && date != null && !date.contains("@")) {
|
|
|
- reportMapper.delete(new QueryWrapper<Report>()
|
|
|
- .eq("create_date", date)
|
|
|
- .eq("creator_id", reportList.get(0).getCreatorId())
|
|
|
- .notIn("id", idList));
|
|
|
}
|
|
|
+ //批量新增或更新
|
|
|
+ reportService.saveOrUpdateBatch(reportList);
|
|
|
|
|
|
int enginerring = companyMapper.selectById(companyId).getPackageEngineering();
|
|
|
if (enginerring == 1) {
|
|
@@ -613,7 +592,6 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
|
|
|
//异步下载图片
|
|
|
-
|
|
|
loadPicFromCorpWXServer(companyId, reportList);
|
|
|
|
|
|
return httpRespMsg;
|
|
@@ -1990,14 +1968,21 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
row.getCell(i).setCellType(CellType.STRING);
|
|
|
}
|
|
|
|
|
|
+ if (row.getCell(0) == null) {
|
|
|
+ msg.setError("第"+dataCount+"行缺少日期");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
boolean isDateFormat = row.getCell(0).getCellTypeEnum() == CellType.NUMERIC;
|
|
|
String reportDate = isDateFormat?sdf.format(row.getCell(0).getDateCellValue()):row.getCell(0).getStringCellValue();
|
|
|
-
|
|
|
+ if (StringUtils.isEmpty(reportDate)) {
|
|
|
+ msg.setError("第"+dataCount+"行缺少日期");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
String username = withCheckIn==null?row.getCell(1).getStringCellValue().trim():row.getCell(2).getStringCellValue().trim();
|
|
|
//检查人员是否存在
|
|
|
Optional<User> any = allUserList.stream().filter(u -> u.getName().equals(username)).findAny();
|
|
|
if (!any.isPresent()) {
|
|
|
- msg.setError("人员["+username+"]不存在,请先在组织结构中添加或者通过企业微信/钉钉同步导入");
|
|
|
+ msg.setError("人员["+username+"]不存在,请先在组织结构中添加或者通过钉钉同步导入");
|
|
|
return msg;
|
|
|
}
|
|
|
User reportCreator = any.get();
|
|
@@ -2051,9 +2036,12 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //先删除老数据
|
|
|
+ //先删除老数据, 修改为批处理
|
|
|
for (Report r : reportList) {
|
|
|
- reportMapper.delete(new QueryWrapper<Report>().eq("company_id", companyId).eq("creator_id", r.getCreatorId()).eq("create_date", r.getCreateDate()));
|
|
|
+ reportMapper.delete(new QueryWrapper<Report>()
|
|
|
+ .eq("company_id", companyId)
|
|
|
+ .eq("creator_id", r.getCreatorId())
|
|
|
+ .eq("create_date", r.getCreateDate()));
|
|
|
}
|
|
|
//存储
|
|
|
reportService.saveBatch(reportList);
|
|
@@ -2067,8 +2055,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
return msg;
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- msg.setError("发生其他错误");
|
|
|
+ msg.setError("发生其他错误:"+e.getMessage());
|
|
|
return msg;
|
|
|
} finally {
|
|
|
//关闭流
|