renkang
2025-05-13 0a99001be87811ebb884b8f3f491f48054a22330
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwStocktakingMapper;
import com.doumee.dao.business.YwStocktakingRecordMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.YwStocktakingRecordService;
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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
 
/**
 * 运维盘点明细记录表Service实现
 * @author 江蹄蹄
 * @date 2025/01/06 11:05
 */
@Service
public class YwStocktakingRecordServiceImpl implements YwStocktakingRecordService {
 
    @Autowired
    private YwStocktakingRecordMapper ywStocktakingRecordMapper;
 
    @Autowired
    private YwStocktakingMapper ywStocktakingMapper;
 
 
    @Override
    public Integer create(YwStocktakingRecord ywStocktakingRecord) {
        ywStocktakingRecordMapper.insert(ywStocktakingRecord);
        return ywStocktakingRecord.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        ywStocktakingRecordMapper.deleteById(id);
    }
 
    @Override
    public void delete(YwStocktakingRecord ywStocktakingRecord) {
        UpdateWrapper<YwStocktakingRecord> deleteWrapper = new UpdateWrapper<>(ywStocktakingRecord);
        ywStocktakingRecordMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        ywStocktakingRecordMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(YwStocktakingRecord ywStocktakingRecord) {
        ywStocktakingRecordMapper.updateById(ywStocktakingRecord);
    }
 
    @Override
    public void updateByIdInBatch(List<YwStocktakingRecord> ywStocktakingRecords) {
        if (CollectionUtils.isEmpty(ywStocktakingRecords)) {
            return;
        }
        for (YwStocktakingRecord ywStocktakingRecord: ywStocktakingRecords) {
            this.updateById(ywStocktakingRecord);
        }
    }
 
    @Override
    public YwStocktakingRecord findById(Integer id) {
        return ywStocktakingRecordMapper.selectById(id);
    }
 
 
    @Override
    public YwStocktakingRecord getDetail(Integer id) {
        MPJLambdaWrapper<YwStocktakingRecord> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwStocktakingRecord.class)
                .selectAs(YwWarehouse::getName, YwStocktakingRecord::getWarehouseName)
                .selectAs(YwMaterial::getCode,YwStocktakingRecord::getMaterialCode)
                .selectAs(YwMaterial::getName,YwStocktakingRecord::getMaterialName)
                .selectAs(YwMaterial::getQrcode,YwStocktakingRecord::getMaterialQrcode)
                .selectAs(YwMaterial::getBrand,YwStocktakingRecord::getMaterialBrand)
                .selectAs(YwMaterial::getUnitName,YwStocktakingRecord::getMaterialUnitName)
                .selectAs(YwMaterial::getAttr,YwStocktakingRecord::getMaterialAttr)
                .selectAs(Company::getName,YwStocktakingRecord::getCompanyName)
                .selectAs(SystemUser::getRealname,YwStocktakingRecord::getUserName)
                .leftJoin(YwStocktaking.class,YwStocktaking::getId,YwStocktakingRecord::getStocktakingId)
                .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId)
                .leftJoin(YwMaterial.class,YwMaterial::getId,YwStocktakingRecord::getMaterialId)
                .leftJoin(SystemUser.class,SystemUser::getId,YwStocktakingRecord::getUserId)
                .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId)
                .eq(YwStocktakingRecord::getId,id)
                .last(" limit 1 ");
        ;
        return ywStocktakingRecordMapper.selectOne(queryWrapper);
    }
 
    @Override
    public YwStocktakingRecord findOne(YwStocktakingRecord ywStocktakingRecord) {
        QueryWrapper<YwStocktakingRecord> wrapper = new QueryWrapper<>(ywStocktakingRecord);
        return ywStocktakingRecordMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwStocktakingRecord> findList(YwStocktakingRecord ywStocktakingRecord) {
        QueryWrapper<YwStocktakingRecord> wrapper = new QueryWrapper<>(ywStocktakingRecord);
        return ywStocktakingRecordMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwStocktakingRecord> findPage(PageWrap<YwStocktakingRecord> pageWrap) {
        IPage<YwStocktakingRecord> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwStocktakingRecord> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwStocktakingRecord model = pageWrap.getModel() ;
        queryWrapper.selectAll(YwStocktakingRecord.class)
                .selectAs(YwWarehouse::getName, YwStocktakingRecord::getWarehouseName)
                .selectAs(YwMaterial::getCode,YwStocktakingRecord::getMaterialCode)
                .selectAs(YwMaterial::getName,YwStocktakingRecord::getMaterialName)
                .selectAs(YwMaterial::getQrcode,YwStocktakingRecord::getMaterialQrcode)
                .selectAs(YwMaterial::getBrand,YwStocktakingRecord::getMaterialBrand)
                .selectAs(YwMaterial::getUnitName,YwStocktakingRecord::getMaterialUnitName)
                .selectAs(YwMaterial::getAttr,YwStocktakingRecord::getMaterialAttr)
                .leftJoin(YwStocktaking.class,YwStocktaking::getId,YwStocktakingRecord::getStocktakingId)
                .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId)
                .leftJoin(YwMaterial.class,YwMaterial::getId,YwStocktakingRecord::getMaterialId)
                .eq(Objects.nonNull(model.getStocktakingId()),YwStocktakingRecord::getStocktakingId,model.getStocktakingId())
                .and(StringUtils.isNotBlank(model.getMaterialCode()),i->i.like(YwMaterial::getCode,model.getMaterialCode()).or().like(YwMaterial::getName,model.getMaterialCode()))
                .eq(Objects.nonNull(model.getType()),YwStocktakingRecord::getType,model.getType())
                .eq(Objects.nonNull(model.getStatus()),YwStocktakingRecord::getStatus,model.getStatus())
                .eq(Objects.nonNull(model.getMaterialQrcode()),YwMaterial::getQrcode,model.getMaterialQrcode());
        IPage iPage = ywStocktakingRecordMapper.selectJoinPage(page, YwStocktakingRecord.class,queryWrapper);
        return PageData.from(iPage);
    }
 
    @Override
    public long count(YwStocktakingRecord ywStocktakingRecord) {
        QueryWrapper<YwStocktakingRecord> wrapper = new QueryWrapper<>(ywStocktakingRecord);
        return ywStocktakingRecordMapper.selectCount(wrapper);
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void takingData(YwStocktakingRecord ywStocktakingRecord) {
        if(Objects.isNull(ywStocktakingRecord)
            || Objects.isNull(ywStocktakingRecord.getId())
            || Objects.isNull(ywStocktakingRecord.getActStock())
            || ywStocktakingRecord.getActStock().compareTo(BigDecimal.ZERO) < 0
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywStocktakingRecord.getLoginUserInfo();
        YwStocktakingRecord model = ywStocktakingRecordMapper.selectById(ywStocktakingRecord.getId());
        if(Objects.isNull(model)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        YwStocktaking ywStocktaking = ywStocktakingMapper.selectById(ywStocktakingRecord.getStocktakingId());
        if(Objects.isNull(ywStocktaking)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(loginUserInfo.getId(),ywStocktaking.getUserId())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非您的盘点单无法进行操作");
        }
        if(!Constants.equalsInteger(ywStocktaking.getStatus(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"盘点订状态已流转,无法进行该操作");
        }
        if(ywStocktakingRecord.getActStock().compareTo(model.getStock())==Constants.ZERO){
            ywStocktakingRecord.setType(Constants.ZERO);
        }else if(ywStocktakingRecord.getActStock().compareTo(model.getStock())>Constants.ZERO){
            ywStocktakingRecord.setType(Constants.TWO);
        }else{
            ywStocktakingRecord.setType(Constants.ONE);
        }
        ywStocktakingRecordMapper.update(new UpdateWrapper<YwStocktakingRecord>().lambda()
                .set(YwStocktakingRecord::getStatus,Constants.ONE)
                .set(YwStocktakingRecord::getType,ywStocktakingRecord.getType())
                .set(YwStocktakingRecord::getActStock,ywStocktakingRecord.getActStock())
                .set(YwStocktakingRecord::getUserId,loginUserInfo.getId())
                .set(YwStocktakingRecord::getPlanDate, DateUtil.getCurrDateTime())
                .set(StringUtils.isNotBlank(ywStocktakingRecord.getRemark()),YwStocktakingRecord::getRemark, ywStocktakingRecord.getRemark())
                .eq(YwStocktakingRecord::getId,ywStocktakingRecord.getId())
        );
 
 
 
    }
 
 
}