no message

main
HUOJIN\92525 2025-09-20 13:19:33 +08:00
parent a13024aaa9
commit 1e4638c589
8 changed files with 253 additions and 93 deletions

View File

@ -2,6 +2,7 @@ package com.youchain.appupdate.service.impl;
import com.youchain.appupdate.request.*;
import com.youchain.appupdate.service.NioF3AppService;
import com.youchain.basicdata.constant.PointTypeEnum;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.service.ItemService;
@ -81,7 +82,7 @@ public class NioF3AppServiceImpl implements NioF3AppService {
//验证起点
Point point = pointService.validatePoint(bindSmall.getSrcPositionCode());
if (!BaseStatus.XJ_DFQ.equals(point.getType())) {
if (!PointTypeEnum.XJ_DFQ.getValue().equals(point.getType())) {
throw new BadRequestException(bindSmall.getSrcPositionCode() + "不属于小件待发区点位");
}
}
@ -174,7 +175,7 @@ public class NioF3AppServiceImpl implements NioF3AppService {
//验证起点
Point point = pointService.validatePoint(bindLarge.getSrcPositionCode());
if (!BaseStatus.DJ_DFQ.equals(point.getType())) {
if (!PointTypeEnum.DJ_DFQ.getValue().equals(point.getType())) {
throw new BadRequestException(bindLarge.getSrcPositionCode() + "不属于大件待发区点位");
}
}
@ -232,7 +233,7 @@ public class NioF3AppServiceImpl implements NioF3AppService {
//验证起点
Point point = pointService.validatePoint(bindLargeZy.getSrcPositionCode());
if (!BaseStatus.DJ_DFQ.equals(point.getType())) {
if (!PointTypeEnum.DJ_DFQ.getValue().equals(point.getType())) {
throw new BadRequestException(bindLargeZy.getSrcPositionCode() + "不属于大件待发区点位");
}
}

View File

@ -0,0 +1,52 @@
package com.youchain.basicdata.constant;
import com.youchain.enumeration.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum PointTypeEnum implements BaseEnum {
STORAGE("STORAGE", "存储点"),
BOX("BOX", "线边点位"),
XJ_DFQ("XJ_DFQ", "小件待发区"),
DJ_DFQ("DJ_DFQ", "大件待发区"),
;
private final String value;
private final String desc;
/**
* value desc
* @param value
* @return null
*/
public static String getDescByValue(String value) {
for (PointTypeEnum status : PointTypeEnum.values()) {
if (status.getValue().equals(value)) {
return status.getDesc();
}
}
return null;
}
/**
* desc value
* @param desc
* @return null
*/
public static String getValueByDesc(String desc) {
for (PointTypeEnum status : PointTypeEnum.values()) {
if (status.getDesc().equals(desc)) {
return status.getValue();
}
}
return null;
}
}

View File

@ -91,7 +91,7 @@ public class Point extends BaseEntity implements Serializable {
@Column(name = "`heat`")
@ApiModelProperty(value = "热度")
private Double heat;
private Double heat=0d;
@Column(name = "`line`")
@ApiModelProperty(value = "排")

View File

@ -15,7 +15,6 @@
*/
package com.youchain.basicdata.service.impl;
import cn.idev.excel.FastExcel;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.requset.ItemImportReq;
import com.youchain.exception.BadRequestException;
@ -27,7 +26,6 @@ import com.youchain.basicdata.service.ItemService;
import com.youchain.basicdata.service.dto.ItemDto;
import com.youchain.basicdata.service.dto.ItemQueryCriteria;
import com.youchain.basicdata.service.mapstruct.ItemMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
@ -51,6 +49,7 @@ public class ItemServiceImpl implements ItemService {
private final ItemRepository itemRepository;
private final ItemMapper itemMapper;
private final BatchUtils batchUtils;
@Override
public Map<String, Object> queryAll(ItemQueryCriteria criteria, Pageable pageable) {
@ -153,17 +152,10 @@ public class ItemServiceImpl implements ItemService {
@Override
@Transactional(rollbackFor = Exception.class)
public String importItem(MultipartFile multipartFile) {
List<ItemImportReq> dataList;
try {
dataList = FastExcel.read(multipartFile.getInputStream()).head(ItemImportReq.class)
.sheet()
.doReadSync();
} catch (IOException e) {
throw new BadRequestException("数据格式存在问题,无法读取");
}
if (CollectionUtils.isEmpty(dataList)) {
throw new BadRequestException("数据为空");
}
List<ItemImportReq> dataList=FastExcelUtils.readExcelData(multipartFile, ItemImportReq.class,0, 1);
//去除掉重复数据
dataList = dataList.stream().distinct().collect(Collectors.toList());
//获取文件中所有物料编码
List<String> codes = dataList.stream()
@ -189,7 +181,7 @@ public class ItemServiceImpl implements ItemService {
Item item = existingItemMap.get(code);
itemsToUpdate.add(updateItem(item, specs));
} else {
//新增容器
//新增物料
Item item = createItem(code, specs, UserUtils.getDept());
itemsToCreate.add(item);
existingItemMap.put(code, item);
@ -197,15 +189,17 @@ public class ItemServiceImpl implements ItemService {
}
//批量新增物料
int[] resultCreate = new int[0];
if (!itemsToCreate.isEmpty()) {
itemRepository.saveAll(itemsToCreate);
resultCreate = batchUtils.batchInsertItems(itemsToCreate);
}
//批量更新物料
int[] resultUpdate = new int[0];
if (!itemsToUpdate.isEmpty()) {
itemRepository.saveAll(itemsToUpdate);
resultUpdate = batchUtils.batchUpdateItems(itemsToUpdate);
}
return ("导入成功:" + " 新增(" + itemsToCreate.size() + ")修改(" + itemsToUpdate.size() + ")");
return String.format("导入成功:新增(%d修改%d", resultCreate.length, resultUpdate.length);
}
private Item createItem(String code, String specs, Dept dept) {

View File

@ -15,7 +15,7 @@
*/
package com.youchain.basicdata.service.impl;
import cn.idev.excel.FastExcel;
import com.youchain.basicdata.constant.PointTypeEnum;
import com.youchain.basicdata.domain.Area;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.repository.AreaRepository;
@ -30,9 +30,7 @@ import com.youchain.basicdata.service.dto.PointDto;
import com.youchain.basicdata.service.dto.PointQueryCriteria;
import com.youchain.basicdata.service.mapstruct.PointMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
@ -59,6 +57,7 @@ public class PointServiceImpl implements PointService {
private final PointRepository pointRepository;
private final AreaRepository areaRepository;
private final PointMapper pointMapper;
private final BatchUtils batchUtils;
@Override
public Map<String, Object> queryAll(PointQueryCriteria criteria, Pageable pageable) {
@ -133,17 +132,11 @@ public class PointServiceImpl implements PointService {
@Override
@Transactional(rollbackFor = Exception.class)
public String importPoint(MultipartFile multipartFile) {
List<PointImportReq> dataList;
try {
dataList = FastExcel.read(multipartFile.getInputStream()).head(PointImportReq.class)
.sheet()
.doReadSync();
} catch (IOException e) {
throw new BadRequestException("数据格式存在问题,无法读取");
}
if (CollectionUtils.isEmpty(dataList)) {
throw new BadRequestException("数据为空");
}
//读取数据
List<PointImportReq> dataList = FastExcelUtils.readExcelData(multipartFile, PointImportReq.class,0, 1);
//去除掉重复数据
dataList = dataList.stream().distinct().collect(Collectors.toList());
//获取文件中所有库区名称
List<String> names = dataList.stream()
@ -198,24 +191,31 @@ public class PointServiceImpl implements PointService {
}
//批量新增容器
//批量新增点位
int[] resultCreate = new int[0];
if (!pointsToCreate.isEmpty()) {
pointRepository.saveAll(pointsToCreate);
resultCreate = batchUtils.batchInsertPoints(pointsToCreate);
}
//批量更新容器
//批量更新点位
int[] resultUpdate = new int[0];
if (!pointsToUpdate.isEmpty()) {
pointRepository.saveAll(pointsToUpdate);
resultUpdate = batchUtils.batchUpdatePoints(pointsToUpdate);
}
return ("导入成功:" + " 新增(" + pointsToCreate.size() + ")修改(" + pointsToUpdate.size() + ")");
return String.format("导入成功:新增(%d修改%d", resultCreate.length, resultUpdate.length);
}
private Point createPoint(String code, String beatCode, String type, Area area, Dept dept) {
if ("缓存点".equals(type)) {
type = BaseStatus.STORAGE;
if ("存储点".equals(type)) {
type = PointTypeEnum.STORAGE.getValue();
} else if ("线边点位".equals(type)) {
type = BaseStatus.BOX;
type = PointTypeEnum.BOX.getValue();
} else if ("小件待发区".equals(type)) {
type = PointTypeEnum.XJ_DFQ.getValue();
} else if ("大件待发区".equals(type)) {
type = PointTypeEnum.DJ_DFQ.getValue();
} else {
throw new BadRequestException(type + "类型不存在");
}
return Point.builder()
.code(code)
@ -226,16 +226,20 @@ public class PointServiceImpl implements PointService {
.enabled(true)
.dept(dept)
.type(type)
.heat(0.0)
.build();
}
private Point updatePoint(Point point, Area area, String beatCode, String type) {
if ("缓存点".equals(type)) {
type = BaseStatus.STORAGE;
if ("存储点".equals(type)) {
type = PointTypeEnum.STORAGE.getValue();
} else if ("线边点位".equals(type)) {
type = BaseStatus.BOX;
type = PointTypeEnum.BOX.getValue();
} else if ("小件待发区".equals(type)) {
type = PointTypeEnum.XJ_DFQ.getValue();
} else if ("大件待发区".equals(type)) {
type = PointTypeEnum.DJ_DFQ.getValue();
} else {
throw new BadRequestException(type + "类型不存在");
}
point.setArea(area);
point.setBeatCode(beatCode);

View File

@ -0,0 +1,61 @@
package com.youchain.enumeration;
import com.alibaba.fastjson.JSONAware;
import lombok.Data;
import java.util.Objects;
public interface BaseEnum {
/**
*
*
* @return Object
*/
Object getValue();
/**
*
*
* @return String
*/
String getDesc();
/**
* value
*
* @param value value
* @return boolean
*/
default boolean equalsValue(Object value) {
return Objects.equals(getValue(), value);
}
/**
*
*
* @param baseEnum
* @return boolean
*/
default boolean equals(BaseEnum baseEnum) {
return Objects.equals(getValue(), baseEnum.getValue()) && Objects.equals(getDesc(), baseEnum.getDesc());
}
@Data
class DeletedQuotationAware implements JSONAware {
private String value;
public DeletedQuotationAware(Object value) {
if (value instanceof String) {
this.value = "'" + value + "'";
} else {
this.value = value.toString();
}
}
@Override
public String toJSONString() {
return value;
}
}
}

View File

@ -22,26 +22,6 @@ public interface BaseStatus {
*/
public static Boolean F =false;
/**
* -
*/
public static String BOX = "BOX";
/**
* -
*/
public static String STORAGE = "STORAGE";
/**
* -
*/
public static String XJ_DFQ = "XJ_DFQ";
/**
* -
*/
public static String DJ_DFQ = "DJ_DFQ";
/**
* 线
*/

View File

@ -1,6 +1,7 @@
package com.youchain.utils;
import com.youchain.basicdata.domain.Area;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
@ -9,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
@Service
@ -17,54 +19,120 @@ public class BatchUtils {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
*
*
*/
@Transactional
public int[] batchInsertAreas(List<Area> areas) {
String sql = "insert into base_area (code, name, enabled, dept_id,create_by,update_by,create_time,update_time) VALUES (?, ?, ?, ?,?,?,?,?)";
public int[] batchInsertItems(List<Item> items) {
String sql = "insert into base_item (code,name,specs,enabled,good_type,unit,dept_id,create_by,update_by,create_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?)";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Area area = areas.get(i);
ps.setString(1, area.getCode());
ps.setString(2, area.getName());
ps.setBoolean(3, area.getEnabled());
ps.setLong(4, area.getDept().getId());
ps.setString(5, area.getCreateBy());
ps.setString(6, area.getUpdateBy());
ps.setTimestamp(7, area.getCreateTime());
ps.setTimestamp(8, area.getUpdateTime());
Item item = items.get(i);
ps.setString(1, item.getCode());
ps.setString(2, item.getName());
ps.setString(3, item.getSpecs());
ps.setBoolean(4, item.getEnabled());
ps.setString(5, item.getGoodType());
ps.setString(6, item.getUnit());
ps.setLong(7, item.getDept().getId());
ps.setString(8, SecurityUtils.getCurrentUsername());
ps.setString(9, SecurityUtils.getCurrentUsername());
ps.setTimestamp(10, new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(11, new Timestamp(System.currentTimeMillis()));
}
@Override
public int getBatchSize() {
return areas.size();
return items.size();
}
});
}
/**
* ID
*
*/
public int[] batchUpdateAreasById(List<Area> areas) {
String sql = "update base_area set name = ?, code = ?, enabled = ? WHERE id = ?";
@Transactional
public int[] batchUpdateItems(List<Item> items) {
String sql = "update base_item set code = ?, name = ?, specs = ?, enabled = ?, good_type = ?, unit = ? where id = ?";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Area area = areas.get(i);
ps.setString(1, area.getName());
ps.setString(2, area.getCode());
ps.setBoolean(3, area.getEnabled());
ps.setLong(4, area.getId()); // WHERE条件
Item item = items.get(i);
ps.setString(1, item.getCode());
ps.setString(2, item.getName());
ps.setString(3, item.getSpecs());
ps.setBoolean(4, item.getEnabled());
ps.setString(5, item.getGoodType());
ps.setString(6, item.getUnit());
ps.setLong(7, item.getId());
}
@Override
public int getBatchSize() {
return areas.size();
return items.size();
}
});
}
/**
*
*/
@Transactional
public int[] batchInsertPoints(List<Point> points) {
String sql = "insert into base_point (code,name,status,beat_code,area_id,enabled,dept_id,type,create_by,update_by,create_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?,?)";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Point point = points.get(i);
ps.setString(1, point.getCode());
ps.setString(2, point.getName());
ps.setString(3, point.getStatus());
ps.setString(4, point.getBeatCode());
ps.setLong(5, point.getArea().getId());
ps.setBoolean(6, point.getEnabled());
ps.setLong(7, point.getDept().getId());
ps.setString(8, point.getType());
ps.setString(9, SecurityUtils.getCurrentUsername());
ps.setString(10, SecurityUtils.getCurrentUsername());
ps.setTimestamp(11, new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(12, new Timestamp(System.currentTimeMillis()));
}
@Override
public int getBatchSize() {
return points.size();
}
});
}
/**
*
*/
@Transactional
public int[] batchUpdatePoints(List<Point> points) {
String sql = "update base_point set code = ?, name = ?, status = ?, beat_code = ? , area_id = ? , enabled = ?, type = ? where id = ?";
return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Point point = points.get(i);
ps.setString(1, point.getCode());
ps.setString(2, point.getName());
ps.setString(3, point.getStatus());
ps.setString(4, point.getBeatCode());
ps.setLong(5, point.getArea().getId());
ps.setBoolean(6, point.getEnabled());
ps.setString(7, point.getType());
ps.setLong(8, point.getId());
}
@Override
public int getBatchSize() {
return points.size();
}
});
}