feat: 添加储位功能
This commit is contained in:
parent
093d4e4772
commit
10b9d39e53
|
|
@ -0,0 +1,97 @@
|
|||
package com.nflg.wms.admin.controller;
|
||||
|
||||
import com.nflg.wms.admin.service.BinControllerService;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.BinAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.BinSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.BinUpdateQO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.vo.BinVO;
|
||||
import com.nflg.wms.starter.BaseController;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 储位管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/bin")
|
||||
public class BinController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private BinControllerService binControllerService;
|
||||
|
||||
/**
|
||||
* 新增储位
|
||||
*/
|
||||
@PostMapping("add")
|
||||
public ApiResult<Void> add(@Valid @RequestBody BinAddQO request){
|
||||
binControllerService.add(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新储位
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public ApiResult<Void> update(@Valid @RequestBody BinUpdateQO request){
|
||||
binControllerService.update(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除储位
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
public ApiResult<Void> delete(@Valid @NotNull Long id){
|
||||
binControllerService.delete(id);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用/禁用储位
|
||||
* @param request 请求参数
|
||||
*/
|
||||
@PostMapping("/enable")
|
||||
public ApiResult<Void> enable(@Valid @RequestBody EnableQO request){
|
||||
binControllerService.enable(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索储位
|
||||
* @param request 搜索参数
|
||||
*/
|
||||
@PostMapping("search")
|
||||
public ApiResult<PageData<BinVO>> search(@Valid @RequestBody BinSearchQO request){
|
||||
return ApiResult.success(binControllerService.search(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入储位
|
||||
* @param file 文件
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("import")
|
||||
public ApiResult importFromExcel(HttpServletResponse response, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||
return binControllerService.importFromExcel(response,file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出选中的仓库,为空时导出模版
|
||||
* @param ids 选中的id集合
|
||||
*/
|
||||
@PostMapping("export")
|
||||
public void exportSelect(HttpServletResponse response,@RequestBody List<Long> ids) throws Exception {
|
||||
binControllerService.exportSelect(response,ids);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
package com.nflg.wms.admin.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.dto.BinExcelExportDTO;
|
||||
import com.nflg.wms.common.pojo.dto.BinExcelImportDTO;
|
||||
import com.nflg.wms.common.pojo.qo.BinAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.BinSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.BinUpdateQO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.vo.BinVO;
|
||||
import com.nflg.wms.common.util.DateTimeUtil;
|
||||
import com.nflg.wms.common.util.EecExcelUtil;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.WmsBin;
|
||||
import com.nflg.wms.repository.entity.WmsWarehouse;
|
||||
import com.nflg.wms.repository.service.IWmsBinService;
|
||||
import com.nflg.wms.repository.service.IWmsWarehouseService;
|
||||
import com.nflg.wms.starter.service.FileUploadService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.ttzero.excel.entity.ListSheet;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class BinControllerService {
|
||||
|
||||
@Resource
|
||||
private IWmsBinService binService;
|
||||
|
||||
@Resource
|
||||
private IWmsWarehouseService wmsWarehouseService;
|
||||
|
||||
@Resource
|
||||
private FileUploadService fileUploadService;
|
||||
|
||||
public void add(@Valid BinAddQO request) {
|
||||
WmsBin bin = Convert.convert(WmsBin.class, request);
|
||||
bin.setCreateBy(UserUtil.getUserName());
|
||||
bin.setCreateTime(LocalDateTime.now());
|
||||
binService.add(bin);
|
||||
}
|
||||
|
||||
public void update(@Valid BinUpdateQO request) {
|
||||
WmsBin bin = Convert.convert(WmsBin.class, request);
|
||||
bin.setUpdateBy(UserUtil.getUserName());
|
||||
bin.setUpdateTime(LocalDateTime.now());
|
||||
binService.update(bin);
|
||||
}
|
||||
|
||||
public void delete(@Valid @NotNull Long id) {
|
||||
binService.delete(id);
|
||||
}
|
||||
|
||||
public void enable(@Valid EnableQO request) {
|
||||
binService.enable(request);
|
||||
}
|
||||
|
||||
public IPage<BinVO> search(@Valid BinSearchQO request) {
|
||||
return binService.search(request);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ApiResult importFromExcel(HttpServletResponse response, MultipartFile file) throws IOException {
|
||||
List<BinExcelImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), BinExcelImportDTO.class);
|
||||
VUtil.trueThrowBusinessError(CollectionUtil.isEmpty(data)).throwMessage("导入文件内容为空");
|
||||
if (updateCheckAndImport(data)) {
|
||||
return ApiResult.success();
|
||||
} else {
|
||||
try(ByteArrayOutputStream osOut = new ByteArrayOutputStream()) {
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(data))
|
||||
.writeTo(osOut);
|
||||
try(ByteArrayInputStream isIn = new ByteArrayInputStream(osOut.toByteArray())) {
|
||||
return ApiResult.error(STATE.DataNoCheckPass, "导入文件失败",fileUploadService.upload("temp/" + DateTimeUtil.format(LocalDate.now(),"yyyyMMdd")+"/"+ IdUtil.fastUUID() + ".xlsx", isIn));
|
||||
}
|
||||
}catch (Exception e){
|
||||
return ApiResult.error(STATE.BusinessError, "保存文件出错");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean updateCheckAndImport(List<BinExcelImportDTO> data) {
|
||||
List<WmsBin> bins = new ArrayList<>();
|
||||
for (BinExcelImportDTO dto : data) {
|
||||
WmsBin bin = new WmsBin();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (StrUtil.isBlank(dto.getWarehouseNo())) {
|
||||
sb.append("仓库编号不能为空;");
|
||||
}else if(StrUtil.isBlank(dto.getNo())){
|
||||
sb.append("储位编号不能为空;");
|
||||
}
|
||||
else {
|
||||
WmsWarehouse warehouse=wmsWarehouseService.lambdaQuery().eq(WmsWarehouse::getNo, dto.getWarehouseNo()).one();
|
||||
if (Objects.isNull(warehouse)){
|
||||
sb.append("仓库编号无效;");
|
||||
}else {
|
||||
bin = binService.lambdaQuery().eq(WmsBin::getNo, dto.getNo()).eq(WmsBin::getWarehouseId, warehouse.getId()).one();
|
||||
if (Objects.isNull(bin)) {
|
||||
bin = new WmsBin()
|
||||
.setNo(dto.getNo())
|
||||
.setWarehouseId(warehouse.getId())
|
||||
.setEnable(true)
|
||||
.setCreateBy(UserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
}else {
|
||||
bin.setUpdateBy(UserUtil.getUserName());
|
||||
bin.setUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(dto.getName())){
|
||||
sb.append("仓库名称不能为空;");
|
||||
}else {
|
||||
bin.setName(dto.getName());
|
||||
}
|
||||
bin.setRemark(dto.getRemark());
|
||||
dto.setError(sb.toString());
|
||||
bins.add(bin);
|
||||
}
|
||||
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
|
||||
binService.saveOrUpdateBatch(bins);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
|
||||
List<BinVO> binVOS = CollectionUtil.isNotEmpty(ids) ? binService.getList(ids) : new ArrayList<>();
|
||||
List<BinExcelExportDTO> datas = binVOS.stream().map(bin -> Convert.convert(BinExcelExportDTO.class, bin)).collect(Collectors.toList());
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("储位导出.xlsx", StandardCharsets.UTF_8));
|
||||
if (CollectionUtil.isEmpty(datas)) {
|
||||
datas.add(new BinExcelExportDTO()
|
||||
.setNo("(必填)储位编号")
|
||||
.setName("(必填)储位名称")
|
||||
.setRemark("备注信息,此行为提示信息,导入时请删除"));
|
||||
}
|
||||
new Workbook()
|
||||
.addSheet(new ListSheet<>(datas))
|
||||
.writeTo(response.getOutputStream());
|
||||
}
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ public class WarehouseControllerService {
|
|||
for (WarehouseExcelImportDTO dto : data) {
|
||||
WmsWarehouse wmsWarehouse = new WmsWarehouse();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (Objects.isNull(dto.getNo())) {
|
||||
if (StrUtil.isBlank(dto.getNo())) {
|
||||
sb.append("仓库编号不能为空;");
|
||||
} else {
|
||||
wmsWarehouse = warehouseService.lambdaQuery().eq(WmsWarehouse::getNo, dto.getNo()).one();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BinExcelExportDTO {
|
||||
|
||||
/**
|
||||
* 仓库编码
|
||||
*/
|
||||
@ExcelColumn("*仓库编码")
|
||||
private String warehouseCode;
|
||||
|
||||
/**
|
||||
* 储位编码
|
||||
*/
|
||||
@ExcelColumn("*储位编码")
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 储位名称
|
||||
*/
|
||||
@ExcelColumn("*储位名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
@Data
|
||||
public class BinExcelImportDTO {
|
||||
|
||||
/**
|
||||
* 仓库编码
|
||||
*/
|
||||
@ExcelColumn("*仓库编码")
|
||||
private String warehouseNo;
|
||||
|
||||
/**
|
||||
* 储位编码
|
||||
*/
|
||||
@ExcelColumn("*储位编码")
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 储位名称
|
||||
*/
|
||||
@ExcelColumn("*储位名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@ExcelColumn("错误信息")
|
||||
private String error;
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BinAddQO {
|
||||
|
||||
/**
|
||||
* 仓库ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 储位编码
|
||||
*/
|
||||
@NotBlank
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 储位名称
|
||||
*/
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@NotBlank
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BinSearchQO extends PageQO{
|
||||
|
||||
|
||||
/**
|
||||
* 仓库ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BinUpdateQO extends BinAddQO{
|
||||
|
||||
@NotNull
|
||||
private Long id;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package com.nflg.wms.common.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class BinVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 仓库ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 仓库名称
|
||||
*/
|
||||
private String warehouseName;
|
||||
|
||||
/**
|
||||
* 仓库编码
|
||||
*/
|
||||
private String warehouseNo;
|
||||
|
||||
/**
|
||||
* 储位编码
|
||||
*/
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 储位名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 最后更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 最后更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* SAP同步状态,0:未导入;1:导入成功;2:导入失败
|
||||
*/
|
||||
private Short sapState;
|
||||
|
||||
/**
|
||||
* SAP同步错误信息
|
||||
*/
|
||||
private String sapError;
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.nflg.wms.repository.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 储位
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@TableName("wms_bin")
|
||||
@Accessors(chain = true)
|
||||
public class WmsBin implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 仓库ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 储位编码
|
||||
*/
|
||||
private String no;
|
||||
|
||||
/**
|
||||
* 储位名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 最后更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 最后更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* SAP同步状态,0:未导入;1:导入成功;2:导入失败
|
||||
*/
|
||||
private Short sapState;
|
||||
|
||||
/**
|
||||
* SAP同步错误信息
|
||||
*/
|
||||
private String sapError;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.nflg.wms.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nflg.wms.common.pojo.qo.BinSearchQO;
|
||||
import com.nflg.wms.common.pojo.vo.BinVO;
|
||||
import com.nflg.wms.repository.entity.WmsBin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 储位 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface WmsBinMapper extends BaseMapper<WmsBin> {
|
||||
|
||||
IPage<BinVO> search(BinSearchQO request, Page<?> objectPage);
|
||||
|
||||
List<BinVO> getList(List<Long> ids);
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.nflg.wms.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.wms.common.pojo.qo.BinSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.vo.BinVO;
|
||||
import com.nflg.wms.repository.entity.WmsBin;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 储位 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
public interface IWmsBinService extends IService<WmsBin> {
|
||||
|
||||
void add(WmsBin bin);
|
||||
|
||||
void update(WmsBin bin);
|
||||
|
||||
void delete(@Valid @NotNull Long id);
|
||||
|
||||
void enable(@Valid EnableQO request);
|
||||
|
||||
IPage<BinVO> search(@Valid BinSearchQO request);
|
||||
|
||||
List<BinVO> getList(List<Long> ids);
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.nflg.wms.repository.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.common.pojo.qo.BinSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.vo.BinVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.WmsBin;
|
||||
import com.nflg.wms.repository.mapper.WmsBinMapper;
|
||||
import com.nflg.wms.repository.service.IAuditLogService;
|
||||
import com.nflg.wms.repository.service.IWmsBinService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 储位 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
@Service
|
||||
public class WmsBinServiceImpl extends ServiceImpl<WmsBinMapper, WmsBin> implements IWmsBinService {
|
||||
|
||||
@Resource
|
||||
private IAuditLogService auditLogService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void add(WmsBin bin) {
|
||||
VUtil.trueThrowBusinessError(lambdaQuery()
|
||||
.eq(WmsBin::getNo, bin.getNo())
|
||||
.eq(WmsBin::getWarehouseId, bin.getWarehouseId())
|
||||
.exists())
|
||||
.throwMessage("储位编码已存在");
|
||||
save(bin);
|
||||
auditLogService.addInsert(WmsBin.class, bin, bin.getCreateBy());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void update(WmsBin bin) {
|
||||
VUtil.trueThrowBusinessError(lambdaQuery()
|
||||
.eq(WmsBin::getNo, bin.getNo())
|
||||
.eq(WmsBin::getWarehouseId, bin.getWarehouseId())
|
||||
.ne(WmsBin::getId, bin.getId()).exists())
|
||||
.throwMessage("储位编码已存在");
|
||||
WmsBin old = getById(bin.getId());
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("储位不存在");
|
||||
updateById(bin);
|
||||
WmsBin newInfo = getById(bin.getId());
|
||||
auditLogService.addUpdate(WmsBin.class, old, newInfo, bin.getUpdateBy());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
// TODO 删除储位,判断是否存储了物料
|
||||
WmsBin old = getById(id);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("储位不存在");
|
||||
removeById(id);
|
||||
auditLogService.addDelete(WmsBin.class, old, UserUtil.getUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(EnableQO request) {
|
||||
WmsBin old = getById(request.getId());
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("储位不存在");
|
||||
lambdaUpdate()
|
||||
.set(WmsBin::getEnable, request.getEnable())
|
||||
.set(WmsBin::getUpdateBy, UserUtil.getUserName())
|
||||
.set(WmsBin::getUpdateTime, LocalDateTime.now())
|
||||
.eq(WmsBin::getId, request.getId())
|
||||
.update();
|
||||
WmsBin newInfo = getById(request.getId());
|
||||
auditLogService.addUpdate(WmsBin.class, old, newInfo, UserUtil.getUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<BinVO> search(BinSearchQO request) {
|
||||
return baseMapper.search(request, new Page<>(request.getPage(), request.getPageSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BinVO> getList(List<Long> ids) {
|
||||
return baseMapper.getList(ids);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,11 @@ import com.nflg.wms.common.pojo.qo.WarehouseSearchQO;
|
|||
import com.nflg.wms.common.pojo.vo.WarehouseVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.WmsBin;
|
||||
import com.nflg.wms.repository.entity.WmsWarehouse;
|
||||
import com.nflg.wms.repository.mapper.WmsWarehouseMapper;
|
||||
import com.nflg.wms.repository.service.IAuditLogService;
|
||||
import com.nflg.wms.repository.service.IWmsBinService;
|
||||
import com.nflg.wms.repository.service.IWmsWarehouseService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -34,6 +36,9 @@ public class WmsWarehouseServiceImpl extends ServiceImpl<WmsWarehouseMapper, Wms
|
|||
@Resource
|
||||
private IAuditLogService auditLogService;
|
||||
|
||||
@Resource
|
||||
private IWmsBinService binService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void add(WmsWarehouse wmsWarehouse) {
|
||||
|
|
@ -58,7 +63,8 @@ public class WmsWarehouseServiceImpl extends ServiceImpl<WmsWarehouseMapper, Wms
|
|||
@Transactional
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
// TODO 删除仓库,判断是否绑定了储位
|
||||
VUtil.trueThrowBusinessError(binService.lambdaQuery().eq(WmsBin::getWarehouseId, id).exists())
|
||||
.throwMessage("删除失败,仓库已绑定储位");
|
||||
WmsWarehouse old = getById(id);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("仓库不存在");
|
||||
removeById(id);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.WmsBinMapper">
|
||||
|
||||
<select id="search" resultType="com.nflg.wms.common.pojo.vo.BinVO">
|
||||
select *, wh.no as warehouse_no, wh.name as warehouse_name
|
||||
from wms_bin bin
|
||||
left join wms_warehouse wh on bin.warehouse_id=wh.id
|
||||
<where>
|
||||
<if test="request.warehouseId != null">
|
||||
and bin.warehouse_id=#{warehouseId}
|
||||
</if>
|
||||
</where>
|
||||
order by bin.id desc
|
||||
</select>
|
||||
|
||||
<select id="getList" resultType="com.nflg.wms.common.pojo.vo.BinVO">
|
||||
select *, wh.no as warehouse_no, wh.name as warehouse_name
|
||||
from wms_bin bin
|
||||
left join wms_warehouse wh on bin.warehouse_id=wh.id
|
||||
where bin.id in
|
||||
<foreach item="item" collection="ids" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -33,7 +33,7 @@ public class CodeGeneratorTest {
|
|||
)
|
||||
.strategyConfig(builder -> {
|
||||
builder
|
||||
.addInclude("warehouse") //只生成指定表
|
||||
.addInclude("wms_bin") //只生成指定表
|
||||
.entityBuilder().idType(IdType.ASSIGN_ID)
|
||||
.enableLombok()
|
||||
.enableChainModel()
|
||||
|
|
|
|||
Loading…
Reference in New Issue