OrderServiceImpl.java 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. package com.poteviohealth.cgp.statistics.service.impl;
  2. import cn.hutool.core.date.DateUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.google.common.collect.Lists;
  8. import com.google.common.collect.Maps;
  9. import com.poteviohealth.cgp.common.filter.TokenContext;
  10. import com.poteviohealth.cgp.common.integrated.DateParams;
  11. import com.poteviohealth.cgp.common.integrated.ListParams;
  12. import com.poteviohealth.cgp.common.integrated.customer.model.CustomerServiceParams;
  13. import com.poteviohealth.cgp.common.integrated.customer.model.CustomerSubsidyDTO;
  14. import com.poteviohealth.cgp.common.integrated.customer.model.SubsidyCustomerFace;
  15. import com.poteviohealth.cgp.common.integrated.customer.model.SubsidyCustomerJsonFace;
  16. import com.poteviohealth.cgp.common.integrated.finance.model.MemberListData;
  17. import com.poteviohealth.cgp.common.integrated.finance.model.MonthData;
  18. import com.poteviohealth.cgp.common.integrated.order.model.OrderStatisticsData;
  19. import com.poteviohealth.cgp.common.integrated.partner.model.AreaDTO;
  20. import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationFace;
  21. import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationJsonFace;
  22. import com.poteviohealth.cgp.common.service.impl.BaseServiceImpl;
  23. import com.poteviohealth.cgp.statistics.mapper.OrderMapper;
  24. import com.poteviohealth.cgp.statistics.model.Order;
  25. import com.poteviohealth.cgp.statistics.model.indto.DishesOrderWebInDTO;
  26. import com.poteviohealth.cgp.statistics.model.indto.OrderCostWebInDTO;
  27. import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
  28. import com.poteviohealth.cgp.statistics.model.outdto.*;
  29. import com.poteviohealth.cgp.statistics.service.IOrderService;
  30. import com.poteviohealth.cgp.statistics.utils.CostOrderExcelTask;
  31. import com.poteviohealth.cgp.statistics.utils.DishesOrderExcelTask;
  32. import com.poteviohealth.cgp.statistics.utils.OrderExcelTask;
  33. import lombok.extern.log4j.Log4j2;
  34. import org.apache.commons.collections.CollectionUtils;
  35. import org.apache.commons.lang3.StringUtils;
  36. import org.apache.commons.lang3.time.DateUtils;
  37. import org.apache.ibatis.builder.BuilderException;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.stereotype.Service;
  40. import java.math.BigDecimal;
  41. import java.text.DecimalFormat;
  42. import java.text.ParseException;
  43. import java.text.SimpleDateFormat;
  44. import java.util.*;
  45. import java.util.concurrent.ForkJoinPool;
  46. import java.util.concurrent.Future;
  47. import java.util.concurrent.TimeUnit;
  48. import java.util.stream.Collectors;
  49. /**
  50. * 居家大屏
  51. * @author Qin
  52. */
  53. @Service
  54. @Log4j2
  55. public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implements IOrderService {
  56. @Value("${sync.dbName}")
  57. private String dbName;
  58. @Override
  59. public void statisticsOrder(String dateTime){
  60. try {
  61. TokenContext.setOperator(1);
  62. //检查区域,没有的新增
  63. List<Order> list = this.list();
  64. Date date = new Date();
  65. if(StringUtils.isNotEmpty(dateTime)){
  66. date = DateUtils.parseDate(dateTime,"yyyy-MM-dd HH:mm:ss");
  67. }
  68. List<AreaDTO> areaList = baseMapper.areaList(dbName);
  69. if(list.size() != areaList.size()){
  70. List<Integer> ids = Lists.newArrayList();
  71. List<Order> newOrderList = Lists.newArrayList();
  72. if(list.size()>0){
  73. ids = list.stream().map(o->o.getAreaId()).collect(Collectors.toList());
  74. }
  75. for (AreaDTO areaDTO : areaList) {
  76. if(!ids.contains(areaDTO.getId())){
  77. Order order = new Order();
  78. order.setOperatorId(1);
  79. order.setAreaId(areaDTO.getId());
  80. order.setAreaName(areaDTO.getName());
  81. order.setTreePath(areaDTO.getTreePath());
  82. order.setSourceLevel(areaDTO.getLevel());
  83. Integer size = 0;
  84. switch (order.getSourceLevel()){
  85. case 1:
  86. size =4;
  87. break;
  88. case 2:
  89. size =6;
  90. break;
  91. case 3:
  92. size =9;
  93. break;
  94. }
  95. if(StringUtils.isNotBlank(areaDTO.getRegionAreaCode())){
  96. order.setRegionAreaCode(areaDTO.getRegionAreaCode().substring(0,size));
  97. }
  98. newOrderList.add(order);
  99. }
  100. }
  101. this.saveBatch(newOrderList);
  102. list = this.list();
  103. }
  104. Map<Integer,List<Order>> maps = list.stream().collect(Collectors.groupingBy(Order::getAreaId));
  105. if(!maps.isEmpty()){
  106. log.info("---数据清零开始---");
  107. changeZero(maps,date);
  108. log.info("---数据清零结束---");
  109. Date startDate = null;
  110. for (Integer integer : maps.keySet()) {
  111. startDate = maps.get(integer).get(0).getChangeDate();
  112. break;
  113. }
  114. DateParams dateParams = new DateParams();
  115. dateParams.setStartDate(startDate);
  116. dateParams.setEndDate(date);
  117. //更新服务人员数据
  118. log.info("---更新服务人员数据开始---");
  119. changeEmployee(maps);
  120. log.info("---更新服务人员数据结束---");
  121. List<Integer> operatorIds = baseMapper.getOperatorList(dbName);
  122. log.info("---获取客户数据开始---");
  123. List<CustomerSubsidyDTO> customerList = this.getSubsidyCustomerList(dateParams,operatorIds);
  124. log.info("---获取客户数据结束---");
  125. //更新客户数据
  126. if(!customerList.isEmpty()){
  127. log.info("---更新客户数据开始---");
  128. changeCustomer(maps,customerList,operatorIds);
  129. log.info("---更新客户数据结束---");
  130. }
  131. //获取助餐服务客户数
  132. List<ListParams> mealList = this.getSubsidyCustomerMealList(dateParams,operatorIds);
  133. if(CollectionUtils.isNotEmpty(mealList)){
  134. for (Integer integer : maps.keySet()) {
  135. for (ListParams params : mealList) {
  136. if(params.getId().equals(integer)){
  137. for (Order order : maps.get(integer)) {
  138. order.setServiceCustomerNum(order.getServiceCustomerNum()+params.getKey());
  139. }
  140. }
  141. }
  142. }
  143. }
  144. //更新工单相关数据
  145. log.info("---更新工单数据开始---");
  146. List<ListParams> categoryList = baseMapper.getAllCategory(dbName);
  147. changeOrder(maps,dateParams,operatorIds,categoryList);
  148. log.info("---更新工单数据结束---");
  149. //更新积分相关数据
  150. log.info("---更新商户积分数据开始---");
  151. changeIntegral(maps,operatorIds,categoryList);
  152. log.info("---更新商户积分数据结束---");
  153. log.info("---客户积分开始获取---");
  154. changeCustomerIntegral(maps,dateParams);
  155. log.info("---客户积分结束获取---");
  156. log.info("---积分流水开始获取---");
  157. changeTransIntegral(maps,dateParams);
  158. log.info("---积分流水结束获取---");
  159. for (Integer integer : maps.keySet()) {
  160. for (Order order : maps.get(integer)) {
  161. order.setChangeDate(date);
  162. }
  163. }
  164. this.saveOrUpdateBatch(list);
  165. }
  166. log.info("完成----");
  167. }catch (Exception e){
  168. e.printStackTrace();
  169. }
  170. }
  171. @Override
  172. public List<OrderExcelDTO> orderExcel(OrderServiceWebInDTO dto) {
  173. Integer operatorId = TokenContext.cureOperatorId();
  174. QueryWrapper queryWrapper = orderServiceQuery(dto, "o.");
  175. int count;
  176. if (null != dto.getProductIds()) {
  177. queryWrapper.eq("od.product_id", dto.getProductIds());
  178. count = baseMapper.orderPageListAllSize(queryWrapper,dbName,operatorId);
  179. }else{
  180. QueryWrapper<Order> queryWrapper2 = orderServiceQuery(dto, "o.");
  181. count = baseMapper.orderPageListSize(queryWrapper2,dbName,operatorId);
  182. }
  183. //每页1000条,计算总页数
  184. int maxPage = (int) Math.ceil(count/10000.0);
  185. List<OrderExcelDTO> list = Lists.newArrayList();
  186. ForkJoinPool pool = new ForkJoinPool();
  187. try {
  188. OrderExcelTask task = new OrderExcelTask(1,maxPage, JSONObject.toJSONString(queryWrapper), operatorId, dbName,baseMapper);
  189. Future<List<OrderExcelDTO>> future = pool.submit(task);
  190. do {
  191. pool.awaitTermination(1, TimeUnit.SECONDS);
  192. } while (!future.isDone());
  193. pool.shutdown();
  194. list = future.get();
  195. }catch (Exception e){
  196. e.printStackTrace();
  197. throw new BuilderException("工单导出失败,请重新操作");
  198. }
  199. return list;
  200. }
  201. @Override
  202. public List<DishesOrderWebOutDTO> orderDishes(DishesOrderWebInDTO dto) {
  203. Integer operatorId = TokenContext.cureOperatorId();
  204. QueryWrapper queryWrapper = webQuery(dto);
  205. int count = baseMapper.dishesOrderPageListAllSize(queryWrapper,dbName,operatorId);
  206. //每页1000条,计算总页数
  207. int maxPage = (int) Math.ceil(count/10000.0);
  208. List<DishesOrderWebOutDTO> list = Lists.newArrayList();
  209. ForkJoinPool pool = new ForkJoinPool();
  210. try {
  211. DishesOrderExcelTask task = new DishesOrderExcelTask(1,maxPage, queryWrapper, operatorId, dbName,baseMapper);
  212. Future<List<DishesOrderWebOutDTO>> future = pool.submit(task);
  213. do {
  214. pool.awaitTermination(1, TimeUnit.SECONDS);
  215. } while (!future.isDone());
  216. pool.shutdown();
  217. list = future.get();
  218. }catch (Exception e){
  219. e.printStackTrace();
  220. throw new BuilderException("餐单导出失败,请重新操作");
  221. }
  222. return list;
  223. }
  224. @Override
  225. public List<OrderCostWebOutDTO> OrderCostList(OrderCostWebInDTO orderCostWebInDTO) {
  226. Integer operatorId = TokenContext.cureOperatorId();
  227. QueryWrapper queryWrapper = webCostQuery(orderCostWebInDTO);
  228. int count = baseMapper.costOrderPageListAllSize(queryWrapper,dbName,operatorId);
  229. //每页1000条,计算总页数
  230. int maxPage = (int) Math.ceil(count/10000.0);
  231. List<OrderCostWebOutDTO> list = Lists.newArrayList();
  232. ForkJoinPool pool = new ForkJoinPool();
  233. try {
  234. CostOrderExcelTask task = new CostOrderExcelTask(1,maxPage, queryWrapper, operatorId, dbName,baseMapper);
  235. Future<List<OrderCostWebOutDTO>> future = pool.submit(task);
  236. do {
  237. pool.awaitTermination(1, TimeUnit.SECONDS);
  238. } while (!future.isDone());
  239. pool.shutdown();
  240. list = future.get();
  241. }catch (Exception e){
  242. e.printStackTrace();
  243. throw new BuilderException("成本核算导出失败,请重新操作");
  244. }
  245. return list;
  246. }
  247. private QueryWrapper webCostQuery(OrderCostWebInDTO orderWebInDTO) {
  248. QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
  249. String searchTime = "o.order_time";
  250. if(StringUtils.isNotBlank(orderWebInDTO.getSearchDateStr())){
  251. searchTime = orderWebInDTO.getSearchDateStr();
  252. }
  253. if (orderWebInDTO.getStartDate() != null) {
  254. orderQueryWrapper.ge("o."+searchTime, orderWebInDTO.getStartDate());
  255. }
  256. if (orderWebInDTO.getEndDate() != null) {
  257. orderQueryWrapper.le( "o."+searchTime, orderWebInDTO.getEndDate());
  258. }
  259. orderQueryWrapper.in( !orderWebInDTO.getSupplierIds().isEmpty(),"o.supplier_id", orderWebInDTO.getSupplierIds());
  260. if(orderWebInDTO.getStationIds() != null && !orderWebInDTO.getStationIds().isEmpty()){
  261. orderQueryWrapper.in( "o.station_id", orderWebInDTO.getStationIds());
  262. }
  263. if(orderWebInDTO.getServiceStationIds() != null && !orderWebInDTO.getServiceStationIds().isEmpty()){
  264. orderQueryWrapper.in( "o.service_station_id", orderWebInDTO.getServiceStationIds());
  265. }
  266. if(orderWebInDTO.getEmployeeId() != null){
  267. orderQueryWrapper.eq( "o.employee_id", orderWebInDTO.getEmployeeId());
  268. }
  269. if(StringUtils.isNotBlank(orderWebInDTO.getCode())){
  270. orderQueryWrapper.eq( "o.sn", orderWebInDTO.getCode());
  271. }
  272. orderQueryWrapper.eq( "o.status", 1);
  273. if(orderWebInDTO.getRevenueStatus() != null){
  274. orderQueryWrapper.eq( "o.revenue_status",orderWebInDTO.getRevenueStatus());
  275. }
  276. if(orderWebInDTO.getCostStatus() != null){
  277. orderQueryWrapper.eq( "o.cost_status",orderWebInDTO.getCostStatus());
  278. }
  279. orderQueryWrapper.orderByDesc("o.order_cost_id");
  280. return orderQueryWrapper;
  281. }
  282. private QueryWrapper webQuery(DishesOrderWebInDTO orderWebInDTO) {
  283. QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
  284. if (StringUtils.isNotBlank(orderWebInDTO.getSn())) {
  285. orderQueryWrapper.eq("o.sn", orderWebInDTO.getSn());
  286. }
  287. if (StringUtils.isNotBlank(orderWebInDTO.getCustomerName())) {
  288. orderQueryWrapper.eq( "o.customer_name", orderWebInDTO.getCustomerName());
  289. }
  290. if (StringUtils.isNotBlank(orderWebInDTO.getCustomerPhone())) {
  291. orderQueryWrapper.eq( "o.customer_phone", orderWebInDTO.getCustomerPhone());
  292. }
  293. if (orderWebInDTO.getPayStyle() != null) {
  294. orderQueryWrapper.like("o.pay_account", orderWebInDTO.getPayStyle());
  295. }
  296. if (orderWebInDTO.getStartDate() != null) {
  297. orderQueryWrapper.ge("o.order_time", orderWebInDTO.getStartDate());
  298. }
  299. if (orderWebInDTO.getEndDate() != null) {
  300. orderQueryWrapper.le("o.order_time", orderWebInDTO.getEndDate());
  301. }
  302. if (!org.springframework.util.CollectionUtils.isEmpty(orderWebInDTO.getSupplierIds())) {
  303. orderQueryWrapper.in("o.supplier_id", orderWebInDTO.getSupplierIds());
  304. }
  305. if (!org.springframework.util.CollectionUtils.isEmpty(orderWebInDTO.getStationIds())) {
  306. orderQueryWrapper.in("o.service_station_id", orderWebInDTO.getStationIds());
  307. }
  308. orderQueryWrapper.eq("o.pay_status",3);
  309. orderQueryWrapper.orderByDesc("o.order_id");
  310. return orderQueryWrapper;
  311. }
  312. private QueryWrapper orderServiceQuery(OrderServiceWebInDTO orderServiceWebInDTO, String prefix) {
  313. QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
  314. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueCustomerName())) {
  315. orderQueryWrapper.eq(prefix + "customer_name", orderServiceWebInDTO.getSearchValueCustomerName());
  316. }
  317. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValuePhone())) {
  318. orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getSearchValuePhone());
  319. }else if (StringUtils.isNotBlank(orderServiceWebInDTO.getPhone())) {
  320. orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getPhone());
  321. }
  322. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueName())) {
  323. orderQueryWrapper.eq(prefix + "name", orderServiceWebInDTO.getSearchValueName());
  324. }
  325. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueIdNumber())) {
  326. orderQueryWrapper.eq(prefix + "id_number", orderServiceWebInDTO.getSearchValueIdNumber());
  327. }
  328. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueEmployeeName())) {
  329. orderQueryWrapper.like(prefix + "employee_name", orderServiceWebInDTO.getSearchValueEmployeeName());
  330. }
  331. if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueOrderCode())) {
  332. orderQueryWrapper.eq(prefix + "sn", orderServiceWebInDTO.getSearchValueOrderCode());
  333. }
  334. if (null != orderServiceWebInDTO.getOrderStatus()) {
  335. if(orderServiceWebInDTO.getOrderStatus().equals(17)){
  336. //已回访
  337. orderQueryWrapper.eq(prefix + "visit_status",1);
  338. }else{
  339. orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getOrderStatus());
  340. }
  341. }
  342. if (null != orderServiceWebInDTO.getIsReturn()) {
  343. if(orderServiceWebInDTO.getIsReturn().equals(1)){
  344. orderQueryWrapper.ne(prefix + "return_num", 0);
  345. }else{
  346. orderQueryWrapper.eq(prefix + "return_num", 0);
  347. }
  348. }
  349. if (null != orderServiceWebInDTO.getPayStatus()) {
  350. orderQueryWrapper.eq(prefix + "pay_status", orderServiceWebInDTO.getPayStatus());
  351. }
  352. if (null != orderServiceWebInDTO.getPayStyle()) {
  353. orderQueryWrapper.eq(prefix + "pay_style", orderServiceWebInDTO.getPayStyle());
  354. }
  355. if (null != orderServiceWebInDTO.getEmployeeId()) {
  356. orderQueryWrapper.eq(prefix + "employee_id",orderServiceWebInDTO.getEmployeeId());
  357. }
  358. if (StringUtils.isNotBlank(orderServiceWebInDTO.getReviewReason())) {
  359. orderQueryWrapper.likeRight(prefix + "review_reason",orderServiceWebInDTO.getReviewReason());
  360. }
  361. if(orderServiceWebInDTO.getStationId() != null && orderServiceWebInDTO.getSource() != null){
  362. switch (orderServiceWebInDTO.getSource()){
  363. case 0:
  364. case 2:
  365. orderQueryWrapper.eq(prefix + "service_station_id",orderServiceWebInDTO.getStationId());
  366. break;
  367. case 1:
  368. orderQueryWrapper.eq(prefix + "supplier_one_id",orderServiceWebInDTO.getStationId());
  369. break;
  370. }
  371. }
  372. if(orderServiceWebInDTO.getServiceStationIds() != null && !orderServiceWebInDTO.getServiceStationIds().isEmpty()){
  373. List<Integer> oneList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s<0).collect(Collectors.toList());
  374. List<Integer> supplierList = Lists.newArrayList();
  375. for (Integer integer : oneList) {
  376. supplierList.add(integer*-1);
  377. }
  378. List<Integer> twoList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s>0).collect(Collectors.toList());
  379. if(!supplierList.isEmpty() && !twoList.isEmpty()){
  380. orderQueryWrapper.and(wr->wr.in(prefix + "supplier_one_id",supplierList).or().in(prefix + "service_station_id",twoList));
  381. }else if(!supplierList.isEmpty()){
  382. orderQueryWrapper.in(prefix + "supplier_one_id",supplierList);
  383. }else if(!twoList.isEmpty()){
  384. orderQueryWrapper.in(prefix + "service_station_id",twoList);
  385. }
  386. }
  387. if (orderServiceWebInDTO.getPayWay() != null) {
  388. orderQueryWrapper.eq(prefix + "pay_way", orderServiceWebInDTO.getPayWay());
  389. }
  390. if (null != orderServiceWebInDTO.getInvalidTime()) {
  391. orderQueryWrapper.eq(prefix + "invalid_time", orderServiceWebInDTO.getInvalidTime());
  392. }
  393. if (orderServiceWebInDTO.getStartDate() != null) {
  394. orderQueryWrapper.ge(prefix + "order_time", orderServiceWebInDTO.getStartDate());
  395. }
  396. if (orderServiceWebInDTO.getEndDate() != null) {
  397. orderQueryWrapper.le(prefix + "order_time", orderServiceWebInDTO.getEndDate());
  398. }
  399. if (orderServiceWebInDTO.getHomeStartDate() != null) {
  400. orderQueryWrapper.ge(prefix + "home_time", orderServiceWebInDTO.getHomeStartDate());
  401. }
  402. if (orderServiceWebInDTO.getHomeEndDate() != null) {
  403. orderQueryWrapper.le(prefix + "home_time", orderServiceWebInDTO.getHomeEndDate());
  404. }
  405. if (orderServiceWebInDTO.getFinishStartDate() != null) {
  406. orderQueryWrapper.ge(prefix + "finish_time", orderServiceWebInDTO.getFinishStartDate());
  407. }
  408. if (orderServiceWebInDTO.getFinishEndDate() != null) {
  409. orderQueryWrapper.le(prefix + "finish_time", orderServiceWebInDTO.getFinishEndDate());
  410. }
  411. if (orderServiceWebInDTO.getSearchStartDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) {
  412. orderQueryWrapper.ge(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchStartDate());
  413. }
  414. if (orderServiceWebInDTO.getSearchEndDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) {
  415. orderQueryWrapper.le(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchEndDate());
  416. }
  417. if (orderServiceWebInDTO.getVisitReserve() != null) {
  418. switch (orderServiceWebInDTO.getVisitReserve()){
  419. case 0:
  420. orderQueryWrapper.isNotNull(prefix + "visit_reserve_date");
  421. break;
  422. case 1:
  423. orderQueryWrapper.isNull(prefix + "visit_reserve_date");
  424. break;
  425. }
  426. }
  427. if (null != orderServiceWebInDTO.getPageType()) {
  428. if(orderServiceWebInDTO.getPageType().equals(15)){
  429. orderQueryWrapper.eq(prefix + "order_status", 15);
  430. }else if(orderServiceWebInDTO.getPageType().equals(16)){
  431. orderQueryWrapper.gt(prefix + "return_num", 0);
  432. }else if(orderServiceWebInDTO.getPageType().equals(17)){
  433. orderQueryWrapper.eq(prefix + "order_status",16);
  434. }else if(orderServiceWebInDTO.getPageType().equals(19)){
  435. orderQueryWrapper.eq(prefix + "visit_status", 1);
  436. }else if (orderServiceWebInDTO.getPageType().equals(11)) {
  437. orderQueryWrapper.in(prefix + "order_status", Lists.newArrayList(11,12));
  438. } else {
  439. orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getPageType());
  440. }
  441. }
  442. orderQueryWrapper.eq(orderServiceWebInDTO.getPlanId() != null,prefix + "plan_id", orderServiceWebInDTO.getPlanId());
  443. String station = prefix+"station_id";
  444. if(TokenContext.cureWebUser().getType()!= null &&
  445. (TokenContext.cureWebUser().getType().equals(2)||TokenContext.cureWebUser().getType().equals(12))){
  446. station = prefix+"service_station_id";
  447. }
  448. orderQueryWrapper.in(!orderServiceWebInDTO.getStationIds().isEmpty(),station,orderServiceWebInDTO.getStationIds());
  449. Integer supplierId = TokenContext.curSupplierId();
  450. Integer belong = TokenContext.wbBelong();
  451. if(belong.equals(1)){
  452. //一级供应商
  453. if (supplierId != null && !supplierId.equals(-1)) {
  454. orderQueryWrapper.eq(prefix + "supplier_one_id", supplierId);
  455. }
  456. }else{
  457. orderQueryWrapper.in(!orderServiceWebInDTO.getSupplierIds().isEmpty(),prefix + "supplier_id",orderServiceWebInDTO.getSupplierIds());
  458. }
  459. orderQueryWrapper.eq(prefix + "order_type", 2);
  460. return orderQueryWrapper;
  461. }
  462. private List<ListParams> getSubsidyCustomerMealList(DateParams dateParams,List<Integer> operatorIds){
  463. List<ListParams> returnList = Lists.newArrayList();
  464. QueryWrapper queryWrapper = new QueryWrapper<>();
  465. if(dateParams.getStartDate() != null){
  466. queryWrapper.ge("meal_date",dateParams.getStartDate());
  467. }
  468. if(dateParams.getEndDate() != null){
  469. queryWrapper.lt("meal_date",dateParams.getEndDate());
  470. }
  471. for (Integer operatorId : operatorIds) {
  472. //获取签约客户信息
  473. List<Customer> dto = baseMapper.getSubsidyCustomerMealList(operatorId,dbName,queryWrapper);
  474. if(!dto.isEmpty()){
  475. Map<Integer,List<Customer>> streetMaps = dto.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(Customer::getNowStreetId));
  476. getMealData(streetMaps,returnList);
  477. //按照区分组
  478. Map<Integer,List<Customer>> countryMaps = dto.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(Customer::getNowCountryId));
  479. getMealData(countryMaps,returnList);
  480. //按照市分组
  481. Map<Integer,List<Customer>> cityMaps = dto.stream().filter(c->c.getNowCityId() != null).collect(Collectors.groupingBy(Customer::getNowCityId));
  482. getMealData(cityMaps,returnList);
  483. }
  484. }
  485. return returnList;
  486. }
  487. private void getMealData(Map<Integer,List<Customer>> maps,List<ListParams> returnList){
  488. for (Integer integer : maps.keySet()) {
  489. ListParams params = new ListParams();
  490. params.setId(integer);
  491. params.setKey(maps.get(integer).size());
  492. returnList.add(params);
  493. }
  494. }
  495. private List<CustomerSubsidyDTO> getSubsidyCustomerList(DateParams dateParams,List<Integer> operatorIds){
  496. List<CustomerSubsidyDTO> returnList = Lists.newArrayList();
  497. QueryWrapper queryWrapper = new QueryWrapper<>();
  498. if(dateParams.getStartDate() != null){
  499. queryWrapper.ge("d.created_date",dateParams.getStartDate());
  500. }
  501. if(dateParams.getEndDate() != null){
  502. queryWrapper.lt("d.created_date",dateParams.getEndDate());
  503. }
  504. for (Integer operatorId : operatorIds) {
  505. //获取签约客户信息
  506. List<CustomerSubsidyDTO> dto =baseMapper.getSubsidyCustomerList(operatorId,dbName,queryWrapper);
  507. if(!dto.isEmpty()){
  508. returnList.addAll(dto);
  509. }
  510. }
  511. return returnList;
  512. }
  513. private void changeZero(Map<Integer,List<Order>> maps,Date date){
  514. Calendar calendar = Calendar.getInstance();
  515. calendar.setTime(date);
  516. int day = calendar.get(Calendar.DAY_OF_MONTH);
  517. int week = calendar.get(Calendar.DAY_OF_WEEK);
  518. int hour = calendar.get(Calendar.HOUR_OF_DAY);
  519. for (Integer integer : maps.keySet()) {
  520. List<Order> orders = maps.get(integer);
  521. for (Order order : orders) {
  522. if(day == 1 && hour == 0){
  523. //每月1日0点清零
  524. order.setOrderNumMonth(0);
  525. if(StringUtils.isNotEmpty(order.getMemberListData())){
  526. MemberListData data =JSONObject.toJavaObject(JSON.parseObject(order.getMemberListData()), MemberListData.class);
  527. data.setTotal(0);
  528. order.setMemberListData(JSONObject.toJSONString(data));
  529. }
  530. }
  531. if (week == Calendar.MONDAY && hour == 0) {
  532. //每周一0点清零
  533. order.setOrderNumWeek(0);
  534. }
  535. if(hour == 0){
  536. //每天0点清零
  537. order.setOrderNumDay(0);
  538. }
  539. }
  540. }
  541. }
  542. private void changeEmployee(Map<Integer, List<Order>> maps) {
  543. List<EmployeeStationFace> employeeStationFaces = this.getEmployeeStationFace();
  544. for (EmployeeStationFace employeeStationFace : employeeStationFaces) {
  545. List<Order> orders = maps.get(employeeStationFace.getAreaId());
  546. if(orders != null){
  547. for (Order order : orders) {
  548. order.setAllStationNum(employeeStationFace.getAllStationNum());
  549. order.setEmployeeNum(employeeStationFace.getNum());
  550. order.setEmployeeList(employeeStationFace.getLists());
  551. }
  552. }
  553. }
  554. }
  555. private void getEmployeeData(Map<Integer,List<SupplierStation>> stationMaps, List<Employee> employeeList, List<SupplierStationEmployee> stationEmployeeList, List<EmployeeStationFace> returnList){
  556. for (Integer integer : stationMaps.keySet()) {
  557. List<SupplierStation> stations = stationMaps.get(integer);
  558. if(org.springframework.util.CollectionUtils.isEmpty(stations)){
  559. continue;
  560. }
  561. EmployeeStationFace face = new EmployeeStationFace();
  562. face.setAreaId(integer);
  563. List<Integer> stationIds = stations.stream().map(s->s.getId()).collect(Collectors.toList());
  564. List<Integer> employeeIds = stationEmployeeList.stream().filter(se->stationIds.contains(se.getStationId())).map(se->se.getEmployeeId()
  565. ).distinct().collect(Collectors.toList());
  566. List<Employee> employees = employeeList.stream().filter(e->employeeIds.contains(e.getId())).collect(Collectors.toList());
  567. face.setAllStationNum(stationIds.size());
  568. face.setNum(employees.size());
  569. EmployeeStationJsonFace json = new EmployeeStationJsonFace();
  570. json.setTotal(face.getNum());
  571. json.setTitle(Lists.newArrayList("30以下","30-39","40-49","50-59","60及以上"));
  572. //按照年龄30以下,30-39,40-49,50-59,60以上
  573. List<String> maleList = Lists.newArrayList();
  574. List<String> womanList = Lists.newArrayList();
  575. List<Employee> thirtyDown = employees.stream().filter(e->e.getAge()<30).collect(Collectors.toList());
  576. Long thirtyDownMale = thirtyDown.stream().filter(e->e.getGender().equals(1)).count();
  577. Long thirtyDownWoman = thirtyDown.stream().filter(e->e.getGender().equals(0)).count();
  578. maleList.add(thirtyDownMale.toString());
  579. womanList.add(thirtyDownWoman.toString());
  580. List<Employee> thirty = employees.stream().filter(e->e.getAge()>=30 && e.getAge()<40).collect(Collectors.toList());
  581. Long thirtyMale = thirty.stream().filter(e->e.getGender().equals(1)).count();
  582. Long thirtyWoman = thirty.stream().filter(e->e.getGender().equals(0)).count();
  583. maleList.add(thirtyMale.toString());
  584. womanList.add(thirtyWoman.toString());
  585. List<Employee> forty = employees.stream().filter(e->e.getAge()>=40 && e.getAge()<50).collect(Collectors.toList());
  586. Long fortyMale = forty.stream().filter(e->e.getGender().equals(1)).count();
  587. Long fortyWoman = forty.stream().filter(e->e.getGender().equals(0)).count();
  588. maleList.add(fortyMale.toString());
  589. womanList.add(fortyWoman.toString());
  590. List<Employee> fifty = employees.stream().filter(e->e.getAge()>=50 && e.getAge()<60).collect(Collectors.toList());
  591. Long fiftyMale = fifty.stream().filter(e->e.getGender().equals(1)).count();
  592. Long fiftyWoman = fifty.stream().filter(e->e.getGender().equals(0)).count();
  593. maleList.add(fiftyMale.toString());
  594. womanList.add(fiftyWoman.toString());
  595. List<Employee> sixtyUp = employees.stream().filter(e->e.getAge()>=60).collect(Collectors.toList());
  596. Long sixtyUpMale = sixtyUp.stream().filter(e->e.getGender().equals(1)).count();
  597. Long sixtyUpWoman = sixtyUp.stream().filter(e->e.getGender().equals(0)).count();
  598. maleList.add(sixtyUpMale.toString());
  599. womanList.add(sixtyUpWoman.toString());
  600. //按照性别分组
  601. json.setMale(maleList);
  602. json.setWoman(womanList);
  603. face.setLists(JSONObject.toJSONString(json));
  604. returnList.add(face);
  605. }
  606. }
  607. private List<EmployeeStationFace> getEmployeeStationFace(){
  608. List<EmployeeStationFace> returnList = Lists.newArrayList();
  609. //获取驿站员工信息
  610. List<SupplierStationEmployee> stationEmployeeList = baseMapper.supplierStationEmployeeList(dbName);
  611. //获取驿站
  612. List<SupplierStation> stationList = baseMapper.supplierStationList(dbName);
  613. //获取员工
  614. List<Employee> employeeList = baseMapper.employeeList(dbName);
  615. //按照街道分组
  616. Map<Integer,List<SupplierStation>> stationStreetMaps = stationList.stream().filter(s->s.getStreet() != null).collect(Collectors.groupingBy(SupplierStation::getStreet));
  617. getEmployeeData(stationStreetMaps,employeeList,stationEmployeeList,returnList);
  618. //按照区分组
  619. Map<Integer,List<SupplierStation>> stationCountryMaps = stationList.stream().filter(s->s.getCountry() != null).collect(Collectors.groupingBy(SupplierStation::getCountry));
  620. getEmployeeData(stationCountryMaps,employeeList,stationEmployeeList,returnList);
  621. //按照市分组
  622. Map<Integer,List<SupplierStation>> stationCityMaps = stationList.stream().filter(s->s.getCity() != null).collect(Collectors.groupingBy(SupplierStation::getCity));
  623. getEmployeeData(stationCityMaps,employeeList,stationEmployeeList,returnList);
  624. return returnList;
  625. }
  626. private List<SubsidyCustomerFace> getSubsidyCustomerFace(List<CustomerSubsidyDTO> customerList){
  627. List<SubsidyCustomerFace> returnList = Lists.newArrayList();
  628. //按照街道分组
  629. Map<Integer,List<CustomerSubsidyDTO>> streetMaps = customerList.stream().filter(c->c.getNowStreetId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowStreetId));
  630. fillData(streetMaps,returnList,3);
  631. //按照区分组
  632. Map<Integer,List<CustomerSubsidyDTO>> countryMaps = customerList.stream().filter(c->c.getNowCountryId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId));
  633. fillData(countryMaps,returnList,2);
  634. //按照市分组
  635. Map<Integer,List<CustomerSubsidyDTO>> cityMaps = customerList.stream().filter(c->c.getNowCityId() != null).collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCityId));
  636. fillData(cityMaps,returnList,1);
  637. // //探访关爱--已单独汇总,此处不再处理
  638. // customerSubsidyVisitService.processCare(returnList,operatorIds);
  639. return returnList;
  640. }
  641. private void fillData(Map<Integer,List<CustomerSubsidyDTO>> maps, List<SubsidyCustomerFace> returnList,Integer source){
  642. for (Integer integer : maps.keySet()) {
  643. List<CustomerSubsidyDTO> csList = maps.get(integer);
  644. SubsidyCustomerFace face = new SubsidyCustomerFace();
  645. face.setAreaId(integer);
  646. face.setNum(csList.size());
  647. face.setCareAllMember(csList.stream().mapToInt(e-> org.apache.commons.lang.StringUtils.isNotEmpty(e.getCustomerSignId())?1:0).sum());
  648. List<Long> ids = csList.stream().map(c->c.getCustomerId()).collect(Collectors.toList());
  649. face.setCustomerIds(ids);
  650. // List<Long> intersectionList = (List<Long>) CollectionUtils.intersection(face.getCustomerIds(),cardCustomer);
  651. face.setCustomerGovernmentNum(csList.stream().filter(c->c.getCategory().equals(1)).collect(Collectors.toList()).size());
  652. face.setCustomerSocietyNum(face.getNum()-face.getCustomerGovernmentNum());
  653. face.setAllCustomerNum(csList.stream().filter(c ->c.getAge() != null && c.getAge() >= 75).collect(Collectors.toList()).size());
  654. MemberListData data = new MemberListData();
  655. Long totalDetailList = csList.stream().filter(d -> d.getCategory().equals(1)).count();
  656. data.setTotal(Integer.parseInt(totalDetailList.toString()));
  657. data.setTitle(Lists.newArrayList("50以下","50-59", "60-69", "70-79", "80-89", "90及以上"));
  658. List<Integer> maleAgeList = Lists.newArrayList();
  659. 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());
  660. 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());
  661. 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());
  662. 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());
  663. 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());
  664. 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());
  665. data.setMale(maleAgeList);
  666. List<Integer> womanAgeList = Lists.newArrayList();
  667. 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());
  668. 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());
  669. 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());
  670. 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());
  671. 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());
  672. 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());
  673. data.setWoman(womanAgeList);
  674. face.setCustomerAgeListData(data);
  675. List<SubsidyCustomerJsonFace> jsonFaceList = Lists.newArrayList();
  676. if(source.equals(1)){
  677. //按区域分组
  678. Map<Integer,List<CustomerSubsidyDTO>> countryMaps = csList.stream().collect(Collectors.groupingBy(CustomerSubsidyDTO::getNowCountryId));
  679. for (Integer key : countryMaps.keySet()) {
  680. List<CustomerSubsidyDTO> keyList = countryMaps.get(key);
  681. SubsidyCustomerJsonFace jsonFace = new SubsidyCustomerJsonFace();
  682. jsonFace.setAreaId(key);
  683. jsonFace.setTitle(keyList.get(0).getNowCountryName());
  684. jsonFace.setTotal(keyList.size());
  685. jsonFace.setCustomerIds(keyList.stream().map(c->c.getCustomerId()).collect(Collectors.toList()));
  686. jsonFaceList.add(jsonFace);
  687. }
  688. }else{
  689. //按老人类型分组
  690. Map<String,List<CustomerSubsidyDTO>> typeMaps = csList.stream().collect(Collectors.groupingBy(CustomerSubsidyDTO::getCustomerTypeId));
  691. Map<String,SubsidyCustomerJsonFace> faceMap = new HashMap<>();
  692. for (String key : typeMaps.keySet()) {
  693. List<CustomerSubsidyDTO> keyList = typeMaps.get(key);
  694. List<Long> idList = keyList.stream().map(CustomerSubsidyDTO::getCustomerId).collect(Collectors.toList());
  695. String customerType = keyList.get(0).getCustomerType();
  696. if (key.contains(",")){
  697. String[] typeIds = key.split(",");
  698. String[] names = customerType.split(",");
  699. for (int i=0; i<typeIds.length; i++){
  700. mergeJsonFace(faceMap, typeIds[i], idList, names[i]);
  701. }
  702. }else{
  703. mergeJsonFace(faceMap, key, idList, customerType);
  704. }
  705. }
  706. jsonFaceList.addAll(faceMap.values());
  707. }
  708. face.setJsonFace(jsonFaceList);
  709. returnList.add(face);
  710. }
  711. }
  712. private void mergeJsonFace(Map<String, SubsidyCustomerJsonFace> faceMap, String key, List<Long> idList, String customerType) {
  713. SubsidyCustomerJsonFace jsonFace = faceMap.get(key);
  714. if (jsonFace== null){
  715. jsonFace = new SubsidyCustomerJsonFace();
  716. jsonFace.setAreaId(Integer.parseInt(key));
  717. jsonFace.setTitle(customerType);
  718. jsonFace.setTotal(idList.size());
  719. jsonFace.setCustomerIds(idList);
  720. faceMap.put(key, jsonFace);
  721. }else{
  722. jsonFace.getCustomerIds().addAll(idList);
  723. jsonFace.setTotal(jsonFace.getCustomerIds().size());
  724. }
  725. }
  726. private List<CustomerServiceParams> orderServiceCustomerList(List<Integer> operatorIds){
  727. List<CustomerServiceParams> returnList = Lists.newArrayList();
  728. for (Integer operatorId : operatorIds) {
  729. returnList.addAll(baseMapper.orderServiceCustomerList(operatorId,dbName));
  730. }
  731. return returnList;
  732. }
  733. private void changeCustomer(Map<Integer, List<Order>> maps,List<CustomerSubsidyDTO> customerList,List<Integer> operatorIds) {
  734. //更新客户数据
  735. List<SubsidyCustomerFace> customerFaceList = this.getSubsidyCustomerFace(customerList);
  736. //获取已服务老人Id集合
  737. List<CustomerServiceParams> serviceCustomerList = this.orderServiceCustomerList(operatorIds);
  738. for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) {
  739. List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
  740. if(orders == null || orders.isEmpty()){
  741. continue;
  742. }
  743. for (Order order : orders) {
  744. order.setCustomerNum((order.getCustomerNum()==null?0:order.getCustomerNum())+subsidyCustomerFace.getNum());
  745. order.setCustomerGovernmentNum((order.getCustomerGovernmentNum()==null?0:order.getCustomerGovernmentNum())+subsidyCustomerFace.getCustomerGovernmentNum());
  746. order.setCustomerSocietyNum((order.getCustomerSocietyNum()==null?0:order.getCustomerSocietyNum())+subsidyCustomerFace.getCustomerSocietyNum());
  747. order.setCareRate(BigDecimal.ZERO);
  748. order.setAllCustomerNum(order.getAllCustomerNum()+ subsidyCustomerFace.getAllCustomerNum());
  749. order.setCareNum(0);
  750. order.setCarePic("");
  751. order.setCareMember(0);
  752. order.setCareAllMember(0);
  753. //已服务老人数
  754. Long serviceSum = 0L;
  755. if(order.getSourceLevel() == 1){
  756. serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getCityId())).mapToLong(s->s.getCustomerNum()).sum();
  757. }else if(order.getSourceLevel() == 2){
  758. serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getCountryId())).mapToLong(s->s.getCustomerNum()).sum();
  759. }else{
  760. serviceSum = serviceCustomerList.stream().filter(s->order.getAreaId().equals(s.getStreetId())).mapToLong(s->s.getCustomerNum()).sum();
  761. }
  762. order.setCustomerServiceNum(serviceSum.intValue());
  763. if(order.getCustomerNum().equals(0)){
  764. order.setCustomerRate(BigDecimal.ZERO);
  765. }else{
  766. BigDecimal decimal = new BigDecimal(order.getCustomerServiceNum()).divide(new BigDecimal(order.getCustomerNum()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2,BigDecimal.ROUND_HALF_UP);
  767. log.info("CustomerRate==="+decimal);
  768. order.setCustomerRate(decimal);
  769. }
  770. List<SubsidyCustomerJsonFace> jsonFace = subsidyCustomerFace.getJsonFace();
  771. List<String> id = Lists.newArrayList();
  772. List<String> title = Lists.newArrayList();
  773. List<Integer> total = Lists.newArrayList();
  774. List<BigDecimal> rate = Lists.newArrayList();
  775. if(StringUtils.isNotEmpty(order.getCustomerList())){
  776. JSONObject jsonObject = new JSONObject(JSON.parseObject(order.getCustomerList()));
  777. SubsidyCustomerJsonVo vo = JSONObject.toJavaObject(jsonObject, SubsidyCustomerJsonVo.class);
  778. if(!vo.getId().isEmpty()){
  779. id.addAll(vo.getId());
  780. }
  781. title.addAll(vo.getTitle());
  782. total.addAll(vo.getTotal());
  783. rate.addAll(vo.getRate());
  784. }
  785. for (SubsidyCustomerJsonFace face : jsonFace) {
  786. Integer num = face.getTotal();
  787. Long sum = 0L;
  788. if(serviceCustomerList != null && !serviceCustomerList.isEmpty() && order.getSourceLevel().equals(1)){
  789. sum = serviceCustomerList.stream().filter(s->(face.getAreaId().equals(s.getCountryId()) || face.getAreaId().equals(s.getStreetId()))).mapToLong(s->s.getCustomerNum()).sum();
  790. }else{
  791. if(order.getSourceLevel().equals(2)){
  792. 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();
  793. }else if (order.getSourceLevel().equals(3) ){
  794. 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();
  795. }
  796. }
  797. if(id.contains(face.getAreaId().toString())){
  798. for (int i = 0; i < id.size(); i++) {
  799. if(id.get(i).equals(face.getAreaId().toString())){
  800. total.set(i,total.get(i)+face.getTotal());
  801. num = total.get(i);
  802. if(num == 0L){
  803. rate.set(i,BigDecimal.ZERO);
  804. }else{
  805. BigDecimal val = new BigDecimal(sum).divide(new BigDecimal(num),4, BigDecimal.ROUND_HALF_UP);
  806. BigDecimal decimal2 = val.multiply(new BigDecimal("100.0")).setScale(2,BigDecimal.ROUND_HALF_UP);
  807. rate.set(i,decimal2);
  808. }
  809. break;
  810. }
  811. }
  812. }else{
  813. id.add(face.getAreaId().toString());
  814. title.add(face.getTitle());
  815. total.add(face.getTotal());
  816. if(num == 0L){
  817. rate.add(BigDecimal.ZERO);
  818. }else {
  819. BigDecimal decimal2 = new BigDecimal(sum).divide(new BigDecimal(num), 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2, BigDecimal.ROUND_HALF_UP);
  820. rate.add(decimal2);
  821. }
  822. }
  823. }
  824. SubsidyCustomerJsonVo vo = new SubsidyCustomerJsonVo();
  825. vo.setId(id);
  826. vo.setTitle(title);
  827. vo.setTotal(total);
  828. vo.setRate(rate);
  829. order.setCustomerList(JSONObject.toJSONString(vo));
  830. if(StringUtils.isNotEmpty(order.getCustomerAgeList()) && subsidyCustomerFace.getCustomerAgeListData() != null){
  831. MemberListData data =JSONObject.toJavaObject(JSON.parseObject(order.getCustomerAgeList()), MemberListData.class);
  832. MemberListData newData = subsidyCustomerFace.getCustomerAgeListData();
  833. data.setTotal(data.getTotal()+newData.getTotal());
  834. for (int i = 0; i < data.getMale().size(); i++) {
  835. data.getMale().set(i,data.getMale().get(i)+newData.getMale().get(i));
  836. }
  837. for (int i = 0; i < data.getWoman().size(); i++) {
  838. data.getWoman().set(i,data.getWoman().get(i)+newData.getWoman().get(i));
  839. }
  840. order.setCustomerAgeList(JSONObject.toJSONString(data));
  841. }else if(subsidyCustomerFace.getCustomerAgeListData() != null){
  842. order.setCustomerAgeList(JSONObject.toJSONString(subsidyCustomerFace.getCustomerAgeListData()));
  843. }
  844. }
  845. }
  846. }
  847. private List<SubsidyCustomerFace> integralCustomer(DateParams dateParams){
  848. List<SubsidyCustomerFace> returnList = Lists.newArrayList();
  849. QueryWrapper detailQueryWrapper = new QueryWrapper<>();
  850. if(dateParams.getStartDate() != null){
  851. detailQueryWrapper.ge("created_date",dateParams.getStartDate());
  852. }
  853. if(dateParams.getEndDate() != null){
  854. detailQueryWrapper.le("created_date",dateParams.getEndDate());
  855. }
  856. List<Integer> operationIds = baseMapper.getIntegralCardAccOperatorIdList(dbName,detailQueryWrapper);
  857. List<IntegralTrans> detailsCustomer = Lists.newArrayList();
  858. QueryWrapper queryWrapper = new QueryWrapper();
  859. if(dateParams.getStartDate() != null){
  860. queryWrapper.ge("d.created_date",dateParams.getStartDate());
  861. }
  862. if(dateParams.getEndDate() != null){
  863. queryWrapper.le("d.created_date",dateParams.getEndDate());
  864. }
  865. for (Integer operationId : operationIds) {
  866. //获取积分数据
  867. detailsCustomer.addAll(baseMapper.integralCustomerList(queryWrapper,operationId,dbName));
  868. }
  869. log.info("---处理积分客户数据开始----");
  870. if(!detailsCustomer.isEmpty()){
  871. Map<Integer,List<IntegralTrans>> streetCustomerMaps = detailsCustomer.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId));
  872. fillData(streetCustomerMaps,returnList);
  873. Map<Integer,List<IntegralTrans>> cityCustomerMaps = detailsCustomer.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId));
  874. fillData(cityCustomerMaps,returnList);
  875. Map<Integer,List<IntegralTrans>> countryCustomerMaps = detailsCustomer.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId));
  876. fillData(countryCustomerMaps,returnList);
  877. }
  878. log.info("---处理积分客户数据结束----");
  879. return returnList;
  880. }
  881. private void fillData(Map<Integer,List<IntegralTrans>> mapCustomerData, List<SubsidyCustomerFace> returnList){
  882. for (Integer integer : mapCustomerData.keySet()) {
  883. List<IntegralTrans> csList = mapCustomerData.get(integer);
  884. SubsidyCustomerFace face = new SubsidyCustomerFace();
  885. face.setAreaId(integer);
  886. face.setCustomerNum(csList.size());
  887. MemberListData data = new MemberListData();
  888. List<IntegralTrans> totalDetailList = csList.stream().filter(d -> d.getCreatedDate().after(com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date()))).collect(Collectors.toList());
  889. data.setTotal(totalDetailList.size());
  890. data.setTitle(Lists.newArrayList("60以下", "60-69", "70-79", "80-89", "90及以上"));
  891. List<Integer> maleAgeList = Lists.newArrayList();
  892. maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() < 60).collect(Collectors.toList()).size());
  893. 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());
  894. 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());
  895. 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());
  896. maleAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(1) && c.getAge() >= 90).collect(Collectors.toList()).size());
  897. data.setMale(maleAgeList);
  898. List<Integer> womanAgeList = Lists.newArrayList();
  899. womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() < 60).collect(Collectors.toList()).size());
  900. 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());
  901. 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());
  902. 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());
  903. womanAgeList.add(csList.stream().filter(c -> c.getSex() != null && c.getAge() != null && c.getSex().equals(0) && c.getAge() >= 90).collect(Collectors.toList()).size());
  904. data.setWoman(womanAgeList);
  905. face.setMemberListData(data);
  906. returnList.add(face);
  907. }
  908. }
  909. private void changeCustomerIntegral(Map<Integer, List<Order>> maps,DateParams dateParams) {
  910. List<SubsidyCustomerFace> integralList = this.integralCustomer(dateParams);
  911. Calendar calendar2 = Calendar.getInstance();
  912. calendar2.setTime(dateParams.getEndDate());
  913. int day = calendar2.get(Calendar.DAY_OF_MONTH);
  914. int hour = calendar2.get(Calendar.HOUR_OF_DAY);
  915. for (SubsidyCustomerFace subsidyCustomerFace : integralList) {
  916. List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
  917. if (CollectionUtils.isEmpty(orders)) {
  918. continue;
  919. }
  920. for (Order order : orders) {
  921. //积分相关
  922. if(order.getPointMember() == null){
  923. order.setPointMember(0);
  924. }
  925. if(subsidyCustomerFace.getCustomerNum() != null){
  926. Integer num =order.getPointMember()+subsidyCustomerFace.getCustomerNum();
  927. order.setPointMember(num);
  928. }
  929. if(StringUtils.isNotEmpty(order.getMemberListData()) && subsidyCustomerFace.getMemberListData() != null){
  930. MemberListData data =JSONObject.toJavaObject(JSON.parseObject(order.getMemberListData()), MemberListData.class);
  931. MemberListData newData = subsidyCustomerFace.getMemberListData();
  932. if(day == 1 && hour == 0){
  933. data.setTotal(newData.getTotal());
  934. }else{
  935. data.setTotal(data.getTotal()+newData.getTotal());
  936. }
  937. for (int i = 0; i < data.getMale().size(); i++) {
  938. data.getMale().set(i,data.getMale().get(i)+newData.getMale().get(i));
  939. }
  940. for (int i = 0; i < data.getWoman().size(); i++) {
  941. data.getWoman().set(i,data.getWoman().get(i)+newData.getWoman().get(i));
  942. }
  943. order.setMemberListData(JSONObject.toJSONString(data));
  944. }else if(subsidyCustomerFace.getMemberListData() != null){
  945. order.setMemberListData(JSONObject.toJSONString(subsidyCustomerFace.getMemberListData()));
  946. }
  947. }
  948. }
  949. }
  950. private List<SubsidyCustomerFace> integralTrans(DateParams dateParams){
  951. List<SubsidyCustomerFace> returnList = Lists.newArrayList();
  952. List<Integer> operationIds = baseMapper.getIntegralCardDetailOperatorIdList(dbName);
  953. List<IntegralTrans> detailsTrans = Lists.newArrayList();
  954. QueryWrapper queryWrapper2 = new QueryWrapper();
  955. if(dateParams.getStartDate() != null){
  956. queryWrapper2.ge("t.build_time",dateParams.getStartDate());
  957. }
  958. if(dateParams.getEndDate() != null){
  959. queryWrapper2.le("t.build_time",dateParams.getEndDate());
  960. }
  961. for (Integer operationId : operationIds) {
  962. //获取积分数据
  963. detailsTrans.addAll(baseMapper.integralTransList(queryWrapper2,operationId,dbName));
  964. }
  965. log.info("---处理流水数据开始----");
  966. Map<Integer,List<IntegralTrans>> streetTransMaps = detailsTrans.stream().filter(i->i.getStreetId() != null).collect(Collectors.groupingBy(IntegralTrans::getStreetId));
  967. fillData2(streetTransMaps,returnList);
  968. Map<Integer,List<IntegralTrans>> cityTransMaps = detailsTrans.stream().filter(i->i.getCityId() != null).collect(Collectors.groupingBy(IntegralTrans::getCityId));
  969. fillData2(cityTransMaps,returnList);
  970. Map<Integer,List<IntegralTrans>> countryTransMaps = detailsTrans.stream().filter(i->i.getCountryId() != null).collect(Collectors.groupingBy(IntegralTrans::getCountryId));
  971. fillData2(countryTransMaps,returnList);
  972. log.info("---处理流水数据结束----");
  973. return returnList;
  974. }
  975. private void fillData2(Map<Integer,List<IntegralTrans>> data2,List<SubsidyCustomerFace> returnList){
  976. for (Integer integer : data2.keySet()) {
  977. List<IntegralTrans> dataList = data2.get(integer);
  978. SubsidyCustomerFace face = new SubsidyCustomerFace();
  979. face.setAreaId(integer);
  980. Long grantSum = dataList.stream().filter(t -> t.getTransType().equals("0")).mapToLong(t -> t.getAmount()).sum();
  981. face.setGrantNum(grantSum);
  982. Long exchangeSum = dataList.stream().filter(t -> t.getTransType().equals("1")).mapToLong(t -> t.getAmount()).sum();
  983. face.setExchangeNum(exchangeSum);
  984. List<MonthData> goodsList = Lists.newArrayList();
  985. Map<Integer, List<IntegralTrans>> maps = dataList.stream().filter(i -> i.getParentId() != null).collect(Collectors.groupingBy(IntegralTrans::getParentId));
  986. for (Integer categoryId : maps.keySet()) {
  987. List<IntegralTrans> categoryList = maps.get(categoryId);
  988. MonthData monthData = new MonthData();
  989. monthData.setAddValue(0L);
  990. for (IntegralTrans IntegralTrans : categoryList) {
  991. String fullName = IntegralTrans.getFullName();
  992. if (fullName.contains("/")) {
  993. fullName = fullName.split("/")[0];
  994. }
  995. monthData.setText(fullName);
  996. monthData.setAddValue(monthData.getAddValue() + IntegralTrans.getAmount());
  997. }
  998. if (monthData.getAddValue() > 0L) {
  999. goodsList.add(monthData);
  1000. }
  1001. }
  1002. //消分商品个数统计
  1003. if (!goodsList.isEmpty()) {
  1004. face.setPointGoodsData2(goodsList);
  1005. }
  1006. face.setPointMonthData(addMonth(dataList, 0));
  1007. face.setPointCountData(addMonth(dataList, 1));
  1008. returnList.add(face);
  1009. }
  1010. }
  1011. private List<MonthData> addMonth(List<IntegralTrans> transList,Integer type){
  1012. Date endDate = new Date();
  1013. Calendar calendar = Calendar.getInstance();
  1014. calendar.setTime(com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(endDate));
  1015. calendar.add(Calendar.SECOND,1);
  1016. calendar.add(Calendar.YEAR, -1);
  1017. Date startDate = calendar.getTime();
  1018. List<MonthData> monthList = Lists.newArrayList();
  1019. Calendar calendar2 = Calendar.getInstance();
  1020. for (int i = 0; i < 12; i++) {
  1021. if(i>0){
  1022. calendar2.add(Calendar.MONTH, 1);
  1023. }else{
  1024. calendar2.setTime(startDate);
  1025. }
  1026. String monthStr = String.format("%02d", calendar2.get(Calendar.MONTH)+1);
  1027. MonthData data = new MonthData();
  1028. data.setText(monthStr+"月");
  1029. if(type.equals(0)){
  1030. if(transList.isEmpty()){
  1031. data.setAddValue(0L);
  1032. data.setUseValue(0L);
  1033. }else{
  1034. 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());
  1035. 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());
  1036. }
  1037. }else {
  1038. if (transList.isEmpty()) {
  1039. data.setAddValue(0L);
  1040. data.setUseValue(0L);
  1041. } else {
  1042. 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());
  1043. 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());
  1044. }
  1045. }
  1046. monthList.add(data);
  1047. }
  1048. return monthList;
  1049. }
  1050. private void changeTransIntegral(Map<Integer, List<Order>> maps,DateParams dateParams) {
  1051. List<SubsidyCustomerFace> integralList = this.integralTrans(dateParams);
  1052. for (SubsidyCustomerFace subsidyCustomerFace : integralList) {
  1053. List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
  1054. if (CollectionUtils.isEmpty(orders)) {
  1055. continue;
  1056. }
  1057. for (Order order : orders) {
  1058. //积分相关
  1059. if(order.getPointGrant() == null){
  1060. order.setPointGrant(0L);
  1061. }
  1062. if(subsidyCustomerFace.getGrantNum() != null){
  1063. Long num = order.getPointGrant()+subsidyCustomerFace.getGrantNum();
  1064. order.setPointGrant(num);
  1065. }
  1066. if(order.getPointExchange() == null){
  1067. order.setPointExchange(0L);
  1068. }
  1069. if(subsidyCustomerFace.getExchangeNum() != null){
  1070. Long num =order.getPointExchange() + subsidyCustomerFace.getExchangeNum();
  1071. order.setPointExchange(num);
  1072. }
  1073. if(StringUtils.isNotEmpty(order.getPointGoodsData2()) && CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointGoodsData2())){
  1074. List<MonthData> list =JSONArray.parseArray(order.getPointGoodsData2(),MonthData.class);
  1075. for (MonthData data : subsidyCustomerFace.getPointGoodsData2()) {
  1076. boolean isHave = false;
  1077. for (MonthData monthData : list) {
  1078. if(data.getText().equals(monthData.getText())){
  1079. monthData.setAddValue(monthData.getAddValue()+data.getAddValue());
  1080. isHave = true;
  1081. break;
  1082. }
  1083. }
  1084. if(!isHave){
  1085. list.add(data);
  1086. }
  1087. }
  1088. order.setPointGoodsData2(JSONObject.toJSONString(list));
  1089. }else if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointGoodsData2())){
  1090. order.setPointGoodsData2(JSONObject.toJSONString(subsidyCustomerFace.getPointGoodsData2()));
  1091. }
  1092. if(StringUtils.isNotEmpty(order.getPointCountData()) && CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointCountData())){
  1093. List<MonthData> list =JSONArray.parseArray(order.getPointCountData(),MonthData.class);
  1094. List<MonthData> nowList =subsidyCustomerFace.getPointCountData();
  1095. int t = 0;
  1096. if(list.get(0).getText().equals(nowList.get(nowList.size()-1).getText())){
  1097. t = 1;
  1098. }
  1099. for (int i = 0; i < nowList.size(); i++) {
  1100. if(t ==nowList.size()){
  1101. break;
  1102. }
  1103. nowList.get(i).setAddValue(nowList.get(i).getAddValue()+list.get(t).getAddValue());
  1104. nowList.get(i).setUseValue(nowList.get(i).getUseValue()+list.get(t).getUseValue());
  1105. t++;
  1106. }
  1107. order.setPointCountData(JSONObject.toJSONString(nowList));
  1108. }else if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointCountData())){
  1109. order.setPointCountData(JSONObject.toJSONString(subsidyCustomerFace.getPointCountData()));
  1110. }
  1111. if(StringUtils.isNotEmpty(order.getPointMonthData()) && CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointMonthData())){
  1112. List<MonthData> list =JSONArray.parseArray(order.getPointMonthData(),MonthData.class);
  1113. List<MonthData> nowList =subsidyCustomerFace.getPointMonthData();
  1114. int t = 0;
  1115. if(list.get(0).getText().equals(nowList.get(nowList.size()-1).getText())){
  1116. t = 1;
  1117. }
  1118. for (int i = 0; i < nowList.size(); i++) {
  1119. if(t ==nowList.size()){
  1120. break;
  1121. }
  1122. nowList.get(i).setAddValue(nowList.get(i).getAddValue()+list.get(t).getAddValue());
  1123. nowList.get(i).setUseValue(nowList.get(i).getUseValue()+list.get(t).getUseValue());
  1124. t++;
  1125. }
  1126. order.setPointMonthData(JSONObject.toJSONString(nowList));
  1127. }else if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointMonthData())){
  1128. order.setPointMonthData(JSONObject.toJSONString(subsidyCustomerFace.getPointMonthData()));
  1129. }
  1130. }
  1131. }
  1132. }
  1133. private List<SubsidyCustomerFace> getMerchantIntegralFace(List<Integer> operatorIds,List<ListParams> categoryList){
  1134. List<SubsidyCustomerFace> returnList = Lists.newArrayList();
  1135. List<IntegralTransaction> transList = Lists.newArrayList();
  1136. List<Product> products = Lists.newArrayList();
  1137. for (Integer operatorId : operatorIds) {
  1138. transList.addAll(baseMapper.integralTransactionList(dbName,operatorId));
  1139. products.addAll(baseMapper.queryIntegralProduct(dbName,operatorId));
  1140. }
  1141. List<StationMerchant> stationMerchantList = baseMapper.getStationMerchantList(dbName);
  1142. List<IntegralProduct> productList = baseMapper.integralProductList(dbName);
  1143. 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());
  1144. List<ListParams> categoryFilterList = categoryList.stream().filter(c->c.getKey().equals(1)).collect(Collectors.toList());
  1145. //按照街道分组
  1146. Map<Integer,List<StationMerchant>> stationStreetMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet));
  1147. fillStationData(stationStreetMaps,returnList,3,productList,categoryFilterList,products,transList);
  1148. //按照区分组
  1149. Map<Integer,List<StationMerchant>> stationCountryMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry));
  1150. fillStationData(stationCountryMaps,returnList,2,productList,categoryFilterList,products,transList);
  1151. //按照市分组
  1152. Map<Integer,List<StationMerchant>> stationCityMaps = stationList.stream().collect(Collectors.groupingBy(StationMerchant::getCity));
  1153. fillStationData(stationCityMaps,returnList,1,productList,categoryFilterList,products,transList);
  1154. log.info("---客户积分处理结束---");
  1155. return returnList;
  1156. }
  1157. private void fillStationData(Map<Integer,List<StationMerchant>> maps, List<SubsidyCustomerFace> returnList,Integer source,
  1158. List<IntegralProduct> productList,List<ListParams> categoryList,List<Product> products,
  1159. List<IntegralTransaction> transList){
  1160. for (Integer integer : maps.keySet()) {
  1161. List<StationMerchant> csList = maps.get(integer);
  1162. SubsidyCustomerFace face = new SubsidyCustomerFace();
  1163. face.setAreaId(integer);
  1164. face.setPointStation(csList.size());
  1165. List<MonthData> dataList = Lists.newArrayList();
  1166. for (StationMerchant dto : csList) {
  1167. MonthData monthData = new MonthData();
  1168. monthData.setText(dto.getName());
  1169. monthData.setAddValue(productList.stream().filter(p->p.getMerchantId().equals(dto.getId())).count());
  1170. if(monthData.getAddValue()>0L){
  1171. dataList.add(monthData);
  1172. }
  1173. }
  1174. //积分商品统计
  1175. dataList = dataList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
  1176. if(dataList.size() >=5){
  1177. face.setGoodsData(dataList.subList(0,5));
  1178. }else{
  1179. face.setGoodsData(dataList);
  1180. }
  1181. List<Integer> supplierIds = csList.stream().filter(s->s.getSupplierId() != null).map(s->s.getSupplierId()).distinct().collect(Collectors.toList());
  1182. List<Product> pList = products.stream().filter(p->supplierIds.contains(p.getProviderId())).collect(Collectors.toList());
  1183. List<MonthData> pDataList = Lists.newArrayList();
  1184. for (ListParams params : categoryList) {
  1185. MonthData monthData = new MonthData();
  1186. monthData.setText(params.getName());
  1187. Long val = 0L;
  1188. for (Product product : pList) {
  1189. if(product.getParentCategoryId().equals(params.getId().longValue())){
  1190. val++;
  1191. }
  1192. }
  1193. if(val>0L){
  1194. monthData.setAddValue(val);
  1195. pDataList.add(monthData);
  1196. }
  1197. }
  1198. //消分商品统计
  1199. face.setGoodsData2(pDataList);
  1200. switch(source){
  1201. case 1:
  1202. //按区域分组
  1203. Map<Integer,List<StationMerchant>> countryMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getCountry));
  1204. List<MonthData> countryList = Lists.newArrayList();
  1205. for (Integer country : countryMaps.keySet()) {
  1206. List<StationMerchant> list = countryMaps.get(country);
  1207. MonthData monthData = new MonthData();
  1208. monthData.setText(countryMaps.get(country).get(0).getCountryName());
  1209. monthData.setAddValue(Long.parseLong(String.valueOf(list.size())));
  1210. countryList.add(monthData);
  1211. }
  1212. countryList = countryList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
  1213. if(countryList.size() >=5){
  1214. face.setProviderData(countryList.subList(0,5));
  1215. }else{
  1216. face.setProviderData(countryList);
  1217. }
  1218. break;
  1219. case 2:
  1220. //按街道分组
  1221. Map<Integer,List<StationMerchant>> streetMaps = csList.stream().collect(Collectors.groupingBy(StationMerchant::getStreet));
  1222. List<MonthData> streetList = Lists.newArrayList();
  1223. for (Integer street : streetMaps.keySet()) {
  1224. List<StationMerchant> list = streetMaps.get(street);
  1225. MonthData monthData = new MonthData();
  1226. monthData.setText(streetMaps.get(street).get(0).getStreetName());
  1227. monthData.setAddValue(Long.parseLong(String.valueOf(list.size())));
  1228. streetList.add(monthData);
  1229. }
  1230. streetList = streetList.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
  1231. if(streetList.size() >=5){
  1232. face.setProviderData(streetList.subList(0,5));
  1233. }else{
  1234. face.setProviderData(streetList);
  1235. }
  1236. break;
  1237. case 3:
  1238. //按商户名称
  1239. List<MonthData> nameList = Lists.newArrayList();
  1240. for (StationMerchant dto : csList) {
  1241. MonthData monthData = new MonthData();
  1242. monthData.setText(dto.getName());
  1243. nameList.add(monthData);
  1244. }
  1245. if(nameList.size() >=5){
  1246. face.setProviderData(nameList.subList(0,5));
  1247. }else{
  1248. face.setProviderData(nameList);
  1249. }
  1250. break;
  1251. }
  1252. List<Integer> ids = csList.stream().map(c->c.getId()).collect(Collectors.toList());
  1253. Map<Integer,List<IntegralTransaction>> transMaps = transList.stream().filter(t->ids.contains(t.getMerchantId())).collect(Collectors.groupingBy(IntegralTransaction::getMerchantId));
  1254. List<MonthData> dataList2 = Lists.newArrayList();
  1255. for (Integer tran : transMaps.keySet()) {
  1256. List<IntegralTransaction> trans = transMaps.get(tran);
  1257. MonthData data = new MonthData();
  1258. data.setText(trans.get(0).getMerchantName());
  1259. Long val = 0L;
  1260. for (IntegralTransaction transaction : trans) {
  1261. val += transaction.getIntegral() * transaction.getNum();
  1262. }
  1263. data.setAddValue(val);
  1264. dataList2.add(data);
  1265. }
  1266. //积分商品个数统计
  1267. dataList2 = dataList2.stream().sorted(Comparator.comparing(MonthData::getAddValue).reversed()).collect(Collectors.toList());
  1268. if(dataList2.size() >=5){
  1269. face.setPointGoodsData(dataList2.subList(0,5));
  1270. }else{
  1271. face.setPointGoodsData(dataList2);
  1272. }
  1273. returnList.add(face);
  1274. }
  1275. }
  1276. private void changeIntegral(Map<Integer, List<Order>> maps,List<Integer> operatorIds,List<ListParams> categoryList) {
  1277. List<SubsidyCustomerFace> customerFaceList = this.getMerchantIntegralFace(operatorIds,categoryList);
  1278. for (SubsidyCustomerFace subsidyCustomerFace : customerFaceList) {
  1279. List<Order> orders = maps.get(subsidyCustomerFace.getAreaId());
  1280. if(orders == null || orders.isEmpty()){
  1281. continue;
  1282. }
  1283. for (Order order : orders) {
  1284. //积分相关
  1285. order.setPointStation(subsidyCustomerFace.getPointStation());
  1286. if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getPointGoodsData())){
  1287. order.setPointGoodsData(JSONObject.toJSONString(subsidyCustomerFace.getPointGoodsData()));
  1288. }
  1289. if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getProviderData())){
  1290. order.setProviderData(JSONObject.toJSONString(subsidyCustomerFace.getProviderData()));
  1291. }
  1292. if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getGoodsData())){
  1293. order.setGoodsData(JSONObject.toJSONString(subsidyCustomerFace.getGoodsData()));
  1294. }
  1295. if(CollectionUtils.isNotEmpty(subsidyCustomerFace.getGoodsData2())){
  1296. order.setGoodsData2(JSONObject.toJSONString(subsidyCustomerFace.getGoodsData2()));
  1297. }
  1298. }
  1299. }
  1300. }
  1301. private List<OrderStatisticsData> getOrderStatisticsDataList(List<Integer> ids,DateParams dateParams,List<ListParams> categoryList){
  1302. List<OrderStatisticsData> returnList = Lists.newArrayList();
  1303. List<OrderIntegrationData> list = Lists.newArrayList();
  1304. for (Integer id : ids) {
  1305. QueryWrapper queryWrapper = new QueryWrapper<>();
  1306. if(dateParams.getStartDate() != null){
  1307. queryWrapper.ge("o.finish_time",dateParams.getStartDate());
  1308. }
  1309. if(dateParams.getEndDate() != null){
  1310. queryWrapper.lt("o.finish_time",dateParams.getEndDate());
  1311. }
  1312. //获取已完成的服务工单
  1313. list.addAll(baseMapper.queryOrderIntegrationData(id,dbName,queryWrapper));
  1314. }
  1315. Map<Integer,List<ListParams>> categoryMap = categoryList.stream().collect(Collectors.groupingBy(ListParams::getId));
  1316. //按照市统计
  1317. Map<Integer,List<OrderIntegrationData>> cityMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCityId));
  1318. //按照区统计
  1319. Map<Integer,List<OrderIntegrationData>> countryMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getCountryId));
  1320. //按照街道统计
  1321. Map<Integer,List<OrderIntegrationData>> streetMaps = list.stream().collect(Collectors.groupingBy(OrderIntegrationData::getStreetId));
  1322. for (Integer integer : cityMaps.keySet()) {
  1323. integrationData(returnList,cityMaps.get(integer),integer,categoryMap);
  1324. }
  1325. for (Integer integer : countryMaps.keySet()) {
  1326. integrationData(returnList,countryMaps.get(integer),integer,categoryMap);
  1327. }
  1328. for (Integer integer : streetMaps.keySet()) {
  1329. integrationData(returnList,streetMaps.get(integer),integer,categoryMap);
  1330. }
  1331. return returnList;
  1332. }
  1333. private void integrationData(List<OrderStatisticsData> returnList,List<OrderIntegrationData> orderList,
  1334. Integer areaId,Map<Integer,List<ListParams>> categoryMap){
  1335. OrderStatisticsData data = new OrderStatisticsData();
  1336. data.setAreaId(areaId);
  1337. List<Long> visitNumList = orderList.stream().map(o->o.getCustomerId()).distinct().collect(Collectors.toList());
  1338. data.setVisitNum(visitNumList.size());
  1339. /* List<OrderIntegrationData> visitOrderList = orderList.stream().filter(o->o.getVisitStatus().equals(1)).collect(Collectors.toList());
  1340. BigDecimal visitRate = new BigDecimal(visitOrderList.size()).divide(new BigDecimal(orderList.size()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2,BigDecimal.ROUND_HALF_UP);*/
  1341. data.setVisitRate(new BigDecimal(100));
  1342. if(data.getVisitNum()>0){
  1343. List<Long> satisfactionList = orderList.stream().filter(v->v.getResult().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList());
  1344. data.setSatisfactionNum(satisfactionList.size());
  1345. List<Long> qualifiedList = orderList.stream().filter(v->v.getQualified().equals(1)).map(o->o.getOrderId()).collect(Collectors.toList());
  1346. //BigDecimal qualifiedRate = new BigDecimal(qualifiedList.size()).divide(new BigDecimal(orderList.size()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100.0)).setScale(2,BigDecimal.ROUND_HALF_UP);
  1347. data.setQualifiedNum(qualifiedList.size());
  1348. }else{
  1349. data.setSatisfactionNum(0);
  1350. data.setQualifiedNum(0);
  1351. }
  1352. data.setOrderNum(orderList.size());
  1353. List<OrderIntegrationData> monthOrderList = orderList.stream()
  1354. .filter(o-> DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.getFirstDayOfMonth(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.getLastDayOfMonth(new Date())))
  1355. .collect(Collectors.toList());
  1356. data.setOrderNumMonth(monthOrderList.size());
  1357. Map<String, String> dateMap = com.poteviohealth.cgp.common.utils.DateUtils.getWeekDate();
  1358. try {
  1359. Date monday = com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("mondayDate")));
  1360. Date sunday = com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(com.alibaba.excel.util.DateUtils.parseDate(dateMap.get("sundayDate")));
  1361. List<OrderIntegrationData> weekOrderList = orderList.stream().filter(o->DateUtil.isIn(o.getFinishTime(),monday,sunday)).collect(Collectors.toList());
  1362. data.setOrderNumWeek(weekOrderList.size());
  1363. } catch (ParseException e) {
  1364. e.printStackTrace();
  1365. }
  1366. List<OrderIntegrationData> dayOrderList = orderList.stream()
  1367. .filter(o->DateUtil.isIn(o.getFinishTime(), com.poteviohealth.cgp.common.utils.DateUtils.startOfDay(new Date()), com.poteviohealth.cgp.common.utils.DateUtils.endOfDay(new Date())))
  1368. .collect(Collectors.toList());
  1369. data.setOrderNumDay(dayOrderList.size());
  1370. //服务类型统计
  1371. List<OrderServiceTypeDTO> typeList = Lists.newArrayList();
  1372. Map<Integer,List<OrderIntegrationData>> orderCategoryMaps = orderList.stream().collect(Collectors.groupingBy(OrderIntegrationData::getProductCategoryId));
  1373. Map<Integer,Integer> maps = Maps.newHashMap();
  1374. for (Integer integer : orderCategoryMaps.keySet()) {
  1375. List<ListParams> list = categoryMap.get(integer);
  1376. if(list != null && !list.isEmpty()){
  1377. ListParams listParent = categoryMap.get(list.get(0).getKey()).get(0);
  1378. if(maps.containsKey(listParent.getId())){
  1379. maps.put(listParent.getId(),maps.get(listParent.getId())+orderCategoryMaps.get(integer).size());
  1380. }else{
  1381. maps.put(listParent.getId(),orderCategoryMaps.get(integer).size());
  1382. }
  1383. }
  1384. }
  1385. DecimalFormat df = new DecimalFormat("#0.00");
  1386. if(!maps.isEmpty()){
  1387. Integer sum = maps.values().stream().mapToInt(Integer::intValue).sum();
  1388. for (Integer integer : maps.keySet()) {
  1389. OrderServiceTypeDTO dto = new OrderServiceTypeDTO();
  1390. dto.setId(integer);
  1391. dto.setCount(maps.get(integer));
  1392. dto.setName(categoryMap.get(integer).get(0).getName());
  1393. if(sum == 0){
  1394. dto.setRate("0");
  1395. }else{
  1396. dto.setRate(df.format((dto.getCount().doubleValue()/sum)*100.0));
  1397. }
  1398. typeList.add(dto);
  1399. }
  1400. typeList = typeList.stream().sorted(Comparator.comparing(OrderServiceTypeDTO::getCount).reversed()).collect(Collectors.toList());
  1401. }
  1402. if(typeList.size()>=5){
  1403. data.setServiceTypeList(JSON.toJSONString(typeList.subList(0,5)));
  1404. }else{
  1405. data.setServiceTypeList(JSON.toJSONString(typeList));
  1406. }
  1407. returnList.add(data);
  1408. }
  1409. private void changeOrder(Map<Integer, List<Order>> maps,DateParams dateParams,List<Integer> operatorIds,List<ListParams> categoryList) {
  1410. Calendar calendar = Calendar.getInstance();
  1411. calendar.setTime(dateParams.getEndDate());
  1412. DecimalFormat df = new DecimalFormat("#0.00");
  1413. //更新工单相关数据
  1414. List<OrderStatisticsData> orderList = this.getOrderStatisticsDataList(operatorIds,dateParams,categoryList);
  1415. for (OrderStatisticsData orderStatisticsData : orderList) {
  1416. List<Order> orders = maps.get(orderStatisticsData.getAreaId());
  1417. if(orders == null || orders.isEmpty()){
  1418. continue;
  1419. }
  1420. for (Order order : orders) {
  1421. if(order.getVisitNum() == null){
  1422. order.setVisitNum(0);
  1423. }
  1424. if(order.getOrderNum() == null){
  1425. order.setOrderNum(0);
  1426. }
  1427. if(order.getSatisfactionRate() == null){
  1428. order.setSatisfactionRate(new BigDecimal("0.00"));
  1429. }
  1430. if(order.getQualifiedRate() == null){
  1431. order.setQualifiedRate(new BigDecimal("0.00"));
  1432. }
  1433. BigDecimal satisfaction = order.getSatisfactionRate().multiply(new BigDecimal(order.getOrderNum())).divide(new BigDecimal("100.0"),2,BigDecimal.ROUND_HALF_UP);
  1434. BigDecimal qualified = order.getQualifiedRate().multiply(new BigDecimal(order.getOrderNum())).divide(new BigDecimal("100.0"),2,BigDecimal.ROUND_HALF_UP);
  1435. order.setOrderNum(order.getOrderNum()+orderStatisticsData.getOrderNum());
  1436. order.setVisitNum(order.getVisitNum()+orderStatisticsData.getVisitNum());
  1437. order.setVisitRate(orderStatisticsData.getVisitRate());
  1438. if(order.getOrderNum().equals(0)){
  1439. order.setSatisfactionRate(new BigDecimal("0.00"));
  1440. order.setQualifiedRate(new BigDecimal("0.00"));
  1441. }else{
  1442. BigDecimal addSatisfaction = satisfaction.add(new BigDecimal(orderStatisticsData.getSatisfactionNum()));
  1443. if(order.getOrderNum() == null || order.getOrderNum().equals(0)){
  1444. order.setSatisfactionRate(new BigDecimal("0.00"));
  1445. order.setQualifiedRate(new BigDecimal("0.00"));
  1446. }else{
  1447. order.setSatisfactionRate(addSatisfaction.multiply(new BigDecimal("100.0")).divide(new BigDecimal(order.getOrderNum()),2,BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP));
  1448. if(order.getSatisfactionRate().compareTo(new BigDecimal(100))>0){
  1449. order.setSatisfactionRate(new BigDecimal(100));
  1450. }
  1451. BigDecimal addQualified = qualified.add(new BigDecimal(orderStatisticsData.getQualifiedNum()));
  1452. order.setQualifiedRate(addQualified.divide(new BigDecimal(order.getOrderNum()),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100.0")).setScale(2,BigDecimal.ROUND_HALF_UP));
  1453. if(order.getQualifiedRate().compareTo(new BigDecimal(100))>0){
  1454. order.setQualifiedRate(new BigDecimal(100));
  1455. }
  1456. }
  1457. }
  1458. if(calendar.get(Calendar.DAY_OF_MONTH) == 1 && calendar.get(Calendar.HOUR_OF_DAY) == 0){
  1459. //每月1日0点清零
  1460. order.setOrderNumMonth(0);
  1461. }else{
  1462. order.setOrderNumMonth((order.getOrderNumMonth() == null ?0:order.getOrderNumMonth())+orderStatisticsData.getOrderNumMonth());
  1463. }
  1464. if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY && calendar.get(Calendar.HOUR_OF_DAY) == 0) {
  1465. //每周一0点清零
  1466. order.setOrderNumWeek(0);
  1467. }else{
  1468. order.setOrderNumWeek((order.getOrderNumWeek()==null?0:order.getOrderNumWeek())+orderStatisticsData.getOrderNumWeek());
  1469. }
  1470. if(calendar.get(Calendar.HOUR_OF_DAY) == 0){
  1471. //每天0点清零
  1472. order.setOrderNumDay(0);
  1473. }else{
  1474. order.setOrderNumDay((order.getOrderNumDay()==null?0:order.getOrderNumDay())+orderStatisticsData.getOrderNumDay());
  1475. }
  1476. if(StringUtils.isEmpty(order.getServiceTypeList())){
  1477. order.setServiceTypeList(orderStatisticsData.getServiceTypeList());
  1478. }else if(StringUtils.isNotEmpty(orderStatisticsData.getServiceTypeList())){
  1479. List<OrderServiceTypeDTO> list =JSONArray.parseArray(order.getServiceTypeList(),OrderServiceTypeDTO.class);
  1480. List<OrderServiceTypeDTO> dataList = JSONArray.parseArray(orderStatisticsData.getServiceTypeList(),OrderServiceTypeDTO.class);
  1481. for (OrderServiceTypeDTO orderServiceTypeDTO : dataList) {
  1482. boolean have = false;
  1483. for (OrderServiceTypeDTO dto : list) {
  1484. if(dto.getId().equals(orderServiceTypeDTO.getId())){
  1485. dto.setCount(dto.getCount()+orderServiceTypeDTO.getCount());
  1486. have = true;
  1487. break;
  1488. }
  1489. }
  1490. if(!have){
  1491. list.add(orderServiceTypeDTO);
  1492. }
  1493. }
  1494. Long sum = list.stream().mapToLong(o->o.getCount()).sum();
  1495. for (OrderServiceTypeDTO dto : list) {
  1496. dto.setRate(df.format((dto.getCount().doubleValue()/sum)*100.0));
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502. public static void main(String[] args) {
  1503. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1504. Calendar calendar = Calendar.getInstance();
  1505. try {
  1506. calendar.setTime(df.parse("2024-03-05 00:00:24"));
  1507. } catch (ParseException e) {
  1508. e.printStackTrace();
  1509. }
  1510. System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
  1511. System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
  1512. }
  1513. }