zxl
9 天以前 0fb6b9d8d414822668c401a2b507df1fe6d1fa2d
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
package cn.lili.controller.settings;
 
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.OperationalJudgment;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.store.entity.vos.FreightTemplateVO;
import cn.lili.modules.store.service.FreightTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.List;
import java.util.Objects;
 
/**
 * 店铺端,运费模板接口
 *
 * @author paulG
 * @since 2020/8/26
 **/
@RestController
@Api(tags = "店铺端,运费模板接口")
@RequestMapping("/store/setting/freightTemplate")
public class FreightTemplateStoreController {
    @Autowired
    private FreightTemplateService freightTemplateService;
 
    @ApiOperation(value = "商家运费模板列表")
    @GetMapping
    public ResultMessage<List<FreightTemplateVO>> list() {
        String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
        return ResultUtil.data(freightTemplateService.getFreightTemplateList(storeId));
    }
 
    @ApiOperation(value = "获取商家运费模板详情")
    @ApiImplicitParam(name = "id", value = "商家模板ID", required = true, paramType = "path")
    @GetMapping("/{id}")
    public ResultMessage<FreightTemplateVO> list(@PathVariable String id) {
        FreightTemplateVO freightTemplate = OperationalJudgment.judgment(freightTemplateService.getFreightTemplate(id));
        return ResultUtil.data(freightTemplate);
    }
 
    @ApiOperation(value = "添加商家运费模板")
    @PostMapping
    public ResultMessage<FreightTemplateVO> add(@Valid @RequestBody FreightTemplateVO freightTemplateVO) {
        String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
        freightTemplateVO.setStoreId(storeId);
        return ResultUtil.data(freightTemplateService.addFreightTemplate(freightTemplateVO));
    }
 
    @ApiOperation(value = "修改商家运费模板")
    @PutMapping("/{id}")
    public ResultMessage<FreightTemplateVO> edit(@PathVariable String id, @RequestBody @Valid FreightTemplateVO freightTemplateVO) {
        OperationalJudgment.judgment(freightTemplateService.getFreightTemplate(id));
        return ResultUtil.data(freightTemplateService.editFreightTemplate(freightTemplateVO));
    }
 
    @ApiOperation(value = "删除商家运费模板")
    @ApiImplicitParam(name = "id", value = "商家模板ID", required = true, paramType = "path")
    @DeleteMapping("/{id}")
    public ResultMessage<Object> edit(@PathVariable String id) {
        OperationalJudgment.judgment(freightTemplateService.getFreightTemplate(id));
        freightTemplateService.removeFreightTemplate(id);
        return ResultUtil.success();
    }
}