Commit 04e9bbb8 authored by usgeek's avatar usgeek Committed by linlinjava
Browse files

小程序后端意见反馈实现

parent 19e3167f
package org.linlinjava.litemall.db.dao;
import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallFeedback;
import org.linlinjava.litemall.db.domain.LitemallFeedbackExample;
import java.util.List;
public interface LitemallFeedbackMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
long countByExample(LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int deleteWithVersionByExample(@Param("version") Integer version, @Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int deleteByExample(LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int deleteWithVersionByPrimaryKey(@Param("version") Integer version, @Param("key") Integer key);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int insert(LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int insertSelective(LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallFeedback selectOneByExample(LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallFeedback selectOneByExampleSelective(@Param("example") LitemallFeedbackExample example, @Param("selective") LitemallFeedback.Column... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<LitemallFeedback> selectByExampleSelective(@Param("example") LitemallFeedbackExample example, @Param("selective") LitemallFeedback.Column... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
List<LitemallFeedback> selectByExample(LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallFeedback selectByPrimaryKeySelective(@Param("id") Integer id, @Param("selective") LitemallFeedback.Column... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
LitemallFeedback selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
LitemallFeedback selectByPrimaryKeyWithLogicalDelete(@Param("id") Integer id, @Param("andLogicalDeleted") boolean andLogicalDeleted);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int updateWithVersionByExample(@Param("version") Integer version, @Param("record") LitemallFeedback record, @Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int updateWithVersionByExampleSelective(@Param("version") Integer version, @Param("record") LitemallFeedback record, @Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") LitemallFeedback record, @Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int updateByExample(@Param("record") LitemallFeedback record, @Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int updateWithVersionByPrimaryKey(@Param("version") Integer version, @Param("record") LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int updateWithVersionByPrimaryKeySelective(@Param("version") Integer version, @Param("record") LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
*/
int updateByPrimaryKey(LitemallFeedback record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByExample(@Param("example") LitemallFeedbackExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_feedback
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByPrimaryKey(Integer id);
}
\ No newline at end of file
package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallFeedbackMapper;
import org.linlinjava.litemall.db.domain.LitemallFeedback;
import org.linlinjava.litemall.db.domain.LitemallFeedbackExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* @author Yogeek
* @date 2018/8/27 11:39
*/
@Service
public class LitemallFeedbackService {
@Autowired
private LitemallFeedbackMapper feedbackMapper;
//提交
public Integer add(LitemallFeedback feedback) {
return feedbackMapper.insertSelective(feedback);
}
public List<LitemallFeedback> querySelective(Integer userId, String username, Integer page, Integer limit, String sort, String order) {
LitemallFeedbackExample example = new LitemallFeedbackExample();
LitemallFeedbackExample.Criteria criteria = example.createCriteria();
if(userId != null){
criteria.andUserIdEqualTo(userId);
}
if(!StringUtils.isEmpty(username)){
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, limit);
return feedbackMapper.selectByExample(example);
}
public int countSelective(Integer userId, String username, Integer page, Integer limit, String sort, String order) {
LitemallFeedbackExample example = new LitemallFeedbackExample();
LitemallFeedbackExample.Criteria criteria = example.createCriteria();
if(userId != null){
criteria.andUserIdEqualTo(userId);
}
if(!StringUtils.isEmpty(username)){
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
return (int)feedbackMapper.countByExample(example);
}
public LitemallFeedback findById(Integer id) {
return feedbackMapper.selectByPrimaryKey(id);
}
public void updateById(LitemallFeedback feedback) {
feedbackMapper.updateByPrimaryKeySelective(feedback);
}
public void delete(Integer id) {
feedbackMapper.logicalDeleteByPrimaryKey(id);
}
}
package org.linlinjava.litemall.wx.web;
import com.alibaba.fastjson.JSONObject;
import org.linlinjava.litemall.core.util.RegexUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallFeedback;
import org.linlinjava.litemall.db.domain.LitemallUser;
import org.linlinjava.litemall.db.service.LitemallFeedbackService;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.time.LocalDateTime;
/**
* @author Yogeek
* @date 2018/8/25 14:10
*/
@RestController
@RequestMapping("/wx/feedback")
@Validated
public class WxFeedbackController {
private final Log logger = LogFactory.getLog(WxFeedbackController.class);
@Autowired
private LitemallFeedbackService feedbackService;
@Autowired
protected HttpServletRequest request;
@Autowired
private LitemallUserService userService;
/**
* 意见反馈
*/
@PostMapping("submit")
@ResponseBody
public Object save(@LoginUser Integer userId){
if(userId == null){
return ResponseUtil.unlogin();
}
LitemallUser user = userService.findById(userId);
String username = user.getUsername();
//获取客户端对象
JSONObject feedbackJson = this.getJsonRequest();
if (null != feedbackJson) {
LitemallFeedback feedback = new LitemallFeedback();
String mobile = feedbackJson.getString("mobile");
// 测试手机号码是否正确
if (!RegexUtil.isMobileExact(mobile)) {
return ResponseUtil.badArgument();
}
String[] feedType = new String [] {"请选择反馈类型", "商品相关", "功能异常", "优化建议", "其他"};
int index = feedbackJson.getInteger("index");
String content = feedbackJson.getString("content");
feedback.setUserId(userId);
feedback.setUsername(username);
feedback.setMobile(mobile);
feedback.setAddTime(LocalDateTime.now());
feedback.setFeedType(feedType[index]);
//状态默认是0,1表示状态已发生变化
feedback.setStatus(1);
feedback.setContent(content);
feedbackService.add(feedback);
return ResponseUtil.ok("感谢您的反馈");
}
return ResponseUtil.badArgument();
}
private JSONObject getJsonRequest() {
JSONObject result = null;
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = request.getReader();) {
char[] buff = new char[1024];
int len;
while ((len = reader.read(buff)) != -1) {
sb.append(buff, 0, len);
}
result = JSONObject.parseObject(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}
Supports Markdown
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