mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
获取排单板材列表添加必要字段
This commit is contained in:
+36
@@ -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<List<PlateOptimize>> getPlateListByPlanId(@Schema(description = "排单id") @RequestParam("planId") Long planId) {
|
||||
return CommonResult.success(optimizePlanService.getPlateListByPlanId(planId));
|
||||
}
|
||||
|
||||
}
|
||||
+15
-2
@@ -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<List<PlateResList>> getPlateByPlanId(@RequestParam("id") Long id) {
|
||||
return success(planService.getPlateByPlanId(id));
|
||||
public CommonResult<List<PlateResList>> 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<PlanRespVO> list = planService.getPlanPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "排单.xls", "数据", PlanRespVO.class,
|
||||
BeanUtils.toBean(list, PlanRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -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;
|
||||
}
|
||||
+44
@@ -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<RemainPlateDO> plateDOList;
|
||||
|
||||
|
||||
}
|
||||
+96
@@ -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;
|
||||
|
||||
}
|
||||
+1
@@ -34,4 +34,5 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
|
||||
.orderByDesc(PlanDO::getId));
|
||||
}
|
||||
|
||||
List<PlateOptimize> selectPlateListByPlanId(Long planId);
|
||||
}
|
||||
+2
-1
@@ -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<PlateDO> {
|
||||
|
||||
IPage<PlatePage> selectPlatePage(@Param("page") IPage<PlatePage> page, @Param("orderId")Long organId, @Param("goodsId") String goodsId);
|
||||
|
||||
List<PlateResList> selectPlateByPlanId(Long id);
|
||||
List<PlateResList> selectPlateByPlanId(@Param(Constants.WRAPPER) Wrapper<PlateDO> wrapper);
|
||||
}
|
||||
+9
@@ -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<PlateOptimize> getPlateListByPlanId(Long planId);
|
||||
}
|
||||
+23
@@ -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<PlateOptimize> getPlateListByPlanId(Long planId) {
|
||||
return planMapper.selectPlateListByPlanId(planId);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -60,5 +60,5 @@ public interface PlanService {
|
||||
|
||||
Boolean cancellation(Long id);
|
||||
|
||||
List<PlateResList> getPlateByPlanId(Long id);
|
||||
List<PlateResList> getPlateByPlanId(GetPlateByPlanIdVO vo);
|
||||
}
|
||||
+25
-5
@@ -314,17 +314,37 @@ public class PlanServiceImpl implements PlanService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlateResList> getPlateByPlanId(Long id) {
|
||||
validatePlanExists(id);
|
||||
List<PlateResList> list = plateMapper.selectPlateByPlanId(id);
|
||||
public List<PlateResList> getPlateByPlanId(GetPlateByPlanIdVO vo) {
|
||||
validatePlanExists(vo.getPalnId());
|
||||
QueryWrapperX<PlateDO> queryWrapperX = new QueryWrapperX<>();
|
||||
List<Integer> 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<PlateResList> list = plateMapper.selectPlateByPlanId(queryWrapperX);
|
||||
Set<Long> bodyIds = list.stream().map(e -> e.getBodyId()).collect(Collectors.toSet());
|
||||
Set<Long> roomIds = list.stream().map(e -> e.getRoomId()).collect(Collectors.toSet());
|
||||
List<ModuleDO> moduleDOS = moduleMapper.selectList(new LambdaQueryWrapperX<ModuleDO>().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;
|
||||
}
|
||||
|
||||
+156
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
@@ -9,4 +9,25 @@
|
||||
文档可见:https://www.cf.com/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<resultMap id="map" type="com.cf.imes.module.executor.controller.admin.plan.vo.PlateOptimize">
|
||||
<result column="goods_name" property="goodsName"/>
|
||||
<result column="material" property="material"/>
|
||||
<result column="color" property="color"/>
|
||||
<result column="width" property="width"/>
|
||||
<result column="height" property="height"/>
|
||||
<result column="plateNum" property="plateNum"/>
|
||||
<collection property="plateDOList" javaType="java.util.List" ofType="com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPlateListByPlanId"
|
||||
resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlateOptimize">
|
||||
select a.goods_name, a.material, a.color, a.width, a.height, a.thickness, count(b.id) as plateNum, d.*
|
||||
from order_goods a
|
||||
left join order_plate b on a.goods_id = b.goods_id
|
||||
left join prod_plan_order c on c.order_id = b.order_id
|
||||
left join order_remain_plate d on a.goods_id = d.goods_id and d.plan_id = c.plan_id
|
||||
GROUP BY a.id, d.id
|
||||
where c.plan_id = #{planId}
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
+4
-1
@@ -27,6 +27,9 @@
|
||||
left join order_item b on a.id = b.data_id and b.type =1
|
||||
left join order_plan_item c on a.id = c.item_id
|
||||
left join order_goods e on e.goods_id = a.goods_id and e.order_id = a.order_id
|
||||
where c.plan_id = #{id}
|
||||
left join `order` f on f.id = a.order_id
|
||||
${ew.customSqlSegment}
|
||||
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
+2
-2
@@ -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));*/
|
||||
}
|
||||
|
||||
}
|
||||
+108
@@ -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<Bean> list = jdbcTemplate.query("select * from order_box_block limit 10", new BeanPropertyRowMapper<Bean>(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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user