feat(box): 添加纸箱品牌和产品拖拽排序功能

- 新增 BoxBrandDragCmd 和 BoxProductDragCmd 命令类
- 在 BoxBrandController 和 BoxProductController 中增加 dragBoxBrand 和 dragBoxProduct 接口
- 在 BoxBrandServiceI 和 BoxProductServiceI 接口中定义 drag 方法
- 实现 BoxBrandServiceImpl 和 BoxProductServiceImpl 的 drag 方法逻辑
- 在 BoxBrandGatewayImpl 和 BoxProductGatewayImpl 中实现拖拽排序的核心算法
- 为 BoxBrandDO 和 BoxProductDO 添加 sort 字段及数据库映射
- 提供批量重置排序的 SQL 注解方式实现
- 调整查询逻辑以支持按 sort 升序排列
- 补充 BoxProductListQry 查询条件字段并优化查询顺序
This commit is contained in:
shenyifei 2025-11-10 00:00:57 +08:00
parent ebfdedc01a
commit 03e24c868f
21 changed files with 361 additions and 39 deletions

View File

@ -8,6 +8,7 @@ import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.BoxBrandServiceI; import com.xunhong.erp.turbo.api.biz.api.BoxBrandServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
@ -34,7 +35,7 @@ public class BoxBrandController {
private final BoxBrandServiceI boxBrandService; private final BoxBrandServiceI boxBrandService;
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
@GetMapping("listBoxBrand") @GetMapping("listBoxBrand")
@Operation(summary = "纸箱品牌列表", method = "GET") @Operation(summary = "纸箱品牌列表", method = "GET")
public MultiResponse<BoxBrandVO> listBoxBrand(@ModelAttribute @Validated BoxBrandListQry boxBrandListQry) { public MultiResponse<BoxBrandVO> listBoxBrand(@ModelAttribute @Validated BoxBrandListQry boxBrandListQry) {
@ -42,7 +43,7 @@ public class BoxBrandController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_CREATE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_CREATE})
@PostMapping("createBoxBrand") @PostMapping("createBoxBrand")
@Operation(summary = "创建纸箱品牌", method = "POST") @Operation(summary = "创建纸箱品牌", method = "POST")
public SingleResponse<BoxBrandVO> createBoxBrand(@RequestBody @Validated BoxBrandCreateCmd boxBrandCreateCmd) { public SingleResponse<BoxBrandVO> createBoxBrand(@RequestBody @Validated BoxBrandCreateCmd boxBrandCreateCmd) {
@ -50,7 +51,7 @@ public class BoxBrandController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
@GetMapping("showBoxBrand") @GetMapping("showBoxBrand")
@Operation(summary = "纸箱品牌详情", method = "GET") @Operation(summary = "纸箱品牌详情", method = "GET")
public SingleResponse<BoxBrandVO> showBoxBrand(@ModelAttribute @Validated BoxBrandShowQry boxBrandShowQry) { public SingleResponse<BoxBrandVO> showBoxBrand(@ModelAttribute @Validated BoxBrandShowQry boxBrandShowQry) {
@ -58,7 +59,7 @@ public class BoxBrandController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
@GetMapping("pageBoxBrand") @GetMapping("pageBoxBrand")
@Operation(summary = "纸箱品牌列表", method = "GET") @Operation(summary = "纸箱品牌列表", method = "GET")
public PageResponse<BoxBrandVO> pageBoxBrand(@ModelAttribute @Validated BoxBrandPageQry boxBrandPageQry) { public PageResponse<BoxBrandVO> pageBoxBrand(@ModelAttribute @Validated BoxBrandPageQry boxBrandPageQry) {
@ -67,7 +68,7 @@ public class BoxBrandController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_UPDATE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_UPDATE})
@RequestMapping(value = "updateBoxBrand", method = {RequestMethod.PATCH, RequestMethod.PUT}) @RequestMapping(value = "updateBoxBrand", method = {RequestMethod.PATCH, RequestMethod.PUT})
@Operation(summary = "纸箱品牌更新", method = "PATCH") @Operation(summary = "纸箱品牌更新", method = "PATCH")
public SingleResponse<BoxBrandVO> updateBoxBrand(@RequestBody @Validated BoxBrandUpdateCmd boxBrandUpdateCmd) { public SingleResponse<BoxBrandVO> updateBoxBrand(@RequestBody @Validated BoxBrandUpdateCmd boxBrandUpdateCmd) {
@ -75,11 +76,20 @@ public class BoxBrandController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_DELETE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_DELETE})
@DeleteMapping("destroyBoxBrand") @DeleteMapping("destroyBoxBrand")
@Operation(summary = "纸箱品牌删除", method = "DELETE") @Operation(summary = "纸箱品牌删除", method = "DELETE")
public Response destroyBoxBrand(@RequestBody @Validated BoxBrandDestroyCmd boxBrandDestroyCmd) { public Response destroyBoxBrand(@RequestBody @Validated BoxBrandDestroyCmd boxBrandDestroyCmd) {
boxBrandService.destroy(boxBrandDestroyCmd); boxBrandService.destroy(boxBrandDestroyCmd);
return Response.buildSuccess(); return Response.buildSuccess();
} }
@SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_UPDATE})
@RequestMapping(value = "dragBoxBrand", method = {RequestMethod.PATCH, RequestMethod.PUT})
@Operation(summary = "纸箱品牌拖拽排序", method = "PATCH")
public Response dragBoxBrand(@RequestBody @Validated BoxBrandDragCmd boxBrandDragCmd) {
boxBrandService.drag(boxBrandDragCmd);
return Response.buildSuccess();
}
} }

View File

@ -8,6 +8,7 @@ import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.BoxProductServiceI; import com.xunhong.erp.turbo.api.biz.api.BoxProductServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
@ -34,7 +35,7 @@ public class BoxProductController {
private final BoxProductServiceI boxProductService; private final BoxProductServiceI boxProductService;
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
@GetMapping("listBoxProduct") @GetMapping("listBoxProduct")
@Operation(summary = "纸箱产品列表", method = "GET") @Operation(summary = "纸箱产品列表", method = "GET")
public MultiResponse<BoxProductVO> listBoxProduct(@ModelAttribute @Validated BoxProductListQry boxProductListQry) { public MultiResponse<BoxProductVO> listBoxProduct(@ModelAttribute @Validated BoxProductListQry boxProductListQry) {
@ -42,7 +43,7 @@ public class BoxProductController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_CREATE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_CREATE})
@PostMapping("createBoxProduct") @PostMapping("createBoxProduct")
@Operation(summary = "创建纸箱产品", method = "POST") @Operation(summary = "创建纸箱产品", method = "POST")
public SingleResponse<BoxProductVO> createBoxProduct(@RequestBody @Validated BoxProductCreateCmd boxProductCreateCmd) { public SingleResponse<BoxProductVO> createBoxProduct(@RequestBody @Validated BoxProductCreateCmd boxProductCreateCmd) {
@ -50,7 +51,7 @@ public class BoxProductController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
@GetMapping("showBoxProduct") @GetMapping("showBoxProduct")
@Operation(summary = "纸箱产品详情", method = "GET") @Operation(summary = "纸箱产品详情", method = "GET")
public SingleResponse<BoxProductVO> showBoxProduct(@ModelAttribute @Validated BoxProductShowQry boxProductShowQry) { public SingleResponse<BoxProductVO> showBoxProduct(@ModelAttribute @Validated BoxProductShowQry boxProductShowQry) {
@ -58,7 +59,7 @@ public class BoxProductController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
@GetMapping("pageBoxProduct") @GetMapping("pageBoxProduct")
@Operation(summary = "纸箱产品列表", method = "GET") @Operation(summary = "纸箱产品列表", method = "GET")
public PageResponse<BoxProductVO> pageBoxProduct(@ModelAttribute @Validated BoxProductPageQry boxProductPageQry) { public PageResponse<BoxProductVO> pageBoxProduct(@ModelAttribute @Validated BoxProductPageQry boxProductPageQry) {
@ -67,7 +68,7 @@ public class BoxProductController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_UPDATE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_UPDATE})
@RequestMapping(value = "updateBoxProduct", method = {RequestMethod.PATCH, RequestMethod.PUT}) @RequestMapping(value = "updateBoxProduct", method = {RequestMethod.PATCH, RequestMethod.PUT})
@Operation(summary = "纸箱产品更新", method = "PATCH") @Operation(summary = "纸箱产品更新", method = "PATCH")
public SingleResponse<BoxProductVO> updateBoxProduct(@RequestBody @Validated BoxProductUpdateCmd boxProductUpdateCmd) { public SingleResponse<BoxProductVO> updateBoxProduct(@RequestBody @Validated BoxProductUpdateCmd boxProductUpdateCmd) {
@ -75,11 +76,20 @@ public class BoxProductController {
} }
@SaCheckLogin @SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_DELETE}) // @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_DELETE})
@DeleteMapping("destroyBoxProduct") @DeleteMapping("destroyBoxProduct")
@Operation(summary = "纸箱产品删除", method = "DELETE") @Operation(summary = "纸箱产品删除", method = "DELETE")
public Response destroyBoxProduct(@RequestBody @Validated BoxProductDestroyCmd boxProductDestroyCmd) { public Response destroyBoxProduct(@RequestBody @Validated BoxProductDestroyCmd boxProductDestroyCmd) {
boxProductService.destroy(boxProductDestroyCmd); boxProductService.destroy(boxProductDestroyCmd);
return Response.buildSuccess(); return Response.buildSuccess();
} }
@SaCheckLogin
// @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_UPDATE})
@RequestMapping(value = "dragBoxProduct", method = {RequestMethod.PATCH, RequestMethod.PUT})
@Operation(summary = "纸箱产品拖拽排序", method = "PATCH")
public Response dragBoxProduct(@RequestBody @Validated BoxProductDragCmd boxProductDragCmd) {
boxProductService.drag(boxProductDragCmd);
return Response.buildSuccess();
}
} }

View File

@ -0,0 +1,21 @@
package com.xunhong.erp.turbo.biz.app.executor.query;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.biz.domain.gateway.BoxBrandGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author shenyifei
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class BoxBrandDragCmdExe {
private final BoxBrandGateway boxBrandGateway;
public void execute(BoxBrandDragCmd boxBrandDragCmd) {
boxBrandGateway.drag(boxBrandDragCmd);
}
}

View File

@ -0,0 +1,21 @@
package com.xunhong.erp.turbo.biz.app.executor.query;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.biz.domain.gateway.BoxProductGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author shenyifei
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class BoxProductDragCmdExe {
private final BoxProductGateway boxProductGateway;
public void execute(BoxProductDragCmd boxProductDragCmd) {
boxProductGateway.drag(boxProductDragCmd);
}
}

View File

@ -3,6 +3,7 @@ package com.xunhong.erp.turbo.biz.app.service;
import com.xunhong.erp.turbo.api.biz.api.BoxBrandServiceI; import com.xunhong.erp.turbo.api.biz.api.BoxBrandServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
@ -12,6 +13,7 @@ import com.xunhong.erp.turbo.base.dto.PageDTO;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandCreateCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandCreateCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandDestroyCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandDestroyCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandUpdateCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxBrandUpdateCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandDragCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandListQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandListQryExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandPageQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandPageQryExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandShowQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxBrandShowQryExe;
@ -33,10 +35,11 @@ public class BoxBrandServiceImpl implements BoxBrandServiceI {
private final BoxBrandCreateCmdExe boxBrandCreateCmdExe; private final BoxBrandCreateCmdExe boxBrandCreateCmdExe;
private final BoxBrandUpdateCmdExe boxBrandUpdateCmdExe; private final BoxBrandUpdateCmdExe boxBrandUpdateCmdExe;
private final BoxBrandPageQryExe boxBrandPageQryExe;
private final BoxBrandListQryExe boxBrandListQryExe;
private final BoxBrandShowQryExe boxBrandShowQryExe; private final BoxBrandShowQryExe boxBrandShowQryExe;
private final BoxBrandDestroyCmdExe boxBrandDestroyCmdExe; private final BoxBrandDestroyCmdExe boxBrandDestroyCmdExe;
private final BoxBrandPageQryExe boxBrandPageQryExe;
private final BoxBrandListQryExe boxBrandListQryExe;
private final BoxBrandDragCmdExe boxBrandDragCmdExe;
@Override @Override
public BoxBrandVO create(BoxBrandCreateCmd boxBrandCreateCmd) { public BoxBrandVO create(BoxBrandCreateCmd boxBrandCreateCmd) {
@ -67,5 +70,9 @@ public class BoxBrandServiceImpl implements BoxBrandServiceI {
public void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd) { public void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd) {
boxBrandDestroyCmdExe.execute(boxBrandDestroyCmd); boxBrandDestroyCmdExe.execute(boxBrandDestroyCmd);
} }
}
@Override
public void drag(BoxBrandDragCmd boxBrandDragCmd) {
boxBrandDragCmdExe.execute(boxBrandDragCmd);
}
}

View File

@ -3,6 +3,7 @@ package com.xunhong.erp.turbo.biz.app.service;
import com.xunhong.erp.turbo.api.biz.api.BoxProductServiceI; import com.xunhong.erp.turbo.api.biz.api.BoxProductServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
@ -12,6 +13,7 @@ import com.xunhong.erp.turbo.base.dto.PageDTO;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductCreateCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductCreateCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductDestroyCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductDestroyCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductUpdateCmdExe; import com.xunhong.erp.turbo.biz.app.executor.cmd.BoxProductUpdateCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductDragCmdExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductListQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductListQryExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductPageQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductPageQryExe;
import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductShowQryExe; import com.xunhong.erp.turbo.biz.app.executor.query.BoxProductShowQryExe;
@ -33,10 +35,11 @@ public class BoxProductServiceImpl implements BoxProductServiceI {
private final BoxProductCreateCmdExe boxProductCreateCmdExe; private final BoxProductCreateCmdExe boxProductCreateCmdExe;
private final BoxProductUpdateCmdExe boxProductUpdateCmdExe; private final BoxProductUpdateCmdExe boxProductUpdateCmdExe;
private final BoxProductPageQryExe boxProductPageQryExe;
private final BoxProductListQryExe boxProductListQryExe;
private final BoxProductShowQryExe boxProductShowQryExe; private final BoxProductShowQryExe boxProductShowQryExe;
private final BoxProductDestroyCmdExe boxProductDestroyCmdExe; private final BoxProductDestroyCmdExe boxProductDestroyCmdExe;
private final BoxProductPageQryExe boxProductPageQryExe;
private final BoxProductListQryExe boxProductListQryExe;
private final BoxProductDragCmdExe boxProductDragCmdExe;
@Override @Override
public BoxProductVO create(BoxProductCreateCmd boxProductCreateCmd) { public BoxProductVO create(BoxProductCreateCmd boxProductCreateCmd) {
@ -67,5 +70,9 @@ public class BoxProductServiceImpl implements BoxProductServiceI {
public void destroy(BoxProductDestroyCmd boxProductDestroyCmd) { public void destroy(BoxProductDestroyCmd boxProductDestroyCmd) {
boxProductDestroyCmdExe.execute(boxProductDestroyCmd); boxProductDestroyCmdExe.execute(boxProductDestroyCmd);
} }
}
@Override
public void drag(BoxProductDragCmd boxProductDragCmd) {
boxProductDragCmdExe.execute(boxProductDragCmd);
}
}

View File

@ -5,6 +5,7 @@ import com.alibaba.cola.dto.DTO;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -41,6 +42,11 @@ public class BoxBrand extends DTO {
*/ */
private Boolean status; private Boolean status;
/**
* 排序
*/
private BigDecimal sort;
/** /**
* 产品列表 * 产品列表
*/ */
@ -52,4 +58,3 @@ public class BoxBrand extends DTO {
private LocalDateTime createdAt; private LocalDateTime createdAt;
} }

View File

@ -62,10 +62,14 @@ public class BoxProduct extends DTO {
*/ */
private Boolean status; private Boolean status;
/**
* 排序
*/
private BigDecimal sort;
/** /**
* 创建时间 * 创建时间
*/ */
private LocalDateTime createdAt; private LocalDateTime createdAt;
} }

View File

@ -3,6 +3,7 @@ package com.xunhong.erp.turbo.biz.domain.gateway;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
@ -26,5 +27,6 @@ public interface BoxBrandGateway {
BoxBrand show(BoxBrandShowQry boxBrandShowQry); BoxBrand show(BoxBrandShowQry boxBrandShowQry);
void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd); void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd);
}
void drag(BoxBrandDragCmd boxBrandDragCmd);
}

View File

@ -3,6 +3,7 @@ package com.xunhong.erp.turbo.biz.domain.gateway;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
@ -26,5 +27,6 @@ public interface BoxProductGateway {
BoxProduct show(BoxProductShowQry boxProductShowQry); BoxProduct show(BoxProductShowQry boxProductShowQry);
void destroy(BoxProductDestroyCmd boxProductDestroyCmd); void destroy(BoxProductDestroyCmd boxProductDestroyCmd);
}
void drag(BoxProductDragCmd boxProductDragCmd);
}

View File

@ -9,6 +9,7 @@ import com.xunhong.erp.turbo.datasource.domain.entity.BaseDO;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -55,8 +56,13 @@ public class BoxBrandDO extends BaseDO<BoxBrandDO> {
@TableField(value = "status") @TableField(value = "status")
private Boolean status; private Boolean status;
/**
* 排序
*/
@TableField(value = "sort")
private BigDecimal sort;
@TableField(exist = false) @TableField(exist = false)
private List<BoxProductDO> boxProductDOList; private List<BoxProductDO> boxProductDOList;
} }

View File

@ -80,4 +80,10 @@ public class BoxProductDO extends BaseDO<BoxProductDO> {
@TableField(value = "status") @TableField(value = "status")
private Boolean status; private Boolean status;
/**
* 排序
*/
@TableField(value = "sort")
private BigDecimal sort;
} }

View File

@ -2,11 +2,13 @@ package com.xunhong.erp.turbo.biz.infrastructure.gateway;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
@ -20,9 +22,11 @@ import com.xunhong.erp.turbo.biz.infrastructure.mapper.BoxBrandMapper;
import com.xunhong.erp.turbo.biz.infrastructure.mapper.BoxProductMapper; import com.xunhong.erp.turbo.biz.infrastructure.mapper.BoxProductMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
/** /**
* @author shenyifei * @author shenyifei
@ -32,7 +36,6 @@ import java.util.Objects;
public class BoxBrandGatewayImpl implements BoxBrandGateway { public class BoxBrandGatewayImpl implements BoxBrandGateway {
private final BoxBrandMapper boxBrandMapper; private final BoxBrandMapper boxBrandMapper;
private final BoxBrandConvert boxBrandConvert; private final BoxBrandConvert boxBrandConvert;
private final BoxProductMapper boxProductMapper; private final BoxProductMapper boxProductMapper;
@Override @Override
@ -49,11 +52,27 @@ public class BoxBrandGatewayImpl implements BoxBrandGateway {
queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getStatus()), BoxBrandDO::getStatus, boxBrandPageQry.getStatus()); queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getStatus()), BoxBrandDO::getStatus, boxBrandPageQry.getStatus());
queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getBrandId()), BoxBrandDO::getBrandId, boxBrandPageQry.getBrandId()); queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getBrandId()), BoxBrandDO::getBrandId, boxBrandPageQry.getBrandId());
queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getType()), BoxBrandDO::getType, boxBrandPageQry.getType()); queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getType()), BoxBrandDO::getType, boxBrandPageQry.getType());
queryWrapper.eq(Objects.nonNull(boxBrandPageQry.getStatus()), BoxBrandDO::getStatus, boxBrandPageQry.getStatus());
queryWrapper.orderByAsc(BoxBrandDO::getSort);
queryWrapper.orderByDesc(BoxBrandDO::getCreatedAt); queryWrapper.orderByDesc(BoxBrandDO::getCreatedAt);
IPage<BoxBrandDO> page = new Page<>(boxBrandPageQry.getPageIndex(), boxBrandPageQry.getPageSize()); IPage<BoxBrandDO> page = new Page<>(boxBrandPageQry.getPageIndex(), boxBrandPageQry.getPageSize());
page = boxBrandMapper.selectPage(page, queryWrapper); page = boxBrandMapper.selectPage(page, queryWrapper);
List<Long> brandIdList = page.getRecords().stream().map(BoxBrandDO::getBrandId).toList();
if (CollUtil.isNotEmpty(brandIdList)) {
LambdaQueryWrapper<BoxProductDO> queryWrapper1 = Wrappers.lambdaQuery(BoxProductDO.class);
queryWrapper1.in(BoxProductDO::getBrandId, brandIdList);
List<BoxProductDO> boxProductDOList = boxProductMapper.selectList(queryWrapper1);
page.getRecords().forEach(boxBrandDO -> {
boxBrandDO.setBoxProductDOList(boxProductDOList.stream()
.filter(boxProductDO -> boxProductDO.getBrandId().equals(boxBrandDO.getBrandId()))
.toList());
});
}
return page.convert(boxBrandConvert::toBoxBrand); return page.convert(boxBrandConvert::toBoxBrand);
} }
@ -63,6 +82,9 @@ public class BoxBrandGatewayImpl implements BoxBrandGateway {
queryWrapper.eq(Objects.nonNull(boxBrandListQry.getStatus()), BoxBrandDO::getStatus, boxBrandListQry.getStatus()); queryWrapper.eq(Objects.nonNull(boxBrandListQry.getStatus()), BoxBrandDO::getStatus, boxBrandListQry.getStatus());
queryWrapper.eq(Objects.nonNull(boxBrandListQry.getBrandId()), BoxBrandDO::getBrandId, boxBrandListQry.getBrandId()); queryWrapper.eq(Objects.nonNull(boxBrandListQry.getBrandId()), BoxBrandDO::getBrandId, boxBrandListQry.getBrandId());
queryWrapper.eq(Objects.nonNull(boxBrandListQry.getType()), BoxBrandDO::getType, boxBrandListQry.getType()); queryWrapper.eq(Objects.nonNull(boxBrandListQry.getType()), BoxBrandDO::getType, boxBrandListQry.getType());
queryWrapper.eq(Objects.nonNull(boxBrandListQry.getStatus()), BoxBrandDO::getStatus, boxBrandListQry.getStatus());
queryWrapper.orderByAsc(BoxBrandDO::getSort);
queryWrapper.orderByDesc(BoxBrandDO::getCreatedAt); queryWrapper.orderByDesc(BoxBrandDO::getCreatedAt);
List<BoxBrandDO> boxBrandDOList = boxBrandMapper.selectList(queryWrapper); List<BoxBrandDO> boxBrandDOList = boxBrandMapper.selectList(queryWrapper);
@ -115,5 +137,50 @@ public class BoxBrandGatewayImpl implements BoxBrandGateway {
BoxBrandDO boxBrandDO = boxBrandMapper.selectOne(queryWrapper); BoxBrandDO boxBrandDO = boxBrandMapper.selectOne(queryWrapper);
boxBrandDO.deleteById(); boxBrandDO.deleteById();
} }
}
@Override
@Transactional
public void drag(BoxBrandDragCmd boxBrandDragCmd) {
reorderTask(boxBrandDragCmd.getCurrentId(), boxBrandDragCmd.getPrevId(), boxBrandDragCmd.getNextId());
}
// 拖拽排序核心方法
public void reorderTask(Long currentId, Long prevId, Long nextId) {
// 获取相邻元素的sort值
Double prevSort = Optional.ofNullable(prevId)
.map(id -> boxBrandMapper.selectById(id).getSort().doubleValue())
.orElse(null);
Double nextSort = Optional.ofNullable(nextId)
.map(id -> boxBrandMapper.selectById(id).getSort().doubleValue())
.orElse(null);
// 计算新sort值
Double newSort = calculateNewSort(prevSort, nextSort);
// 检查是否需要重整排序
if (needResetSort(prevSort, nextSort)) {
boxBrandMapper.batchResetSort(boxBrandMapper.selectById(currentId).getBrandId());
} else {
// 更新当前任务sort值
boxBrandMapper.update(null, new LambdaUpdateWrapper<BoxBrandDO>()
.eq(BoxBrandDO::getBrandId, currentId)
.set(BoxBrandDO::getSort, newSort)
);
}
}
private Double calculateNewSort(Double prevSort, Double nextSort) {
if (prevSort == null && nextSort != null) {
return nextSort - 1000; // 插入到开头
} else if (nextSort == null && prevSort != null) {
return prevSort + 1000; // 插入到末尾
} else if (prevSort == null && nextSort == null) {
return 0.0;
} else {
return (prevSort + nextSort) / 2; // 插入中间
}
}
private boolean needResetSort(Double prevSort, Double nextSort) {
return prevSort != null && nextSort != null
&& (nextSort - prevSort) < 1.0; // 判断间隙是否耗尽
}
}

View File

@ -2,11 +2,13 @@ package com.xunhong.erp.turbo.biz.infrastructure.gateway;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
@ -18,9 +20,11 @@ import com.xunhong.erp.turbo.biz.infrastructure.entity.BoxProductDO;
import com.xunhong.erp.turbo.biz.infrastructure.mapper.BoxProductMapper; import com.xunhong.erp.turbo.biz.infrastructure.mapper.BoxProductMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
/** /**
* @author shenyifei * @author shenyifei
@ -43,12 +47,11 @@ public class BoxProductGatewayImpl implements BoxProductGateway {
public IPage<BoxProduct> page(BoxProductPageQry boxProductPageQry) { public IPage<BoxProduct> page(BoxProductPageQry boxProductPageQry) {
LambdaQueryWrapper<BoxProductDO> queryWrapper = Wrappers.lambdaQuery(BoxProductDO.class); LambdaQueryWrapper<BoxProductDO> queryWrapper = Wrappers.lambdaQuery(BoxProductDO.class);
queryWrapper.like(StrUtil.isNotBlank(boxProductPageQry.getName()), BoxProductDO::getName, boxProductPageQry.getName()); queryWrapper.like(StrUtil.isNotBlank(boxProductPageQry.getName()), BoxProductDO::getName, boxProductPageQry.getName());
queryWrapper.like(StrUtil.isNotBlank(boxProductPageQry.getRemark()), BoxProductDO::getRemark, boxProductPageQry.getRemark());
queryWrapper.eq(Objects.nonNull(boxProductPageQry.getStatus()), BoxProductDO::getStatus, boxProductPageQry.getStatus());
queryWrapper.eq(Objects.nonNull(boxProductPageQry.getBrandId()), BoxProductDO::getBrandId, boxProductPageQry.getBrandId());
queryWrapper.eq(Objects.nonNull(boxProductPageQry.getSpecType()), BoxProductDO::getSpecType, boxProductPageQry.getSpecType()); queryWrapper.eq(Objects.nonNull(boxProductPageQry.getSpecType()), BoxProductDO::getSpecType, boxProductPageQry.getSpecType());
queryWrapper.eq(Objects.nonNull(boxProductPageQry.getType()), BoxProductDO::getType, boxProductPageQry.getType()); queryWrapper.eq(Objects.nonNull(boxProductPageQry.getBrandId()), BoxProductDO::getBrandId, boxProductPageQry.getBrandId());
queryWrapper.eq(Objects.nonNull(boxProductPageQry.getStatus()), BoxProductDO::getStatus, boxProductPageQry.getStatus());
queryWrapper.orderByAsc(BoxProductDO::getSort);
queryWrapper.orderByDesc(BoxProductDO::getCreatedAt); queryWrapper.orderByDesc(BoxProductDO::getCreatedAt);
IPage<BoxProductDO> page = new Page<>(boxProductPageQry.getPageIndex(), boxProductPageQry.getPageSize()); IPage<BoxProductDO> page = new Page<>(boxProductPageQry.getPageIndex(), boxProductPageQry.getPageSize());
@ -60,7 +63,13 @@ public class BoxProductGatewayImpl implements BoxProductGateway {
@Override @Override
public List<BoxProduct> list(BoxProductListQry boxProductListQry) { public List<BoxProduct> list(BoxProductListQry boxProductListQry) {
LambdaQueryWrapper<BoxProductDO> queryWrapper = Wrappers.lambdaQuery(BoxProductDO.class); LambdaQueryWrapper<BoxProductDO> queryWrapper = Wrappers.lambdaQuery(BoxProductDO.class);
queryWrapper.eq(Objects.nonNull(boxProductListQry.getType()), BoxProductDO::getType, boxProductListQry.getType()); queryWrapper.like(StrUtil.isNotBlank(boxProductListQry.getName()), BoxProductDO::getName, boxProductListQry.getName());
queryWrapper.eq(Objects.nonNull(boxProductListQry.getSpecType()), BoxProductDO::getSpecType, boxProductListQry.getSpecType());
queryWrapper.eq(Objects.nonNull(boxProductListQry.getBrandId()), BoxProductDO::getBrandId, boxProductListQry.getBrandId());
queryWrapper.eq(Objects.nonNull(boxProductListQry.getStatus()), BoxProductDO::getStatus, boxProductListQry.getStatus());
queryWrapper.orderByAsc(BoxProductDO::getSort);
queryWrapper.orderByDesc(BoxProductDO::getCreatedAt);
List<BoxProductDO> boxProductDOList = boxProductMapper.selectList(queryWrapper); List<BoxProductDO> boxProductDOList = boxProductMapper.selectList(queryWrapper);
return boxProductDOList.stream().map(boxProductConvert::toBoxProduct).toList(); return boxProductDOList.stream().map(boxProductConvert::toBoxProduct).toList();
} }
@ -98,4 +107,50 @@ public class BoxProductGatewayImpl implements BoxProductGateway {
BoxProductDO boxProductDO = boxProductMapper.selectOne(queryWrapper); BoxProductDO boxProductDO = boxProductMapper.selectOne(queryWrapper);
boxProductDO.deleteById(); boxProductDO.deleteById();
} }
@Override
@Transactional
public void drag(BoxProductDragCmd boxProductDragCmd) {
reorderTask(boxProductDragCmd.getCurrentId(), boxProductDragCmd.getPrevId(), boxProductDragCmd.getNextId());
}
// 拖拽排序核心方法
public void reorderTask(Long currentId, Long prevId, Long nextId) {
// 获取相邻元素的sort值
Double prevSort = Optional.ofNullable(prevId)
.map(id -> boxProductMapper.selectById(id).getSort().doubleValue())
.orElse(null);
Double nextSort = Optional.ofNullable(nextId)
.map(id -> boxProductMapper.selectById(id).getSort().doubleValue())
.orElse(null);
// 计算新sort值
Double newSort = calculateNewSort(prevSort, nextSort);
// 检查是否需要重整排序
if (needResetSort(prevSort, nextSort)) {
boxProductMapper.batchResetSort(boxProductMapper.selectById(currentId).getProductId());
} else {
// 更新当前任务sort值
boxProductMapper.update(null, new LambdaUpdateWrapper<BoxProductDO>()
.eq(BoxProductDO::getProductId, currentId)
.set(BoxProductDO::getSort, newSort)
);
}
}
private Double calculateNewSort(Double prevSort, Double nextSort) {
if (prevSort == null && nextSort != null) {
return nextSort - 1000; // 插入到开头
} else if (nextSort == null && prevSort != null) {
return prevSort + 1000; // 插入到末尾
} else if (prevSort == null && nextSort == null) {
return 0.0;
} else {
return (prevSort + nextSort) / 2; // 插入中间
}
}
private boolean needResetSort(Double prevSort, Double nextSort) {
return prevSort != null && nextSort != null
&& (nextSort - prevSort) < 1.0; // 判断间隙是否耗尽
}
} }

View File

@ -3,11 +3,19 @@ package com.xunhong.erp.turbo.biz.infrastructure.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xunhong.erp.turbo.biz.infrastructure.entity.BoxBrandDO; import com.xunhong.erp.turbo.biz.infrastructure.entity.BoxBrandDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
/** /**
* @author shenyifei * @author shenyifei
*/ */
@Mapper @Mapper
public interface BoxBrandMapper extends BaseMapper<BoxBrandDO> { public interface BoxBrandMapper extends BaseMapper<BoxBrandDO> {
// 批量更新排序值用于间隙重整
@Update("UPDATE box_brand t " +
"JOIN (SELECT brand_id, (ROW_NUMBER() OVER (ORDER BY sort) - 1) * 1000 AS new_sort " +
"FROM box_brand WHERE brand_id = #{brandId}) AS sorted_rows " +
"ON t.brand_id = sorted_rows.brand_id " +
"SET t.sort = sorted_rows.new_sort WHERE t.brand_id = #{brandId}")
void batchResetSort(@Param("brandId") Long brandId);
} }

View File

@ -3,11 +3,19 @@ package com.xunhong.erp.turbo.biz.infrastructure.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xunhong.erp.turbo.biz.infrastructure.entity.BoxProductDO; import com.xunhong.erp.turbo.biz.infrastructure.entity.BoxProductDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
/** /**
* @author shenyifei * @author shenyifei
*/ */
@Mapper @Mapper
public interface BoxProductMapper extends BaseMapper<BoxProductDO> { public interface BoxProductMapper extends BaseMapper<BoxProductDO> {
// 批量更新排序值用于间隙重整
@Update("UPDATE box_product t " +
"JOIN (SELECT product_id, (ROW_NUMBER() OVER (ORDER BY sort) - 1) * 1000 AS new_sort " +
"FROM box_product WHERE product_id = #{productId}) AS sorted_rows " +
"ON t.product_id = sorted_rows.product_id " +
"SET t.sort = sorted_rows.new_sort WHERE t.product_id = #{productId}")
void batchResetSort(@Param("productId") Long productId);
} }

View File

@ -2,6 +2,7 @@ package com.xunhong.erp.turbo.api.biz.api;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
@ -26,5 +27,6 @@ public interface BoxBrandServiceI {
BoxBrandVO show(BoxBrandShowQry boxBrandShowQry); BoxBrandVO show(BoxBrandShowQry boxBrandShowQry);
void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd); void destroy(BoxBrandDestroyCmd boxBrandDestroyCmd);
}
void drag(BoxBrandDragCmd boxBrandDragCmd);
}

View File

@ -2,6 +2,7 @@ package com.xunhong.erp.turbo.api.biz.api;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd; import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry; import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
@ -26,5 +27,6 @@ public interface BoxProductServiceI {
BoxProductVO show(BoxProductShowQry boxProductShowQry); BoxProductVO show(BoxProductShowQry boxProductShowQry);
void destroy(BoxProductDestroyCmd boxProductDestroyCmd); void destroy(BoxProductDestroyCmd boxProductDestroyCmd);
}
void drag(BoxProductDragCmd boxProductDragCmd);
}

View File

@ -0,0 +1,33 @@
package com.xunhong.erp.turbo.api.biz.dto.cmd;
import com.xunhong.erp.turbo.base.dto.Command;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author shenyifei
*/
@Data
@Schema(title = "纸箱品牌拖拽")
@EqualsAndHashCode(callSuper = true)
public class BoxBrandDragCmd extends Command {
/**
* 相邻元素
*/
@Schema(title = "相邻元素前")
private Long prevId;
/**
* 相邻元素
*/
@Schema(title = "相邻元素后")
private Long nextId;
/**
* 当前元素
*/
@Schema(title = "当前元素")
private Long currentId;
}

View File

@ -0,0 +1,33 @@
package com.xunhong.erp.turbo.api.biz.dto.cmd;
import com.xunhong.erp.turbo.base.dto.Command;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author shenyifei
*/
@Data
@Schema(title = "纸箱产品拖拽")
@EqualsAndHashCode(callSuper = true)
public class BoxProductDragCmd extends Command {
/**
* 相邻元素
*/
@Schema(title = "相邻元素前")
private Long prevId;
/**
* 相邻元素
*/
@Schema(title = "相邻元素后")
private Long nextId;
/**
* 当前元素
*/
@Schema(title = "当前元素")
private Long currentId;
}

View File

@ -1,6 +1,7 @@
package com.xunhong.erp.turbo.api.biz.dto.qry; package com.xunhong.erp.turbo.api.biz.dto.qry;
import com.xunhong.erp.turbo.api.biz.dto.enums.BoxBrandTypeEnum; import com.xunhong.erp.turbo.api.biz.dto.enums.BoxBrandTypeEnum;
import com.xunhong.erp.turbo.api.biz.dto.enums.BoxProductSpecTypeEnum;
import com.xunhong.erp.turbo.base.dto.Query; import com.xunhong.erp.turbo.base.dto.Query;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -17,6 +18,18 @@ public class BoxProductListQry extends Query {
@Schema(title = "纸箱产品ID", type = "string") @Schema(title = "纸箱产品ID", type = "string")
private Long productId; private Long productId;
@Schema(title = "纸箱产品名称", type = "string")
private String name;
@Schema(title = "纸箱品牌ID", type = "string")
private String brandId;
/**
* 规格1_2粒装2_4粒装
*/
@Schema(title = "规格1_2粒装2_4粒装")
private BoxProductSpecTypeEnum specType;
/** /**
* 品牌类型1_我方纸箱2_瓜农纸箱3_第三方纸箱 * 品牌类型1_我方纸箱2_瓜农纸箱3_第三方纸箱
*/ */