| | |
| | | package org.jeecg.modules.mes.controller; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | 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 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.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: 排产工单 |
| | |
| | | @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
| | | @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | | QueryWrapper<MesProductionWorkOrder> queryWrapper = QueryGenerator.initQueryWrapper(mesProductionWorkOrder, req.getParameterMap()); |
| | | Map<String, String[]> parameterMap = req.getParameterMap(); |
| | | QueryWrapper<MesProductionWorkOrder> queryWrapper = QueryGenerator.initQueryWrapper(mesProductionWorkOrder, parameterMap); |
| | | String[] startDates = parameterMap.get("startDate"); |
| | | String[] endDates = parameterMap.get("endDate"); |
| | | if (startDates != null && startDates.length > 0) { |
| | | queryWrapper.ge("work_order_date", startDates[0]); |
| | | } |
| | | if (endDates != null && endDates.length > 0) { |
| | | queryWrapper.le("work_order_date", endDates[0]); |
| | | } |
| | | Page<MesProductionWorkOrder> page = new Page<MesProductionWorkOrder>(pageNo, pageSize); |
| | | IPage<MesProductionWorkOrder> pageList = mesProductionWorkOrderService.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | |
| | | public Result<String> add(@RequestBody MesProductionWorkOrder mesProductionWorkOrder) { |
| | | mesProductionWorkOrderService.save(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 -> item.setWorkOrderStatus(ProductionWorkOrderStatus.NEW.name())); |
| | | mesProductionWorkOrderService.saveBatch(mesProductionWorkOrderList); |
| | | 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; |
| | | } |
| | | |
| | | @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)); |
| | | } |
| | | |
| | | @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("发布成功"); |
| | | } |
| | | |
| | | @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("重发布成功!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return super.importExcel(request, response, MesProductionWorkOrder.class); |
| | | } |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | try { |
| | | return (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | } |