gongzuming
2024-10-09 3dc4aac8aec62f2c2a1e4af699e622ac9dfaba59
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
package com.mzl.flower.web.v2.comment;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.dto.request.comment.CreateFlowerCommentBatchDTO;
import com.mzl.flower.dto.request.comment.CreateFlowerCommentDTO;
import com.mzl.flower.dto.request.comment.QueryFlowerCommentDTO;
import com.mzl.flower.dto.request.comment.UpdateFlowerCommentDTO;
import com.mzl.flower.dto.response.comment.FlowerCommentVO;
import com.mzl.flower.dto.response.coupon.CouponTemplatePointVO;
import com.mzl.flower.dto.response.coupon.CouponTemplateVO;
import com.mzl.flower.service.comment.FlowerCommentService;
import com.mzl.flower.utils.ConverterUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.mzl.flower.entity.FlowerCommentDO;
 
 
/**
 * 商品评论表前端控制器
 *
* @author @TaoJie
* @since 2024-09-29
*/
@RestController
@RequestMapping("/api/v2/flower-comment")
@Api(value = "商品评论", tags = "商品评论")
@Validated
public class FlowerCommentController extends BaseController {
 
    @Autowired
    private FlowerCommentService flowerCommentService;
 
    @PostMapping("")
    @ApiOperation(value = "新增", notes = "新增")
    public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateFlowerCommentDTO dto) {
 
        // 信息验证
        valid(dto);
        flowerCommentService.createFlowerComment(dto);
        return returnData(R.SUCCESS.getCode(), null);
 
 
    }
 
    @PostMapping("/batch")
    @ApiOperation(value = "批量新增", notes = "批量新增")
    public ResponseEntity<ReturnDataDTO> createBatch(@Validated @RequestBody CreateFlowerCommentBatchDTO dto) {
 
        //
        flowerCommentService.createFlowerCommentBatch(dto);
        return returnData(R.SUCCESS.getCode(), null);
 
 
    }
 
    @PutMapping("/{id}")
    @ApiOperation(value = "修改", notes = "修改")
    public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody UpdateFlowerCommentDTO dto) {
 
        // 手动设置id值
        dto.setId(id);
        flowerCommentService.updateFlowerComment(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除", notes = "删除")
    public ResponseEntity<ReturnDataDTO> delete(@PathVariable String id) {
 
        FlowerCommentDO flowerCommentDO = flowerCommentService.getById(id);
        if (null == flowerCommentDO) {
            throw new ValidationException("评论不存在");
        }
        flowerCommentService.deleteFlowerComment(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping("/{id}")
    @ApiOperation(value = "详情", notes = "详情")
    public ResponseEntity<ReturnDataDTO> get(@PathVariable String id) {
        FlowerCommentVO flowerCommentVO = flowerCommentService.getDetailById(id);
        return returnData(R.SUCCESS.getCode(), ConverterUtil.transObject(flowerCommentVO, FlowerCommentVO.class));
    }
 
    @GetMapping("/page")
    @ApiOperation(value = "查询-分页", notes = "查询-分页")
    public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> page(Page page, QueryFlowerCommentDTO dto) {
        // 设置只查询活动优惠券的
 
        Page<FlowerCommentVO> resultPage = flowerCommentService.getPage(page, dto);
        return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, FlowerCommentVO.class));
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "查询-全部", notes = "查询-全部")
    public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> list(QueryFlowerCommentDTO dto) {
        // 设置只查询活动优惠券的
 
        return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(flowerCommentService.getList(dto), FlowerCommentVO.class));
    }
 
    @GetMapping("/avg/{id}")
    @ApiOperation(value = "平均分", notes = "平均分")
    public ResponseEntity<ReturnDataDTO> getCommentAvg(@PathVariable Long id) {
        return returnData(R.SUCCESS.getCode(), flowerCommentService.getSupplierAvgScore(id));
    }
 
    @GetMapping("/statis/{id}")
    @ApiOperation(value = "统计", notes = "统计")
    public ResponseEntity<ReturnDataDTO> getStatis(@PathVariable Long id) {
        return returnData(R.SUCCESS.getCode(), flowerCommentService.getSupplierStatis(id));
    }
 
    private void valid(CreateFlowerCommentDTO dto){
 
    }
 
}