张晓波
2023-09-26 83a237a7e22ff2cd829034632d6d785d74c1789b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.thhy.mobile.modules.biz.checkdevice.service.impl;
 
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.DeepCopyUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.mobile.modules.biz.checkdevice.entity.*;
import com.thhy.mobile.modules.biz.checkdevice.mapper.CheckDeviceFileMapper;
import com.thhy.mobile.modules.biz.checkdevice.mapper.CheckDeviceMapper;
import com.thhy.mobile.modules.biz.checkdevice.service.CheckDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
 
/**
 *  服务实现类
 * @author zhang_xiao_bo
 * @since 2023-09-25 16:02:35
 */
@Service
public class CheckDeviceServiceImpl implements CheckDeviceService {
 
 
 
    @Autowired
    private CheckDeviceMapper checkDeviceMapper;
 
    @Autowired
    private CheckDeviceFileMapper fileMapper;
 
    public CheckDevice get(Serializable id){
        return checkDeviceMapper.queryById(id);
    }
 
    public List<CheckDeviceListVo> findList(CheckDeviceDto checkDeviceDto){
        return checkDeviceMapper.findList(checkDeviceDto);
    }
 
    public CheckDeviceListVo checkDeviceInfo(CheckDeviceDto checkDeviceDto){
        CheckDeviceListVo deviceListVo = checkDeviceMapper.queryInfoById(checkDeviceDto.getId());
        List<CheckDeviceFile> fileList = fileMapper.findAll(deviceListVo.getId());
        deviceListVo.setFileList(fileList);
        return  deviceListVo;
    }
 
    /**
     * 增加和修改
     * @param checkDeviceAddDto
     */
    @Transactional
    public void addCheckDevice(CheckDeviceAddDto checkDeviceAddDto){
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        List<CheckDeviceFile> fileList = checkDeviceAddDto.getFileList();
        CheckDevice checkDevice = new CheckDevice();
        DeepCopyUtils.copy(checkDeviceAddDto,checkDevice);
        if(checkDevice.getId() == null){
            //增加操作
            checkDevice.setAdminUser(userInfo.getUserId());
            checkDeviceMapper.insert(checkDevice);
        }else{
            //修改操作
            checkDeviceMapper.update(checkDevice);
            fileMapper.deleteByCheckId(checkDevice.getId());
        }
        for(CheckDeviceFile deviceFile : fileList){
            deviceFile.setCheckId(checkDevice.getId());
            fileMapper.insert(deviceFile);
        }
 
    }
 
    /**
     * 修改
     * @param checkDevice
     */
    public void update(CheckDevice checkDevice){
        checkDeviceMapper.update(checkDevice);
    }
 
    /**
     * 删除
     * @param id
     */
    public void delete(Serializable id){
        checkDeviceMapper.deletelogic(id);
    }
 
    @Override
    public List<HashMap<String, Object>> deviceList() {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        return checkDeviceMapper.deviceList(userInfo.getCompanyId());
    }
}