package com.ruoyi.web.controller.app; import java.util.*; import javax.servlet.http.HttpServletResponse; import com.ruoyi.app.DTO.HookBindBatchListDTO; import com.ruoyi.app.domain.request.AddHookBindBatch; import com.ruoyi.app.domain.request.EditHookBindBatch; import com.ruoyi.app.domain.request.ReqHookBindDetail; import com.ruoyi.app.domain.request.ReqHookBindList; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; 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.domain.HookBind; import com.ruoyi.app.service.IHookBindService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; import static com.ruoyi.common.utils.uuid.IdUtils.fastSimpleUUID; /** * 吊钩绑定Controller * * @author coede * @date 2025-03-19 */ @Api("吊钩绑定信息管理") @RestController @RequestMapping("/app/hookBind") public class HookBindController extends BaseController { @Autowired private IHookBindService hookBindService; /** * 查询吊钩绑定列表 */ @ApiOperation("查询吊钩绑定列表") @GetMapping("/list") public TableDataInfo list(HookBind hookBind) { startPage(); List list = hookBindService.selectHookBindList(hookBind); return getDataTable(list); } /** * 按批次查询吊钩绑定列表 */ @ApiOperation("按批次查询吊钩绑定列表") @GetMapping("/batchList") public TableDataInfo batchList(ReqHookBindList req) { startPage(); List list = hookBindService.selectHookBindListByBatch(req); return getDataTable(list); } /** * 导出吊钩绑定列表 */ @ApiOperation("导出吊钩绑定列表") @PreAuthorize("@ss.hasPermi('app:hookBind:export')") @Log(title = "吊钩绑定", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, HookBind hookBind) { List list = hookBindService.selectHookBindList(hookBind); ExcelUtil util = new ExcelUtil(HookBind.class); util.exportExcel(response, list, "吊钩绑定数据"); } /** * 获取吊钩绑定详细信息 */ @ApiOperation("获取吊钩绑定详细信息") @GetMapping(value = "/group") public AjaxResult getGroupInfo(@Validated ReqHookBindDetail req) { return success(hookBindService.selectHookBindByBatch(req.getGroupId())); } /** * 获取吊钩绑定详细信息 */ @ApiOperation("获取吊钩绑定详细信息") @GetMapping(value = "/detail/{hookNo}") public AjaxResult getDetail(@PathVariable("hookNo") String hookNo) { return success(hookBindService.selectHookBindDetail(hookNo)); } /** * 新增吊钩绑定 暂时不用 */ @ApiOperation("新增吊钩绑定 暂时不用") @PreAuthorize("@ss.hasPermi('app:hookBind:add')") @Log(title = "吊钩绑定", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody HookBind hookBind) { hookBind.setCreateBy(getUsername()); return toAjax(hookBindService.insertHookBind(hookBind)); } /** * 新增吊钩批量绑定 */ @ApiOperation("新增吊钩批量绑定") @PreAuthorize("@ss.hasPermi('app:hookBind:add')") @Log(title = "吊钩绑定", businessType = BusinessType.INSERT) @PostMapping("/addBatch") public AjaxResult addBatch(@Validated @RequestBody AddHookBindBatch req) { //生成新对象 String[] hooks = req.getHookNoList().split(","); List hookBindArr = new ArrayList<>(); String batchNo = fastSimpleUUID(); //先判断本身数组内是否有重复的 Set uniqueIds = new HashSet<>(); //未传绑定时间默认当前时间 if(req.getBindTime() == null){ req.setBindTime(DateUtils.getNowDate()); } for(String hook : hooks){ //noinspection ConstantConditions 忽略错误的IDEA提示 if (!uniqueIds.add(hook)) { return error("新增吊钩批量绑定,本次添加存在相同的吊钩号"); } HookBind hookBind = new HookBind(); hookBind.setBatchNo(batchNo); hookBind.setHookNo(hook); hookBind.setBindTime(req.getBindTime()); hookBind.setDistributeBatchId(req.getDistributeBatchId()); hookBind.setSlaughterCode(req.getSlaughterCode()); hookBind.setCreateTime(DateUtils.getNowDate()); hookBind.setCreateBy(getUsername()); hookBindArr.add(hookBind); } //校验数据库的 for (HookBind hookBind : hookBindArr) { HookBind check = hookBindService.checkHookNoUnique(hookBind); if (StringUtils.isNotNull(check)) { return error("新增吊钩批量绑定失败,'" + check.getHookNo() + "'同一时间已存在绑定"); } } return toAjax(hookBindService.insertHookBindBatch(hookBindArr)); } /** * 修改吊钩绑定 */ @ApiOperation("修改吊钩绑定") @PreAuthorize("@ss.hasPermi('app:hookBind:edit')") @Log(title = "吊钩绑定", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@Validated @RequestBody HookBind hookBind) { hookBind.setUpdateBy(getUsername()); return toAjax(hookBindService.updateHookBind(hookBind)); } /** * 批量修改吊钩绑定 */ @ApiOperation("批量修改吊钩绑定") @PreAuthorize("@ss.hasPermi('app:hookBind:edit')") @Log(title = "吊钩绑定", businessType = BusinessType.UPDATE) @PostMapping("/editBatch") public AjaxResult editBatch(@Validated @RequestBody EditHookBindBatch req) { req.setUpdateBy(getUsername()); return toAjax(hookBindService.updateHookBindBatch(req)); } /** * 删除吊钩绑定 */ @ApiOperation("删除吊钩绑定") @PreAuthorize("@ss.hasPermi('app:hookBind:remove')") @Log(title = "吊钩绑定", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable String[] ids) { return toAjax(hookBindService.deleteHookBindByIds(ids)); } }