SlaughterRelationController.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package com.ruoyi.web.controller.app;
  2. import java.util.HashSet;
  3. import java.util.List;
  4. import java.util.Set;
  5. import java.util.stream.Collectors;
  6. import javax.servlet.http.HttpServletResponse;
  7. import com.ruoyi.app.DTO.SlaughterRelationDTO;
  8. import com.ruoyi.app.domain.Purchaser;
  9. import com.ruoyi.app.domain.request.AddSlaughterRelationBatch;
  10. import com.ruoyi.app.domain.request.ExportSlaughterRelation;
  11. import com.ruoyi.app.domain.request.ReqGetSlaughterRelation;
  12. import com.ruoyi.app.domain.response.RespGetSlaughterRelation;
  13. import com.ruoyi.common.utils.DateUtils;
  14. import com.ruoyi.common.utils.StringUtils;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.validation.annotation.Validated;
  20. import org.springframework.web.bind.annotation.GetMapping;
  21. import org.springframework.web.bind.annotation.PostMapping;
  22. import org.springframework.web.bind.annotation.PutMapping;
  23. import org.springframework.web.bind.annotation.DeleteMapping;
  24. import org.springframework.web.bind.annotation.PathVariable;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import com.ruoyi.common.annotation.Log;
  29. import com.ruoyi.common.core.controller.BaseController;
  30. import com.ruoyi.common.core.domain.AjaxResult;
  31. import com.ruoyi.common.enums.BusinessType;
  32. import com.ruoyi.app.domain.SlaughterRelation;
  33. import com.ruoyi.app.service.ISlaughterRelationService;
  34. import com.ruoyi.common.utils.poi.ExcelUtil;
  35. import com.ruoyi.common.core.page.TableDataInfo;
  36. /**
  37. * 血码关系Controller
  38. *
  39. * @author coede
  40. * @date 2025-03-19
  41. */
  42. @Api("血码关系信息管理")
  43. @RestController
  44. @RequestMapping("/app/slaughterRelation")
  45. public class SlaughterRelationController extends BaseController
  46. {
  47. @Autowired
  48. private ISlaughterRelationService slaughterRelationService;
  49. /**
  50. * 供应商血码数量列表
  51. */
  52. @ApiOperation("供应商血码数量列表")
  53. @GetMapping("/supplierList")
  54. public TableDataInfo supplierList(ReqGetSlaughterRelation req)
  55. {
  56. startPage();
  57. List<RespGetSlaughterRelation> list = slaughterRelationService.selectSupplierList(req);
  58. return getDataTable(list);
  59. }
  60. /**
  61. * 查询血码关系列表
  62. */
  63. @ApiOperation("查询血码关系列表")
  64. @GetMapping("/list")
  65. public TableDataInfo list(SlaughterRelation slaughterRelation)
  66. {
  67. startPage();
  68. List<SlaughterRelation> list = slaughterRelationService.selectSlaughterRelationList(slaughterRelation);
  69. return getDataTable(list);
  70. }
  71. /**
  72. * 导出血码关系列表
  73. */
  74. @ApiOperation("导出血码关系列表")
  75. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:export')")
  76. @Log(title = "血码关系", businessType = BusinessType.EXPORT)
  77. @PostMapping("/export")
  78. public void export(HttpServletResponse response, ExportSlaughterRelation req)
  79. {
  80. List<SlaughterRelationDTO> list = slaughterRelationService.exportSlaughterRelationList(req);
  81. list.forEach(item -> item.setQrcode(item.getSlaughterCode()));
  82. ExcelUtil<SlaughterRelationDTO> util = new ExcelUtil<>(SlaughterRelationDTO.class);
  83. util.exportExcel(response, list, "血码关系数据");
  84. }
  85. /**
  86. * 获取血码关系详细信息
  87. */
  88. @ApiOperation("获取血码关系详细信息")
  89. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:query')")
  90. @GetMapping(value = "/{id}")
  91. public AjaxResult getInfo(@PathVariable("id") Long id)
  92. {
  93. return success(slaughterRelationService.selectSlaughterRelationById(id));
  94. }
  95. /**
  96. * 新增血码关系
  97. */
  98. @ApiOperation("新增血码关系")
  99. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:add')")
  100. @Log(title = "血码关系", businessType = BusinessType.INSERT)
  101. @PostMapping
  102. public AjaxResult add(@Validated @RequestBody SlaughterRelation slaughterRelation)
  103. {
  104. if (!slaughterRelationService.checkCodeUnique(slaughterRelation))
  105. {
  106. return error("新增血码关系失败,血码'" + slaughterRelation.getSlaughterCode() + "'已存在");
  107. }
  108. SlaughterRelation check = slaughterRelationService.checkPurchaserUnique(slaughterRelation);
  109. if (StringUtils.isNotNull(check))
  110. {
  111. Purchaser purchaser = check.getPurchaser();
  112. return error("新增血码关系失败,该供应商下肉商'" + purchaser.getPurchaserName() + "'已存在");
  113. }
  114. slaughterRelation.setCreateBy(getUsername());
  115. return toAjax(slaughterRelationService.insertSlaughterRelation(slaughterRelation));
  116. }
  117. /**
  118. * 批量新增血码关系
  119. */
  120. @ApiOperation("批量新增血码关系")
  121. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:add')")
  122. @Log(title = "血码关系", businessType = BusinessType.INSERT)
  123. @PostMapping(value = "/addBatch")
  124. public AjaxResult addBatch(@Validated @RequestBody AddSlaughterRelationBatch req)
  125. {
  126. //生成新对象
  127. List<SlaughterRelation> relationArr = req.getRelationArr().stream()
  128. .map(item -> {
  129. SlaughterRelation newrelation = new SlaughterRelation();
  130. newrelation.setPurchaserId(item.getPurchaserId());
  131. newrelation.setSlaughterCode(item.getSlaughterCode());
  132. newrelation.setSupplierId(req.getSupplierId());
  133. newrelation.setCreateTime(DateUtils.getNowDate());
  134. newrelation.setCreateBy(getUsername());
  135. return newrelation;
  136. })
  137. .collect(Collectors.toList());
  138. //先判断本身数组内是否有重复的
  139. Set<String> uniqueIds = new HashSet<>();
  140. Set<String> uniqueCodes = new HashSet<>();
  141. for (SlaughterRelation relation : relationArr) {
  142. String key = String.valueOf(relation.getPurchaserId());
  143. //noinspection ConstantConditions 忽略错误的IDEA提示
  144. if (!uniqueIds.add(key)) {
  145. return error("新增血码关系失败,存在同一肉商配置多个血码的情况");
  146. }
  147. String code = relation.getSlaughterCode();
  148. //noinspection ConstantConditions 忽略错误的IDEA提示
  149. if (!uniqueCodes.add(code)) {
  150. return error("新增血码关系失败,存在多个肉商配置同一血码的情况");
  151. }
  152. }
  153. //校验数据库的
  154. for (SlaughterRelation relation : relationArr) {
  155. if (!slaughterRelationService.checkCodeUnique(relation))
  156. {
  157. return error("新增血码关系失败,血码'" + relation.getSlaughterCode() + "'已存在");
  158. }
  159. SlaughterRelation check = slaughterRelationService.checkPurchaserUnique(relation);
  160. if (StringUtils.isNotNull(check))
  161. {
  162. Purchaser purchaser = check.getPurchaser();
  163. return error("新增血码关系失败,该供应商下肉商'" + purchaser.getPurchaserName() + "'已存在");
  164. }
  165. }
  166. return toAjax(slaughterRelationService.insertSlaughterRelationBatch(relationArr));
  167. }
  168. /**
  169. * 修改血码关系
  170. */
  171. @ApiOperation("修改血码关系")
  172. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:edit')")
  173. @Log(title = "血码关系", businessType = BusinessType.UPDATE)
  174. @PutMapping
  175. public AjaxResult edit(@Validated @RequestBody SlaughterRelation slaughterRelation)
  176. {
  177. if (!slaughterRelationService.checkCodeUnique(slaughterRelation))
  178. {
  179. return error("修改血码关系失败,血码'" + slaughterRelation.getSlaughterCode() + "'已存在");
  180. }
  181. SlaughterRelation check = slaughterRelationService.checkPurchaserUnique(slaughterRelation);
  182. if (StringUtils.isNotNull(check) && check.getId().longValue() != slaughterRelation.getId().longValue())
  183. {
  184. Purchaser purchaser = check.getPurchaser();
  185. return error("修改血码关系失败,该供应商下肉商'" + purchaser.getPurchaserName() + "'已存在");
  186. }
  187. slaughterRelation.setUpdateBy(getUsername());
  188. return toAjax(slaughterRelationService.updateSlaughterRelation(slaughterRelation));
  189. }
  190. /**
  191. * 删除血码关系
  192. */
  193. @ApiOperation("删除血码关系")
  194. @PreAuthorize("@ss.hasPermi('app:slaughterRelation:remove')")
  195. @Log(title = "血码关系", businessType = BusinessType.DELETE)
  196. @DeleteMapping("/{ids}")
  197. public AjaxResult remove(@PathVariable Long[] ids)
  198. {
  199. return toAjax(slaughterRelationService.deleteSlaughterRelationByIds(ids));
  200. }
  201. /**
  202. * 查询全部血码关系列表
  203. */
  204. @ApiOperation("查询全部血码关系列表")
  205. @GetMapping("/optionselect")
  206. public AjaxResult optionselect(SlaughterRelation slaughterRelation)
  207. {
  208. List<SlaughterRelation> list = slaughterRelationService.selectSlaughterRelationList(slaughterRelation);
  209. return success(list);
  210. }
  211. }