|
|
@@ -2017,6 +2017,7 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
try {
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
//获取月成本列表
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
@@ -2151,86 +2152,130 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
|
|
|
BigDecimal percentTotal = new BigDecimal(0);
|
|
|
//加上待分摊的无工时项目,如果当前项目列表没有的话
|
|
|
if (assignNoProUser != null && assignNoProUser && noProjectItem.project != null) {
|
|
|
-// List<FinanceProjects> financeProjects = financeProjectsMapper.selectList(new QueryWrapper<FinanceProjects>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
- /**添加非分摊项目筛选*/
|
|
|
- List<FinanceProjects> financeProjects = financeProjectsMapper.getExcludeFinanceProjects(companyId,yearMonth);
|
|
|
- if (financeProjects.size() == 0) {
|
|
|
- //httpRespMsg.setError("缺少待分摊项目,请重新设置并保存分摊比例设置");
|
|
|
- httpRespMsg.setError(MessageUtils.message("project.lackApportion"));
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
- //检查是否已经设置好分配规则
|
|
|
- ProjectPercentage percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
- List<Map> noPUserDataList = new ArrayList<>();
|
|
|
- //构造各个项目的分配比例
|
|
|
- if (percentage == null) {
|
|
|
- //httpRespMsg.setError("请先设置无项目工时人员的分配比例");
|
|
|
- httpRespMsg.setError(MessageUtils.message("project.setPersonnelAllotment"));
|
|
|
- return httpRespMsg;
|
|
|
+ if (timeType.getFinanceTwiceAssign()) {
|
|
|
+ //自动二次分摊, 目前羲合超导开放,按照生产和研发的规则执行分配
|
|
|
+ List<String> userIds = noProjectUser.stream().map(Finance::getUserId).collect(Collectors.toList());
|
|
|
+ if (userIds.size() > 0) {
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", userIds).eq("company_id", companyId));
|
|
|
+ List<Project> allProjects = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId).in("id", pList.stream().map(ProjectSumItem::getProjectId).collect(Collectors.toList())));
|
|
|
+ for (Finance user: noProjectUser) {
|
|
|
+ User curUser = userList.stream().filter(u -> u.getId().equals(user.getUserId())).findFirst().orElse(null);
|
|
|
+ if (curUser != null && "生产".equals(curUser.getPlate1()) || "研发".equals(curUser.getPlate1())) {
|
|
|
+ System.out.println("分摊无工时人员=="+curUser.getName());
|
|
|
+ List<ProjectSumItem> filteredList = new ArrayList<>();
|
|
|
+ for (ProjectSumItem p : pList) {
|
|
|
+ Project project = allProjects.stream().filter(p1 -> p1.getId().equals(p.projectId)).findFirst().orElse(null);
|
|
|
+ if (project.getCategoryName() != null && project.getCategoryName().equals(curUser.getPlate1())) {
|
|
|
+ filteredList.add(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (filteredList.size() > 0) {
|
|
|
+ //计算项目的各自工时占比
|
|
|
+ System.out.println("按比例分配无工时人员");
|
|
|
+ BigDecimal accumulate = new BigDecimal(0);
|
|
|
+ double sum = filteredList.stream().mapToDouble(ProjectSumItem::getWorkingTime).sum();
|
|
|
+ System.out.println("总时长=="+sum);
|
|
|
+ for (int i=0;i<filteredList.size(); i++) {
|
|
|
+ ProjectSumItem p = filteredList.get(i);
|
|
|
+ System.out.println("+p.getWorkingtime="+p.workingTime+", project="+p.project);
|
|
|
+ //避免偏差
|
|
|
+ BigDecimal assignAmount = i < filteredList.size() -1 ?user.getTotalCost().multiply(new BigDecimal(p.workingTime / sum)):user.getTotalCost().subtract(accumulate);
|
|
|
+ assignAmount = assignAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ accumulate = accumulate.add(assignAmount);
|
|
|
+ System.out.println("增加项目成本==="+assignAmount);
|
|
|
+ p.cost = p.cost.add(assignAmount);
|
|
|
+ if (p.secondCost == null) {
|
|
|
+ p.secondCost = new BigDecimal(0);
|
|
|
+ }
|
|
|
+ p.secondCost = p.secondCost.add(assignAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ totalMoneyCost = totalMoneyCost.add(user.getTotalCost());
|
|
|
+ percentTotal = percentTotal.add(user.getTotalCost());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- //获取设置的项目
|
|
|
- String data = percentage.getData();
|
|
|
- JSONArray parse = JSONArray.parseArray(data);
|
|
|
-
|
|
|
- //获取到无项目人员配置的项目
|
|
|
- for (FinanceProjects f : financeProjects) {
|
|
|
- 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()+"");
|
|
|
- Optional<Finance> first = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- Finance finance = first.get();
|
|
|
- userCostMap.put("finance", finance);
|
|
|
- userCostMap.put("percent", percent);
|
|
|
- userCostMap.put("project", f.getProjectName());
|
|
|
- userCostMap.put("projectId", f.getProjectId());
|
|
|
- userCostMap.put("projectCode", f.getProjectCode());
|
|
|
- noPUserDataList.add(userCostMap);
|
|
|
- } else {
|
|
|
- System.out.println("@@@@@@@noProjectUser中不存在该人员:"+username+"["+userId+"]");
|
|
|
+ /**添加非分摊项目筛选*/
|
|
|
+ List<FinanceProjects> financeProjects = financeProjectsMapper.getExcludeFinanceProjects(companyId,yearMonth);
|
|
|
+ if (financeProjects.size() == 0) {
|
|
|
+ //httpRespMsg.setError("缺少待分摊项目,请重新设置并保存分摊比例设置");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("project.lackApportion"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //检查是否已经设置好分配规则
|
|
|
+ ProjectPercentage percentage = projectPercentageMapper.selectOne(new QueryWrapper<ProjectPercentage>().eq("company_id", companyId).eq("ymonth", yearMonth));
|
|
|
+ List<Map> noPUserDataList = new ArrayList<>();
|
|
|
+ //构造各个项目的分配比例
|
|
|
+ if (percentage == null) {
|
|
|
+ //httpRespMsg.setError("请先设置无项目工时人员的分配比例");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("project.setPersonnelAllotment"));
|
|
|
+ return httpRespMsg;
|
|
|
+ } else {
|
|
|
+ //获取设置的项目
|
|
|
+ String data = percentage.getData();
|
|
|
+ JSONArray parse = JSONArray.parseArray(data);
|
|
|
+
|
|
|
+ //获取到无项目人员配置的项目
|
|
|
+ for (FinanceProjects f : financeProjects) {
|
|
|
+ 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()+"");
|
|
|
+ Optional<Finance> first = noProjectUser.stream().filter(no -> no.getUserId().equals(userId)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Finance finance = first.get();
|
|
|
+ userCostMap.put("finance", finance);
|
|
|
+ userCostMap.put("percent", percent);
|
|
|
+ userCostMap.put("project", f.getProjectName());
|
|
|
+ userCostMap.put("projectId", f.getProjectId());
|
|
|
+ userCostMap.put("projectCode", f.getProjectCode());
|
|
|
+ noPUserDataList.add(userCostMap);
|
|
|
+ } else {
|
|
|
+ System.out.println("@@@@@@@noProjectUser中不存在该人员:"+username+"["+userId+"]");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
- List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
|
|
|
- financeProjects.forEach(f->{
|
|
|
- if (!pList.stream().anyMatch(pItem->pItem.getProjectId().intValue() == 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);
|
|
|
+ List<FinanceProjects> notInFPList = new ArrayList<FinanceProjects>();
|
|
|
+ financeProjects.forEach(f->{
|
|
|
+ if (!pList.stream().anyMatch(pItem->pItem.getProjectId().intValue() == f.getProjectId())) {
|
|
|
+ notInFPList.add(f);
|
|
|
+ }
|
|
|
});
|
|
|
- }
|
|
|
- //按比例分配
|
|
|
- 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");
|
|
|
- //各项收入按比例计算,累加到当前项目上
|
|
|
- Finance newFinance = Finance.getByPercent(finance, percent);
|
|
|
- p.cost = p.cost.add(newFinance.getTotalCost());
|
|
|
- //叠加到总计的各项成本上
|
|
|
- totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
|
|
|
- percentTotal = percentTotal.add(newFinance.getTotalCost());
|
|
|
+ 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());
|
|
|
+ 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);
|
|
|
+ p.cost = p.cost.add(newFinance.getTotalCost());
|
|
|
+ //叠加到总计的各项成本上
|
|
|
+ totalMoneyCost = totalMoneyCost.add(newFinance.getTotalCost());
|
|
|
+ percentTotal = percentTotal.add(newFinance.getTotalCost());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|