OrderServiceImpl.java 89 KB

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