goupan
2024-04-29 dd6313419318b1e544ddb0f5a3385bb905fc6cf0
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
156
157
158
159
160
161
162
163
package cn.stylefeng.rest.modular.user.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.modular.business.entity.CounsellingInfo;
import cn.stylefeng.guns.modular.business.entity.CounsellingOrderReservation;
import cn.stylefeng.guns.modular.business.entity.Course;
import cn.stylefeng.guns.modular.business.entity.UserEvaluate;
import cn.stylefeng.guns.modular.business.service.*;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.alibaba.druid.sql.visitor.functions.If;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 用户评价表管理类
 * @author guo
 */
@RestController
@Api(tags = "用户评价")
@ApiResource(name = "用户评价", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping
public class UserEvaluateController {
 
    @Resource
    private IUserEvaluateService userEvaluateService;
 
    @Resource
    private ICourseService courseService;
 
    @Resource
    private ICounsellingInfoService counsellingInfoService;
 
    @Resource
    private CustomerService customerService;
 
 
 
    /**
     * 添加用户评价表
     */
    @ApiOperation("添加用户评价表")
    @PostResource(name = "添加用户评价表", path = "/userEvaluate/add")
    public ResponseData<?> add(@RequestBody UserEvaluate userEvaluate) {
        userEvaluate.setCreateTime(new Date());
        userEvaluate.setUpdateTime(new Date());
        if (userEvaluate.getUserId() == null){
            userEvaluate.setUserId(LoginContext.me().getLoginUser().getUserId());
        }
        this.userEvaluateService.save(userEvaluate);
        //查询评价评分
        Map<String,Object> map = this.userEvaluateService.getMap(new QueryWrapper<UserEvaluate>().select(" IFNULL(AVG(score),0) score ").lambda().eq(UserEvaluate::getBuinessId,userEvaluate.getBuinessId())
                .eq(UserEvaluate::getBuinessType,userEvaluate.getBuinessType()).eq(UserEvaluate::getIsDelete,false));
        if (map != null){
        //计算对应评分 业务类型 1-课程,2-咨询
            if (userEvaluate.getBuinessType().intValue() ==1){
                if (map.get("score") != null){
                    this.courseService.update(new LambdaUpdateWrapper<Course>().set(Course::getTotalScore,map.get("score")).eq(Course::getId,userEvaluate.getBuinessId()));
                }
            }else if (userEvaluate.getBuinessType().intValue() == 2){
                if (map.get("score") != null){
                    this.counsellingInfoService.update(new LambdaUpdateWrapper<CounsellingInfo>().set(CounsellingInfo::getTotalScore,map.get("score")).eq(CounsellingInfo::getId,userEvaluate.getBuinessId()));
                }
            }
        }
        return new SuccessResponseData<>();
    }
 
 
 
    /**
     * 修改用户评价表
     */
    @ApiOperation("修改用户评价表")
    @PostResource(name = "修改用户评价表", path = "/userEvaluate/edit")
    public ResponseData<?> edit(@RequestBody UserEvaluate userEvaluate) {
        this.userEvaluateService.updateById(userEvaluate);
        //判断是否有修改评分
        if (userEvaluate.getScore() != null){
            //查询评价评分
            Map<String,Object> map = this.userEvaluateService.getMap(new QueryWrapper<UserEvaluate>().select(" IFNULL(AVG(score),0) score ").lambda().eq(UserEvaluate::getBuinessId,userEvaluate.getBuinessId())
                    .eq(UserEvaluate::getBuinessType,userEvaluate.getBuinessType()).eq(UserEvaluate::getIsDelete,false));
            if (map != null){
                //计算对应评分 业务类型 1-课程,2-咨询
                if (userEvaluate.getBuinessType().intValue() ==1){
                    if (map.get("score") != null){
                        this.courseService.update(new LambdaUpdateWrapper<Course>().set(Course::getTotalScore,map.get("score")).eq(Course::getId,userEvaluate.getBuinessId()));
                    }
                }else if (userEvaluate.getBuinessType().intValue() == 2){
                    if (map.get("score") != null){
                        this.counsellingInfoService.update(new LambdaUpdateWrapper<CounsellingInfo>().set(CounsellingInfo::getTotalScore,map.get("score")).eq(CounsellingInfo::getId,userEvaluate.getBuinessId()));
                    }
                }
            }
        }
 
 
        return new SuccessResponseData<>();
    }
 
 
 
 
 
    /**
     * 获取用户评价表列表(分页)
     */
 
    @ApiOperation(value = "获取用户评价表列表(分页)")
    @GetResource(name = "获取用户评价表列表(分页)", path = "/userEvaluate/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "buinessType", value = "业务类型 1-课程,2-咨询", dataTypeClass = Integer.class, paramType = "query"),
            @ApiImplicitParam(name = "buinessId", value = "业务id 课程id或咨询人员id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "评价用户id(查询自己的评价时候使用)", dataTypeClass = Long.class, paramType = "query"),
    })
    public ResponseData<PageResult<UserEvaluate>> page(Integer pageNo, Integer pageSize, Integer buinessType, Long buinessId,Long userId) {
        LambdaQueryWrapper<UserEvaluate> lambdaQueryWrapper = new LambdaQueryWrapper<UserEvaluate>().eq(UserEvaluate::getIsDelete,false)
                    .orderByDesc(UserEvaluate::getUpdateTime);
        lambdaQueryWrapper.eq(buinessType != null,UserEvaluate::getBuinessType,buinessType);
        lambdaQueryWrapper.eq(buinessId != null,UserEvaluate::getBuinessId,buinessId);
        lambdaQueryWrapper.eq(userId != null,UserEvaluate::getUserId,userId);
        Page<UserEvaluate> page = this.userEvaluateService.page(PageFactory.defaultPage(), lambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            page.getRecords().forEach(userEvaluate -> {
                Customer customer = this.customerService.getById(userEvaluate.getUserId());
                if (customer != null){
                    userEvaluate.setAvatar(customer.getAvatarObjectName());
                    userEvaluate.setNickName(customer.getNickName());
                }
            });
        }
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
}