diff --git a/script/数据库更新语句.sql b/script/数据库更新语句.sql index d3edbe7..a1c38d5 100644 --- a/script/数据库更新语句.sql +++ b/script/数据库更新语句.sql @@ -30,3 +30,22 @@ CREATE TABLE `stack_order` ( ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1; + + +DROP TABLE IF EXISTS `stock_rules`; +CREATE TABLE `stock_rules` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT 'id', + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '建垛规则名称', + `customerId` bigint NULL DEFAULT NULL COMMENT '客户ID', + `prefix` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '前缀', + `startNum` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '起始数', + `step` int NULL DEFAULT NULL COMMENT '步进数', + `serialNum` int NULL DEFAULT NULL COMMENT '顺序号', + `status` tinyint(1) NULL DEFAULT NULL COMMENT '启用状态:0:禁用,1:启用', + `createTime` datetime NULL DEFAULT NULL COMMENT '创建时间', + `updateTime` datetime NULL DEFAULT NULL COMMENT '更新时间', + `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '建垛规则表' ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/java/com/glxp/udi/admin/controller/basic/StockRulesController.java b/src/main/java/com/glxp/udi/admin/controller/basic/StockRulesController.java new file mode 100644 index 0000000..e74094b --- /dev/null +++ b/src/main/java/com/glxp/udi/admin/controller/basic/StockRulesController.java @@ -0,0 +1,90 @@ +package com.glxp.udi.admin.controller.basic; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.glxp.udi.admin.common.enums.ResultEnum; +import com.glxp.udi.admin.common.res.BaseResponse; +import com.glxp.udi.admin.common.util.ResultVOUtils; +import com.glxp.udi.admin.entity.basic.StockRulesEntity; +import com.glxp.udi.admin.req.basic.FilterStockRulesRequest; +import com.glxp.udi.admin.req.inout.DeleteRequest; +import com.glxp.udi.admin.res.PageSimpleResponse; +import com.glxp.udi.admin.service.basic.StockRulesService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 建垛规则相关接口 + */ +@Slf4j +@RestController +public class StockRulesController { + + @Resource + private StockRulesService stockRulesService; + + /** + * 查询建垛规则列表 + * + * @param filterStockRulesRequest + * @return + */ + @GetMapping("/udims/stockRules/filter") + public BaseResponse filterStockRules(FilterStockRulesRequest filterStockRulesRequest) { + IPage page = stockRulesService.filter(filterStockRulesRequest); + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setList(page.getRecords()); + pageSimpleResponse.setTotal(page.getTotal()); + return ResultVOUtils.success(pageSimpleResponse); + } + + /** + * 添加建垛规则 + * + * @param stockRulesEntity + * @return + */ + @PostMapping("/udims/stockRules/add") + public BaseResponse addStockRules(@RequestBody StockRulesEntity stockRulesEntity) { + stockRulesService.addStockRules(stockRulesEntity); + return ResultVOUtils.success(); + } + + /** + * 更新建垛规则 + * + * @param stockRulesEntity + * @return + */ + @PostMapping("/udims/stockRules/update") + public BaseResponse updateStockRules(@RequestBody StockRulesEntity stockRulesEntity, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + + stockRulesService.updateStockRules(stockRulesEntity); + return ResultVOUtils.success("更新成功"); + } + + /** + * 删除建垛规则 + * + * @param deleteRequest + * @return + */ + @PostMapping("/udims/stockRules/delete") + public BaseResponse deleteStockRules(@RequestBody DeleteRequest deleteRequest) { + if (null == deleteRequest || StrUtil.isNotBlank(deleteRequest.getId())) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); + } + stockRulesService.delete(deleteRequest.getId()); + return ResultVOUtils.success("删除成功"); + } + +} diff --git a/src/main/java/com/glxp/udi/admin/req/basic/FilterStockRulesRequest.java b/src/main/java/com/glxp/udi/admin/req/basic/FilterStockRulesRequest.java new file mode 100644 index 0000000..bf7313c --- /dev/null +++ b/src/main/java/com/glxp/udi/admin/req/basic/FilterStockRulesRequest.java @@ -0,0 +1,27 @@ +package com.glxp.udi.admin.req.basic; + +import com.glxp.udi.admin.req.ListPageRequest; +import lombok.Data; + +/** + * 查询建垛规则参数 + */ +@Data +public class FilterStockRulesRequest extends ListPageRequest { + + /** + * 建垛规则名称 + */ + private String name; + + /** + * 客户ID + */ + private String customerId; + + /** + * 是否启用 0:禁用 1:启用 + */ + private Integer status; + +} diff --git a/src/main/java/com/glxp/udi/admin/service/basic/StockRulesService.java b/src/main/java/com/glxp/udi/admin/service/basic/StockRulesService.java new file mode 100644 index 0000000..8dbf270 --- /dev/null +++ b/src/main/java/com/glxp/udi/admin/service/basic/StockRulesService.java @@ -0,0 +1,88 @@ +package com.glxp.udi.admin.service.basic; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.glxp.udi.admin.dao.basic.StockRulesDao; +import com.glxp.udi.admin.entity.basic.StockRulesEntity; +import com.glxp.udi.admin.req.basic.FilterStockRulesRequest; +import com.glxp.udi.admin.service.auth.AuthAdminService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * 建垛规则Service + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class StockRulesService { + + @Resource + private StockRulesDao stockRulesDao; + @Resource + private AuthAdminService authAdminService; + + /** + * 查询建垛规则列表 + * + * @param filterStockRulesRequest + * @return + */ + public IPage filter(FilterStockRulesRequest filterStockRulesRequest) { + QueryWrapper wrapper = buildWrapper(filterStockRulesRequest); + IPage page = new Page<>(filterStockRulesRequest.getPage(), filterStockRulesRequest.getLimit()); + return stockRulesDao.selectPage(page, wrapper); + } + + /** + * 构造建垛规则查询条件 + * + * @param filterStockRulesRequest + * @return + */ + private QueryWrapper buildWrapper(FilterStockRulesRequest filterStockRulesRequest) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StrUtil.isNotBlank(filterStockRulesRequest.getName()), "name", filterStockRulesRequest.getName()) + .eq(null != filterStockRulesRequest.getStatus(), "status", filterStockRulesRequest.getStatus()) + .eq(StrUtil.isNotBlank(filterStockRulesRequest.getCustomerId()), "customerId", filterStockRulesRequest.getCustomerId()); + return wrapper; + } + + /** + * 添加建垛规则 + * + * @param stockRulesEntity + */ + public void addStockRules(StockRulesEntity stockRulesEntity) { + stockRulesEntity.setCreateTime(new Date()); + stockRulesEntity.setUpdateTime(new Date()); + String customerId = authAdminService.getCurrentUserCustomerId(); + stockRulesEntity.setCustomerId(Long.valueOf(customerId)); + stockRulesDao.insert(stockRulesEntity); + } + + /** + * 更新建垛规则 + * + * @param stockRulesEntity + */ + public void updateStockRules(StockRulesEntity stockRulesEntity) { + stockRulesEntity.setUpdateTime(new Date()); + stockRulesDao.updateStockRules(stockRulesEntity); + } + + /** + * 删除建垛规则 + * + * @param id + */ + public void delete(String id) { + stockRulesDao.deleteById(id); + } +}