123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package com.ruoyi.demo.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ruoyi.demo.entity.WdInfo;
- import com.ruoyi.demo.entity.bo.ChannelBo;
- import com.ruoyi.demo.entity.vo.AddStatusVo;
- import com.ruoyi.demo.entity.vo.ChannelVo;
- import com.ruoyi.demo.entity.vo.TimeVo;
- import com.ruoyi.demo.mapper.StoreWdOpcloseDao;
- import com.ruoyi.demo.mapper.WdInfoMapper;
- import com.ruoyi.demo.mapper.WdOpcloseDao;
- import com.ruoyi.demo.service.WdInfoService;
- import com.ruoyi.demo.utils.CategoryUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.util.ArrayList;
- import java.util.List;
- @Service
- @Transactional
- public class WdInfoServiceImpl implements WdInfoService {
- @Autowired
- CategoryUtil categoryUtil;
- @Autowired
- WdInfoMapper wdInfoMapper;
- @Autowired
- WdOpcloseDao wdOpcloseDao;
- @Autowired
- StoreWdOpcloseDao storeWdOpcloseDao;
- @Override
- public List<AddStatusVo> searchAddStatus(List<String> addrCodes, List<String> typeCodes) {
- // 初始化时间信息,补齐地址信息
- categoryUtil.setWdTypeMap();
- List<String> addrs = new ArrayList<>();
- List<String> times = new ArrayList<>();
- for (int i = 0; i < 12; i++)
- times.add(LocalDateTime.now(ZoneId.of("Asia/Shanghai")).plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyy-MM")));
- if (addrCodes != null) {
- if (!addrCodes.isEmpty())
- for (String s : addrCodes)
- addrs.addAll(categoryUtil.getAllOtherAddrCode(s));
- } else
- addrs = null;
- List<AddStatusVo> addStatusVos = wdInfoMapper.searchAddStatusByMulti(times, addrs, typeCodes);
- addStatusVos.forEach(vo -> vo.setTypeName(categoryUtil.wdTypeMap.get(vo.getTypeCode())));
- return addStatusVos;
- }
- public Integer timeUtil(String time) {
- String[] split = time.split(":");
- int hour = Integer.parseInt(split[0]);
- int min = Integer.parseInt(split[1]);
- return hour * 100 + min;
- }
- public int compareTime(String time1, String time2) {
- return timeUtil(time1).compareTo(timeUtil(time2));
- }
- @Override
- public List<TimeVo> searchOpenTimes(List<String> addrCodes, List<String> typeCodeBys) {
- // 补齐地址码和类型码
- List<String> addrs = new ArrayList<>();
- if (addrCodes != null) {
- if (!addrCodes.isEmpty())
- for (String addr : addrCodes)
- addrs.addAll(categoryUtil.getAllOtherAddrCode(addr));
- } else
- addrs = null;
- List<String> types = new ArrayList<>();
- if (typeCodeBys != null) {
- if (!typeCodeBys.isEmpty())
- for (String type : typeCodeBys)
- types.addAll(categoryUtil.getAllOtherTypeBy(type));
- } else
- types = null;
- List<TimeVo> vos = storeWdOpcloseDao.selectWdOpenTimes(addrs, types);
- // 初始化
- List<TimeVo> rvos = new ArrayList<>();
- for (int i = 0; i < 24; i += 2) {
- TimeVo vo = new TimeVo();
- vo.setTime(i + ":00~" + (i + 2) + ":00");
- vo.setCount(0);
- rvos.add(vo);
- }
- // 赋值
- vos.forEach(vo -> {
- for (TimeVo rvo : rvos) {
- String[] times = rvo.getTime().split("~");
- if (compareTime(vo.getTime(), times[0]) < 0 || compareTime(times[1], vo.getTime()) < 0)
- continue;
- rvo.setCount(rvo.getCount() + vo.getCount());
- }
- });
- return rvos;
- }
- @Override
- public List<TimeVo> searchCloseTimes(List<String> addrCodes, List<String> typeCodeBys) {
- // 补齐地址码和类型码
- List<String> addrs = new ArrayList<>();
- if (addrCodes != null) {
- if (!addrCodes.isEmpty())
- for (String addr : addrCodes)
- addrs.addAll(categoryUtil.getAllOtherAddrCode(addr));
- } else
- addrs = null;
- List<String> types = new ArrayList<>();
- if (typeCodeBys != null) {
- if (!typeCodeBys.isEmpty())
- for (String type : typeCodeBys)
- types.addAll(categoryUtil.getAllOtherTypeBy(type));
- } else
- types = null;
- List<TimeVo> vos = storeWdOpcloseDao.selectWdCloseTimes(addrs, types);
- // 初始化
- List<TimeVo> rvos = new ArrayList<>();
- for (int i = 0; i < 24; i += 2) {
- TimeVo vo = new TimeVo();
- vo.setTime(i + ":00~" + (i + 2) + ":00");
- vo.setCount(0);
- rvos.add(vo);
- }
- // 赋值
- vos.forEach(vo -> {
- for (TimeVo rvo : rvos) {
- String[] times = rvo.getTime().split("~");
- if (compareTime(vo.getTime(), times[0]) < 0 || compareTime(times[1], vo.getTime()) < 0)
- continue;
- rvo.setCount(rvo.getCount() + vo.getCount());
- }
- });
- return rvos;
- }
- @Override
- public Page<ChannelVo> searchChannel(ChannelBo bo) {
- QueryWrapper<WdInfo> wdInfoQueryWrapper = new QueryWrapper<>();
- wdInfoQueryWrapper.ne("dsw.channel_type", "无");
- if (bo.getText() != null){
- wdInfoQueryWrapper.and(wrapper -> {
- wrapper.like("dwi.wd_name", bo.getText())
- .or()
- .like("dsw.contact", bo.getText())
- .or()
- .like("dsw.telephone", bo.getText());
- });
- }
- Page<WdInfo> page = new Page<>(bo.getPageNum(), bo.getPageSize());
- return wdInfoMapper.selectChannel(page, wdInfoQueryWrapper);
- }
- }
|