|
@@ -390,6 +390,9 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
allUserIds = ListUtil.convertLongIdsArrayToList(userIds);
|
|
|
}
|
|
|
//按选择的人员来查询数据
|
|
|
+ //根据当前人员的角色权限来判断
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+
|
|
|
List<Map<String, Object>> list = departmentMapper
|
|
|
.getCostByUser(null, startDate, endDate, companyId, allUserIds);
|
|
|
Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
|
|
@@ -641,6 +644,99 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportDeptStatistic(String startDate, String endDate, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ List<Integer> deptIds = new ArrayList<>();
|
|
|
+ deptIds.add(-1);
|
|
|
+ if (user.getManageDeptId() != 0) {
|
|
|
+ //有负责的部门
|
|
|
+ List<Department> myDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", user.getId()));
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
|
|
|
+ for (Department dept: myDeptList) {
|
|
|
+ deptIds.add(dept.getDepartmentId());
|
|
|
+ deptIds.addAll(getBranchDepartment(dept.getDepartmentId(), allDeptList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("获取到管理的部门ids length=="+deptIds);
|
|
|
+ List<Map<String, Object>> list = departmentMapper
|
|
|
+ .getCostByUser(deptIds, startDate, endDate, companyId, null);
|
|
|
+ Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ if (tempMap.containsKey(map.get("user"))) {
|
|
|
+ //这个名字已经装进数组中了
|
|
|
+ List<Map<String, Object>> tempList = tempMap.get(map.get("user"));
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("project", map.get("project"));
|
|
|
+ Double time = (Double) map.getOrDefault("time", 0);
|
|
|
+ dataMap.put("time", time);
|
|
|
+ tempList.add(dataMap);
|
|
|
+ } else {
|
|
|
+ //这个名字尚未装进数组中
|
|
|
+ List<Map<String, Object>> tempList = new ArrayList<>();
|
|
|
+ if (map.containsKey("project")) {
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("project", map.get("project"));
|
|
|
+ Double time = (Double) map.getOrDefault("time", 0);
|
|
|
+ dataMap.put("time", time);
|
|
|
+ tempList.add(dataMap);
|
|
|
+ }
|
|
|
+ tempMap.put((String) map.get("user"), tempList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+ List<List<String>> dataList = new ArrayList<List<String>>();
|
|
|
+ String[] titles = {"人员", "项目", "工时(h)"};
|
|
|
+ List<String> titleList = Arrays.asList(titles.clone());
|
|
|
+ dataList.add(titleList);
|
|
|
+ double totalCostTime = 0;
|
|
|
+ for (String key : tempMap.keySet()) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("name", key);
|
|
|
+ map.put("project", tempMap.get(key));
|
|
|
+ List<String> nameList = new ArrayList<String>();
|
|
|
+ nameList.add(key);//姓名
|
|
|
+ nameList.add("");//空着
|
|
|
+ List<Map<String, Object>> tempList = tempMap.get(key);
|
|
|
+ //统计个人的时间和成本
|
|
|
+ double tTime = 0;
|
|
|
+ for (Map<String, Object> membData : tempList) {
|
|
|
+ tTime += (double)membData.get("time");
|
|
|
+ }
|
|
|
+ totalCostTime += tTime;
|
|
|
+ nameList.add(df.format(tTime));
|
|
|
+ dataList.add(nameList);
|
|
|
+ //装载该人员下的项目的工时数据
|
|
|
+ for (Map<String, Object> membData : tempList) {
|
|
|
+ tTime += (double)membData.get("time");
|
|
|
+ List<String> projectDataList = new ArrayList<>();
|
|
|
+ projectDataList.add("");
|
|
|
+ projectDataList.add(membData.get("project")+"");
|
|
|
+ projectDataList.add(df.format((double)membData.get("time"))+"");
|
|
|
+ dataList.add(projectDataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //合计
|
|
|
+ List<String> sumRow = new ArrayList<String>();
|
|
|
+ sumRow.add("合计");
|
|
|
+ sumRow.add("");
|
|
|
+ sumRow.add(""+df.format(totalCostTime));
|
|
|
+ dataList.add(sumRow);
|
|
|
+ //生成excel文件导出
|
|
|
+ String fileName = "人员工时统计_"+System.currentTimeMillis();
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , dataList, path);
|
|
|
+
|
|
|
+ httpRespMsg.data = resp;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void fillDeptUser(List<DepartmentVO> list, List<HashMap> userList) {
|
|
|
list.forEach(l->{
|