| | |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.wx.WxMiniUtilService; |
| | | import com.doumee.dao.business.BikesMapper; |
| | | import com.doumee.dao.business.LocksMapper; |
| | | import com.doumee.dao.business.SitesMapper; |
| | | import com.doumee.dao.business.model.Bikes; |
| | | import com.doumee.dao.business.model.Locks; |
| | | import com.doumee.dao.business.model.Sites; |
| | | import com.doumee.dao.business.web.request.SitesMonitorBikeDTO; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | |
| | | @Autowired |
| | | private LocksMapper locksMapper; |
| | | @Autowired |
| | | private BikesMapper bikesMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | |
| | | @Override |
| | | public String create(Sites sites) { |
| | |
| | | |
| | | QueryWrapper<Sites> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Sites::getCode,sites.getCode()); |
| | | Integer count = sitesMapper.selectCount(wrapper); |
| | | .eq(Sites::getCode,sites.getCode()) |
| | | .eq(Sites::getIsdeleted,Constants.ZERO); |
| | | Long count = sitesMapper.selectCount(wrapper); |
| | | if (count > 0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"站点编号已存在"); |
| | | } |
| | | Sites insert = new Sites(); |
| | | insert.setId(sites.getCode()); |
| | | insert.setCreateDate(new Date()); |
| | | insert.setCreator(principal.getId()); |
| | | insert.setEditDate(new Date()); |
| | |
| | | insert.setIsdeleted(Constants.ZERO); |
| | | insert.setInfo(sites.getInfo()); |
| | | insert.setName(sites.getName()); |
| | | insert.setType(sites.getType()); |
| | | insert.setCode(sites.getCode()); |
| | | insert.setStatus(sites.getStatus()); |
| | | insert.setElectronicFence(sites.getElectronicFence()); |
| | | insert.setStatus(Constants.ZERO); |
| | | insert.setLockNum(sites.getLockNum()); |
| | | insert.setIp(sites.getIp()); |
| | | sitesMapper.insert(sites); |
| | | sitesMapper.insert(insert); |
| | | return sites.getId(); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void updateById(Sites sites) { |
| | | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | QueryWrapper<Sites> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Sites::getCode,sites.getCode()); |
| | | Sites count = sitesMapper.selectOne(wrapper); |
| | | if (Objects.nonNull(count) && !count.getId().equals(sites.getId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"站点编号已存在"); |
| | | } |
| | | Sites update = new Sites(); |
| | | update.setId(sites.getId()); |
| | | update.setCreateDate(new Date()); |
| | | update.setEditor(principal.getId()); |
| | | update.setName(sites.getName()); |
| | | update.setLockNum(sites.getLockNum()); |
| | | update.setElectronicFence(sites.getElectronicFence()); |
| | | update.setIp(sites.getIp()); |
| | | update.setNeedNotice(sites.getNeedNotice()); |
| | | sitesMapper.updateById(update); |
| | | } |
| | | @Override |
| | | public void updateByMqtt(Sites sites) { |
| | | sitesMapper.updateById(sites); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public List<Sites> findList(Sites sites) { |
| | | QueryWrapper<Sites> wrapper = new QueryWrapper<>(sites); |
| | | return sitesMapper.selectList(wrapper); |
| | | } |
| | | @Override |
| | | public void noticeNoLinkList(Sites sites) { |
| | | //发送钉钉通知 |
| | | int second =0; |
| | | try { |
| | | second = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.NOTICE_SITE_LINK_LIMIT).getCode()); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | if(second <=0){ |
| | | return ; |
| | | } |
| | | sites.setIsdeleted(Constants.ZERO); |
| | | sites.setType(Constants.ZERO); |
| | | sites.setStatus(Constants.ZERO); |
| | | QueryWrapper<Sites> wrapper = new QueryWrapper<>(sites); |
| | | wrapper.lambda().orderByDesc(Sites::getLastLinkDate); |
| | | List<Sites> siteList =sitesMapper.selectList(wrapper); |
| | | List<Sites> errorList = new ArrayList<>(); |
| | | for(Sites site : siteList){ |
| | | //时间查过通信异常阈值 |
| | | if(Constants.formatIntegerNum(site.getNeedNotice()) == Constants.ZERO |
| | | &&(site.getLastLinkDate() == null |
| | | || System.currentTimeMillis()-site.getLastLinkDate().getTime() > second*1000)){ |
| | | errorList.add(site); |
| | | } |
| | | } |
| | | if(errorList.size()>0){ |
| | | try { |
| | | DingDingNotice.siteNoLink(errorList, systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_TOKEN).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_ROBOTCODE).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_CHATTOKEN).getCode()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (pageWrap.getModel().getClientVersion() != null) { |
| | | queryWrapper.lambda().eq(Sites::getClientVersion, pageWrap.getModel().getClientVersion()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.lambda().eq(Sites::getType, pageWrap.getModel().getType()); |
| | | } |
| | | /*for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | }*/ |
| | | queryWrapper.lambda().orderByAsc(Sites::getCode); |
| | | return PageData.from(sitesMapper.selectPage(page, queryWrapper)); |
| | | } |
| | | |
| | |
| | | public long count(Sites sites) { |
| | | QueryWrapper<Sites> wrapper = new QueryWrapper<>(sites); |
| | | return sitesMapper.selectCount(wrapper); |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public void dealSiteLocks(Sites sites) { |
| | | if(StringUtils.isBlank(sites.getId()) || StringUtils.isBlank(sites.getClientVersion())){ |
| | | return; |
| | | } |
| | | sites.setEditDate(new Date()); |
| | | sitesMapper.updateById(sites); |
| | | String[] lockCods = new String[sites.getLockNum()]; |
| | | if(Constants.formatIntegerNum(sites.getLockNum())>0){ |
| | | for (int i = 1; i < sites.getLockNum()+1; i++) { |
| | | lockCods[i-1] = i+""; |
| | | } |
| | | } |
| | | locksMapper.delete(new UpdateWrapper<Locks>().lambda() |
| | | .eq(Locks::getSiteId,sites.getId()) |
| | | .notIn(lockCods.length>0,Locks::getCode,lockCods)); |
| | | bikesMapper.delete(new UpdateWrapper<Bikes>().lambda() |
| | | .eq(Bikes::getSiteId,sites.getId()) |
| | | .notIn(lockCods.length>0,Bikes::getLockId,lockCods)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | ",(select count(l.bike_code) from locks l where l.site_id = sites.id and l.bike_code IS NOT NULL and l.bike_code !='' ) as bikeCount"); |
| | | // Page<SitesMonitorDTO> sitesMonitorDTO = sitesMapper.getSitesMonitorDTO(page, pageWrap.getModel().getCode(), pageWrap.getModel().getName()); |
| | | queryWrapper.lambda().like(StringUtils.isNotBlank(pageWrap.getModel().getCode()),Sites::getCode,pageWrap.getModel().getCode()); |
| | | queryWrapper.lambda().like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Sites::getCode,pageWrap.getModel().getName()); |
| | | queryWrapper.lambda().like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Sites::getName,pageWrap.getModel().getName()); |
| | | queryWrapper.lambda().orderByAsc(Sites::getCode); |
| | | IPage<Sites> sitesMonitorDTO = sitesMapper.selectPage(page, queryWrapper); |
| | | if (!CollectionUtils.isEmpty(sitesMonitorDTO.getRecords())){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void siteReservesNotice(String siteId) throws Exception { |
| | | |
| | | public void siteReservesNotice() throws Exception{ |
| | | QueryWrapper<Sites> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select(" *, " + |
| | | " (select count(r.id) from locks r where r.site_id = sites.id) as all_lock_num ," + |
| | | "(select count(l.bike_code) from locks l where l.site_id = sites.id and l.bike_code IS NOT NULL and l.bike_code !='' ) as bikeCount"); |
| | | queryWrapper.lambda().eq(Sites::getStatus,Constants.ZERO); |
| | | queryWrapper.lambda().eq(Sites::getIsdeleted,Constants.ZERO); |
| | | queryWrapper.lambda().orderByAsc(Sites::getCode); |
| | | List<Sites> sitesList = sitesMapper.selectList(queryWrapper); |
| | | if (!CollectionUtils.isEmpty(sitesList)){ |
| | | for (Sites s:sitesList) { |
| | | if(Constants.formatIntegerNum(s.getAllLockNum())<=Constants.ZERO){ |
| | | continue; |
| | | } |
| | | BigDecimal warnMin = new BigDecimal(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.WARN_MIN).getCode()); |
| | | BigDecimal warnMax = new BigDecimal(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.WARN_MAX).getCode()); |
| | | BigDecimal rata = new BigDecimal(s.getBikeCount()).divide(new BigDecimal(s.getAllLockNum()),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100L)); |
| | | if(rata.compareTo(warnMax)>Constants.ZERO){ |
| | | //发送钉钉通知 |
| | | DingDingNotice.reservesNotice(StringUtils.isBlank(s.getName())?s.getId() + " - 未知" :s.getId() + " - " + s.getName(), |
| | | Constants.ZERO,warnMax, |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_TOKEN).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_ROBOTCODE).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_CHATTOKEN).getCode()); |
| | | }else if(rata.compareTo(warnMin)<Constants.ZERO){ |
| | | //发送钉钉通知 |
| | | DingDingNotice.reservesNotice(StringUtils.isBlank(s.getName())?s.getId() + " - 未知" :s.getId() + " - " + s.getName() |
| | | ,Constants.ONE,warnMin, |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_TOKEN).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_ROBOTCODE).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.DINGDING,Constants.DINGDING_CHATTOKEN).getCode()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Sites> getSiteList(Integer type){ |
| | | return sitesMapper.selectList(new QueryWrapper<Sites>().lambda() |
| | | .eq(Sites::getIsdeleted,Constants.ZERO) |
| | | .eq(Sites::getStatus,Constants.ZERO) |
| | | .eq(Objects.nonNull(type),Sites::getType,type)); |
| | | } |
| | | |
| | | } |