VciInfoServiceImpl.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.om.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.om.entity.dto.VciQueryPageDTO;
  6. import com.om.entity.po.DiagnosticLog;
  7. import com.om.entity.po.User;
  8. import com.om.entity.po.UserVci;
  9. import com.om.entity.po.VciInfo;
  10. import com.om.entity.vo.DiaLogQueryPageVO;
  11. import com.om.entity.vo.UserVciVO;
  12. import com.om.entity.vo.VciQueryPageVO;
  13. import com.om.exception.BadReqException;
  14. import com.om.mapper.UserMapper;
  15. import com.om.mapper.VciInfoMapper;
  16. import com.om.service.IUserService;
  17. import com.om.service.IUserVciService;
  18. import com.om.service.IVciInfoService;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.om.utils.Result;
  21. import org.springframework.stereotype.Service;
  22. import javax.annotation.Resource;
  23. import java.time.LocalDateTime;
  24. import java.util.ArrayList;
  25. import java.util.Collections;
  26. import java.util.List;
  27. /**
  28. * <p>
  29. * 服务实现类
  30. * </p>
  31. *
  32. * @author bmmx
  33. * @since 2024-02-27
  34. */
  35. @Service
  36. public class VciInfoServiceImpl extends ServiceImpl<VciInfoMapper, VciInfo> implements IVciInfoService {
  37. @Resource
  38. private UserMapper userMapper;
  39. @Resource
  40. private IUserVciService userVciService;
  41. @Override
  42. public Result addVci(VciInfo vciInfo) {
  43. if (BeanUtil.isEmpty(vciInfo)){
  44. throw new BadReqException("参数为空");
  45. }
  46. vciInfo.setCreateTime(LocalDateTime.now());
  47. vciInfo.setUpdateTime(LocalDateTime.now());
  48. this.save(vciInfo);
  49. return Result.ok();
  50. }
  51. @Override
  52. public Result addList(List<VciInfo> vciInfos) {
  53. if (BeanUtil.isEmpty(vciInfos)){
  54. throw new BadReqException("参数为空");
  55. }
  56. for (VciInfo vciInfo : vciInfos) {
  57. vciInfo.setCreateTime(LocalDateTime.now());
  58. vciInfo.setUpdateTime(LocalDateTime.now());
  59. }
  60. this.saveBatch(vciInfos);
  61. return Result.ok();
  62. }
  63. @Override
  64. public Result deleteByNum(String vciNum) {
  65. //根据vciNum查询
  66. VciInfo one = this.lambdaQuery()
  67. .eq(VciInfo::getVciNum, vciNum)
  68. .one();
  69. if (BeanUtil.isEmpty(one)){
  70. throw new BadReqException("vci设备不存在");
  71. }
  72. //删除
  73. this.removeById(one);
  74. return Result.ok();
  75. }
  76. @Override
  77. public Result updateState(Integer id, Integer state) {
  78. //根据id查询
  79. VciInfo vciInfo = this.getById(id);
  80. if (BeanUtil.isEmpty(vciInfo)){
  81. throw new BadReqException("vci设备不存在");
  82. }
  83. vciInfo.setState(state);
  84. this.updateById(vciInfo);
  85. return Result.ok();
  86. }
  87. @Override
  88. public Result getList() {
  89. List<VciInfo> list = this.list();
  90. return Result.ok(list);
  91. }
  92. @Override
  93. public Result<List<UserVciVO>> getListByUserId(Integer userId) {
  94. //根据userId查询用户
  95. User user = userMapper.selectById(userId);
  96. if (BeanUtil.isEmpty(user)){
  97. throw new BadReqException("该用户不存在");
  98. }
  99. List<UserVci> list = userVciService.lambdaQuery()
  100. .eq(UserVci::getUserId, userId)
  101. .list();
  102. if (CollectionUtil.isEmpty(list)){
  103. return Result.ok(Collections.emptyList());
  104. }
  105. List<UserVciVO> vos= new ArrayList<>();
  106. for (UserVci userVci : list) {
  107. UserVciVO userVciVO = BeanUtil.copyProperties(userVci, UserVciVO.class);
  108. userVciVO.setUsername(user.getUsername());
  109. vos.add(userVciVO);
  110. }
  111. return Result.ok(vos);
  112. }
  113. @Override
  114. public Result<VciQueryPageVO> getPageList(VciQueryPageDTO dto) {
  115. Integer pageIndex = dto.getPageIndex();
  116. Integer pageSize = dto.getPageSize();
  117. String vciNum = dto.getVciNum();
  118. Page<VciInfo> page = this.lambdaQuery()
  119. .like(vciNum != null, VciInfo::getVciNum, vciNum)
  120. .orderByDesc(VciInfo::getCreateTime)
  121. .page(new Page<>(pageIndex, pageSize));
  122. VciQueryPageVO vo = new VciQueryPageVO();
  123. vo.setCurrent((int) page.getCurrent());
  124. vo.setSize((int) page.getSize());
  125. vo.setPages((int) page.getPages());
  126. vo.setTotal((int) page.getTotal());
  127. if (vciNum != null){
  128. vo.setSearchCount(true);
  129. }
  130. List<VciInfo> records = page.getRecords();
  131. vo.setRecords(records);
  132. return Result.ok(vo);
  133. }
  134. }