Commit d09ff45c by 胡学良

添加意见反馈和投诉举报功能

parent dbc0e054
package cn.meteor.beyondclouds.modules.feedback.api;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.modules.feedback.entity.Feedback;
import cn.meteor.beyondclouds.modules.feedback.exception.FeedbackServiceException;
import cn.meteor.beyondclouds.modules.feedback.form.ComplaintForm;
import cn.meteor.beyondclouds.modules.feedback.form.FeedbackForm;
import cn.meteor.beyondclouds.modules.feedback.service.IFeedbackService;
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.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
......@@ -25,42 +31,59 @@ import javax.validation.Valid;
*/
@Api(tags = "反馈API")
@RestController
@RequestMapping("/api/")
@RequestMapping("/api")
public class FeedbackApi {
private IFeedbackService feedbackService;
@Autowired
public FeedbackApi(IFeedbackService feedbackService) {
this.feedbackService = feedbackService;
}
/**
* 意见反馈
* @param feedbackForm
* @param bindingResult
* @return
*/
@Anonymous
@PostMapping("/feedback")
@ApiOperation("意见反馈")
private Response feedback(@Valid FeedbackForm feedbackForm, BindingResult bindingResult) {
public Response feedback(@RequestBody @Valid FeedbackForm feedbackForm, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return Response.fieldError(bindingResult.getFieldError());
}
// TODO 实现反馈功能
Feedback feedback = new Feedback();
BeanUtils.copyProperties(feedbackForm, feedback);
try {
feedbackService.feedback(feedback, feedbackForm.getVerifyCode());
return Response.success();
} catch (FeedbackServiceException e) {
return Response.error(e);
}
}
/**
* 意见反馈
* 投诉举报
* @param complaintForm
* @param bindingResult
* @return
*/
@Anonymous
@PostMapping("/complaint")
@ApiOperation("投诉举报")
private Response feedback(@Valid ComplaintForm complaintForm, BindingResult bindingResult) {
public Response complaint(@RequestBody @Valid ComplaintForm complaintForm, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return Response.fieldError(bindingResult.getFieldError());
}
// TODO 实现投诉举报功能
Feedback complaint = new Feedback();
BeanUtils.copyProperties(complaintForm, complaint);
feedbackService.complaint(complaint);
return Response.success();
}
......
......@@ -30,7 +30,7 @@ public class Feedback implements Serializable {
private Integer feedbackId;
@ApiModelProperty(value = "反馈类型,1-反馈,2-举报")
private Boolean feedbackType;
private Integer feedbackType;
private String feedbackReason;
......
package cn.meteor.beyondclouds.modules.feedback.enums;
import cn.meteor.beyondclouds.core.IErrorCode;
/**
* @author 胡学良
* @since 2020/2/14
*/
public enum FeedBackErrorCode implements IErrorCode {
;
private long code;
private String msg;
FeedBackErrorCode(long code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public long code() {
return 0;
}
@Override
public String msg() {
return null;
}
}
package cn.meteor.beyondclouds.modules.feedback.exception;
import cn.meteor.beyondclouds.core.IErrorCode;
import cn.meteor.beyondclouds.core.exception.ServiceException;
/**
* @author 胡学良
* @since 2020/2/14
*/
public class FeedbackServiceException extends ServiceException {
public FeedbackServiceException(long errorCode, String errorMsg) {
super(errorCode, errorMsg);
}
public FeedbackServiceException(IErrorCode errorCode) {
super(errorCode);
}
}
package cn.meteor.beyondclouds.modules.feedback.form;
import cn.meteor.beyondclouds.core.constant.RegexPatterns;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
/**
* 投诉举报
* @author meteor
......@@ -19,6 +23,7 @@ public class ComplaintForm {
* 内容侵权
* 其它
*/
@NotEmpty(message = "举报原因不能为空")
private String feedbackReason;
/**
......@@ -29,6 +34,7 @@ public class ComplaintForm {
/**
* 要举报的链接(必填)
*/
@NotEmpty(message = "举报链接不能为空")
private String link;
/**
......
package cn.meteor.beyondclouds.modules.feedback.form;
import cn.meteor.beyondclouds.core.constant.RegexPatterns;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* 意见反馈
* @author meteor
......@@ -16,11 +21,13 @@ public class FeedbackForm {
* 功能提议
* 其它
*/
@NotEmpty(message = "反馈类型不能为空")
private String feedbackReason;
/**
* 反馈描述
*/
@NotEmpty(message = "反馈信息不能为空")
private String content;
/**
......@@ -31,11 +38,14 @@ public class FeedbackForm {
/**
* 反馈人手机号(必填,还得通过验证码验证才行)
*/
@NotEmpty(message = "手机号不能为空")
@Pattern(regexp = RegexPatterns.MOBILE, message = "手机号格式不正确")
private String mobile;
/**
* 验证码
*/
@NotEmpty(message = "验证码不能为空")
private String verifyCode;
}
package cn.meteor.beyondclouds.modules.feedback.service;
import cn.meteor.beyondclouds.modules.feedback.entity.Feedback;
import cn.meteor.beyondclouds.modules.feedback.exception.FeedbackServiceException;
import com.baomidou.mybatisplus.extension.service.IService;
/**
......@@ -13,4 +14,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IFeedbackService extends IService<Feedback> {
/**
*意见反馈
* @param feedback
* @param verifyCode
* @throws FeedbackServiceException
*/
void feedback(Feedback feedback, String verifyCode) throws FeedbackServiceException;
/**
* 投诉举报
* @param complaint
*/
void complaint(Feedback complaint);
}
package cn.meteor.beyondclouds.modules.feedback.service.impl;
import cn.meteor.beyondclouds.common.helper.IRedisHelper;
import cn.meteor.beyondclouds.core.redis.RedisKey;
import cn.meteor.beyondclouds.modules.feedback.entity.Feedback;
import cn.meteor.beyondclouds.modules.feedback.exception.FeedbackServiceException;
import cn.meteor.beyondclouds.modules.feedback.mapper.FeedbackMapper;
import cn.meteor.beyondclouds.modules.feedback.service.IFeedbackService;
import cn.meteor.beyondclouds.modules.user.enums.UserErrorCode;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
......@@ -17,4 +24,37 @@ import org.springframework.stereotype.Service;
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements IFeedbackService {
private IRedisHelper redisHelper;
@Autowired
public FeedbackServiceImpl(IRedisHelper redisHelper) {
this.redisHelper = redisHelper;
}
@Override
public void feedback(Feedback feedback, String verifyCode) throws FeedbackServiceException {
//1.检查验证码是否正确
String realVerifyCode = redisHelper.get(RedisKey.MOBILE_VERIFY_CODE(feedback.getMobile()));
if (StringUtils.isEmpty(realVerifyCode) || !realVerifyCode.equals(verifyCode)) {
throw new FeedbackServiceException(UserErrorCode.REG_VERIFY_CODE_ERROR);
}
// 删除验证码
redisHelper.del(RedisKey.MOBILE_VERIFY_CODE(feedback.getMobile()));
//2.设置反馈类型,1-反馈,2-举报
feedback.setFeedbackType(1);
//3.保存意见反馈信息
save(feedback);
}
@Override
public void complaint(Feedback complaint) {
//1.设置反馈类型,1-反馈,2-举报
complaint.setFeedbackType(2);
//2.保存投诉举报信息
save(complaint);
}
}
......@@ -4,7 +4,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 100Centa30821%mysql
password: 197442
# 邮箱
mail:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment