no message

main
HUOJIN\92525 2024-04-16 09:33:47 +08:00
parent d47e09fdec
commit 0903643bf3
9 changed files with 264 additions and 51 deletions

View File

@ -1,24 +1,27 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.businessdata.rest;
import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.businessdata.domain.Mo;
import com.youchain.businessdata.inputJson.IssueInfo;
import com.youchain.businessdata.service.MoService;
import com.youchain.businessdata.service.dto.MoQueryCriteria;
import com.youchain.exception.handler.ApiResult;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
@ -27,14 +30,18 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;
/**
* @website https://eladmin.vip
* @author huojin
* @date 2024-04-10
**/
* @author huojin
* @website https://eladmin.vip
* @date 2024-04-10
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "mo管理")
@ -55,23 +62,23 @@ public class MoController {
@Log("查询mo")
@ApiOperation("查询mo")
@PreAuthorize("@el.check('mo:list')")
public ResponseEntity<Object> queryMo(MoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(moService.queryAll(criteria,pageable),HttpStatus.OK);
public ResponseEntity<Object> queryMo(MoQueryCriteria criteria, Pageable pageable) {
return new ResponseEntity<>(moService.queryAll(criteria, pageable), HttpStatus.OK);
}
@PostMapping
@Log("新增mo")
@ApiOperation("新增mo")
@PreAuthorize("@el.check('mo:add')")
public ResponseEntity<Object> createMo(@Validated @RequestBody Mo resources){
return new ResponseEntity<>(moService.create(resources),HttpStatus.CREATED);
public ResponseEntity<Object> createMo(@Validated @RequestBody Mo resources) {
return new ResponseEntity<>(moService.create(resources), HttpStatus.CREATED);
}
@PutMapping
@Log("修改mo")
@ApiOperation("修改mo")
@PreAuthorize("@el.check('mo:edit')")
public ResponseEntity<Object> updateMo(@Validated @RequestBody Mo resources){
public ResponseEntity<Object> updateMo(@Validated @RequestBody Mo resources) {
moService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@ -84,4 +91,5 @@ public class MoController {
moService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}
}

View File

@ -0,0 +1,49 @@
package com.youchain.businessdata.rest;
import com.github.s7connector.api.S7Connector;
import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.businessdata.service.MoService;
import com.youchain.exception.handler.ApiResult;
import com.youchain.utils.S7ConnectorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;
/**
* @author huojin
* @website
* @date 2024-04-10
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "plc管理")
@RequestMapping("/api/plc")
public class PlcController {
private final MoService moService;
@PostMapping("/scanMo")
@AnonymousAccess
@Log("PLC扫描容器")
@ApiOperation("PLC扫描容器")
public ResponseEntity<Object> scanMo(@RequestBody String mo) {
try {
moService.scanMo(mo);
S7Connector s7Connector = S7ConnectorUtils.connect();
S7ConnectorUtils.write(s7Connector,1);
return new ResponseEntity<>(ApiResult.success(OK.value(), "", ""), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(ApiResult.success(BAD_REQUEST.value(), e.getMessage(), ""), HttpStatus.BAD_REQUEST);
}
}
}

View File

@ -89,4 +89,10 @@ public interface MoService {
* @return
*/
Mo toEntity(MoDto moDto);
/**
* MO
* @param mo MO
*/
void scanMo(String mo);
}

View File

@ -56,6 +56,13 @@ public interface OrderService {
*/
OrderDto findById(Integer id);
/**
* deliveryLineId
* @param deliveryLineId deliveryLineId
* @return OrderDto
*/
OrderDto findBydeliveryLineId(Integer deliveryLineId);
/**
* barcodeNumber
* @param barcodeNumber

View File

@ -15,6 +15,7 @@ import com.youchain.businessdata.inputJson.*;
import com.youchain.businessdata.service.*;
import com.youchain.businessdata.service.dto.MoDto;
import com.youchain.businessdata.service.dto.OrderDto;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.system.domain.Dept;
import com.youchain.modules.system.service.DeptService;
import com.youchain.modules.system.service.dto.DeptDto;
@ -37,10 +38,13 @@ public class MlsServiceImpl implements MlsService {
private final ItemService itemService;
private final DeptService deptService;
private final MoService moService;
private final TaskService taskService;
private final PointService pointService;
private final AgvTaskService agvTaskService;
private final PickDetailService pickDetailService;
private final InventoryService inventoryService;
/**
* Token
*
@ -292,9 +296,11 @@ public class MlsServiceImpl implements MlsService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public synchronized void getIssueInfo(IssueInfo issueInfo) {
Set workOrderNameSet = issueInfo.getWorkOrderName();
if (workOrderNameSet.size() == 0) {
// 指定Set的类型
Set<String> workOrderNameSet = issueInfo.getWorkOrderName();
if (workOrderNameSet.isEmpty()) {
throw new RuntimeException("没有获取到工单号!");
}
@ -304,16 +310,17 @@ public class MlsServiceImpl implements MlsService {
}
//目标点
Point endPoint = pointService.findByCode("",null,null,null,null);
Point endPoint = pointService.findByCode(null, null, null, "出库接驳口", null);
for (Inventory inv : inventoryList) {
//根据库存信息生成叫料任务
Stock stock = inv.getStock();//容器
Point startPoint = inv.getPoint();//起始点位
Item item = inv.getItemKey().getItem();
inv.setQueuedQty(inv.getQueuedQty());
inventoryService.update(inv);
PickDetail pd = new PickDetail();
pd.setItem(inv.getItemKey().getItem());
pd.setItem(item);
pd.setPo(inv.getBillCode());
pd.setOrderQty(inv.getQuantity());
@ -321,9 +328,9 @@ public class MlsServiceImpl implements MlsService {
pd.setStatus(BizStatus.ALLOCATE);
pickDetailService.create(pd);
/*//生成搬运任务
//生成搬运任务
AgvTask agvTask = new AgvTask(BizStatus.PICK, stock.getCode(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "01");
agvTaskRepository.save(agvTask);
agvTaskService.create(agvTask);
//生成Task
Task task = new Task();
task.setItem(item);
@ -339,11 +346,11 @@ public class MlsServiceImpl implements MlsService {
task.setDstPointCode(endPoint.getCode());
task.setInvStatus(inv.getStatus());
task.setTaskStatus(BizStatus.OPEN);
task.setPlanQty(allocateQty);
task.setPlanQty(inv.getQuantity());
task.setInvId(inv.getId());
task.setDept(dept);
task.setDept(item.getDept());
task.setAgvTask(agvTask);
taskRepository.save(task);*/
taskService.create(task);
}

View File

@ -15,33 +15,42 @@
*/
package com.youchain.businessdata.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.youchain.basicdata.domain.Item;
import com.youchain.businessdata.domain.Mo;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Stock;
import com.youchain.basicdata.service.ItemService;
import com.youchain.basicdata.service.PointService;
import com.youchain.basicdata.service.StockService;
import com.youchain.businessdata.domain.*;
import com.youchain.businessdata.service.*;
import com.youchain.businessdata.service.dto.OrderDto;
import com.youchain.exception.EntityExistException;
import com.youchain.utils.FileUtil;
import com.youchain.utils.PageUtil;
import com.youchain.utils.QueryHelp;
import com.youchain.utils.ValidationUtil;
import com.youchain.exception.handler.ApiResult;
import com.youchain.modules.system.service.DictService;
import com.youchain.utils.*;
import lombok.RequiredArgsConstructor;
import com.youchain.businessdata.repository.MoRepository;
import com.youchain.businessdata.service.MoService;
import com.youchain.businessdata.service.dto.MoDto;
import com.youchain.businessdata.service.dto.MoQueryCriteria;
import com.youchain.businessdata.service.mapstruct.MoMapper;
import org.springframework.data.domain.Example;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
/**
* @author huojin
@ -56,6 +65,16 @@ public class MoServiceImpl implements MoService {
private final MoRepository moRepository;
private final MoMapper moMapper;
private final EntityManager entityManager;
private final OrderService orderService;
private final ItemService itemService;
private final StockService stockService;
private final InventoryService inventoryService;
private final PointService pointService;
private final AgvTaskService agvTaskService;
private final TaskService taskService;
private final AsnDetailService asnDetailService;
private final ItemKeyService itemKeyService;
private final DictService dictService;
@Override
public Map<String, Object> queryAll(MoQueryCriteria criteria, Pageable pageable) {
@ -127,4 +146,79 @@ public class MoServiceImpl implements MoService {
public Mo toEntity(MoDto moDto) {
return moMapper.toEntity(moDto);
}
@Override
public synchronized void scanMo(String mo) {
String agv_on_off = "OFF";
String code = "0";
String message = "";
agv_on_off = dictService.getDictDescription("agv_on_off") == null ? "OFF" : dictService.getDictDescription("agv_on_off").getDescription();
MoDto moDto = this.findByLabelNo(mo);
if (moDto == null) {
throw new RuntimeException(mo + "系统无此标签!");
}
if (!moDto.getLabelState().equals("PRINTED")) {
throw new RuntimeException(mo + "标签已被接收(已接收状态)!");
}
OrderDto orderDto = orderService.findBydeliveryLineId(moDto.getDeliveryHeaderId());
if (orderDto == null) {
throw new RuntimeException(moDto.getDeliveryHeaderId() + "系统无此订单!");
}
if (!orderDto.getDeliveryStatus().equals("lm_initial")) {
throw new RuntimeException(orderDto.getBarcodeNumber() + "标签背后的送货单已取消(标签失效)!");
}
String itemCode = "";//物料编号
String stockCode = "";//容器编号
Item item = itemService.existItem(itemCode);
if (item == null) {
throw new RuntimeException(itemCode + "系统无此物料!");
}
Stock stock = stockService.findByCode(stockCode, null);
if (stock == null) {
throw new RuntimeException(stockCode + "系统无此容器!");
}
if (inventoryService.queryInventory(stock).size() > 0) {
throw new RuntimeException(stockCode + "箱码已经有绑定关系!");
}
Point srcPoint = pointService.findByCode(null, null, null, "入库接驳口", null);
if (srcPoint == null) {
throw new RuntimeException("系统无入库接驳口!");
}
Point endPoint = pointService.findByCode(null, BaseStatus.FREE, BaseStatus.STORAGE, "存储区", null);
if (endPoint == null) {
throw new RuntimeException("存储区没有空闲点位!");
}
//生成AGV任务
AgvTask agvTask = new AgvTask(BizStatus.ASN, stock.getCode(), srcPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "RACK_MOVE_FULL");
agvTaskService.create(agvTask);
//生成入库任务
Date date = cn.hutool.core.date.DateUtil.date();
String propC1 = DateUtil.format(date, "yyyyMMdd");
AsnDetail asnDetail = asnDetailService.createAsnDetail(item, stock, srcPoint, propC1, null);
asnDetail.setOrderQty(item.getExtendD1());
asnDetail.setPo(orderDto.getBarcodeNumber());
asnDetailService.create(asnDetail);
//生成Itemkey
ItemKey itemKey = itemKeyService.getItemKey(item, asnDetail.getPropC1(), asnDetail.getOrderNumber());
//生成收货记录
Task task = new Task(item, itemKey, asnDetail.getOrderNumber(), BizStatus.ASN, asnDetail, null, null, null, stock, stock, srcPoint, endPoint, stock.getCode(), stock.getCode(), srcPoint.getCode(), endPoint.getCode(), null, BizStatus.OPEN, asnDetail.getOrderQty(), null, null, item.getDept(), agvTask);
taskService.create(task);
//容器改为占用,目标点位占用
stock.setStatus(BaseStatus.USED);
stockService.update(stock);
}
}

View File

@ -77,6 +77,14 @@ public class OrderServiceImpl implements OrderService {
return orderMapper.toDto(order);
}
@Override
@Transactional
public OrderDto findBydeliveryLineId(Integer deliveryLineId) {
Order order = orderRepository.findById(deliveryLineId).orElseGet(Order::new);
ValidationUtil.isNull(order.getDeliveryHeaderId(), "Order", "deliveryLineId", deliveryLineId);
return orderMapper.toDto(order);
}
@Override
public OrderDto findByBarcodeNumber(String barcodeNumber) {
String hql = "from Order o where o.barcodeNumber = :barcodeNumber";

View File

@ -0,0 +1,32 @@
package com.youchain.modules.quartz.task;
import com.github.s7connector.api.S7Connector;
import com.youchain.businessdata.rest.MoController;
import com.youchain.businessdata.rest.PlcController;
import com.youchain.utils.S7ConnectorUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class plcTask {
private final PlcController plcController;
@Autowired
public plcTask(PlcController plcController) {
this.plcController = plcController;
}
public void plcTask() {
try {
S7Connector connector = S7ConnectorUtils.connect();
String mo = S7ConnectorUtils.readMo(connector);
plcController.scanMo(mo);
} catch (Exception e) {
throw new RuntimeException("异常信息" + e.getMessage());
}
}
}

View File

@ -20,12 +20,12 @@ import java.nio.ByteBuffer;
@Slf4j
public class S7ConnectorUtils {
public S7Connector connect() {
public static S7Connector connect() {
S7Connector s7Connector = null;
try {
s7Connector = S7ConnectorFactory
.buildTCPConnector()
.withHost("192.168.0.21")//设置PLC的IP地址
.withHost("192.168.56.188")//设置PLC的IP地址
.withPort(102)//设置PLC的端口号
.withTimeout(10000)//设置连接超时时间
.withRack(0)//设置PLC的机架号
@ -44,7 +44,8 @@ public class S7ConnectorUtils {
*
* @param connector
*/
public void readMo(S7Connector connector) {
public static String readMo(S7Connector connector) {
String mo = null;
if (connector == null) {
throw new RuntimeException("PLC连接失败请检查!");
}
@ -64,13 +65,15 @@ public class S7ConnectorUtils {
String str1 = "";
StringConverter converter = new StringConverter();
String extract1 = converter.extract(str1.getClass(), PlcData, 0, 0);
log.info("内置方法转换str=" + extract1);
mo = converter.extract(str1.getClass(), PlcData, 0, 0);
log.info("内置方法转换str=" + mo);
try {
connector.close();
} catch (Exception e) {
e.printStackTrace();
}
return mo;
}
/**
@ -79,7 +82,7 @@ public class S7ConnectorUtils {
*
* @param connector
*/
public Integer readStock(S7Connector connector) throws IOException {
public static Integer readStock(S7Connector connector) throws IOException {
Integer status = null;
try {
@ -117,7 +120,7 @@ public class S7ConnectorUtils {
* @param connector
* @param instruct ;PLC120PLC
*/
public void write(S7Connector connector, Integer instruct) {
public static void write(S7Connector connector, Integer instruct) {
long startTime = System.currentTimeMillis();
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
buffer.putInt(instruct);
@ -128,5 +131,4 @@ public class S7ConnectorUtils {
System.out.print("写入成功");
}
}