xuhy
1 天以前 26e6eefcf5f897a5ed01a36c853d8948e0d9b48d
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
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.TOrderStock;
import com.ruoyi.system.domain.TOrderStockGoods;
import com.ruoyi.system.dto.TOrderStockDTO;
import com.ruoyi.system.query.TOrderStockQuery;
import com.ruoyi.system.service.TOrderStockGoodsService;
import com.ruoyi.system.service.TOrderStockService;
import com.ruoyi.system.vo.TOrderStockVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 进货单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-14
 */
@Api(tags = "进货单")
@RestController
@RequestMapping("/t-order-stock")
public class TOrderStockController {
    private final TOrderStockService orderStockService;
    private final TOrderStockGoodsService orderStockGoodsService;
    private final TokenService tokenService;
 
    @Autowired
    public TOrderStockController(TOrderStockService orderStockService, TOrderStockGoodsService orderStockGoodsService, TokenService tokenService) {
        this.orderStockService = orderStockService;
        this.orderStockGoodsService = orderStockGoodsService;
        this.tokenService = tokenService;
    }
 
    /**
     * 查询进货单分页列表
     */
    @ApiOperation( value = "查询进货单分页列表")
    @PostMapping(value = "/pageList")
    public AjaxResult<PageInfo<TOrderStockVO>> pageList(@RequestBody TOrderStockQuery query) {
        query.setShopId(tokenService.getLoginUser().getObjectId());
        query.setIsCover(1);
        return AjaxResult.success(orderStockService.pageList(query));
    }
 
    /**
     * 进货单下单接口
     */
    @ApiOperation( value = "进货单下单接口")
    @PostMapping(value = "/add")
    public AjaxResult<String> add(@RequestBody TOrderStockDTO dto) {
        dto.setShopId(tokenService.getLoginUser().getObjectId());
        orderStockService.add(dto);
        return AjaxResult.success();
    }
 
    /**
     * 编辑进货单下单接口
     */
    @ApiOperation( value = "编辑进货单下单接口")
    @PostMapping(value = "/edit")
    public AjaxResult<String> edit(@RequestBody TOrderStockDTO dto) {
        orderStockService.edit(dto);
        return AjaxResult.success();
    }
 
    /**
     * 编辑进货单下单接口
     */
    @ApiOperation( value = "编辑生成进货单接口")
    @PostMapping(value = "/editGenerator")
    public AjaxResult<String> editGenerator(@RequestBody TOrderStockDTO dto) {
        orderStockService.editGenerator(dto);
        return AjaxResult.success();
    }
 
    /**
     * 查看进货单详情
     */
    @ApiOperation( value = "查看进货单详情")
    @GetMapping(value = "/getDetailById")
    public AjaxResult<TOrderStockVO> getDetailById(@RequestParam("id") Long id) {
        TOrderStock orderStock = orderStockService.getById(id);
        TOrderStockVO orderStockVO = new TOrderStockVO();
        BeanUtils.copyProperties(orderStock, orderStockVO);
        // 查询进货单商品
        List<TOrderStockGoods> list = orderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class)
                .eq(TOrderStockGoods::getOrderId, id));
        orderStockVO.setOrderStockGoods(list);
        return AjaxResult.success(orderStockVO);
    }
 
    /**
     * 删除进货单
     */
    @Log(title = "进货单-删除进货单", businessType = BusinessType.DELETE)
    @ApiOperation( value = "删除进货单")
    @DeleteMapping(value = "/deleteById")
    public AjaxResult<Boolean> deleteById(@RequestParam("id") Long id) {
        // 删除进货商品
        orderStockGoodsService.remove(Wrappers.lambdaQuery(TOrderStockGoods.class)
                .eq(TOrderStockGoods::getOrderId, id));
        return AjaxResult.success(orderStockService.removeById(id));
    }
 
    /**
     * 批量删除进货单
     */
    @ApiOperation( value = "批量删除进货单")
    @DeleteMapping(value = "/deleteByIds")
    public AjaxResult<Boolean> deleteByIds(@RequestBody List<Long> ids) {
        orderStockGoodsService.remove(Wrappers.lambdaQuery(TOrderStockGoods.class)
                .in(TOrderStockGoods::getOrderId, ids));
        return AjaxResult.success(orderStockService.removeByIds(ids));
    }
 
}