feat: 添加物料存储功能
This commit is contained in:
parent
10b9d39e53
commit
1edeab2588
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.nflg.wms.admin.controller;
|
||||||
|
|
||||||
|
import com.nflg.wms.admin.service.StorageControllerService;
|
||||||
|
import com.nflg.wms.common.pojo.ApiResult;
|
||||||
|
import com.nflg.wms.common.pojo.PageData;
|
||||||
|
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageAddQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageSearchQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageUpdateQO;
|
||||||
|
import com.nflg.wms.common.pojo.vo.StorageVO;
|
||||||
|
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("/storage")
|
||||||
|
public class StorageController extends BaseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private StorageControllerService storageControllerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("add")
|
||||||
|
public ApiResult<Void> add(@Valid @RequestBody StorageAddQO request){
|
||||||
|
storageControllerService.add(request);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
@PostMapping("update")
|
||||||
|
public ApiResult<Void> update(@Valid @RequestBody StorageUpdateQO request){
|
||||||
|
storageControllerService.update(request);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("delete")
|
||||||
|
public ApiResult<Void> delete(@Valid @NotNull Long id){
|
||||||
|
storageControllerService.delete(id);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用/禁用
|
||||||
|
* @param request 请求参数
|
||||||
|
*/
|
||||||
|
@PostMapping("/enable")
|
||||||
|
public ApiResult<Void> enable(@Valid @RequestBody EnableQO request){
|
||||||
|
storageControllerService.enable(request);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索
|
||||||
|
* @param request 搜索参数
|
||||||
|
*/
|
||||||
|
@PostMapping("search")
|
||||||
|
public ApiResult<PageData<StorageVO>> search(@Valid @RequestBody StorageSearchQO request){
|
||||||
|
return ApiResult.success(storageControllerService.search(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入
|
||||||
|
* @param file 文件
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@PostMapping("import")
|
||||||
|
public ApiResult importFromExcel(HttpServletResponse response, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||||
|
return storageControllerService.importFromExcel(response,file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出选中的数据,为空时导出模版
|
||||||
|
* @param ids 选中的id集合
|
||||||
|
*/
|
||||||
|
@PostMapping("export")
|
||||||
|
public void exportSelect(HttpServletResponse response,@RequestBody List<Long> ids) throws Exception {
|
||||||
|
storageControllerService.exportSelect(response,ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,204 @@
|
||||||
|
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.conditions.query.LambdaQueryWrapper;
|
||||||
|
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.StorageExcelExportDTO;
|
||||||
|
import com.nflg.wms.common.pojo.dto.StorageExcelImportDTO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageAddQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageSearchQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageUpdateQO;
|
||||||
|
import com.nflg.wms.common.pojo.vo.StorageVO;
|
||||||
|
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.WmsMaterial;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorage;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorageBin;
|
||||||
|
import com.nflg.wms.repository.service.IWmsBinService;
|
||||||
|
import com.nflg.wms.repository.service.IWmsMaterialService;
|
||||||
|
import com.nflg.wms.repository.service.IWmsStorageBinService;
|
||||||
|
import com.nflg.wms.repository.service.IWmsStorageService;
|
||||||
|
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 StorageControllerService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWmsStorageService storageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWmsStorageBinService storageBinService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileUploadService fileUploadService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWmsMaterialService materialService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWmsBinService binService;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void add(@Valid StorageAddQO request) {
|
||||||
|
WmsStorage storage = Convert.convert(WmsStorage.class, request);
|
||||||
|
storage.setCreateBy(UserUtil.getUserName());
|
||||||
|
storage.setCreateTime(LocalDateTime.now());
|
||||||
|
storageService.add(storage);
|
||||||
|
storageBinService.add(storage.getId(), request.getBinIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void update(@Valid StorageUpdateQO request) {
|
||||||
|
WmsStorage storage = new WmsStorage()
|
||||||
|
.setId(request.getId())
|
||||||
|
.setEnable(request.getEnable())
|
||||||
|
.setRemark(request.getRemark())
|
||||||
|
.setWarehouseId(request.getWarehouseId())
|
||||||
|
.setUpdateBy(UserUtil.getUserName())
|
||||||
|
.setUpdateTime(LocalDateTime.now());
|
||||||
|
storageService.update(storage);
|
||||||
|
storageBinService.add(storage.getId(), request.getBinIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void delete(@Valid @NotNull Long id) {
|
||||||
|
storageService.delete(id);
|
||||||
|
storageBinService.deleteByStorageId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enable(@Valid EnableQO request) {
|
||||||
|
storageService.enable(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPage<StorageVO> search(@Valid StorageSearchQO request) {
|
||||||
|
return storageService.search(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiResult importFromExcel(HttpServletResponse response, MultipartFile file) throws IOException {
|
||||||
|
List<StorageExcelImportDTO> data = EecExcelUtil.getExcelContext(file.getInputStream(), StorageExcelImportDTO.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<StorageExcelImportDTO> data) {
|
||||||
|
List<WmsStorage> storages = new ArrayList<>();
|
||||||
|
List<WmsStorageBin> storageBinAll = new ArrayList<>();
|
||||||
|
for (StorageExcelImportDTO dto : data) {
|
||||||
|
WmsStorage storage = new WmsStorage();
|
||||||
|
List<WmsStorageBin> storageBins=new ArrayList<>();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (StrUtil.isBlank(dto.getMaterialNo())) {
|
||||||
|
sb.append("物料编号不能为空;");
|
||||||
|
} else {
|
||||||
|
WmsMaterial material = materialService.lambdaQuery().eq(WmsMaterial::getNo, dto.getMaterialNo()).one();
|
||||||
|
if (Objects.isNull(material)) {
|
||||||
|
sb.append("物料编号无效;");
|
||||||
|
} else {
|
||||||
|
storage = storageService.lambdaQuery().eq(WmsStorage::getMaterialId, material.getId()).one();
|
||||||
|
if (Objects.isNull(storage)) {
|
||||||
|
storage = new WmsStorage()
|
||||||
|
.setId(IdUtil.getSnowflakeNextId())
|
||||||
|
.setEnable(true)
|
||||||
|
.setMaterialId(material.getId())
|
||||||
|
.setCreateBy(UserUtil.getUserName())
|
||||||
|
.setCreateTime(LocalDateTime.now());
|
||||||
|
}else {
|
||||||
|
storage.setUpdateBy(UserUtil.getUserName());
|
||||||
|
storage.setUpdateTime(LocalDateTime.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(dto.getBinNos())) {
|
||||||
|
sb.append("储位编号不能为空;");
|
||||||
|
} else {
|
||||||
|
List<String> binNos = StrUtil.split(dto.getBinNos(), ",");
|
||||||
|
List<WmsBin> bins = binService.lambdaQuery().in(WmsBin::getNo, binNos).list();
|
||||||
|
List<String> bs = bins.stream().map(WmsBin::getNo).toList();
|
||||||
|
binNos.removeAll(bs);
|
||||||
|
if (CollectionUtil.isNotEmpty(binNos)) {
|
||||||
|
sb.append(StrUtil.join(";", binNos));
|
||||||
|
}else {
|
||||||
|
WmsStorage finalStorage = storage;
|
||||||
|
storageBins = bins.stream().map(bin -> new WmsStorageBin()
|
||||||
|
.setStorageId(finalStorage.getId())
|
||||||
|
.setBinId(bin.getId())).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.setRemark(dto.getRemark());
|
||||||
|
dto.setError(sb.toString());
|
||||||
|
storages.add(storage);
|
||||||
|
storageBinAll.addAll(storageBins);
|
||||||
|
}
|
||||||
|
if (data.stream().noneMatch(it -> StrUtil.isNotBlank(it.getError()))) {
|
||||||
|
storageService.saveOrUpdateBatch(storages);
|
||||||
|
storageBinService.remove(new LambdaQueryWrapper<WmsStorageBin>()
|
||||||
|
.in(WmsStorageBin::getStorageId, storages.stream().map(WmsStorage::getId).toList()));
|
||||||
|
storageBinService.saveBatch(storageBinAll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exportSelect(HttpServletResponse response, List<Long> ids) throws IOException {
|
||||||
|
List<StorageVO> storageVOS = CollectionUtil.isNotEmpty(ids) ? storageService.getList(ids) : new ArrayList<>();
|
||||||
|
List<StorageExcelExportDTO> datas = storageVOS.stream().map(bin -> Convert.convert(StorageExcelExportDTO.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 StorageExcelExportDTO()
|
||||||
|
.setMaterialNo("(必填)物料编号")
|
||||||
|
.setWarehouseNo("(必填)库位编号")
|
||||||
|
.setBinNos("(必填)储位编号")
|
||||||
|
.setRemark("备注信息,此行为提示信息,导入时请删除"));
|
||||||
|
}
|
||||||
|
new Workbook()
|
||||||
|
.addSheet(new ListSheet<>(datas))
|
||||||
|
.writeTo(response.getOutputStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 StorageExcelExportDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料编号
|
||||||
|
*/
|
||||||
|
@ExcelColumn("物料编号")
|
||||||
|
private String materialNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 库位编号
|
||||||
|
*/
|
||||||
|
@ExcelColumn("库位编号")
|
||||||
|
private String warehouseNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位编号
|
||||||
|
*/
|
||||||
|
@ExcelColumn("储位编号")
|
||||||
|
private String binNos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@ExcelColumn("备注")
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.nflg.wms.common.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.ttzero.excel.annotation.ExcelColumn;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StorageExcelImportDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料编号
|
||||||
|
*/
|
||||||
|
@ExcelColumn("*物料编号")
|
||||||
|
private String materialNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位编号
|
||||||
|
*/
|
||||||
|
@ExcelColumn("*储位编号")
|
||||||
|
private String binNos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@ExcelColumn("备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
@ExcelColumn("错误信息")
|
||||||
|
private String error;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.nflg.wms.common.pojo.qo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class StorageAddQO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料id
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private Long materialId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仓库ID
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位id列表
|
||||||
|
*/
|
||||||
|
@NotEmpty
|
||||||
|
private List<Long> binIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Boolean enable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.nflg.wms.common.pojo.qo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StorageSearchQO extends PageQO{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仓库编码
|
||||||
|
*/
|
||||||
|
private String warehouseNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位编码
|
||||||
|
*/
|
||||||
|
private String binNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料编码
|
||||||
|
*/
|
||||||
|
private String materialNo;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.nflg.wms.common.pojo.qo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StorageUpdateQO extends StorageAddQO{
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long id;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.nflg.wms.common.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StorageVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料编码
|
||||||
|
*/
|
||||||
|
private String materialNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料描述
|
||||||
|
*/
|
||||||
|
private String materialDescribe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仓库编码
|
||||||
|
*/
|
||||||
|
private String warehouseNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位编码
|
||||||
|
*/
|
||||||
|
private String binNos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
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,83 @@
|
||||||
|
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
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("wms_storage")
|
||||||
|
public class WmsStorage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料id
|
||||||
|
*/
|
||||||
|
private Long materialId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仓库ID
|
||||||
|
*/
|
||||||
|
private Long warehouseId;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("wms_storage_bin")
|
||||||
|
public class WmsStorageBin implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料存储id
|
||||||
|
*/
|
||||||
|
private Long storageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 储位id
|
||||||
|
*/
|
||||||
|
private Long binId;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.nflg.wms.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorageBin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
public interface WmsStorageBinMapper extends BaseMapper<WmsStorageBin> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.StorageSearchQO;
|
||||||
|
import com.nflg.wms.common.pojo.vo.StorageVO;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorage;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 物料存储 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
public interface WmsStorageMapper extends BaseMapper<WmsStorage> {
|
||||||
|
|
||||||
|
IPage<StorageVO> search(StorageSearchQO request, Page<?> objectPage);
|
||||||
|
|
||||||
|
List<StorageVO> getList(List<Long> ids);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.nflg.wms.repository.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorageBin;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
public interface IWmsStorageBinService extends IService<WmsStorageBin> {
|
||||||
|
|
||||||
|
void add(Long storageId, @NotEmpty List<Long> binIds);
|
||||||
|
|
||||||
|
void deleteByStorageId(@Valid @NotNull Long id);
|
||||||
|
}
|
||||||
|
|
@ -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.EnableQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageSearchQO;
|
||||||
|
import com.nflg.wms.common.pojo.vo.StorageVO;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorage;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 物料存储 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
public interface IWmsStorageService extends IService<WmsStorage> {
|
||||||
|
|
||||||
|
void add(WmsStorage storage);
|
||||||
|
|
||||||
|
void update(WmsStorage storage);
|
||||||
|
|
||||||
|
void delete(@Valid @NotNull Long id);
|
||||||
|
|
||||||
|
void enable(@Valid EnableQO request);
|
||||||
|
|
||||||
|
IPage<StorageVO> search(@Valid StorageSearchQO request);
|
||||||
|
|
||||||
|
List<StorageVO> getList(List<Long> ids);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.nflg.wms.repository.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorageBin;
|
||||||
|
import com.nflg.wms.repository.mapper.WmsStorageBinMapper;
|
||||||
|
import com.nflg.wms.repository.service.IWmsStorageBinService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 代码生成器生成
|
||||||
|
* @since 2025
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class WmsStorageBinServiceImpl extends ServiceImpl<WmsStorageBinMapper, WmsStorageBin> implements IWmsStorageBinService {
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void add(Long storageId, List<Long> binIds) {
|
||||||
|
deleteByStorageId(storageId);
|
||||||
|
saveBatch(binIds.stream().map(bId -> new WmsStorageBin()
|
||||||
|
.setStorageId(storageId)
|
||||||
|
.setBinId(bId)).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteByStorageId(Long id) {
|
||||||
|
remove(new LambdaQueryWrapper<WmsStorageBin>().eq(WmsStorageBin::getStorageId, id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
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.EnableQO;
|
||||||
|
import com.nflg.wms.common.pojo.qo.StorageSearchQO;
|
||||||
|
import com.nflg.wms.common.pojo.vo.StorageVO;
|
||||||
|
import com.nflg.wms.common.util.UserUtil;
|
||||||
|
import com.nflg.wms.common.util.VUtil;
|
||||||
|
import com.nflg.wms.repository.entity.WmsStorage;
|
||||||
|
import com.nflg.wms.repository.mapper.WmsStorageMapper;
|
||||||
|
import com.nflg.wms.repository.service.IAuditLogService;
|
||||||
|
import com.nflg.wms.repository.service.IWmsStorageService;
|
||||||
|
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 WmsStorageServiceImpl extends ServiceImpl<WmsStorageMapper, WmsStorage> implements IWmsStorageService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IAuditLogService auditLogService;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void add(WmsStorage storage) {
|
||||||
|
VUtil.trueThrowBusinessError(lambdaQuery().eq(WmsStorage::getMaterialId, storage.getMaterialId()).exists())
|
||||||
|
.throwMessage("该物料已存在");
|
||||||
|
save(storage);
|
||||||
|
auditLogService.addInsert(WmsStorage.class, storage, storage.getCreateBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void update(WmsStorage storage) {
|
||||||
|
WmsStorage old = getById(storage.getId());
|
||||||
|
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("数据不存在");
|
||||||
|
updateById(storage);
|
||||||
|
WmsStorage newInfo= getById(storage.getId());
|
||||||
|
auditLogService.addUpdate(WmsStorage.class, old, newInfo, storage.getUpdateBy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Long id) {
|
||||||
|
WmsStorage old = getById(id);
|
||||||
|
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("数据不存在");
|
||||||
|
removeById(id);
|
||||||
|
auditLogService.addDelete(WmsStorage.class, old, UserUtil.getUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enable(EnableQO request) {
|
||||||
|
WmsStorage old = getById(request.getId());
|
||||||
|
VUtil.trueThrowBusinessError(Objects.isNull(old)).throwMessage("储位不存在");
|
||||||
|
lambdaUpdate()
|
||||||
|
.set(WmsStorage::getEnable, request.getEnable())
|
||||||
|
.set(WmsStorage::getUpdateBy, UserUtil.getUserName())
|
||||||
|
.set(WmsStorage::getUpdateTime, LocalDateTime.now())
|
||||||
|
.eq(WmsStorage::getId, request.getId())
|
||||||
|
.update();
|
||||||
|
WmsStorage newInfo = getById(request.getId());
|
||||||
|
auditLogService.addUpdate(WmsStorage.class, old, newInfo, UserUtil.getUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<StorageVO> search(StorageSearchQO request) {
|
||||||
|
return baseMapper.search(request,new Page<>(request.getPage(),request.getPageSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StorageVO> getList(List<Long> ids) {
|
||||||
|
return baseMapper.getList(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?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.WmsStorageBinMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?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.WmsStorageMapper">
|
||||||
|
|
||||||
|
<select id="search" resultType="com.nflg.wms.common.pojo.vo.StorageVO">
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
s.*,
|
||||||
|
wh.no AS "warehouseNo",
|
||||||
|
m.no AS "materialNo",
|
||||||
|
m.describe AS "materialDescribe",
|
||||||
|
get_binnos(s.id) AS "binNos"
|
||||||
|
FROM wms_storage s
|
||||||
|
LEFT JOIN wms_warehouse wh ON s.warehouse_id = wh.id
|
||||||
|
LEFT JOIN wms_material m ON s.material_id = m.id
|
||||||
|
<where>
|
||||||
|
<if test="request.warehouseNo!=null and request.warehouseNo!=''">
|
||||||
|
and wh.no like concat('%', #{request.warehouseNo}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="request.materialNo!=null and request.materialNo!=''">
|
||||||
|
and (m.no like concat('%', #{request.materialNo}, '%') or m.describe like concat('%',
|
||||||
|
#{request.materialNo}, '%'))
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
) t
|
||||||
|
<where>
|
||||||
|
<if test="request.binNo!=null and request.binNo!=''">
|
||||||
|
and t."binNos" like concat('%', #{request.binNo}, '%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getList" resultType="com.nflg.wms.common.pojo.vo.StorageVO">
|
||||||
|
SELECT
|
||||||
|
s.*,
|
||||||
|
wh.no AS "warehouseNo",
|
||||||
|
m.no AS "materialNo",
|
||||||
|
m.describe AS "materialDescribe",
|
||||||
|
get_binnos(s.id) AS "binNos"
|
||||||
|
FROM wms_storage s
|
||||||
|
LEFT JOIN wms_warehouse wh ON s.warehouse_id = wh.id
|
||||||
|
LEFT JOIN wms_material m ON s.material_id = m.id
|
||||||
|
where s.id in
|
||||||
|
<foreach item="item" collection="ids" separator="," open="(" close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
|
|
@ -33,7 +33,7 @@ public class CodeGeneratorTest {
|
||||||
)
|
)
|
||||||
.strategyConfig(builder -> {
|
.strategyConfig(builder -> {
|
||||||
builder
|
builder
|
||||||
.addInclude("wms_bin") //只生成指定表
|
.addInclude("wms_storage_bin") //只生成指定表
|
||||||
.entityBuilder().idType(IdType.ASSIGN_ID)
|
.entityBuilder().idType(IdType.ASSIGN_ID)
|
||||||
.enableLombok()
|
.enableLombok()
|
||||||
.enableChainModel()
|
.enableChainModel()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue