Merge remote-tracking branch 'origin/main'

This commit is contained in:
liuzhaotian
2024-06-19 17:35:35 +08:00
26 changed files with 612 additions and 96 deletions
@@ -70,14 +70,14 @@ public class OrderController {
@PostMapping("/create")
@Operation(summary = "创建生产单")
@PreAuthorize("@ss.hasPermission('executor:order:create')")
@PreAuthorize("@ss.hasPermission('production:manager-list:create')")
public CommonResult<Long> createOrder(@Valid @RequestBody OrderSaveReqVO createReqVO) {
return success(orderService.createOrder(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新生产单")
@PreAuthorize("@ss.hasPermission('executor:order:update')")
@PreAuthorize("@ss.hasPermission('production:manager-list:edit')")
public CommonResult<Boolean> updateOrder(@Valid @RequestBody OrderSaveReqVO updateReqVO) {
orderService.updateOrder(updateReqVO);
return success(true);
@@ -90,7 +90,7 @@ public class OrderController {
@Parameter(name = "orderId", description = "生产单编号", required = true, example = "1024"),
@Parameter(name = "bodyIds", description = "柜体编号集合", required = true, example = "1,2")
})
@PreAuthorize("@ss.hasPermission('executor:order:delete')")
@PreAuthorize("@ss.hasPermission('production:manager-list:deleteCabinet')")
public CommonResult<Boolean> deleteBody(@RequestParam("orderId") Long orderId, @RequestParam("bodyIds") Set<Long> bodyIds) {
orderService.deleteBodyByOrder(orderId, bodyIds);
return success(true);
@@ -99,7 +99,7 @@ public class OrderController {
@DeleteMapping("/delete")
@Operation(summary = "作废")
@Parameter(name = "orderId", description = "生产单id", required = true, example = "1")
@PreAuthorize("@ss.hasPermission('executor:order:delete')")
@PreAuthorize("@ss.hasPermission('production:manager-list:nullify')")
public CommonResult<Boolean> deleteOrder(@RequestParam("orderId") Long orderId) {
orderService.deleteOrder(orderId);
return success(true);
@@ -108,7 +108,7 @@ public class OrderController {
@PutMapping("/restore")
@Operation(summary = "还原")
@Parameter(name = "orderId", description = "生产单id", required = true, example = "1")
@PreAuthorize("@ss.hasPermission('executor:order:update')")
@PreAuthorize("@ss.hasPermission('production:manager-list:backOrder')")
public CommonResult<Boolean> restoreOrder(@RequestBody JSONObject jsonObject) {
Long orderId = jsonObject.getLong("orderId");
orderService.restoreOrder(orderId);
@@ -118,7 +118,7 @@ public class OrderController {
@GetMapping("/get")
@Operation(summary = "获得(单个)生产单")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<OrderRespVO> getOrder(@RequestParam("id") Long id) {
OrderDO order = orderService.getOrder(id);
return success(BeanUtils.toBean(order, OrderRespVO.class));
@@ -126,7 +126,7 @@ public class OrderController {
@GetMapping("/page")
@Operation(summary = "获得生产单分页")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('productManager:List')")
public CommonResult<PageResult<OrderRespVO>> getOrderPage(@Valid OrderPageReqVO pageReqVO) {
PageResult<OrderDO> pageResult = orderService.getOrderPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, OrderRespVO.class));
@@ -142,7 +142,7 @@ public class OrderController {
@GetMapping("/get-room")
@Operation(summary = "生产单详情-房间和柜体id")
@Parameter(name = "orderId", description = "生产单编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<List<OrderBodyRespVO>> getRoom(@RequestParam("orderId") Long orderId) {
List<OrderBodyRespVO> orderBodyMap = orderService.getOrderBody(orderId);
return success(orderBodyMap);
@@ -151,7 +151,7 @@ public class OrderController {
@GetMapping("/get-module")
@Operation(summary = "生产单详情-数量信息")
@Parameter(name = "orderId", description = "生产单编号", example = "1024")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<Map<String,List<?>>> getModule(@RequestParam("orderId") Long orderId) {
Map<String,List<?>> moduleDOList = orderService.getModule(orderId);
return success(moduleDOList);
@@ -166,7 +166,7 @@ public class OrderController {
@Parameter(name = "groupId", description = "加工组编号", example = "1024"),
@Parameter(name = "groupName", description = "加工组名称", example = "弧形")
})
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<List<OrderPlatesDetailReqVO>> platesDetails(@RequestParam("orderId") Long orderId,
@RequestParam(value = "roomId", required = false) Long roomId,
@RequestParam(value = "bodyId", required = false) Long bodyId,
@@ -184,7 +184,7 @@ public class OrderController {
@Parameter(name = "bodyId", description = "柜体编号", example = "1024"),
@Parameter(name = "name", description = "配件名称", example = "1024")
})
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<List<OrderPartsRespVO>> partsDetails(@RequestParam("orderId") Long orderId,
@RequestParam(value = "roomId", required = false) Long roomId,
@RequestParam(value = "bodyId", required = false) Long bodyId,
@@ -197,14 +197,14 @@ public class OrderController {
@GetMapping("/get-body")
@Operation(summary = "生产单柜体数据获取")
@Parameter(name = "orderId", description = "生产单编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<List<OrderBodyRespVO>> getBody(@RequestParam("orderId") Long orderId) {
return success(BeanUtils.toBean(orderService.getBody(orderId), OrderBodyRespVO.class));
}
@GetMapping("getApiData")
@Operation(summary = "生产单api数据导入新增")
@PreAuthorize("@ss.hasPermission('executor:order:getApiData')")
@PreAuthorize("@ss.hasPermission('production:manager-list:create')")
public CommonResult<Long> test(@RequestParam(value = "orderNo", required = false, defaultValue = "20230809027818") String orderNo)
throws InterruptedException, ExecutionException {
// return success(orderService.importApiData(orderNo));
@@ -235,7 +235,7 @@ public class OrderController {
@Parameter(name = "file", description = "文件", required = true),
@Parameter(name = "type", description = "文件类型", required = true)
})
@PreAuthorize("@ss.hasPermission('executor:order:importExcel')")
@PreAuthorize("@ss.hasPermission('production:manager-list:create')")
@OperateLog(type = EXPORT)
public void exportTest(@RequestPart("file") MultipartFile file,
@RequestParam(value = "type", required = false, defaultValue = "true") Integer type,
@@ -274,7 +274,7 @@ public class OrderController {
@GetMapping("/get-goodsList")
@Operation(summary = "生产单所用板材商品信息")
@Parameter(name = "orderId", description = "生产单编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:detail')")
public CommonResult<List<GoodsDO>> getGoodsList(@RequestParam("orderId") Long orderId) {
List<GoodsDO> goodsDOS = orderService.getGoodsList(orderId);
return success(goodsDOS);
@@ -286,7 +286,7 @@ public class OrderController {
@Parameter(name = "file", description = "文件", required = true),
@Parameter(name = "type", description = "是否强制上传", required = false)
})
@PreAuthorize("@ss.hasPermission('executor:order:upload')")
@PreAuthorize("@ss.hasPermission('production:manager-list:create')")
public CommonResult<String> uploadOrderType(@RequestPart("file") MultipartFile file,
@RequestParam(value = "type", required = false, defaultValue = "false") Boolean type) {
return success(orderService.importTemplate(file,type));
@@ -295,7 +295,7 @@ public class OrderController {
@GetMapping("/printing")
@Operation(summary = "打印/导出 数据文件")
@Parameter(name = "type", description = "文件类型", required = true, example = "0")
@PreAuthorize("@ss.hasPermission('executor:order:query')")
@PreAuthorize("@ss.hasPermission('production:manager-list:export')")
@OperateLog(type = EXPORT)
public CommonResult<Map<String, Object>> getOrderPrintData(
@RequestParam("orderId") Long orderId,
@@ -90,7 +90,7 @@ public class OptimizePlanController {
@GetMapping("/getOrderSource")
@Operation(summary = "获取生产单源数据")
@PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')")
@PreAuthorize("@ss.hasPermission('production:manager-list:calculate')")
public CommonResult<OrderSource> getOrderSource(@Schema(description = "生产单id") @RequestParam(required = false) Long orderId,
@Schema(description = "排单id") @RequestParam(required = false) Long planId,
@Schema(description = "机台Id") @RequestParam("machineId") Long machineId
@@ -37,14 +37,14 @@ public class PlanController {
@PostMapping("/create")
@Operation(summary = "创建排单")
@PreAuthorize("@ss.hasPermission('executor:plan:create')")
@PreAuthorize("@ss.hasPermission('placeorder:create')")
public CommonResult<Long> createPlan(@Validated(CreateGroup.class) @RequestBody PlanSaveReqVO createReqVO) {
return success(planService.createPlan(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新排单")
@PreAuthorize("@ss.hasPermission('executor:plan:update')")
@PreAuthorize("@ss.hasPermission('placeorder:update')")
public CommonResult<Boolean> updatePlan(@Validated(UpdateGroup.class) @RequestBody PlanSaveReqVO updateReqVO) {
planService.updatePlan(updateReqVO);
return success(true);
@@ -53,7 +53,7 @@ public class PlanController {
@DeleteMapping("/delete")
@Operation(summary = "删除排单")
@Parameter(name = "id", description = "排单id", required = true)
@PreAuthorize("@ss.hasPermission('executor:plan:delete')")
@PreAuthorize("@ss.hasPermission('placeorder:delete')")
public CommonResult<Boolean> deletePlan(@RequestParam("id") Long id) {
return success(planService.deletePlan(id));
}
@@ -70,7 +70,7 @@ public class PlanController {
@GetMapping("/get")
@Operation(summary = "获得排单")
@Parameter(name = "id", description = "排单id", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('executor:plan:query')")
@PreAuthorize("@ss.hasPermission('placeorder:query')")
public CommonResult<PlanRespVO> getPlan(@RequestParam("id") Long id) {
PlanRespVO plan = planService.getPlan(id);
return success(BeanUtils.toBean(plan, PlanRespVO.class));
@@ -85,14 +85,14 @@ public class PlanController {
@GetMapping("getOrderByPlan")
@Operation(summary = "根据排单获取生产单分页")
@PreAuthorize("@ss.hasPermission('executor:plan:query')")
@PreAuthorize("@ss.hasPermission('placeorder:orderlist')")
public CommonResult<PageResult<OrderRespVO>> getOrderByPlanId(@Valid PlanOrderPageReqVO pageReqVO) {
return success(planService.getOrderByPlanId(pageReqVO));
}
@GetMapping("/page")
@Operation(summary = "获得排单分页")
@PreAuthorize("@ss.hasPermission('executor:plan:query')")
@PreAuthorize("@ss.hasPermission('placeorder:query')")
public CommonResult<PageResult<PlanRespVO>> getPlanPage(@Valid PlanPageReqVO pageReqVO) {
PageResult<PlanRespVO> pageResult = planService.getPlanPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, PlanRespVO.class));
@@ -100,14 +100,14 @@ public class PlanController {
@PostMapping("/setSort")
@Operation(summary = "设置排单优先级")
@PreAuthorize("@ss.hasPermission('executor:plan:query')")
@PreAuthorize("@ss.hasPermission('placeorder:priority')")
public CommonResult<Boolean> setSort(@Valid @NotEmpty(message = "参数不能空") @RequestBody List<SortVO> list) {
return success(planService.setSort(list));
}
@GetMapping("getNotPlanOrderListPage")
@Operation(summary = "获取未排单的板材生产单板材分页列表")
@PreAuthorize("@ss.hasPermission('executor:plan:query')")
@PreAuthorize("@ss.hasPermission('placeorder:query')")
public CommonResult<PageResult<OrderRespVOCopy>> getOrderPage(@Valid OrderPageReqVOCopy pageReqVO) {
return success(planService.getOrderPage(pageReqVO));
}
@@ -8,23 +8,12 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*;
import com.cf.imes.module.executor.controller.admin.process.vo.*;
import com.cf.imes.module.executor.dal.dataobject.process.OrderProcessDO;
import com.cf.imes.module.executor.service.process.OrderProcessService;
@@ -40,7 +29,7 @@ public class OrderProcessController {
@PostMapping("/create")
@Operation(summary = "创建生产单工序组")
@PreAuthorize("@ss.hasPermission('executor:order-process:create')")
@PreAuthorize("@ss.hasPermission('production:manager-list:putInto')")
public CommonResult<Long> createOrderProcess(@Valid @RequestBody OrderProcessSaveReqVO createReqVO) {
return success(orderProcessService.createOrderProcess(createReqVO));
}
@@ -40,11 +40,11 @@ public class GoodsDO extends BaseDO {
/**
* 设计端商品ID
*/
private Long rawGoodsId;
private String rawGoodsId;
/**
* 商品 ID
*/
private Long goodsId;
private String goodsId;
/**
* 商品名称
*/
@@ -6,6 +6,8 @@ import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
import org.apache.ibatis.annotations.Mapper;
import java.math.BigDecimal;
/**
* 板材信息 Mapper plate
*
@@ -14,12 +16,28 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PlateGoodMapper extends BaseMapperX<PlateGoodDO> {
// 查询单个生产单中信息
default PlateGoodDO selectGoodOne(Long id, Long organId) {
// goodsId匹配
default PlateGoodDO selectGoodOne(String id, Long organId) {
return selectOne(new LambdaQueryWrapper<PlateGoodDO>()
.eq(PlateGoodDO::getGoodsId, id)
.eq(PlateGoodDO::getDeleted, 0)
.eq(PlateGoodDO::getOrganId, organId));
}
// 其他信息匹配
default PlateGoodDO selectGood(String goodsName, String material, String color, Integer texture, BigDecimal width,
BigDecimal thickness, BigDecimal height, String brand, String spec, Long organId) {
return selectOne(new LambdaQueryWrapper<PlateGoodDO>()
.eq(PlateGoodDO::getGoodsName, goodsName)
.eq(PlateGoodDO::getMaterial, material)
.eq(PlateGoodDO::getColor, color)
.eq(PlateGoodDO::getTexture, texture)
.eq(PlateGoodDO::getWidth, width)
.eq(PlateGoodDO::getHeight, height)
.eq(PlateGoodDO::getThickness, thickness)
.eq(PlateGoodDO::getBrand, brand)
.eq(PlateGoodDO::getSpec, spec)
.eq(PlateGoodDO::getDeleted, 0)
.eq(PlateGoodDO::getOrganId, organId));
}
}
@@ -305,6 +305,7 @@ public class OrderServiceImpl implements OrderService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteBodyByOrder(Long orderId, Collection<Long> bodyIds) {
validateOrderExists(orderId, OrganContextHolder.getOrganId());
// 校验生产单的状态 1 为新单状态,才可以修改
@@ -373,26 +374,38 @@ public class OrderServiceImpl implements OrderService {
List<PlateGoodDO> plateGoodLists = new ArrayList<>();
for (GoodsDO goodsDO : goodsLists) {
PlateGoodDO plateGoodDO;
if (goodsDO.getGoodsId() != null) { // 有goodsId
PlateGoodDO plateGoodDO = plateGoodMapper.selectGoodOne(goodsDO.getGoodsId(), SecurityFrameworkUtils.getLoginUser().getOrganId());
if (plateGoodDO != null) {//存在
goodsDO.setGoodsId(plateGoodDO.getId());
}
plateGoodDO = plateGoodMapper.selectGoodOne(goodsDO.getGoodsId(), SecurityFrameworkUtils.getLoginUser().getOrganId());
}else { // 没有goodsId 其他信息匹配
plateGoodDO = plateGoodMapper.selectGood(goodsDO.getGoodsName(), goodsDO.getMaterial(), goodsDO.getColor(),
goodsDO.getTexture(), goodsDO.getWidth(), goodsDO.getWidth(), goodsDO.getHeight(), goodsDO.getSpec(),
goodsDO.getBrand(), SecurityFrameworkUtils.getLoginUser().getOrganId());
}
if (plateGoodDO != null) {//存在板材
goodsDO.setGoodsId(plateGoodDO.getGoodsId());
break;
}else { // 不存在板材
Long plateGoods = (Long) identifierGenerator.nextId(null);
Long goodsId = (Long) identifierGenerator.nextId(null);
plateGoodDO = BeanUtils.toBean(goodsDO, PlateGoodDO.class)
.setId(plateGoods)
.setGoodsId(String.valueOf(goodsId));
// 判断是否存在raw_goods_id
System.out.println("goodsDO.getGoodsId() " + goodsDO.getGoodsId());
if (goodsDO.getGoodsId() != null) {
plateGoodDO.setGoodsId(goodsDO.getGoodsId());
}else {
goodsDO.setGoodsId(plateGoodDO.getGoodsId());
}
plateGoodLists.add(plateGoodDO);
}
Long plateGoods = (Long) identifierGenerator.nextId(null);
PlateGoodDO plateGoodDO = BeanUtils.toBean(goodsDO, PlateGoodDO.class)
.setId(plateGoods)
.setGoodsId(String.valueOf(goodsDO.getGoodsId()));
goodsDO.setGoodsId(plateGoodDO.getId());
plateGoodLists.add(plateGoodDO);
}
map.put("goodsDO", goodsLists);
map.put("plateGoodDOLists", plateGoodLists);
System.err.println(" map " + map);
return map;
}
@@ -501,13 +514,18 @@ public class OrderServiceImpl implements OrderService {
Map<String, List<?>> listMap = excelTypeRealize.changeDate(list, orderDO.getId());
List<RawGoodsDO> rawGoodsDO = (List<RawGoodsDO>) listMap.get("rawGoodsDOS");
List<GoodsDO> goodsDO = (List<GoodsDO>) listMap.get("goodsDOS");
List<PlateGoodDO> plateGoodDOS = (List<PlateGoodDO>) listMap.get("plateGoodDOS");
// List<PlateGoodDO> plateGoodDOS = (List<PlateGoodDO>) listMap.get("plateGoodDOS");
List<OrderBodyDO> bodyDO = (List<OrderBodyDO>) listMap.get("orderBodyDOS");
List<OrderGroupDO> groupDO = (List<OrderGroupDO>) listMap.get("orderGroupDOS");
List<PlateDO> plateDO = (List<PlateDO>) listMap.get("plateDOS");
List<OrderPartsDO> partsDO = (List<OrderPartsDO>) listMap.get("orderPartsDOS");
List<OrderItemDO> itemDO = (List<OrderItemDO>) listMap.get("orderItemDOS");
List<OrderModelDO> orderModelDOS = (List<OrderModelDO>) listMap.get("orderModelDOS");
// 板材库匹配
Map<String, List<?>> map = getPlateGoods(goodsDO);// 检验商品板材信息是否存在
goodsDO = (List<GoodsDO>) map.get("goodsDO");
List<PlateGoodDO> plateGoodDOS = (List<PlateGoodDO>) map.get("plateGoodDOLists");
validateCustomOrderNoExists(orderDO.getCustomOrderNo());
orderInputProcessor.batchInsert(rawGoodsDO, bodyDO, groupDO, partsDO, plateDO, null, itemDO, orderDO, goodsDO, plateGoodDOS);
orderInputProcessor.batchSaveModel(orderModelDOS);
@@ -0,0 +1,25 @@
package com.cf.imes.module.executor.util;
import java.util.concurrent.atomic.AtomicInteger;
public class MinuteCounter {
private static final int MASK = 0x7FFFFFFF;
private final AtomicInteger atom;
public MinuteCounter() {
atom = new AtomicInteger(0);
}
public final int incrementAndGet() {
return atom.incrementAndGet() & MASK;
}
public int get() {
return atom.get() & MASK;
}
public void set(int newValue) {
atom.set(newValue & MASK);
}
}
@@ -0,0 +1,131 @@
package com.cf.imes.module.executor.util.fileConversion.admin;
import com.cf.imes.module.executor.util.MinuteCounter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
/**
* @ClassName: SnowflakeIdWorker3rd
* @Description:snowflake算法改进
* @author: yonnie
* @date: 2024/06/18 14:10:47
* @version V1.0
*
* 将产生的Id类型更改为Integer 32bit <br>
* 把时间戳的单位改为分钟,使用25bit的时间戳
* 7bit作为自增值即 2^7 = 128
*/
@Slf4j
@Component
public class SnowflakeIdWorker3rd {
/** 初始时间 (2024-01-01: 1704038400) */
// private final int twepoch = 28400640;// 1704038400000L/1000/60;
private final int twepoch = 1704038400;
/** 序列在id中占位数 */
private final long sequenceBits = 7L;
/** 时间截向左移7bit */
private final long timestampLeftShift = sequenceBits;
/** 生成序列的MASK (0x7F) */
private final int sequenceMask = -1 ^ (-1 << sequenceBits);
/** 分钟内序 (0~127) */
private int sequence = 0;
private int laterSequence = 0;
/** 上次生成ID的时间戳 */
private int lastTimestamp = -1;
private final MinuteCounter counter = new MinuteCounter();
/** 预支时间标志 */
boolean isAdvance = false;
// ==============================Constructors=====================================
public SnowflakeIdWorker3rd() {
}
// ==============================Test=============================================
/** 测试 */
public static void main(String[] args) {
SnowflakeIdWorker3rd idWorker = new SnowflakeIdWorker3rd();
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(i + ": " + id + " " + "2406" + Long.toString(id).substring(2));
}
// long id = idWorker.nextId();
// System.out.println(id);
}
// ==============================Methods==========================================
/**
* 获取当前年月
* @return null
*/
public static int obtainingTime() {
LocalDate now = LocalDate.now();
int year = now.getYear();
String year_last_two_digits = String.valueOf(year).substring(2);
int month = now.getMonthValue();
String formatted_date = year_last_two_digits + String.format("%02d", month);
return Integer.parseInt(formatted_date);
}
/**
* 获得下一个ID (该方法是线程安全)
*
* @return SnowflakeId
*/
public synchronized int nextId() {
int timestamp = timeGen();
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟修改过
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format(
"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
if (timestamp > counter.get()) {
counter.set(timestamp);
isAdvance = false;
}
// 如果是同时间生成的,则进行分钟内序列
if (lastTimestamp == timestamp || isAdvance) {
if (!isAdvance) {
sequence = (sequence + 1) & sequenceMask;
}
// 分钟内自增列溢出
if (sequence == 0) {
// 预支下一分获得新的时间戳
isAdvance = true;
int laterTimestamp = counter.get();
if (laterSequence == 0) {
laterTimestamp = counter.incrementAndGet();
}
int nextId = ((laterTimestamp - twepoch) << timestampLeftShift) | laterSequence;
laterSequence = (laterSequence + 1) & sequenceMask;
return nextId;
}
} else { // 时间戳改变,分钟内序列置0
sequence = 0;
laterSequence = 0;
}
// 上次生成ID的时间截
lastTimestamp = timestamp;
// 移位并或运算拼成32位的ID
return ((timestamp - twepoch) << timestampLeftShift) | sequence;
}
/**
* 返回以分钟为单位的当前时
*
* @return 当前时间(分钟)
*/
protected int timeGen() {
// String timestamp = String.valueOf(System.currentTimeMillis() / 1000 / 60);
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
return Integer.valueOf(timestamp);
}
}
@@ -13,6 +13,7 @@ import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
import com.cf.imes.module.executor.enums.*;
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
import com.cf.imes.module.executor.util.deviseData.dataTwo.*;
import com.cf.imes.module.system.api.dict.DictDataApi;
import lombok.extern.slf4j.Slf4j;
@@ -39,6 +40,9 @@ public class ApiTypeRealize {
@Resource
private DictDataApi dictDataApi;
@Resource
SnowflakeIdWorker3rd idWorker;
private Integer num = 0;
private Integer groupNum = 0;
@@ -85,7 +89,9 @@ public class ApiTypeRealize {
Map<Integer, OrderBodyDO> bodyInfoChange = bodyInfoChange(dataBody, orderId);
// System.out.println(" bodyInfoChange " + bodyInfoChange);
// 加工组 少异形数量、板材数量
Map<String, Map<Integer, ?>> group = groupInfoChange(dataModule, orderId, bodyInfoChange);
Map<String, Map<Integer, ?>> group =
groupInfoChange(dataModule, orderId, bodyInfoChange);
Map<Integer, OrderGroupDO> orderGroupDO = (Map<Integer, OrderGroupDO>) group.get("orderGroup");
map.put("groupDO", orderGroupDO.values().stream().collect(Collectors.toList()));
Map<Integer, List<Integer>> groupLists = (Map<Integer, List<Integer>>) group.get("lists");
@@ -276,7 +282,7 @@ public class ApiTypeRealize {
RawGoodsDO rawGoodsDO = RawGoodsDO.builder()
.id((Long) identifierGenerator.nextId(null))
.orderId(orderId)
.rawGoodsId(String.valueOf(goods.getLong("GoodsID")))
.rawGoodsId(goods.getString("GoodsID"))
.goodsName(goods.getString("GoodsName"))
.material(goods.getString("Material"))
.color(goods.getString("Color"))
@@ -291,8 +297,8 @@ public class ApiTypeRealize {
GoodsDO goodsDO = GoodsDO.builder()
.id((Long) identifierGenerator.nextId(null))
.orderId(orderId)
.rawGoodsId(rawGoodsDO.getId())
.goodsId(goods.getLong("GoodsID"))
.rawGoodsId(String.valueOf(rawGoodsDO.getId()))
.goodsId(goods.getString("GoodsID")) // 先填这个,后面改
.goodsName(goods.getString("GoodsName"))
.material(goods.getString("Material"))
.color(goods.getString("Color"))
@@ -401,7 +407,7 @@ public class ApiTypeRealize {
.unit(parts.getString("Units"))
.price(parts.getDouble("Price"))
.isComposite(parts.getBoolean("IsComposite"))
.remark(partsRemarkChange(parts))
.remark(parts.getString("Remark"))
.build();
partsInfos.put(parts.getInteger("DataID"), partsInfo);
@@ -443,6 +449,7 @@ public class ApiTypeRealize {
String remark = JSON.toJSONString(mapList);
return remark;
}
/**
* 板材信息转换 写表 Integer指板材的ItemID板id 加一个板材自定义编号
*/
@@ -462,6 +469,9 @@ public class ApiTypeRealize {
if (dataPlates != null && !dataPlates.isEmpty()) {
JSONArray plateLists = dataPlates.getJSONArray("List");
for (int i = 0; i < plateLists.size(); i++) {
long plateNo = idWorker.nextId();
long obtainingTime = idWorker.obtainingTime();
JSONObject plate = plateLists.getJSONObject(i);
Integer type = Integer.valueOf(dictDataApi.parseDictData("order_plate_type",
@@ -472,8 +482,10 @@ public class ApiTypeRealize {
.id(plateId)
.orderId(orderId)
.name(plate.getString("BoardName"))
.plateNo(plate.getString("CustBlockNo"))
// .plateNo(plate.getString("CustBlockNo"))
.plateNo((obtainingTime)+ Long.toString(plateNo).substring(2))
.type(type)
.goodsId(goodsDOMap.get(plate.getInteger("GoodsID")) != null
? goodsDOMap.get(plate.getInteger("GoodsID")).getId() : plate.getInteger("GoodsID"))
// .width(BigDecimal.valueOf(plate.getDouble("CutWidth")))
@@ -12,8 +12,9 @@ import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
import com.cf.imes.module.executor.enums.OrderItemTypeEnum;
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -22,8 +23,6 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.FILE_UPLOAD_ERR;
/**
* 实现数据格式转换
@@ -37,7 +36,7 @@ public class ExcelTypeRealize {
private SnowFlakeGenerator snowFlakeGenerator;
@Resource
private PlateGoodMapper plateGoodMapper;
SnowflakeIdWorker3rd idWorker;
// 数据转换 + 错误验证
public Map<String, List<?>> changeDate(List<?> list, Long orderId) {
@@ -74,50 +73,45 @@ public class ExcelTypeRealize {
Map<List<Object>, List<OrderPlateImportExcelVO>> goodsMap = value.stream()
.collect(Collectors.groupingBy(
p -> Arrays.asList(p.getGoodsName(),
p.getGoodsName(),
p.getThickness(),
p.getMaterial(),
p.getColor(),
p.getSpec(),
p.getThickness()),
p.getTexture(),
p.getModel(),
p.getBrand()),
Collectors.toList()
));
goodsMap.forEach((goodKey, goodValue) -> {
Long plateGoodId = (Long) snowFlakeGenerator.nextId(null);
PlateGoodDO plateGoodDO = setPlateGoodDO(goodValue.get(0)).setId(plateGoodId).setOrganId(organId);
plateGoodDOS.add(plateGoodDO);
// 板材信息合集,添加生产单id,添加生产单板材设计端商品编码,板材信息写入order_raw_goods
Long rawGoodsId = (Long) snowFlakeGenerator.nextId(null);
RawGoodsDO rawGoodsDO = setRawGoodsDO(goodValue.get(0)).setId(rawGoodsId).setOrderId(orderId);
// 板材信息合集,添加生产单id,添加生产单板材设计端商品编码,板材信息写入order_raw_goods
// 规格分解
List<Double> specList = spec(goodValue.get(0).getSpec());
RawGoodsDO rawGoodsDO = setRawGoodsDO(goodValue.get(0)).setId((Long) snowFlakeGenerator.nextId(null)).setOrderId(orderId);
rawGoodsDOS.add(rawGoodsDO);
Long goodId = (Long) snowFlakeGenerator.nextId(null);
GoodsDO plateDO = setGoodsDO(goodValue.get(0)).setId(goodId).setOrderId(orderId)
.setRawGoodsId(rawGoodsId).setGoodsId(plateGoodId);
.setRawGoodsId(String.valueOf(rawGoodsDO.getId()))
.setHeight(BigDecimal.valueOf(specList.get(0))).setWidth(BigDecimal.valueOf(specList.get(1))); // 在good_id为空的时候,首先赋值为空值
goodsDOS.add(plateDO);
// 赋值给板件未对应前order_raw_goods的id
// 赋值给板件未对应前order_raw_goods的id
for (OrderPlateImportExcelVO reqVO : goodValue) {
reqVO.setGoodId(goodId);
}
});
} else { // 商品编码有的
// 判断商品是否存在板材库中
PlateGoodDO plateGoodDO = plateGoodMapper.selectOne(PlateGoodDO::getGoodsId, value.get(0).getGoodsId());
Long plateGoodId = null;
if (plateGoodDO != null) {//存在
plateGoodId = plateGoodDO.getId();
} else {
plateGoodId = (Long) snowFlakeGenerator.nextId(null);
PlateGoodDO plateGoodDONew = setPlateGoodDO(value.get(0)).setId(plateGoodId).setOrganId(organId);
plateGoodDOS.add(plateGoodDONew);
}
// 板材信息合集,添加生产单id,添加生产单板材设计端商品编码,板材信息写入order_raw_goods
Long rawGoodsId = (Long) snowFlakeGenerator.nextId(null);
RawGoodsDO rawGoodsDO = setRawGoodsDO(value.get(0)).setId(rawGoodsId).setOrderId(orderId);
List<Double> specList = spec(value.get(0).getSpec());
// 板材信息合集,添加生产单id,添加生产单板材设计端商品编码,板材信息写入order_raw_goods
RawGoodsDO rawGoodsDO = setRawGoodsDO(value.get(0)).setId((Long) snowFlakeGenerator.nextId(null)).setOrderId(orderId);
rawGoodsDOS.add(rawGoodsDO);
Long goodId = (Long) snowFlakeGenerator.nextId(null);
GoodsDO plateDO = setGoodsDO(value.get(0)).setId(goodId).setOrderId(orderId)
.setRawGoodsId(rawGoodsId).setGoodsId(plateGoodId);
.setRawGoodsId(String.valueOf(rawGoodsDO.getId())).setGoodsId(String.valueOf(rawGoodsDO.getRawGoodsId()))
.setHeight(BigDecimal.valueOf(specList.get(0))).setWidth(BigDecimal.valueOf(specList.get(1)));
goodsDOS.add(plateDO);
// 赋值给板件未对应前order_raw_goods的id
// 赋值给板件未对应前order_raw_goods的id
for (OrderPlateImportExcelVO reqVO : value) {
reqVO.setGoodId(goodId);
}
@@ -179,10 +173,14 @@ public class ExcelTypeRealize {
//板材
plateCountByCombination[0] = plateCountByCombination[0] + Double.parseDouble(combination.getGoodsNumber());
for (int i = 0; i < Integer.parseInt(combination.getGoodsNumber()); i++) {
long plateNo = idWorker.nextId();
long obtainingTime = idWorker.obtainingTime();
Long plateId = (Long) snowFlakeGenerator.nextId(null);
PlateDO plateDO = PlateDO.builder()
.id(plateId).orderId(orderId).name(combination.getName()).plateNo(combination.getPlateNo())
.goodsId(combination.getGoodId()).width(BigDecimal.valueOf(Double.parseDouble(combination.getWidth())))
.plateNo(((obtainingTime)+ Long.toString(plateNo).substring(2)))
.height(BigDecimal.valueOf(Double.parseDouble(combination.getHeight())))
.thickness(BigDecimal.valueOf(Double.parseDouble(combination.getThickness())))
.splitWidth(BigDecimal.valueOf(Double.parseDouble(combination.getSplitWidth())))
@@ -300,15 +298,22 @@ public class ExcelTypeRealize {
}
// spec分离数据
public List<String> spec(String spec) {
List<String> list = null;
public List<Double> spec(String spec) {
List<Double> list = new ArrayList<>();
String[] parts = spec.split("\\×");
if (parts.length <= 1) {
return null;
}
for (int i = 0; i < parts.length; i++) {
list.add(parts[i]);
for (int i = 0; i < 3; i++) {
Double num = 0.0;
try {
if (i < parts.length)
num = Double.parseDouble(parts[i]);
} catch (NumberFormatException e) {
// 转换失败,保持num为0
}
list.add(num);
}
return list;
}