123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- package com.om.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollectionUtil;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.om.entity.dto.VciQueryPageDTO;
- import com.om.entity.po.DiagnosticLog;
- import com.om.entity.po.User;
- import com.om.entity.po.UserVci;
- import com.om.entity.po.VciInfo;
- import com.om.entity.vo.DiaLogQueryPageVO;
- import com.om.entity.vo.UserVciVO;
- import com.om.entity.vo.VciQueryPageVO;
- import com.om.exception.BadReqException;
- import com.om.mapper.UserMapper;
- import com.om.mapper.VciInfoMapper;
- import com.om.service.IUserService;
- import com.om.service.IUserVciService;
- import com.om.service.IVciInfoService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.om.utils.Result;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author bmmx
- * @since 2024-02-27
- */
- @Service
- public class VciInfoServiceImpl extends ServiceImpl<VciInfoMapper, VciInfo> implements IVciInfoService {
- @Resource
- private UserMapper userMapper;
- @Resource
- private IUserVciService userVciService;
- @Override
- public Result addVci(VciInfo vciInfo) {
- if (BeanUtil.isEmpty(vciInfo)){
- throw new BadReqException("参数为空");
- }
- vciInfo.setCreateTime(LocalDateTime.now());
- vciInfo.setUpdateTime(LocalDateTime.now());
- this.save(vciInfo);
- return Result.ok();
- }
- @Override
- public Result addList(List<VciInfo> vciInfos) {
- if (BeanUtil.isEmpty(vciInfos)){
- throw new BadReqException("参数为空");
- }
- for (VciInfo vciInfo : vciInfos) {
- vciInfo.setCreateTime(LocalDateTime.now());
- vciInfo.setUpdateTime(LocalDateTime.now());
- }
- this.saveBatch(vciInfos);
- return Result.ok();
- }
- @Override
- public Result deleteByNum(String vciNum) {
- //根据vciNum查询
- VciInfo one = this.lambdaQuery()
- .eq(VciInfo::getVciNum, vciNum)
- .one();
- if (BeanUtil.isEmpty(one)){
- throw new BadReqException("vci设备不存在");
- }
- //删除
- this.removeById(one);
- return Result.ok();
- }
- @Override
- public Result updateState(Integer id, Integer state) {
- //根据id查询
- VciInfo vciInfo = this.getById(id);
- if (BeanUtil.isEmpty(vciInfo)){
- throw new BadReqException("vci设备不存在");
- }
- vciInfo.setState(state);
- this.updateById(vciInfo);
- return Result.ok();
- }
- @Override
- public Result getList() {
- List<VciInfo> list = this.list();
- return Result.ok(list);
- }
- @Override
- public Result<List<UserVciVO>> getListByUserId(Integer userId) {
- //根据userId查询用户
- User user = userMapper.selectById(userId);
- if (BeanUtil.isEmpty(user)){
- throw new BadReqException("该用户不存在");
- }
- List<UserVci> list = userVciService.lambdaQuery()
- .eq(UserVci::getUserId, userId)
- .list();
- if (CollectionUtil.isEmpty(list)){
- return Result.ok(Collections.emptyList());
- }
- List<UserVciVO> vos= new ArrayList<>();
- for (UserVci userVci : list) {
- UserVciVO userVciVO = BeanUtil.copyProperties(userVci, UserVciVO.class);
- userVciVO.setUsername(user.getUsername());
- vos.add(userVciVO);
- }
- return Result.ok(vos);
- }
- @Override
- public Result<VciQueryPageVO> getPageList(VciQueryPageDTO dto) {
- Integer pageIndex = dto.getPageIndex();
- Integer pageSize = dto.getPageSize();
- String vciNum = dto.getVciNum();
- Page<VciInfo> page = this.lambdaQuery()
- .like(vciNum != null, VciInfo::getVciNum, vciNum)
- .orderByDesc(VciInfo::getCreateTime)
- .page(new Page<>(pageIndex, pageSize));
- VciQueryPageVO vo = new VciQueryPageVO();
- vo.setCurrent((int) page.getCurrent());
- vo.setSize((int) page.getSize());
- vo.setPages((int) page.getPages());
- vo.setTotal((int) page.getTotal());
- if (vciNum != null){
- vo.setSearchCount(true);
- }
- List<VciInfo> records = page.getRecords();
- vo.setRecords(records);
- return Result.ok(vo);
- }
- }
|