WeCommunityGroupSopController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.linkwechat.controller;
  2. import com.linkwechat.common.constant.HttpStatus;
  3. import com.linkwechat.common.core.controller.BaseController;
  4. import com.linkwechat.common.core.domain.AjaxResult;
  5. import com.linkwechat.common.core.page.TableDataInfo;
  6. import com.linkwechat.domain.community.WeGroupSop;
  7. import com.linkwechat.domain.community.query.WeGroupSopQuery;
  8. import com.linkwechat.domain.community.vo.WeGroupSopVo;
  9. import com.linkwechat.service.IWeGroupSopService;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.validation.annotation.Validated;
  13. import org.springframework.web.bind.annotation.*;
  14. import java.util.List;
  15. /**
  16. * 社群运营群sop
  17. */
  18. @RestController
  19. @RequestMapping(value = "/communityGroupSop")
  20. public class WeCommunityGroupSopController extends BaseController {
  21. @Autowired
  22. private IWeGroupSopService iWeGroupSopService;
  23. /**
  24. * 通过过滤条件获取群sop列表
  25. *
  26. * @param ruleName 规则名称
  27. * @param createBy 创建者
  28. * @param beginTime 创建区间 - 开始时间
  29. * @param endTime 创建区间 - 结束时间
  30. * @return 群sop规则列表
  31. */
  32. @GetMapping(path = "/list")
  33. public TableDataInfo<List<WeGroupSopVo>> getSopList(
  34. @RequestParam(value = "ruleName", required = false) String ruleName,
  35. @RequestParam(value = "createBy", required = false) String createBy,
  36. @RequestParam(value = "beginTime", required = false) String beginTime,
  37. @RequestParam(value = "endTime", required = false) String endTime
  38. )
  39. {
  40. startPage();
  41. List<WeGroupSopVo> groupSopVoList = iWeGroupSopService.getGroupSopList(ruleName, createBy, beginTime, endTime);
  42. return getDataTable(groupSopVoList);
  43. }
  44. /**
  45. * 通过规则id获取sop规则
  46. *
  47. * @param ruleId 规则id
  48. * @return 结果
  49. */
  50. @GetMapping(path = "/{ruleId}")
  51. public AjaxResult<WeGroupSopVo> getGroupSop(@PathVariable("ruleId") Long ruleId) {
  52. WeGroupSopVo groupSopVo = iWeGroupSopService.getGroupSopById(ruleId);
  53. if (null == groupSopVo) {
  54. return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
  55. }
  56. return AjaxResult.success(groupSopVo);
  57. }
  58. /**
  59. * 新增SOP规则
  60. *
  61. * @param groupSopDto 更新数据
  62. * @return 结果
  63. */
  64. @PostMapping(path = "/")
  65. public AjaxResult addGroupSop(@Validated @RequestBody WeGroupSopQuery groupSopDto) {
  66. WeGroupSop weGroupSop = new WeGroupSop();
  67. BeanUtils.copyProperties(groupSopDto, weGroupSop);
  68. if (iWeGroupSopService.isNameOccupied(weGroupSop.getRuleName())) {
  69. return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
  70. }
  71. try {
  72. iWeGroupSopService.addGroupSop(weGroupSop, groupSopDto.getChatIdList(), groupSopDto.getMaterialIdList(), groupSopDto.getPicList());
  73. }catch (Exception e){
  74. return AjaxResult.error(e.getMessage());
  75. }
  76. return AjaxResult.success();
  77. }
  78. /**
  79. * 更改SOP规则
  80. *
  81. * @param ruleId SOP规则 id
  82. * @param groupSopDto 更新数据
  83. * @return 结果
  84. */
  85. @PutMapping(path = "/{ruleId}")
  86. public AjaxResult updateGroupSop(@PathVariable Long ruleId, @Validated @RequestBody WeGroupSopQuery groupSopDto) {
  87. // 校验是否存在
  88. WeGroupSop oldWeGroupSop = iWeGroupSopService.getById(ruleId);
  89. if (null == oldWeGroupSop) {
  90. return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
  91. }
  92. WeGroupSop weGroupSop = new WeGroupSop();
  93. weGroupSop.setRuleId(ruleId);
  94. BeanUtils.copyProperties(groupSopDto, weGroupSop);
  95. // 校验规则名是否可用
  96. if(!oldWeGroupSop.getRuleName().equals(groupSopDto.getRuleName())){
  97. if (iWeGroupSopService.isNameOccupied(weGroupSop.getRuleName())) {
  98. return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
  99. }
  100. }
  101. iWeGroupSopService.updateGroupSop(weGroupSop, groupSopDto.getChatIdList(), groupSopDto.getMaterialIdList(), groupSopDto.getPicList());
  102. return AjaxResult.success();
  103. }
  104. /**
  105. * 根据id列表批量删除群sop规则
  106. *
  107. * @param ids 群sop规则列表
  108. * @return 结果
  109. */
  110. @DeleteMapping(path = "/{ids}")
  111. public AjaxResult batchDeleteSopRule(@PathVariable("ids") Long[] ids) {
  112. iWeGroupSopService.batchRemoveGroupSopByIds(ids);
  113. return AjaxResult.success();
  114. }
  115. }