package org.jeecg.modules.mes.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.modules.eam.constant.BusinessCodeConst; import org.jeecg.modules.mes.entity.MesMaterialTransferRequest; import org.jeecg.modules.mes.enums.MaterialTransferPublishStatus; import org.jeecg.modules.mes.service.IMesMaterialTransferRequestService; import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; /** * @Description: 物料拉动申请 * @Author: jeecg-boot * @Date: 2025-07-04 * @Version: V1.0 */ @Api(tags = "物料拉动申请") @RestController @RequestMapping("/mes/mesMaterialTransferRequest") @Slf4j public class MesMaterialTransferRequestController extends JeecgController { @Autowired private IMesMaterialTransferRequestService mesMaterialTransferRequestService; @Autowired private ISysBusinessCodeRuleService businessCodeRuleService; /** * 分页列表查询 * * @param mesMaterialTransferRequest * @param pageNo * @param pageSize * @param req * @return */ //@AutoLog(value = "物料拉动申请-分页列表查询") @ApiOperation(value = "物料拉动申请-分页列表查询", notes = "物料拉动申请-分页列表查询") @GetMapping(value = "/list") public Result> queryPageList(MesMaterialTransferRequest mesMaterialTransferRequest, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(mesMaterialTransferRequest, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = mesMaterialTransferRequestService.page(page, queryWrapper); return Result.OK(pageList); } /** * 添加 * * @param request * @return */ @AutoLog(value = "物料拉动申请-添加") @ApiOperation(value = "物料拉动申请-添加", notes = "物料拉动申请-添加") @PostMapping(value = "/add") public Result add(@RequestBody MesMaterialTransferRequest request) { String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MATERIAL_TRANSFER_CODE_RULE); request.setRequestCode(codeSeq); boolean b = mesMaterialTransferRequestService.addMaterialTransferRequest(request); if (!b) { return Result.error("添加失败!"); } return Result.OK("添加成功!"); } /** * 编辑 * * @param mesMaterialTransferRequest * @return */ @AutoLog(value = "物料拉动申请-编辑") @ApiOperation(value = "物料拉动申请-编辑", notes = "物料拉动申请-编辑") @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) public Result edit(@RequestBody MesMaterialTransferRequest mesMaterialTransferRequest) { mesMaterialTransferRequestService.updateById(mesMaterialTransferRequest); return Result.OK("编辑成功!"); } /** * 通过id删除 * * @param id * @return */ @AutoLog(value = "物料拉动申请-通过id删除") @ApiOperation(value = "物料拉动申请-通过id删除", notes = "物料拉动申请-通过id删除") @DeleteMapping(value = "/delete") public Result delete(@RequestParam(name = "id", required = true) String id) { MesMaterialTransferRequest entity = mesMaterialTransferRequestService.getById(id); if (entity == null) { return Result.error("删除的数据不存在,请刷新重试!"); } if (!MaterialTransferPublishStatus.WAIT_PUBLISH.name().equals(entity.getPublishStatus())) { return Result.error("数据已发布,无法删除!"); } entity.setDelFlag(CommonConstant.DEL_FLAG_1); mesMaterialTransferRequestService.updateById(entity); return Result.OK("删除成功!"); } /** * 批量删除 * * @param ids * @return */ @AutoLog(value = "物料拉动申请-批量删除") @ApiOperation(value = "物料拉动申请-批量删除", notes = "物料拉动申请-批量删除") @DeleteMapping(value = "/deleteBatch") public Result deleteBatch(@RequestParam(name = "ids", required = true) String ids) { if (StringUtils.isBlank(ids)) { return Result.error("参数错误!"); } String[] split = ids.split(","); for (String id : split) { MesMaterialTransferRequest entity = mesMaterialTransferRequestService.getById(id); if (entity == null || !MaterialTransferPublishStatus.WAIT_PUBLISH.name().equals(entity.getPublishStatus())) { //不做处理 continue; } entity.setDelFlag(CommonConstant.DEL_FLAG_1); mesMaterialTransferRequestService.updateById(entity); } return Result.OK("批量删除成功!"); } /** * 通过id查询 * * @param id * @return */ //@AutoLog(value = "物料拉动申请-通过id查询") @ApiOperation(value = "物料拉动申请-通过id查询", notes = "物料拉动申请-通过id查询") @GetMapping(value = "/queryById") public Result queryById(@RequestParam(name = "id", required = true) String id) { MesMaterialTransferRequest mesMaterialTransferRequest = mesMaterialTransferRequestService.getById(id); if (mesMaterialTransferRequest == null) { return Result.error("未找到对应数据"); } return Result.OK(mesMaterialTransferRequest); } /** * 通过id发布 * * @param id * @return */ @AutoLog(value = "物料拉动申请-发布") @ApiOperation(value = "物料拉动申请-发布", notes = "物料拉动申请-发布") @PutMapping(value = "/publish") public Result publish(@RequestParam(name = "id", required = true) String id) { boolean b = mesMaterialTransferRequestService.publish(id); if (!b) { return Result.error("发布失败!"); } return Result.OK("发布成功!"); } /** * 批量发布 * * @param ids * @return */ @AutoLog(value = "物料拉动申请-批量发布") @ApiOperation(value = "物料拉动申请-批量发布", notes = "物料拉动申请-批量发布") @PutMapping(value = "/publishBatch") public Result publishBatch(@RequestParam(name = "ids", required = true) String ids) { if (StringUtils.isBlank(ids)) { return Result.error("参数错误!"); } String[] split = ids.split(","); int count = 0; for (String id : split) { try { boolean b = mesMaterialTransferRequestService.publish(id); if(b) { count++; } } catch (Exception e) { log.error(e.getMessage(), e); } } return Result.OK("成功发布" + count + "条数据!"); } /** * 通过id请求WMS * * @param id * @return */ @AutoLog(value = "物料拉动申请-请求WMS") @ApiOperation(value = "物料拉动申请-请求WMS", notes = "物料拉动申请-请求WMS") @PutMapping(value = "/request") public Result request(@RequestParam(name = "id", required = true) String id) { boolean b = mesMaterialTransferRequestService.request(id); if (!b) { return Result.error("请求失败!"); } return Result.OK("请求成功!"); } /** * 批量请求WMS * * @param ids * @return */ @AutoLog(value = "物料拉动申请-批量请求WMS") @ApiOperation(value = "物料拉动申请-批量请求WMS", notes = "物料拉动申请-批量请求WMS") @PutMapping(value = "/requestBatch") public Result requestBatch(@RequestParam(name = "ids", required = true) String ids) { if (StringUtils.isBlank(ids)) { return Result.error("参数错误!"); } String[] split = ids.split(","); int count = 0; for (String id : split) { try { boolean b = mesMaterialTransferRequestService.request(id); if(b) { count++; } } catch (Exception e) { log.error(e.getMessage(), e); } } return Result.OK("成功请求WMS" + count + "条数据!"); } /* * 通过workOrderId 查询mesMaterialTransferRequest数据 *@param workOrderId * */ @GetMapping(value = "/queryMaterialTransferRequestByWorkOrderId") public Result queryMaterialTransferRequestByWorkOrderId(@RequestParam(name = "workOrderId", required = true) String workOrderId) { return Result.OK(mesMaterialTransferRequestService.queryMaterialTransferRequestByWorkOrderId(workOrderId)); } }