diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java new file mode 100644 index 000000000..1fbae2fc0 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/OptimizePlanController.java @@ -0,0 +1,36 @@ +package com.cf.imes.module.executor.controller.admin.plan; + +import com.cf.imes.framework.common.pojo.CommonResult; +import com.cf.imes.module.executor.controller.admin.plan.vo.PlateOptimize; +import com.cf.imes.module.executor.service.optimizeplan.OptimizePlanService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author there + */ +@RestController +@RequestMapping("/executor/optimize-plan") +@Tag(name= "优化排单") +public class OptimizePlanController { + + @Resource + private OptimizePlanService optimizePlanService; + + @GetMapping("/getPlateListByPlanId") + @Operation(summary = "根据排单id获取板材列表") + @PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')") + public CommonResult> getPlateListByPlanId(@Schema(description = "排单id") @RequestParam("planId") Long planId) { + return CommonResult.success(optimizePlanService.getPlateListByPlanId(planId)); + } + +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/PlanController.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/PlanController.java index 21e9e9666..378095c95 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/PlanController.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/PlanController.java @@ -82,8 +82,8 @@ public class PlanController { @Operation(summary = "根据排单id获取板材列表") @Parameter(name = "id", description = "排单id", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('executor:plan:query')") - public CommonResult> getPlateByPlanId(@RequestParam("id") Long id) { - return success(planService.getPlateByPlanId(id)); + public CommonResult> getPlateByPlanId(@Valid GetPlateByPlanIdVO vo) { + return success(planService.getPlateByPlanId(vo)); } @GetMapping("/page") @@ -129,4 +129,17 @@ public class PlanController { BeanUtils.toBean(list, PlanRespVO.class)); } + @GetMapping("/export-plate-excel") + @Operation(summary = "导出板材 Excel") + @PreAuthorize("@ss.hasPermission('executor:plan:export')") + @OperateLog(type = EXPORT) + public void exportPlateExcel(@Valid PlanPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = planService.getPlanPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "排单.xls", "数据", PlanRespVO.class, + BeanUtils.toBean(list, PlanRespVO.class)); + } + } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/GetPlateByPlanIdVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/GetPlateByPlanIdVO.java new file mode 100644 index 000000000..3e93de5a3 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/GetPlateByPlanIdVO.java @@ -0,0 +1,43 @@ +package com.cf.imes.module.executor.controller.admin.plan.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; +import java.util.Date; + +import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Data +public class GetPlateByPlanIdVO { + @Schema(description = "排单id") + @NotNull(message = "排单id不能空") + private Long palnId; + @Schema(description = "矩形") + private boolean rectangle; + @Schema(description = "异形") + private boolean specialShaped; + @Schema(description = "造型") + private boolean sculpt; + @Schema(description = "有挖穿造型") + private boolean holeThrough; + @Schema(description = "有挖穿孔") + private boolean burrow; + @Schema(description = "有二维纹路") + private boolean twoDimensionalToolPath; + @Schema(description = "开始时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginDate; + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endDate; + @Schema(description = "长 小范围") + private BigDecimal longMinRang; + @Schema(description = "长 大范围") + private BigDecimal longMaxRang; + @Schema(description = "宽 小范围") + private BigDecimal widthMinRang; + @Schema(description = "宽 大范围") + private BigDecimal widthMaxRang; +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateOptimize.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateOptimize.java new file mode 100644 index 000000000..de41205b5 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/controller/admin/plan/vo/PlateOptimize.java @@ -0,0 +1,44 @@ +package com.cf.imes.module.executor.controller.admin.plan.vo; + +import com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author there + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PlateOptimize { + @Schema(description = "是否已排") + private Boolean isPlan; + @Schema(description = "商品名称") + private String goodsName; + @Schema(description = "商品材质") + private String material; + @Schema(description = "商品颜色") + private String color; + @Schema(description = "宽") + private BigDecimal width; + @Schema(description = "高") + private BigDecimal height; + @Schema(description = "厚") + private BigDecimal thickness; + @Schema(description = "小板数量") + private Integer plateNum; + @Schema(description = "有纹路") + private Boolean hasLines; + + @Schema(description = "余料板列表") + private List plateDOList; + + +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/remainplaten/RemainPlateDO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/remainplaten/RemainPlateDO.java new file mode 100644 index 000000000..c7bbf87dc --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/dataobject/remainplaten/RemainPlateDO.java @@ -0,0 +1,96 @@ +package com.cf.imes.module.executor.dal.dataobject.remainplaten; + +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cf.imes.framework.mybatis.core.dataobject.BaseDO; +import lombok.*; + +import java.math.BigDecimal; + +/** + * 生产单余料板表 order_remain_plate_{N} DO + * + * @author 晨丰科技 + */ +@TableName("order_remain_plate") +@KeySequence("order_remain_plate_n_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class RemainPlateDO extends BaseDO { + + /** + * 余料板 ID + */ + @TableId + private Long id; + /** + * 排单 ID + */ + private Long planId; + /** + * 初始排单 ID + */ + private Long initPlanId; + /** + * 余料板状态,0未使用,1使用中,2已使用 + */ + private Integer status; + /** + * 商品 ID + */ + private String goodsId; + /** + * 商品名 + */ + private String name; + /** + * 材料 + */ + private String material; + /** + * 颜色 + */ + private String color; + /** + * 宽度 + */ + private BigDecimal width; + /** + * 长度 + */ + private BigDecimal length; + /** + * 厚度 + */ + private BigDecimal thickness; + /** + * 品牌 + */ + private String brand; + /** + * 放置样式,0正面,1正面右转,2正面后转,3正面左转,4反面,5反面右转,6反面后转,7反面左转 + */ + private Integer placeStyle; + /** + * 仓库名 + */ + private String store; + /** + * 数量 + */ + private Integer count; + /** + * 备注 + */ + private String remark; + /** + * 轮廊数据,Json 串 + */ + private String outline; + +} \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java index d2d1b6f42..171bbb61a 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plan/PlanMapper.java @@ -34,4 +34,5 @@ public interface PlanMapper extends BaseMapperX { .orderByDesc(PlanDO::getId)); } + List selectPlateListByPlanId(Long planId); } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java index b489f289c..2d2a41097 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/dal/mysql/plate/PlateMapper.java @@ -10,6 +10,7 @@ import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX; import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX; import com.cf.imes.module.executor.controller.admin.plan.vo.PlatePage; import com.cf.imes.module.executor.controller.admin.plan.vo.PlateResList; +import com.cf.imes.module.executor.dal.dataobject.order.OrderDO; import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO; import org.apache.ibatis.annotations.Mapper; import com.cf.imes.module.executor.controller.admin.plate.vo.*; @@ -63,5 +64,5 @@ public interface PlateMapper extends BaseMapperX { IPage selectPlatePage(@Param("page") IPage page, @Param("orderId")Long organId, @Param("goodsId") String goodsId); - List selectPlateByPlanId(Long id); + List selectPlateByPlanId(@Param(Constants.WRAPPER) Wrapper wrapper); } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanService.java new file mode 100644 index 000000000..3d15ba2c5 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanService.java @@ -0,0 +1,9 @@ +package com.cf.imes.module.executor.service.optimizeplan; + +import com.cf.imes.module.executor.controller.admin.plan.vo.PlateOptimize; + +import java.util.List; + +public interface OptimizePlanService { + List getPlateListByPlanId(Long planId); +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java new file mode 100644 index 000000000..01ccc83d0 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/optimizeplan/OptimizePlanServiceImpl.java @@ -0,0 +1,23 @@ +package com.cf.imes.module.executor.service.optimizeplan; + +import com.cf.imes.module.executor.controller.admin.plan.vo.PlateOptimize; +import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author there + */ +@Service +public class OptimizePlanServiceImpl implements OptimizePlanService{ + + @Resource + private PlanMapper planMapper; + + @Override + public List getPlateListByPlanId(Long planId) { + return planMapper.selectPlateListByPlanId(planId); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanService.java index 562fc4c01..1ab45f9dc 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanService.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanService.java @@ -60,5 +60,5 @@ public interface PlanService { Boolean cancellation(Long id); - List getPlateByPlanId(Long id); + List getPlateByPlanId(GetPlateByPlanIdVO vo); } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java index 2088840fd..9a519b961 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java @@ -314,17 +314,37 @@ public class PlanServiceImpl implements PlanService { } @Override - public List getPlateByPlanId(Long id) { - validatePlanExists(id); - List list = plateMapper.selectPlateByPlanId(id); + public List getPlateByPlanId(GetPlateByPlanIdVO vo) { + validatePlanExists(vo.getPalnId()); + QueryWrapperX queryWrapperX = new QueryWrapperX<>(); + List filterTypes = new ArrayList<>(); + if (vo.isHoleThrough()) { + filterTypes.add(1); + } + if (vo.isBurrow()) { + filterTypes.add(2); + } + if (vo.isTwoDimensionalToolPath()) { + filterTypes.add(4); + } + queryWrapperX.betweenIfPresent("a.width", new BigDecimal[]{vo.getWidthMinRang(), vo.getWidthMaxRang()}) + .betweenIfPresent("a.height", new BigDecimal[]{vo.getLongMinRang(), vo.getLongMaxRang()}) + .inIfPresent("c.filter_type", filterTypes) + .betweenIfPresent("f.delivery_date", new Date[]{vo.getBeginDate(), vo.getEndDate()}) + .inIfPresent("a.filter_type", filterTypes) + .eq("a.id", vo.getPalnId()) + ; + + + List list = plateMapper.selectPlateByPlanId(queryWrapperX); Set bodyIds = list.stream().map(e -> e.getBodyId()).collect(Collectors.toSet()); Set roomIds = list.stream().map(e -> e.getRoomId()).collect(Collectors.toSet()); List moduleDOS = moduleMapper.selectList(new LambdaQueryWrapperX().in(ModuleDO::getId, bodyIds).eq(ModuleDO::getType, 2) .or().in(ModuleDO::getId, roomIds).eq(ModuleDO::getType, 1) ); for (PlateResList resList : list) { - resList.setBodyName(moduleDOS.stream().filter(e->Objects.equals(e.getId(), resList.getBodyId())).map(e->e.getName()).findAny().orElse(null)); - resList.setRoomName(moduleDOS.stream().filter(e->Objects.equals(e.getId(), resList.getRoomId())).map(e->e.getName()).findAny().orElse(null)); + resList.setBodyName(moduleDOS.stream().filter(e -> Objects.equals(e.getId(), resList.getBodyId())).map(e -> e.getName()).findAny().orElse(null)); + resList.setRoomName(moduleDOS.stream().filter(e -> Objects.equals(e.getId(), resList.getRoomId())).map(e -> e.getName()).findAny().orElse(null)); } return list; } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/ZLibUtils.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/ZLibUtils.java new file mode 100644 index 000000000..a47254e05 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/ZLibUtils.java @@ -0,0 +1,156 @@ +package com.cf.imes.module.executor.util; + +import java.io.*; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; + + + +//ZLib压缩工具 +public class ZLibUtils { + + //压缩直接数组 + public static byte[] compress(byte[] data) { + byte[] output = new byte[0]; + + Deflater compresser = new Deflater(); + + compresser.reset(); + compresser.setInput(data); + compresser.finish(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); + try { + byte[] buf = new byte[1024]; + while (!compresser.finished()) { + int i = compresser.deflate(buf); + bos.write(buf, 0, i); + } + output = bos.toByteArray(); + } catch (Exception e) { + output = data; + e.printStackTrace(); + } finally { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + compresser.end(); + return output; + } + + //压缩 字节数组到输出流 + public static void compress(byte[] data, OutputStream os) { + DeflaterOutputStream dos = new DeflaterOutputStream(os); + + try { + dos.write(data, 0, data.length); + + dos.finish(); + + dos.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //解压缩 字节数组 + public static byte[] decompress(byte[] data) { + byte[] output = new byte[0]; + + Inflater decompresser = new Inflater(); + decompresser.reset(); + decompresser.setInput(data); + + ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); + try { + byte[] buf = new byte[1024]; + while (!decompresser.finished()) { + int i = decompresser.inflate(buf); + o.write(buf, 0, i); + } + output = o.toByteArray(); + } catch (Exception e) { + output = data; + e.printStackTrace(); + } finally { + try { + o.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + decompresser.end(); + return output; + } + + //解压缩 输入流 到字节数组 + public static byte[] decompress(InputStream is) { + InflaterInputStream iis = new InflaterInputStream(is); + ByteArrayOutputStream o = new ByteArrayOutputStream(1024); + try { + int i = 1024; + byte[] buf = new byte[i]; + + while ((i = iis.read(buf, 0, i)) > 0) { + o.write(buf, 0, i); + } + + } catch (IOException e) { + e.printStackTrace(); + } + return o.toByteArray(); + } + + public static void main(String[] args) + { + //测试字节数组 + System.err.println("字节压缩/解压缩测试"); + String inputStr = "snowolf@zlex.org;dongliang@zlex.org;zlex.dongliang@zlex.org"; + System.err.println("输入字符串:\t" + inputStr); + byte[] input = inputStr.getBytes(); + System.err.println("输入字节长度:\t" + input.length); + + byte[] data = ZLibUtils.compress(input); + System.err.println("压缩后字节长度:\t" + data.length); + + byte[] output = ZLibUtils.decompress(data); + System.err.println("解压缩后字节长度:\t" + output.length); + String outputStr = new String(output); + System.err.println("输出字符串:\t" + outputStr); + + //测试文件 + String filename = "zlib"; + File file = new File(filename); + System.err.println("文件压缩/解压缩测试"); + try { + + FileOutputStream fos = new FileOutputStream(file); + ZLibUtils.compress(input, fos); + fos.close(); + System.err.println("压缩后字节长度:\t" + file.length()); + } catch (Exception e) { + System.err.println("错误:\t" + e.getMessage()); + } + + try { + FileInputStream fis = new FileInputStream(file); + output = ZLibUtils.decompress(fis); + fis.close(); + + } catch (Exception e) { + System.err.println("错误:\t" + e.getMessage()); + } + System.err.println("解压缩后字节长度:\t" + output.length); + outputStr = new String(output); + System.err.println("输出字符串:\t" + outputStr); + } + +} + + + diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml index 7476ac020..9f8bf6c24 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plan/PlanMapper.xml @@ -9,4 +9,25 @@ 文档可见:https://www.cf.com/MyBatis/x-plugins/ --> + + + + + + + + + + + \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml index d013fb662..0ff8688dc 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/resources/mapper/plate/PlateMapper.xml @@ -22,11 +22,14 @@ \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/goods/GoodsServiceImplTest.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/goods/GoodsServiceImplTest.java index 8eeb64968..9f536a6b3 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/goods/GoodsServiceImplTest.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/goods/GoodsServiceImplTest.java @@ -108,7 +108,7 @@ public class GoodsServiceImplTest extends BaseDbUnitTest { @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetGoodsPage() { - // mock 数据 + /* // mock 数据 GoodsDO dbGoods = randomPojo(GoodsDO.class, o -> { // 等会查询到 o.setOrderNo(null); o.setGoodsId(null); @@ -172,7 +172,7 @@ public class GoodsServiceImplTest extends BaseDbUnitTest { // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbGoods, pageResult.getList().get(0)); + assertPojoEquals(dbGoods, pageResult.getList().get(0));*/ } } \ No newline at end of file diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/zlib/ZlibTest.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/zlib/ZlibTest.java new file mode 100644 index 000000000..f4bad2238 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/zlib/ZlibTest.java @@ -0,0 +1,108 @@ +package com.cf.imes.module.executor.service.zlib; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.handler.codec.compression.JdkZlibDecoder; +import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.handler.codec.compression.ZlibDecoder; +import com.cf.imes.module.executor.util.ZLibUtils; +import lombok.Data; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.sql.PreparedStatement; +import java.util.Base64; +import java.util.List; +import java.util.Objects; +import java.util.zip.Inflater; + +public class ZlibTest { + + private JdbcTemplate jdbcTemplate; + + @BeforeEach + public void init() { + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + druidDataSource.setUrl("jdbc:mysql://192.168.1.245:3306/cferp_test_1"); + druidDataSource.setUsername("mes_visitor"); + druidDataSource.setPassword("cf123456"); + //创建jdbc模板对象 + JdbcTemplate jdbcTemplate = new JdbcTemplate(); + jdbcTemplate.setDataSource(druidDataSource); + this.jdbcTemplate = jdbcTemplate; + } + + @Test + void get() throws UnsupportedEncodingException { + /*String source = "xxxxxxxxx"; + byte[] compress = ZLibUtils.compress(source.getBytes()); + System.out.println(compress.length);*/ + List list = jdbcTemplate.query("select * from order_box_block limit 10", new BeanPropertyRowMapper(Bean.class)); + for (Bean bean : list) { + if (!Objects.isNull(bean.Data)) { + System.out.println(new String(ZLibUtils.decompress(new ByteArrayInputStream(Base64.getDecoder().decode(bean.Data))), "utf-8")); + System.err.println("------------------------------------------"); + } + } + } + + @Test + void test() { + String source = "xxxxxxxxxxaassad"; + //压缩 + byte[] compress = ZLibUtils.compress(source.getBytes()); + String str = new String(compress); + System.out.println(str); + //解压 + System.out.println(new String(ZLibUtils.decompress(new ByteArrayInputStream(compress)))); + + + } + + public void insertByteArray(String tableName, byte[] data, String columnName) { + final String sql = "INSERT INTO " + tableName + " (" + columnName + ") VALUES (?)"; + jdbcTemplate.update( + conn -> { + PreparedStatement ps = conn.prepareStatement(sql); + ps.setBinaryStream(1, new ByteArrayInputStream(data), data.length); + return ps; + } + ); + } + + + public static String uncompress(byte[] input) throws IOException { + Inflater inflater = new Inflater(); + inflater.setInput(input); + ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length); + try { + byte[] buff = new byte[1024]; + while (!inflater.finished()) { + int count = inflater.inflate(buff); + baos.write(buff, 0, count); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + baos.close(); + } + inflater.end(); + byte[] output = baos.toByteArray(); + return new String(output, "UTF-8"); + } + + + @Data + public static class Bean { + long BoxID; + long ShardKey; + long OrderNo; + byte[] Data; + long CompanyID; + } +}