无关风月
2025-01-10 70061624664c6ef437c0250e8ae2c9cffd1134e0
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
package com.jilongda.manage.controller;
 
 
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.manage.dto.FrameInventoryDTO;
import com.jilongda.manage.dto.GetCurrentByParam;
import com.jilongda.manage.dto.GetCurrentByParamLens;
import com.jilongda.manage.dto.LensInventoryDTO;
import com.jilongda.manage.model.*;
import com.jilongda.manage.query.TFrameGoodsQuery;
import com.jilongda.manage.query.TInventoryQuery;
import com.jilongda.manage.service.*;
import com.jilongda.manage.utils.LoginInfoUtil;
import com.jilongda.manage.vo.TFrameGoodsVO;
import com.jilongda.manage.vo.TInventoryInfoVO;
import com.jilongda.manage.vo.TInventoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 盘点表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@RestController
@Api(tags = "盘点管理")
@RequestMapping("/t-inventory")
public class TInventoryController {
 
    @Resource
    private TInventoryService inventoryService;
    @Resource
    private TInventoryFrameDetailService inventoryFrameDetailService;
    @Resource
    private TInventoryLensDetailService inventoryLensDetailService;
    @Resource
    private LoginInfoUtil loginInfoUtil;
    @Resource
    private TFrameGoodsService frameGoodsService;
    @Resource
    private TLensGoodsService lensGoodsService;
    @Resource
    private TLensSeriesService lensSeriesService;
    @Resource
    private TModelService modelService;
    @Resource
    private TStoreService storeService;
    @ApiOperation(value = "盘点分页列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TInventoryVO>> pageList(@RequestBody TInventoryQuery query) {
        if (StringUtils.hasLength(query.getStartTime())){
            query.setStartTime(query.getStartTime()+" 00:00:00");
            query.setEndTime(query.getEndTime()+" 23:59:59");
        }
        return ApiResult.success(inventoryService.pageList(query));
    }
    @ApiOperation(value = "镜架添加盘点")
    @PostMapping(value = "/addFrameInventory")
    public ApiResult addFrameInventory(@RequestBody FrameInventoryDTO query) {
        TInventory tInventory = new TInventory();
        BeanUtils.copyProperties(query, tInventory);
        inventoryService.save(tInventory);
        for (TInventoryFrameDetail tInventoryFrameDetail : query.getList()) {
            tInventoryFrameDetail.setInventoryId(tInventory.getId());
        }
        inventoryFrameDetailService.saveBatch(query.getList());
        return ApiResult.success(tInventory.getId());
    }
    @ApiOperation(value = "镜片添加盘点")
    @PostMapping(value = "/addLensInventory")
    public ApiResult addLensInventory(@RequestBody LensInventoryDTO query) {
        TInventory tInventory = new TInventory();
        BeanUtils.copyProperties(query, tInventory);
        inventoryService.save(tInventory);
        for (TInventoryLensDetail tInventoryFrameDetail : query.getList()) {
            tInventoryFrameDetail.setInventoryId(tInventory.getId());
        }
        inventoryLensDetailService.saveBatch(query.getList());
        return ApiResult.success(tInventory.getId());
    }
 
    @ApiOperation(value = "镜架-根据品牌id查询对应库存")
    @PostMapping(value = "/getCountByBrandId")
    public ApiResult getCountByBrandId(Integer id,Integer storeId) {
        List<Integer> collect = modelService.lambdaQuery().eq(TModel::getBrandId, id)
                .list().stream().map(TModel::getId).distinct().collect(Collectors.toList());
        if (collect.isEmpty())collect.add(-1);
        List<TFrameGoods> list = frameGoodsService.lambdaQuery().in(TFrameGoods::getModelId, collect)
                .eq(TFrameGoods::getStoreId,storeId)
                .list();
        if (list.isEmpty())return ApiResult.success("0");
        int i = 0;
        for (TFrameGoods tFrameGoods : list) {
            i+=tFrameGoods.getTotal();
        }
        return ApiResult.success(i);
    }
    @ApiOperation(value = "镜架-根据材质id查询对应库存")
    @GetMapping(value = "/getCountByMaterialId")
    public ApiResult getCountByMaterialId(Integer id,Integer storeId) {
        List<Integer> collect = modelService.lambdaQuery().eq(TModel::getMaterialId, id)
                .list().stream().map(TModel::getId).distinct().collect(Collectors.toList());
        if (collect.isEmpty())collect.add(-1);
        List<TFrameGoods> list = frameGoodsService.lambdaQuery().in(TFrameGoods::getModelId, collect).
        eq(TFrameGoods::getStoreId,storeId).list();
        if (list.isEmpty())return ApiResult.success("0");
        int i = 0;
        for (TFrameGoods tFrameGoods : list) {
            i+=tFrameGoods.getTotal();
        }
        return ApiResult.success(i);
    }
    @ApiOperation(value = "镜架-根据品牌id、型号名称、色号名称、材质id查询当前库存")
    @PostMapping(value = "/getCurrentByParamFrame")
    public ApiResult<Integer> getCurrentByParamFrame(@RequestBody GetCurrentByParam getCurrentByParam) {
        // 根据型号名称 查询型号列表ids
        List<Integer> collect = modelService.lambdaQuery().eq(StringUtils.hasLength(getCurrentByParam.getModel()),TModel::getName, getCurrentByParam.getModel())
                .eq(StringUtils.hasLength(getCurrentByParam.getColor()),TModel::getColor,getCurrentByParam.getColor())
                .eq(getCurrentByParam.getMaterialId()!=null,TModel::getMaterialId,getCurrentByParam.getMaterialId())
                .eq(getCurrentByParam.getBrandId()!=null,TModel::getBrandId,getCurrentByParam.getBrandId())
                .list().stream().map(TModel::getId).collect(Collectors.toList());
        if (collect.isEmpty())collect.add(-1);
        List<TFrameGoods> one = frameGoodsService.lambdaQuery().in(TFrameGoods::getModelId, collect)
                .eq(TFrameGoods::getStoreId,getCurrentByParam.getStoreId())
                .eq(TFrameGoods::getColor, getCurrentByParam.getColor()).list();
        if (one.isEmpty())return ApiResult.success(0);
        Integer temp = one.stream()
                .mapToInt(TFrameGoods::getTotal)
                .sum();
        return ApiResult.success(temp);
    }
    @ApiOperation(value = "镜片-根据品牌id、型号名称、色号名称、材质id查询当前库存")
    @PostMapping(value = "/getCurrentByParamLens")
    public ApiResult<Integer> getCurrentByParamLens(@RequestBody GetCurrentByParamLens dto) {
        List<TLensGoods> one = lensGoodsService.lambdaQuery().in(TLensGoods::getSeriesId, dto.getSeriesId())
                .eq(dto.getLensType()!=null,TLensGoods::getLensType, dto.getLensType())
                .eq(StringUtils.hasLength(dto.getRefractiveIndex()),TLensGoods::getRefractiveIndex, dto.getRefractiveIndex())
                .eq(StringUtils.hasLength(dto.getBallMirror()),TLensGoods::getBallMirror, dto.getBallMirror())
                .eq(StringUtils.hasLength(dto.getColumnMirror()),TLensGoods::getColumnMirror, dto.getColumnMirror())
                .eq(dto.getStoreId()!=null,TLensGoods::getStoreId, dto.getStoreId())
                .list();
        if (one.isEmpty())return ApiResult.success(0);
        Integer temp = one.stream()
                .mapToInt(TLensGoods::getTotal)
                .sum();
        return ApiResult.success(temp);
    }
    @ApiOperation(value = "查看详情")
    @GetMapping(value = "/getDetailById")
    public ApiResult<TInventoryInfoVO> getDetailById(Integer id) {
        TInventoryInfoVO tInventoryInfoVO = new TInventoryInfoVO();
 
        TInventory byId = inventoryService.getById(id);
        BeanUtils.copyProperties(byId, tInventoryInfoVO);
        switch (byId.getType()){
            case 1:
                List<TInventoryFrameDetail> list = inventoryFrameDetailService.lambdaQuery().eq(TInventoryFrameDetail::getInventoryId, id).list();
                tInventoryInfoVO.setFrameList(list);
                break;
            case 2:
                List<TInventoryLensDetail> list2 = inventoryLensDetailService.lambdaQuery().eq(TInventoryLensDetail::getInventoryId, id).list();
                tInventoryInfoVO.setLensList(list2);
                break;
        }
        TStore byId1 = storeService.getById(byId.getStoreId());
        if (byId1!=null)tInventoryInfoVO.setStore(byId1.getName());
        return ApiResult.success(tInventoryInfoVO);
    }
}