李林
2023-08-09 eaf8534802ba41c3db61989aafedf842362b64ea
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.yuanchu.mom.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.pojo.dto.vo.SaleVo;
import com.yuanchu.mom.utils.JackSonUtil;
import org.json.JSONException;
import org.json.JSONObject;
import com.yuanchu.mom.pojo.dto.SaleDto;
import com.yuanchu.mom.service.SaleService;
import com.yuanchu.mom.utils.Jwt;
import com.yuanchu.mom.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * <p>
 * 销售单 前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-08-08
 */
@Api(tags = "销售管理")
@RestController
@RequestMapping("/sale")
public class SaleController {
 
    @Resource
    SaleService saleService;
 
    @Resource
    Jwt jwt;
 
    @ApiOperation(value = "查询销售单列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageSize", value = "页数", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "countSize", value = "条数/页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "orderNumber", value = "订单编号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "产品名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "状态(为空=全部)", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "delTime", value = "交货日期", dataTypeClass = String.class)
    })
    @GetMapping("/selectSaleList")
    public Result selectSaleList(Integer pageSize, Integer countSize, String orderNumber, String name, Integer type, String delTime) {
        IPage<Map<String, Object>> salePage = saleService.selectSaleList(new Page<Object>(pageSize, countSize), orderNumber, name, type, delTime);
        Map<String, Object> map = new HashMap<>();
        map.put("total", salePage.getTotal());
        map.put("row", salePage.getRecords());
        return Result.success(map);
    }
 
    @ApiOperation(value = "新增销售单")
    @PostMapping("/addSale")
    public Result addSale(@RequestHeader("token") String token, @RequestBody SaleDto saleDto) throws Exception {
        Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
        saleService.addSale(data.get("name").replaceAll("\"", ""), saleDto);
        return Result.success("新增成功!");
    }
 
    @ApiOperation(value = "根据销售单id查看详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "销售单id", dataTypeClass = Integer.class, required = true)
    })
    @GetMapping("/selectSaleDatilById")
    public Result selectSaleDatil(Integer id) {
        return Result.success(saleService.selectSaleDatil(id));
    }
 
    @ApiOperation(value = "根据销售单id修改详情信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "销售单id", dataTypeClass = Integer.class, required = true)
    })
    @PostMapping("/updateSaleById")
    public Result updateSaleById(@RequestHeader("token") String token, Integer id, @RequestBody SaleVo saleVo) throws JSONException {
        Map<String, String> map = jwt.readJWT(token);
        String data = map.get("data");
        JSONObject jsonObject = new JSONObject(data);
        String saleman = jsonObject.getString("name");
        saleService.updateSaleById(saleman,id, saleVo);
        return Result.success("修改成功!");
    }
 
    @ApiOperation(value = "根据销售单id删除")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "销售单id", dataTypeClass = Integer.class, required = true)
    })
    @PostMapping("/delSale")
    public Result delSale(Integer id) {
        saleService.delSale(id);
        return Result.success();
    }
 
    @ApiOperation(value = "批量删除")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ids", value = "销售单id", dataTypeClass = String.class, dataType = "List", required = true)
    })
    @PostMapping("/delAllSale")
    public Result delAllSale( List<Integer> ids) {
        saleService.delAllSale(ids);
        return Result.success();
    }
 
    @ApiOperation(value = "审核")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "销售单id", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "type", value = "状态", dataTypeClass = Integer.class, required = true)
    })
    @PostMapping("/check")
    public Result check(@RequestHeader("token") String token,Integer id,Integer type) throws JSONException {
        Map<String, String> map = jwt.readJWT(token);
        String data = map.get("data");
        JSONObject jsonObject = new JSONObject(data);
        String checkname = jsonObject.getString("name");
        saleService.check(checkname,id,type);
        return Result.success("审核成功");
    }
 
 
}