package com.qianwen.mdc.service.manufacturer;
|
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.qianwen.mdc.domain.Manufacturer;
|
import com.qianwen.mdc.dto.manufacturer.ManufacturerDTO;
|
import com.qianwen.mdc.dto.manufacturer.ManufacturerQueryDTO;
|
import com.qianwen.mdc.mapper.ManufacturerMapper;
|
|
/**
|
* @author y_ys79
|
* 设备台账查询服务
|
*/
|
@Service
|
public class ManufacturerService {
|
@Autowired
|
private ManufacturerMapper manufacturerMapper;
|
|
@Transactional
|
public void save(ManufacturerDTO dto) {
|
|
Manufacturer m = new Manufacturer();
|
|
m.setName(dto.getName());
|
|
manufacturerMapper.insert(m);
|
|
}
|
|
@Transactional
|
public void modify(ManufacturerDTO dto) {
|
|
Manufacturer m = manufacturerMapper.selectById(dto.getId());
|
|
m.setName(dto.getName());
|
|
manufacturerMapper.updateById(m);
|
|
}
|
|
/**
|
* 设备台账分页查询
|
* @param dto 查询参数
|
* @return
|
*/
|
@Transactional(readOnly=true)
|
public Page<ManufacturerDTO> pageQuery(ManufacturerQueryDTO dto) {
|
|
Page<ManufacturerDTO> rowPage = new Page<>(dto.finalPageNo(),dto.finalPageSize());
|
|
rowPage = manufacturerMapper.queryPage(rowPage, dto);
|
return rowPage;
|
}
|
|
@Transactional(readOnly=true)
|
public ManufacturerDTO get(Integer id) {
|
Manufacturer dtype = manufacturerMapper.selectById(id);
|
|
ManufacturerDTO dto = new ManufacturerDTO();
|
|
BeanUtils.copyProperties(dtype, dto);
|
return dto;
|
}
|
|
@Transactional
|
public void delete(List<Long> ids) {
|
for(Long id : ids) {
|
|
manufacturerMapper.deleteById(id);
|
}
|
|
}
|
|
@Transactional(readOnly=true)
|
public List<ManufacturerDTO> allList() {
|
QueryWrapper<Manufacturer> qwp = Wrappers.query();
|
|
return manufacturerMapper.selectList(qwp).stream().map(m ->{
|
ManufacturerDTO dto = new ManufacturerDTO();
|
BeanUtils.copyProperties(m, dto);
|
return dto;
|
}).collect(Collectors.toList());
|
}
|
}
|