|
@@ -1,11 +1,32 @@
|
|
|
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>
|
|
|
* 服务实现类
|
|
@@ -17,4 +38,126 @@ import org.springframework.stereotype.Service;
|
|
|
@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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|