|
@@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
@@ -110,30 +111,82 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
map.put("state", state);
|
|
|
}
|
|
|
|
|
|
- int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("incharger_id", leaderId));
|
|
|
- if (cnt > 0) {
|
|
|
- //担任项目经理,查找相关的人员的日报
|
|
|
- List<Map<String, Object>> puserNames = reportMapper.getReportNameByDate(date, user.getCompanyId(), leaderId);
|
|
|
- List<Map<String, Object>> inchargeReportList= reportMapper.getInchargeReportByDate(date, leaderId, null);
|
|
|
- for (Map<String, Object> map2 : puserNames) {
|
|
|
- nameList.add(map2);
|
|
|
- //再根据人分别获取当天的报告
|
|
|
- List<Map<String, Object>> list2 =
|
|
|
- inchargeReportList.stream().filter(i->i.get("creatorId").equals(map2.get("id"))).collect(Collectors.toList());
|
|
|
- map2.put("data", list2);
|
|
|
- double reportTime = 0;
|
|
|
- BigDecimal total = new BigDecimal(0);
|
|
|
- for (Map<String, Object> m : list2) {
|
|
|
- double t = (double) m.get("time");
|
|
|
- reportTime += t;
|
|
|
- total = total.add((BigDecimal)m.get("cost"));
|
|
|
+ //部门经理需要看本部门的所有人员的日报
|
|
|
+ if (user.getManageDeptId() != null && user.getManageDeptId() > 0) {
|
|
|
+ int manageDeptId = user.getManageDeptId();
|
|
|
+ //找到该部门的所有子部门
|
|
|
+ List<Department> allDepts = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
|
|
|
+ Optional<Department> first = allDepts.stream().filter(d -> d.getDepartmentId().equals(manageDeptId)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Department department = first.get();
|
|
|
+ //递归获取全部子部门
|
|
|
+ List<Department> deptList = getSubDepts(department, allDepts);
|
|
|
+ deptList.add(department);
|
|
|
+ List ids = deptList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ nameList = reportMapper.getReportNameByDateAndDept(date,
|
|
|
+ ids, null, null);
|
|
|
+
|
|
|
+ if (nameList.size() > 0) {
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ nameList.forEach(n->{
|
|
|
+ String id = (String) n.get("id");
|
|
|
+ userIds.add(id);
|
|
|
+ });
|
|
|
+ List<Map<String, Object>> reportList = reportMapper.getUserReportByDate(date, userIds);
|
|
|
+ for (Map<String, Object> memb : nameList) {
|
|
|
+ //再根据人分别获取当天的报告
|
|
|
+ List<Map<String, Object>> rList = new ArrayList<Map<String, Object>>();
|
|
|
+ BigDecimal total = new BigDecimal(0);
|
|
|
+ for (Map<String, Object> report : reportList) {
|
|
|
+ if (((String)report.get("creatorId")).equals((String)memb.get("id"))) {
|
|
|
+ rList.add(report);
|
|
|
+ total = total.add((BigDecimal) report.get("cost"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ memb.put("data", rList);
|
|
|
+ memb.put("cost", total);
|
|
|
+ double reportTime = 0;
|
|
|
+ if (list.size() > 0) {
|
|
|
+ for (Map<String, Object> m : list) {
|
|
|
+ double t = (double) m.get("time");
|
|
|
+ reportTime += t;
|
|
|
+ }
|
|
|
+ memb.put("state", list.get(0).get("state"));
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ memb.put("reportTime", df.format(reportTime));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非部门经理,检查是否是项目经理
|
|
|
+ int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("incharger_id", leaderId));
|
|
|
+ if (cnt > 0) {
|
|
|
+ //担任项目经理,查找相关的人员的日报
|
|
|
+ List<Map<String, Object>> puserNames = reportMapper.getReportNameByDate(date, user.getCompanyId(), leaderId);
|
|
|
+ List<Map<String, Object>> inchargeReportList= reportMapper.getInchargeReportByDate(date, leaderId, null);
|
|
|
+ for (Map<String, Object> map2 : puserNames) {
|
|
|
+ nameList.add(map2);
|
|
|
+ //再根据人分别获取当天的报告
|
|
|
+ List<Map<String, Object>> list2 =
|
|
|
+ inchargeReportList.stream().filter(i->i.get("creatorId").equals(map2.get("id"))).collect(Collectors.toList());
|
|
|
+ map2.put("data", list2);
|
|
|
+ double reportTime = 0;
|
|
|
+ BigDecimal total = new BigDecimal(0);
|
|
|
+ for (Map<String, Object> m : list2) {
|
|
|
+ double t = (double) m.get("time");
|
|
|
+ reportTime += t;
|
|
|
+ total = total.add((BigDecimal)m.get("cost"));
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ map2.put("reportTime", df.format(reportTime));
|
|
|
+ map2.put("cost", total);
|
|
|
+ map2.put("state", list2.get(0).get("state"));
|
|
|
}
|
|
|
- DecimalFormat df = new DecimalFormat("0.00");
|
|
|
- map2.put("reportTime", df.format(reportTime));
|
|
|
- map2.put("cost", total);
|
|
|
- map2.put("state", list2.get(0).get("state"));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
List<Integer> ids = null;
|
|
@@ -151,9 +204,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
nameList = reportMapper.getReportNameByDateAndDept(date,
|
|
|
ids, targetUid, companyId);
|
|
|
- nameList.forEach(n->{
|
|
|
- System.out.println("name=="+n.get("name"));
|
|
|
- });
|
|
|
+
|
|
|
if (nameList.size() > 0) {
|
|
|
List<String> userIds = new ArrayList<>();
|
|
|
nameList.forEach(n->{
|
|
@@ -257,6 +308,13 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
public HttpRespMsg editReport(List<Report> reportList, String date) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
+ BigDecimal hourCost = userMapper.selectById(reportList.get(0).getCreatorId()).getCost();
|
|
|
+ Integer companyId = userMapper.selectById(reportList.get(0).getCreatorId()).getCompanyId();
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ double totalWorkTime = 0;
|
|
|
+ for (Report report : reportList) {
|
|
|
+ totalWorkTime +=report.getWorkingTime();
|
|
|
+ }
|
|
|
for (Report report : reportList) {
|
|
|
//获取一下信息
|
|
|
if (report.getWorkingTime() <= 0.0) {
|
|
@@ -264,12 +322,30 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
if (report.getId() == null) {
|
|
|
+ //检查是否存在计算加班工资的情况
|
|
|
+ if (!timeType.getPayOvertime()) {
|
|
|
+ //不能超过最多时间,超过的话,等比例核算
|
|
|
+ if (totalWorkTime > timeType.getAllday()) {
|
|
|
+ BigDecimal 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 = 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("操作失败");
|
|
|
}
|