huminmin
2026-06-05 4f45f29e6b53f4c01b414409c5000ff4e212b3d9
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
119
120
121
122
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());
    }
}