Fixiaobai
2023-09-05 c9da1b0da1178911e383ddcaebecd1e088fa6004
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
package com.yuanchu.limslaboratory.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.mapper.UserMapper;
import com.yuanchu.limslaboratory.pojo.Instrument;
import com.yuanchu.limslaboratory.mapper.InstrumentMapper;
import com.yuanchu.limslaboratory.pojo.User;
import com.yuanchu.limslaboratory.service.InstrumentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.limslaboratory.utils.JsonUtil;
import com.yuanchu.limslaboratory.utils.MyUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-20
 */
@Service
public class InstrumentServiceImpl extends ServiceImpl<InstrumentMapper, Instrument> implements InstrumentService {
 
    @Resource
    private InstrumentMapper instrumentMapper;
 
    @Resource
    private UserMapper userMapper;
 
    @Override
    public Integer addInstrumentInformation(Instrument instrument) {
        LambdaQueryWrapper<Instrument> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Instrument::getEquipmentCode, instrument.getEquipmentCode());
        wrapper.eq(Instrument::getState, 1);
        wrapper.select(Instrument::getEquipmentCode);
        Instrument instrument1 = instrumentMapper.selectOne(wrapper);
        if (ObjectUtils.isEmpty(instrument1)){
            return instrumentMapper.insert(instrument);
        }
        return 0;
    }
 
    @Override
    public Boolean deleteInstrumentInformation(String instrumentId) {
        LambdaUpdateWrapper<Instrument> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Instrument::getId, instrumentId);
        updateWrapper.set(Instrument::getState, 0);
        int isUpdateSuccess = instrumentMapper.update(new Instrument(), updateWrapper);
        return isUpdateSuccess > 0;
    }
 
    @Override
    public IPage<Map<String, Object>> getListInstrumentInformation(Integer conditions, Boolean whetherWhether, String numberOrNameOrSpecifications,
                                                                   Integer classifyId, Page<Objects> page) {
        return instrumentMapper.getListInstrumentInformation(conditions, whetherWhether, numberOrNameOrSpecifications, classifyId, page);
    }
 
    @Override
    public Map<String, Object> getIdInstrumentInformation(Integer instrumentId) {
        LambdaQueryWrapper<Instrument> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Instrument::getId, instrumentId);
        Instrument instrument = instrumentMapper.selectOne(wrapper);
        User user = userMapper.selectById(instrument.getUserId());
        Map<String, Object> map = JsonUtil.jsonToPojo(JsonUtil.jsonToString(instrument), Map.class);
        map.put("userName",user.getName());
        return map;
    }
 
    @Override
    public Integer updateEquipmentPointInformation(Instrument instrument) {
        LambdaQueryWrapper<Instrument> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Instrument::getEquipmentCode, instrument.getEquipmentCode());
        wrapper.eq(Instrument::getState, 1);
        wrapper.select(Instrument::getEquipmentCode, Instrument::getId);
        Instrument instrument1 = instrumentMapper.selectOne(wrapper);
        if (ObjectUtils.isEmpty(instrument1)){
            return instrumentMapper.updateById(instrument);
        } else if (instrument.getId().equals(instrument1.getId())){
            return instrumentMapper.updateById(instrument);
        }
        return 0;
    }
 
 
}