package com.poteviohealth.cgp.statistics.service.impl; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.poteviohealth.cgp.common.filter.TokenContext; import com.poteviohealth.cgp.common.integrated.ListParams; import com.poteviohealth.cgp.common.integrated.customer.model.*; import com.poteviohealth.cgp.common.integrated.finance.model.*; import com.poteviohealth.cgp.common.integrated.order.model.OrderStatisticsData; import com.poteviohealth.cgp.common.integrated.order.model.PayAccount; 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.common.service.impl.BaseServiceImpl; import com.poteviohealth.cgp.statistics.constant.enums.OrderConstantEnum; import com.poteviohealth.cgp.statistics.mapper.OrderMapper; import com.poteviohealth.cgp.statistics.model.Order; import com.poteviohealth.cgp.statistics.model.WatermarkImg; import com.poteviohealth.cgp.statistics.model.indto.*; import com.poteviohealth.cgp.statistics.model.outdto.*; import com.poteviohealth.cgp.statistics.service.IOrderService; import lombok.extern.log4j.Log4j2; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.builder.BuilderException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.util.*; import java.util.stream.Collectors; /** * 居家大屏 * @author Qin */ @Service @Log4j2 public class OrderServiceImpl extends BaseServiceImpl implements IOrderService { @Value("${sync.dbName}") private String dbName; @Override public void statisticsOrder(String dateTime){ try { //检查区域,没有的新增 List list = this.list(); /* Date date = new Date(); if(StringUtils.isNotEmpty(dateTime)){ date = DateUtils.parseDate(dateTime,"yyyy-MM-dd HH:mm:ss"); }*/ List areaList = baseMapper.areaList(dbName); if(list.size() != areaList.size()){ List ids = Lists.newArrayList(); List 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(1); 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); } } this.saveBatch(newOrderList); list = this.list(); } Map> maps = list.stream().collect(Collectors.groupingBy(Order::getAreaId)); if(!maps.isEmpty()){ /* log.info("---数据清零开始---"); changeZero(maps,date); log.info("---数据清零结束---");*/ //更新服务人员数据 log.info("---更新服务人员数据开始---"); changeEmployee(maps); log.info("---更新服务人员数据结束---"); List operatorIds = baseMapper.getOperatorList(dbName); log.info("---获取客户数据开始---"); List customerList = this.getSubsidyCustomerList(operatorIds); log.info("---获取客户数据结束---"); //更新客户数据 if(!customerList.isEmpty()){ log.info("---更新客户数据开始---"); changeCustomer(maps,customerList,operatorIds); log.info("---更新客户数据结束---"); } //获取助餐服务客户数 List mealList = this.getSubsidyCustomerMealList(operatorIds); 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 categoryList = baseMapper.getAllCategory(dbName); changeOrder(maps,operatorIds,categoryList); changeOrderVisit(maps,operatorIds); log.info("---更新工单数据结束---"); //更新积分相关数据 log.info("---更新商户积分数据开始---"); changeIntegral(maps,operatorIds,categoryList); log.info("---更新商户积分数据结束---"); log.info("---客户积分开始获取---"); changeCustomerIntegral(maps); log.info("---客户积分结束获取---"); log.info("---积分流水开始获取---"); changeTransIntegral(maps); log.info("---积分流水结束获取---"); this.saveOrUpdateBatch(list); } log.info("完成----"); }catch (Exception e){ e.printStackTrace(); } } @Override public List orderExcel(OrderServiceWebInDTO dto) { try { Integer operatorId = TokenContext.cureOperatorId(); QueryWrapper queryWrapper = orderServiceQuery(dto, "o."); int count; if (null != dto.getProductIds()) { queryWrapper.eq("od.product_id", dto.getProductIds()); count = baseMapper.orderPageListAllSize(queryWrapper,dbName,operatorId); }else{ QueryWrapper queryWrapper2 = orderServiceQuery(dto, "o."); count = baseMapper.orderPageListSize(queryWrapper2,dbName,operatorId); } //每页10000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.orderExcel(queryWrapper,dbName,operatorId,start); start = findList.getLast().getId(); list.addAll(findList); } for (OrderExcelDTO orderExcelDTO : list) { for (OrderConstantEnum.OrderStatus status : EnumUtils.getEnumList(OrderConstantEnum.OrderStatus.class)) { if (status.getCode().toString().equals(orderExcelDTO.getOrderStatus())) { orderExcelDTO.setOrderStatus(status.getDisplay()); break; } } for (OrderConstantEnum.PayStyle status : EnumUtils.getEnumList(OrderConstantEnum.PayStyle.class)) { if (status.getCode().toString().equals(orderExcelDTO.getPayStyle())) { orderExcelDTO.setPayStyle(status.getDisplay()); break; } } for (OrderConstantEnum.PayStatus status : EnumUtils.getEnumList(OrderConstantEnum.PayStatus.class)) { if (status.getCode().toString().equals(orderExcelDTO.getPayStatus())) { orderExcelDTO.setPayStatus(status.getDisplay()); break; } } for (OrderConstantEnum.OrderStyle status : EnumUtils.getEnumList(OrderConstantEnum.OrderStyle.class)) { if (status.getCode().toString().equals(orderExcelDTO.getOrderStyle())) { orderExcelDTO.setOrderStyle(status.getDisplay()); break; } } orderExcelDTO.setPayAccount(getPayAccountString(orderExcelDTO.getPayAccount())); orderExcelDTO.setStationOrGroupName(StringUtils.isNotEmpty(orderExcelDTO.getGroupLeaderName())?orderExcelDTO.getGroupLeaderName():orderExcelDTO.getServiceStationName()); } //ForkJoinPool pool = new ForkJoinPool(); /* OrderExcelTask task = new OrderExcelTask(1,maxPage,queryWrapper, operatorId, dbName,baseMapper); Future> future = pool.submit(task); do { pool.awaitTermination(1, TimeUnit.SECONDS); } while (!future.isDone()); pool.shutdown(); list = future.get();*/ return list; }catch (Exception e){ e.printStackTrace(); throw new BuilderException("工单导出失败,请重新操作"); } } @Override public List excelList(OrderWebInDTO dto) { try { Integer operatorId = TokenContext.cureOperatorId(); QueryWrapper queryWrapper = webOrderQuery(dto, "o."); //int count; /* if (null != dto.getProductIds()) { queryWrapper.eq("od.product_id", dto.getProductIds()); count = baseMapper.orderPageListAllSize(queryWrapper,dbName,operatorId); }else{*/ int count = baseMapper.orderPageListSize(queryWrapper,dbName,operatorId); // } //每页10000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.orderExcel(queryWrapper,dbName,operatorId,start); start = findList.getLast().getId(); list.addAll(findList); } for (OrderExcelDTO orderExcelDTO : list) { for (OrderConstantEnum.OrderStatus status : EnumUtils.getEnumList(OrderConstantEnum.OrderStatus.class)) { if (status.getCode().toString().equals(orderExcelDTO.getOrderStatus())) { orderExcelDTO.setOrderStatus(status.getDisplay()); break; } } for (OrderConstantEnum.PayStyle status : EnumUtils.getEnumList(OrderConstantEnum.PayStyle.class)) { if (status.getCode().toString().equals(orderExcelDTO.getPayStyle())) { orderExcelDTO.setPayStyle(status.getDisplay()); break; } } for (OrderConstantEnum.PayStatus status : EnumUtils.getEnumList(OrderConstantEnum.PayStatus.class)) { if (status.getCode().toString().equals(orderExcelDTO.getPayStatus())) { orderExcelDTO.setPayStatus(status.getDisplay()); break; } } for (OrderConstantEnum.OrderStyle status : EnumUtils.getEnumList(OrderConstantEnum.OrderStyle.class)) { if (status.getCode().toString().equals(orderExcelDTO.getOrderStyle())) { orderExcelDTO.setOrderStyle(status.getDisplay()); break; } } orderExcelDTO.setPayAccount(getPayAccountString(orderExcelDTO.getPayAccount())); orderExcelDTO.setStationOrGroupName(StringUtils.isNotEmpty(orderExcelDTO.getGroupLeaderName())?orderExcelDTO.getGroupLeaderName():orderExcelDTO.getServiceStationName()); } //ForkJoinPool pool = new ForkJoinPool(); /* OrderExcelTask task = new OrderExcelTask(1,maxPage,queryWrapper, operatorId, dbName,baseMapper); Future> future = pool.submit(task); do { pool.awaitTermination(1, TimeUnit.SECONDS); } while (!future.isDone()); pool.shutdown(); list = future.get();*/ return list; }catch (Exception e){ e.printStackTrace(); throw new BuilderException("工单导出失败,请重新操作"); } } @Override public List pageCardExcel(MemberPlanPageDTO dto) { try { QueryWrapper queryWrapper = cardQueryWrapper(dto); int count = baseMapper.pageCardListSize(dto,queryWrapper,dbName); //每页10000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.pageCardList(dto,queryWrapper,dbName,start); start = findList.getLast().getId(); list.addAll(findList); } return list; }catch (Exception e){ e.printStackTrace(); throw new BuilderException("账户导出失败,请重新操作"); } } @Override public List excelGoldSendList(GoldSendPage vo) { try { QueryWrapper queryWrapper = getQueryWrapper(vo); int count = baseMapper.goldSendListSize(vo.getYearTime(),queryWrapper,dbName); //每页10000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.goldSendList(vo.getYearTime(),queryWrapper,dbName,start); start = findList.getLast().getId(); list.addAll(findList); } return list; }catch (Exception e){ e.printStackTrace(); throw new BuilderException("数据导出失败,请重新操作"); } } private QueryWrapper getQueryWrapper(GoldSendPage vo) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("d.operator_id", TokenContext.cureOperatorId()); if(StringUtils.isNotEmpty(vo.getSendTime())){ queryWrapper.eq("send_time", vo.getSendTime()); } if(StringUtils.isNotEmpty(vo.getExpectTime())){ queryWrapper.eq("expect_time", vo.getExpectTime()); } if(StringUtils.isNotEmpty(vo.getIdNumber())){ queryWrapper.eq("d.id_number", vo.getIdNumber()); } if(StringUtils.isNotEmpty(vo.getName())){ queryWrapper.eq("d.name", vo.getName()); } if(vo.getGoldType() != null){ queryWrapper.eq("d.gold_type", vo.getGoldType()); } if(vo.getSendType() != null){ queryWrapper.eq("d.send_type", vo.getSendType()); } if(vo.getIsDelete() != null){ queryWrapper.eq("d.is_delete", vo.getIsDelete()); } if(vo.getCountryId() != null){ queryWrapper.eq("d.country_id", vo.getCountryId()); } if(vo.getStreetId() != null){ queryWrapper.eq("d.street_id", vo.getStreetId()); } if(vo.getCommunityId() != null){ queryWrapper.eq("d.community_id", vo.getCommunityId()); } return queryWrapper; } @Override public List excelGoldSendBankList(GoldSendPage page) { try { QueryWrapper queryWrapper = getQueryWrapper(page); int count = baseMapper.goldSendListSize(page.getYearTime(),queryWrapper,dbName); //每页10000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.goldSendBankList(page.getYearTime(),queryWrapper,dbName,start); start = findList.getLast().getId(); list.addAll(findList); } return list; }catch (Exception e){ e.printStackTrace(); throw new BuilderException("数据导出失败,请重新操作"); } } private QueryWrapper cardQueryWrapper(MemberPlanPageDTO dto){ QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("d.operator_id",TokenContext.cureOperatorId()); if (StringUtils.isNotEmpty(dto.getNameOrPhone())){ queryWrapper.and(wr->wr.like("d.name", dto.getNameOrPhone()).or().like("d.phone", dto.getNameOrPhone())); } if(StringUtils.isNotEmpty(dto.getIdNumber())){ queryWrapper.eq("d.id_number", dto.getIdNumber()); } if(dto.getEnabled() != null){ queryWrapper.eq("d.enable", dto.getEnabled()); } if(dto.getCardId() != null){ queryWrapper.eq("d.card_id", dto.getCardId()); } if(org.apache.commons.collections4.CollectionUtils.isNotEmpty(dto.getSupplierIds())){ queryWrapper.in("d.supplier_id", dto.getSupplierIds()); } return queryWrapper; } private String getPayAccountString(String payAccount){ StringBuilder sb = new StringBuilder(); for (String s : payAccount.split(",")) { if(StringUtils.isNotEmpty(s)){ for (PayAccount account : EnumUtils.getEnumList(PayAccount.class)) { if(account.getCode().equals(Integer.parseInt(s))){ sb.append(account.getDisplay()+","); break; } } } } if(sb.length()>0){ return sb.substring(0,sb.length()-1); } return ""; } @Override public List orderDishes(DishesOrderWebInDTO inDTO) { Integer operatorId = TokenContext.cureOperatorId(); QueryWrapper queryWrapper = webQuery(inDTO); int count = baseMapper.dishesOrderPageListAllSize(queryWrapper,dbName,operatorId); //每页1000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.dishesOrderExcel(queryWrapper,dbName,operatorId,start); start = findList.getLast().getId(); list.addAll(findList); } for (DishesOrderWebOutDTO dto : list) { String val = ""; for (String s : dto.getPayAccountStr().split(",")) { if("1".equals(s)){ val+="补贴,"; }else if("2".equals(s)){ val+="积分,"; }else if("3".equals(s)){ val+="账户,"; }else if("4".equals(s)){ val+="现金,"; } } if(val != ""){ val = val.substring(0, val.length()-1); } dto.setPayAccountStr(val); } return list; /* List list = Lists.newArrayList(); ForkJoinPool pool = new ForkJoinPool(); try { DishesOrderExcelTask task = new DishesOrderExcelTask(1,maxPage, queryWrapper, operatorId, dbName,baseMapper); Future> future = pool.submit(task); do { pool.awaitTermination(1, TimeUnit.SECONDS); } while (!future.isDone()); pool.shutdown(); list = future.get(); }catch (Exception e){ e.printStackTrace(); throw new BuilderException("餐单导出失败,请重新操作"); } return list;*/ } @Override public List transRechargeExcel(CardWebInDTO dto) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("d.card_id",dto.getTypeId()); queryWrapper.eq("d.operator_id", TokenContext.cureOperatorId()); queryWrapper.in(!dto.getSupplierIds().isEmpty(),"d.supplier_id", dto.getSupplierIds()); int count = baseMapper.transRechargeExcelListAllSize(queryWrapper,dto,dbName); //每页1000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); int start = 0; LinkedList list = Lists.newLinkedList(); for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.transRechargeExcel(queryWrapper,dto,dbName,start); start = findList.getLast().getId(); list.addAll(findList); } return list; } @Override public List OrderCostList(OrderCostWebInDTO orderCostWebInDTO) { Integer operatorId = TokenContext.cureOperatorId(); QueryWrapper queryWrapper = webCostQuery(orderCostWebInDTO); int count = baseMapper.costOrderPageListAllSize(queryWrapper,dbName,operatorId); //每页1000条,计算总页数 int maxPage = (int) Math.ceil(count/10000.0); List list = Lists.newArrayList(); int start = 0; for (int i = 0; i < maxPage; i++) { LinkedList findList = baseMapper.costOrderExcel(queryWrapper,dbName,operatorId,start); start = findList.getLast().getId(); list.addAll(findList); } /* ForkJoinPool pool = new ForkJoinPool(); try { CostOrderExcelTask task = new CostOrderExcelTask(1,maxPage, queryWrapper, operatorId, dbName,baseMapper); Future> future = pool.submit(task); do { pool.awaitTermination(1, TimeUnit.SECONDS); } while (!future.isDone()); pool.shutdown(); list = future.get(); }catch (Exception e){ e.printStackTrace(); throw new BuilderException("成本核算导出失败,请重新操作"); }*/ return list; } private QueryWrapper webCostQuery(OrderCostWebInDTO orderWebInDTO) { QueryWrapper orderQueryWrapper = new QueryWrapper<>(); String searchTime = "o.order_time"; if(StringUtils.isNotEmpty(orderWebInDTO.getSearchDateStr())){ searchTime = orderWebInDTO.getSearchDateStr(); } if (orderWebInDTO.getStartDate() != null) { orderQueryWrapper.ge("o."+searchTime, orderWebInDTO.getStartDate()); } if (orderWebInDTO.getEndDate() != null) { orderQueryWrapper.le( "o."+searchTime, orderWebInDTO.getEndDate()); } orderQueryWrapper.in( !orderWebInDTO.getSupplierIds().isEmpty(),"o.supplier_id", orderWebInDTO.getSupplierIds()); if(orderWebInDTO.getStationIds() != null && !orderWebInDTO.getStationIds().isEmpty()){ orderQueryWrapper.in( "o.station_id", orderWebInDTO.getStationIds()); } if(orderWebInDTO.getServiceStationIds() != null && !orderWebInDTO.getServiceStationIds().isEmpty()){ orderQueryWrapper.in( "o.service_station_id", orderWebInDTO.getServiceStationIds()); } if(orderWebInDTO.getEmployeeId() != null){ orderQueryWrapper.eq( "o.employee_id", orderWebInDTO.getEmployeeId()); } if(StringUtils.isNotEmpty(orderWebInDTO.getCode())){ orderQueryWrapper.eq( "o.sn", orderWebInDTO.getCode()); } orderQueryWrapper.eq( "o.status", 1); if(orderWebInDTO.getRevenueStatus() != null){ orderQueryWrapper.eq( "o.revenue_status",orderWebInDTO.getRevenueStatus()); } if(orderWebInDTO.getCostStatus() != null){ orderQueryWrapper.eq( "o.cost_status",orderWebInDTO.getCostStatus()); } // orderQueryWrapper.orderByDesc("o.order_cost_id"); return orderQueryWrapper; } private QueryWrapper webOrderQuery(OrderWebInDTO orderWebInDTO, String prefix) { QueryWrapper orderQueryWrapper = new QueryWrapper<>(); if (StringUtils.isNotEmpty(orderWebInDTO.getSearchValuePhone())) { orderQueryWrapper.eq(prefix + "phone", orderWebInDTO.getSearchValuePhone()); } if (StringUtils.isNotEmpty(orderWebInDTO.getSearchValueName())) { orderQueryWrapper.like(prefix + "name", orderWebInDTO.getSearchValueName()); } if (StringUtils.isNotEmpty(orderWebInDTO.getSearchValueOrderCode())) { orderQueryWrapper.eq(prefix + "sn", orderWebInDTO.getSearchValueOrderCode()); } if (StringUtils.isNotEmpty(orderWebInDTO.getOrderStatus())) { orderQueryWrapper.eq(prefix + "order_status", orderWebInDTO.getOrderStatus()); } if (StringUtils.isNotEmpty(orderWebInDTO.getPayStatus())) { orderQueryWrapper.eq(prefix + "pay_status", orderWebInDTO.getPayStatus()); } if (orderWebInDTO.getPayWay() != null) { orderQueryWrapper.eq(prefix + "pay_way", orderWebInDTO.getPayWay()); } if (StringUtils.isNotEmpty(orderWebInDTO.getOrderStyle())) { orderQueryWrapper.eq(prefix + "order_style", orderWebInDTO.getOrderStyle()); } if (orderWebInDTO.getStartDate() != null) { orderQueryWrapper.ge(prefix + "order_time", orderWebInDTO.getStartDate()); } if (orderWebInDTO.getEndDate() != null) { orderQueryWrapper.le(prefix + "order_time", orderWebInDTO.getEndDate()); } Integer stationId = TokenContext.curStationId(); Integer belong = TokenContext.wbBelong(); Integer supplierId = TokenContext.curSupplierId(); if(belong.equals(1)){ orderQueryWrapper.eq(prefix + "supplier_one_id", supplierId); }else if(belong.equals(2)){ orderQueryWrapper.eq(stationId != null,prefix+"service_station_id",stationId); }else{ orderQueryWrapper.eq(stationId != null,prefix+"station_id",stationId); if (supplierId != null && !supplierId.equals(-1)) { orderWebInDTO.setSupplierId(supplierId); }else if(orderWebInDTO.getSupplierId() == null){ orderQueryWrapper.in(!TokenContext.supplierList().isEmpty(),prefix + "supplier_id",TokenContext.supplierList()); } orderQueryWrapper.eq(orderWebInDTO.getSupplierId() != null,prefix + "supplier_id", orderWebInDTO.getSupplierId()); } orderQueryWrapper.eq(prefix + "order_type", OrderConstantEnum.OrderType.PRODUCT.getCode()); return orderQueryWrapper; } private QueryWrapper webQuery(DishesOrderWebInDTO orderWebInDTO) { QueryWrapper orderQueryWrapper = new QueryWrapper<>(); if (StringUtils.isNotEmpty(orderWebInDTO.getSn())) { orderQueryWrapper.eq("o.sn", orderWebInDTO.getSn()); } if (StringUtils.isNotEmpty(orderWebInDTO.getCustomerName())) { orderQueryWrapper.eq( "o.customer_name", orderWebInDTO.getCustomerName()); } if (StringUtils.isNotEmpty(orderWebInDTO.getCustomerPhone())) { orderQueryWrapper.eq( "o.customer_phone", orderWebInDTO.getCustomerPhone()); } if (orderWebInDTO.getPayStyle() != null) { orderQueryWrapper.like("o.pay_account", orderWebInDTO.getPayStyle()); } if (orderWebInDTO.getStartDate() != null) { orderQueryWrapper.ge("o.order_time", orderWebInDTO.getStartDate()); } if (orderWebInDTO.getEndDate() != null) { orderQueryWrapper.le("o.order_time", orderWebInDTO.getEndDate()); } if (!org.springframework.util.CollectionUtils.isEmpty(orderWebInDTO.getSupplierIds())) { orderQueryWrapper.in("o.supplier_id", orderWebInDTO.getSupplierIds()); } if (!org.springframework.util.CollectionUtils.isEmpty(orderWebInDTO.getStationIds())) { orderQueryWrapper.in("o.service_station_id", orderWebInDTO.getStationIds()); } if (StringUtils.isNotBlank(orderWebInDTO.getIdCard())) { orderQueryWrapper.like( "id_card", orderWebInDTO.getIdCard()); } if (orderWebInDTO.getSourceId() != null) { orderQueryWrapper.eq("source_id", orderWebInDTO.getSourceId()); } if (orderWebInDTO.getEatIn() != null) { orderQueryWrapper.eq("eat_in", orderWebInDTO.getEatIn()); } if (orderWebInDTO.getDistrictid() >0) { orderQueryWrapper.eq("country", orderWebInDTO.getDistrictid()); } if (orderWebInDTO.getStreetid() >0) { orderQueryWrapper.eq("street", orderWebInDTO.getStreetid()); } orderQueryWrapper.eq("o.pay_status",3); //orderQueryWrapper.orderByDesc("o.id"); return orderQueryWrapper; } private QueryWrapper orderServiceQuery(OrderServiceWebInDTO orderServiceWebInDTO, String prefix) { QueryWrapper orderQueryWrapper = new QueryWrapper<>(); if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValueCustomerName())) { orderQueryWrapper.eq(prefix + "customer_name", orderServiceWebInDTO.getSearchValueCustomerName()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValuePhone())) { orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getSearchValuePhone()); }else if (StringUtils.isNotEmpty(orderServiceWebInDTO.getPhone())) { orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getPhone()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValueName())) { orderQueryWrapper.eq(prefix + "name", orderServiceWebInDTO.getSearchValueName()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValueIdNumber())) { orderQueryWrapper.eq(prefix + "id_number", orderServiceWebInDTO.getSearchValueIdNumber()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValueEmployeeName())) { orderQueryWrapper.like(prefix + "employee_name", orderServiceWebInDTO.getSearchValueEmployeeName()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchValueOrderCode())) { orderQueryWrapper.eq(prefix + "sn", orderServiceWebInDTO.getSearchValueOrderCode()); } if (StringUtils.isNotBlank(orderServiceWebInDTO.getCards())) { orderQueryWrapper.like(prefix + "card_names", orderServiceWebInDTO.getCards()); } if (null != orderServiceWebInDTO.getOrderStatus()) { if(orderServiceWebInDTO.getOrderStatus().equals(17)){ //已回访 orderQueryWrapper.eq(prefix + "visit_status",1); }else{ orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getOrderStatus()); } } if (null != orderServiceWebInDTO.getIsReturn()) { if(orderServiceWebInDTO.getIsReturn().equals(1)){ orderQueryWrapper.ne(prefix + "return_num", 0); }else{ orderQueryWrapper.eq(prefix + "return_num", 0); } } if (null != orderServiceWebInDTO.getPayStatus()) { orderQueryWrapper.eq(prefix + "pay_status", orderServiceWebInDTO.getPayStatus()); } if (null != orderServiceWebInDTO.getPayStyle()) { orderQueryWrapper.eq(prefix + "pay_style", orderServiceWebInDTO.getPayStyle()); } if (null != orderServiceWebInDTO.getEmployeeId()) { orderQueryWrapper.eq(prefix + "employee_id",orderServiceWebInDTO.getEmployeeId()); } if (StringUtils.isNotEmpty(orderServiceWebInDTO.getReviewReason())) { orderQueryWrapper.likeRight(prefix + "review_reason",orderServiceWebInDTO.getReviewReason()); } if(orderServiceWebInDTO.getCountryId() != null){ orderQueryWrapper.eq(prefix + "country_id", orderServiceWebInDTO.getCountryId()); } if(orderServiceWebInDTO.getStreetId() != null){ orderQueryWrapper.eq(prefix + "street_id", orderServiceWebInDTO.getStreetId()); } if(orderServiceWebInDTO.getCommunityId() != null){ orderQueryWrapper.eq(prefix + "community_id", orderServiceWebInDTO.getCommunityId()); } if(orderServiceWebInDTO.getReviewStatus() != null){ String roles = ""; List authList = TokenContext.cureWebUser().getAuthorities(); if(authList.contains("10")){ roles = "10"; }else if(authList.contains("11")){ roles = "11"; }else if(authList.contains("12")){ roles = "12"; } if(!"".equals(roles)){ if(orderServiceWebInDTO.getReviewStatus().equals(1)){ orderQueryWrapper.like(prefix + "review_government_role", roles); }else{ String val = roles; orderQueryWrapper.and(wr->wr.isNull(prefix + "review_government_role").or().notLike(prefix + "review_government_role",val)); orderQueryWrapper.eq(prefix + "order_status", 6); } } } if(orderServiceWebInDTO.getStationId() != null && orderServiceWebInDTO.getSource() != null){ switch (orderServiceWebInDTO.getSource()){ case 0: case 2: orderQueryWrapper.eq(prefix + "service_station_id",orderServiceWebInDTO.getStationId()); break; case 1: orderQueryWrapper.eq(prefix + "supplier_one_id",orderServiceWebInDTO.getStationId()); break; } } if(orderServiceWebInDTO.getServiceStationIds() != null && !orderServiceWebInDTO.getServiceStationIds().isEmpty()){ List oneList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s<0).collect(Collectors.toList()); List supplierList = Lists.newArrayList(); for (Integer integer : oneList) { supplierList.add(integer*-1); } List twoList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s>0).collect(Collectors.toList()); if(!supplierList.isEmpty() && !twoList.isEmpty()){ orderQueryWrapper.and(wr->wr.in(prefix + "supplier_one_id",supplierList).or().in(prefix + "service_station_id",twoList)); }else if(!supplierList.isEmpty()){ orderQueryWrapper.in(prefix + "supplier_one_id",supplierList); }else if(!twoList.isEmpty()){ orderQueryWrapper.in(prefix + "service_station_id",twoList); } } if (orderServiceWebInDTO.getPayWay() != null) { orderQueryWrapper.eq(prefix + "pay_way", orderServiceWebInDTO.getPayWay()); } if (null != orderServiceWebInDTO.getInvalidTime()) { orderQueryWrapper.eq(prefix + "invalid_time", orderServiceWebInDTO.getInvalidTime()); } if (orderServiceWebInDTO.getStartDate() != null) { orderQueryWrapper.ge(prefix + "order_time", orderServiceWebInDTO.getStartDate()); } if (orderServiceWebInDTO.getEndDate() != null) { orderQueryWrapper.le(prefix + "order_time", orderServiceWebInDTO.getEndDate()); } if (orderServiceWebInDTO.getHomeStartDate() != null) { orderQueryWrapper.ge(prefix + "home_time", orderServiceWebInDTO.getHomeStartDate()); } if (orderServiceWebInDTO.getHomeEndDate() != null) { orderQueryWrapper.le(prefix + "home_time", orderServiceWebInDTO.getHomeEndDate()); } if (orderServiceWebInDTO.getFinishStartDate() != null) { orderQueryWrapper.ge(prefix + "finish_time", orderServiceWebInDTO.getFinishStartDate()); } if (orderServiceWebInDTO.getFinishEndDate() != null) { orderQueryWrapper.le(prefix + "finish_time", orderServiceWebInDTO.getFinishEndDate()); } if (orderServiceWebInDTO.getSearchStartDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) { orderQueryWrapper.ge(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchStartDate()); } if (orderServiceWebInDTO.getSearchEndDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) { orderQueryWrapper.le(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchEndDate()); } if (orderServiceWebInDTO.getVisitReserve() != null) { switch (orderServiceWebInDTO.getVisitReserve()){ case 0: orderQueryWrapper.isNotNull(prefix + "visit_reserve_date"); break; case 1: orderQueryWrapper.isNull(prefix + "visit_reserve_date"); break; } } if (null != orderServiceWebInDTO.getPageType()) { if(orderServiceWebInDTO.getPageType().equals(15)){ orderQueryWrapper.eq(prefix + "order_status", 15); }else if(orderServiceWebInDTO.getPageType().equals(16)){ orderQueryWrapper.gt(prefix + "return_num", 0); }else if(orderServiceWebInDTO.getPageType().equals(17)){ orderQueryWrapper.eq(prefix + "order_status",16); }else if(orderServiceWebInDTO.getPageType().equals(19)){ orderQueryWrapper.eq(prefix + "visit_status", 1); }else if (orderServiceWebInDTO.getPageType().equals(11)) { orderQueryWrapper.in(prefix + "order_status", Lists.newArrayList(11,12)); } else { orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getPageType()); } } orderQueryWrapper.eq(orderServiceWebInDTO.getPlanId() != null,prefix + "plan_id", orderServiceWebInDTO.getPlanId()); String station = prefix+"station_id"; if(TokenContext.cureWebUser().getType()!= null && (TokenContext.cureWebUser().getType().equals(2)||TokenContext.cureWebUser().getType().equals(12))){ station = prefix+"service_station_id"; } orderQueryWrapper.in(!orderServiceWebInDTO.getStationIds().isEmpty(),station,orderServiceWebInDTO.getStationIds()); Integer supplierId = TokenContext.curSupplierId(); Integer belong = TokenContext.wbBelong(); if(belong.equals(1)){ //一级供应商 if (supplierId != null && !supplierId.equals(-1)) { orderQueryWrapper.eq(prefix + "supplier_one_id", supplierId); } }else{ orderQueryWrapper.in(!orderServiceWebInDTO.getSupplierIds().isEmpty(),prefix + "supplier_id",orderServiceWebInDTO.getSupplierIds()); } orderQueryWrapper.eq(prefix + "order_type", 2); return orderQueryWrapper; } private List getSubsidyCustomerMealList(List operatorIds){ List returnList = Lists.newArrayList(); for (Integer operatorId : operatorIds) { //获取签约客户信息 List dto = baseMapper.getSubsidyCustomerMealList(operatorId,dbName); if(!dto.isEmpty()){ Map> streetMaps = dto.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(Customer::getNowStreetId)); getMealData(streetMaps,returnList); //按照区分组 Map> countryMaps = dto.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(Customer::getNowCountryId)); getMealData(countryMaps,returnList); //按照市分组 Map> cityMaps = dto.stream().filter(c->c.getNowCityId() != null).collect(Collectors.groupingBy(Customer::getNowCityId)); getMealData(cityMaps,returnList); } } return returnList; } private void getMealData(Map> maps,List returnList){ for (Integer integer : maps.keySet()) { ListParams params = new ListParams(); params.setId(integer); params.setKey(maps.get(integer).size()); returnList.add(params); } } private List getSubsidyCustomerList(List operatorIds){ List returnList = Lists.newArrayList(); for (Integer operatorId : operatorIds) { //获取签约客户信息 List dto =baseMapper.getSubsidyCustomerList(operatorId,dbName); if(!dto.isEmpty()){ returnList.addAll(dto); } } return returnList; } private void changeZero(Map> maps,Date date){ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int day = calendar.get(Calendar.DAY_OF_MONTH); int week = calendar.get(Calendar.DAY_OF_WEEK); int hour = calendar.get(Calendar.HOUR_OF_DAY); for (Integer integer : maps.keySet()) { List orders = maps.get(integer); for (Order order : orders) { if(day == 1 && hour == 0){ //每月1日0点清零 order.setOrderNumMonth(0); if(StringUtils.isNotEmpty(order.getMemberListData())){ MemberListData data =JSONObject.toJavaObject(JSON.parseObject(order.getMemberListData()), MemberListData.class); data.setTotal(0); order.setMemberListData(JSONObject.toJSONString(data)); } } if (week == Calendar.MONDAY && hour == 0) { //每周一0点清零 order.setOrderNumWeek(0); } if(hour == 0){ //每天0点清零 order.setOrderNumDay(0); } } } } private void changeEmployee(Map> maps) { List employeeStationFaces = this.getEmployeeStationFace(); for (EmployeeStationFace employeeStationFace : employeeStationFaces) { List 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> stationMaps, List employeeList, List stationEmployeeList, List returnList){ for (Integer integer : stationMaps.keySet()) { List stations = stationMaps.get(integer); if(org.springframework.util.CollectionUtils.isEmpty(stations)){ continue; } EmployeeStationFace face = new EmployeeStationFace(); face.setAreaId(integer); List stationIds = stations.stream().map(s->s.getId()).collect(Collectors.toList()); List employeeIds = stationEmployeeList.stream().filter(se->stationIds.contains(se.getStationId())).map(se->se.getEmployeeId() ).distinct().collect(Collectors.toList()); List 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 maleList = Lists.newArrayList(); List womanList = Lists.newArrayList(); List 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 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 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 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 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 getEmployeeStationFace(){ List returnList = Lists.newArrayList(); //获取驿站员工信息 List stationEmployeeList = baseMapper.supplierStationEmployeeList(dbName); //获取驿站 List stationList = baseMapper.supplierStationList(dbName); //获取员工 List employeeList = baseMapper.employeeList(dbName); //按照街道分组 Map> stationStreetMaps = stationList.stream().filter(s->s.getStreet() != null).collect(Collectors.groupingBy(SupplierStation::getStreet)); getEmployeeData(stationStreetMaps,employeeList,stationEmployeeList,returnList); //按照区分组 Map> stationCountryMaps = stationList.stream().filter(s->s.getCountry() != null).collect(Collectors.groupingBy(SupplierStation::getCountry)); getEmployeeData(stationCountryMaps,employeeList,stationEmployeeList,returnList); //按照市分组 Map> stationCityMaps = stationList.stream().filter(s->s.getCity() != null).collect(Collectors.groupingBy(SupplierStation::getCity)); getEmployeeData(stationCityMaps,employeeList,stationEmployeeList,returnList); return returnList; } private List getSubsidyCustomerFace(List customerList){ List returnList = Lists.newArrayList(); //按照街道分组 Map> streetMaps = customerList.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowStreetId)); fillData(streetMaps,returnList,3); //按照区分组 Map> countryMaps = customerList.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId)); fillData(countryMaps,returnList,2); //按照市分组 Map> 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> maps, List returnList,Integer source){ for (Integer integer : maps.keySet()) { List 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 ids = csList.stream().map(c->c.getCustomerId()).collect(Collectors.toList()); face.setCustomerIds(ids); // List intersectionList = (List) 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 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 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 jsonFaceList = Lists.newArrayList(); if(source.equals(1)){ //按区域分组 Map> countryMaps = csList.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId)); for (Integer key : countryMaps.keySet()) { List 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> typeMaps = csList.stream().filter(c->StringUtils.isNotEmpty(c.getCustomerTypeId())).collect(Collectors.groupingBy(CustomerSubsidyDTO::getCustomerTypeId)); Map faceMap = Maps.newHashMap(); for (String key : typeMaps.keySet()) { List keyList = typeMaps.get(key); List 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 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 orderServiceCustomerList(List operatorIds){ List returnList = Lists.newArrayList(); for (Integer operatorId : operatorIds) { returnList.addAll(baseMapper.orderServiceCustomerList(operatorId,dbName)); } return returnList; } private void changeCustomer(Map> maps,List customerList,List operatorIds) { //更新客户数据 List customerFaceList = this.getSubsidyCustomerFace(customerList); //获取已服务老人Id集合 List serviceCustomerList = this.orderServiceCustomerList(operatorIds); for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) { List 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 jsonFace = subsidyCustomerFace.getJsonFace(); List id = Lists.newArrayList(); List title = Lists.newArrayList(); List total = Lists.newArrayList(); List 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 integralCustomer(){ List returnList = Lists.newArrayList(); List operationIds = baseMapper.getIntegralCardAccOperatorIdList(dbName); List detailsCustomer = Lists.newArrayList(); for (Integer operationId : operationIds) { //获取积分数据 detailsCustomer.addAll(baseMapper.integralCustomerList(operationId,dbName)); } log.info("---处理积分客户数据开始----"); if(!detailsCustomer.isEmpty()){ Map> streetCustomerMaps = detailsCustomer.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId)); fillData(streetCustomerMaps,returnList); Map> cityCustomerMaps = detailsCustomer.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId)); fillData(cityCustomerMaps,returnList); Map> countryCustomerMaps = detailsCustomer.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId)); fillData(countryCustomerMaps,returnList); } log.info("---处理积分客户数据结束----"); return returnList; } private void fillData(Map> mapCustomerData, List returnList){ for (Integer integer : mapCustomerData.keySet()) { List csList = mapCustomerData.get(integer); SubsidyCustomerFace face = new SubsidyCustomerFace(); face.setAreaId(integer); face.setCustomerNum(csList.size()); MemberListData data = new MemberListData(); List 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 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 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> maps) { List integralList = this.integralCustomer(); for (SubsidyCustomerFace subsidyCustomerFace : integralList) { List 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 integralTrans(){ List returnList = Lists.newArrayList(); List operationIds = baseMapper.getIntegralCardDetailOperatorIdList(dbName); List detailsTrans = Lists.newArrayList(); for (Integer operationId : operationIds) { //获取积分数据 detailsTrans.addAll(baseMapper.integralTransList(operationId,dbName)); } log.info("---处理流水数据开始----"); Map> streetTransMaps = detailsTrans.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId)); fillData2(streetTransMaps,returnList); Map> cityTransMaps = detailsTrans.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId)); fillData2(cityTransMaps,returnList); Map> countryTransMaps = detailsTrans.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId)); fillData2(countryTransMaps,returnList); log.info("---处理流水数据结束----"); return returnList; } private void fillData2(Map> data2,List returnList){ for (Integer integer : data2.keySet()) { List 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().contains("文明积分")).mapToLong(t -> t.getAmount()).sum(); face.setGrantNumWm(grantWmSum); Long grantYlSum = dataList.stream().filter(t -> t.getTransType().equals("0") && t.getRemark().contains("银龄积分")).mapToLong(t -> t.getAmount()).sum(); face.setGrantNumYl(grantYlSum); Long exchangeWmSum = dataList.stream().filter(t -> t.getTransType().equals("1") && t.getRemark().contains("文明积分")).mapToLong(t -> t.getAmount()).sum(); face.setExchangeNumWm(exchangeWmSum); List goodsList = Lists.newArrayList(); Map> maps = dataList.stream().filter(i -> i.getParentId() != null).collect(Collectors.groupingBy(IntegralTrans::getParentId)); for (Integer categoryId : maps.keySet()) { List 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 addMonth(List 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 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().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().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> maps) { List integralList = this.integralTrans(); for (SubsidyCustomerFace subsidyCustomerFace : integralList) { List 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 getMerchantIntegralFace(List operatorIds,List categoryList){ List returnList = Lists.newArrayList(); List transList = Lists.newArrayList(); List products = Lists.newArrayList(); for (Integer operatorId : operatorIds) { transList.addAll(baseMapper.integralTransactionList(dbName,operatorId)); products.addAll(baseMapper.queryIntegralProduct(dbName,operatorId)); } List stationMerchantList = baseMapper.getStationMerchantList(dbName); List productList = baseMapper.integralProductList(dbName); List 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 categoryFilterList = categoryList.stream().filter(c->c.getKey().equals(1)).collect(Collectors.toList()); //按照街道分组 Map> stationStreetMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet)); fillStationData(stationStreetMaps,returnList,3,productList,categoryFilterList,products,transList); //按照区分组 Map> stationCountryMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry)); fillStationData(stationCountryMaps,returnList,2,productList,categoryFilterList,products,transList); //按照市分组 Map> stationCityMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCity)); fillStationData(stationCityMaps,returnList,1,productList,categoryFilterList,products,transList); log.info("---客户积分处理结束---"); return returnList; } private void fillStationData(Map> maps, List returnList,Integer source, List productList,List categoryList,List products, List transList){ for (Integer integer : maps.keySet()) { List csList = maps.get(integer); SubsidyCustomerFace face = new SubsidyCustomerFace(); face.setAreaId(integer); face.setPointStation(csList.size()); List 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 supplierIds = csList.stream().filter(s->s.getSupplierId() != null).map(s->s.getSupplierId()).distinct().collect(Collectors.toList()); List pList = products.stream().filter(p->supplierIds.contains(p.getProviderId())).collect(Collectors.toList()); List 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> countryMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry)); List countryList = Lists.newArrayList(); for (Integer country : countryMaps.keySet()) { List 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> streetMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet)); List streetList = Lists.newArrayList(); for (Integer street : streetMaps.keySet()) { List 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 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 ids = csList.stream().map(c->c.getId()).collect(Collectors.toList()); Map> transMaps = transList.stream().filter(t->ids.contains(t.getMerchantId())).collect(Collectors.groupingBy(IntegralTransaction::getMerchantId)); List dataList2 = Lists.newArrayList(); for (Integer tran : transMaps.keySet()) { List 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> maps,List operatorIds,List categoryList) { List customerFaceList = this.getMerchantIntegralFace(operatorIds,categoryList); for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) { List 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 getOrderStatisticsDataList(List ids,List categoryList){ List returnList = Lists.newArrayList(); List list = Lists.newArrayList(); for (Integer id : ids) { //获取已完成的服务工单 list.addAll(baseMapper.queryOrderIntegrationData(id,dbName)); } Map> categoryMap = categoryList.stream().collect(Collectors.groupingBy(ListParams::getId)); //按照市统计 Map> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId)); //按照区统计 Map> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId)); //按照街道统计 Map> 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 getOrderVisitStatisticsDataList(List ids){ List returnList = Lists.newArrayList(); List list = Lists.newArrayList(); for (Integer id : ids) { //获取已完成的服务工单 list.addAll(baseMapper.queryOrderVisitData(id,dbName)); } //按照市统计 Map> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId)); //按照区统计 Map> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId)); //按照街道统计 Map> 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 returnList,List orderList,Integer areaId){ OrderStatisticsData data = new OrderStatisticsData(); data.setAreaId(areaId); List visitNumList = orderList.stream().map(o->o.getCustomerId()).distinct().collect(Collectors.toList()); data.setVisitNum(visitNumList.size()); data.setOrderNum(orderList.size()); data.setVisitRate(new BigDecimal(100)); if(data.getVisitNum()>0){ List satisfactionList = orderList.stream().filter(v->v.getResult().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList()); data.setSatisfactionNum(satisfactionList.size()); List qualifiedList = orderList.stream().filter(v->v.getQualified().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList()); data.setQualifiedNum(qualifiedList.size()); }else{ data.setSatisfactionNum(0); data.setQualifiedNum(0); } returnList.add(data); } private void integrationData(List returnList,List orderList, Integer areaId,Map> categoryMap){ OrderStatisticsData data = new OrderStatisticsData(); data.setAreaId(areaId); data.setOrderNum(orderList.size()); List monthOrderList = orderList.stream() .filter(o-> DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(new Date()))) .collect(Collectors.toList()); data.setOrderNumMonth(monthOrderList.size()); Map dateMap = com.poteviohealth.cgp.common.utils.DateUtils.getWeekDate(); try { Date monday = com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("mondayDate"))); Date sunday = com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("sundayDate"))); List weekOrderList = orderList.stream().filter(o->DateUtil.isIn(o.getFinishTime(),monday,sunday)).collect(Collectors.toList()); data.setOrderNumWeek(weekOrderList.size()); } catch (ParseException e) { e.printStackTrace(); } List dayOrderList = orderList.stream() .filter(o->DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(new Date()))) .collect(Collectors.toList()); data.setOrderNumDay(dayOrderList.size()); //服务类型统计 List typeList = Lists.newArrayList(); Map> orderCategoryMaps = orderList.stream().collect(Collectors.groupingBy(OrderIntegrationData::getProductCategoryId)); Map maps = Maps.newHashMap(); for (Integer integer : orderCategoryMaps.keySet()) { List list = categoryMap.get(integer); if(list != null && !list.isEmpty()){ ListParams listParent = categoryMap.get(list.get(0).getKey()).get(0); if(maps.containsKey(listParent.getId())){ maps.put(listParent.getId(),maps.get(listParent.getId())+orderCategoryMaps.get(integer).size()); }else{ maps.put(listParent.getId(),orderCategoryMaps.get(integer).size()); } } } DecimalFormat df = new DecimalFormat("#0.00"); if(!maps.isEmpty()){ Integer 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).get(0).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> maps,List operatorIds,List categoryList) { //更新工单相关数据 List orderList = this.getOrderStatisticsDataList(operatorIds,categoryList); for (OrderStatisticsData orderStatisticsData : orderList) { List 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> maps,List operatorIds) { //更新工单相关数据 List orderList = this.getOrderVisitStatisticsDataList(operatorIds); for (OrderStatisticsData orderStatisticsData : orderList) { List 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)); } } } } }