cloudroam
2024-12-06 4ecc52d0f6558cbbcec1c86647c9dba04ac66b7d
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
151
152
153
154
155
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.base.annotation.OperationLog;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.dto.request.comment.*;
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.entity.log.OperationRecord;
import com.mzl.flower.entity.payment.Order;
import com.mzl.flower.service.comment.FlowerCommentService;
import com.mzl.flower.service.payment.OrderService;
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;
 
    @Autowired
    private OrderService orderService;
 
    @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}")
    @OperationLog(value = "评价删除",type = "flower_comment")
    @ApiOperation(value = "删除", notes = "删除")
    public ResponseEntity<ReturnDataDTO> delete(@PathVariable String id) {
 
        FlowerCommentDO flowerCommentDO = flowerCommentService.getById(id);
        if (null == flowerCommentDO) {
            throw new ValidationException("评论不存在");
        }
        flowerCommentService.deleteFlowerComment(id);
        Order order = orderService.getOrderInfoById(flowerCommentDO.getOrderId());
        String content = "评价删除id:【" + id + "】,订单编号【" + order.getOrderNo() + "】,供应商id:【" + flowerCommentDO.getSupplierId() + "】,评价内容:【" + flowerCommentDO.getComment() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
    @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));
    }
 
    @PutMapping("/show/{id}")
    @ApiOperation(value = "显示/隐藏", notes = "显示/隐藏")
    public ResponseEntity<ReturnDataDTO> updateShow(@PathVariable String id,@Validated @RequestBody ShowFlowerCommentDTO dto) {
 
        // 手动设置id值
        dto.setId(id);
        flowerCommentService.updateShowFlowerComment(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @PutMapping("/replay/{id}")
    @ApiOperation(value = "评论回复", notes = "评论回复")
    public ResponseEntity<ReturnDataDTO> updateReplay(@PathVariable String id,@Validated @RequestBody ReplayFlowerCommentDTO dto) {
 
        // 手动设置id值
        dto.setId(id);
        flowerCommentService.updateReplayFlowerComment(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    private void valid(CreateFlowerCommentDTO dto){
 
    }
 
}