库位、物料、容器新增导入、导出
parent
59b4c78226
commit
7156c8445c
|
|
@ -61,6 +61,7 @@ public class AdminCacheConst extends CacheKeyConst {
|
|||
public static final String AREA_ENTITY = "area_cache";
|
||||
public static final String LOCATION_ENTITY = "location_cache";
|
||||
public static final String ITEM_ENTITY = "item_cache";
|
||||
public static final String STOCK_ENTITY = "stock_cache";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package net.lab1024.sa.admin.module.business.base.area.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class AreaSelect {
|
||||
|
||||
@Schema(description = "库区名称集合")
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
|||
import net.lab1024.sa.admin.module.business.base.area.dao.AreaDao;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.lab1024.sa.admin.module.business.base.area.service.AreaQueryService;
|
||||
import net.lab1024.sa.admin.module.business.category.domain.entity.CategoryEntity;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
|
|
|||
|
|
@ -82,6 +82,27 @@ public class AreaQueryService {
|
|||
return areaMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据库区name集合查询库区信息
|
||||
*
|
||||
* @param areaNameList 库区name集合
|
||||
* @return Map<Long, AreaEntity>
|
||||
*/
|
||||
public Map<String, AreaEntity> queryAreaByNameList(List<String> areaNameList) {
|
||||
if (CollectionUtils.isEmpty(areaNameList)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
LambdaQueryWrapper<AreaEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(AreaEntity::getAreaName, areaNameList);
|
||||
|
||||
List<AreaEntity> areaList = areaDao.selectList(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(areaList)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return areaList.stream()
|
||||
.collect(Collectors.toMap(AreaEntity::getAreaName, area -> area, (existing, replacement) -> existing));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据库区名称查询库区信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package net.lab1024.sa.admin.module.business.base.area.service;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import net.lab1024.sa.admin.module.business.base.area.dao.AreaDao;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.form.AreaAddForm;
|
||||
|
|
@ -17,13 +16,14 @@ import net.lab1024.sa.base.common.domain.ResponseDTO;
|
|||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 库区信息 Service
|
||||
*
|
||||
* @Author hj
|
||||
* @Date 2025-03-11 11:12:36
|
||||
* @Copyright 友仓
|
||||
* @author hj
|
||||
* @since 2025-03-11 11:12:36
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Service
|
||||
|
|
@ -48,6 +48,7 @@ public class AreaService {
|
|||
* @param addForm 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> add(AreaAddForm addForm) {
|
||||
AreaEntity existingArea = areaQueryService.queryByAreaName(addForm.getAreaName());
|
||||
if (existingArea != null) {
|
||||
|
|
@ -66,6 +67,7 @@ public class AreaService {
|
|||
* @param updateForm 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> update(AreaUpdateForm updateForm) {
|
||||
AreaEntity existingArea = areaQueryService.queryByAreaName(updateForm.getAreaName());
|
||||
if (existingArea != null && !existingArea.getAreaId().equals(updateForm.getAreaId())) {
|
||||
|
|
@ -84,6 +86,7 @@ public class AreaService {
|
|||
* @param idList 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -117,6 +120,7 @@ public class AreaService {
|
|||
* @param areaId 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> delete(Long areaId) {
|
||||
if (null == areaId) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -124,8 +128,7 @@ public class AreaService {
|
|||
|
||||
AreaEntity area = areaManager.queryArea(areaId);
|
||||
if (!locationQueryService.checkLocationExist(areaId)) {
|
||||
String msg = area.getAreaName() + "已关联库位,无法删除";
|
||||
return ResponseDTO.error(UserErrorCode.BAD_ERROR, msg);
|
||||
return ResponseDTO.userErrorParam(area.getAreaName() + "已关联库位,无法删除");
|
||||
}
|
||||
|
||||
areaDao.deleteById(areaId);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
package net.lab1024.sa.admin.module.business.base.item.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.entity.ItemEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemAddForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemVO;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemsExcelVO;
|
||||
import net.lab1024.sa.admin.module.business.base.item.service.ItemQueryService;
|
||||
import net.lab1024.sa.admin.module.business.base.item.service.ItemService;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.LocationSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.vo.LocationVO;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import net.lab1024.sa.base.common.domain.RequestUser;
|
||||
import net.lab1024.sa.base.common.domain.ValidateList;
|
||||
import net.lab1024.sa.base.common.util.SmartExcelUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
|
|
@ -21,15 +22,17 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物料信息 Controller
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-25 17:08:18
|
||||
* @Copyright 友仓
|
||||
* @author 霍锦
|
||||
* @since 2024-11-25 17:08:18
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@RestController
|
||||
|
|
@ -85,4 +88,19 @@ public class ItemController {
|
|||
public ResponseDTO<List<ItemEntity>> queryItem(@RequestBody ItemSelect itemSelect) {
|
||||
return ResponseDTO.ok(itemQueryService.queryItem(itemSelect));
|
||||
}
|
||||
|
||||
@Operation(summary = "导入 霍锦")
|
||||
@PostMapping("/item/importItems")
|
||||
@SaCheckPermission("item:importItems")
|
||||
public ResponseDTO<String> importItems(@RequestParam MultipartFile file) {
|
||||
return itemService.importItems(file);
|
||||
}
|
||||
|
||||
@Operation(summary = "导出 霍锦")
|
||||
@GetMapping("/item/exportItems")
|
||||
@SaCheckPermission("item:exportItems")
|
||||
public void exportItems(HttpServletResponse response) throws IOException {
|
||||
List<ItemsExcelVO> itemsList = itemQueryService.getItemsExcelVOList();
|
||||
SmartExcelUtil.exportExcel(response, "物料信息.xlsx", "物料", ItemsExcelVO.class, itemsList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -18,6 +20,7 @@ import lombok.Data;
|
|||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@TableName("t_item")
|
||||
public class ItemEntity {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package net.lab1024.sa.admin.module.business.base.item.domain.form;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ItemsImportForm {
|
||||
@ExcelProperty("物料编码")
|
||||
private String itemCode;
|
||||
|
||||
@ExcelProperty("物料名称")
|
||||
private String itemName;
|
||||
|
||||
@ExcelProperty("物料类型")
|
||||
private String itemType;
|
||||
|
||||
@ExcelProperty("包装单位")
|
||||
private String unit;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package net.lab1024.sa.admin.module.business.base.item.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ItemsExcelVO {
|
||||
|
||||
@ExcelProperty("物料编码")
|
||||
private String itemCode;
|
||||
|
||||
@ExcelProperty("物料名称")
|
||||
private String itemName;
|
||||
|
||||
@ExcelProperty("物料类型")
|
||||
private String itemType;
|
||||
|
||||
@ExcelProperty("包装单位")
|
||||
private String unit;
|
||||
|
||||
@ExcelProperty("是否启用")
|
||||
private String disabledFlag;
|
||||
}
|
||||
|
|
@ -8,17 +8,27 @@ import net.lab1024.sa.admin.module.business.base.item.domain.entity.ItemEntity;
|
|||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemVO;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemsExcelVO;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import net.lab1024.sa.base.common.util.SmartPageUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ItemQueryService {
|
||||
@Resource
|
||||
private ItemDao itemDao;
|
||||
|
||||
@Resource
|
||||
private DictCacheService dictCacheService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
|
|
@ -32,7 +42,7 @@ public class ItemQueryService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 查询物料信息
|
||||
* 物料下拉查询
|
||||
*
|
||||
* @param itemSelect 入参
|
||||
* @return List<ItemEntity>
|
||||
|
|
@ -57,4 +67,52 @@ public class ItemQueryService {
|
|||
queryWrapper.eq(ItemEntity::getItemCode, itemCode);
|
||||
return itemDao.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据物料编码集合查询物料信息
|
||||
*
|
||||
* @param itemCodes 物料编码集合
|
||||
* @return List<ItemEntity>
|
||||
*/
|
||||
public List<ItemEntity> queryByItemCodes(List<String> itemCodes) {
|
||||
LambdaQueryWrapper<ItemEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(ItemEntity::getItemCode, itemCodes);
|
||||
return itemDao.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据物料编码集合查询物料信息
|
||||
*
|
||||
* @param itemCodes 物料集合
|
||||
* @return Map<String, ItemEntity>
|
||||
*/
|
||||
public Map<String, ItemEntity> queryItemListToMap(List<String> itemCodes) {
|
||||
if (CollectionUtils.isEmpty(itemCodes)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<ItemEntity> items = queryByItemCodes(itemCodes);
|
||||
return items.stream()
|
||||
.collect(Collectors.toMap(ItemEntity::getItemCode, item -> item, (existing, replacement) -> existing));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 物料导出
|
||||
*
|
||||
* @return List<LocationsExcelVO>
|
||||
*/
|
||||
public List<ItemsExcelVO> getItemsExcelVOList() {
|
||||
List<ItemEntity> itemsList = itemDao.selectList(null);
|
||||
return itemsList.stream()
|
||||
.map(item ->
|
||||
ItemsExcelVO.builder()
|
||||
.itemCode(item.getItemCode())
|
||||
.itemName(item.getItemName())
|
||||
.itemType(dictCacheService.selectValueNameByValueCode(DictConst.ITEM_TYPE.getValue(), item.getItemType()))
|
||||
.unit(dictCacheService.selectValueNameByValueCode(DictConst.ITEM_UNIT.getValue(), item.getUnit()))
|
||||
.disabledFlag(item.getDisabledFlag() ? "启用" : "禁用")
|
||||
.build()
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,41 @@
|
|||
package net.lab1024.sa.admin.module.business.base.item.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
||||
import cn.idev.excel.FastExcel;
|
||||
import net.lab1024.sa.admin.module.business.base.item.dao.ItemDao;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.entity.ItemEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemAddForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemVO;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemsImportForm;
|
||||
import net.lab1024.sa.admin.module.business.base.item.manager.ItemManager;
|
||||
import net.lab1024.sa.admin.util.JoinerResult;
|
||||
import net.lab1024.sa.admin.util.ResponseDTOUtils;
|
||||
import net.lab1024.sa.admin.util.ValidateDictKey;
|
||||
import net.lab1024.sa.base.common.code.UserErrorCode;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartBeanUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartPageUtil;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 物料信息 Service
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-25 17:08:18
|
||||
* @Copyright 友仓
|
||||
* @author 霍锦
|
||||
* @since 2024-11-25 17:08:18
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Service
|
||||
|
|
@ -41,12 +50,16 @@ public class ItemService {
|
|||
@Resource
|
||||
private ItemQueryService itemQueryService;
|
||||
|
||||
@Resource
|
||||
private ValidateDictKey ValidateDictKey;
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param addForm 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> add(ItemAddForm addForm) {
|
||||
ItemEntity existingItem = itemQueryService.queryByItemCode(addForm.getItemCode());
|
||||
if (existingItem != null) {
|
||||
|
|
@ -66,6 +79,7 @@ public class ItemService {
|
|||
* @param updateForm 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> update(ItemUpdateForm updateForm) {
|
||||
ItemEntity existingItem = itemQueryService.queryByItemCode(updateForm.getItemCode());
|
||||
if (existingItem != null && !existingItem.getItemId().equals(updateForm.getItemId())) {
|
||||
|
|
@ -84,6 +98,7 @@ public class ItemService {
|
|||
* @param idList 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -102,6 +117,7 @@ public class ItemService {
|
|||
* @param itemId 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> delete(Long itemId) {
|
||||
if (null == itemId) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -113,4 +129,92 @@ public class ItemService {
|
|||
itemManager.removeCache();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 物料导入
|
||||
*
|
||||
* @param file 上传文件
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> importItems(MultipartFile file) {
|
||||
List<ItemsImportForm> dataList;
|
||||
try {
|
||||
dataList = FastExcel.read(file.getInputStream()).head(ItemsImportForm.class)
|
||||
.sheet()
|
||||
.doReadSync();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("数据格式存在问题,无法读取");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(dataList)) {
|
||||
return ResponseDTO.userErrorParam("数据为空");
|
||||
}
|
||||
|
||||
//获取所有去重后的物料类型
|
||||
List<String> itemTypes = dataList.stream().map(ItemsImportForm::getItemType).distinct().collect(Collectors.toList());
|
||||
|
||||
//验证物料类型
|
||||
Map<String, String> itemTypeMap = ValidateDictKey.validateDictCodes(itemTypes, DictConst.ITEM_TYPE.getValue());
|
||||
|
||||
//获取所有去重后的包装单位
|
||||
List<String> units = dataList.stream().map(ItemsImportForm::getUnit).distinct().collect(Collectors.toList());
|
||||
|
||||
//验证包装单位
|
||||
Map<String, String> unitMap = ValidateDictKey.validateDictCodes(units, DictConst.ITEM_UNIT.getValue());
|
||||
|
||||
//获取所有去重后的容器编码
|
||||
List<String> itemCodes = dataList.stream().map(ItemsImportForm::getItemCode).distinct().collect(Collectors.toList());
|
||||
|
||||
//查询数据库存在的物料
|
||||
Map<String, ItemEntity> exitItemMap = itemQueryService.queryItemListToMap(itemCodes);
|
||||
|
||||
List<ItemEntity> insertToItem = new ArrayList<>();
|
||||
List<ItemEntity> updateToItem = new ArrayList<>();
|
||||
for (ItemsImportForm itemsImportForm : dataList) {
|
||||
|
||||
//物料类型
|
||||
String itemType = itemTypeMap.get(itemsImportForm.getItemType());
|
||||
|
||||
//包装单位
|
||||
String unit = unitMap.get(itemsImportForm.getUnit());
|
||||
|
||||
//物料
|
||||
ItemEntity item = exitItemMap.get(itemsImportForm.getItemCode());
|
||||
|
||||
//物料为空则新增,否则更新
|
||||
if (item == null) {
|
||||
insertToItem.add(createItem(itemsImportForm.getItemCode(), itemsImportForm.getItemName(), unit, BigDecimal.ONE, itemType));
|
||||
} else {
|
||||
updateToItem.add(createItem(itemsImportForm.getItemCode(), itemsImportForm.getItemName(), unit, BigDecimal.ONE, itemType));
|
||||
}
|
||||
}
|
||||
|
||||
JoinerResult resultMsg = JoinerResult.createJoiner();
|
||||
return ResponseDTOUtils.buildResponseSussDTO(insertToItem, updateToItem, itemManager::saveBatch, itemManager::updateBatchById, resultMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建物料
|
||||
*
|
||||
* @param itemCode 物料编码
|
||||
* @param itemName 物料名称
|
||||
* @param unit 包装单位
|
||||
* @param packFactor 包装系数
|
||||
* @param itemType 物料类型
|
||||
* @return ItemEntity
|
||||
*/
|
||||
public ItemEntity createItem(String itemCode, String itemName, String unit, BigDecimal packFactor, String itemType) {
|
||||
return ItemEntity.builder()
|
||||
.itemCode(itemCode)
|
||||
.itemName(itemName)
|
||||
.unit(unit)
|
||||
.packFactor(packFactor)
|
||||
.disabledFlag(true)
|
||||
.itemType(itemType)
|
||||
.createUserId(SmartRequestUtil.getRequestUser().getUserId())
|
||||
.createUserName(SmartRequestUtil.getRequestUser().getUserName())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package net.lab1024.sa.admin.module.business.base.location.controller;
|
||||
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.*;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.vo.LocationVO;
|
||||
import net.lab1024.sa.admin.module.business.base.location.service.LocationQueryService;
|
||||
import net.lab1024.sa.admin.module.business.base.location.service.LocationService;
|
||||
import net.lab1024.sa.base.common.domain.RequestUser;
|
||||
import net.lab1024.sa.base.common.domain.ValidateList;
|
||||
import net.lab1024.sa.base.common.util.SmartExcelUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
|
|
@ -18,6 +20,7 @@ import jakarta.annotation.Resource;
|
|||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -89,7 +92,7 @@ public class LocationController {
|
|||
return locationService.multipleAdjust(multipleAdjust);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量调整 霍锦")
|
||||
@Operation(summary = "批量新建 霍锦")
|
||||
@PostMapping("/location/multipleInsert")
|
||||
@SaCheckPermission("location:multipleInsert")
|
||||
public ResponseDTO<String> multipleInsert(@RequestBody @Valid MultipleInsert multipleInsert) {
|
||||
|
|
@ -102,4 +105,13 @@ public class LocationController {
|
|||
public ResponseDTO<String> importLocations(@RequestParam MultipartFile file) {
|
||||
return locationService.importLocations(file);
|
||||
}
|
||||
|
||||
@Operation(summary = "导出 霍锦")
|
||||
@GetMapping("/location/exportLocations")
|
||||
@SaCheckPermission("location:exportLocations")
|
||||
public void exportLocations(HttpServletResponse response) throws IOException {
|
||||
List<LocationsExcelVO> locationsList = locationQueryService.getLocationsExcelVOList();
|
||||
SmartExcelUtil.exportExcel(response, "库位信息.xlsx", "库位", LocationsExcelVO.class, locationsList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package net.lab1024.sa.admin.module.business.base.location.domain.form;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LocationsExcelVO {
|
||||
@ExcelProperty("库区")
|
||||
private String areaName;
|
||||
|
||||
@ExcelProperty("库位")
|
||||
private String locationCode;
|
||||
|
||||
@ExcelProperty("库位类型")
|
||||
private String locationType;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private String status;
|
||||
|
||||
@ExcelProperty("是否启用")
|
||||
private String disabledFlag;
|
||||
|
||||
}
|
||||
|
|
@ -2,14 +2,16 @@ package net.lab1024.sa.admin.module.business.base.location.domain.form;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MultipleAdjust {
|
||||
@Schema(description = "库位", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "库位 不能为空")
|
||||
@NotNull(message = "库位 不能为空")
|
||||
List<Long> locationIds;
|
||||
|
||||
@Schema(description = "状态;true:空闲;false:占用")
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package net.lab1024.sa.admin.module.business.base.location.manager;
|
|||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.constant.AdminCacheConst;
|
||||
import net.lab1024.sa.admin.module.business.base.area.dao.AreaDao;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.location.dao.LocationDao;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.entity.LocationEntity;
|
||||
|
||||
|
|
@ -16,9 +14,9 @@ import org.springframework.stereotype.Service;
|
|||
/**
|
||||
* 库位信息 Manager
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-18 14:17:31
|
||||
* @Copyright 友仓
|
||||
* @author 霍锦
|
||||
* @since 2024-11-18 14:17:31
|
||||
* copyright 友仓
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Maps;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.admin.constant.UsageStatusEnum;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.form.AreaSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.area.manager.AreaManager;
|
||||
|
|
@ -12,10 +13,14 @@ import net.lab1024.sa.admin.module.business.base.location.dao.LocationDao;
|
|||
import net.lab1024.sa.admin.module.business.base.location.domain.entity.LocationEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.LocationQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.LocationSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.LocationsExcelVO;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.vo.LocationVO;
|
||||
import net.lab1024.sa.admin.module.business.base.location.manager.LocationManager;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import net.lab1024.sa.base.common.util.SmartEnumUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartPageUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -40,6 +45,9 @@ public class LocationQueryService {
|
|||
@Resource
|
||||
private AreaQueryService areaQueryService;
|
||||
|
||||
@Resource
|
||||
private DictCacheService dictCacheService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
|
|
@ -101,7 +109,7 @@ public class LocationQueryService {
|
|||
}
|
||||
//库区
|
||||
if (CollectionUtils.isNotEmpty(locationSelect.getAreaNames())) {
|
||||
AreaSelect areaSelect = new AreaSelect();
|
||||
AreaSelect areaSelect = AreaSelect.builder().areaNames(locationSelect.getAreaNames()).build();
|
||||
areaSelect.setAreaNames(locationSelect.getAreaNames());
|
||||
List<AreaEntity> areaList = areaQueryService.queryArea(areaSelect);
|
||||
if (CollectionUtils.isNotEmpty(areaList)) {
|
||||
|
|
@ -182,5 +190,45 @@ public class LocationQueryService {
|
|||
return locationDao.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据库位编码集合查询库位信息
|
||||
*
|
||||
* @param locationCodes 库位集合
|
||||
* @return Map<String, LocationEntity>
|
||||
*/
|
||||
public Map<String, LocationEntity> queryLocationListToMap(List<String> locationCodes) {
|
||||
if (CollectionUtils.isEmpty(locationCodes)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<LocationEntity> locations = queryByLocationCodes(locationCodes);
|
||||
return locations.stream()
|
||||
.collect(Collectors.toMap(LocationEntity::getLocationCode, location -> location, (existing, replacement) -> existing));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 库位导出
|
||||
*
|
||||
* @return List<LocationsExcelVO>
|
||||
*/
|
||||
public List<LocationsExcelVO> getLocationsExcelVOList() {
|
||||
List<LocationEntity> locationsList = locationDao.selectList(null);
|
||||
//库区
|
||||
List areaIds = locationsList.stream().map(LocationEntity::getAreaId).distinct().collect(Collectors.toList());
|
||||
Map<Long, AreaEntity> areaMap = areaQueryService.queryAreaList(areaIds);
|
||||
return locationsList.stream()
|
||||
.map(location ->
|
||||
LocationsExcelVO.builder()
|
||||
.areaName(areaMap.get(location.getAreaId()).getAreaName())
|
||||
.locationCode(location.getLocationCode())
|
||||
.locationType(dictCacheService.selectValueNameByValueCode(DictConst.LOC_TYPE.getValue(), location.getLocationType()))
|
||||
.status(SmartEnumUtil.getEnumDescByValue(location.getStatus(), UsageStatusEnum.class))
|
||||
.disabledFlag(location.getDisabledFlag() ? "启用" : "禁用")
|
||||
.build()
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,40 @@
|
|||
package net.lab1024.sa.admin.module.business.base.location.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.idev.excel.FastExcel;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.constant.UsageStatusEnum;
|
||||
import net.lab1024.sa.admin.module.business.base.area.domain.entity.AreaEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.area.service.AreaQueryService;
|
||||
import net.lab1024.sa.admin.module.business.base.location.dao.LocationDao;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.entity.LocationEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.location.domain.form.*;
|
||||
import net.lab1024.sa.admin.module.business.base.location.manager.LocationManager;
|
||||
import net.lab1024.sa.admin.util.JoinerResult;
|
||||
import net.lab1024.sa.admin.util.ResponseDTOUtils;
|
||||
import net.lab1024.sa.admin.util.ValidateDictKey;
|
||||
import net.lab1024.sa.base.common.code.UserErrorCode;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartBeanUtil;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartStringUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 库位信息 Service
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-18 14:17:31
|
||||
* @Copyright 友仓
|
||||
* @author 霍锦
|
||||
* @since 2024-11-18 14:17:31
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Service
|
||||
|
|
@ -45,11 +47,14 @@ public class LocationService {
|
|||
@Resource
|
||||
private LocationManager locationManager;
|
||||
|
||||
@Resource
|
||||
private AreaQueryService areaQueryService;
|
||||
|
||||
@Resource
|
||||
private LocationQueryService locationQueryService;
|
||||
|
||||
@Resource
|
||||
private DictCacheService dictCacheService;
|
||||
private ValidateDictKey ValidateDictKey;
|
||||
|
||||
/**
|
||||
* 添加
|
||||
|
|
@ -57,6 +62,7 @@ public class LocationService {
|
|||
* @param addForm 添加参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> add(LocationAddForm addForm) {
|
||||
LocationEntity existingLocation = locationQueryService.queryByLocationCode(addForm.getLocationCode());
|
||||
if (existingLocation != null) {
|
||||
|
|
@ -76,6 +82,7 @@ public class LocationService {
|
|||
* @param updateForm 更新参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> update(LocationUpdateForm updateForm) {
|
||||
LocationEntity existingLocation = locationQueryService.queryByLocationCode(updateForm.getLocationCode());
|
||||
if (existingLocation != null && !existingLocation.getLocationId().equals(updateForm.getLocationId())) {
|
||||
|
|
@ -94,6 +101,7 @@ public class LocationService {
|
|||
* @param idList 删除参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -111,6 +119,7 @@ public class LocationService {
|
|||
* @param locationId 入参
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> delete(Long locationId) {
|
||||
if (null == locationId) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
|
|
@ -128,6 +137,7 @@ public class LocationService {
|
|||
* @param multipleAdjust 参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> multipleAdjust(MultipleAdjust multipleAdjust) {
|
||||
|
||||
if (CollectionUtils.isEmpty(multipleAdjust.getLocationIds())) {
|
||||
|
|
@ -191,20 +201,37 @@ public class LocationService {
|
|||
.build();
|
||||
}
|
||||
|
||||
|
||||
public LocationEntity createLocation(String locationCode, Long areaId, String locationType) {
|
||||
int firstDashIndex = locationCode.indexOf('-');
|
||||
if (firstDashIndex == -1) {
|
||||
return createLocation(locationCode, areaId, null, null, null, locationType);
|
||||
}
|
||||
String[] parts = locationCode.substring(firstDashIndex + 1).split("-");
|
||||
if (parts.length < 3) {
|
||||
return createLocation(locationCode, areaId, null, null, null, locationType);
|
||||
}
|
||||
String row = parts[0];
|
||||
String col = parts[1];
|
||||
String layer = parts[2];
|
||||
return createLocation(locationCode, areaId, row, col, layer, locationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
* @param locationCodes 库位集合
|
||||
* @param areaId 库区
|
||||
* @param locationType 库位类型
|
||||
*/
|
||||
public void multipleInsert(List<String> locationCodes, Long areaId, String locationType) {
|
||||
List<LocationEntity> insertToLocation = new ArrayList<>();
|
||||
for (String locationCode : locationCodes) {
|
||||
int firstDashIndex = locationCode.indexOf('-');
|
||||
String[] parts = locationCode.substring(firstDashIndex + 1).split("-");
|
||||
String row = parts[0];
|
||||
String col = parts[1];
|
||||
String layer = parts[2];
|
||||
LocationEntity location = createLocation(locationCode, areaId, row, col, layer, locationType);
|
||||
LocationEntity location = createLocation(locationCode, areaId, locationType);
|
||||
insertToLocation.add(location);
|
||||
}
|
||||
//批量新增
|
||||
if (CollectionUtils.isNotEmpty(insertToLocation)) {
|
||||
locationDao.insert(insertToLocation);
|
||||
locationManager.saveBatch(insertToLocation);
|
||||
}
|
||||
|
||||
// 更新缓存
|
||||
|
|
@ -217,6 +244,7 @@ public class LocationService {
|
|||
* @param multipleInsert 参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> multipleInsert(MultipleInsert multipleInsert) {
|
||||
//入参的所以库位集合
|
||||
List<String> locationCodes = multipleInsert.getLocationCodes();
|
||||
|
|
@ -233,9 +261,11 @@ public class LocationService {
|
|||
joiner.getErrorMsg().add(getIntersection + "库位已存在,新增失败");
|
||||
// 获取两个集合的非交集说明库位不存在;批量新增
|
||||
List<String> difference = SmartStringUtil.getDifference(locationCodes, existingLocationCodes);
|
||||
//批量新增
|
||||
multipleInsert(difference, multipleInsert.getAreaId(), multipleInsert.getLocationType());
|
||||
joiner.getSussMsg().add(difference + "库位新增成功");
|
||||
if (CollectionUtils.isNotEmpty(difference)) {
|
||||
//批量新增
|
||||
multipleInsert(difference, multipleInsert.getAreaId(), multipleInsert.getLocationType());
|
||||
joiner.getSussMsg().add(difference + "库位新增成功");
|
||||
}
|
||||
|
||||
return ResponseDTOUtils.buildResponseDTO(joiner);
|
||||
}
|
||||
|
|
@ -253,6 +283,7 @@ public class LocationService {
|
|||
* @param file 上传文件
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> importLocations(MultipartFile file) {
|
||||
List<LocationsImportForm> dataList;
|
||||
try {
|
||||
|
|
@ -262,13 +293,73 @@ public class LocationService {
|
|||
} catch (IOException e) {
|
||||
throw new BusinessException("数据格式存在问题,无法读取");
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(dataList)) {
|
||||
return ResponseDTO.userErrorParam("数据为空");
|
||||
}
|
||||
|
||||
return ResponseDTO.okMsg("成功导入" + dataList.size() + "条,具体数据为:" + JSON.toJSONString(dataList));
|
||||
//获取所有去重后的库区
|
||||
List<String> areaNames = dataList.stream().map(LocationsImportForm::getAreaName).distinct().collect(Collectors.toList());
|
||||
|
||||
//验证库区
|
||||
Map<String, AreaEntity> areaMap = validateArea(areaNames);
|
||||
|
||||
//获取所有去重后的库位类型
|
||||
List<String> locationTypes = dataList.stream().map(LocationsImportForm::getLocationType).distinct().collect(Collectors.toList());
|
||||
|
||||
//验证库位类型
|
||||
Map<String, String> locationTypeMap = ValidateDictKey.validateDictCodes(locationTypes, DictConst.LOC_TYPE.getValue());
|
||||
|
||||
//获取所有去重后的库位编码
|
||||
List<String> locationCodes = dataList.stream().map(LocationsImportForm::getLocationCode).distinct().collect(Collectors.toList());
|
||||
|
||||
//查询数据库存在的库位编码
|
||||
Map<String, LocationEntity> exitLocationMap = locationQueryService.queryLocationListToMap(locationCodes);
|
||||
|
||||
List<LocationEntity> insertToLocation = new ArrayList<>();
|
||||
List<LocationEntity> updateToLocation = new ArrayList<>();
|
||||
for (LocationsImportForm locationsImportForm : dataList) {
|
||||
//库区
|
||||
AreaEntity area = areaMap.get(locationsImportForm.getAreaName());
|
||||
|
||||
//库位类型
|
||||
String locationType = locationTypeMap.get(locationsImportForm.getLocationType());
|
||||
|
||||
//库位
|
||||
LocationEntity location = exitLocationMap.get(locationsImportForm.getLocationCode());
|
||||
|
||||
//库位为空则更新,否则新增
|
||||
if (location == null) {
|
||||
insertToLocation.add(createLocation(locationsImportForm.getLocationCode(), area.getAreaId(), locationType));
|
||||
} else {
|
||||
updateToLocation.add(createLocation(locationsImportForm.getLocationCode(), area.getAreaId(), locationType));
|
||||
}
|
||||
}
|
||||
|
||||
JoinerResult resultMsg = JoinerResult.createJoiner();
|
||||
return ResponseDTOUtils.buildResponseSussDTO(insertToLocation, updateToLocation, locationManager::saveBatch, locationManager::updateBatchById, resultMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证库区
|
||||
*
|
||||
* @param areaNames 库区集合
|
||||
* @return Map<String, AreaEntity>
|
||||
*/
|
||||
public Map<String, AreaEntity> validateArea(List<String> areaNames) {
|
||||
//查询数据库存在的库区
|
||||
Map<String, AreaEntity> areaMap = areaQueryService.queryAreaByNameList(areaNames);
|
||||
if (areaMap.isEmpty()) {
|
||||
throw new BusinessException(areaNames + "库区不存在,在库区管理中维护库区");
|
||||
}
|
||||
|
||||
//获取map的key集合
|
||||
List<String> exitAreaNameList = areaMap.keySet().stream().toList();
|
||||
//获取两个集合的非交集说明库区不存在;提示错误
|
||||
List<String> diffAreaName = SmartStringUtil.getDifference(areaNames, exitAreaNameList);
|
||||
if (CollectionUtils.isNotEmpty(diffAreaName)) {
|
||||
throw new BusinessException(diffAreaName + "库区不存在,在库区管理中维护库区");
|
||||
}
|
||||
return areaMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.entity.ItemEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.vo.ItemsExcelVO;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.entity.StockEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockAddForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.vo.StockVO;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.vo.StocksExcelVO;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.service.StockQueryService;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.service.StockService;
|
||||
import net.lab1024.sa.base.common.domain.ValidateList;
|
||||
import net.lab1024.sa.base.common.util.SmartExcelUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 容器信息 Controller
|
||||
*
|
||||
* @author 霍锦
|
||||
* @since 2024-11-26 11:37:48
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@Tag(name = "容器信息")
|
||||
public class StockController {
|
||||
|
||||
@Resource
|
||||
private StockService stockService;
|
||||
|
||||
@Resource
|
||||
private StockQueryService stockQueryService;
|
||||
|
||||
@Operation(summary = "分页查询 @author 霍锦")
|
||||
@PostMapping("/stock/queryPage")
|
||||
@SaCheckPermission("stock:query")
|
||||
public ResponseDTO<PageResult<StockVO>> queryPage(@RequestBody @Valid StockQueryForm queryForm) {
|
||||
return ResponseDTO.ok(stockQueryService.queryPage(queryForm));
|
||||
}
|
||||
|
||||
@Operation(summary = "添加 @author 霍锦")
|
||||
@PostMapping("/stock/add")
|
||||
@SaCheckPermission("stock:add")
|
||||
public ResponseDTO<String> add(@RequestBody @Valid StockAddForm addForm) {
|
||||
return stockService.add(addForm);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新 @author 霍锦")
|
||||
@PostMapping("/stock/update")
|
||||
@SaCheckPermission("stock:update")
|
||||
public ResponseDTO<String> update(@RequestBody @Valid StockUpdateForm updateForm) {
|
||||
return stockService.update(updateForm);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除 @author 霍锦")
|
||||
@PostMapping("/stock/batchDelete")
|
||||
@SaCheckPermission("stock:batchDelete")
|
||||
public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
|
||||
return stockService.batchDelete(idList);
|
||||
}
|
||||
|
||||
@Operation(summary = "单个删除 @author 霍锦")
|
||||
@GetMapping("/stock/delete")
|
||||
@SaCheckPermission("stock:delete")
|
||||
public ResponseDTO<String> delete(@RequestParam Long stockId) {
|
||||
return stockService.delete(stockId);
|
||||
}
|
||||
|
||||
@Operation(summary = "容器下拉查询")
|
||||
@PostMapping("/stock/queryStock")
|
||||
public ResponseDTO<List<StockEntity>> queryItem(@RequestBody StockSelect stockSelect) {
|
||||
return ResponseDTO.ok(stockQueryService.queryStock(stockSelect));
|
||||
}
|
||||
|
||||
@Operation(summary = "导入 霍锦")
|
||||
@PostMapping("/stock/importStocks")
|
||||
@SaCheckPermission("stock:importStocks")
|
||||
public ResponseDTO<String> importStocks(@RequestParam MultipartFile file) {
|
||||
return stockService.importStocks(file);
|
||||
}
|
||||
|
||||
@Operation(summary = "导出 霍锦")
|
||||
@GetMapping("/stock/exportStocks")
|
||||
@SaCheckPermission("stock:exportStocks")
|
||||
public void stock(HttpServletResponse response) throws IOException {
|
||||
List<StocksExcelVO> stocksList = stockQueryService.getStocksExcelVOList();
|
||||
SmartExcelUtil.exportExcel(response, "容器信息.xlsx", "容器", StocksExcelVO.class, stocksList);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.dao;
|
||||
|
||||
import java.util.List;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.entity.StockEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.vo.StockVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 容器信息 Dao
|
||||
*
|
||||
* @author 霍锦
|
||||
* @since 2024-11-26 11:37:48
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
@Component
|
||||
public interface StockDao extends BaseMapper<StockEntity> {
|
||||
|
||||
/**
|
||||
* 分页 查询
|
||||
*
|
||||
* @param page
|
||||
* @param queryForm
|
||||
* @return
|
||||
*/
|
||||
List<StockVO> queryPage(Page page, @Param("queryForm") StockQueryForm queryForm);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 容器信息 实体类
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-26 11:37:48
|
||||
* @Copyright 友仓
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@TableName("t_stock")
|
||||
public class StockEntity {
|
||||
|
||||
/**
|
||||
* 容器id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long stockId;
|
||||
|
||||
/**
|
||||
* 容器编码
|
||||
*/
|
||||
private String stockCode;
|
||||
|
||||
/**
|
||||
* 库位ID
|
||||
*/
|
||||
private Long locationId;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
private Boolean disabledFlag;
|
||||
|
||||
/**
|
||||
* 容器类型
|
||||
*/
|
||||
private String stockType;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createUserId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.form;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.common.json.deserializer.DictValueVoDeserializer;
|
||||
|
||||
/**
|
||||
* 容器信息 新建表单
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-26 11:37:48
|
||||
* @Copyright 友仓
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class StockAddForm {
|
||||
|
||||
@Schema(description = "容器id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "容器id 不能为空")
|
||||
private Long stockId;
|
||||
|
||||
@Schema(description = "容器编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "容器编码 不能为空")
|
||||
private String stockCode;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "状态 不能为空")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "启用状态 不能为空")
|
||||
private Boolean disabledFlag;
|
||||
|
||||
@Schema(description = "容器类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "容器类型 不能为空")
|
||||
@JsonDeserialize(using = DictValueVoDeserializer.class)
|
||||
private String stockType;
|
||||
|
||||
@Schema(description = "创建人ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "创建人ID 不能为空")
|
||||
private Long createUserId;
|
||||
|
||||
@Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "创建人 不能为空")
|
||||
private String createUserName;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "创建时间 不能为空")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "更新时间 不能为空")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.form;
|
||||
|
||||
import net.lab1024.sa.base.common.domain.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 容器信息 分页查询表单
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-26 11:37:48
|
||||
* @Copyright 友仓
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class StockQueryForm extends PageParam {
|
||||
|
||||
@Schema(description = "容器编码")
|
||||
private String stockCode;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StockSelect {
|
||||
@Schema(description = "状态")
|
||||
String status;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
Boolean disabledFlag;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.form;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.common.json.deserializer.DictValueVoDeserializer;
|
||||
|
||||
/**
|
||||
* 容器信息 更新表单
|
||||
*
|
||||
* @author 霍锦
|
||||
* @since 2024-11-26 11:37:48
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class StockUpdateForm {
|
||||
|
||||
@Schema(description = "容器id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "容器id 不能为空")
|
||||
private Long stockId;
|
||||
|
||||
@Schema(description = "容器编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "容器编码 不能为空")
|
||||
private String stockCode;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "状态 不能为空")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "启用状态 不能为空")
|
||||
private Boolean disabledFlag;
|
||||
|
||||
@Schema(description = "容器类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "容器类型 不能为空")
|
||||
@JsonDeserialize(using = DictValueVoDeserializer.class)
|
||||
private String stockType;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.form;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StocksImportForm {
|
||||
@ExcelProperty("容器编码")
|
||||
private String stockCode;
|
||||
|
||||
@ExcelProperty("容器类型")
|
||||
private String stockType;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 容器信息 列表VO
|
||||
*
|
||||
* @Author 霍锦
|
||||
* @Date 2024-11-26 11:37:48
|
||||
* @Copyright 友仓
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class StockVO {
|
||||
|
||||
|
||||
@Schema(description = "容器id")
|
||||
private Long stockId;
|
||||
|
||||
@Schema(description = "容器编码")
|
||||
private String stockCode;
|
||||
|
||||
@Schema(description = "库位ID")
|
||||
private Long locationId;
|
||||
|
||||
@Schema(description = "状态")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "启用状态")
|
||||
private Boolean disabledFlag;
|
||||
|
||||
@Schema(description = "容器类型")
|
||||
private String stockType;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.domain.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StocksExcelVO {
|
||||
@ExcelProperty("容器编码")
|
||||
private String stockCode;
|
||||
|
||||
@ExcelProperty("容器类型")
|
||||
private String stockType;
|
||||
|
||||
@ExcelProperty("库位")
|
||||
private String locationCode;
|
||||
|
||||
@ExcelProperty("是否启用")
|
||||
private String disabledFlag;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.manager;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.constant.AdminCacheConst;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.dao.StockDao;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.entity.StockEntity;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 容器信息 Manager
|
||||
*
|
||||
* @author 霍锦
|
||||
* @since 2024-11-26 11:37:48
|
||||
* copyright 友仓
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StockManager extends ServiceImpl<StockDao, StockEntity> {
|
||||
|
||||
@Resource
|
||||
private StockDao stockDao;
|
||||
|
||||
/**
|
||||
* 根据类目id 移除缓存
|
||||
*/
|
||||
@CacheEvict(value = {AdminCacheConst.Base.STOCK_ENTITY}, allEntries = true)
|
||||
public void removeCache() {
|
||||
log.info("clear LOCATION_ENTITY");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢类目
|
||||
*/
|
||||
@Cacheable(AdminCacheConst.Base.STOCK_ENTITY)
|
||||
public StockEntity queryStock(Long stockId) {
|
||||
return stockDao.selectById(stockId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.admin.module.business.base.location.manager.LocationManager;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.dao.StockDao;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.entity.StockEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockSelect;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.vo.StockVO;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.vo.StocksExcelVO;
|
||||
import net.lab1024.sa.base.common.domain.PageResult;
|
||||
import net.lab1024.sa.base.common.util.SmartPageUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class StockQueryService {
|
||||
|
||||
@Resource
|
||||
private StockDao stockDao;
|
||||
|
||||
@Resource
|
||||
private LocationManager locationManager;
|
||||
|
||||
@Resource
|
||||
private DictCacheService dictCacheService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param queryForm 查询参数
|
||||
* @return PageResult<StockVO>
|
||||
*/
|
||||
public PageResult<StockVO> queryPage(StockQueryForm queryForm) {
|
||||
Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
|
||||
List<StockVO> list = stockDao.queryPage(page, queryForm);
|
||||
return SmartPageUtil.convert2PageResult(page, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 容器下拉查询
|
||||
*
|
||||
* @param stockSelect 入参
|
||||
* @return List<StockEntity>
|
||||
*/
|
||||
public List<StockEntity> queryStock(StockSelect stockSelect) {
|
||||
LambdaQueryWrapper<StockEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
//是否启用
|
||||
if (stockSelect.getDisabledFlag() != null) {
|
||||
queryWrapper.eq(StockEntity::getDisabledFlag, stockSelect.getDisabledFlag());
|
||||
}
|
||||
//状态
|
||||
if (StringUtils.isNotBlank(stockSelect.getStatus())) {
|
||||
queryWrapper.eq(StockEntity::getStatus, stockSelect.getStatus());
|
||||
}
|
||||
return stockDao.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据容器编码查询容器信息
|
||||
*
|
||||
* @param stockCode 容器编码
|
||||
* @return StockEntity
|
||||
*/
|
||||
public StockEntity queryByStockCode(String stockCode) {
|
||||
LambdaQueryWrapper<StockEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StockEntity::getStockCode, stockCode);
|
||||
return stockDao.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据容器编码集合查询容器信息
|
||||
*
|
||||
* @param stockCodes 容器料编码集合
|
||||
* @return List<StockEntity>
|
||||
*/
|
||||
public List<StockEntity> queryByItemCodes(List<String> stockCodes) {
|
||||
LambdaQueryWrapper<StockEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(StockEntity::getStockCode, stockCodes);
|
||||
return stockDao.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据容器编码集合查询容器信息
|
||||
*
|
||||
* @param stockCodes 容器编码集合
|
||||
* @return Map<String, StockEntity>
|
||||
*/
|
||||
public Map<String, StockEntity> queryStockListToMap(List<String> stockCodes) {
|
||||
if (CollectionUtils.isEmpty(stockCodes)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<StockEntity> stocks = queryByItemCodes(stockCodes);
|
||||
return stocks.stream()
|
||||
.collect(Collectors.toMap(StockEntity::getStockCode, stock -> stock, (existing, replacement) -> existing));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 容器导出
|
||||
*
|
||||
* @return List<StocksExcelVO>
|
||||
*/
|
||||
public List<StocksExcelVO> getStocksExcelVOList() {
|
||||
List<StockEntity> stocksList = stockDao.selectList(null);
|
||||
return stocksList.stream()
|
||||
.map(stock ->
|
||||
StocksExcelVO.builder()
|
||||
.stockCode(stock.getStockCode())
|
||||
.stockType(dictCacheService.selectValueNameByValueCode(DictConst.STOCK_TYPE.getValue(), stock.getStockType()))
|
||||
.locationCode(locationManager.queryLocation(stock.getLocationId()) == null ? "" : locationManager.queryLocation(stock.getLocationId()).getLocationCode())
|
||||
.disabledFlag(stock.getDisabledFlag() ? "启用" : "禁用")
|
||||
.build()
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
package net.lab1024.sa.admin.module.business.base.stock.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.idev.excel.FastExcel;
|
||||
import net.lab1024.sa.admin.constant.UsageStatusEnum;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.entity.ItemEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.item.domain.form.ItemsImportForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.dao.StockDao;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.entity.StockEntity;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockAddForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StockUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.domain.form.StocksImportForm;
|
||||
import net.lab1024.sa.admin.module.business.base.stock.manager.StockManager;
|
||||
import net.lab1024.sa.admin.util.JoinerResult;
|
||||
import net.lab1024.sa.admin.util.ResponseDTOUtils;
|
||||
import net.lab1024.sa.admin.util.ValidateDictKey;
|
||||
import net.lab1024.sa.base.common.code.UserErrorCode;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartBeanUtil;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.constant.DictConst;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 容器信息 Service
|
||||
*
|
||||
* @author 霍锦
|
||||
* @since 2024-11-26 11:37:48
|
||||
* copyright 友仓
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class StockService {
|
||||
|
||||
@Resource
|
||||
private StockDao stockDao;
|
||||
|
||||
@Resource
|
||||
private StockManager stockManager;
|
||||
|
||||
@Resource
|
||||
private ValidateDictKey ValidateDictKey;
|
||||
|
||||
@Resource
|
||||
private StockQueryService stockQueryService;
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param addForm 添加参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> add(StockAddForm addForm) {
|
||||
StockEntity existingStock = stockQueryService.queryByStockCode(addForm.getStockCode());
|
||||
if (existingStock != null) {
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, UserErrorCode.ALREADY_EXIST.getMsg());
|
||||
}
|
||||
StockEntity stockEntity = SmartBeanUtil.copy(addForm, StockEntity.class);
|
||||
stockDao.insert(stockEntity);
|
||||
|
||||
//更新缓存
|
||||
stockManager.removeCache();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param updateForm 更新参数
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> update(StockUpdateForm updateForm) {
|
||||
StockEntity existingStock = stockQueryService.queryByStockCode(updateForm.getStockCode());
|
||||
if (existingStock != null && !existingStock.getStockId().equals(updateForm.getStockId())) {
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, UserErrorCode.ALREADY_EXIST.getMsg());
|
||||
}
|
||||
StockEntity stockEntity = SmartBeanUtil.copy(updateForm, StockEntity.class);
|
||||
stockDao.updateById(stockEntity);
|
||||
|
||||
//更新缓存
|
||||
stockManager.removeCache();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param idList id集合
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
}
|
||||
|
||||
//批量删除
|
||||
stockManager.removeBatchByIds(idList);
|
||||
|
||||
//更新缓存
|
||||
stockManager.removeCache();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*
|
||||
* @param stockId 容器Id
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
public ResponseDTO<String> delete(Long stockId) {
|
||||
if (null == stockId) {
|
||||
return ResponseDTO.userErrorParam(UserErrorCode.PARAM_ERROR.getMsg());
|
||||
}
|
||||
|
||||
stockDao.deleteById(stockId);
|
||||
|
||||
//更新缓存
|
||||
stockManager.removeCache();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 容器导入
|
||||
*
|
||||
* @param file 上传文件
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> importStocks(MultipartFile file) {
|
||||
List<StocksImportForm> dataList;
|
||||
try {
|
||||
dataList = FastExcel.read(file.getInputStream()).head(StocksImportForm.class)
|
||||
.sheet()
|
||||
.doReadSync();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("数据格式存在问题,无法读取");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(dataList)) {
|
||||
return ResponseDTO.userErrorParam("数据为空");
|
||||
}
|
||||
|
||||
//获取所有去重后的容器类型
|
||||
List<String> stockTypes = dataList.stream().map(StocksImportForm::getStockType).distinct().collect(Collectors.toList());
|
||||
|
||||
//验证容器类型
|
||||
Map<String, String> itemTypeMap = ValidateDictKey.validateDictCodes(stockTypes, DictConst.STOCK_TYPE.getValue());
|
||||
|
||||
//获取所有去重后的容器编码
|
||||
List<String> stockCodes = dataList.stream().map(StocksImportForm::getStockCode).distinct().collect(Collectors.toList());
|
||||
|
||||
//查询数据库存在的容器
|
||||
Map<String, StockEntity> exitStockMap = stockQueryService.queryStockListToMap(stockCodes);
|
||||
|
||||
List<StockEntity> insertToStock = new ArrayList<>();
|
||||
List<StockEntity> updateToStock = new ArrayList<>();
|
||||
for (StocksImportForm stocksImportForm : dataList) {
|
||||
|
||||
//容器类型
|
||||
String stockType = itemTypeMap.get(stocksImportForm.getStockType());
|
||||
|
||||
//容器
|
||||
StockEntity stock = exitStockMap.get(stocksImportForm.getStockCode());
|
||||
|
||||
//容器为空新增,否则更新
|
||||
if (stock == null) {
|
||||
insertToStock.add(createStock(stocksImportForm.getStockCode(), stockType));
|
||||
} else {
|
||||
updateToStock.add(createStock(stocksImportForm.getStockCode(), stockType));
|
||||
}
|
||||
}
|
||||
|
||||
JoinerResult resultMsg = JoinerResult.createJoiner();
|
||||
return ResponseDTOUtils.buildResponseSussDTO(insertToStock, updateToStock, stockManager::saveBatch, stockManager::updateBatchById, resultMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建容器
|
||||
*
|
||||
* @param stockCode 容器编码
|
||||
* @param stockType 容器类型
|
||||
* @return StockEntity
|
||||
*/
|
||||
public StockEntity createStock(String stockCode, String stockType) {
|
||||
return StockEntity.builder()
|
||||
.stockCode(stockCode)
|
||||
.stockType(stockType)
|
||||
.status(UsageStatusEnum.FREE.getValue())
|
||||
.disabledFlag(true)
|
||||
.createUserId(SmartRequestUtil.getRequestUser().getUserId())
|
||||
.createUserName(SmartRequestUtil.getRequestUser().getUserName())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# 默认是按前端工程文件的 /views/business 文件夹的路径作为前端组件路径,如果你没把生成的 .vue 前端代码放在 /views/business 下,
|
||||
# 那就根据自己实际情况修改下面 SQL 的 path,component 字段值,避免执行 SQL 后菜单无法访问。
|
||||
# 如果你一切都是按照默认,那么下面的 SQL 基本不用改
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, path, component, frame_flag, cache_flag, visible_flag, disabled_flag, perms_type, create_user_id )
|
||||
VALUES ( '容器信息', 2, 0, '/stock/list', '/business/stock/stock-list.vue', false, false, true, false, 1, 1 );
|
||||
|
||||
# 按菜单名称查询该菜单的 menu_id 作为按钮权限的 父菜单ID 与 功能点关联菜单ID
|
||||
SET @parent_id = NULL;
|
||||
SELECT t_menu.menu_id INTO @parent_id FROM t_menu WHERE t_menu.menu_name = '容器信息';
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '查询', 3, @parent_id, false, false, true, false, 'stock:query', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '添加', 3, @parent_id, false, false, true, false, 'stock:add', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '更新', 3, @parent_id, false, false, true, false, 'stock:update', 1, @parent_id, 1 );
|
||||
|
||||
INSERT INTO t_menu ( menu_name, menu_type, parent_id, frame_flag, cache_flag, visible_flag, disabled_flag, api_perms, perms_type, context_menu_id, create_user_id )
|
||||
VALUES ( '删除', 3, @parent_id, false, false, true, false, 'stock:delete', 1, @parent_id, 1 );
|
||||
|
|
@ -10,8 +10,8 @@ import java.util.StringJoiner;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JoinerResult {
|
||||
StringJoiner sussMsg = null;
|
||||
StringJoiner errorMsg = null;
|
||||
StringJoiner sussMsg;
|
||||
StringJoiner errorMsg;
|
||||
public static JoinerResult createJoiner() {
|
||||
return new JoinerResult(new StringJoiner(","), new StringJoiner(","));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,21 @@ package net.lab1024.sa.admin.util;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ResponseDTOUtils {
|
||||
private ResponseDTOUtils() {
|
||||
// 私有构造函数,防止实例化
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建返回结果
|
||||
* @param joiner Msg信息
|
||||
* @return ResponseDTO<String>
|
||||
*/
|
||||
public static ResponseDTO<String> buildResponseDTO(JoinerResult joiner) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (joiner.getSussMsg() != null) {
|
||||
|
|
@ -20,7 +26,40 @@ public class ResponseDTOUtils {
|
|||
if (joiner.getErrorMsg() != null) {
|
||||
jsonObject.put("error", joiner.getErrorMsg().toString());
|
||||
}
|
||||
return ResponseDTO.ok(jsonObject.toString());
|
||||
return ResponseDTO.okMsg(jsonObject.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建返回结果
|
||||
* @param insertList 新增集合对象
|
||||
* @param updateList 更新集合对象
|
||||
* @param saveBatchFunction 批量新增函数
|
||||
* @param updateBatchFunction 批量更新函数
|
||||
* @param joiner Msg信息
|
||||
*/
|
||||
public static <T> ResponseDTO<String> buildResponseSussDTO(
|
||||
List<T> insertList,
|
||||
List<T> updateList,
|
||||
Consumer<List<T>> saveBatchFunction,
|
||||
Consumer<List<T>> updateBatchFunction,
|
||||
JoinerResult joiner
|
||||
) {
|
||||
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
saveBatchFunction.accept(insertList);
|
||||
String msg = String.format("新增%s条", insertList.size());
|
||||
joiner.getSussMsg().add(msg);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(updateList)) {
|
||||
updateBatchFunction.accept(updateList);
|
||||
String msg = String.format("更新%s条", updateList.size());
|
||||
joiner.getSussMsg().add(msg);
|
||||
}
|
||||
|
||||
return buildResponseDTO(joiner);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package net.lab1024.sa.admin.util;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartStringUtil;
|
||||
import net.lab1024.sa.base.module.support.dict.domain.vo.DictValueVO;
|
||||
import net.lab1024.sa.base.module.support.dict.service.DictCacheService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ValidateDictKey {
|
||||
|
||||
@Resource
|
||||
public DictCacheService dictCacheService;
|
||||
|
||||
public Map<String, String> validateDictCodes(List<String> dictCodes, String dictCode) {
|
||||
//通过字典编号查询数据库已存在的类型
|
||||
List<DictValueVO> selectByKeyCode = dictCacheService.selectByKeyCode(dictCode);
|
||||
if (CollectionUtils.isEmpty(selectByKeyCode)) {
|
||||
throw new BusinessException("字典中" + dictCode + "参数错误");
|
||||
}
|
||||
|
||||
//获取字典集合中的valueName集合
|
||||
List<String> exitDictCodes = selectByKeyCode.stream().map(DictValueVO::getValueName).distinct().collect(Collectors.toList());
|
||||
|
||||
//获取两个集合的非交集说明库区不存在;提示错误
|
||||
List<String> diff = SmartStringUtil.getDifference(dictCodes, exitDictCodes);
|
||||
if (CollectionUtils.isNotEmpty(diff)) {
|
||||
throw new BusinessException(diff + "不存在,请在数据字典中维护");
|
||||
}
|
||||
|
||||
return selectByKeyCode.stream()
|
||||
.collect(Collectors.toMap(DictValueVO::getValueName, DictValueVO::getValueCode));
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
AND t_area.disabled_flag=#{queryForm.disabledFlag}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t_area.area_code
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@
|
|||
|
||||
<!-- 查询结果列 -->
|
||||
<sql id="base_columns">
|
||||
t_item
|
||||
.
|
||||
item_id
|
||||
,
|
||||
t_item. item_id,
|
||||
t_item.item_code,
|
||||
t_item.item_name,
|
||||
t_item.unit,
|
||||
|
|
@ -36,6 +33,7 @@
|
|||
AND t_item.disabled_flag=#{queryForm.disabledFlag}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t_item.item_code
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
AND t_location.disabled_flag=#{queryForm.disabledFlag}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t_location.location_code
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?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="net.lab1024.sa.admin.module.business.base.stock.dao.StockDao">
|
||||
|
||||
<!-- 查询结果列 -->
|
||||
<sql id="base_columns">
|
||||
t_stock.stock_id,
|
||||
t_stock.stock_code,
|
||||
t_stock.location_id,
|
||||
t_stock.status,
|
||||
t_stock.disabled_flag,
|
||||
t_stock.stock_type,
|
||||
t_stock.remark,
|
||||
t_stock.create_user_id,
|
||||
t_stock.create_user_name,
|
||||
t_stock.create_time,
|
||||
t_stock.update_time
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="queryPage" resultType="net.lab1024.sa.admin.module.business.base.stock.domain.vo.StockVO">
|
||||
SELECT
|
||||
<include refid="base_columns"/>
|
||||
FROM t_stock
|
||||
<where>
|
||||
<!--容器编码-->
|
||||
<if test="queryForm.stockCode != null and queryForm.stockCode != ''">
|
||||
AND INSTR(t_stock.stock_code,#{queryForm.stockCode})
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t_stock.stock_code
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -7,32 +7,24 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public class AdminApplicationTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> locationCodes = new ArrayList<>();
|
||||
locationCodes.add("A");
|
||||
locationCodes.add("B");
|
||||
locationCodes.add("C");
|
||||
String locationCode = "CSQ01-";
|
||||
int firstDashIndex = locationCode.indexOf('-');
|
||||
|
||||
List<String> existingLocationCodes = new ArrayList<>();
|
||||
existingLocationCodes.add("B");
|
||||
String[] parts = locationCode.substring(firstDashIndex + 1).split("-");
|
||||
System.out.println(parts.length);
|
||||
String row = parts[0];
|
||||
String col = parts[1];
|
||||
String layer = parts[2];
|
||||
|
||||
// 获取交集
|
||||
List<String> intersection = SmartStringUtil.getIntersection(locationCodes, existingLocationCodes);
|
||||
// 获取非交集
|
||||
List<String> difference = SmartStringUtil.getDifference(locationCodes, existingLocationCodes);
|
||||
|
||||
// 输出交集
|
||||
System.out.println("交集: " + intersection);
|
||||
// 输出非交集
|
||||
System.out.println("非交集: " + difference);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ import lombok.Getter;
|
|||
@AllArgsConstructor
|
||||
public enum UserErrorCode implements ErrorCode {
|
||||
|
||||
BAD_ERROR(30013, "通用提示错误"),
|
||||
|
||||
PARAM_ERROR(30001, "参数错误"),
|
||||
|
||||
DATA_NOT_EXIST(30002, "左翻右翻,数据竟然找不到了~"),
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import cn.idev.excel.FastExcel;
|
|||
import cn.idev.excel.write.handler.SheetWriteHandler;
|
||||
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import cn.idev.excel.write.metadata.holder.WriteWorkbookHolder;
|
||||
import cn.idev.excel.write.metadata.style.WriteCellStyle;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFPictureData;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRelation;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
|
|
@ -18,14 +20,16 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* excel 工具类
|
||||
*
|
||||
* @Author 1024创新实验室-主任:卓大
|
||||
|
|
@ -39,7 +43,7 @@ public final class SmartExcelUtil {
|
|||
/**
|
||||
* 通用单sheet导出
|
||||
*/
|
||||
public static void exportExcel(HttpServletResponse response, String fileName, String sheetName, Class head,Collection<?> data) throws IOException {
|
||||
public static void exportExcel(HttpServletResponse response, String fileName, String sheetName, Class head, Collection<?> data) throws IOException {
|
||||
// 设置下载消息头
|
||||
SmartResponseUtil.setDownloadFileHeader(response, fileName, null);
|
||||
// 下载
|
||||
|
|
@ -52,7 +56,7 @@ public final class SmartExcelUtil {
|
|||
/**
|
||||
* 通用单 sheet水印 导出
|
||||
*/
|
||||
public static void exportExcelWithWatermark(HttpServletResponse response, String fileName, String sheetName, Class head,Collection<?> data, String watermarkString) throws IOException {
|
||||
public static void exportExcelWithWatermark(HttpServletResponse response, String fileName, String sheetName, Class head, Collection<?> data, String watermarkString) throws IOException {
|
||||
// 设置下载消息头
|
||||
SmartResponseUtil.setDownloadFileHeader(response, fileName, null);
|
||||
// 水印
|
||||
|
|
@ -181,7 +185,7 @@ public final class SmartExcelUtil {
|
|||
/**
|
||||
* 画笔颜色
|
||||
*/
|
||||
private Color color = new Color(239,239,239);
|
||||
private Color color = new Color(239, 239, 239);
|
||||
|
||||
/**
|
||||
* 字体样式
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package net.lab1024.sa.base.common.util;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 独有的字符串工具类
|
||||
|
|
@ -12,7 +13,7 @@ import java.util.*;
|
|||
* @Date 2021-09-02 20:21:10
|
||||
* @Wechat zhuoda1024
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
public class SmartStringUtil extends StrUtil {
|
||||
|
||||
|
|
@ -324,54 +325,30 @@ public class SmartStringUtil extends StrUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取两个列表的交集
|
||||
* 获取两个列表的相同的元素
|
||||
*
|
||||
* @param list1 第一个列表
|
||||
* @param list2 第二个列表
|
||||
* @return 交集列表
|
||||
* @return 相同元素
|
||||
*/
|
||||
public static List<String> getIntersection(List<String> list1, List<String> list2) {
|
||||
// 将 list2 转换为 HashSet,以便快速查找
|
||||
Set<String> set2 = new HashSet<>(list2);
|
||||
// 存储交集的列表
|
||||
List<String> intersection = new ArrayList<>();
|
||||
|
||||
// 遍历 list1
|
||||
for (String element : list1) {
|
||||
if (set2.contains(element)) {
|
||||
// 如果元素存在于 set2 中,则为交集元素
|
||||
intersection.add(element);
|
||||
}
|
||||
}
|
||||
return intersection;
|
||||
return list1.stream()
|
||||
.filter(list2::contains)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个列表的非交集
|
||||
* 找到 list1 中存在但 list2 中不存在的元素
|
||||
*
|
||||
* @param list1 第一个列表
|
||||
* @param list2 第二个列表
|
||||
* @return 非交集列表
|
||||
* @return 不同
|
||||
*/
|
||||
public static List<String> getDifference(List<String> list1, List<String> list2) {
|
||||
// 将 list2 转换为 HashSet,以便快速查找
|
||||
Set<String> set2 = new HashSet<>(list2);
|
||||
// 存储非交集的列表
|
||||
List<String> difference = new ArrayList<>();
|
||||
|
||||
// 遍历 list1,将不在 list2 中的元素添加到非交集中
|
||||
for (String element : list1) {
|
||||
if (!set2.contains(element)) {
|
||||
difference.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// 将 list2 中不在 list1 中的元素添加到非交集中
|
||||
Set<String> set1 = new HashSet<>(list1);
|
||||
for (String element : list2) {
|
||||
if (!set1.contains(element)) {
|
||||
difference.add(element);
|
||||
}
|
||||
}
|
||||
return difference;
|
||||
Set<String> existingLocationCodesSet = new HashSet<>(list2);
|
||||
return list1.stream()
|
||||
.filter(code -> !existingLocationCodesSet.contains(code))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package net.lab1024.sa.base.module.support.dict.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum DictConst {
|
||||
/**
|
||||
* 物料类型
|
||||
*/
|
||||
ITEM_TYPE("ITEM_TYPE", "物料类型"),
|
||||
|
||||
/**
|
||||
* 包装单位
|
||||
*/
|
||||
ITEM_UNIT("ITEM_UNIT", "包装单位"),
|
||||
|
||||
/**
|
||||
* 容器类型
|
||||
*/
|
||||
STOCK_TYPE("STOCK_TYPE", "容器类型"),
|
||||
|
||||
|
||||
/**
|
||||
* 库位类型
|
||||
*/
|
||||
LOC_TYPE("LOC_TYPE", "库位类型");
|
||||
|
||||
private final String value;
|
||||
|
||||
private final String desc;
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ public class DictCacheService {
|
|||
return null;
|
||||
}
|
||||
|
||||
List<DictValueVO> dictValueVOList = DICT_CACHE.get(valueCode);
|
||||
List<DictValueVO> dictValueVOList = DICT_CACHE.get(keyCode);
|
||||
if (CollectionUtils.isEmpty(dictValueVOList)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue