无关风月
2025-02-28 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99
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
package com.jilongda.manage.controller;
 
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.manage.dto.TAddWarehousingLensDTO;
import com.jilongda.manage.dto.TLensWarehousingDetailDTO;
import com.jilongda.manage.dto.TWarehousingLensDTO;
import com.jilongda.manage.model.*;
import com.jilongda.manage.query.TLensSeriesQuery;
import com.jilongda.manage.query.TOptometristQuery;
import com.jilongda.manage.service.TLensGoodsService;
import com.jilongda.manage.service.TLensSeriesService;
import com.jilongda.manage.service.TLensWarehousingDetailService;
import com.jilongda.manage.service.TWarehousingService;
import com.jilongda.manage.vo.TLensSeriesVO;
import com.jilongda.manage.vo.TOptometristVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 镜片系列表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@Api(tags = "镜片系列管理")
@RestController
@RequestMapping("/t-lens-series")
public class TLensSeriesController {
    @Autowired
    private TLensSeriesService lensSeriesService;
    @Autowired
    private TWarehousingService warehousingService;
    @Autowired
    private TLensWarehousingDetailService lensWarehousingDetailService;
    @ApiOperation(value = "镜片系列列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TLensSeriesVO>> pageList(@RequestBody TLensSeriesQuery query) {
        PageInfo<TLensSeriesVO> optometristVOPageInfo = lensSeriesService.pageList(query);
        return ApiResult.success(optometristVOPageInfo);
    }
    @ApiOperation(value = "镜片系列添加")
    @PostMapping(value = "/add")
    public ApiResult<String> add(@RequestBody TLensSeries dto) {
        lensSeriesService.save(dto);
        return ApiResult.success();
    }
    @Autowired
    private TLensGoodsService lensGoodsService;
    @ApiOperation(value = "镜片系列生成库存")
    @PostMapping(value = "/addGoods")
    public ApiResult<String> addGoods(@RequestBody TAddWarehousingLensDTO dto) {
        List<TLensGoods> list = lensGoodsService.lambdaQuery().list();
        List<TLensWarehousingDetailDTO> tLensWarehousingDetail = dto.getLensWarehousingDetails();
        List<TLensSeries> lensSeries = lensSeriesService.list();
        List<TLensGoods> tLensGoods = new ArrayList<>();
        for (TLensWarehousingDetailDTO frameWarehousingDetail : tLensWarehousingDetail) {
            TLensSeries series = lensSeries.stream().filter(e -> e.getId().equals(frameWarehousingDetail.getSeriesId())).findFirst().orElse(null);
            if (series!=null){
                    double endBallCondition =0.00;
                    double endColumnCondition =0.00;
                    TLensGoods tLensGoods1 = list.stream().filter(e -> e.getSeriesId().equals(frameWarehousingDetail.getSeriesId()) &&
                            e.getRefractiveIndex().equals(frameWarehousingDetail.getRefractiveIndex())
                            && e.getLensType().equals(frameWarehousingDetail.getType())
                            && e.getBallMirror().equals(endBallCondition+"")
                            && e.getColumnMirror().equals(endColumnCondition+"")).findFirst().orElse(null);
                    if (tLensGoods1==null){
                        // 新增
                        TLensGoods tFrameGoods = new TLensGoods();
                        tFrameGoods.setStatus(1);
                        tFrameGoods.setLensType(frameWarehousingDetail.getType());
                        tFrameGoods.setSeriesId(frameWarehousingDetail.getSeriesId());
                        tFrameGoods.setBallMirror(String.format("%.2f",endBallCondition));
                        tFrameGoods.setColumnMirror(String.format("%.2f",endColumnCondition));
                        tFrameGoods.setRefractiveIndex(frameWarehousingDetail.getRefractiveIndex());
                        tFrameGoods.setTotal(0);
                        tFrameGoods.setStoreId(dto.getStoreId());
                        tLensGoods.add(tFrameGoods);
                    }
            }
        }
        lensGoodsService.saveBatch(tLensGoods);
        return ApiResult.success();
    }
 
    public static void main(String[] args) {
        double temp = -0.25;
        System.err.println(temp-0.25);
 
        System.err.println(String.format("%.2f",temp-0.25));
    }
    @ApiOperation(value = "镜片系列编辑")
    @PostMapping(value = "/update")
    public ApiResult<String> update(@RequestBody TLensSeries dto) {
        if (!StringUtils.hasLength(dto.getSphere())){
            dto.setSphere("");
        }
        if (!StringUtils.hasLength(dto.getAsphericSurface())){
            dto.setAsphericSurface("");
        }
        if (!StringUtils.hasLength(dto.getDoubleNon())){
            dto.setDoubleNon("");
        }
        lensSeriesService.updateById(dto);
        return ApiResult.success();
    }
    @ApiOperation(value = "镜片系列启用/禁用")
    @GetMapping(value = "/updateState")
    public ApiResult<String> update(Integer id) {
        TLensSeries byId = lensSeriesService.getById(id);
        if (byId.getStatus()==1){
            byId.setStatus(2);
        }else{
            byId.setStatus(1);
        }
        lensSeriesService.updateById(byId);
        return ApiResult.success();
    }
    @ApiOperation(value = "通过品牌id查询镜片系列列表")
    @GetMapping(value = "/seriesList")
    public ApiResult<List<TLensSeries>> seriesList(Integer brandId) {
        return ApiResult.success(lensSeriesService.lambdaQuery().eq(TLensSeries::getBrandId,brandId).list());
    }
    @ApiOperation(value = "通过品牌id查询镜片系列列表-添加销售订单用 过滤没有生成库存的系列")
    @GetMapping(value = "/seriesListOrder")
    public ApiResult<List<TLensSeries>> seriesListOrder(Integer brandId) {
        List<TLensGoods> list = lensGoodsService.lambdaQuery().list();
        List<Integer> collect = list.stream().map(TLensGoods::getSeriesId).distinct().collect(Collectors.toList());
        if (list.isEmpty()){
            return ApiResult.success(new ArrayList<TLensSeries>());
        }
        List<TLensSeries> lensSeries = lensSeriesService.lambdaQuery().eq(TLensSeries::getBrandId, brandId)
                .in(TLensSeries::getId,collect).list();
        return ApiResult.success(lensSeries);
    }
    @ApiOperation(value = "通过系列id查询球/非球 返回参数1为球 2非球 3双飞")
    @GetMapping(value = "/lensTypeList")
    public ApiResult<List<Integer>> lensTypeList(Integer id) {
        TLensSeries byId = lensSeriesService.getById(id);
        List<Integer> integers = new ArrayList<>();
        if (StringUtils.hasLength(byId.getSphere())){
            integers.add(1);
        }
        if (StringUtils.hasLength(byId.getAsphericSurface())){
            integers.add(2);
        }
        if (StringUtils.hasLength(byId.getDoubleNon())){
            integers.add(3);
        }
        return ApiResult.success(integers);
    }
    @ApiOperation(value = "根据系列id + 球/非球查询折射率列表 球/非球入参数1为球 2非球 3双飞")
    @GetMapping(value = "/refractiveIndexList")
    public ApiResult<JSONArray> refractiveIndexList(Integer id, Integer lensType) {
        TLensSeries byId = lensSeriesService.getById(id);
        JSONArray jsonArray = null;
        if (lensType==1){
            String sphere = byId.getSphere();
            // 将字符串化为jsonArray
            if (StringUtils.hasLength(sphere)) {
                jsonArray = JSONObject.parseArray(sphere);
            } else {
                return ApiResult.success(new JSONArray());
            }
        }
        if (lensType==2){
            String asphericSurface = byId.getAsphericSurface();
            if (StringUtils.hasLength(asphericSurface)) {
                jsonArray = JSONObject.parseArray(asphericSurface);
            } else {
                return ApiResult.success(new JSONArray());
            }
        }
        if (lensType==3){
            String doubleNon = byId.getDoubleNon();
            if (StringUtils.hasLength(doubleNon)) {
                jsonArray = JSONObject.parseArray(doubleNon);
            } else {
                return ApiResult.success(new JSONArray());
            }
        }
 
        return ApiResult.success(jsonArray);
    }
}