sgj
2026-04-01 f9ddeb748da46dc7341b7608f64435695601f4b6
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
123
124
125
126
127
128
129
130
131
package com.fzzy.igds.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.igds.data.IgdsBaseParam;
import com.fzzy.igds.domain.InoutLossOver;
import com.fzzy.igds.domain.InoutStockChange;
import com.fzzy.igds.mapper.InoutLossOverMapper;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.DateUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/12/19 09:05
 */
@Slf4j
@Service
public class InoutLossOverService {
 
    @Resource
    private InoutLossOverMapper inoutLossOverMapper;
 
    /**
     * 列表分页查询
     * @param page
     * @param param
     */
    public void pageData(Page<InoutLossOver> page, IgdsBaseParam param) {
        QueryWrapper<InoutLossOver> queryWrapper = new QueryWrapper<>();
 
        param.setCompanyId(ContextUtil.getCompanyId());
        param.setDeptId(ContextUtil.subDeptId(null));
        queryWrapper.eq("company_id", param.getCompanyId());
        queryWrapper.eq("dept_id", param.getDeptId());
 
        if(StringUtils.isNotBlank(param.getDepotId())){
            queryWrapper.like("depot_id", param.getDepotId());
        }
        if(null != param.getStart()){
            queryWrapper.ge("loss_time", DateUtil.getCurZero(param.getStart()));
        }
        if(null != param.getEnd()){
            queryWrapper.le("loss_time", DateUtil.getNextZero(param.getEnd()));
        }
 
        inoutLossOverMapper.selectPage(page, queryWrapper);
    }
 
 
    /**
     * 根据时间类型,获取数据
     * @param timeType
     * @param param
     * @return
     */
    public List<InoutLossOver> getDataByTime(String timeType, IgdsBaseParam param) {
        if(StringUtils.isBlank(timeType)){
            return null;
        }
 
        QueryWrapper<InoutLossOver> queryWrapper = new QueryWrapper<>();
 
        queryWrapper.likeRight("dept_id", param.getDeptId());
        queryWrapper.ge(timeType, param.getStart());
        queryWrapper.le(timeType, param.getEnd());
        queryWrapper.orderByAsc("loss_time");
 
        return inoutLossOverMapper.selectList(queryWrapper);
    }
 
    /**
     * 保存数据
     * @param data
     */
    public void saveData(InoutLossOver data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
        if(StringUtils.isEmpty(data.getId())){
            data.setId(getStrId(data.getLossTime()));
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
            inoutLossOverMapper.insert(data);
        }else {
            inoutLossOverMapper.updateById(data);
        }
    }
 
    /**
     * 获取主键ID
     *
     * @param time
     */
    public String getStrId(Date time) {
 
        QueryWrapper<InoutLossOver> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("loss_time", DateUtil.getCurZero(time));
        queryWrapper.le("loss_time", DateUtil.getNextZero(time));
        queryWrapper.orderByDesc("id");
 
        List<InoutLossOver> list = inoutLossOverMapper.selectList(queryWrapper);
        String oldOrderId = null;
        if (null != list && list.size() > 0) {
            oldOrderId = list.get(0).getId().substring(8);
        }
        return DateFormatUtils.format(time, "yyyyMMdd") + ContextUtil.getOrderId(oldOrderId, 3);
    }
 
    /**
     * 删除数据
     * @param data
     * @return
     */
    public String delData(InoutLossOver data) {
        inoutLossOverMapper.deleteById(data);
        return null;
    }
}