package com.ruoyi.basic.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.utils.QueryWrappers;
|
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.basic.dto.DefectiveProductAuditDto;
|
import com.ruoyi.basic.dto.DefectiveProductDto;
|
import com.ruoyi.basic.mapper.QualityDefectiveProductMapper;
|
import com.ruoyi.basic.pojo.QualityDefectiveProduct;
|
import com.ruoyi.basic.service.QualityDefectiveProductService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
/**
|
* 不良品登记Service实现类
|
*/
|
@Service
|
public class QualityDefectiveProductServiceImpl implements QualityDefectiveProductService {
|
|
@Resource
|
private QualityDefectiveProductMapper defectiveProductMapper;
|
|
@Override
|
public IPage<QualityDefectiveProduct> selectPage(Page<QualityDefectiveProduct> page, QualityDefectiveProduct entity) {
|
return defectiveProductMapper.selectPage(page, QueryWrappers.queryWrappers(entity));
|
}
|
|
@Override
|
public QualityDefectiveProduct selectById(Long id) {
|
return defectiveProductMapper.selectById(id);
|
}
|
|
@Override
|
public int insert(DefectiveProductDto dto) {
|
QualityDefectiveProduct entity = new QualityDefectiveProduct();
|
BeanUtils.copyProperties(dto, entity);
|
|
// 获取当前登录用户
|
String username = SecurityUtils.getUsername();
|
|
// 设置登记相关字段
|
entity.setRegisterBy(username);
|
entity.setRegisterTime(LocalDateTime.now());
|
|
// 设置创建相关字段
|
entity.setCreateBy(username);
|
entity.setCreateTime(LocalDateTime.now());
|
|
// 设置更新相关字段
|
entity.setUpdateBy(username);
|
entity.setUpdateTime(LocalDateTime.now());
|
|
// 设置审核状态为待审核
|
entity.setAuditStatus(0);
|
|
return defectiveProductMapper.insert(entity);
|
}
|
|
@Override
|
public int update(Long id, DefectiveProductDto dto) {
|
QualityDefectiveProduct entity = defectiveProductMapper.selectById(id);
|
if (entity == null) {
|
throw new RuntimeException("不良品信息不存在");
|
}
|
|
BeanUtils.copyProperties(dto, entity);
|
entity.setId(id);
|
entity.setUpdateBy(SecurityUtils.getUsername());
|
entity.setUpdateTime(LocalDateTime.now());
|
|
return defectiveProductMapper.updateById(entity);
|
}
|
|
@Override
|
public int update(QualityDefectiveProduct entity) {
|
if (entity.getId() == null) {
|
throw new RuntimeException("ID不能为空");
|
}
|
entity.setUpdateBy(SecurityUtils.getUsername());
|
entity.setUpdateTime(LocalDateTime.now());
|
return defectiveProductMapper.updateById(entity);
|
}
|
|
@Override
|
public int deleteById(Long id) {
|
return defectiveProductMapper.deleteById(id);
|
}
|
|
@Override
|
public int deleteBatchIds(Long[] ids) {
|
return defectiveProductMapper.deleteBatchIds(java.util.Arrays.asList(ids));
|
}
|
|
@Override
|
public int audit(DefectiveProductAuditDto auditDto) {
|
QualityDefectiveProduct entity = defectiveProductMapper.selectById(auditDto.getId());
|
if (entity == null) {
|
throw new RuntimeException("不良品信息不存在");
|
}
|
|
String username = SecurityUtils.getUsername();
|
LocalDateTime now = LocalDateTime.now();
|
|
entity.setAuditBy(username);
|
entity.setAuditRemark(auditDto.getAuditRemark());
|
entity.setAuditStatus(auditDto.getAuditStatus());
|
entity.setAuditTime(now);
|
return defectiveProductMapper.updateById(entity);
|
}
|
|
@Override
|
public List<QualityDefectiveProduct> selectList() {
|
return defectiveProductMapper.selectList(Wrappers.emptyWrapper());
|
}
|
}
|