gongchunyi
4 小时以前 84746c6a1fe8fb6c0216495110895cb5d346563e
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
package com.ruoyi.aftersalesservice.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.aftersalesservice.mapper.AfterSalesNearExpiryMapper;
import com.ruoyi.aftersalesservice.pojo.AfterSalesNearExpiry;
import com.ruoyi.aftersalesservice.service.AfterSalesNearExpiryService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.Arrays;
 
/**
 * <br>
 * 临期售后管理接口实现类
 * </br>
 *
 * @author deslrey
 * @version 1.0
 * @since 2026/03/02 14:46
 */
@Service
public class AfterSalesNearExpiryServiceImpl extends ServiceImpl<AfterSalesNearExpiryMapper, AfterSalesNearExpiry> implements AfterSalesNearExpiryService {
 
    @Override
    public void add(AfterSalesNearExpiry entity) {
        if (entity == null) {
            throw new ServiceException("添加失败,数据不能为空");
        }
        if (entity.getProductName() == null || entity.getProductName().trim().isEmpty()) {
            throw new ServiceException("产品名称不能为空");
        }
        if (entity.getBatchNumber() == null || entity.getBatchNumber().trim().isEmpty()) {
            throw new ServiceException("产品批号不能为空");
        }
        if (entity.getExpireDate() == null) {
            throw new ServiceException("临期日期不能为空");
        }
 
        entity.setId(null);
        entity.setStatus(1);
        entity.setDisposeUserId(null);
        entity.setDisposeNickName(null);
        entity.setDisDate(null);
        entity.setCreateTime(LocalDateTime.now());
        entity.setCreateUser(SecurityUtils.getLoginUser().getUserId());
        entity.setUpdateUser(null);
        entity.setUpdateTime(null);
        entity.setTenantId(SecurityUtils.getLoginUser().getTenantId());
 
        int result = baseMapper.insert(entity);
        if (result <= 0) {
            throw new ServiceException("新增失败");
        }
    }
 
    @Override
    public void update(AfterSalesNearExpiry entity) {
        if (entity == null || entity.getId() == null) {
            throw new ServiceException("更新失败,数据不完整");
        }
        entity.setStatus(2);
        entity.setUpdateUser(SecurityUtils.getLoginUser().getUserId());
        entity.setUpdateTime(LocalDateTime.now());
        int result = baseMapper.updateById(entity);
        if (result <= 0) {
            throw new ServiceException("更新失败");
        }
    }
 
    @Override
    public void delete(Long[] ids) {
        if (ids == null || ids.length == 0) {
            throw new ServiceException("请选择要删除的数据");
        }
        int result = baseMapper.deleteBatchIds(Arrays.asList(ids));
        if (result <= 0) {
            throw new ServiceException("删除失败");
        }
    }
 
    @Override
    public IPage<AfterSalesNearExpiry> listPage(Page<AfterSalesNearExpiry> page, AfterSalesNearExpiry entity) {
        return baseMapper.listPage(page, entity);
    }
}