无关风月
2024-08-01 8876b1b9cd27fad076ea9e5f3e04197b84ba02bd
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
package com.ruoyi.management.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.ClientTypeEnum;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.management.domain.InventoriesSupplies;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.management.domain.SlGoodsShelf;
import com.ruoyi.management.domain.SlStoreManagement;
import com.ruoyi.management.domain.SlVolumeProductionRk;
import com.ruoyi.management.domain.dto.InventoriesSuppDTO;
import com.ruoyi.management.domain.dto.InventoriesSuppliesQuery;
import com.ruoyi.management.domain.dto.ScanCodesDTO;
import com.ruoyi.management.domain.vo.InventoriesSuppliesVO;
import com.ruoyi.management.domain.vo.SlGoodsMaterialsVO;
import com.ruoyi.management.domain.vo.SlGoodsShelfVO;
import com.ruoyi.management.mapper.InventoriesSuppliesMapper;
import com.ruoyi.management.mapper.SlStoreManagementMapper;
import com.ruoyi.management.mapper.SlVolumeProductionRkMapper;
import com.ruoyi.management.service.InventoriesSuppliesService;
import com.ruoyi.management.service.SlVolumeProductionRkService;
import com.ruoyi.system.api.constants.NotificationTypeConstant;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.domain.WebsocketMessageDTO;
import com.ruoyi.system.api.feignClient.SysUserClient;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 物资盘点 服务实现类
 * </p>
 *
 * @author hjl
 * @since 2024-07-01
 */
@Service
public class InventoriesSuppliesServiceImpl extends ServiceImpl<InventoriesSuppliesMapper, InventoriesSupplies> implements InventoriesSuppliesService {
 
    @Resource
    private SlStoreManagementMapper slStoreManagementMapper;
 
    @Resource
    private SysUserClient sysUserClient;
 
    @Resource
    private SlVolumeProductionRkMapper slVolumeProductionRkMapper;
 
    private static final ObjectMapper objectMapper = new ObjectMapper();
 
    @Override
    public PageDTO<InventoriesSuppliesVO> getInventoriesSuppliesList(InventoriesSuppliesQuery inventoriesSuppliesQuery) {
        LambdaQueryWrapper<SlStoreManagement> wrapper= Wrappers.lambdaQuery();
        if (inventoriesSuppliesQuery.getStoreManagementName()!=null&&inventoriesSuppliesQuery.getStoreManagementName()!=""){
            wrapper.eq(SlStoreManagement::getStoreManagementName,inventoriesSuppliesQuery.getStoreManagementName());
        }
        if (inventoriesSuppliesQuery.getStoreManagementNo()!=null&&inventoriesSuppliesQuery.getStoreManagementNo()!=""){
        wrapper.eq(SlStoreManagement::getStoreManagementNo,inventoriesSuppliesQuery.getStoreManagementNo());
        }
        List<SlStoreManagement> slStoreManagements = slStoreManagementMapper.selectList(wrapper);
 
        Set<Long> slStoreManagementIdList = null;
        slStoreManagementIdList = slStoreManagements.stream().map(SlStoreManagement::getId)
                .collect(Collectors.toSet());
 
        Page<InventoriesSupplies> page = new Page<>(inventoriesSuppliesQuery.getPageCurr(), inventoriesSuppliesQuery.getPageSize());
        LambdaQueryWrapper< InventoriesSupplies> wrapper1= Wrappers.lambdaQuery();
        if (inventoriesSuppliesQuery.getPdrName()!=null&&inventoriesSuppliesQuery.getPdrName()!=""){
            wrapper1.like(InventoriesSupplies::getPdrName,inventoriesSuppliesQuery.getPdrName());
        }
        if (slStoreManagementIdList.size()>0){
            wrapper1.in(InventoriesSupplies::getMaterialsId,slStoreManagementIdList);
        }else {
                Set<Long> goodsSkuIdList1 = new HashSet<>();
                goodsSkuIdList1.add(0L);
                wrapper1.in(InventoriesSupplies::getMaterialsId,goodsSkuIdList1);
        }
        if (inventoriesSuppliesQuery.getStartpdTime()!=null){
 
            wrapper1.gt(InventoriesSupplies::getPdTime, inventoriesSuppliesQuery.getStartpdTime());
        }
        if (inventoriesSuppliesQuery.getEndpdTime()!=null&&inventoriesSuppliesQuery.getPdrName()!=""){
            wrapper1.le(InventoriesSupplies::getPdTime, inventoriesSuppliesQuery.getEndpdTime());
       }
 
 
        wrapper1.eq( InventoriesSupplies::getDelFlag,0);
        wrapper1.orderByDesc(InventoriesSupplies::getCreateTime);
        Page<InventoriesSupplies> page2 = this.page(page, wrapper1);
        PageDTO<InventoriesSuppliesVO> slGoodsMaterialsVO = PageDTO.of(page2, InventoriesSuppliesVO.class);
        List<InventoriesSuppliesVO> list = slGoodsMaterialsVO.getList();
        for (InventoriesSuppliesVO sl:list){
            SlStoreManagement slStoreManagementzs = slStoreManagementMapper.selectById(sl.getMaterialsId());
            sl.setStoreManagementName(slStoreManagementzs.getStoreManagementName());
            sl.setStoreManagementNo(slStoreManagementzs.getStoreManagementNo());
        }
 
        return slGoodsMaterialsVO;
    }
 
    @Override
    public void addInventoriesSupp(InventoriesSuppDTO inventoriesSuppDTO) {
        InventoriesSupplies inventoriesSupplies=new InventoriesSupplies();
        inventoriesSupplies.setMaterialsId(inventoriesSuppDTO.getMaterialsId());
        inventoriesSupplies.setPdTime(new Date());
        inventoriesSupplies.setCreateTime(new Date());
        inventoriesSupplies.setPdrId(inventoriesSuppDTO.getPdrId());
        R<SysUser> sysUser = sysUserClient.getSysUser(inventoriesSuppDTO.getPdrId());
        inventoriesSupplies.setPdrName(sysUser.getData().getNickName());
        this.save(inventoriesSupplies);
    }
 
    @Override
    public void scanCodes(String rkNumber) {
        LambdaQueryWrapper< SlVolumeProductionRk> wrapper1= Wrappers.lambdaQuery();
        wrapper1.like(SlVolumeProductionRk::getRkNumber,rkNumber);
        wrapper1.eq( SlVolumeProductionRk::getDelFlag,0);
        wrapper1.orderByDesc(SlVolumeProductionRk::getCreateTime);
        SlVolumeProductionRk page2 = slVolumeProductionRkMapper.selectOne(wrapper1);
        if (page2.getSmerwmNum()>0){
            Integer i=page2.getSmerwmNum()-1;
            page2.setSmerwmNum(i);
            slVolumeProductionRkMapper.updateById(page2);
        }
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.SCANCODES);
        map.put("SlVolumeProductionRk",page2);
        String msg = null;
        try {
            msg = objectMapper.writeValueAsString(map);
        } catch (JsonProcessingException e) {
        }
        sysUserClient.pushAll(msg, SecurityConstants.INNER);
    }
 
 
}