PosAppealController.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.ruoyi.system.controller;
  2. import java.util.List;
  3. import java.util.stream.Collectors;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.ruoyi.system.utils.JwtUtil;
  9. import jakarta.servlet.http.HttpServletResponse;
  10. import com.ruoyi.common.annotation.Anonymous;
  11. import com.ruoyi.system.domain.PosOrder;
  12. import com.ruoyi.system.service.IPosOrderService;
  13. import com.ruoyi.system.utils.Auth;
  14. import org.springframework.security.access.prepost.PreAuthorize;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import com.ruoyi.common.annotation.Log;
  18. import com.ruoyi.common.core.controller.BaseController;
  19. import com.ruoyi.common.core.domain.AjaxResult;
  20. import com.ruoyi.common.enums.BusinessType;
  21. import com.ruoyi.system.domain.PosAppeal;
  22. import com.ruoyi.system.service.IPosAppealService;
  23. import com.ruoyi.common.utils.poi.ExcelUtil;
  24. import com.ruoyi.common.core.page.TableDataInfo;
  25. /**
  26. * 留言信息Controller
  27. *
  28. * @author ruoyi
  29. * @date 2024-07-07
  30. */
  31. @RestController
  32. @RequestMapping("/system/appeal")
  33. public class PosAppealController extends BaseController
  34. {
  35. @Autowired
  36. private IPosAppealService posAppealService;
  37. @Autowired
  38. private IPosOrderService posOrderService;
  39. //前端api--start
  40. /**
  41. * 新增留言信息
  42. */
  43. @Anonymous
  44. @Auth
  45. @Log(title = "留言信息", businessType = BusinessType.INSERT)
  46. @PostMapping("/apiAdd")
  47. public AjaxResult apiAdd(@RequestHeader String token,@RequestBody PosAppeal posAppeal)
  48. {
  49. JwtUtil jwtUtil = new JwtUtil();
  50. String id = jwtUtil.getusid(token);
  51. Long uid=Long.valueOf(id);
  52. posAppeal.setUserId(uid);
  53. PosOrder po = new PosOrder();
  54. po.setDdId(posAppeal.getDdId());
  55. List<PosOrder> list = posOrderService.selectPosOrderList(po);
  56. if(list!=null && list.size()>0){
  57. for(PosOrder od:list){
  58. od.setKefuState(2L);
  59. posOrderService.saveOrUpdate(od);
  60. }
  61. }
  62. return success(posAppealService.insertPosAppeal(posAppeal));
  63. }
  64. /**
  65. * 查询留言信息列表
  66. */
  67. @Anonymous
  68. @Auth
  69. @GetMapping("/apiList")
  70. public AjaxResult list(@RequestHeader String token,@RequestParam(defaultValue = "",required = false)String ddId, @RequestParam Integer page, @RequestParam Integer size)
  71. {
  72. JwtUtil jwtUtil = new JwtUtil();
  73. String id = jwtUtil.getusid(token);
  74. Long uid=Long.valueOf(id);
  75. Page<PosAppeal> pageInput=new Page<>(page,size);
  76. LambdaQueryWrapper<PosAppeal> query=new LambdaQueryWrapper<>();
  77. query.eq(PosAppeal::getUserId,uid);
  78. query.eq(!StrUtil.isEmpty(ddId),PosAppeal::getDdId,ddId);
  79. IPage<PosAppeal> result= posAppealService.page(pageInput,query);
  80. if(!result.getRecords().isEmpty()){
  81. List<String>ddIds= result.getRecords().stream().map(PosAppeal::getDdId).collect(Collectors.toList());
  82. List<PosAppeal> child= posAppealService.list(new LambdaQueryWrapper<PosAppeal>().in(PosAppeal::getDdId,ddIds).eq(PosAppeal::getUserId,0L).orderByDesc(PosAppeal::getId));
  83. for (PosAppeal data:result.getRecords()){
  84. var sub= child.stream().filter(x-> data.getDdId().equals(x.getDdId())).toList();
  85. data.setChild(sub);
  86. }
  87. }
  88. return success(result);
  89. }
  90. //前端api--end
  91. /**
  92. * 查询留言信息列表
  93. */
  94. @PreAuthorize("@ss.hasPermi('system:appeal:list')")
  95. @GetMapping("/list")
  96. public TableDataInfo list(PosAppeal posAppeal)
  97. {
  98. startPage();
  99. List<PosAppeal> list = posAppealService.selectPosAppealList(posAppeal);
  100. return getDataTable(list);
  101. }
  102. /**
  103. * 导出留言信息列表
  104. */
  105. @PreAuthorize("@ss.hasPermi('system:appeal:export')")
  106. @Log(title = "留言信息", businessType = BusinessType.EXPORT)
  107. @PostMapping("/export")
  108. public void export(HttpServletResponse response, PosAppeal posAppeal)
  109. {
  110. List<PosAppeal> list = posAppealService.selectPosAppealList(posAppeal);
  111. ExcelUtil<PosAppeal> util = new ExcelUtil<PosAppeal>(PosAppeal.class);
  112. util.exportExcel(response, list, "留言信息数据");
  113. }
  114. /**
  115. * 获取留言信息详细信息
  116. */
  117. @PreAuthorize("@ss.hasPermi('system:appeal:query')")
  118. @GetMapping(value = "/{id}")
  119. public AjaxResult getInfo(@PathVariable("id") Long id)
  120. {
  121. return success(posAppealService.selectPosAppealById(id));
  122. }
  123. /**
  124. * 新增留言信息
  125. */
  126. @PreAuthorize("@ss.hasPermi('system:appeal:add')")
  127. @Log(title = "留言信息", businessType = BusinessType.INSERT)
  128. @PostMapping
  129. public AjaxResult add(@RequestBody PosAppeal posAppeal)
  130. {
  131. posAppeal.setUserId(0L);
  132. return toAjax(posAppealService.insertPosAppeal(posAppeal));
  133. }
  134. /**
  135. * 修改留言信息
  136. */
  137. @PreAuthorize("@ss.hasPermi('system:appeal:edit')")
  138. @Log(title = "留言信息", businessType = BusinessType.UPDATE)
  139. @PutMapping
  140. public AjaxResult edit(@RequestBody PosAppeal posAppeal)
  141. {
  142. return toAjax(posAppealService.updatePosAppeal(posAppeal));
  143. }
  144. /**
  145. * 删除留言信息
  146. */
  147. @PreAuthorize("@ss.hasPermi('system:appeal:remove')")
  148. @Log(title = "留言信息", businessType = BusinessType.DELETE)
  149. @DeleteMapping("/{ids}")
  150. public AjaxResult remove(@PathVariable Long[] ids)
  151. {
  152. return toAjax(posAppealService.deletePosAppealByIds(ids));
  153. }
  154. }