| | |
| | | package com.fzzy.igds.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.fzzy.igds.constant.RedisConst; |
| | | import com.fzzy.igds.data.DeviceIotParam; |
| | | import com.fzzy.igds.domain.DeviceIot; |
| | | import com.fzzy.igds.repository.DeviceIotRepository; |
| | | import com.fzzy.igds.mapper.DeviceIotMapper; |
| | | import com.fzzy.igds.utils.ContextUtil; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.springframework.stereotype.Service; |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | @Resource |
| | | private DeviceIotRepository deviceIotRepository; |
| | | private DeviceIotMapper deviceIotMapper; |
| | | |
| | | /** |
| | | * JPA分页查询数据 |
| | | * |
| | | * @param specification |
| | | * @param pageable |
| | | * @return |
| | | * 分页查询数据 |
| | | * @param page |
| | | * @param param |
| | | */ |
| | | public Page<DeviceIot> findAll(Specification<DeviceIot> specification, Pageable pageable) { |
| | | return deviceIotRepository.findAll(specification, pageable); |
| | | public void listPageData(Page<DeviceIot> page, DeviceIotParam param) { |
| | | QueryWrapper<DeviceIot> queryWrapper = new QueryWrapper<>(); |
| | | |
| | | param.setCompanyId(ContextUtil.getCompanyId()); |
| | | param.setDeptId(ContextUtil.subDeptId(null)); |
| | | queryWrapper.eq("company_id", param.getCompanyId()); |
| | | queryWrapper.eq("dept_id", param.getDeptId()); |
| | | |
| | | if (StringUtils.isNotBlank(param.getDepotId())) { |
| | | queryWrapper.eq("depot_id", param.getDepotId()); |
| | | } |
| | | if (StringUtils.isNotBlank(param.getType())) { |
| | | queryWrapper.eq("type", param.getType()); |
| | | } |
| | | if (StringUtils.isNotBlank(param.getSerId())) { |
| | | queryWrapper.eq("ser_id", param.getSerId()); |
| | | } |
| | | |
| | | deviceIotMapper.selectPage(page, queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件查询 |
| | | * @param companyId |
| | | */ |
| | | public List<DeviceIot> listData(String companyId) { |
| | | QueryWrapper<DeviceIot> queryWrapper = new QueryWrapper<>(); |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | queryWrapper.eq("company_id", companyId); |
| | | |
| | | return deviceIotMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | |
| | | deviceIot.setId(ContextUtil.generateId()); |
| | | deviceIot.setCreateBy(ContextUtil.getLoginUserName()); |
| | | deviceIot.setCreateTime(new Date()); |
| | | deviceIot.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | deviceIot.setUpdateTime(new Date()); |
| | | deviceIotMapper.insert(deviceIot); |
| | | }else { |
| | | deviceIot.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | deviceIot.setUpdateTime(new Date()); |
| | | deviceIotMapper.updateById(deviceIot); |
| | | } |
| | | deviceIot.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | deviceIot.setUpdateTime(new Date()); |
| | | deviceIotRepository.save(deviceIot); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param deviceIot |
| | | */ |
| | | public void delDepotDeviceIot(DeviceIot deviceIot) { |
| | | deviceIotRepository.delete(deviceIot); |
| | | deviceIotMapper.deleteById(deviceIot); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param posY |
| | | */ |
| | | public void updatePos(String deviceId, Double posX, Double posY) { |
| | | deviceIotRepository.updatePos(deviceId, posX, posY); |
| | | UpdateWrapper<DeviceIot> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", deviceId).set("pos_x", posX).set("pos_y", posY); |
| | | deviceIotMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | /** |
| | |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | // 获取所有的设备信息 |
| | | List<DeviceIot> listAll =deviceIotRepository.getDeviceIotByCompanyId(companyId); |
| | | List<DeviceIot> listAll =this.listData(companyId); |
| | | |
| | | if (null != listAll) { |
| | | this.setCacheAllDeviceIot(listAll, companyId); |