WdInfoServiceImpl.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.ruoyi.demo.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.ruoyi.demo.entity.WdInfo;
  5. import com.ruoyi.demo.entity.bo.ChannelBo;
  6. import com.ruoyi.demo.entity.vo.AddStatusVo;
  7. import com.ruoyi.demo.entity.vo.ChannelVo;
  8. import com.ruoyi.demo.entity.vo.TimeVo;
  9. import com.ruoyi.demo.mapper.StoreWdOpcloseDao;
  10. import com.ruoyi.demo.mapper.WdInfoMapper;
  11. import com.ruoyi.demo.mapper.WdOpcloseDao;
  12. import com.ruoyi.demo.service.WdInfoService;
  13. import com.ruoyi.demo.utils.CategoryUtil;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import java.time.LocalDateTime;
  18. import java.time.ZoneId;
  19. import java.time.format.DateTimeFormatter;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. @Service
  23. @Transactional
  24. public class WdInfoServiceImpl implements WdInfoService {
  25. @Autowired
  26. CategoryUtil categoryUtil;
  27. @Autowired
  28. WdInfoMapper wdInfoMapper;
  29. @Autowired
  30. WdOpcloseDao wdOpcloseDao;
  31. @Autowired
  32. StoreWdOpcloseDao storeWdOpcloseDao;
  33. @Override
  34. public List<AddStatusVo> searchAddStatus(List<String> addrCodes, List<String> typeCodes) {
  35. // 初始化时间信息,补齐地址信息
  36. categoryUtil.setWdTypeMap();
  37. List<String> addrs = new ArrayList<>();
  38. List<String> times = new ArrayList<>();
  39. for (int i = 0; i < 12; i++)
  40. times.add(LocalDateTime.now(ZoneId.of("Asia/Shanghai")).plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyy-MM")));
  41. if (addrCodes != null) {
  42. if (!addrCodes.isEmpty())
  43. for (String s : addrCodes)
  44. addrs.addAll(categoryUtil.getAllOtherAddrCode(s));
  45. } else
  46. addrs = null;
  47. List<AddStatusVo> addStatusVos = wdInfoMapper.searchAddStatusByMulti(times, addrs, typeCodes);
  48. addStatusVos.forEach(vo -> vo.setTypeName(categoryUtil.wdTypeMap.get(vo.getTypeCode())));
  49. return addStatusVos;
  50. }
  51. public Integer timeUtil(String time) {
  52. String[] split = time.split(":");
  53. int hour = Integer.parseInt(split[0]);
  54. int min = Integer.parseInt(split[1]);
  55. return hour * 100 + min;
  56. }
  57. public int compareTime(String time1, String time2) {
  58. return timeUtil(time1).compareTo(timeUtil(time2));
  59. }
  60. @Override
  61. public List<TimeVo> searchOpenTimes(List<String> addrCodes, List<String> typeCodeBys) {
  62. // 补齐地址码和类型码
  63. List<String> addrs = new ArrayList<>();
  64. if (addrCodes != null) {
  65. if (!addrCodes.isEmpty())
  66. for (String addr : addrCodes)
  67. addrs.addAll(categoryUtil.getAllOtherAddrCode(addr));
  68. } else
  69. addrs = null;
  70. List<String> types = new ArrayList<>();
  71. if (typeCodeBys != null) {
  72. if (!typeCodeBys.isEmpty())
  73. for (String type : typeCodeBys)
  74. types.addAll(categoryUtil.getAllOtherTypeBy(type));
  75. } else
  76. types = null;
  77. List<TimeVo> vos = storeWdOpcloseDao.selectWdOpenTimes(addrs, types);
  78. // 初始化
  79. List<TimeVo> rvos = new ArrayList<>();
  80. for (int i = 0; i < 24; i += 2) {
  81. TimeVo vo = new TimeVo();
  82. vo.setTime(i + ":00~" + (i + 2) + ":00");
  83. vo.setCount(0);
  84. rvos.add(vo);
  85. }
  86. // 赋值
  87. vos.forEach(vo -> {
  88. for (TimeVo rvo : rvos) {
  89. String[] times = rvo.getTime().split("~");
  90. if (compareTime(vo.getTime(), times[0]) < 0 || compareTime(times[1], vo.getTime()) < 0)
  91. continue;
  92. rvo.setCount(rvo.getCount() + vo.getCount());
  93. }
  94. });
  95. return rvos;
  96. }
  97. @Override
  98. public List<TimeVo> searchCloseTimes(List<String> addrCodes, List<String> typeCodeBys) {
  99. // 补齐地址码和类型码
  100. List<String> addrs = new ArrayList<>();
  101. if (addrCodes != null) {
  102. if (!addrCodes.isEmpty())
  103. for (String addr : addrCodes)
  104. addrs.addAll(categoryUtil.getAllOtherAddrCode(addr));
  105. } else
  106. addrs = null;
  107. List<String> types = new ArrayList<>();
  108. if (typeCodeBys != null) {
  109. if (!typeCodeBys.isEmpty())
  110. for (String type : typeCodeBys)
  111. types.addAll(categoryUtil.getAllOtherTypeBy(type));
  112. } else
  113. types = null;
  114. List<TimeVo> vos = storeWdOpcloseDao.selectWdCloseTimes(addrs, types);
  115. // 初始化
  116. List<TimeVo> rvos = new ArrayList<>();
  117. for (int i = 0; i < 24; i += 2) {
  118. TimeVo vo = new TimeVo();
  119. vo.setTime(i + ":00~" + (i + 2) + ":00");
  120. vo.setCount(0);
  121. rvos.add(vo);
  122. }
  123. // 赋值
  124. vos.forEach(vo -> {
  125. for (TimeVo rvo : rvos) {
  126. String[] times = rvo.getTime().split("~");
  127. if (compareTime(vo.getTime(), times[0]) < 0 || compareTime(times[1], vo.getTime()) < 0)
  128. continue;
  129. rvo.setCount(rvo.getCount() + vo.getCount());
  130. }
  131. });
  132. return rvos;
  133. }
  134. @Override
  135. public Page<ChannelVo> searchChannel(ChannelBo bo) {
  136. QueryWrapper<WdInfo> wdInfoQueryWrapper = new QueryWrapper<>();
  137. wdInfoQueryWrapper.ne("dsw.channel_type", "无");
  138. if (bo.getText() != null){
  139. wdInfoQueryWrapper.and(wrapper -> {
  140. wrapper.like("dwi.wd_name", bo.getText())
  141. .or()
  142. .like("dsw.contact", bo.getText())
  143. .or()
  144. .like("dsw.telephone", bo.getText());
  145. });
  146. }
  147. Page<WdInfo> page = new Page<>(bo.getPageNum(), bo.getPageSize());
  148. return wdInfoMapper.selectChannel(page, wdInfoQueryWrapper);
  149. }
  150. }