HookBindController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package com.ruoyi.web.controller.app;
  2. import java.util.*;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.ruoyi.app.DTO.HookBindBatchListDTO;
  5. import com.ruoyi.app.domain.request.AddHookBindBatch;
  6. import com.ruoyi.app.domain.request.EditHookBindBatch;
  7. import com.ruoyi.app.domain.request.ReqHookBindDetail;
  8. import com.ruoyi.app.domain.request.ReqHookBindList;
  9. import com.ruoyi.common.utils.DateUtils;
  10. import com.ruoyi.common.utils.StringUtils;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.springframework.security.access.prepost.PreAuthorize;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.validation.annotation.Validated;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.PutMapping;
  19. import org.springframework.web.bind.annotation.DeleteMapping;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import com.ruoyi.common.annotation.Log;
  25. import com.ruoyi.common.core.controller.BaseController;
  26. import com.ruoyi.common.core.domain.AjaxResult;
  27. import com.ruoyi.common.enums.BusinessType;
  28. import com.ruoyi.app.domain.HookBind;
  29. import com.ruoyi.app.service.IHookBindService;
  30. import com.ruoyi.common.utils.poi.ExcelUtil;
  31. import com.ruoyi.common.core.page.TableDataInfo;
  32. import static com.ruoyi.common.utils.uuid.IdUtils.fastSimpleUUID;
  33. /**
  34. * 吊钩绑定Controller
  35. *
  36. * @author coede
  37. * @date 2025-03-19
  38. */
  39. @Api("吊钩绑定信息管理")
  40. @RestController
  41. @RequestMapping("/app/hookBind")
  42. public class HookBindController extends BaseController
  43. {
  44. @Autowired
  45. private IHookBindService hookBindService;
  46. /**
  47. * 查询吊钩绑定列表
  48. */
  49. @ApiOperation("查询吊钩绑定列表")
  50. @GetMapping("/list")
  51. public TableDataInfo list(HookBind hookBind)
  52. {
  53. startPage();
  54. List<HookBind> list = hookBindService.selectHookBindList(hookBind);
  55. return getDataTable(list);
  56. }
  57. /**
  58. * 按批次查询吊钩绑定列表
  59. */
  60. @ApiOperation("按批次查询吊钩绑定列表")
  61. @GetMapping("/batchList")
  62. public TableDataInfo batchList(ReqHookBindList req)
  63. {
  64. startPage();
  65. List<HookBindBatchListDTO> list = hookBindService.selectHookBindListByBatch(req);
  66. return getDataTable(list);
  67. }
  68. /**
  69. * 导出吊钩绑定列表
  70. */
  71. @ApiOperation("导出吊钩绑定列表")
  72. @PreAuthorize("@ss.hasPermi('app:hookBind:export')")
  73. @Log(title = "吊钩绑定", businessType = BusinessType.EXPORT)
  74. @PostMapping("/export")
  75. public void export(HttpServletResponse response, HookBind hookBind)
  76. {
  77. List<HookBind> list = hookBindService.selectHookBindList(hookBind);
  78. ExcelUtil<HookBind> util = new ExcelUtil<HookBind>(HookBind.class);
  79. util.exportExcel(response, list, "吊钩绑定数据");
  80. }
  81. /**
  82. * 获取吊钩绑定详细信息
  83. */
  84. @ApiOperation("获取吊钩绑定详细信息")
  85. @GetMapping(value = "/group")
  86. public AjaxResult getGroupInfo(@Validated ReqHookBindDetail req)
  87. {
  88. return success(hookBindService.selectHookBindByBatch(req.getGroupId()));
  89. }
  90. /**
  91. * 获取吊钩绑定详细信息
  92. */
  93. @ApiOperation("获取吊钩绑定详细信息")
  94. @GetMapping(value = "/detail/{hookNo}")
  95. public AjaxResult getDetail(@PathVariable("hookNo") String hookNo)
  96. {
  97. return success(hookBindService.selectHookBindDetail(hookNo));
  98. }
  99. /**
  100. * 新增吊钩绑定 暂时不用
  101. */
  102. @ApiOperation("新增吊钩绑定 暂时不用")
  103. @PreAuthorize("@ss.hasPermi('app:hookBind:add')")
  104. @Log(title = "吊钩绑定", businessType = BusinessType.INSERT)
  105. @PostMapping
  106. public AjaxResult add(@Validated @RequestBody HookBind hookBind)
  107. {
  108. hookBind.setCreateBy(getUsername());
  109. return toAjax(hookBindService.insertHookBind(hookBind));
  110. }
  111. /**
  112. * 新增吊钩批量绑定
  113. */
  114. @ApiOperation("新增吊钩批量绑定")
  115. @PreAuthorize("@ss.hasPermi('app:hookBind:add')")
  116. @Log(title = "吊钩绑定", businessType = BusinessType.INSERT)
  117. @PostMapping("/addBatch")
  118. public AjaxResult addBatch(@Validated @RequestBody AddHookBindBatch req)
  119. {
  120. //生成新对象
  121. String[] hooks = req.getHookNoList().split(",");
  122. List<HookBind> hookBindArr = new ArrayList<>();
  123. String batchNo = fastSimpleUUID();
  124. //先判断本身数组内是否有重复的
  125. Set<String> uniqueIds = new HashSet<>();
  126. //未传绑定时间默认当前时间
  127. if(req.getBindTime() == null){
  128. req.setBindTime(DateUtils.getNowDate());
  129. }
  130. for(String hook : hooks){
  131. //noinspection ConstantConditions 忽略错误的IDEA提示
  132. if (!uniqueIds.add(hook)) {
  133. return error("新增吊钩批量绑定,本次添加存在相同的吊钩号");
  134. }
  135. HookBind hookBind = new HookBind();
  136. hookBind.setBatchNo(batchNo);
  137. hookBind.setHookNo(hook);
  138. hookBind.setBindTime(req.getBindTime());
  139. hookBind.setDistributeBatchId(req.getDistributeBatchId());
  140. hookBind.setSlaughterCode(req.getSlaughterCode());
  141. hookBind.setCreateTime(DateUtils.getNowDate());
  142. hookBind.setCreateBy(getUsername());
  143. hookBindArr.add(hookBind);
  144. }
  145. //校验数据库的
  146. for (HookBind hookBind : hookBindArr) {
  147. HookBind check = hookBindService.checkHookNoUnique(hookBind);
  148. if (StringUtils.isNotNull(check))
  149. {
  150. return error("新增吊钩批量绑定失败,'" + check.getHookNo() + "'同一时间已存在绑定");
  151. }
  152. }
  153. return toAjax(hookBindService.insertHookBindBatch(hookBindArr));
  154. }
  155. /**
  156. * 修改吊钩绑定
  157. */
  158. @ApiOperation("修改吊钩绑定")
  159. @PreAuthorize("@ss.hasPermi('app:hookBind:edit')")
  160. @Log(title = "吊钩绑定", businessType = BusinessType.UPDATE)
  161. @PutMapping
  162. public AjaxResult edit(@Validated @RequestBody HookBind hookBind)
  163. {
  164. hookBind.setUpdateBy(getUsername());
  165. return toAjax(hookBindService.updateHookBind(hookBind));
  166. }
  167. /**
  168. * 批量修改吊钩绑定
  169. */
  170. @ApiOperation("批量修改吊钩绑定")
  171. @PreAuthorize("@ss.hasPermi('app:hookBind:edit')")
  172. @Log(title = "吊钩绑定", businessType = BusinessType.UPDATE)
  173. @PostMapping("/editBatch")
  174. public AjaxResult editBatch(@Validated @RequestBody EditHookBindBatch req)
  175. {
  176. req.setUpdateBy(getUsername());
  177. return toAjax(hookBindService.updateHookBindBatch(req));
  178. }
  179. /**
  180. * 删除吊钩绑定
  181. */
  182. @ApiOperation("删除吊钩绑定")
  183. @PreAuthorize("@ss.hasPermi('app:hookBind:remove')")
  184. @Log(title = "吊钩绑定", businessType = BusinessType.DELETE)
  185. @DeleteMapping("/{ids}")
  186. public AjaxResult remove(@PathVariable String[] ids)
  187. {
  188. return toAjax(hookBindService.deleteHookBindByIds(ids));
  189. }
  190. }