| | |
| | | package org.jeecg.modules.mes.controller; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authz.annotation.RequiresPermissions; |
| | | 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.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.TranslateDictTextUtils; |
| | | import org.jeecg.modules.mes.dto.MesProductionWorkOrderRepublishRequest; |
| | | import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest; |
| | | import org.jeecg.modules.mes.entity.MesProductionWorkOrder; |
| | | import org.jeecg.modules.mes.enums.ProductionWorkOrderStatus; |
| | | import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Arrays; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 排产工单 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-04 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Api(tags="排产工单") |
| | | * @Description: 排产工单 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-04 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Api(tags = "排产工单") |
| | | @RestController |
| | | @RequestMapping("/mesproductionworkorder/mesProductionWorkOrder") |
| | | @Slf4j |
| | | public class MesProductionWorkOrderController extends JeecgController<MesProductionWorkOrder, IMesProductionWorkOrderService> { |
| | | @Autowired |
| | | private IMesProductionWorkOrderService mesProductionWorkOrderService; |
| | | @Autowired |
| | | private IMesProductionWorkOrderService mesProductionWorkOrderService; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | @Autowired |
| | | private TranslateDictTextUtils translateDictTextUtils; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param req |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "排产工单-分页列表查询") |
| | | @ApiOperation(value="排产工单-分页列表查询", notes="排产工单-分页列表查询") |
| | | @GetMapping(value = "/list") |
| | | public Result<IPage<MesProductionWorkOrder>> queryPageList(MesProductionWorkOrder mesProductionWorkOrder, |
| | | @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
| | | @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<MesProductionWorkOrder> queryWrapper = QueryGenerator.initQueryWrapper(mesProductionWorkOrder, req.getParameterMap()); |
| | | Page<MesProductionWorkOrder> page = new Page<MesProductionWorkOrder>(pageNo, pageSize); |
| | | IPage<MesProductionWorkOrder> pageList = mesProductionWorkOrderService.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | | } |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param req |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "排产工单-分页列表查询") |
| | | @ApiOperation(value = "排产工单-分页列表查询", notes = "排产工单-分页列表查询") |
| | | @GetMapping(value = "/list") |
| | | public Result<IPage<?>> queryPageList(MesProductionWorkOrder mesProductionWorkOrder, |
| | | @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | Map<String, String[]> parameterMap = req.getParameterMap(); |
| | | QueryWrapper<MesProductionWorkOrder> queryWrapper = QueryGenerator.initQueryWrapper(mesProductionWorkOrder, parameterMap); |
| | | Page<MesProductionWorkOrder> page = new Page<MesProductionWorkOrder>(pageNo, pageSize); |
| | | IPage<MesProductionWorkOrder> pageList = mesProductionWorkOrderService.queryPageList(page, parameterMap); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-添加") |
| | | @ApiOperation(value="排产工单-添加", notes="排产工单-添加") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:add") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody MesProductionWorkOrder mesProductionWorkOrder) { |
| | | mesProductionWorkOrderService.save(mesProductionWorkOrder); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-添加") |
| | | @ApiOperation(value = "排产工单-添加", notes = "排产工单-添加") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:add") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody MesProductionWorkOrder mesProductionWorkOrder) { |
| | | mesProductionWorkOrderService.save(mesProductionWorkOrder); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-编辑") |
| | | @ApiOperation(value="排产工单-编辑", notes="排产工单-编辑") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:edit") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| | | public Result<String> edit(@RequestBody MesProductionWorkOrder mesProductionWorkOrder) { |
| | | mesProductionWorkOrderService.updateById(mesProductionWorkOrder); |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | @AutoLog(value = "排产工单-保存排产计划") |
| | | @ApiOperation(value = "排产工单-保存排产计划", notes = "排产工单-保存排产计划") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:saveSchedulePlan") |
| | | @PostMapping("/addSchedulePlan") |
| | | public Result<String> addSchedulePlan(@RequestBody List<MesProductionWorkOrder> mesProductionWorkOrderList) { |
| | | if (!validatePlan(mesProductionWorkOrderList)) { |
| | | return Result.error("排产计划不合理,保存失败!"); |
| | | } |
| | | mesProductionWorkOrderList.forEach(item -> { |
| | | if (Objects.isNull(item.getId())) { |
| | | item.setWorkOrderStatus(ProductionWorkOrderStatus.NEW.name()); |
| | | } |
| | | }); |
| | | mesProductionWorkOrderService.saveOrUpdateBatch(mesProductionWorkOrderList); |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-通过id删除") |
| | | @ApiOperation(value="排产工单-通过id删除", notes="排产工单-通过id删除") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:delete") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<String> delete(@RequestParam(name="id",required=true) String id) { |
| | | mesProductionWorkOrderService.removeById(id); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | | private boolean validatePlan(List<MesProductionWorkOrder> mesProductionWorkOrderList) { |
| | | //同一物料、同一日期下、只能存在一个班次 |
| | | Map<String, List<MesProductionWorkOrder>> orderMapByMaterial = mesProductionWorkOrderList.stream() |
| | | .collect(Collectors.groupingBy(MesProductionWorkOrder::getMaterialNumber)); |
| | | for (String materialNumber : orderMapByMaterial.keySet()) { |
| | | List<MesProductionWorkOrder> workOrderList = orderMapByMaterial.get(materialNumber); |
| | | Map<Date, List<MesProductionWorkOrder>> orderMapByDate = workOrderList.stream() |
| | | .collect(Collectors.groupingBy(MesProductionWorkOrder::getWorkOrderDate)); |
| | | for (Date date : orderMapByDate.keySet()) { |
| | | List<MesProductionWorkOrder> orderList = orderMapByDate.get(date); |
| | | Map<String, List<MesProductionWorkOrder>> orderMapByShift = orderList.stream() |
| | | .collect(Collectors.groupingBy(MesProductionWorkOrder::getShiftId)); |
| | | for (String shiftId : orderMapByShift.keySet()) { |
| | | List<MesProductionWorkOrder> list = orderMapByShift.get(shiftId); |
| | | if (list.size() > 1) { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-批量删除") |
| | | @ApiOperation(value="排产工单-批量删除", notes="排产工单-批量删除") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:deleteBatch") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { |
| | | this.mesProductionWorkOrderService.removeByIds(Arrays.asList(ids.split(","))); |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | | @AutoLog(value = "排产工单-生成排产计划") |
| | | @ApiOperation(value = "排产工单-生成排产计划", notes = "排产工单-生成排产计划") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:schedule") |
| | | @GetMapping(value = "/schedule") |
| | | public Result<?> schedule(MesProductionWorkScheduleRequest request) { |
| | | if (StringUtils.isBlank(request.getFactoryId()) |
| | | || Objects.isNull(request.getStartDate()) |
| | | || Objects.isNull(request.getEndDate())) { |
| | | return Result.error("请传入必要参数!"); |
| | | } |
| | | return Result.ok(mesProductionWorkOrderService.schedule(request)); |
| | | } |
| | | |
| | | /** |
| | | * 通过id查询 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "排产工单-通过id查询") |
| | | @ApiOperation(value="排产工单-通过id查询", notes="排产工单-通过id查询") |
| | | @GetMapping(value = "/queryById") |
| | | public Result<MesProductionWorkOrder> queryById(@RequestParam(name="id",required=true) String id) { |
| | | MesProductionWorkOrder mesProductionWorkOrder = mesProductionWorkOrderService.getById(id); |
| | | if(mesProductionWorkOrder==null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | return Result.OK(mesProductionWorkOrder); |
| | | } |
| | | @AutoLog(value = "排产工单-发布排产计划") |
| | | @ApiOperation(value = "排产工单-发布排产计划", notes = "排产工单-发布排产计划") |
| | | //@RequiresPermissions("mes:production:work:order:publish") |
| | | @RequestMapping(value = "/publish", method = {RequestMethod.POST, RequestMethod.PUT}) |
| | | public Result<String> publish(@RequestParam("ids") String ids) { |
| | | List<String> idList = Arrays.asList(ids.split(",")); |
| | | List<MesProductionWorkOrder> list = mesProductionWorkOrderService.list(new LambdaQueryWrapper<MesProductionWorkOrder>() |
| | | .in(MesProductionWorkOrder::getId, idList) |
| | | .eq(MesProductionWorkOrder::getDelFlag, CommonConstant.DEL_FLAG_0)).stream() |
| | | .filter(i -> !ProductionWorkOrderStatus.NEW.name().equals(i.getWorkOrderStatus())) |
| | | .collect(Collectors.toList()); |
| | | if (!list.isEmpty()) { |
| | | return Result.error("已发布的排产计划不能重复发布!"); |
| | | } |
| | | List<MesProductionWorkOrder> publishList = CollectionUtil.newArrayList(); |
| | | idList.forEach(id -> { |
| | | MesProductionWorkOrder publish = new MesProductionWorkOrder() |
| | | .setId(id) |
| | | .setPublishTime(new Date()) |
| | | .setPublisher(Objects.requireNonNull(getCurrentUser()).getUsername()) |
| | | .setWorkOrderStatus(ProductionWorkOrderStatus.PUBLISHED.name()); |
| | | publishList.add(publish); |
| | | }); |
| | | mesProductionWorkOrderService.updateBatchById(publishList); |
| | | return Result.OK("发布成功"); |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param request |
| | | * @param mesProductionWorkOrder |
| | | */ |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:exportXls") |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, MesProductionWorkOrder mesProductionWorkOrder) { |
| | | return super.exportXls(request, mesProductionWorkOrder, MesProductionWorkOrder.class, "排产工单"); |
| | | } |
| | | @AutoLog(value = "排产工单-重发布排产计划") |
| | | @ApiOperation(value="排产工单-重发布排产计划", notes="重发布排产计划") |
| | | //@RequiresPermissions("mes:production:work:order:republish") |
| | | @PostMapping(value = "/republish") |
| | | public Result<String> republish(@RequestBody MesProductionWorkOrderRepublishRequest request) { |
| | | MesProductionWorkOrder workOrder = mesProductionWorkOrderService.getById(request.getId()); |
| | | //todo 判断班次是否结束的逻辑 |
| | | if (!ProductionWorkOrderStatus.PUBLISHED.name().equals(workOrder.getWorkOrderStatus())) { |
| | | return Result.error("当前工单状态不支持重发布!"); |
| | | } |
| | | MesProductionWorkOrder republish = new MesProductionWorkOrder() |
| | | .setId(request.getId()) |
| | | .setPlanQuantity(request.getPlanQuantity()) |
| | | .setRepublisher(Objects.requireNonNull(getCurrentUser()).getUsername()) |
| | | .setRepublishTime(new Date()) |
| | | .setRepublishReason(request.getRepublishReason()) |
| | | .setWorkOrderStatus(ProductionWorkOrderStatus.REPUBLISHED.name()); |
| | | mesProductionWorkOrderService.updateById(republish); |
| | | return Result.ok("重发布成功!"); |
| | | } |
| | | |
| | | /** |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param mesProductionWorkOrder |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-编辑") |
| | | @ApiOperation(value = "排产工单-编辑", notes = "排产工单-编辑") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:edit") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) |
| | | public Result<String> edit(@RequestBody MesProductionWorkOrder mesProductionWorkOrder) { |
| | | mesProductionWorkOrderService.updateById(mesProductionWorkOrder); |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-通过id删除") |
| | | @ApiOperation(value = "排产工单-通过id删除", notes = "排产工单-通过id删除") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:delete") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<String> delete(@RequestParam(name = "id", required = true) String id) { |
| | | mesProductionWorkOrderService.removeById(id); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "排产工单-批量删除") |
| | | @ApiOperation(value = "排产工单-批量删除", notes = "排产工单-批量删除") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:deleteBatch") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { |
| | | this.mesProductionWorkOrderService.removeByIds(Arrays.asList(ids.split(","))); |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 通过id查询 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | //@AutoLog(value = "排产工单-通过id查询") |
| | | @ApiOperation(value = "排产工单-通过id查询", notes = "排产工单-通过id查询") |
| | | @GetMapping(value = "/queryById") |
| | | public Result<MesProductionWorkOrder> queryById(@RequestParam(name = "id", required = true) String id) { |
| | | MesProductionWorkOrder mesProductionWorkOrder = mesProductionWorkOrderService.getById(id); |
| | | if (mesProductionWorkOrder == null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | return Result.OK(mesProductionWorkOrder); |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param request |
| | | * @param mesProductionWorkOrder |
| | | */ |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:exportXls") |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, MesProductionWorkOrder mesProductionWorkOrder) { |
| | | return super.exportXls(request, mesProductionWorkOrder, MesProductionWorkOrder.class, "排产工单"); |
| | | } |
| | | |
| | | /** |
| | | * 通过excel导入数据 |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | //@RequiresPermissions("mes_production_work_order:importExcel") |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | return super.importExcel(request, response, MesProductionWorkOrder.class); |
| | | } |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | //@RequiresPermissions("mes_production_work_order:importExcel") |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | return super.importExcel(request, response, MesProductionWorkOrder.class); |
| | | } |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | try { |
| | | return (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | } |