|
|
@ -2,22 +2,35 @@ package org.nl.hand.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.acs.common.base.CommonFinalParam; |
|
|
|
import org.nl.acs.data.domain.Materialbase; |
|
|
|
import org.nl.acs.data.service.IMaterialbaseService; |
|
|
|
import org.nl.acs.device.domain.Device; |
|
|
|
import org.nl.acs.device.service.DeviceService; |
|
|
|
import org.nl.acs.order.mapper.OrderDetailMapper; |
|
|
|
import org.nl.acs.order.mapper.OrderMapper; |
|
|
|
import org.nl.acs.order.service.OrderService; |
|
|
|
import org.nl.acs.order.service.dto.OrderDetailDto; |
|
|
|
import org.nl.acs.order.service.dto.OrderDto; |
|
|
|
import org.nl.acs.point.domain.AcsPoint; |
|
|
|
import org.nl.acs.point.service.IAcsPointService; |
|
|
|
import org.nl.acs.sch.task.service.WorkService; |
|
|
|
import org.nl.acs.sch.task.service.dao.Work; |
|
|
|
import org.nl.acs.sch.task.service.dao.mapper.WorkMapper; |
|
|
|
import org.nl.acs.sch.task_manage.task.core.TaskStatus; |
|
|
|
import org.nl.acs.task.domain.Task; |
|
|
|
import org.nl.acs.task.service.TaskService; |
|
|
|
import org.nl.acs.task.service.dto.TaskDto; |
|
|
|
import org.nl.common.exception.BadRequestException; |
|
|
|
import org.nl.common.utils.CodeUtil; |
|
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
|
import org.nl.config.language.LangProcess; |
|
|
|
import org.nl.hand.service.PdaService; |
|
|
@ -25,16 +38,25 @@ import org.nl.hand.service.dao.dto.PdaDto; |
|
|
|
import org.nl.hand.service.dao.mapper.PdaMapper; |
|
|
|
import org.nl.hand.service.dao.vo.PdaResponseVo; |
|
|
|
import org.nl.hand.service.vo.OrderVo; |
|
|
|
import org.nl.hand.service.vo.PointVo; |
|
|
|
import org.nl.hand.service.vo.WorkVo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class PdaServiceImpl implements PdaService { |
|
|
|
|
|
|
|
private static final List<String> VALID_REGIONS = Arrays.asList("1", "2"); |
|
|
|
private static final List<String> VALID_STATUS = Arrays.asList("0", "1"); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OrderMapper orderMapper; |
|
|
|
@Autowired |
|
|
|
private OrderDetailMapper orderDetailMapper; |
|
|
|
@Autowired |
|
|
|
private PdaMapper pdaMapper; |
|
|
|
@Autowired |
|
|
@ -45,6 +67,14 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
private DeviceService deviceService; |
|
|
|
@Autowired |
|
|
|
private TaskService taskserver; |
|
|
|
@Autowired |
|
|
|
private IMaterialbaseService materialbaseService; |
|
|
|
@Autowired |
|
|
|
private WorkMapper workMapper; |
|
|
|
@Autowired |
|
|
|
private TaskService taskService; |
|
|
|
@Autowired |
|
|
|
private IAcsPointService acsPointService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<OrderVo> queryOrders() { |
|
|
@ -54,22 +84,54 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
@Override |
|
|
|
public PdaResponseVo startOrder(JSONObject whereJson) { |
|
|
|
String mfg_order_name = whereJson.getString("mfg_order_name"); |
|
|
|
if (StrUtil.isEmpty(mfg_order_name)){ |
|
|
|
return PdaResponseVo.pdaResultOk("工单号为空!"); |
|
|
|
} |
|
|
|
OrderDto dto = orderService.findByCode(mfg_order_name); |
|
|
|
if (ObjectUtil.isNull(dto)){ |
|
|
|
return PdaResponseVo.pdaResultOk("工单不存在"); |
|
|
|
} |
|
|
|
String currentUserId = SecurityUtils.getCurrentUserId(); |
|
|
|
String currentUsername = SecurityUtils.getCurrentUsername(); |
|
|
|
dto.setStatus("1"); |
|
|
|
dto.setRealstart_time(DateUtil.now()); |
|
|
|
dto.setUpdate_optid(currentUserId); |
|
|
|
dto.setUpdate_optname(currentUsername); |
|
|
|
dto.setUpdate_time(DateUtil.now()); |
|
|
|
orderService.updateById(dto); |
|
|
|
return PdaResponseVo.pdaResultOk("工单:[" + dto.getMfg_order_name() + "]已开始"); |
|
|
|
OrderDto orderDto = orderService.findByCode(mfg_order_name); |
|
|
|
if (ObjectUtil.isNull(orderDto)&& "0".equals(orderDto.getStatus())) { |
|
|
|
throw new BadRequestException("工单状态不为开始"); |
|
|
|
} |
|
|
|
orderDto.setStatus("1"); |
|
|
|
orderDto.setRealstart_time(DateUtil.now()); |
|
|
|
orderDto.setUpdate_optid(currentUserId); |
|
|
|
orderDto.setUpdate_optname(currentUsername); |
|
|
|
orderDto.setUpdate_time(DateUtil.now()); |
|
|
|
//生成配料任务
|
|
|
|
List<OrderDetailDto> list = orderDetailMapper.selectList(Wrappers.lambdaQuery(OrderDetailDto.class).eq(OrderDetailDto::getWorkorder_id, orderDto.getWorkorder_id())); |
|
|
|
Set<String> materialCodes = list.stream().map(OrderDetailDto::getMaterial_code).collect(Collectors.toSet()); |
|
|
|
Map<String, Materialbase> materialbaseMap = materialbaseService.findByCodes(materialCodes); |
|
|
|
List<Work> works = new ArrayList<>(); |
|
|
|
for (OrderDetailDto orderDetailDto : list) { |
|
|
|
String material_code = orderDetailDto.getMaterial_code(); |
|
|
|
if (material_code == null) { |
|
|
|
throw new BadRequestException("物料编码不能为空"); |
|
|
|
} |
|
|
|
Materialbase materialbase = materialbaseMap.get(material_code); |
|
|
|
if (materialbase == null) { |
|
|
|
throw new BadRequestException("不存在物料编码为" + material_code + "的物料!"); |
|
|
|
} |
|
|
|
|
|
|
|
int count = (int) Math.ceil((double) orderDetailDto.getProductin_qty() / materialbase.getQty()); |
|
|
|
Work work = new Work(); |
|
|
|
work.setWork_id(IdUtil.getSnowflake(1, 1).nextId() + "") |
|
|
|
.setWork_code(CodeUtil.getNewCode("WORK_CODE")) |
|
|
|
.setStatus("0") |
|
|
|
.setSeq_no(orderDetailDto.getSeq_no()) |
|
|
|
.setMfg_order_name(orderDetailDto.getMfg_order_name()) |
|
|
|
.setMaterial_code(orderDetailDto.getMaterial_code()) |
|
|
|
.setMaterial_name(orderDetailDto.getMaterial_name()) |
|
|
|
.setResource_name(orderDto.getResource_name()) |
|
|
|
.setRequire_num(count) |
|
|
|
.setRemain_num(count) |
|
|
|
.setQty(orderDetailDto.getProductin_qty()) |
|
|
|
.setCreate_by(currentUsername) |
|
|
|
.setCreate_time(DateUtil.now()) |
|
|
|
.setUpdate_by(currentUsername) |
|
|
|
.setUpdate_time(DateUtil.now()); |
|
|
|
works.add(work); |
|
|
|
} |
|
|
|
workService.saveBatch(works); |
|
|
|
orderMapper.updateById(orderDto); |
|
|
|
return PdaResponseVo.pdaResultOk("工单:[" + orderDto.getMfg_order_name() + "]已开始"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -131,6 +193,10 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
} |
|
|
|
return pdaMapper.getWorks(whereJson.getString("mfg_order_name")); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public List<PointVo> queryPoints() { |
|
|
|
return pdaMapper.getPoints(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<WorkVo> getExcWorks() { |
|
|
@ -177,6 +243,13 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
} |
|
|
|
work.setStatus(TaskStatus.FINISHED.getCode()); |
|
|
|
workService.updateById(work); |
|
|
|
OrderDto dto = orderService.findByCode(work.getMfg_order_name()); |
|
|
|
List<Work> works = workMapper.selectList(Wrappers.lambdaQuery(Work.class).eq(Work::getMfg_order_name, work.getMfg_order_name()).eq(Work::getStatus, TaskStatus.FINISHED.getCode())); |
|
|
|
// 工单所有配料任务都完成,则工单状态改为已完成
|
|
|
|
if (works.size() == dto.getDetail_count()) { |
|
|
|
dto.setStatus(CommonFinalParam.FINISHED); |
|
|
|
orderService.update(dto); |
|
|
|
} |
|
|
|
return PdaResponseVo.pdaResultOk("完成配料作业成功"); |
|
|
|
} |
|
|
|
|
|
|
@ -184,9 +257,10 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
public JSONArray queryAllPoints() { |
|
|
|
//查询所有设备
|
|
|
|
List<Device> list = deviceService.lambdaQuery() |
|
|
|
.in(Device::getRegion, VALID_REGIONS) |
|
|
|
.list(); |
|
|
|
if (CollectionUtil.isEmpty(list)) { |
|
|
|
throw new BadRequestException(LangProcess.msg("error_no_regional")); |
|
|
|
throw new BadRequestException("未查询到设备!"); |
|
|
|
} |
|
|
|
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(list)); |
|
|
|
JSONArray result = new JSONArray(); |
|
|
@ -204,19 +278,41 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
public Map<String, Object> callTask(PdaDto dto) { |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
String start_device_code = dto.getStart_device_code(); |
|
|
|
String next_device_code = dto.getNext_device_code(); |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(start_device_code)) { |
|
|
|
throw new BadRequestException("起点不能为空"); |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(next_device_code)) { |
|
|
|
throw new BadRequestException("终点不能为空"); |
|
|
|
List<Task> list = taskService.lambdaQuery() |
|
|
|
.in(Task::getTask_status, VALID_STATUS) |
|
|
|
.list(); |
|
|
|
if (list.size()>0) { |
|
|
|
throw new BadRequestException("已存在正在执行中或者就绪的AGV任务!"); |
|
|
|
} |
|
|
|
|
|
|
|
AcsPoint startPoint = acsPointService.lambdaQuery() |
|
|
|
.eq(AcsPoint::getPoint_code, start_device_code) |
|
|
|
.one(); |
|
|
|
AcsPoint nextPoint = acsPointService.lambdaQuery() |
|
|
|
.eq(AcsPoint::getPoint_code,"QZJYTW1") |
|
|
|
.one(); |
|
|
|
if (ObjectUtil.isEmpty(nextPoint)) { |
|
|
|
throw new BadRequestException("终点设备不存在"); |
|
|
|
} |
|
|
|
if (!nextPoint.getIs_used().booleanValue() || nextPoint.getPoint_status().equals(CommonFinalParam.ONE)) { |
|
|
|
throw new BadRequestException("下发任务失败的原因是:终点点位被禁用或者终点点位有货,请检查起点点位"+nextPoint.getPoint_code()+"的状态!"); |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(startPoint)) { |
|
|
|
throw new BadRequestException("起点设备不存在"); |
|
|
|
} |
|
|
|
if (!startPoint.getIs_used().booleanValue() || startPoint.getPoint_status().equals(CommonFinalParam.ZERO)) { |
|
|
|
throw new BadRequestException("下发任务失败的原因是:起点点位被禁用或者起点点位无货,请检查起点点位"+startPoint.getPoint_code()+"的状态!"); |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("start_device_code", start_device_code); |
|
|
|
jo.put("next_device_code", next_device_code); |
|
|
|
jo.put("next_device_code", "QZJYTW1"); |
|
|
|
jo.put("start_point_code", start_device_code); |
|
|
|
jo.put("next_point_code", next_device_code); |
|
|
|
jo.put("next_point_code", "QZJYTW1"); |
|
|
|
jo.put("task_type", "1"); |
|
|
|
jo.put("priority", "1"); |
|
|
|
|
|
|
@ -251,4 +347,28 @@ public class PdaServiceImpl implements PdaService { |
|
|
|
workService.pause(work.getWork_id()); |
|
|
|
return PdaResponseVo.pdaResultOk("暂停成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PdaResponseVo operation(JSONObject whereJson) { |
|
|
|
String point_code = whereJson.getString("point_code"); |
|
|
|
String type = whereJson.getString("type");//1:点位状态修改有货,0:点位状态修改无货
|
|
|
|
if (StrUtil.isEmpty(point_code)) { |
|
|
|
return PdaResponseVo.pdaResultOk("点位为空"); |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(type)) { |
|
|
|
return PdaResponseVo.pdaResultOk("类型为空"); |
|
|
|
} |
|
|
|
AcsPoint point = acsPointService.findByCode(point_code); |
|
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
|
return PdaResponseVo.pdaResultOk("点位不存在"); |
|
|
|
} |
|
|
|
if (type.equals("1")) { |
|
|
|
point.setPoint_status("1"); |
|
|
|
} |
|
|
|
if (type.equals("0")) { |
|
|
|
point.setPoint_status("0"); |
|
|
|
} |
|
|
|
acsPointService.updateById(point); |
|
|
|
return PdaResponseVo.pdaResultOk("更新成功"); |
|
|
|
} |
|
|
|
} |
|
|
|