| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package com.ruoyi.web.controller.app;
- import java.util.HashMap;
- import java.util.List;
- import javax.servlet.http.HttpServletResponse;
- import com.ruoyi.app.model.request.ReqPurchaser;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.DeleteMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.app.model.Purchaser;
- import com.ruoyi.app.service.IPurchaserService;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.common.core.page.TableDataInfo;
- /**
- * 肉商Controller
- *
- * @author coede
- * @date 2025-03-19
- */
- @Api("肉商信息管理")
- @RestController
- @RequestMapping("/app/purchaser")
- public class PurchaserController extends BaseController
- {
- @Autowired
- private IPurchaserService purchaserService;
- /**
- * 查询肉商列表
- */
- @ApiOperation("查询肉商列表")
- @GetMapping("/list")
- public TableDataInfo list(ReqPurchaser purchaser)
- {
- startPage();
- List<Purchaser> list = purchaserService.selectPurchaserList(purchaser);
- return getDataTable(list);
- }
- /**
- * 获取肉商选择框列表
- */
- @ApiOperation("获取肉商选择框列表")
- @GetMapping("/optionselect")
- public AjaxResult optionselect()
- {
- List<Purchaser> list = purchaserService.selectAllPurchaserList();
- return success(list);
- }
- /**
- * 导出肉商列表
- */
- @PreAuthorize("@ss.hasPermi('app:purchaser:export')")
- @Log(title = "肉商", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, ReqPurchaser purchaser)
- {
- List<Purchaser> list = purchaserService.selectPurchaserList(purchaser);
- ExcelUtil<Purchaser> util = new ExcelUtil<Purchaser>(Purchaser.class);
- util.exportExcel(response, list, "肉商数据");
- }
- /**
- * 获取肉商详细信息
- */
- @ApiOperation("获取肉商详细信息")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return success(purchaserService.selectPurchaserById(id));
- }
- /**
- * 新增肉商
- */
- @ApiOperation("新增肉商")
- @PreAuthorize("@ss.hasPermi('app:purchaser:add')")
- @Log(title = "肉商", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@Validated @RequestBody Purchaser purchaser)
- {
- // if (!purchaserService.checkPurchaserNoUnique(purchaser))
- // {
- // return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商编号");
- // }
- if (!purchaserService.checkPurchaserNameUnique(purchaser))
- {
- return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商名称");
- }
- if (!purchaserService.checkIDNumberUnique(purchaser))
- {
- return error("新增肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的身份证号");
- }
- purchaser.setCreateBy(getUsername());
- return toAjax(purchaserService.insertPurchaser(purchaser));
- }
- /**
- * 修改肉商
- */
- @ApiOperation("修改肉商")
- @PreAuthorize("@ss.hasPermi('app:purchaser:edit')")
- @Log(title = "肉商", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@Validated @RequestBody Purchaser purchaser)
- {
- if (!purchaserService.checkPurchaserNoUnique(purchaser))
- {
- return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商编号");
- }
- if (!purchaserService.checkPurchaserNameUnique(purchaser))
- {
- return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的肉商名称");
- }
- if (!purchaserService.checkIDNumberUnique(purchaser))
- {
- return error("修改肉商'" + purchaser.getPurchaserName() + "'失败,列表中存在重复的身份证号");
- }
- purchaser.setUpdateBy(getUsername());
- return toAjax(purchaserService.updatePurchaser(purchaser));
- }
- /**
- * 删除肉商
- */
- @ApiOperation("删除肉商")
- @PreAuthorize("@ss.hasPermi('app:purchaser:remove')")
- @Log(title = "肉商", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(purchaserService.deletePurchaserByIds(ids));
- }
- @ApiOperation("查询自动生成的肉商编号")
- @GetMapping("/nextNo")
- public AjaxResult nextNo()
- {
- return success(new HashMap<String, String>() {{ put("nextNo", purchaserService.getNextNo());}});
- }
- }
|