MrShi
2025-02-07 364d3221b9a8e6dd3a19701d30c4dc4239ef8abf
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
132
133
134
135
136
137
138
139
140
141
142
143
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwOutinboundRecordMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.YwOutinboundRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * 运维出入库信息明细表Service实现
 * @author 江蹄蹄
 * @date 2025/01/06 14:28
 */
@Service
public class YwOutinboundRecordServiceImpl implements YwOutinboundRecordService {
 
    @Autowired
    private YwOutinboundRecordMapper ywOutinboundRecordMapper;
 
    @Override
    public Integer create(YwOutinboundRecord ywOutinboundRecord) {
        ywOutinboundRecordMapper.insert(ywOutinboundRecord);
        return ywOutinboundRecord.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        ywOutinboundRecordMapper.deleteById(id);
    }
 
    @Override
    public void delete(YwOutinboundRecord ywOutinboundRecord) {
        UpdateWrapper<YwOutinboundRecord> deleteWrapper = new UpdateWrapper<>(ywOutinboundRecord);
        ywOutinboundRecordMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        ywOutinboundRecordMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(YwOutinboundRecord ywOutinboundRecord) {
        ywOutinboundRecordMapper.updateById(ywOutinboundRecord);
    }
 
    @Override
    public void updateByIdInBatch(List<YwOutinboundRecord> ywOutinboundRecords) {
        if (CollectionUtils.isEmpty(ywOutinboundRecords)) {
            return;
        }
        for (YwOutinboundRecord ywOutinboundRecord: ywOutinboundRecords) {
            this.updateById(ywOutinboundRecord);
        }
    }
 
    @Override
    public YwOutinboundRecord findById(Integer id) {
        return ywOutinboundRecordMapper.selectById(id);
    }
 
    @Override
    public YwOutinboundRecord findOne(YwOutinboundRecord ywOutinboundRecord) {
        QueryWrapper<YwOutinboundRecord> wrapper = new QueryWrapper<>(ywOutinboundRecord);
        return ywOutinboundRecordMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwOutinboundRecord> findList(YwOutinboundRecord ywOutinboundRecord) {
        QueryWrapper<YwOutinboundRecord> wrapper = new QueryWrapper<>(ywOutinboundRecord);
        return ywOutinboundRecordMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwOutinboundRecord> findPage(PageWrap<YwOutinboundRecord> pageWrap) {
        IPage<YwOutinboundRecord> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwOutinboundRecord> queryWrapper = new MPJLambdaWrapper<YwOutinboundRecord>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwOutinboundRecord model = pageWrap.getModel();
        List<Integer> typeList = new ArrayList<>();
        if(!(Objects.isNull(model)||Objects.isNull(model.getInOut()))){
            typeList  = Constants.ywOutInType.getAllTypeKey(model.getInOut());
        }
        queryWrapper.selectAll(YwOutinboundRecord.class)
                .selectAs(SystemUser::getRealname,YwOutinboundRecord::getCreateUserName)
                .selectAs(YwOutinbound::getCode,YwOutinboundRecord::getCode)
                .selectAs(YwOutinbound::getType,YwOutinboundRecord::getType)
                .selectAs(YwOutinbound::getDoneDate,YwOutinboundRecord::getDoneDate)
                .selectAs(YwWarehouse::getName,YwOutinboundRecord::getWarehouseName)
                .selectAs(YwMaterial::getCode,YwOutinboundRecord::getMaterialCode)
                .selectAs(YwMaterial::getName,YwOutinboundRecord::getMaterialName)
                .selectAs(YwMaterial::getQrcode,YwOutinboundRecord::getMaterialQrcode)
                .selectAs(YwMaterial::getBrand,YwOutinboundRecord::getMaterialBrand)
                .selectAs(YwMaterial::getUnitName,YwOutinboundRecord::getMaterialUnitName)
                .select(" c.name ",YwOutinboundRecord::getCategoryParentName)
                .select(" c1.name ",YwOutinboundRecord::getCategoryName)
                .leftJoin(YwOutinbound.class,YwOutinbound::getId,YwOutinboundRecord::getOutInBoundId)
                .leftJoin(SystemUser.class,SystemUser::getId,YwOutinbound::getCreator)
                .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwOutinbound::getWarehouseId)
                .leftJoin(YwMaterial.class,YwMaterial::getId,YwOutinboundRecord::getMaterialId)
                .leftJoin("category c on t4.PARENT_CATE_ID = c.id")
                .leftJoin("category c1 on t4.CATE_ID = c1.id")
                .like(StringUtils.isNotBlank(model.getCode()),YwOutinbound::getCode,model.getCode())
                .like(StringUtils.isNotBlank(model.getMaterialCode()),YwMaterial::getCode,model.getMaterialCode())
                .eq(Objects.nonNull(model.getWarehouseId()),YwOutinbound::getWarehouseId,model.getWarehouseId())
                .in(Objects.nonNull(model.getInOut()),YwOutinbound::getType,typeList)
                .ge(StringUtils.isNotBlank(model.getDoneDateStart()),YwOutinbound::getDoneDate,model.getDoneDateStart()+" 00:00:00")
                .le(StringUtils.isNotBlank(model.getDoneDateEnd()),YwOutinbound::getDoneDate,model.getDoneDateEnd()+" 23:59:59")
                .ge(StringUtils.isNotBlank(model.getCreateDateStart()),YwOutinbound::getCreateDate,model.getCreateDateStart()+" 00:00:00")
                .le(StringUtils.isNotBlank(model.getCreateDateEnd()),YwOutinbound::getCreateDate,model.getCreateDateEnd()+" 23:59:59")
                .orderByDesc(YwOutinbound::getCreateDate)
        ;
        IPage iPage = ywOutinboundRecordMapper.selectJoinPage(page,YwOutinboundRecord.class,queryWrapper);
        return PageData.from(iPage);
    }
 
    @Override
    public long count(YwOutinboundRecord ywOutinboundRecord) {
        QueryWrapper<YwOutinboundRecord> wrapper = new QueryWrapper<>(ywOutinboundRecord);
        return ywOutinboundRecordMapper.selectCount(wrapper);
    }
}