zhanghua
2023-03-14 feffedd3a450e935debea24599cb5ce2f4c06ab2
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
package com.ycl.controller.store;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.annotation.LogSave;
import com.ycl.api.CommonPage;
import com.ycl.api.CommonResult;
import com.ycl.common.util.UtilNumber;
import com.ycl.dto.store.UmsStoreInfoParam;
import com.ycl.entity.store.StoreInfo;
import com.ycl.entity.store.StoreScore;
import com.ycl.service.store.StoreInfoService;
import com.ycl.service.video.impl.IVideoPointService;
import com.ycl.vo.store.StoreInfoVO;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyq
 * @since 2022-09-08
 */
@RestController
@RequestMapping("/store/storeinfo")
@Api(tags = "门店管理")
public class StoreInfoController {
    private StoreInfoService storeInfoService;
 
    @Autowired
    UtilNumber utilNumber;
 
    @Autowired
    private IVideoPointService videoPointService;
 
 
    @Autowired
    public void setUmsStoreInfoService(StoreInfoService umsStoreInfoService) {
        this.storeInfoService = umsStoreInfoService;
    }
 
    @ApiOperation("根据门店名称分页获取门店列表列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "查询门店")
    public CommonResult<CommonPage<StoreInfoVO>> list(@RequestParam(value = "keyword", required = false) String keyword,
                                                      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "status", required = false) String status
    ) {
        Page<StoreInfoVO> storeInfoPage = storeInfoService.list(keyword, pageSize, pageNum,status);
        return CommonResult.success(CommonPage.restPage(storeInfoPage));
    }
 
    @ApiOperation("根据id获取门店信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "查询门店")
    public CommonResult<StoreInfoVO> getItem(@PathVariable Long id) {
        StoreInfo storeInfo = storeInfoService.getById(id);
        StoreInfoVO vo = new StoreInfoVO();
        BeanUtils.copyProperties(storeInfo, vo);
        vo.setVideoPoint(videoPointService.getById(storeInfo.getVideoId()));
        return CommonResult.success(vo);
    }
 
    @ApiOperation(value = "添加门店信息")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "添加门店")
    public CommonResult<StoreInfo> add(@Validated @RequestBody UmsStoreInfoParam umsStoreInfoParam) {
        StoreInfo storeInfo = StoreInfo.builder()
                .owner(umsStoreInfoParam.getOwner())
                .storeName(umsStoreInfoParam.getStoreName())
                .contact(umsStoreInfoParam.getContact())
                .storeAddress(umsStoreInfoParam.getStoreAddress())
                .storePhoto(umsStoreInfoParam.getStorephoto())
                .idCardInfo(umsStoreInfoParam.getIdcardinfo())
                .storeNumber(utilNumber.createShopCode())
                .type(umsStoreInfoParam.getType())
                .description(umsStoreInfoParam.getDescription())
                .videoId(umsStoreInfoParam.getRelationVideo())
                .storeScore(100.0)
                .status(umsStoreInfoParam.getStatus())
                .build();
        boolean success = storeInfoService.save(storeInfo);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }
 
    @ApiOperation(value = "根据id删除门店信息")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "删除门店")
    public CommonResult delete(@PathVariable Long id) {
        boolean success = storeInfoService.removeById(id);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }
 
    @ApiOperation(value = "修改门店信息")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "修改门店")
    public CommonResult update(@RequestBody StoreInfo storeInfo) {
        boolean success = storeInfoService.updateById(storeInfo);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }
 
    @ApiOperation(value = "根据excel模板批量导入门店信息")
    @RequestMapping(value = "/add/excel", method = RequestMethod.POST)
    @ResponseBody
    @LogSave(operationType = "门店管理", contain = "导入门店")
    public CommonResult addByExcel(MultipartFile file) {
        boolean success = storeInfoService.addByExcel(file);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }
 
    @ApiOperation("根据id获取门店积分详情")
    @RequestMapping(value = "/{id}/storeScore", method = RequestMethod.GET)
    @ResponseBody
    @LogSave(operationType = "门店积分详情", contain = "门店积分详情")
    public CommonResult<Page<StoreScore>> getScoreList(@PathVariable Long id,
                                                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<StoreScore> page = storeInfoService.getScoreList(id, pageSize, pageNum);
        return CommonResult.success(page);
    }
}