OrderServiceImpl.java 100 KB

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