| | |
| | | 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.exception.JeecgBootException; |
| | | 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.eam.constant.MaintenanceCategoryEnum; |
| | | import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrder; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrderDetail; |
| | | import org.jeecg.modules.eam.entity.EamProcessCheck; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.mes.dto.MesProductionWorkOrderRepublishRequest; |
| | | import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest; |
| | | import org.jeecg.modules.mes.entity.MesKittingCompletenessCheck; |
| | | import org.jeecg.modules.mes.entity.MesProductionWorkOrder; |
| | | import org.jeecg.modules.mes.enums.ProductionWorkOrderStatus; |
| | | import org.jeecg.modules.mes.service.IMesKittingCompletenessCheckService; |
| | | import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; |
| | | import org.jeecg.modules.mes.utils.CommonUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | */ |
| | | @Api(tags = "排产工单") |
| | | @RestController |
| | | @RequestMapping("/mesproductionworkorder/mesProductionWorkOrder") |
| | | @RequestMapping("/mes/mesProductionWorkOrder") |
| | | @Slf4j |
| | | public class MesProductionWorkOrderController extends JeecgController<MesProductionWorkOrder, IMesProductionWorkOrderService> { |
| | | @Autowired |
| | | private IMesProductionWorkOrderService mesProductionWorkOrderService; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | private IMesKittingCompletenessCheckService mesKittingCompletenessCheckService; |
| | | @Autowired |
| | | private TranslateDictTextUtils translateDictTextUtils; |
| | | private IEamInspectionOrderService eamInspectionOrderService; |
| | | @Autowired |
| | | private IEamInspectionOrderDetailService eamInspectionOrderDetailService; |
| | | @Autowired |
| | | private IEamProcessCheckService eamProcessCheckService; |
| | | @Autowired |
| | | private IEamProcessCheckDetailService eamProcessCheckDetailService; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | |
| | | //@AutoLog(value = "排产工单-分页列表查询") |
| | | @ApiOperation(value = "排产工单-分页列表查询", notes = "排产工单-分页列表查询") |
| | | @GetMapping(value = "/list") |
| | | public Result<IPage<?>> queryPageList(MesProductionWorkOrder mesProductionWorkOrder, |
| | | public Result<IPage<MesProductionWorkOrder>> queryPageList(MesProductionWorkOrder mesProductionWorkOrder, |
| | | @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, |
| | | HttpServletRequest req) { |
| | |
| | | mesProductionWorkOrderList.forEach(item -> { |
| | | if (Objects.isNull(item.getId())) { |
| | | item.setWorkOrderStatus(ProductionWorkOrderStatus.NEW.name()); |
| | | item.setCompletenessCheckFlag(CommonConstant.DEFAULT_0); |
| | | item.setEquipmentInspectionFlag(CommonConstant.DEFAULT_0); |
| | | item.setProcessInspectionFlag(CommonConstant.DEFAULT_0); |
| | | item.setActualQuantity(BigDecimal.ZERO); |
| | | item.setFinishedPallets(0); |
| | | } |
| | | }); |
| | | mesProductionWorkOrderService.saveOrUpdateBatch(mesProductionWorkOrderList); |
| | |
| | | |
| | | @AutoLog(value = "排产工单-发布排产计划") |
| | | @ApiOperation(value = "排产工单-发布排产计划", notes = "排产工单-发布排产计划") |
| | | //@RequiresPermissions("mes:production:work:order:publish") |
| | | //@RequiresPermissions("org.jeecg.modules: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(",")); |
| | |
| | | MesProductionWorkOrder publish = new MesProductionWorkOrder() |
| | | .setId(id) |
| | | .setPublishTime(new Date()) |
| | | .setPublisher(Objects.requireNonNull(getCurrentUser()).getUsername()) |
| | | .setPublisher(Objects.requireNonNull(CommonUtils.getCurrentUser()).getUsername()) |
| | | .setWorkOrderStatus(ProductionWorkOrderStatus.PUBLISHED.name()); |
| | | publishList.add(publish); |
| | | }); |
| | |
| | | |
| | | @AutoLog(value = "排产工单-重发布排产计划") |
| | | @ApiOperation(value="排产工单-重发布排产计划", notes="重发布排产计划") |
| | | //@RequiresPermissions("mes:production:work:order:republish") |
| | | //@RequiresPermissions("org.jeecg.modules: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())) { |
| | | if (ProductionWorkOrderStatus.NEW.name().equals(workOrder.getWorkOrderStatus()) |
| | | || ProductionWorkOrderStatus.CLOSED.name().equals(workOrder.getWorkOrderStatus())) { |
| | | return Result.error("当前工单状态不支持重发布!"); |
| | | } |
| | | MesProductionWorkOrder republish = new MesProductionWorkOrder() |
| | | .setId(request.getId()) |
| | | .setPlanQuantity(request.getPlanQuantity()) |
| | | .setRepublisher(Objects.requireNonNull(getCurrentUser()).getUsername()) |
| | | .setRepublisher(Objects.requireNonNull(Objects.requireNonNull(CommonUtils.getCurrentUser()).getUsername())) |
| | | .setRepublishTime(new Date()) |
| | | .setRepublishReason(request.getRepublishReason()) |
| | | .setWorkOrderStatus(ProductionWorkOrderStatus.REPUBLISHED.name()); |
| | | .setRepublishReason(request.getRepublishReason()); |
| | | mesProductionWorkOrderService.updateById(republish); |
| | | return Result.ok("重发布成功!"); |
| | | } |
| | | |
| | | @AutoLog(value = "排产工单-齐套性检查") |
| | | @ApiOperation(value="排产工单-齐套性检查", notes="齐套性检查") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:workOrderCompletenessCheck") |
| | | @GetMapping(value = "/workOrderCompletenessCheck") |
| | | public Result<List<MesKittingCompletenessCheck>> workOrderCompletenessCheck(@RequestParam("id") String id) { |
| | | MesProductionWorkOrder workOrder = mesProductionWorkOrderService.getById(id); |
| | | if (workOrder == null) { |
| | | return Result.error("工单不存在!"); |
| | | } |
| | | if (!ProductionWorkOrderStatus.PUBLISHED.name().equals(workOrder.getWorkOrderStatus())) { |
| | | return Result.error("当前工单状态不能进行齐套性检查!"); |
| | | } |
| | | List<MesKittingCompletenessCheck> list = mesProductionWorkOrderService.workOrderCompletenessCheck(workOrder); |
| | | return Result.ok(list); |
| | | } |
| | | |
| | | @AutoLog(value = "排产工单-执行排产工单计划") |
| | | @ApiOperation(value = "排产工单-执行排产工单计划", notes = "排产工单-执行排产工单计划") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:execute") |
| | | @GetMapping(value = "/execute") |
| | | public Result<?> execute(@RequestParam("id") String id) { |
| | | MesProductionWorkOrder workOrder = mesProductionWorkOrderService.getById(id); |
| | | if (!ProductionWorkOrderStatus.PUBLISHED.name().equals(workOrder.getWorkOrderStatus())) { |
| | | return Result.error("当前工单状态不能执行!"); |
| | | } |
| | | //检查是否做过齐套性检查、工艺点检、设备点检 |
| | | if (!completeCheck(workOrder)) { |
| | | return Result.error("请先完成齐套性检查、工艺点检、设备点检!"); |
| | | } |
| | | MesProductionWorkOrder executeOrder = new MesProductionWorkOrder() |
| | | .setId(id) |
| | | .setWorkOrderStatus(ProductionWorkOrderStatus.EXECUTING.name()); |
| | | mesProductionWorkOrderService.updateById(executeOrder); |
| | | return Result.ok("执行成功!"); |
| | | } |
| | | |
| | | private boolean completeCheck(MesProductionWorkOrder workOrder) { |
| | | List<MesKittingCompletenessCheck> completenessCheckList = mesKittingCompletenessCheckService.list(new LambdaQueryWrapper<MesKittingCompletenessCheck>() |
| | | .eq(MesKittingCompletenessCheck::getWorkOrderId, workOrder.getId())); |
| | | if (completenessCheckList.isEmpty()) { |
| | | return false; |
| | | } |
| | | List<EamInspectionOrder> inspectionOrderList = eamInspectionOrderService.list(new LambdaQueryWrapper<EamInspectionOrder>() |
| | | .eq(EamInspectionOrder::getWorkOrderId, workOrder.getId())); |
| | | if (inspectionOrderList.isEmpty()) { |
| | | return false; |
| | | } |
| | | List<EamProcessCheck> processCheckList = eamProcessCheckService.list(new LambdaQueryWrapper<EamProcessCheck>() |
| | | .eq(EamProcessCheck::getWorkOrderId, workOrder.getId())); |
| | | if (processCheckList.isEmpty()) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @AutoLog(value = "排产工单-工单执行前检查") |
| | | @ApiOperation(value = "排产工单-工单执行前检查", notes = "排产工单-工单执行前检查") |
| | | //@RequiresPermissions("org.jeecg.modules:mes_production_work_order:execute") |
| | | @GetMapping(value = "/checkBeforeExecute") |
| | | public Result<?> checkBeforeExecute(@RequestParam("id") String id) { |
| | | MesProductionWorkOrder workOrder = mesProductionWorkOrderService.getById(id); |
| | | if (workOrder == null) { |
| | | throw new JeecgBootException("工单不存在!"); |
| | | } |
| | | Map<String, Object> resMap = new HashMap<>(); |
| | | //齐套性检查 |
| | | List<MesKittingCompletenessCheck> completenessCheckList = mesKittingCompletenessCheckService.list(new LambdaQueryWrapper<MesKittingCompletenessCheck>() |
| | | .eq(MesKittingCompletenessCheck::getWorkOrderId, id)); |
| | | if (completenessCheckList.isEmpty()) { |
| | | //未执行过齐套性检查 |
| | | resMap.put("completenessCheckFlag", false); |
| | | } else { |
| | | List<MesKittingCompletenessCheck> unCompletenessList = completenessCheckList.stream().filter(i -> !CommonConstant.DEFAULT_1.equals(i.getCheckFlag())) |
| | | .collect(Collectors.toList()); |
| | | if (unCompletenessList.isEmpty()) { |
| | | //齐套性检查全部通过 |
| | | resMap.put("completenessCheckFlag", true); |
| | | } else { |
| | | List<String> unCompletenessListMaterial = unCompletenessList.stream() |
| | | .map(i -> i.getMaterialNumber() + "[" + i.getMaterialName() + "]").collect(Collectors.toList()); |
| | | //存在未通过 |
| | | resMap.put("completenessCheckFlag", false); |
| | | resMap.put("unCompletenessCheckList", unCompletenessListMaterial); |
| | | } |
| | | } |
| | | //设备点检 |
| | | List<EamInspectionOrder> inspectionOrderList = eamInspectionOrderService.list(new LambdaQueryWrapper<EamInspectionOrder>() |
| | | .eq(EamInspectionOrder::getWorkOrderId, workOrder.getId())); |
| | | if (inspectionOrderList.isEmpty()) { |
| | | //未执行过设备点检 |
| | | resMap.put("inspectionFlag", false); |
| | | } else { |
| | | List<String> unInspectEquipmentList = eamEquipmentService.list(new LambdaQueryWrapper<EamEquipment>() |
| | | .eq(EamEquipment::getOrgId, workOrder.getFactoryId()) |
| | | .eq(EamEquipment::getDelFlag, CommonConstant.DEL_FLAG_0) |
| | | .apply("NOT EXISTS (SELECT 1 FROM eam_inspection_order t WHERE t.equipment_id = eam_equipment.id AND t.work_order_id = {0})", workOrder.getId()) |
| | | .apply("EXISTS (SELECT 1 FROM eam_maintenance_standard t WHERE t.equipment_id = eam_equipment.id AND t.del_flag = {0} " + |
| | | "AND t.standard_status = {1} AND t.maintenance_category = {2})", |
| | | CommonConstant.DEL_FLAG_0, MaintenanceStandardStatusEnum.NORMAL.name(), MaintenanceCategoryEnum.POINT_INSPECTION.name())) |
| | | .stream().map(e -> e.getEquipmentCode() + "[" + e.getEquipmentName() + "]").collect(Collectors.toList()); |
| | | if (unInspectEquipmentList.isEmpty()) { |
| | | //全部设备都已点检 |
| | | resMap.put("equipmentInspectFlag", true); |
| | | } else { |
| | | //存在未点检的设备 |
| | | resMap.put("equipmentInspectFlag", false); |
| | | resMap.put("unInspectEquipmentList", unInspectEquipmentList); |
| | | } |
| | | } |
| | | //工艺点检 |
| | | List<EamProcessCheck> processCheckList = eamProcessCheckService.list(new LambdaQueryWrapper<EamProcessCheck>() |
| | | .eq(EamProcessCheck::getWorkOrderId, workOrder.getId())); |
| | | if (processCheckList.isEmpty()) { |
| | | //未执行过工艺点检 |
| | | resMap.put("processCheckFlag", false); |
| | | } else { |
| | | List<String> unCheckEquipmentList = eamEquipmentService.list(new LambdaQueryWrapper<EamEquipment>() |
| | | .eq(EamEquipment::getOrgId, workOrder.getFactoryId()) |
| | | .eq(EamEquipment::getDelFlag, CommonConstant.DEL_FLAG_0) |
| | | .apply("EXISTS (SELECT 1 FROM eam_equipment_process_parameters t WHERE t.equipment_id = eam_equipment.id)") |
| | | .apply("NOT EXISTS (SELECT 1 FROM eam_process_check t WHERE t.equipment_id = eam_equipment.id AND t.work_order_id = {0})", workOrder.getId())) |
| | | .stream().map(e -> e.getEquipmentCode() + "[" + e.getEquipmentName() + "]").collect(Collectors.toList()); |
| | | if (unCheckEquipmentList.isEmpty()) { |
| | | //全部设备都已点检 |
| | | resMap.put("processCheckFlag", true); |
| | | } else { |
| | | //存在未点检的设备 |
| | | resMap.put("processCheckFlag", false); |
| | | resMap.put("unCheckEquipmentList", unCheckEquipmentList); |
| | | } |
| | | } |
| | | return Result.ok(resMap); |
| | | } |
| | | |
| | | /** |
| | |
| | | return super.importExcel(request, response, MesProductionWorkOrder.class); |
| | | } |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | try { |
| | | return (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | } |