SlaughterRelationController.java 9.1 KB

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