liujie
23 小时以前 c8e080d65e26158ea62c98548a11e9aa75c2112e
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package com.ruoyi.web.controller.api;
 
 
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.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.ClinicOutboundGoodsDto;
import com.ruoyi.system.dto.InventoryDto;
import com.ruoyi.system.dto.WarehouseGoodsDto;
import com.ruoyi.system.dto.clinicWarehouseGoodsDto;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.*;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * erp诊所入库 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-08-20
 */
@RestController
@RequestMapping("/t-erp-clinic-warehousing")
@Api(tags = "诊所库存管理")
public class TErpClinicWarehousingController {
 
    private final TErpClinicWarehousingService erpClinicWarehousingService;
    private final TErpGoodsService erpGoodsService;
    private final TokenService tokenService;
    private final TCrmClinicService crmClinicService;
    private final TCrmSupplierService crmSupplierService;
    private final TErpClinicWarehousingBatchService erpClinicWarehousingBatchService;
    private final TErpGoodsUnitService erpGoodsUnitService;
 
 
    @Autowired
    public TErpClinicWarehousingController(TErpClinicWarehousingService erpClinicWarehousingService, TErpGoodsService erpGoodsService, TokenService tokenService,
                                             TCrmClinicService crmClinicService,TCrmSupplierService crmSupplierService,TErpClinicWarehousingBatchService erpClinicWarehousingBatchService,
                                           TErpGoodsUnitService erpGoodsUnitService) {
        this.erpClinicWarehousingService = erpClinicWarehousingService;
        this.erpGoodsService = erpGoodsService;
        this.tokenService = tokenService;
        this.crmClinicService = crmClinicService;
        this.crmSupplierService = crmSupplierService;
        this.erpClinicWarehousingBatchService = erpClinicWarehousingBatchService;
        this.erpGoodsUnitService = erpGoodsUnitService;
 
    }
 
 
 
 
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "诊所 获取库存分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TErpGoodsVO>> pageList(@RequestBody TErpGoodsQuery query) {
 
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmSupplier.getId());
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmClinic.getId());
        }
 
        return R.ok(erpClinicWarehousingService.pageList(query,user));
    }
 
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "诊所 获取库存库存不足")
    @PostMapping(value = "/pageNotInventoryGoodsList")
    public R<List<TErpGoodsVO>> pageNotInventoryGoodsList(@RequestBody TErpGoodsQuery query) {
 
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        if(roleType == 4){
            // 供应商
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmSupplier.getId());
        }
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            query.setSupplierClinicId(crmClinic.getId());
        }
 
        return R.ok(erpClinicWarehousingService.pageList1(query,user));
    }
 
 
 
    @ApiOperation(value = "诊所 盘点")
    @PostMapping(value = "/pageInventoryList")
    public R<PageInfo<PageInventoryListVo>> pageInventoryList(@RequestBody TErpInventoryQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        return R.ok(erpClinicWarehousingService.pageInventoryList(query,user));
    }
 
 
 
 
 
    @ApiOperation(value = "诊所 盘点详情")
    @GetMapping(value = "/detailInventory/{id}")
    public R<List<InventoryDetailVo>> detailInventory(@PathVariable String id) {
        SysUser user = tokenService.getLoginUser().getUser();
        return R.ok(erpClinicWarehousingService.detailInventory(id,user));
    }
 
 
 
    @ApiOperation(value = "诊所 盘点 出库 商品选择")
    @PostMapping(value = "/pageInventoryGoodsPageList")
    public R<PageInfo<TErpGoodsInventoryVO>> pageInventoryGoodsPageList(@RequestBody @Valid TErpGoodsInventoryQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        return R.ok(erpGoodsService.pageInventoryGoodsPageList1(query,user));
    }
 
 
 
 
    @ApiOperation(value = "诊所 有效期预警商品选择")
    @GetMapping(value = "/pageInventoryGoodsList")
    public R<List<TErpGoodsInventoryVO>> pageInventoryGoodsList(String warehouseId,@RequestParam(required = false)String batchId) {
        SysUser user = tokenService.getLoginUser().getUser();
        List<TErpGoodsInventoryVO> tErpGoodsInventoryVOS = erpGoodsService.pageInventoryGoodsList1(warehouseId, user);
        if(batchId!=null && !"".equals(batchId)){
            tErpGoodsInventoryVOS = tErpGoodsInventoryVOS.stream().filter(e->e.getId().equals(batchId)).collect(Collectors.toList());
        }
        return R.ok(tErpGoodsInventoryVOS);
    }
 
 
 
 
 
    @ApiOperation(value = "诊所 确认盘点")
    @PostMapping(value = "/inventoryGoods")
    public R<?> inventoryGoods(@RequestBody @Valid InventoryDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        erpGoodsService.inventoryGoods1(dto,user);
        return R.ok();
    }
 
 
 
 
    @ApiOperation(value = "诊所 有效期预警")
    @PostMapping(value = "/validityPeriodWarning")
    public R<PageInfo<ValidityPeriodWarningVo>> validityPeriodWarning(@RequestBody ValidityPeriodWarningQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        PageInfo<ValidityPeriodWarningVo> pageInfo =erpClinicWarehousingService.validityPeriodWarning(query,user);
        return R.ok(pageInfo);
    }
 
 
 
 
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "诊所 入库列表")
    @PostMapping(value = "/warehousePageList")
    public R<PageInfo<TErpClinicWarehousePageListVO>> warehousePageList(@RequestBody TClinicWarehouseQuery query) {
 
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
 
        return R.ok(erpClinicWarehousingService.warehousePageList(query,user,supplierClinicId));
    }
 
 
    @ApiOperation(value = "诊所 入库商品列表")
    @PostMapping(value = "/warehouseGoodsPageList")
    public R<Page<TErpGoods>> warehouseGoodsPageList(@RequestBody TClinicGoodsWarehouseQuery query) {
 
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
 
        return R.ok(erpGoodsService.warehouseGoodsPageList(query,user,supplierClinicId));
    }
 
 
 
    @ApiOperation(value = "诊所 入库商品详情")
    @GetMapping(value = "/warehouseGoodsDetail/{id}")
    public R<WarehouseGoodsDetailVo> warehouseGoodsDetail(@PathVariable String id) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
 
        return R.ok(erpGoodsService.warehouseGoodsDetail(id));
    }
 
 
    @ApiOperation(value = "诊所 出库商品详情")
    @GetMapping(value = "/outboundGoodsDetail/{id}")
    public R<OutboundGoodsDetailVo> outboundGoodsDetail(@PathVariable String id) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
 
        return R.ok(erpGoodsService.outboundGoodsDetail(id));
    }
 
    @ApiOperation(value = "诊所 入库商品操作")
    @PostMapping(value = "/warehouseGoods")
    public R<?> warehouseGoods(@RequestBody @Valid WarehouseGoodsDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
        erpClinicWarehousingService.warehouseGoods(dto,user,supplierClinicId);
        return R.ok();
    }
    @ApiOperation(value = "诊所 获取草稿")
    @GetMapping(value = "/getWarehouseGoodsDraft")
    public R<List<TErpClinicWarehousingBatch>> getWarehouseGoodsDraft() {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        ArrayList<TErpClinicWarehousingBatch> clinicWarehouseGoodsDtos = new ArrayList<>();
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
            List<TErpClinicWarehousing> list = erpClinicWarehousingService.list(new LambdaQueryWrapper<TErpClinicWarehousing>().eq(TErpClinicWarehousing::getClinicId, supplierClinicId).eq(TErpClinicWarehousing::getStatus, 1).orderByDesc(BaseModel::getCreateTime));
            if(list.isEmpty()){
                return R.ok(clinicWarehouseGoodsDtos);
            }
            List<TErpClinicWarehousingBatch> list1 = erpClinicWarehousingBatchService.list(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getWarehousingId, list.get(0).getId()));
            for (TErpClinicWarehousingBatch tErpClinicWarehousingBatch : list1) {
                String goodsId = tErpClinicWarehousingBatch.getGoodsId();
                TErpGoods tErpGoods = erpGoodsService.getOne(new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getId, goodsId));
                TErpGoodsUnit byId = erpGoodsUnitService.getById(tErpGoods.getPackingUnitId());
                tErpClinicWarehousingBatch.setUnitName(byId.getUnitName());
            }
            return R.ok(list1);
        }
        return R.ok(clinicWarehouseGoodsDtos);
    }
 
 
 
 
 
    /**
     * 获取erp问题上报管理列表
     */
    @ApiOperation(value = "诊所 出库列表")
    @PostMapping(value = "/outboundPageList")
    public R<PageInfo<TErpClinicOutboundPageListVO>> outboundPageList(@RequestBody TClinicOutboundQuery query) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
 
        return R.ok(erpClinicWarehousingService.outboundPageList(query,user,supplierClinicId));
    }
 
 
    @ApiOperation(value = "诊所 出库商品操作")
    @PostMapping(value = "/outboundGoods")
    public R<?> outboundGoods(@RequestBody @Valid ClinicOutboundGoodsDto dto) {
        SysUser user = tokenService.getLoginUser().getUser();
        Integer roleType = user.getRoleType();
        String supplierClinicId =null;
        if(roleType == 5){
            // 诊所
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, user.getUserId())
                    .last("LIMIT 1"));
            supplierClinicId = crmClinic.getId();
        }
        erpClinicWarehousingService.outboundGoods(dto,user,supplierClinicId);
        return R.ok();
    }
 
 
}