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));
|
}
|
}
|