no message
parent
64a374c70e
commit
f6fb151886
|
|
@ -48,6 +48,10 @@ public class Pick extends BaseEntity implements Serializable {
|
||||||
@ApiModelProperty(value = "序号")
|
@ApiModelProperty(value = "序号")
|
||||||
private int lineNo;
|
private int lineNo;
|
||||||
|
|
||||||
|
@Column(name = "`task_code`",nullable = false)
|
||||||
|
@ApiModelProperty(value = "任务编号")
|
||||||
|
private String taskCode;
|
||||||
|
|
||||||
@Column(name = "`code`",nullable = false)
|
@Column(name = "`code`",nullable = false)
|
||||||
@ApiModelProperty(value = "出库单号")
|
@ApiModelProperty(value = "出库单号")
|
||||||
private String code;
|
private String code;
|
||||||
|
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
package com.youchain.businessdata.rest;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.youchain.annotation.AnonymousAccess;
|
|
||||||
import com.youchain.annotation.Log;
|
|
||||||
import com.youchain.appupdate.inputJson.MissionStateCallback;
|
|
||||||
import com.youchain.basicdata.domain.Stock;
|
|
||||||
|
|
||||||
import com.youchain.exception.handler.ApiResult;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Api(tags = "输送线")
|
|
||||||
@RequestMapping("/api/Robot/")
|
|
||||||
@Slf4j
|
|
||||||
public class LineController {
|
|
||||||
|
|
||||||
@PostMapping("/NotifyConveyor")
|
|
||||||
@Log("料箱机器人申请取货/放货/取放完成回调")
|
|
||||||
@ApiOperation("料箱机器人申请取货/放货/取放完成回调")
|
|
||||||
@AnonymousAccess
|
|
||||||
public ResponseEntity<Object> NotifyConveyor(@RequestBody MissionStateCallback missionStateCallback) {
|
|
||||||
|
|
||||||
return new ResponseEntity<>(ApiResult.success(OK.value(), "", ""), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/getConveyorState")
|
|
||||||
@Log("读取输送线、流利式货架状态")
|
|
||||||
@ApiOperation("读取输送线、流利式货架状态")
|
|
||||||
@AnonymousAccess
|
|
||||||
public ResponseEntity<Object> getConveyorState(String conveyorId) {
|
|
||||||
//查询点位是否允许取放;conveyorId出入口编号
|
|
||||||
boolean success=false;
|
|
||||||
String code="400";
|
|
||||||
String message="";
|
|
||||||
String state="";
|
|
||||||
//查询输送线出入口是否有容器;有则,否则
|
|
||||||
Stock stock=null;
|
|
||||||
if(conveyorId.equals("入")){
|
|
||||||
if(stock==null){
|
|
||||||
state="3";//不允许取货
|
|
||||||
}else{
|
|
||||||
state="1";//允许取货
|
|
||||||
code="200";
|
|
||||||
success=true;
|
|
||||||
}
|
|
||||||
}else if(conveyorId.equals("出")){
|
|
||||||
if(stock==null){
|
|
||||||
state="4";//不允许放货
|
|
||||||
}else{
|
|
||||||
state="2";//允许取货
|
|
||||||
code="200";
|
|
||||||
success=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject(new LinkedHashMap<>());
|
|
||||||
Map<String, Object> objMap = new LinkedHashMap<>();
|
|
||||||
objMap.put("success", success);//
|
|
||||||
objMap.put("code", code);//
|
|
||||||
objMap.put("message", message);//
|
|
||||||
objMap.put("conveyorId", conveyorId);//
|
|
||||||
objMap.put("state", state);//
|
|
||||||
jsonObject.putAll(objMap);
|
|
||||||
return new ResponseEntity<>(ApiResult.success(OK.value(), "", jsonObject), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -18,6 +18,7 @@ package com.youchain.businessdata.service.dto;
|
||||||
import com.youchain.basicdata.domain.Point;
|
import com.youchain.basicdata.domain.Point;
|
||||||
import com.youchain.modules.system.domain.Dept;
|
import com.youchain.modules.system.domain.Dept;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
@ -40,6 +41,11 @@ public class PickDto implements Serializable {
|
||||||
*/
|
*/
|
||||||
private int lineNo;
|
private int lineNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务编号
|
||||||
|
*/
|
||||||
|
private String taskCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 出库单号
|
* 出库单号
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.youchain.businessdata.service.impl;
|
package com.youchain.businessdata.service.impl;
|
||||||
|
|
||||||
|
import com.youchain.RequestData.ItemDate;
|
||||||
import com.youchain.RequestData.Yclbl;
|
import com.youchain.RequestData.Yclbl;
|
||||||
import com.youchain.basicdata.domain.Item;
|
import com.youchain.basicdata.domain.Item;
|
||||||
import com.youchain.basicdata.domain.Point;
|
import com.youchain.basicdata.domain.Point;
|
||||||
|
|
@ -45,6 +46,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author huojin
|
* @author huojin
|
||||||
|
|
@ -68,7 +70,6 @@ public class PickServiceImpl implements PickService {
|
||||||
private final RedisObjectUtils redisObjectUtils;
|
private final RedisObjectUtils redisObjectUtils;
|
||||||
private final BatchCreateOrUpdate batchCreateOrUpdate;
|
private final BatchCreateOrUpdate batchCreateOrUpdate;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> queryAll(PickQueryCriteria criteria, Pageable pageable) {
|
public Map<String, Object> queryAll(PickQueryCriteria criteria, Pageable pageable) {
|
||||||
Page<Pick> page = pickRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
Page<Pick> page = pickRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||||
|
|
@ -181,18 +182,21 @@ public class PickServiceImpl implements PickService {
|
||||||
/** 验证出库单是否存在 */
|
/** 验证出库单是否存在 */
|
||||||
checkIfGdExists(yclbl);
|
checkIfGdExists(yclbl);
|
||||||
|
|
||||||
|
/** 验证物料是否存在 */
|
||||||
|
Map<String, Item> itemMap = checkIfItemExists(yclbl);
|
||||||
|
|
||||||
List<Pick> createPicks = new ArrayList<>();
|
List<Pick> createPicks = new ArrayList<>();
|
||||||
List<PickDetail> createPickDetails = new ArrayList<>();
|
List<PickDetail> createPickDetails = new ArrayList<>();
|
||||||
AtomicInteger lineNo = new AtomicInteger(1);
|
AtomicInteger lineNo = new AtomicInteger(1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** 遍历成品集合 */
|
/** 遍历成品集合 */
|
||||||
|
String orderNo = yclbl.getOrderNo();
|
||||||
|
String taskCode = yclbl.getTaskCode();
|
||||||
yclbl.getBlzc().forEach(zcData -> {
|
yclbl.getBlzc().forEach(zcData -> {
|
||||||
Pick pick = createPick(yclbl.getOrderNo(), lineNo.getAndIncrement(), zcData.getCompleteCode(), zcData.getStation());
|
Pick pick = createPick(orderNo, taskCode, lineNo.getAndIncrement(), zcData.getCompleteCode(), zcData.getStation());
|
||||||
createPicks.add(pick);
|
createPicks.add(pick);
|
||||||
zcData.getBlzcmx().forEach(itemDate -> {
|
zcData.getBlzcmx().forEach(itemDate -> {
|
||||||
Item item = validateItem(itemDate.getItemCode()); // 验证单品是否存在
|
Item item = itemMap.get(itemDate.getItemCode());
|
||||||
PickDetail pickDetail = createPickDetail(pick, item, BaseStatus.GD_TYPE_CT, itemDate.getItemQty(), zcData.getCompleteQty());
|
PickDetail pickDetail = createPickDetail(pick, item, BaseStatus.GD_TYPE_CT, itemDate.getItemQty(), zcData.getCompleteQty());
|
||||||
createPickDetails.add(pickDetail);
|
createPickDetails.add(pickDetail);
|
||||||
});
|
});
|
||||||
|
|
@ -200,32 +204,22 @@ public class PickServiceImpl implements PickService {
|
||||||
|
|
||||||
/** 遍历单品品集合 */
|
/** 遍历单品品集合 */
|
||||||
yclbl.getBlzcmx().forEach(itemDate -> {
|
yclbl.getBlzcmx().forEach(itemDate -> {
|
||||||
Pick pick = createPick(yclbl.getOrderNo(), lineNo.getAndIncrement(), itemDate.getItemCode(), itemDate.getStation());
|
Pick pick = createPick(orderNo, taskCode, lineNo.getAndIncrement(), itemDate.getItemCode(), itemDate.getStation());
|
||||||
createPicks.add(pick);
|
createPicks.add(pick);
|
||||||
Item item = validateItem(itemDate.getItemCode()); // 验证单品是否存在
|
Item item = itemMap.get(itemDate.getItemCode());
|
||||||
PickDetail pickDetail = createPickDetail(pick, item, BaseStatus.GD_TYPE_DP, itemDate.getItemQty(), null);
|
PickDetail pickDetail = createPickDetail(pick, item, BaseStatus.GD_TYPE_DP, itemDate.getItemQty(), null);
|
||||||
createPickDetails.add(pickDetail);
|
createPickDetails.add(pickDetail);
|
||||||
});
|
});
|
||||||
|
|
||||||
ExecutorService executor = ThreadPoolExecutorUtil.getPoll("materialBL-job");
|
|
||||||
try {
|
|
||||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
|
||||||
|
|
||||||
/** 使用并行流批量保存 */
|
if (!createPicks.isEmpty()) {
|
||||||
if (!createPicks.isEmpty()) {
|
pickRepository.saveAll(createPicks);
|
||||||
futures.add(CompletableFuture.runAsync(() -> pickRepository.saveAll(createPicks), executor));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!createPickDetails.isEmpty()) {
|
|
||||||
futures.add(CompletableFuture.runAsync(() -> pickDetailRepository.saveAll(createPickDetails), executor));
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("创建出库单失败!", e);
|
|
||||||
} finally {
|
|
||||||
executor.shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!createPickDetails.isEmpty()) {
|
||||||
|
pickDetailRepository.saveAll(createPickDetails);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -258,6 +252,39 @@ public class PickServiceImpl implements PickService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Item> checkIfItemExists(Yclbl yclbl) {
|
||||||
|
// 获取所有成品和单品的itemCode
|
||||||
|
Set<String> itemCodes = yclbl.getBlzc().stream().flatMap(zcData -> zcData.getBlzcmx().stream()).map(ItemDate::getItemCode).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
itemCodes.addAll(yclbl.getBlzcmx().stream().map(ItemDate::getItemCode).collect(Collectors.toSet()));
|
||||||
|
|
||||||
|
// 查找数据库中存在的items
|
||||||
|
List<Item> items = itemRepository.findByCodes(itemCodes);
|
||||||
|
Set<String> newItemCodes = items.stream().map(Item::getCode).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 取itemCodes和newItemCodes的差集,说明有不存在的物料
|
||||||
|
Set<String> diffItemCodes = itemCodes.stream().filter(code -> !newItemCodes.contains(code)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
if (!diffItemCodes.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("WMS不存在的物料集合,请维护:" + diffItemCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建itemCode到Item的映射
|
||||||
|
return items.stream().collect(Collectors.toMap(Item::getCode, item -> item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取两个集合的不同的元素
|
||||||
|
*/
|
||||||
|
private Set<String> diffItemCodes(Set set1, Set set2) {
|
||||||
|
Set<String> difference = new HashSet<>(set1);
|
||||||
|
difference.addAll(set2);
|
||||||
|
Set<String> tmp = new HashSet<>(set1);
|
||||||
|
tmp.retainAll(set2);
|
||||||
|
difference.removeAll(tmp);
|
||||||
|
return difference;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证单品是否存在
|
* 验证单品是否存在
|
||||||
*
|
*
|
||||||
|
|
@ -285,8 +312,9 @@ public class PickServiceImpl implements PickService {
|
||||||
return pickDetail;
|
return pickDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pick createPick(String gdCode, int lineNo, String cpCodeOrpCode, String station) {
|
public Pick createPick(String gdCode, String taskCode, int lineNo, String cpCodeOrpCode, String station) {
|
||||||
Pick pick = new Pick();
|
Pick pick = new Pick();
|
||||||
|
pick.setTaskCode(taskCode);
|
||||||
pick.setLineNo(lineNo);
|
pick.setLineNo(lineNo);
|
||||||
pick.setCode(gdCode + "_" + lineNo);
|
pick.setCode(gdCode + "_" + lineNo);
|
||||||
pick.setGdCode(gdCode);
|
pick.setGdCode(gdCode);
|
||||||
|
|
|
||||||
|
|
@ -21,26 +21,11 @@ public class BatchCreateOrUpdate {
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public <T> void batchCreate(List<T> entities) {
|
public <T> void batchCreate(List<T> entities) {
|
||||||
int batchSize = 100;
|
|
||||||
if (entities == null || entities.isEmpty()) {
|
if (entities == null || entities.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (T entity : entities) {
|
for (T entity : entities) {
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
i++;
|
|
||||||
if (i % batchSize == 0) {
|
|
||||||
// 执行flush将实体状态同步到数据库,并清理持久化上下文
|
|
||||||
entityManager.flush();
|
|
||||||
entityManager.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保最后未达到batchSize的数据也能被flush到数据库
|
|
||||||
if (i % batchSize != 0) {
|
|
||||||
entityManager.flush();
|
|
||||||
entityManager.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,25 +38,12 @@ public class BatchCreateOrUpdate {
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public <T> void batchUpdate(List<T> entities) {
|
public <T> void batchUpdate(List<T> entities) {
|
||||||
int batchSize = 100;
|
|
||||||
if (entities == null || entities.isEmpty()) {
|
if (entities == null || entities.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (T entity : entities) {
|
for (T entity : entities) {
|
||||||
entityManager.merge(entity);
|
entityManager.merge(entity);
|
||||||
i++;
|
|
||||||
if (i % batchSize == 0) {
|
|
||||||
// 执行flush和clear以同步状态到数据库并清理上下文,减少内存使用
|
|
||||||
entityManager.flush();
|
|
||||||
entityManager.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i % batchSize != 0) {
|
|
||||||
entityManager.flush();
|
|
||||||
entityManager.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ spring:
|
||||||
druid:
|
druid:
|
||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
url: jdbc:log4jdbc:mysql://${DB_HOST:47.100.54.81}:${DB_PORT:53306}/${DB_NAME:byd_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
url: jdbc:log4jdbc:mysql://${DB_HOST:47.100.54.81}:${DB_PORT:53306}/${DB_NAME:byd_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
|
||||||
username: ${DB_USER:root}
|
username: ${DB_USER:root}
|
||||||
password: ${DB_PWD:Youchain@56}
|
password: ${DB_PWD:Youchain@56}
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ spring:
|
||||||
druid:
|
druid:
|
||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.100.102}:${DB_PORT:3306}/${DB_NAME:byd_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.100.102}:${DB_PORT:3306}/${DB_NAME:byd_wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true
|
||||||
username: ${DB_USER:root}
|
username: ${DB_USER:root}
|
||||||
password: ${DB_PWD:Youchain@56}
|
password: ${DB_PWD:Youchain@56}
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,12 @@ spring:
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||||
|
jdbc:
|
||||||
|
batch_size: 500
|
||||||
|
batch_versioned_data: true
|
||||||
|
order_inserts: true
|
||||||
|
order_updates: true
|
||||||
|
generate_statistics: false
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
#数据库索引
|
#数据库索引
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,16 @@ public class EladminSystemApplicationTests {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static Set bb(Set set1, Set set2) {
|
||||||
|
Set<String> difference = new HashSet<>(set1);
|
||||||
|
difference.addAll(set2);
|
||||||
|
Set<String> tmp = new HashSet<>(set1);
|
||||||
|
tmp.retainAll(set2);
|
||||||
|
difference.removeAll(tmp);
|
||||||
|
return difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int MAX_TASK_COUNT = 4;
|
private static final int MAX_TASK_COUNT = 4;
|
||||||
|
|
@ -29,6 +39,20 @@ public class EladminSystemApplicationTests {
|
||||||
|
|
||||||
void aa() {
|
void aa() {
|
||||||
|
|
||||||
|
Set<String> itemCodes = new HashSet<>();
|
||||||
|
itemCodes.add("A");
|
||||||
|
itemCodes.add("B");
|
||||||
|
itemCodes.add("C");
|
||||||
|
itemCodes.add("D");
|
||||||
|
Set<String> newItemCodes = new HashSet<>();
|
||||||
|
newItemCodes.add("A");
|
||||||
|
newItemCodes.add("B");
|
||||||
|
|
||||||
|
Set<String> difference = bb(itemCodes, newItemCodes);
|
||||||
|
StringBuffer sbf = new StringBuffer();
|
||||||
|
sbf.append("WMS不存在的物料集合,请维护:").append(difference);
|
||||||
|
System.out.println(sbf.toString());
|
||||||
|
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
list.add("物料库存不足,请先补充库存!");
|
list.add("物料库存不足,请先补充库存!");
|
||||||
list.add("数量已分配!");
|
list.add("数量已分配!");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue