OrderServiceImpl.java 98 KB

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