doum
8 小时以前 59b1f0e9967902aa10f5e017d5a0bdfd1b60c9ea
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.xpyun.XpyunPrintService;
import com.doumee.core.utils.xpyun.XpyunResponse;
import com.doumee.dao.business.PrinterInfoMapper;
import com.doumee.dao.business.model.PrinterInfo;
import com.doumee.service.business.PrinterInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
 
/**
 * 打印机信息Service实现
 * @author rk
 * @date 2026/04/28
 */
@Service
public class PrinterInfoServiceImpl implements PrinterInfoService {
 
    @Autowired
    private PrinterInfoMapper printerInfoMapper;
 
    @Autowired
    private XpyunPrintService xpyunPrintService;
 
    @Override
    public Integer create(PrinterInfo printerInfo) {
        if (StringUtils.isBlank(printerInfo.getSn())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "打印机SN不能为空");
        }
        if (StringUtils.isBlank(printerInfo.getName())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "打印机名称不能为空");
        }
        XpyunResponse response = xpyunPrintService.addPrinter(printerInfo.getSn(), printerInfo.getName());
        if (response.getCode() != 0) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "芯烨云添加打印机失败:" + response.getMsg());
        }
        printerInfoMapper.insert(printerInfo);
        return printerInfo.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        printerInfoMapper.deleteById(id);
    }
 
    @Override
    public void delete(PrinterInfo printerInfo) {
        printerInfoMapper.delete(new QueryWrapper<>(printerInfo));
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        printerInfoMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(PrinterInfo printerInfo) {
        printerInfoMapper.updateById(printerInfo);
    }
 
    @Override
    public void updateByIdInBatch(List<PrinterInfo> printerInfos) {
        if (CollectionUtils.isEmpty(printerInfos)) {
            return;
        }
        for (PrinterInfo printerInfo : printerInfos) {
            this.updateById(printerInfo);
        }
    }
 
    @Override
    public PrinterInfo findById(Integer id) {
        return printerInfoMapper.selectById(id);
    }
 
    @Override
    public PrinterInfo findOne(PrinterInfo printerInfo) {
        return printerInfoMapper.selectOne(new QueryWrapper<>(printerInfo));
    }
 
    @Override
    public List<PrinterInfo> findList(PrinterInfo printerInfo) {
        return printerInfoMapper.selectList(new QueryWrapper<>(printerInfo));
    }
 
    @Override
    public PageData<PrinterInfo> findPage(PageWrap<PrinterInfo> pageWrap) {
        IPage<PrinterInfo> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<PrinterInfo> wrapper = new QueryWrapper<>(pageWrap.getModel());
        for (PageWrap.SortData sortData : pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                wrapper.orderByDesc(sortData.getProperty());
            } else {
                wrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(printerInfoMapper.selectPage(page, wrapper));
    }
 
    @Override
    public long count(PrinterInfo printerInfo) {
        return printerInfoMapper.selectCount(new QueryWrapper<>(printerInfo));
    }
}