|
@@ -4483,6 +4483,186 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getTimeCostByMainProject(String startDate, String endDate, String userId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ //根据系统配置的员工成本计算方式,按固定时薪还是固定月薪,分情况计算。
|
|
|
+ User targetUser = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId =targetUser.getCompanyId();
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ //当前用户管理部门
|
|
|
+ List<Integer> deptIds=null;
|
|
|
+ List<Department> allDepartmentList=departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id", companyId));
|
|
|
+ List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", targetUser.getId()));
|
|
|
+ List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看全公司");
|
|
|
+ List<SysRichFunction> functionDpartList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看负责部门");
|
|
|
+ List<SysRichFunction> functionTimeList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看工时统计");
|
|
|
+ List<SysRichFunction> functionCostList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看成本统计");
|
|
|
+ //判断查看权限
|
|
|
+ if(functionAllList.size()==0){
|
|
|
+ deptIds=new ArrayList<>();
|
|
|
+ deptIds.add(-1);
|
|
|
+ if(functionDpartList.size()>0){
|
|
|
+ if(functionTimeList.size()>0||functionCostList.size()>0){
|
|
|
+ List<Integer> collect = departmentList.stream().distinct().map(dm -> dm.getDepartmentId()).collect(Collectors.toList());
|
|
|
+ List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
|
|
|
+ collect.addAll(otherCollect);
|
|
|
+ for (Integer integer : collect) {
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
|
|
|
+ deptIds.addAll(branchDepartment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ if (timeType.getFixMonthcost() == 1) {
|
|
|
+ //每月固定月薪的方式计算,平摊到各个项目中
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostReport(companyId, startDate+"-01", endDate+"-31", null,deptIds);
|
|
|
+ //检查财务表中是否已经导入成本
|
|
|
+ List<Finance> financeList = financeMapper.selectList(new QueryWrapper<Finance>().eq("ymonth", startDate).eq("company_id", companyId));
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ //计算人员总工时
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
+ double cost = (double)map.get("cost");
|
|
|
+ User user = userList.stream().filter(u -> u.getId().equals(creatorId)).findFirst().get();
|
|
|
+ user.setTotalHours(user.getTotalHours() + cost);
|
|
|
+ }
|
|
|
+ //计算实际时薪
|
|
|
+ for (User user : userList) {
|
|
|
+ if (user.getTotalHours() != 0) {
|
|
|
+ Optional<Finance> first = financeList.stream().filter(f -> f.getUserId().equals(user.getId())).findFirst();
|
|
|
+ BigDecimal monthCost = null;
|
|
|
+ if (first.isPresent()) {
|
|
|
+ monthCost = first.get().getTotalCost();
|
|
|
+ } else {
|
|
|
+ monthCost = user.getMonthCost();
|
|
|
+ }
|
|
|
+ user.setCost(monthCost.divide(new BigDecimal(user.getTotalHours()), 6, BigDecimal.ROUND_HALF_UP));
|
|
|
+ } else {
|
|
|
+ user.setCost(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<>();
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId).orderByAsc("id"));
|
|
|
+ for (Project p : projectList) {
|
|
|
+ Map<String, Object> projectMap = new HashMap<>();
|
|
|
+ projectMap.put("id", p.getId());
|
|
|
+ projectMap.put("name", p.getProjectName());
|
|
|
+ //按照主项目汇总
|
|
|
+ double pTotalTime = 0;
|
|
|
+ BigDecimal pTotalMoney = new BigDecimal(0);
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
+ int projectId = (int)map.get("projectId");
|
|
|
+ if (projectId == p.getId()) {
|
|
|
+ double costTime = (double)map.get("cost");
|
|
|
+ pTotalTime += costTime;
|
|
|
+ User curUser = userList.stream().filter(u->u.getId().equals(creatorId)).findFirst().get();
|
|
|
+ //该人员的成本
|
|
|
+ pTotalMoney = pTotalMoney.add(curUser.getCost().multiply(new BigDecimal(costTime)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pTotalTime > 0) {
|
|
|
+ projectMap.put("cost", pTotalTime);
|
|
|
+ projectMap.put("costMoney", pTotalMoney);
|
|
|
+ retList.add(projectMap);
|
|
|
+ totalMoneyCost = totalMoneyCost.add(pTotalMoney);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultMap.put("costList", retList);
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
+ if(functionCostList.size()==0){
|
|
|
+ resultMap.put("totalCostMoney",null);
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("costMoney",null);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(functionTimeList.size()==0){
|
|
|
+ retList.forEach(li->{
|
|
|
+ li.put("cost",null);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostByMainProject(companyId, startDate, endDate, null, userId,deptIds);
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ if (!map.containsKey("cost")) {
|
|
|
+ map.put("cost", 0);
|
|
|
+ }
|
|
|
+ if (!map.containsKey("costMoney")) {
|
|
|
+ map.put("costMoney", 0);
|
|
|
+ } else {
|
|
|
+ totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultMap.put("costList", list);
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
+ if(functionCostList.size()==0){
|
|
|
+ resultMap.put("totalCostMoney",null);
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("costMoney",null);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(functionTimeList.size()==0){
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("cost",null);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
+ }
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getCostByGroup(String startDate, String endDate, Integer projectId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ //首先查看有无浏览权限
|
|
|
+ if (!projectMapper.selectById(projectId).getCompanyId().equals(companyId)) {
|
|
|
+ httpRespMsg.setError("无权查看其他公司的项目详情");
|
|
|
+ } else {
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ List<Map<String, Object>> list = projectMapper.getCostByGroup(startDate, endDate, projectId);
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ if (!map.containsKey("costMoney")) {
|
|
|
+ map.put("costMoney", 0);
|
|
|
+ } else {
|
|
|
+ totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultMap.put("costList", list);
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
+ }
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getTimeCostByGroup(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private List<Department> getSubDepts(Department dp, List<Department> list) {
|
|
|
List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());
|