|
|
@@ -0,0 +1,1109 @@
|
|
|
+package com.poteviohealth.cgp.statistics.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.poteviohealth.cgp.common.integrated.ListParams;
|
|
|
+import com.poteviohealth.cgp.common.integrated.customer.model.CustomerServiceParams;
|
|
|
+import com.poteviohealth.cgp.common.integrated.customer.model.CustomerSubsidyDTO;
|
|
|
+import com.poteviohealth.cgp.common.integrated.customer.model.SubsidyCustomerFace;
|
|
|
+import com.poteviohealth.cgp.common.integrated.customer.model.SubsidyCustomerJsonFace;
|
|
|
+import com.poteviohealth.cgp.common.integrated.finance.model.MemberListData;
|
|
|
+import com.poteviohealth.cgp.common.integrated.finance.model.MonthData;
|
|
|
+import com.poteviohealth.cgp.common.integrated.order.model.OrderStatisticsData;
|
|
|
+import com.poteviohealth.cgp.common.integrated.partner.model.AreaDTO;
|
|
|
+import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationFace;
|
|
|
+import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationJsonFace;
|
|
|
+import com.poteviohealth.cgp.statistics.mapper.QujingOrderMapper;
|
|
|
+import com.poteviohealth.cgp.statistics.model.Order;
|
|
|
+import com.poteviohealth.cgp.statistics.model.outdto.*;
|
|
|
+import com.poteviohealth.cgp.statistics.service.IQujingOrderService;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 居家大屏
|
|
|
+ * @author Qin
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class QujingOrderServiceImpl implements IQujingOrderService {
|
|
|
+ @Resource
|
|
|
+ private QujingOrderMapper baseMapper;
|
|
|
+
|
|
|
+ @Value("${sync.dbName}")
|
|
|
+ private String dbName;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void statisticsOrder(String dateTime, Integer operatorId, Integer supplierId){
|
|
|
+ try {
|
|
|
+ //检查区域,没有的新增
|
|
|
+ List<Order> list = baseMapper.listAll();
|
|
|
+ /* Date date = new Date();
|
|
|
+ if(StringUtils.isNotEmpty(dateTime)){
|
|
|
+ date = DateUtils.parseDate(dateTime,"yyyy-MM-dd HH:mm:ss");
|
|
|
+ }*/
|
|
|
+
|
|
|
+ List<AreaDTO> areaList = baseMapper.areaList(dbName);
|
|
|
+ if(list.size() != areaList.size()){
|
|
|
+ List<Integer> ids = Lists.newArrayList();
|
|
|
+ List<Order> newOrderList = Lists.newArrayList();
|
|
|
+ if(list.size()>0){
|
|
|
+ ids = list.stream().map(o->o.getAreaId()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ for (AreaDTO areaDTO : areaList) {
|
|
|
+ if(!ids.contains(areaDTO.getId())){
|
|
|
+ Order order = new Order();
|
|
|
+ order.setOperatorId(operatorId);
|
|
|
+ order.setAreaId(areaDTO.getId());
|
|
|
+ order.setAreaName(areaDTO.getName());
|
|
|
+ order.setTreePath(areaDTO.getTreePath());
|
|
|
+ order.setSourceLevel(areaDTO.getLevel());
|
|
|
+ Integer size = 0;
|
|
|
+ switch (order.getSourceLevel()){
|
|
|
+ case 1:
|
|
|
+ size =4;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ size =6;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ size =9;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(areaDTO.getRegionAreaCode())){
|
|
|
+ order.setRegionAreaCode(areaDTO.getRegionAreaCode().substring(0,size));
|
|
|
+ }
|
|
|
+
|
|
|
+ newOrderList.add(order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(Order o:newOrderList) {
|
|
|
+ baseMapper.saveOrder(o);
|
|
|
+ }
|
|
|
+ list = baseMapper.listAll();
|
|
|
+ }
|
|
|
+ Map<Integer,List<Order>> maps = list.stream().collect(Collectors.groupingBy(Order::getAreaId));
|
|
|
+
|
|
|
+ if(!maps.isEmpty()){
|
|
|
+ /* log.info("---数据清零开始---");
|
|
|
+ changeZero(maps,date);
|
|
|
+ log.info("---数据清零结束---");*/
|
|
|
+ //更新服务人员数据
|
|
|
+ log.info("---更新服务人员数据开始---");
|
|
|
+ changeEmployee(maps,supplierId);
|
|
|
+ log.info("---更新服务人员数据结束---");
|
|
|
+// List<Integer> operatorIds = Collections.singletonList(operatorId);
|
|
|
+ log.info("---获取客户数据开始---");
|
|
|
+ List<CustomerSubsidyDTO> customerList = this.getSubsidyCustomerList(operatorId,supplierId);
|
|
|
+ log.info("---获取客户数据结束---");
|
|
|
+ //更新客户数据
|
|
|
+ if(!customerList.isEmpty()){
|
|
|
+ log.info("---更新客户数据开始---");
|
|
|
+ changeCustomer(maps,customerList,operatorId,supplierId);
|
|
|
+ log.info("---更新客户数据结束---");
|
|
|
+ }
|
|
|
+ //获取助餐服务客户数
|
|
|
+ List<ListParams> mealList = this.getSubsidyCustomerMealList(operatorId,supplierId);
|
|
|
+ if(CollectionUtils.isNotEmpty(mealList)){
|
|
|
+ for (Integer integer : maps.keySet()) {
|
|
|
+ for (ListParams params : mealList) {
|
|
|
+ if(params.getId().equals(integer)){
|
|
|
+ for (Order order : maps.get(integer)) {
|
|
|
+ order.setServiceCustomerNum(params.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新工单相关数据
|
|
|
+ log.info("---更新工单数据开始---");
|
|
|
+ List<ListParams> categoryList = baseMapper.getAllCategory(dbName);
|
|
|
+ changeOrder(maps,operatorId,categoryList,supplierId);
|
|
|
+ changeOrderVisit(maps,operatorId,supplierId);
|
|
|
+ log.info("---更新工单数据结束---");
|
|
|
+ //更新积分相关数据
|
|
|
+ log.info("---更新商户积分数据开始---");
|
|
|
+ changeIntegral(maps,operatorId,categoryList,supplierId);
|
|
|
+ log.info("---更新商户积分数据结束---");
|
|
|
+
|
|
|
+ log.info("---客户积分开始获取---");
|
|
|
+ changeCustomerIntegral(maps,supplierId);
|
|
|
+ log.info("---客户积分结束获取---");
|
|
|
+ log.info("---积分流水开始获取---");
|
|
|
+ changeTransIntegral(maps,supplierId);
|
|
|
+ log.info("---积分流水结束获取---");
|
|
|
+// this.saveOrUpdateBatch(list);
|
|
|
+ for (Order o:list){
|
|
|
+ baseMapper.updateOrder(o);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("完成----");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<ListParams> getSubsidyCustomerMealList(Integer operatorId, Integer supplierId){
|
|
|
+ List<ListParams> returnList = Lists.newArrayList();
|
|
|
+ //获取签约客户信息
|
|
|
+ List<Customer> dto = baseMapper.getSubsidyCustomerMealList(operatorId,dbName,supplierId);
|
|
|
+ if(!dto.isEmpty()){
|
|
|
+ Map<Integer,List<Customer>> streetMaps = dto.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(Customer::getNowStreetId));
|
|
|
+ getMealData(streetMaps,returnList);
|
|
|
+ //按照区分组
|
|
|
+ Map<Integer,List<Customer>> countryMaps = dto.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(Customer::getNowCountryId));
|
|
|
+ getMealData(countryMaps,returnList);
|
|
|
+ //按照市分组
|
|
|
+ Map<Integer,List<Customer>> cityMaps = dto.stream().filter(c->c.getNowCityId() != null).collect(Collectors.groupingBy(Customer::getNowCityId));
|
|
|
+ getMealData(cityMaps,returnList);
|
|
|
+ }
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getMealData(Map<Integer,List<Customer>> maps,List<ListParams> returnList){
|
|
|
+
|
|
|
+ for (Integer integer : maps.keySet()) {
|
|
|
+ ListParams params = new ListParams();
|
|
|
+ params.setId(integer);
|
|
|
+ params.setKey(maps.get(integer).size());
|
|
|
+ returnList.add(params);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CustomerSubsidyDTO> getSubsidyCustomerList(Integer operatorId,Integer supplierId){
|
|
|
+ //获取签约客户信息
|
|
|
+ return baseMapper.getSubsidyCustomerList(operatorId,dbName,supplierId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeEmployee(Map<Integer, List<Order>> maps,Integer supplierId) {
|
|
|
+
|
|
|
+ List<EmployeeStationFace> employeeStationFaces = this.getEmployeeStationFace(supplierId);
|
|
|
+ for (EmployeeStationFace employeeStationFace : employeeStationFaces) {
|
|
|
+ List<Order> orders = maps.get(employeeStationFace.getAreaId());
|
|
|
+ if(orders != null){
|
|
|
+ for (Order order : orders) {
|
|
|
+ order.setAllStationNum(employeeStationFace.getAllStationNum());
|
|
|
+ order.setEmployeeNum(employeeStationFace.getNum());
|
|
|
+ order.setEmployeeList(employeeStationFace.getLists());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getEmployeeData(Map<Integer,List<SupplierStation>> stationMaps, List<Employee> employeeList, List<SupplierStationEmployee> stationEmployeeList, List<EmployeeStationFace> returnList){
|
|
|
+ for (Integer integer : stationMaps.keySet()) {
|
|
|
+ List<SupplierStation> stations = stationMaps.get(integer);
|
|
|
+ if(org.springframework.util.CollectionUtils.isEmpty(stations)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ EmployeeStationFace face = new EmployeeStationFace();
|
|
|
+ face.setAreaId(integer);
|
|
|
+
|
|
|
+ List<Integer> stationIds = stations.stream().map(s->s.getId()).collect(Collectors.toList());
|
|
|
+ List<Integer> employeeIds = stationEmployeeList.stream().filter(se->stationIds.contains(se.getStationId())).map(se->se.getEmployeeId()
|
|
|
+ ).distinct().collect(Collectors.toList());
|
|
|
+ List<Employee> employees = employeeList.stream().filter(e->employeeIds.contains(e.getId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ face.setAllStationNum(stationIds.size());
|
|
|
+ face.setNum(employees.size());
|
|
|
+ EmployeeStationJsonFace json = new EmployeeStationJsonFace();
|
|
|
+ json.setTotal(face.getNum());
|
|
|
+ json.setTitle(Lists.newArrayList("30以下","30-39","40-49","50-59","60及以上"));
|
|
|
+ //按照年龄30以下,30-39,40-49,50-59,60以上
|
|
|
+ List<String> maleList = Lists.newArrayList();
|
|
|
+ List<String> womanList = Lists.newArrayList();
|
|
|
+ List<Employee> thirtyDown = employees.stream().filter(e->e.getAge()<30).collect(Collectors.toList());
|
|
|
+ Long thirtyDownMale = thirtyDown.stream().filter(e->e.getGender().equals(1)).count();
|
|
|
+ Long thirtyDownWoman = thirtyDown.stream().filter(e->e.getGender().equals(0)).count();
|
|
|
+ maleList.add(thirtyDownMale.toString());
|
|
|
+ womanList.add(thirtyDownWoman.toString());
|
|
|
+ List<Employee> thirty = employees.stream().filter(e->e.getAge()>=30 && e.getAge()<40).collect(Collectors.toList());
|
|
|
+ Long thirtyMale = thirty.stream().filter(e->e.getGender().equals(1)).count();
|
|
|
+ Long thirtyWoman = thirty.stream().filter(e->e.getGender().equals(0)).count();
|
|
|
+ maleList.add(thirtyMale.toString());
|
|
|
+ womanList.add(thirtyWoman.toString());
|
|
|
+ List<Employee> forty = employees.stream().filter(e->e.getAge()>=40 && e.getAge()<50).collect(Collectors.toList());
|
|
|
+ Long fortyMale = forty.stream().filter(e->e.getGender().equals(1)).count();
|
|
|
+ Long fortyWoman = forty.stream().filter(e->e.getGender().equals(0)).count();
|
|
|
+ maleList.add(fortyMale.toString());
|
|
|
+ womanList.add(fortyWoman.toString());
|
|
|
+ List<Employee> fifty = employees.stream().filter(e->e.getAge()>=50 && e.getAge()<60).collect(Collectors.toList());
|
|
|
+ Long fiftyMale = fifty.stream().filter(e->e.getGender().equals(1)).count();
|
|
|
+ Long fiftyWoman = fifty.stream().filter(e->e.getGender().equals(0)).count();
|
|
|
+ maleList.add(fiftyMale.toString());
|
|
|
+ womanList.add(fiftyWoman.toString());
|
|
|
+ List<Employee> sixtyUp = employees.stream().filter(e->e.getAge()>=60).collect(Collectors.toList());
|
|
|
+ Long sixtyUpMale = sixtyUp.stream().filter(e->e.getGender().equals(1)).count();
|
|
|
+ Long sixtyUpWoman = sixtyUp.stream().filter(e->e.getGender().equals(0)).count();
|
|
|
+ maleList.add(sixtyUpMale.toString());
|
|
|
+ womanList.add(sixtyUpWoman.toString());
|
|
|
+ //按照性别分组
|
|
|
+ json.setMale(maleList);
|
|
|
+ json.setWoman(womanList);
|
|
|
+ face.setLists(JSONObject.toJSONString(json));
|
|
|
+ returnList.add(face);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<EmployeeStationFace> getEmployeeStationFace(Integer supplierId){
|
|
|
+ List<EmployeeStationFace> returnList = Lists.newArrayList();
|
|
|
+ //获取驿站员工信息
|
|
|
+ List<SupplierStationEmployee> stationEmployeeList = baseMapper.supplierStationEmployeeList(dbName,supplierId);
|
|
|
+ //获取驿站
|
|
|
+ List<SupplierStation> stationList = baseMapper.supplierStationList(dbName,supplierId);
|
|
|
+ //获取员工
|
|
|
+ List<Employee> employeeList = baseMapper.employeeList(dbName,supplierId);
|
|
|
+
|
|
|
+ //按照街道分组
|
|
|
+ Map<Integer,List<SupplierStation>> stationStreetMaps = stationList.stream().filter(s->s.getStreet() != null).collect(Collectors.groupingBy(SupplierStation::getStreet));
|
|
|
+ getEmployeeData(stationStreetMaps,employeeList,stationEmployeeList,returnList);
|
|
|
+ //按照区分组
|
|
|
+ Map<Integer,List<SupplierStation>> stationCountryMaps = stationList.stream().filter(s->s.getCountry() != null).collect(Collectors.groupingBy(SupplierStation::getCountry));
|
|
|
+ getEmployeeData(stationCountryMaps,employeeList,stationEmployeeList,returnList);
|
|
|
+ //按照市分组
|
|
|
+ Map<Integer,List<SupplierStation>> stationCityMaps = stationList.stream().filter(s->s.getCity() != null).collect(Collectors.groupingBy(SupplierStation::getCity));
|
|
|
+ getEmployeeData(stationCityMaps,employeeList,stationEmployeeList,returnList);
|
|
|
+
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SubsidyCustomerFace> getSubsidyCustomerFace(List<CustomerSubsidyDTO> customerList){
|
|
|
+
|
|
|
+ List<SubsidyCustomerFace> returnList = Lists.newArrayList();
|
|
|
+
|
|
|
+ //按照街道分组
|
|
|
+ Map<Integer,List<CustomerSubsidyDTO>> streetMaps = customerList.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowStreetId));
|
|
|
+ fillData(streetMaps,returnList,3);
|
|
|
+ //按照区分组
|
|
|
+ Map<Integer,List<CustomerSubsidyDTO>> countryMaps = customerList.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId));
|
|
|
+ fillData(countryMaps,returnList,2);
|
|
|
+ //按照市分组
|
|
|
+ Map<Integer,List<CustomerSubsidyDTO>> cityMaps = customerList.stream().filter(c->c.getNowCityId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCityId));
|
|
|
+ fillData(cityMaps,returnList,1);
|
|
|
+// //探访关爱--已单独汇总,此处不再处理
|
|
|
+// customerSubsidyVisitService.processCare(returnList,operatorIds);
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void fillData(Map<Integer,List<CustomerSubsidyDTO>> maps, List<SubsidyCustomerFace> returnList,Integer source){
|
|
|
+ for (Integer integer : maps.keySet()) {
|
|
|
+ List<CustomerSubsidyDTO> csList = maps.get(integer);
|
|
|
+ SubsidyCustomerFace face = new SubsidyCustomerFace();
|
|
|
+ face.setAreaId(integer);
|
|
|
+ face.setNum(csList.size());
|
|
|
+ face.setCareAllMember(csList.stream().mapToInt(e-> org.apache.commons.lang.StringUtils.isNotEmpty(e.getCustomerSignId())?1:0).sum());
|
|
|
+ List<Long> ids = csList.stream().map(c->c.getCustomerId()).collect(Collectors.toList());
|
|
|
+ face.setCustomerIds(ids);
|
|
|
+ // List<Long> intersectionList = (List<Long>) CollectionUtils.intersection(face.getCustomerIds(),cardCustomer);
|
|
|
+ face.setCustomerGovernmentNum(csList.stream().filter(c->c.getCategory().equals(1)).collect(Collectors.toList()).size());
|
|
|
+ face.setCustomerSocietyNum(face.getNum()-face.getCustomerGovernmentNum());
|
|
|
+ face.setAllCustomerNum(csList.stream().filter(c ->c.getAge() != null && c.getAge() >= 75).collect(Collectors.toList()).size());
|
|
|
+
|
|
|
+ MemberListData data = new MemberListData();
|
|
|
+ Long totalDetailList = csList.stream().filter(d -> d.getCategory().equals(1)).count();
|
|
|
+ data.setTotal(Integer.parseInt(totalDetailList.toString()));
|
|
|
+ data.setTitle(Lists.newArrayList("50以下","50-59", "60-69", "70-79", "80-89", "90及以上"));
|
|
|
+ List<Integer> maleAgeList = Lists.newArrayList();
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() < 50).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 50 && c.getAge() < 60).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 60 && c.getAge() < 70).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 70 && c.getAge() < 80).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 80 && c.getAge() < 90).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 90).collect(Collectors.toList()).size());
|
|
|
+ data.setMale(maleAgeList);
|
|
|
+ List<Integer> womanAgeList = Lists.newArrayList();
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() < 50).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 50 && c.getAge() < 60).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 60 && c.getAge() < 70).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 70 && c.getAge() < 80).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 80 && c.getAge() < 90).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c ->c.getCategory().equals(1) && c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 90).collect(Collectors.toList()).size());
|
|
|
+ data.setWoman(womanAgeList);
|
|
|
+ face.setCustomerAgeListData(data);
|
|
|
+
|
|
|
+ List<SubsidyCustomerJsonFace> jsonFaceList = Lists.newArrayList();
|
|
|
+ if(source.equals(1)){
|
|
|
+ //按区域分组
|
|
|
+ Map<Integer,List<CustomerSubsidyDTO>> countryMaps = csList.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId));
|
|
|
+ for (Integer key : countryMaps.keySet()) {
|
|
|
+ List<CustomerSubsidyDTO> keyList = countryMaps.get(key);
|
|
|
+ SubsidyCustomerJsonFace jsonFace = new SubsidyCustomerJsonFace();
|
|
|
+ jsonFace.setAreaId(key);
|
|
|
+ jsonFace.setTitle(keyList.get(0).getNowCountryName());
|
|
|
+ jsonFace.setTotal(keyList.size());
|
|
|
+ jsonFace.setCustomerIds(keyList.stream().map(c->c.getCustomerId()).collect(Collectors.toList()));
|
|
|
+ jsonFaceList.add(jsonFace);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //按老人类型分组
|
|
|
+ Map<String,List<CustomerSubsidyDTO>> typeMaps = csList.stream().filter(c->StringUtils.isNotEmpty(c.getCustomerTypeId())).collect(Collectors.groupingBy(CustomerSubsidyDTO::getCustomerTypeId));
|
|
|
+
|
|
|
+ Map<String,SubsidyCustomerJsonFace> faceMap = Maps.newHashMap();
|
|
|
+ for (String key : typeMaps.keySet()) {
|
|
|
+
|
|
|
+ List<CustomerSubsidyDTO> keyList = typeMaps.get(key);
|
|
|
+ List<Long> idList = keyList.stream().map(CustomerSubsidyDTO::getCustomerId).collect(Collectors.toList());
|
|
|
+ String customerType = keyList.get(0).getCustomerType();
|
|
|
+ if (key.contains(",")){
|
|
|
+ String[] typeIds = key.split(",");
|
|
|
+ String[] names = customerType.split(",");
|
|
|
+ for (int i=0; i<typeIds.length; i++){
|
|
|
+ String keyType = typeIds[i];
|
|
|
+ mergeJsonFace(faceMap, keyType, idList.size(), names[i]);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ mergeJsonFace(faceMap, key, idList.size(), customerType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonFaceList.addAll(faceMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ face.setJsonFace(jsonFaceList);
|
|
|
+ returnList.add(face);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void mergeJsonFace(Map<String, SubsidyCustomerJsonFace> faceMap, String key, Integer idListSize, String customerType) {
|
|
|
+ SubsidyCustomerJsonFace jsonFace = faceMap.get(key);
|
|
|
+ if (jsonFace== null){
|
|
|
+ jsonFace = new SubsidyCustomerJsonFace();
|
|
|
+ jsonFace.setAreaId(Integer.parseInt(key));
|
|
|
+ jsonFace.setTitle(customerType);
|
|
|
+ jsonFace.setTotal(idListSize);
|
|
|
+ //jsonFace.setCustomerIds(idList);
|
|
|
+ faceMap.put(key, jsonFace);
|
|
|
+ }else{
|
|
|
+ //jsonFace.getCustomerIds().addAll(idList);
|
|
|
+ jsonFace.setTotal(jsonFace.getTotal()+idListSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CustomerServiceParams> orderServiceCustomerList(Integer operatorId, Integer supplierId){
|
|
|
+ return baseMapper.orderServiceCustomerList(operatorId,dbName,supplierId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeCustomer(Map<Integer, List<Order>> maps,List<CustomerSubsidyDTO> customerList,Integer operatorId,Integer supplierId) {
|
|
|
+ //更新客户数据
|
|
|
+ List<SubsidyCustomerFace> customerFaceList = this.getSubsidyCustomerFace(customerList);
|
|
|
+ //获取已服务老人Id集合
|
|
|
+ List<CustomerServiceParams> serviceCustomerList = this.orderServiceCustomerList(operatorId,supplierId);
|
|
|
+ for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) {
|
|
|
+ List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
|
|
|
+ if(orders == null || orders.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Order order : orders) {
|
|
|
+ order.setCustomerNum(subsidyCustomerFace.getNum());
|
|
|
+ order.setCustomerGovernmentNum(subsidyCustomerFace.getCustomerGovernmentNum());
|
|
|
+ order.setCustomerSocietyNum(subsidyCustomerFace.getCustomerSocietyNum());
|
|
|
+ order.setCareRate(BigDecimal.ZERO);
|
|
|
+ order.setAllCustomerNum(subsidyCustomerFace.getAllCustomerNum());
|
|
|
+ order.setCareNum(0);
|
|
|
+ order.setCarePic("");
|
|
|
+ order.setCareMember(0);
|
|
|
+ order.setCareAllMember(0);
|
|
|
+ //已服务老人数
|
|
|
+ Long serviceSum = 0L;
|
|
|
+ if(order.getSourceLevel() == 1){
|
|
|
+ serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getCityId())).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }else if(order.getSourceLevel() == 2){
|
|
|
+ serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getCountryId())).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }else{
|
|
|
+ serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getStreetId())).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }
|
|
|
+ order.setCustomerServiceNum(serviceSum.intValue());
|
|
|
+ if(order.getCustomerNum().equals(0)){
|
|
|
+ order.setCustomerRate(BigDecimal.ZERO);
|
|
|
+ }else{
|
|
|
+ BigDecimal decimal = new BigDecimal(order.getCustomerServiceNum()).multiply(new BigDecimal(100.0)).divide(new BigDecimal(order.getCustomerNum()),2,BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ order.setCustomerRate(decimal);
|
|
|
+ }
|
|
|
+ List<SubsidyCustomerJsonFace> jsonFace = subsidyCustomerFace.getJsonFace();
|
|
|
+ List<String> id = Lists.newArrayList();
|
|
|
+ List<String> title = Lists.newArrayList();
|
|
|
+ List<Integer> total = Lists.newArrayList();
|
|
|
+ List<BigDecimal> rate = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (SubsidyCustomerJsonFace face : jsonFace) {
|
|
|
+ Integer num = face.getTotal();
|
|
|
+ Long sum = 0L;
|
|
|
+ if(serviceCustomerList != null && !serviceCustomerList.isEmpty() && order.getSourceLevel().equals(1)){
|
|
|
+ sum = serviceCustomerList.stream().filter(s->(face.getAreaId().equals(s.getCountryId()) || face.getAreaId().equals(s.getStreetId()))).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }else{
|
|
|
+ if(order.getSourceLevel().equals(2)){
|
|
|
+ sum = serviceCustomerList.stream().filter(s->s.getCountryId().equals(order.getAreaId()) && StringUtils.isNotEmpty(s.getCustomerTypeId()) && s.getCustomerTypeId().contains(","+face.getAreaId().toString()+",")).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }else if (order.getSourceLevel().equals(3) ){
|
|
|
+ sum = serviceCustomerList.stream().filter(s->s.getStreetId().equals(order.getAreaId()) && StringUtils.isNotEmpty(s.getCustomerTypeId()) && s.getCustomerTypeId().contains(","+face.getAreaId().toString()+",")).mapToLong(s->s.getCustomerNum()).sum();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ id.add(face.getAreaId().toString());
|
|
|
+ title.add(face.getTitle());
|
|
|
+ total.add(face.getTotal());
|
|
|
+
|
|
|
+ if(num.equals(0)){
|
|
|
+ rate.add(BigDecimal.ZERO);
|
|
|
+ }else {
|
|
|
+ BigDecimal decimal2 = new BigDecimal(sum).multiply(new BigDecimal(100.0)).divide(new BigDecimal(num), 2, BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ rate.add(decimal2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SubsidyCustomerJsonVo vo = new SubsidyCustomerJsonVo();
|
|
|
+ vo.setId(id);
|
|
|
+ vo.setTitle(title);
|
|
|
+ vo.setTotal(total);
|
|
|
+ vo.setRate(rate);
|
|
|
+ order.setCustomerList(JSONObject.toJSONString(vo));
|
|
|
+
|
|
|
+ if(subsidyCustomerFace.getCustomerAgeListData() != null){
|
|
|
+ order.setCustomerAgeList(JSONObject.toJSONString(subsidyCustomerFace.getCustomerAgeListData()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SubsidyCustomerFace> integralCustomer(Integer supplierId){
|
|
|
+ List<SubsidyCustomerFace> returnList = Lists.newArrayList();
|
|
|
+ List<Integer> operationIds = baseMapper.getIntegralCardAccOperatorIdList(dbName,supplierId);
|
|
|
+
|
|
|
+ List<IntegralTrans> detailsCustomer = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (Integer operationId : operationIds) {
|
|
|
+ //获取积分数据
|
|
|
+ detailsCustomer.addAll(baseMapper.integralCustomerList(operationId,dbName,supplierId));
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("---处理积分客户数据开始----");
|
|
|
+ if(!detailsCustomer.isEmpty()){
|
|
|
+ Map<Integer,List<IntegralTrans>> streetCustomerMaps = detailsCustomer.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId));
|
|
|
+ fillData(streetCustomerMaps,returnList);
|
|
|
+
|
|
|
+ Map<Integer,List<IntegralTrans>> cityCustomerMaps = detailsCustomer.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId));
|
|
|
+ fillData(cityCustomerMaps,returnList);
|
|
|
+
|
|
|
+ Map<Integer,List<IntegralTrans>> countryCustomerMaps = detailsCustomer.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId));
|
|
|
+ fillData(countryCustomerMaps,returnList);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("---处理积分客户数据结束----");
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillData(Map<Integer,List<IntegralTrans>> mapCustomerData, List<SubsidyCustomerFace> returnList){
|
|
|
+ for (Integer integer : mapCustomerData.keySet()) {
|
|
|
+ List<IntegralTrans> csList = mapCustomerData.get(integer);
|
|
|
+ SubsidyCustomerFace face = new SubsidyCustomerFace();
|
|
|
+ face.setAreaId(integer);
|
|
|
+ face.setCustomerNum(csList.size());
|
|
|
+
|
|
|
+ MemberListData data = new MemberListData();
|
|
|
+ List<IntegralTrans> totalDetailList = csList.stream().filter(d -> d.getCreatedDate().after(com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date()))).collect(Collectors.toList());
|
|
|
+ data.setTotal(totalDetailList.size());
|
|
|
+ data.setTitle(Lists.newArrayList("60以下", "60-69", "70-79", "80-89", "90及以上"));
|
|
|
+ List<Integer> maleAgeList = Lists.newArrayList();
|
|
|
+ maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() < 60).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 60 && c.getAge() < 70).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 70 && c.getAge() < 80).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 80 && c.getAge() < 90).collect(Collectors.toList()).size());
|
|
|
+ maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 90).collect(Collectors.toList()).size());
|
|
|
+ data.setMale(maleAgeList);
|
|
|
+ List<Integer> womanAgeList = Lists.newArrayList();
|
|
|
+ womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() < 60).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 60 && c.getAge() < 70).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 70 && c.getAge() < 80).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 80 && c.getAge() < 90).collect(Collectors.toList()).size());
|
|
|
+ womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 90).collect(Collectors.toList()).size());
|
|
|
+ data.setWoman(womanAgeList);
|
|
|
+ face.setMemberListData(data);
|
|
|
+
|
|
|
+ returnList.add(face);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeCustomerIntegral(Map<Integer, List<Order>> maps,Integer supplierId) {
|
|
|
+ List<SubsidyCustomerFace> integralList = this.integralCustomer(supplierId);
|
|
|
+ for (SubsidyCustomerFace subsidyCustomerFace : integralList) {
|
|
|
+ List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
|
|
|
+ if (CollectionUtils.isEmpty(orders)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Order order : orders) {
|
|
|
+ //积分相关
|
|
|
+ if(order.getPointMember() == null){
|
|
|
+ order.setPointMember(0);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getCustomerNum() != null){
|
|
|
+ order.setPointMember(subsidyCustomerFace.getCustomerNum());
|
|
|
+ }
|
|
|
+ order.setMemberListData(JSONObject.toJSONString(subsidyCustomerFace.getMemberListData()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<SubsidyCustomerFace> integralTrans(Integer supplierId){
|
|
|
+ List<SubsidyCustomerFace> returnList = Lists.newArrayList();
|
|
|
+ List<Integer> operationIds = baseMapper.getIntegralCardDetailOperatorIdList(dbName,supplierId);
|
|
|
+ List<IntegralTrans> detailsTrans = Lists.newArrayList();
|
|
|
+ for (Integer operationId : operationIds) {
|
|
|
+ //获取积分数据
|
|
|
+ detailsTrans.addAll(baseMapper.integralTransList(operationId,dbName,supplierId));
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("---处理流水数据开始----");
|
|
|
+ Map<Integer,List<IntegralTrans>> streetTransMaps = detailsTrans.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId));
|
|
|
+
|
|
|
+ fillData2(streetTransMaps,returnList);
|
|
|
+ Map<Integer,List<IntegralTrans>> cityTransMaps = detailsTrans.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId));
|
|
|
+
|
|
|
+ fillData2(cityTransMaps,returnList);
|
|
|
+ Map<Integer,List<IntegralTrans>> countryTransMaps = detailsTrans.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId));
|
|
|
+
|
|
|
+ fillData2(countryTransMaps,returnList);
|
|
|
+ log.info("---处理流水数据结束----");
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillData2(Map<Integer,List<IntegralTrans>> data2,List<SubsidyCustomerFace> returnList){
|
|
|
+ for (Integer integer : data2.keySet()) {
|
|
|
+ List<IntegralTrans> dataList = data2.get(integer);
|
|
|
+ SubsidyCustomerFace face = new SubsidyCustomerFace();
|
|
|
+ face.setAreaId(integer);
|
|
|
+
|
|
|
+ Long grantSum = dataList.stream().filter(t -> t.getTransType().equals("0")).mapToLong(t -> t.getAmount()).sum();
|
|
|
+ face.setGrantNum(grantSum);
|
|
|
+ Long exchangeSum = dataList.stream().filter(t -> t.getTransType().equals("1")).mapToLong(t -> t.getAmount()).sum();
|
|
|
+ face.setExchangeNum(exchangeSum);
|
|
|
+
|
|
|
+ Long grantWmSum = dataList.stream().filter(t -> t.getTransType().equals("0") && t.getRemark() !=null && t.getRemark().contains("文明积分")).mapToLong(t -> t.getAmount()).sum();
|
|
|
+ face.setGrantNumWm(grantWmSum);
|
|
|
+ Long grantYlSum = dataList.stream().filter(t -> t.getTransType().equals("0") && t.getRemark() !=null && t.getRemark().contains("银龄积分")).mapToLong(t -> t.getAmount()).sum();
|
|
|
+ face.setGrantNumYl(grantYlSum);
|
|
|
+ Long exchangeWmSum = dataList.stream().filter(t -> t.getTransType().equals("1") && t.getRemark() !=null && t.getRemark().contains("文明积分")).mapToLong(t -> t.getAmount()).sum();
|
|
|
+ face.setExchangeNumWm(exchangeWmSum);
|
|
|
+ List<MonthData> goodsList = Lists.newArrayList();
|
|
|
+ Map<Integer, List<IntegralTrans>> maps = dataList.stream().filter(i -> i.getParentId() != null).collect(Collectors.groupingBy(IntegralTrans::getParentId));
|
|
|
+ for (Integer categoryId : maps.keySet()) {
|
|
|
+ List<IntegralTrans> categoryList = maps.get(categoryId);
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setAddValue(0L);
|
|
|
+ for (IntegralTrans IntegralTrans : categoryList) {
|
|
|
+ String fullName = IntegralTrans.getFullName();
|
|
|
+ if (fullName.contains("/")) {
|
|
|
+ fullName = fullName.split("/")[0];
|
|
|
+ }
|
|
|
+ monthData.setText(fullName);
|
|
|
+ monthData.setAddValue(monthData.getAddValue() + IntegralTrans.getAmount());
|
|
|
+ }
|
|
|
+ if (monthData.getAddValue() > 0L) {
|
|
|
+ goodsList.add(monthData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //消分商品个数统计
|
|
|
+ if (!goodsList.isEmpty()) {
|
|
|
+ face.setPointGoodsData2(goodsList);
|
|
|
+ }
|
|
|
+ face.setPointMonthData(addMonth(dataList, 0,""));
|
|
|
+ face.setPointMonthDataWm(addMonth(dataList, 0,"文明积分"));
|
|
|
+ face.setPointMonthDataYl(addMonth(dataList, 0,"银龄积分"));
|
|
|
+ face.setPointCountData(addMonth(dataList, 1,""));
|
|
|
+ returnList.add(face);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<MonthData> addMonth(List<IntegralTrans> transList,Integer type,String remark){
|
|
|
+ Date endDate = new Date();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(endDate));
|
|
|
+ calendar.add(Calendar.SECOND,1);
|
|
|
+ calendar.add(Calendar.YEAR, -1);
|
|
|
+ Date startDate = calendar.getTime();
|
|
|
+ List<MonthData> monthList = Lists.newArrayList();
|
|
|
+ Calendar calendar2 = Calendar.getInstance();
|
|
|
+ for (int i = 0; i < 12; i++) {
|
|
|
+ if(i>0){
|
|
|
+ calendar2.add(Calendar.MONTH, 1);
|
|
|
+ }else{
|
|
|
+ calendar2.setTime(startDate);
|
|
|
+ }
|
|
|
+ String monthStr = String.format("%02d", calendar2.get(Calendar.MONTH)+1);
|
|
|
+ MonthData data = new MonthData();
|
|
|
+ data.setText(monthStr+"月");
|
|
|
+ if(type.equals(0)){
|
|
|
+ if(transList.isEmpty()){
|
|
|
+ data.setAddValue(0L);
|
|
|
+ data.setUseValue(0L);
|
|
|
+ }else{
|
|
|
+ if(StringUtils.isNotEmpty(remark)){
|
|
|
+ data.setAddValue(transList.stream().filter(c->c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("0") && c.getRemark() !=null && c.getRemark().contains(remark)).mapToLong(c->c.getAmount()).sum());
|
|
|
+ data.setUseValue(transList.stream().filter(c->c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("1") && c.getRemark() !=null && c.getRemark().contains(remark)).mapToLong(c->c.getAmount()).sum());
|
|
|
+ }else{
|
|
|
+ data.setAddValue(transList.stream().filter(c->c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("0")).mapToLong(c->c.getAmount()).sum());
|
|
|
+ data.setUseValue(transList.stream().filter(c->c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("1")).mapToLong(c->c.getAmount()).sum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (transList.isEmpty()) {
|
|
|
+ data.setAddValue(0L);
|
|
|
+ data.setUseValue(0L);
|
|
|
+ } else {
|
|
|
+ data.setAddValue(transList.stream().filter(c -> c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("0")).count());
|
|
|
+ data.setUseValue(transList.stream().filter(c -> c.getBuildTime().after(calendar2.getTime()) && c.getBuildTime().before(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(calendar2.getTime())) && c.getTransType().equals("1")).count());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ monthList.add(data);
|
|
|
+ }
|
|
|
+ return monthList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeTransIntegral(Map<Integer, List<Order>> maps, Integer supplierId) {
|
|
|
+ List<SubsidyCustomerFace> integralList = this.integralTrans(supplierId);
|
|
|
+
|
|
|
+ for (SubsidyCustomerFace subsidyCustomerFace : integralList) {
|
|
|
+ List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
|
|
|
+ if (CollectionUtils.isEmpty(orders)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Order order : orders) {
|
|
|
+ //积分相关
|
|
|
+ if(order.getPointGrant() == null){
|
|
|
+ order.setPointGrant(0L);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getGrantNum() != null){
|
|
|
+ order.setPointGrant(subsidyCustomerFace.getGrantNum());
|
|
|
+ }
|
|
|
+ if(order.getPointGrantWm() == null){
|
|
|
+ order.setPointGrantWm(0L);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getGrantNumWm() != null){
|
|
|
+ order.setPointGrantWm(subsidyCustomerFace.getGrantNumWm());
|
|
|
+ }
|
|
|
+ if(order.getPointGrantYl() == null){
|
|
|
+ order.setPointGrantYl(0L);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getGrantNumYl() != null){
|
|
|
+ order.setPointGrantYl(subsidyCustomerFace.getGrantNumYl());
|
|
|
+ }
|
|
|
+ if(order.getPointExchange() == null){
|
|
|
+ order.setPointExchange(0L);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getExchangeNum() != null){
|
|
|
+ order.setPointExchange(subsidyCustomerFace.getExchangeNum());
|
|
|
+ }
|
|
|
+ if(order.getPointExchangeWm() == null){
|
|
|
+ order.setPointExchangeWm(0L);
|
|
|
+ }
|
|
|
+ if(subsidyCustomerFace.getExchangeNumWm() != null){
|
|
|
+ order.setPointExchangeWm(subsidyCustomerFace.getExchangeNumWm());
|
|
|
+ }
|
|
|
+
|
|
|
+ order.setPointGoodsData2(JSONObject.toJSONString(subsidyCustomerFace.getPointGoodsData2()));
|
|
|
+
|
|
|
+ order.setPointCountData(JSONObject.toJSONString(subsidyCustomerFace.getPointCountData()));
|
|
|
+
|
|
|
+ order.setPointMonthData(JSONObject.toJSONString(subsidyCustomerFace.getPointMonthData()));
|
|
|
+
|
|
|
+ order.setPointMonthDataWm(JSONObject.toJSONString(subsidyCustomerFace.getPointMonthDataWm()));
|
|
|
+
|
|
|
+ order.setPointMonthDataYl(JSONObject.toJSONString(subsidyCustomerFace.getPointMonthDataYl()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SubsidyCustomerFace> getMerchantIntegralFace(Integer operatorId,List<ListParams> categoryList,Integer supplierId){
|
|
|
+ List<SubsidyCustomerFace> returnList = Lists.newArrayList();
|
|
|
+ List<IntegralTransaction> transList = baseMapper.integralTransactionList(dbName,operatorId,supplierId);
|
|
|
+ List<Product> products = baseMapper.queryIntegralProduct(dbName,operatorId,supplierId);
|
|
|
+
|
|
|
+ List<StationMerchant> stationMerchantList = baseMapper.getStationMerchantList(dbName,supplierId);
|
|
|
+ List<IntegralProduct> productList = baseMapper.integralProductList(dbName,supplierId);
|
|
|
+ List<StationMerchant> stationList = stationMerchantList.stream().filter(s->s.getStatus().equals(1) && !s.getType().equals(18) && s.getStreet() != null && s.getCountry() != null && s.getCity() != null).collect(Collectors.toList());
|
|
|
+ List<ListParams> categoryFilterList = categoryList.stream().filter(c->c.getKey().equals(1)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //按照街道分组
|
|
|
+ Map<Integer,List<StationMerchant>> stationStreetMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet));
|
|
|
+ fillStationData(stationStreetMaps,returnList,3,productList,categoryFilterList,products,transList);
|
|
|
+ //按照区分组
|
|
|
+ Map<Integer,List<StationMerchant>> stationCountryMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry));
|
|
|
+ fillStationData(stationCountryMaps,returnList,2,productList,categoryFilterList,products,transList);
|
|
|
+ //按照市分组
|
|
|
+ Map<Integer,List<StationMerchant>> stationCityMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCity));
|
|
|
+ fillStationData(stationCityMaps,returnList,1,productList,categoryFilterList,products,transList);
|
|
|
+ log.info("---客户积分处理结束---");
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillStationData(Map<Integer,List<StationMerchant>> maps, List<SubsidyCustomerFace> returnList,Integer source,
|
|
|
+ List<IntegralProduct> productList,List<ListParams> categoryList,List<Product> products,
|
|
|
+ List<IntegralTransaction> transList){
|
|
|
+ for (Integer integer : maps.keySet()) {
|
|
|
+ List<StationMerchant> csList = maps.get(integer);
|
|
|
+ SubsidyCustomerFace face = new SubsidyCustomerFace();
|
|
|
+ face.setAreaId(integer);
|
|
|
+ face.setPointStation(csList.size());
|
|
|
+ List<MonthData> dataList = Lists.newArrayList();
|
|
|
+ for (StationMerchant dto : csList) {
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setText(dto.getName());
|
|
|
+ monthData.setAddValue(productList.stream().filter(p->p.getMerchantId().equals(dto.getId())).count());
|
|
|
+ if(monthData.getAddValue()>0L){
|
|
|
+ dataList.add(monthData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //积分商品统计
|
|
|
+ dataList = dataList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
|
|
|
+ if(dataList.size() >=5){
|
|
|
+ face.setGoodsData(dataList.subList(0,5));
|
|
|
+ }else{
|
|
|
+ face.setGoodsData(dataList);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> supplierIds = csList.stream().filter(s->s.getSupplierId() != null).map(s->s.getSupplierId()).distinct().collect(Collectors.toList());
|
|
|
+ List<Product> pList = products.stream().filter(p->supplierIds.contains(p.getProviderId())).collect(Collectors.toList());
|
|
|
+ List<MonthData> pDataList = Lists.newArrayList();
|
|
|
+ for (ListParams params : categoryList) {
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setText(params.getName());
|
|
|
+ Long val = 0L;
|
|
|
+ for (Product product : pList) {
|
|
|
+ if(product.getParentCategoryId().equals(params.getId().longValue())){
|
|
|
+ val++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(val>0L){
|
|
|
+ monthData.setAddValue(val);
|
|
|
+ pDataList.add(monthData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //消分商品统计
|
|
|
+ face.setGoodsData2(pDataList);
|
|
|
+
|
|
|
+ switch(source){
|
|
|
+ case 1:
|
|
|
+ //按区域分组
|
|
|
+ Map<Integer,List<StationMerchant>> countryMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry));
|
|
|
+ List<MonthData> countryList = Lists.newArrayList();
|
|
|
+ for (Integer country : countryMaps.keySet()) {
|
|
|
+ List<StationMerchant> list = countryMaps.get(country);
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setText(countryMaps.get(country).get(0).getCountryName());
|
|
|
+ monthData.setAddValue(Long.parseLong(String.valueOf(list.size())));
|
|
|
+ countryList.add(monthData);
|
|
|
+ }
|
|
|
+ countryList = countryList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
|
|
|
+ if(countryList.size() >=5){
|
|
|
+ face.setProviderData(countryList.subList(0,5));
|
|
|
+ }else{
|
|
|
+ face.setProviderData(countryList);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //按街道分组
|
|
|
+ Map<Integer,List<StationMerchant>> streetMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet));
|
|
|
+ List<MonthData> streetList = Lists.newArrayList();
|
|
|
+ for (Integer street : streetMaps.keySet()) {
|
|
|
+ List<StationMerchant> list = streetMaps.get(street);
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setText(streetMaps.get(street).get(0).getStreetName());
|
|
|
+ monthData.setAddValue(Long.parseLong(String.valueOf(list.size())));
|
|
|
+ streetList.add(monthData);
|
|
|
+ }
|
|
|
+ streetList = streetList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
|
|
|
+ if(streetList.size() >=5){
|
|
|
+ face.setProviderData(streetList.subList(0,5));
|
|
|
+ }else{
|
|
|
+ face.setProviderData(streetList);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //按商户名称
|
|
|
+ List<MonthData> nameList = Lists.newArrayList();
|
|
|
+ for (StationMerchant dto : csList) {
|
|
|
+ MonthData monthData = new MonthData();
|
|
|
+ monthData.setText(dto.getName());
|
|
|
+ nameList.add(monthData);
|
|
|
+ }
|
|
|
+ if(nameList.size() >=5){
|
|
|
+ face.setProviderData(nameList.subList(0,5));
|
|
|
+ }else{
|
|
|
+ face.setProviderData(nameList);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> ids = csList.stream().map(c->c.getId()).collect(Collectors.toList());
|
|
|
+ Map<Integer,List<IntegralTransaction>> transMaps = transList.stream().filter(t->ids.contains(t.getMerchantId())).collect(Collectors.groupingBy(IntegralTransaction::getMerchantId));
|
|
|
+ List<MonthData> dataList2 = Lists.newArrayList();
|
|
|
+ for (Integer tran : transMaps.keySet()) {
|
|
|
+ List<IntegralTransaction> trans = transMaps.get(tran);
|
|
|
+ MonthData data = new MonthData();
|
|
|
+ data.setText(trans.get(0).getMerchantName());
|
|
|
+ Long val = 0L;
|
|
|
+ for (IntegralTransaction transaction : trans) {
|
|
|
+ val += transaction.getIntegral() * transaction.getNum();
|
|
|
+ }
|
|
|
+ data.setAddValue(val);
|
|
|
+ dataList2.add(data);
|
|
|
+ }
|
|
|
+ //积分商品个数统计
|
|
|
+ dataList2 = dataList2.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
|
|
|
+ if(dataList2.size() >=5){
|
|
|
+ face.setPointGoodsData(dataList2.subList(0,5));
|
|
|
+ }else{
|
|
|
+ face.setPointGoodsData(dataList2);
|
|
|
+ }
|
|
|
+ returnList.add(face);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeIntegral(Map<Integer, List<Order>> maps,Integer operatorId,List<ListParams> categoryList,Integer supplierId) {
|
|
|
+ List<SubsidyCustomerFace> customerFaceList = this.getMerchantIntegralFace(operatorId,categoryList,supplierId);
|
|
|
+ for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) {
|
|
|
+ List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
|
|
|
+ if(orders == null || orders.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Order order : orders) {
|
|
|
+ //积分相关
|
|
|
+ order.setPointStation(subsidyCustomerFace.getPointStation());
|
|
|
+ if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointGoodsData())){
|
|
|
+ order.setPointGoodsData(JSONObject.toJSONString(subsidyCustomerFace.getPointGoodsData()));
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getProviderData())){
|
|
|
+ order.setProviderData(JSONObject.toJSONString(subsidyCustomerFace.getProviderData()));
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getGoodsData())){
|
|
|
+ order.setGoodsData(JSONObject.toJSONString(subsidyCustomerFace.getGoodsData()));
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getGoodsData2())){
|
|
|
+ order.setGoodsData2(JSONObject.toJSONString(subsidyCustomerFace.getGoodsData2()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<OrderStatisticsData> getOrderStatisticsDataList(Integer id,List<ListParams> categoryList,Integer supplierId){
|
|
|
+ List<OrderStatisticsData> returnList = Lists.newArrayList();
|
|
|
+ Date beginMonth = com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date());
|
|
|
+ Date endMonth= com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(new Date());
|
|
|
+ Map<String, String> dateMap = com.poteviohealth.cgp.common.utils.DateUtils.getWeekDate();
|
|
|
+ Date monday ;
|
|
|
+ Date sunday ;
|
|
|
+ try {
|
|
|
+ monday = com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("mondayDate")));
|
|
|
+ sunday = com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("sundayDate")));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ log.error("日期解析失败",e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Date beginDay = com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(new Date());
|
|
|
+ Date endDay = com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(new Date());
|
|
|
+ //获取已完成的服务工单
|
|
|
+ List<OrderIntegrationData> list=baseMapper.queryOrderIntegrationData(id,dbName, beginDay, endDay, monday, sunday, beginMonth, endMonth,supplierId);
|
|
|
+
|
|
|
+
|
|
|
+ Map<Integer,ListParams> categoryMap = categoryList.stream().collect(Collectors.toMap(ListParams::getId, Function.identity()));
|
|
|
+ //按照市统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId));
|
|
|
+ //按照区统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId));
|
|
|
+ //按照街道统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> streetMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getStreetId));
|
|
|
+ for (Integer integer : cityMaps.keySet()) {
|
|
|
+ integrationData(returnList,cityMaps.get(integer),integer,categoryMap);
|
|
|
+ }
|
|
|
+ for (Integer integer : countryMaps.keySet()) {
|
|
|
+ integrationData(returnList,countryMaps.get(integer),integer,categoryMap);
|
|
|
+ }
|
|
|
+ for (Integer integer : streetMaps.keySet()) {
|
|
|
+ integrationData(returnList,streetMaps.get(integer),integer,categoryMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<OrderStatisticsData> getOrderVisitStatisticsDataList(Integer id,Integer supplierId){
|
|
|
+ List<OrderStatisticsData> returnList = Lists.newArrayList();
|
|
|
+ //获取已完成的服务工单
|
|
|
+ List<OrderIntegrationData> list = baseMapper.queryOrderVisitData(id,dbName,supplierId);
|
|
|
+
|
|
|
+ //按照市统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId));
|
|
|
+ //按照区统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId));
|
|
|
+ //按照街道统计
|
|
|
+ Map<Integer,List<OrderIntegrationData>> streetMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getStreetId));
|
|
|
+ for (Integer integer : cityMaps.keySet()) {
|
|
|
+ visitData(returnList,cityMaps.get(integer),integer);
|
|
|
+ }
|
|
|
+ for (Integer integer : countryMaps.keySet()) {
|
|
|
+ visitData(returnList,countryMaps.get(integer),integer);
|
|
|
+ }
|
|
|
+ for (Integer integer : streetMaps.keySet()) {
|
|
|
+ visitData(returnList,streetMaps.get(integer),integer);
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnList;
|
|
|
+ }
|
|
|
+ private void visitData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,Integer areaId){
|
|
|
+
|
|
|
+ OrderStatisticsData data = new OrderStatisticsData();
|
|
|
+ data.setAreaId(areaId);
|
|
|
+ int visitNum = 0;
|
|
|
+ int orderNum = 0;
|
|
|
+ int satisfactionNum = 0;
|
|
|
+ int qualifiedNum = 0;
|
|
|
+ for (OrderIntegrationData item:orderList){
|
|
|
+ orderNum += item.getOrderId();
|
|
|
+ visitNum += item.getCustomerId();
|
|
|
+ satisfactionNum += item.getResult();
|
|
|
+ qualifiedNum += item.getQualified();
|
|
|
+ }
|
|
|
+ data.setVisitNum(visitNum);
|
|
|
+ data.setOrderNum(orderNum);
|
|
|
+ data.setVisitRate(new BigDecimal(100));
|
|
|
+ data.setSatisfactionNum(satisfactionNum);
|
|
|
+ data.setQualifiedNum(qualifiedNum);
|
|
|
+
|
|
|
+ returnList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void integrationData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,
|
|
|
+ Integer areaId,Map<Integer,ListParams> categoryMap){
|
|
|
+ OrderStatisticsData data = new OrderStatisticsData();
|
|
|
+ data.setAreaId(areaId);
|
|
|
+ int orderNum = 0;
|
|
|
+ int dayNum = 0;
|
|
|
+ int weekNum = 0;
|
|
|
+ int monthNum = 0;
|
|
|
+ for (OrderIntegrationData item:orderList){
|
|
|
+ orderNum += item.getOrderId();
|
|
|
+ dayNum += item.getVisitStatus();
|
|
|
+ weekNum += item.getResult();
|
|
|
+ monthNum += item.getQualified();
|
|
|
+ }
|
|
|
+ data.setOrderNum(orderNum);
|
|
|
+ data.setOrderNumMonth(monthNum);
|
|
|
+ data.setOrderNumWeek(weekNum);
|
|
|
+ data.setOrderNumDay(dayNum);
|
|
|
+
|
|
|
+ //服务类型统计
|
|
|
+ List<OrderServiceTypeDTO> typeList = Lists.newArrayList();
|
|
|
+ Map<Integer,List<OrderIntegrationData>> orderCategoryMaps = orderList.stream().collect(Collectors.groupingBy(OrderIntegrationData::getProductCategoryId));
|
|
|
+
|
|
|
+ Map<Integer,Integer> maps = Maps.newHashMap();
|
|
|
+ for (Integer integer : orderCategoryMaps.keySet()) {
|
|
|
+ ListParams list = categoryMap.get(integer);
|
|
|
+ if(list != null ){
|
|
|
+ ListParams listParent = categoryMap.get(list.getKey());
|
|
|
+ long num = orderCategoryMaps.get(integer).stream().mapToLong(OrderIntegrationData::getOrderId).sum();
|
|
|
+ Integer parentId = listParent.getId();
|
|
|
+ if(maps.containsKey(parentId)){
|
|
|
+ maps.put(parentId,maps.get(parentId)+ (int)num);
|
|
|
+ }else{
|
|
|
+ maps.put(parentId, (int)num);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
+ if(!maps.isEmpty()){
|
|
|
+ int sum = maps.values().stream().mapToInt(Integer::intValue).sum();
|
|
|
+ for (Integer integer : maps.keySet()) {
|
|
|
+ OrderServiceTypeDTO dto = new OrderServiceTypeDTO();
|
|
|
+ dto.setId(integer);
|
|
|
+ dto.setCount(maps.get(integer));
|
|
|
+ dto.setName(categoryMap.get(integer).getName());
|
|
|
+ if(sum == 0){
|
|
|
+ dto.setRate("0");
|
|
|
+ }else{
|
|
|
+ dto.setRate(df.format((dto.getCount().doubleValue()/sum)*100.0));
|
|
|
+ }
|
|
|
+ typeList.add(dto);
|
|
|
+ }
|
|
|
+ typeList = typeList.stream().sorted(Comparator.comparing(OrderServiceTypeDTO::getCount).reversed()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if(typeList.size()>=5){
|
|
|
+ data.setServiceTypeList(JSON.toJSONString(typeList.subList(0,5)));
|
|
|
+ }else{
|
|
|
+ data.setServiceTypeList(JSON.toJSONString(typeList));
|
|
|
+ }
|
|
|
+
|
|
|
+ returnList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeOrder(Map<Integer, List<Order>> maps,Integer operatorId,List<ListParams> categoryList,Integer supplierId) {
|
|
|
+ //更新工单相关数据
|
|
|
+ List<OrderStatisticsData> orderList = this.getOrderStatisticsDataList(operatorId,categoryList,supplierId);
|
|
|
+ for (OrderStatisticsData orderStatisticsData : orderList) {
|
|
|
+ List<Order> orders = maps.get(orderStatisticsData.getAreaId());
|
|
|
+ if(orders == null || orders.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Order order : orders) {
|
|
|
+ if(order.getOrderNum() == null){
|
|
|
+ order.setOrderNum(0);
|
|
|
+ }
|
|
|
+ order.setOrderNum(orderStatisticsData.getOrderNum());
|
|
|
+ order.setOrderNumMonth(orderStatisticsData.getOrderNumMonth());
|
|
|
+ order.setOrderNumWeek(orderStatisticsData.getOrderNumWeek());
|
|
|
+ order.setOrderNumDay(orderStatisticsData.getOrderNumDay());
|
|
|
+ order.setServiceTypeList(orderStatisticsData.getServiceTypeList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeOrderVisit(Map<Integer, List<Order>> maps,Integer operatorId,Integer supplierId) {
|
|
|
+ //更新工单相关数据
|
|
|
+ List<OrderStatisticsData> orderList = this.getOrderVisitStatisticsDataList(operatorId,supplierId);
|
|
|
+ for (OrderStatisticsData orderStatisticsData : orderList) {
|
|
|
+ List<Order> orders = maps.get(orderStatisticsData.getAreaId());
|
|
|
+ if(orders == null || orders.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Order order : orders) {
|
|
|
+ if(order.getVisitNum() == null){
|
|
|
+ order.setVisitNum(0);
|
|
|
+ }
|
|
|
+ if(order.getSatisfactionRate() == null){
|
|
|
+ order.setSatisfactionRate(new BigDecimal("0.00"));
|
|
|
+ }
|
|
|
+ if(order.getQualifiedRate() == null){
|
|
|
+ order.setQualifiedRate(new BigDecimal("0.00"));
|
|
|
+ }
|
|
|
+ order.setVisitNum(orderStatisticsData.getVisitNum());
|
|
|
+ order.setVisitRate(orderStatisticsData.getVisitRate());
|
|
|
+ BigDecimal addSatisfaction = new BigDecimal(orderStatisticsData.getSatisfactionNum());
|
|
|
+ order.setSatisfactionRate(addSatisfaction.multiply(new BigDecimal("100.0")).divide(new BigDecimal(orderStatisticsData.getOrderNum()),2,BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP));
|
|
|
+ if(order.getSatisfactionRate().compareTo(new BigDecimal(100))>0){
|
|
|
+ order.setSatisfactionRate(new BigDecimal(100));
|
|
|
+ }
|
|
|
+ BigDecimal addQualified = new BigDecimal(orderStatisticsData.getQualifiedNum());
|
|
|
+ order.setQualifiedRate(addQualified.multiply(new BigDecimal("100.0")).divide(new BigDecimal(orderStatisticsData.getOrderNum()),2,BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP));
|
|
|
+ if(order.getQualifiedRate().compareTo(new BigDecimal(100))>0){
|
|
|
+ order.setQualifiedRate(new BigDecimal(100));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|