ComplaintController.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.zhiqiyun.open.mvc.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.OrderItem;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.zhiqiyun.open.annotation.Permission;
  6. import com.zhiqiyun.open.core.enmus.ComplaintState;
  7. import com.zhiqiyun.open.core.models.statistics.ComplaintInfo;
  8. import com.zhiqiyun.open.core.service.ComplaintInfoService;
  9. import com.zhiqiyun.open.core.service.SequenceService;
  10. import com.zhiqiyun.open.mvc.Result;
  11. import com.zhiqiyun.open.mvc.params.statistics.QueryComplaintInfoParams;
  12. import com.zhiqiyun.open.mvc.params.statistics.SaveComplaintInfoParams;
  13. import com.zhiqiyun.open.utils.DateUtil;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.springframework.beans.BeanUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import javax.validation.Valid;
  22. import java.util.List;
  23. @RestController
  24. @RequestMapping("/statistics/complaint")
  25. public class ComplaintController {
  26. @Autowired
  27. private ComplaintInfoService complaintInfoService;
  28. @Autowired
  29. private SequenceService sequenceService;
  30. @Permission(value = "complaint.find", tags = "查询客诉信息")
  31. @PostMapping("/findPage")
  32. public Result findPage(@RequestBody QueryComplaintInfoParams params) {
  33. QueryWrapper<ComplaintInfo> wrapper = new QueryWrapper<>();
  34. if (StringUtils.isNotBlank(params.getTitle())) {
  35. wrapper.like("title", params.getTitle());
  36. }
  37. if (StringUtils.isNotBlank(params.getCategory())) {
  38. wrapper.like("category", params.getCategory());
  39. }
  40. if (StringUtils.isNotBlank(params.getChannel())) {
  41. wrapper.like("channel", params.getChannel());
  42. }
  43. if (params.getState() != null) {
  44. wrapper.eq("state", params.getState());
  45. }
  46. if (params.getCreatedTime() != null) {
  47. wrapper.between("created_time", params.getCreatedTime().getStatDate(), params.getCreatedTime().getEndDate());
  48. }
  49. if (params.getProcessedTime() != null) {
  50. wrapper.between("processed_time", params.getProcessedTime().getStatDate(), params.getProcessedTime().getEndDate());
  51. }
  52. Page<ComplaintInfo> page = params.getPage();
  53. page.addOrder(OrderItem.desc("id"));
  54. Page<ComplaintInfo> resultData = this.complaintInfoService.page(page, wrapper);
  55. return Result.instance(Result.Code.SUCCESS).setData(resultData);
  56. }
  57. @Permission(value = "complaint.add", tags = "保存客诉信息")
  58. @PostMapping("/save")
  59. public Result save(@Valid @RequestBody SaveComplaintInfoParams params) {
  60. this.complaintInfoService.save(this.buildEntity(this.sequenceService.nextId(), params));
  61. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  62. }
  63. @Permission(value = "complaint.edit", tags = "编辑客诉信息")
  64. @PostMapping("/updateById")
  65. public Result updateById(Long id, @Valid @RequestBody SaveComplaintInfoParams params) {
  66. this.complaintInfoService.updateById(this.buildEntity(id, params));
  67. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  68. }
  69. private ComplaintInfo buildEntity(Long id, @Valid SaveComplaintInfoParams params) {
  70. ComplaintInfo entity = new ComplaintInfo();
  71. BeanUtils.copyProperties(params, entity);
  72. entity.setState(ComplaintState.PENDING);
  73. entity.setCreatedTime(DateUtil.current());
  74. entity.setId(id);
  75. return entity;
  76. }
  77. @Permission(value = "complaint.delete", tags = "删除客诉信息")
  78. @PostMapping("/deleteByIds")
  79. public Result deleteByIds(@RequestBody List<Long> ids) {
  80. this.complaintInfoService.removeByIds(ids);
  81. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  82. }
  83. @Permission(value = "complaint.process", tags = "设置客诉为已处理")
  84. @PostMapping("/processedByIds")
  85. public Result processedByIds(@RequestBody List<Long> ids) {
  86. ComplaintInfo entity = new ComplaintInfo();
  87. entity.setState(ComplaintState.PROCESSED);
  88. entity.setProcessedTime(DateUtil.current());
  89. QueryWrapper<ComplaintInfo> wrapper = new QueryWrapper<>();
  90. wrapper.in("id", ids);
  91. this.complaintInfoService.update(entity, wrapper);
  92. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  93. }
  94. }