PurchaserController.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.ruoyi.web.controller.app;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.ruoyi.app.model.request.ReqPurchaser;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import org.springframework.security.access.prepost.PreAuthorize;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.validation.annotation.Validated;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.PutMapping;
  14. import org.springframework.web.bind.annotation.DeleteMapping;
  15. import org.springframework.web.bind.annotation.PathVariable;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.ruoyi.common.annotation.Log;
  20. import com.ruoyi.common.core.controller.BaseController;
  21. import com.ruoyi.common.core.domain.AjaxResult;
  22. import com.ruoyi.common.enums.BusinessType;
  23. import com.ruoyi.app.model.Purchaser;
  24. import com.ruoyi.app.service.IPurchaserService;
  25. import com.ruoyi.common.utils.poi.ExcelUtil;
  26. import com.ruoyi.common.core.page.TableDataInfo;
  27. /**
  28. * 肉商Controller
  29. *
  30. * @author coede
  31. * @date 2025-03-19
  32. */
  33. @Api("肉商信息管理")
  34. @RestController
  35. @RequestMapping("/app/purchaser")
  36. public class PurchaserController extends BaseController
  37. {
  38. @Autowired
  39. private IPurchaserService purchaserService;
  40. /**
  41. * 查询肉商列表
  42. */
  43. @ApiOperation("查询肉商列表")
  44. @GetMapping("/list")
  45. public TableDataInfo list(ReqPurchaser purchaser)
  46. {
  47. startPage();
  48. List<Purchaser> list = purchaserService.selectPurchaserList(purchaser);
  49. return getDataTable(list);
  50. }
  51. /**
  52. * 获取肉商选择框列表
  53. */
  54. @ApiOperation("获取肉商选择框列表")
  55. @GetMapping("/optionselect")
  56. public AjaxResult optionselect()
  57. {
  58. List<Purchaser> list = purchaserService.selectAllPurchaserList();
  59. return success(list);
  60. }
  61. /**
  62. * 导出肉商列表
  63. */
  64. @PreAuthorize("@ss.hasPermi('app:purchaser:export')")
  65. @Log(title = "肉商", businessType = BusinessType.EXPORT)
  66. @PostMapping("/export")
  67. public void export(HttpServletResponse response, ReqPurchaser purchaser)
  68. {
  69. List<Purchaser> list = purchaserService.selectPurchaserList(purchaser);
  70. ExcelUtil<Purchaser> util = new ExcelUtil<Purchaser>(Purchaser.class);
  71. util.exportExcel(response, list, "肉商数据");
  72. }
  73. /**
  74. * 获取肉商详细信息
  75. */
  76. @ApiOperation("获取肉商详细信息")
  77. @GetMapping(value = "/{id}")
  78. public AjaxResult getInfo(@PathVariable("id") Long id)
  79. {
  80. return success(purchaserService.selectPurchaserById(id));
  81. }
  82. /**
  83. * 新增肉商
  84. */
  85. @ApiOperation("新增肉商")
  86. @PreAuthorize("@ss.hasPermi('app:purchaser:add')")
  87. @Log(title = "肉商", businessType = BusinessType.INSERT)
  88. @PostMapping
  89. public AjaxResult add(@Validated @RequestBody Purchaser purchaser)
  90. {
  91. // if (!purchaserService.checkPurchaserNoUnique(purchaser))
  92. // {
  93. // return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商编号");
  94. // }
  95. if (!purchaserService.checkPurchaserNameUnique(purchaser))
  96. {
  97. return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商名称");
  98. }
  99. if (!purchaserService.checkIDNumberUnique(purchaser))
  100. {
  101. return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的身份证号");
  102. }
  103. purchaser.setCreateBy(getUsername());
  104. return toAjax(purchaserService.insertPurchaser(purchaser));
  105. }
  106. /**
  107. * 修改肉商
  108. */
  109. @ApiOperation("修改肉商")
  110. @PreAuthorize("@ss.hasPermi('app:purchaser:edit')")
  111. @Log(title = "肉商", businessType = BusinessType.UPDATE)
  112. @PutMapping
  113. public AjaxResult edit(@Validated @RequestBody Purchaser purchaser)
  114. {
  115. if (!purchaserService.checkPurchaserNoUnique(purchaser))
  116. {
  117. return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商编号");
  118. }
  119. if (!purchaserService.checkPurchaserNameUnique(purchaser))
  120. {
  121. return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商名称");
  122. }
  123. if (!purchaserService.checkIDNumberUnique(purchaser))
  124. {
  125. return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的身份证号");
  126. }
  127. purchaser.setUpdateBy(getUsername());
  128. return toAjax(purchaserService.updatePurchaser(purchaser));
  129. }
  130. /**
  131. * 删除肉商
  132. */
  133. @ApiOperation("删除肉商")
  134. @PreAuthorize("@ss.hasPermi('app:purchaser:remove')")
  135. @Log(title = "肉商", businessType = BusinessType.DELETE)
  136. @DeleteMapping("/{ids}")
  137. public AjaxResult remove(@PathVariable Long[] ids)
  138. {
  139. return toAjax(purchaserService.deletePurchaserByIds(ids));
  140. }
  141. @ApiOperation("查询自动生成的肉商编号")
  142. @GetMapping("/nextNo")
  143. public AjaxResult nextNo()
  144. {
  145. return success(new HashMap<String, String>() {{ put("nextNo", purchaserService.getNextNo());}});
  146. }
  147. }