|
@@ -9,15 +9,13 @@ import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.entity.OnPassag
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.mapper.OnPassageMaterialsMapper;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.reportPerson.entity.ReportPerson;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.reportPerson.mapper.ReportPersonMapper;
|
|
|
+import org.apache.shiro.crypto.hash.Hash;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
@@ -34,124 +32,63 @@ public class OnPassageMaterialsService extends CrudService<OnPassageMaterialsMap
|
|
|
private ReportPersonMapper reportPersonMapper;
|
|
|
|
|
|
public void comparativeData(List<OnPassageMaterials> onPassageMaterialsList, List<MaterialInformation> materialInformationList){
|
|
|
- List<String> goHeavy = new ArrayList<>();
|
|
|
- //物料编码 计划编制人相同
|
|
|
- List<OnPassageMaterials> sameList = new ArrayList<>();
|
|
|
- //计划编制人为空
|
|
|
- List<OnPassageMaterials> isEmptyList = new ArrayList<>();
|
|
|
- //统计物料编码 部门
|
|
|
- Map<String, String> materialCountMap = new HashMap<>();
|
|
|
- //统计物料编码 计划编制人相同合同数量
|
|
|
- Map<String, BigDecimal> sameMap = new HashMap<>();
|
|
|
- //统计计划编制人为空合同数量
|
|
|
- Map<String, BigDecimal> isEmptyMap = new HashMap<>();
|
|
|
- //在途物资表J列
|
|
|
- Map<String, BigDecimal> JMap = new HashMap<>();
|
|
|
- //项目物资需求表H列
|
|
|
- Map<String, BigDecimal> HMap = new HashMap<>();
|
|
|
-
|
|
|
- //从数据库中索取所有部门及提报人
|
|
|
- Map<String, List<ReportPerson>> reportPersonMap = getReportPerson();
|
|
|
+
|
|
|
+ //在途物资统计表 key=统计物料编码-部门 去重汇总统计
|
|
|
+ Map<String, BigDecimal> onPassageMaterialsMap = new HashMap<>();
|
|
|
+ //项目物资需求表 key=统计物料编码-部门 去重汇总统计
|
|
|
+ Map<String, BigDecimal> materialInformationMap = new HashMap<>();
|
|
|
+
|
|
|
+ //在途物资统计表 如果计划编制人为空存储
|
|
|
+ //Map<String, BigDecimal> isEmptyMap = new HashMap<>();
|
|
|
+
|
|
|
+ //在途物资统计表与项目物资需求表比较 在途物资统计表J列>=项目物资需求表H列 标识
|
|
|
+ List<String> flagList = new ArrayList<>();
|
|
|
/**************************************************************************/
|
|
|
- //循环比较找出 计划编制人为空添加isEmptyMap 根据计划编制人找出所在部门 物料编码-部门为去重条件
|
|
|
- onPassageMaterialsList.forEach(opm -> {
|
|
|
- String key = "";
|
|
|
- if (!opm.getPlanner().isEmpty()) {
|
|
|
- //计划编制人不为空存放
|
|
|
- String temp = opm.getMaterialCode() + "-" + opm.getPlanner();
|
|
|
- //去重 物料编码-计划编制人
|
|
|
- if(!goHeavy.contains(temp)){
|
|
|
- goHeavy.add(temp);
|
|
|
- sameList.add(opm);
|
|
|
- }
|
|
|
- String reportPersonOfDepartment = getReportPersonOfDepartment(reportPersonMap, opm.getPlanner());
|
|
|
- if (reportPersonOfDepartment!=null) {
|
|
|
- key = opm.getMaterialCode() + "-" + reportPersonOfDepartment;
|
|
|
- } else {
|
|
|
- key = opm.getMaterialCode()/* + "-"*/;
|
|
|
- }
|
|
|
|
|
|
- dataCount(sameMap, sameList, key);
|
|
|
- } else {
|
|
|
- //提报人为空
|
|
|
- /*key = opm.getMaterialCode();
|
|
|
- isEmptyList.add(opm);
|
|
|
- dataCount(isEmptyMap, isEmptyList, key);*/
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
+ //从数据库中获取所有的提报人与部门
|
|
|
+ Map<String, String> reportPersonMap = getReportPerson();
|
|
|
|
|
|
- materialInformationList.forEach(m -> {
|
|
|
- String key = "";
|
|
|
- if(!m.getReportingDepartment().isEmpty()){
|
|
|
- key = m.getMaterialCode() + "-" + m.getReportingDepartment();
|
|
|
- }else{
|
|
|
- key = m.getMaterialCode();
|
|
|
- }
|
|
|
- //如果有相同的去重不加
|
|
|
- if (materialCountMap.containsKey(key)) {
|
|
|
- /*BigDecimal temp = new BigDecimal(String.valueOf(materialCountMap.get(key)));
|
|
|
- temp = new BigDecimal(m.getTotal()).add(temp);
|
|
|
- materialCountMap.put(key, temp);*/
|
|
|
+ //在途物资统计表 去重汇总统计
|
|
|
+ onPassageMaterialsList.forEach(opm -> {
|
|
|
+ //根据提报人 找到对应部门
|
|
|
+ String reportPersonOfDepartment = reportPersonMap.get(opm.getPlanner());
|
|
|
+ //如果没有部门 表示空部门 物料编码-部门
|
|
|
+ String key = opm.getMaterialCode() + "-" + reportPersonOfDepartment;
|
|
|
+ if (onPassageMaterialsMap.containsKey(key)) {
|
|
|
+ onPassageMaterialsMap.put(key, new BigDecimal(opm.getContractCount()).add(onPassageMaterialsMap.get(key)));
|
|
|
} else {
|
|
|
- materialCountMap.put(key, m.getTotal());
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- materialCountMap.forEach((k, v) -> {
|
|
|
- String[] split = k.split("-");
|
|
|
- //如果有该部门则增加
|
|
|
- if(split.length==2){
|
|
|
- if (HMap.containsKey(split[1])) {
|
|
|
- BigDecimal temp = new BigDecimal(v).add(HMap.get(split[1]));
|
|
|
- HMap.put(split[1], temp);
|
|
|
- } else {
|
|
|
- HMap.put(split[1], new BigDecimal(v));
|
|
|
- }
|
|
|
+ onPassageMaterialsMap.put(key, new BigDecimal(opm.getContractCount()));
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
|
|
|
- sameMap.forEach((k, v) -> {
|
|
|
- String[] split = k.split("-");
|
|
|
- //如果有该部门则增加
|
|
|
- if(split.length==2){
|
|
|
- if (JMap.containsKey(split[1])) {
|
|
|
- BigDecimal temp = v.add(JMap.get(split[1]));
|
|
|
- JMap.put(split[1], temp);
|
|
|
- } else {
|
|
|
- JMap.put(split[1], v);
|
|
|
+ //项目物资需求表 去重汇总统计
|
|
|
+ materialInformationList.forEach(m -> {
|
|
|
+ //物料编码-部门
|
|
|
+ String key = m.getMaterialCode() + "-" + m.getReportingDepartment();
|
|
|
+ if (materialInformationMap.containsKey(key)) {
|
|
|
+ materialInformationMap.put(key, new BigDecimal(m.getTotal()).add(materialInformationMap.get(key)));
|
|
|
+ } else {
|
|
|
+ if(!m.getMaterialCode().isEmpty()&&!m.getTotal().isEmpty()){
|
|
|
+ materialInformationMap.put(key, new BigDecimal(m.getTotal()));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- /******************两表比较*******************/
|
|
|
-
|
|
|
- HMap.forEach((k, v) -> {
|
|
|
- if (JMap.containsKey(k)) {
|
|
|
- if (JMap.get(k).compareTo(v) >= 0) {
|
|
|
- materialInformationList.forEach(m -> {
|
|
|
- if (m.getReportingDepartment().equals(k)) {
|
|
|
- m.setRemarkText("在途已有" + JMap.get(k) + "单位,请核实本次需求");
|
|
|
- }
|
|
|
- });
|
|
|
+ //两表比较 添加标识
|
|
|
+ materialInformationMap.forEach((k,v)->{
|
|
|
+ if(onPassageMaterialsMap.containsKey(k)){
|
|
|
+ if(onPassageMaterialsMap.get(k).compareTo(v)>=0){
|
|
|
+ flagList.add(k);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
|
|
|
- private void dataCount(Map<String, BigDecimal> map, List<OnPassageMaterials> list, String key) {
|
|
|
- list.forEach(l -> {
|
|
|
- //如果有相同就不加去重
|
|
|
- if (map.containsKey(key)) {
|
|
|
- BigDecimal temp = new BigDecimal(String.valueOf(map.get(key)));
|
|
|
- temp = new BigDecimal(l.getContractCount()).add(temp);
|
|
|
- map.put(key, temp);
|
|
|
-
|
|
|
- } else {
|
|
|
- map.put(key, new BigDecimal(l.getContractCount()));
|
|
|
+ //根据标识在原表中追加备注
|
|
|
+ materialInformationList.forEach(l->{
|
|
|
+ String key = l.getMaterialCode() + "-" + l.getReportingDepartment();
|
|
|
+ if(flagList.contains(key)){
|
|
|
+ l.setRemarkText("在途已有" + onPassageMaterialsMap.get(key)+"单位,请核实本次需求");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -160,38 +97,16 @@ public class OnPassageMaterialsService extends CrudService<OnPassageMaterialsMap
|
|
|
* 查询数据库获取对应的部门及部门下的人
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String,List<ReportPerson>> getReportPerson(){
|
|
|
- Map<String,List<ReportPerson>> map = new HashMap<>();
|
|
|
- /*List<String> department = reportPersonMapper.findDepartment();
|
|
|
- department.forEach(l->{
|
|
|
- map.put(l,reportPersonMapper.findDepartmentOfPerson(l));
|
|
|
- });*/
|
|
|
+ private Map<String,String> getReportPerson(){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
List<ReportPerson> departmentGroupByPerson = reportPersonMapper.findDepartmentGroupByPerson();
|
|
|
departmentGroupByPerson.forEach(l->{
|
|
|
- if(map.containsKey(l.getReportDepartment())){
|
|
|
- map.get(l.getReportDepartment()).add(l);
|
|
|
- }else{
|
|
|
- List<ReportPerson> reportPeople = new ArrayList<>();
|
|
|
- reportPeople.add(l);
|
|
|
- map.put(l.getReportDepartment(),reportPeople);
|
|
|
- }
|
|
|
+ map.put(l.getReportPerson(),l.getReportDepartment());
|
|
|
});
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取提报人部门
|
|
|
- */
|
|
|
- private String getReportPersonOfDepartment(Map<String, List<ReportPerson>> reportPerson,String name){
|
|
|
- AtomicReference<String> departmentName = new AtomicReference<>();
|
|
|
- reportPerson.forEach((k,v)->{
|
|
|
- v.forEach(l->{
|
|
|
- if(l.getReportPerson().equals(name)){
|
|
|
- departmentName.set(k);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- return departmentName.get();
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|