|
@@ -1,5 +1,7 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.*;
|
|
@@ -64,6 +66,10 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
private UserService userService;
|
|
|
@Resource
|
|
|
private FinanceTblcuscolMapper financeTblcuscolMapper;
|
|
|
+ @Resource
|
|
|
+ private FinanceProjectsMapper financeProjectsMapper;
|
|
|
+ @Resource
|
|
|
+ private ProjectPercentageMapper projectPercentageMapper;
|
|
|
|
|
|
@Resource
|
|
|
private ProjectMapper projectMapper;
|
|
@@ -74,6 +80,28 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
public HttpRespMsg getByMonth(Integer companyId, String yearMonth) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
List<Finance> financeList = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+
|
|
|
+ //当前月是否有项目日报数据
|
|
|
+ List<Map<String, Object>> userList = reportMapper.selectFillReportUserList(companyId, yearMonth+"-01", yearMonth+"-31");
|
|
|
+
|
|
|
+ financeList.forEach(f->{
|
|
|
+ if (f.getHasReport() == null) {
|
|
|
+ boolean has = false;
|
|
|
+ for (Map<String, Object> map : userList) {
|
|
|
+ if (f.getUserId().equals(map.get("creatorId"))) {
|
|
|
+ has = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (has) {
|
|
|
+ f.setHasReport(1);
|
|
|
+ } else {
|
|
|
+ f.setHasReport(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
msg.data = financeList;
|
|
|
return msg;
|
|
|
}
|
|
@@ -391,7 +419,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg exportData(String yearMonth, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg exportData(String yearMonth, Boolean assignNoProUser, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
try {
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
@@ -443,6 +471,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
|
|
|
List<Map<String, Object>> projectTimeList = reportMapper.getRealProjectTime(startDate, endDate, companyId);
|
|
|
|
|
|
+
|
|
|
//计算每个项目的时间和成本
|
|
|
ProjectSumItem item = new ProjectSumItem();
|
|
|
List<ProjectSumItem> pList = new ArrayList<ProjectSumItem>();
|
|
@@ -461,11 +490,66 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
userTime.get(creatorId).workingTime = userTime.get(creatorId).workingTime.add(new BigDecimal((Double)map.get("workingTime")));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
List<Finance> finances = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
- List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ List<Finance> noProjectUser = new ArrayList<>();
|
|
|
+ //计算无项目的人员
|
|
|
+ for (Finance f : finances) {
|
|
|
+ boolean has = false;
|
|
|
+ for (Map<String, Object> map : projectTimeList) {
|
|
|
+ String creatorId = (String) map.get("creatorId");
|
|
|
+ if (creatorId.equals(f.getUserId())) {
|
|
|
+ has = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has) {
|
|
|
+ noProjectUser.add(f);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ ProjectPercentage percentage = null;
|
|
|
+ List<FinanceProjects> financeProjects = financeProjectsMapper.selectList(new QueryWrapper<FinanceProjects>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ //无项目工时人员的分配比例设置
|
|
|
+ List<Map> noPUserDataList = new ArrayList<>();
|
|
|
+ if (assignNoProUser != null && assignNoProUser && noProjectUser.size() > 0) {
|
|
|
+ //检查是否已经设置好分配规则
|
|
|
+ percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ if (percentage == null) {
|
|
|
+ httpRespMsg.setError("请先设置无项目工时人员的分配比例");
|
|
|
+ return httpRespMsg;
|
|
|
+ } else {
|
|
|
+ //获取设置的项目
|
|
|
+ String data = percentage.getData();
|
|
|
+ JSONArray parse = JSONArray.parseArray(data);
|
|
|
+ //获取到无项目人员配置的项目
|
|
|
+ financeProjects.forEach(f->{
|
|
|
+ for (int i = 0; i < parse.size(); i++) {
|
|
|
+ JSONObject json = parse.getJSONObject(i);
|
|
|
+ String userId = json.getString("id");
|
|
|
+ String username = json.getString("name");
|
|
|
+ //获取各个项目的分配比例值
|
|
|
+ HashMap userCostMap = new HashMap();
|
|
|
+ userCostMap.put("creatorId", userId);
|
|
|
+ userCostMap.put("workingTime", 0.0f);
|
|
|
+ double percent = json.getDouble(f.getProjectId()+"");
|
|
|
+ Finance finance = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst().get();
|
|
|
+// BigDecimal curProjectCost = finance.getTotalCost().multiply(new BigDecimal(percent)).divide(new BigDecimal(100));
|
|
|
+ userCostMap.put("finance", finance);
|
|
|
+ userCostMap.put("percent", percent);
|
|
|
+ userCostMap.put("project", f.getProjectId());
|
|
|
+ userCostMap.put("projectId", f.getProjectId());
|
|
|
+ userCostMap.put("projectCode", f.getProjectCode());
|
|
|
+ noPUserDataList.add(userCostMap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
for (Map<String, Object> map : projectTimeList) {
|
|
|
+ Integer projectId = (Integer) map.get("projectId");
|
|
|
+ String curProjectCode = (String) map.get("projectCode");
|
|
|
String curProject = (String) map.get("project");
|
|
|
String creatorId = (String) map.get("creatorId");
|
|
|
Optional<Finance> first = finances.stream().filter(f -> f.getUserId().equals(creatorId)).findFirst();
|
|
@@ -532,6 +616,8 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
item = new ProjectSumItem();
|
|
|
pList.add(item);
|
|
|
item.project = curProject;
|
|
|
+ item.projectId = projectId;
|
|
|
+ item.projectCode = curProjectCode;
|
|
|
item.workingTime = workingTime;
|
|
|
item.cost = cost;
|
|
|
item.salary = salary;
|
|
@@ -568,6 +654,83 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //加上待分摊的无工时项目,如果当前项目列表没有的话
|
|
|
+ if (assignNoProUser != null && assignNoProUser) {
|
|
|
+ List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
|
|
|
+ financeProjects.forEach(f->{
|
|
|
+ if (!projectTimeList.stream().anyMatch(map->((Integer)map.get("projectId")).equals(f.getProjectId()))) {
|
|
|
+ notInFPList.add(f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (notInFPList.size() > 0) {
|
|
|
+ //添加进去
|
|
|
+ notInFPList.forEach(np->{
|
|
|
+ ProjectSumItem npItem = new ProjectSumItem();
|
|
|
+ npItem.project = np.getProjectName();
|
|
|
+ npItem.projectCode = np.getProjectCode();
|
|
|
+ npItem.projectId = np.getProjectId();
|
|
|
+ //初始设置为0
|
|
|
+ npItem.cost = new BigDecimal(0);
|
|
|
+ npItem.salary = new BigDecimal(0);
|
|
|
+ npItem.bonus = new BigDecimal(0);
|
|
|
+ npItem.allowance = new BigDecimal(0);
|
|
|
+ npItem.old = new BigDecimal(0);
|
|
|
+ npItem.medical = new BigDecimal(0);
|
|
|
+ npItem.loseJob = new BigDecimal(0);
|
|
|
+ npItem.injury = new BigDecimal(0);
|
|
|
+ npItem.house = new BigDecimal(0);
|
|
|
+ npItem.field1 = new BigDecimal(0);
|
|
|
+ npItem.field2 = new BigDecimal(0);
|
|
|
+ npItem.field3 = new BigDecimal(0);
|
|
|
+ pList.add(npItem);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //按比例分配
|
|
|
+ for (ProjectSumItem p : pList) {
|
|
|
+ List<Map> filterUserList = noPUserDataList.stream().filter(map->((Integer)map.get("projectId")).equals(p.projectId)).collect(Collectors.toList());
|
|
|
+ for (Map f : filterUserList) {
|
|
|
+ String curUserId = (String)f.get("creatorId");
|
|
|
+ double percent = (double)f.get("percent");
|
|
|
+ Finance finance = (Finance)f.get("finance");
|
|
|
+ System.out.println(finance.getTotalCost());
|
|
|
+ //各项收入按比例计算,累加到当前项目上
|
|
|
+ Finance newFinance = Finance.getByPercent(finance, percent);
|
|
|
+ p.cost = p.cost.add(newFinance.getTotalCost());
|
|
|
+ p.salary = p.salary.add(newFinance.getMonthCost());
|
|
|
+ p.bonus = p.bonus.add(newFinance.getBonus());
|
|
|
+ p.allowance = p.allowance.add(newFinance.getAllowance());
|
|
|
+ p.old = p.old.add(newFinance.getInsuranceOld());
|
|
|
+ p.medical = p.medical.add(newFinance.getInsuranceMedical());
|
|
|
+ p.loseJob = p.loseJob.add(newFinance.getInsuranceLosejob());
|
|
|
+ p.injury = p.injury.add(newFinance.getInsuranceInjury());
|
|
|
+ p.house = p.house.add(newFinance.getHouseFund());
|
|
|
+// item.other = item.other.add(other);
|
|
|
+ p.field1 = p.field1.add(newFinance.getCustomField1());
|
|
|
+ p.field2 = p.field2.add(newFinance.getCustomField2());
|
|
|
+ p.field3 = p.field3.add(newFinance.getCustomField3());
|
|
|
+
|
|
|
+ //叠加到总计的各项成本上
|
|
|
+ totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
|
|
|
+ totalSalary = totalSalary.add(newFinance.getMonthCost());
|
|
|
+ totalBonus = totalBonus.add(newFinance.getBonus());
|
|
|
+ totalAllowance = totalAllowance.add(newFinance.getAllowance());
|
|
|
+ totalOld = totalOld.add(newFinance.getInsuranceOld());
|
|
|
+ totalMedical = totalMedical.add(newFinance.getInsuranceMedical());
|
|
|
+ totalLoseJob = totalLoseJob.add(newFinance.getInsuranceLosejob());
|
|
|
+ totalInjury = totalInjury.add((newFinance.getInsuranceInjury()));
|
|
|
+ totalHouse = totalHouse.add(newFinance.getHouseFund());
|
|
|
+ if (totalField1 != null) {
|
|
|
+ totalField1 = totalField1.add(newFinance.getCustomField1());
|
|
|
+ }
|
|
|
+ if (totalField2 != null) {
|
|
|
+ totalField2 = totalField2.add(newFinance.getCustomField2());
|
|
|
+ }
|
|
|
+ if (totalField3 != null) {
|
|
|
+ totalField3 = totalField3.add(newFinance.getCustomField3());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//整体四舍五入处理
|
|
|
totalMoneyCost = totalMoneyCost.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
@@ -589,6 +752,55 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
if (totalField3 != null) {
|
|
|
totalField3 = totalField3.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// if (assignNoProUser != null && assignNoProUser) {
|
|
|
+ //按比例分摊
|
|
|
+
|
|
|
+ //均摊各项成本到项目
|
|
|
+// for (Finance npu : noProjectUser) {
|
|
|
+// pList.forEach(p->{
|
|
|
+// p.cost = p.cost.add(npu.getTotalCost().divide(new BigDecimal(pList.size())));
|
|
|
+// p.salary = p.salary.add(npu.getMonthCost().divide(new BigDecimal(pList.size())));
|
|
|
+// p.bonus = p.bonus.add(npu.getBonus().divide(new BigDecimal(pList.size())));
|
|
|
+// p.allowance = p.allowance.add(npu.getAllowance().divide(new BigDecimal(pList.size())));
|
|
|
+// p.old = p.old.add(npu.getInsuranceOld().divide(new BigDecimal(pList.size())));
|
|
|
+// p.medical = p.medical.add(npu.getInsuranceMedical().divide(new BigDecimal(pList.size())));
|
|
|
+// p.loseJob = p.loseJob.add(npu.getInsuranceLosejob().divide(new BigDecimal(pList.size())));
|
|
|
+// p.injury = p.injury.add(npu.getInsuranceInjury().divide(new BigDecimal(pList.size())));
|
|
|
+// p.house = p.house.add(npu.getHouseFund().divide(new BigDecimal(pList.size())));
|
|
|
+// //处理自定义字段的数据累加
|
|
|
+// if (npu.getCustomField1() != null) {
|
|
|
+// p.field1 = p.field1.add(npu.getCustomField1().divide(new BigDecimal(pList.size())));
|
|
|
+// }
|
|
|
+// if (npu.getCustomField2() != null) {
|
|
|
+// p.field2 = p.field2.add(npu.getCustomField2().divide(new BigDecimal(pList.size())));
|
|
|
+// }
|
|
|
+// if (npu.getCustomField3() != null) {
|
|
|
+// p.field3 = p.field3.add(npu.getCustomField3().divide(new BigDecimal(pList.size())));
|
|
|
+// }
|
|
|
+// });
|
|
|
+// totalMoneyCost = totalMoneyCost.add(npu.getTotalCost());
|
|
|
+// totalSalary = totalSalary.add(npu.getMonthCost());
|
|
|
+// totalBonus = totalBonus.add(npu.getBonus());
|
|
|
+// totalAllowance = totalAllowance.add(npu.getAllowance());
|
|
|
+// totalOld = totalOld.add(npu.getInsuranceOld());
|
|
|
+// totalMedical = totalMedical.add(npu.getInsuranceMedical());
|
|
|
+// totalLoseJob = totalLoseJob.add(npu.getInsuranceLosejob());
|
|
|
+// totalInjury = totalInjury.add(npu.getInsuranceInjury());
|
|
|
+// totalHouse = totalHouse.add(npu.getHouseFund());
|
|
|
+//// totalOther = totalOther.add(other);
|
|
|
+// if (totalField1 != null && npu.getCustomField1() != null) {
|
|
|
+// totalField1 = totalField1.add(npu.getTotalCost());
|
|
|
+// }
|
|
|
+// if (totalField2 != null && npu.getCustomField2() != null) {
|
|
|
+// totalField2 = totalField2.add(npu.getCustomField2());
|
|
|
+// }
|
|
|
+// if (totalField3 != null && npu.getCustomField3() != null) {
|
|
|
+// totalField3 = totalField3.add(npu.getCustomField3());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
pList.forEach(p->{
|
|
|
p.cost = p.cost.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
p.salary = p.salary.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
@@ -684,8 +896,62 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
allList.add(membRowData);
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
+ //无项目人员成本
|
|
|
+ if (assignNoProUser != null && assignNoProUser) {
|
|
|
+ for (Finance npu : noProjectUser) {
|
|
|
+ List<String> membRowData = new ArrayList<String>();
|
|
|
+ membRowData.add("");
|
|
|
+ Double workingTime = new Double(0);
|
|
|
+ Finance userFinance = npu;
|
|
|
+ Optional<Map> op = noPUserDataList.stream().filter(map->((Integer)map.get("projectId")).equals(p.projectId) && ((String)map.get("creatorId")).equals(npu.getUserId())).findFirst();
|
|
|
+ if (op.isPresent()) {
|
|
|
+ Map percentMap = op.get();
|
|
|
+ double percent = (double)percentMap.get("percent");
|
|
|
+ if (percent > 0) {
|
|
|
+ //各项收入按比例计算,累加到当前项目上
|
|
|
+ Finance newFinance = Finance.getByPercent(npu, percent);
|
|
|
+
|
|
|
+ BigDecimal cost = newFinance.getTotalCost();
|
|
|
+ BigDecimal salary = newFinance.getMonthCost();
|
|
|
+ BigDecimal bonus = newFinance.getBonus();
|
|
|
+ BigDecimal allowance = newFinance.getAllowance();
|
|
|
+ BigDecimal old = newFinance.getInsuranceOld();
|
|
|
+ BigDecimal medical = newFinance.getInsuranceMedical();
|
|
|
+ BigDecimal loseJob = newFinance.getInsuranceLosejob();
|
|
|
+ BigDecimal injury = newFinance.getInsuranceInjury();
|
|
|
+ BigDecimal house = newFinance.getHouseFund();
|
|
|
+ BigDecimal field1 = newFinance.getCustomField1() == null? new BigDecimal(0):newFinance.getCustomField1();
|
|
|
+ BigDecimal field2 = newFinance.getCustomField2() == null? new BigDecimal(0):newFinance.getCustomField2();
|
|
|
+ BigDecimal field3 = newFinance.getCustomField3() == null? new BigDecimal(0):newFinance.getCustomField3();
|
|
|
+
|
|
|
+ membRowData.add(npu.getName());
|
|
|
+ membRowData.add(workingTime+"");
|
|
|
+ membRowData.add(salary.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(bonus.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(allowance.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(old.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(medical.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(loseJob.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(injury.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ membRowData.add(house.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ //自定义字段
|
|
|
+ if (cusColList.size() > 0) {
|
|
|
+ membRowData.add(field1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ if (cusColList.size() > 1) {
|
|
|
+ membRowData.add(field2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ if (cusColList.size() > 2) {
|
|
|
+ membRowData.add(field3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ membRowData.add(cost.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
+ allList.add(membRowData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
//合计
|
|
|
List<String> sumRow = new ArrayList<String>();
|
|
@@ -721,7 +987,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getTimeCost(String yearMonth, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg getTimeCost(String yearMonth, Boolean assignNoProUser, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
try {
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
@@ -752,16 +1018,24 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
userTime.put(creatorId, d);
|
|
|
}
|
|
|
}
|
|
|
- Set<String> strings = userTime.keySet();
|
|
|
- Iterator<String> iterator = strings.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- String next = iterator.next();
|
|
|
- System.out.println(next+": "+userTime.get(next));
|
|
|
- }
|
|
|
List<Finance> finances = financeMapper.selectList(new QueryWrapper<Finance>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
- List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
//未投入项目的人员
|
|
|
ProjectSumItem noProjectItem = new ProjectSumItem();
|
|
|
+ List<Finance> noProjectUser = new ArrayList<>();
|
|
|
+ //计算无项目的人员
|
|
|
+ for (Finance f : finances) {
|
|
|
+ boolean has = false;
|
|
|
+ for (Map<String, Object> map : projectTimeList) {
|
|
|
+ String creatorId = (String) map.get("creatorId");
|
|
|
+ if (creatorId.equals(f.getUserId())) {
|
|
|
+ has = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has) {
|
|
|
+ noProjectUser.add(f);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
finances.forEach(f->{
|
|
|
String uid = f.getUserId();
|
|
@@ -773,10 +1047,8 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
noProjectItem.project = "无项目";
|
|
|
noProjectItem.workingTime = 0;
|
|
|
noProjectItem.cost = new BigDecimal(0);
|
|
|
-
|
|
|
}
|
|
|
noProjectItem.cost = noProjectItem.cost.add(f.getTotalCost());
|
|
|
-
|
|
|
} else {
|
|
|
BigDecimal avgHourCost = f.getTotalCost().divide(b,6, BigDecimal.ROUND_HALF_UP);
|
|
|
f.setHourCost(avgHourCost);
|
|
@@ -785,6 +1057,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
|
|
|
|
|
|
for (Map<String, Object> map : projectTimeList) {
|
|
|
+ Integer projectId = (Integer) map.get("projectId");
|
|
|
String curProject = (String) map.get("project");
|
|
|
String creatorId = (String) map.get("creatorId");
|
|
|
Optional<Finance> first = finances.stream().filter(f -> f.getUserId().equals(creatorId)).findFirst();
|
|
@@ -802,17 +1075,89 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
} else {
|
|
|
item = new ProjectSumItem();
|
|
|
pList.add(item);
|
|
|
+ item.projectId = projectId;
|
|
|
item.project = curProject;
|
|
|
item.workingTime = workingTime;
|
|
|
item.cost = cost;
|
|
|
}
|
|
|
totalMoneyCost = totalMoneyCost.add(cost);
|
|
|
}
|
|
|
-// //存在无项目的人员,加入总成本
|
|
|
-// if (noProjectItem.project != null){
|
|
|
-// totalMoneyCost = totalMoneyCost.add(noProjectItem.cost);
|
|
|
-// pList.add(noProjectItem);
|
|
|
-// }
|
|
|
+
|
|
|
+
|
|
|
+ //加上待分摊的无工时项目,如果当前项目列表没有的话
|
|
|
+ if (assignNoProUser != null && assignNoProUser && noProjectItem.project != null) {
|
|
|
+ List<FinanceProjects> financeProjects = financeProjectsMapper.selectList(new QueryWrapper<FinanceProjects>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+
|
|
|
+ //检查是否已经设置好分配规则
|
|
|
+ ProjectPercentage percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ List<Map> noPUserDataList = new ArrayList<>();
|
|
|
+ //构造各个项目的分配比例
|
|
|
+ if (percentage == null) {
|
|
|
+ httpRespMsg.setError("请先设置无项目工时人员的分配比例");
|
|
|
+ return httpRespMsg;
|
|
|
+ } else {
|
|
|
+ //获取设置的项目
|
|
|
+ String data = percentage.getData();
|
|
|
+ JSONArray parse = JSONArray.parseArray(data);
|
|
|
+ //获取到无项目人员配置的项目
|
|
|
+ financeProjects.forEach(f->{
|
|
|
+ for (int i = 0; i < parse.size(); i++) {
|
|
|
+ JSONObject json = parse.getJSONObject(i);
|
|
|
+ String userId = json.getString("id");
|
|
|
+ String username = json.getString("name");
|
|
|
+ //获取各个项目的分配比例值
|
|
|
+ HashMap userCostMap = new HashMap();
|
|
|
+ userCostMap.put("creatorId", userId);
|
|
|
+ userCostMap.put("workingTime", 0.0f);
|
|
|
+ double percent = json.getDouble(f.getProjectId()+"");
|
|
|
+ Finance finance = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst().get();
|
|
|
+// BigDecimal curProjectCost = finance.getTotalCost().multiply(new BigDecimal(percent)).divide(new BigDecimal(100));
|
|
|
+ userCostMap.put("finance", finance);
|
|
|
+ userCostMap.put("percent", percent);
|
|
|
+ userCostMap.put("project", f.getProjectId());
|
|
|
+ userCostMap.put("projectId", f.getProjectId());
|
|
|
+ userCostMap.put("projectCode", f.getProjectCode());
|
|
|
+ noPUserDataList.add(userCostMap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
|
|
|
+ financeProjects.forEach(f->{
|
|
|
+ if (!projectTimeList.stream().anyMatch(map->((Integer)map.get("projectId")).equals(f.getProjectId()))) {
|
|
|
+ notInFPList.add(f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (notInFPList.size() > 0) {
|
|
|
+ //添加进去
|
|
|
+ notInFPList.forEach(np->{
|
|
|
+ ProjectSumItem npItem = new ProjectSumItem();
|
|
|
+ npItem.project = np.getProjectName();
|
|
|
+ npItem.projectCode = np.getProjectCode();
|
|
|
+ npItem.projectId = np.getProjectId();
|
|
|
+ //初始设置为0
|
|
|
+ npItem.cost = new BigDecimal(0);
|
|
|
+ pList.add(npItem);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //按比例分配
|
|
|
+ for (ProjectSumItem p : pList) {
|
|
|
+ List<Map> filterUserList = noPUserDataList.stream().filter(map->((Integer)map.get("projectId")).equals(p.projectId)).collect(Collectors.toList());
|
|
|
+ System.out.println(p.project+", 找到匹配人员=="+filterUserList.size());
|
|
|
+ for (Map f : filterUserList) {
|
|
|
+ String curUserId = (String)f.get("creatorId");
|
|
|
+ double percent = (double)f.get("percent");
|
|
|
+ Finance finance = (Finance)f.get("finance");
|
|
|
+ //各项收入按比例计算,累加到当前项目上
|
|
|
+ Finance newFinance = Finance.getByPercent(finance, percent);
|
|
|
+ System.out.println("比例=="+newFinance.getTotalCost());
|
|
|
+ p.cost = p.cost.add(newFinance.getTotalCost());
|
|
|
+ //叠加到总计的各项成本上
|
|
|
+ totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//整体四舍五入处理
|
|
|
totalMoneyCost = totalMoneyCost.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
@@ -864,4 +1209,24 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public HttpRespMsg getProjects(Integer companyId, String yearMonth) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ //如果没有记录,默认返回全部的
|
|
|
+ List<FinanceProjects> list = financeProjectsMapper.selectList(new QueryWrapper<FinanceProjects>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ List<Project> allProjects = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
+ if (list.size() == 0) {
|
|
|
+ allProjects.forEach(a->{
|
|
|
+ FinanceProjects item = new FinanceProjects();
|
|
|
+ item.setProjectId(a.getId());
|
|
|
+ item.setProjectCode(a.getProjectCode());
|
|
|
+ item.setProjectName(a.getProjectName());
|
|
|
+ list.add(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ HashMap map = new HashMap();
|
|
|
+ map.put("allProjectList", allProjects);
|
|
|
+ map.put("financeProjects", list);
|
|
|
+ msg.data = map;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|