Commit 74ba29c1 by pfh

custom仓库rest接口添加

parent a9dc8dcd
...@@ -6,9 +6,12 @@ import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO; ...@@ -6,9 +6,12 @@ import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO; import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoSnakeVO; import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoSnakeVO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoVO; import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoVO;
import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* 仓库管理 App Service 接口 * 仓库管理 App Service 接口
...@@ -53,4 +56,16 @@ public interface CustomWarehouseInfoService { ...@@ -53,4 +56,16 @@ public interface CustomWarehouseInfoService {
* @param ids 仓库 ID,逗号分隔 * @param ids 仓库 ID,逗号分隔
*/ */
void remove(String ids); void remove(String ids);
List<CustomWarehouseInfoVO> getOnlineWarehouse(String namespace);
List<CustomWarehouseInfoVO> allStatusList();
Set<String> checkGoodsBelongWarehouse(Map<String, Long> param);
Set<String> checkGoodsDirectBelongWarehouse(Map<String, Long> param);
CustomWarehouseInfoVO selectCustomWarehouseInfoById(Long id);
List<CustomWarehouseInfoVO> getByIds(Collection<Long> ids);
} }
...@@ -2,6 +2,7 @@ package com.jomalls.custom.app.service.warehouse.impl; ...@@ -2,6 +2,7 @@ package com.jomalls.custom.app.service.warehouse.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO; import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO; import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO;
...@@ -17,11 +18,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -17,11 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -93,4 +90,106 @@ public class CustomWarehouseInfoServiceImpl implements CustomWarehouseInfoServic ...@@ -93,4 +90,106 @@ public class CustomWarehouseInfoServiceImpl implements CustomWarehouseInfoServic
customWarehouseInfoDomainService.removeByIds(idList); customWarehouseInfoDomainService.removeByIds(idList);
log.info("批量删除仓库成功: ids={}", ids); log.info("批量删除仓库成功: ids={}", ids);
} }
@Override
public List<CustomWarehouseInfoVO> getOnlineWarehouse(String namespace){
LambdaQueryWrapper<CustomWarehouseInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CustomWarehouseInfoEntity::getStatus, CustomWarehouseEnums.ONLINE.status);
if (!"demo".equals(namespace)){
queryWrapper.eq(CustomWarehouseInfoEntity::getFormal,true);
}
List<CustomWarehouseInfoEntity> list = customWarehouseInfoDomainService.list(queryWrapper);
List<CustomWarehouseInfoVO> customWarehouseInfoVOS = BeanMapper.snakeCase().convertList(list, CustomWarehouseInfoVO.class);
return customWarehouseInfoVOS;
}
@Override
public List<CustomWarehouseInfoVO> allStatusList(){
List<CustomWarehouseInfoEntity> list = customWarehouseInfoDomainService.list();
List<CustomWarehouseInfoVO> customWarehouseInfoVOS = BeanMapper.snakeCase().convertList(list, CustomWarehouseInfoVO.class);
return customWarehouseInfoVOS;
}
@Override
public Set<String> checkGoodsBelongWarehouse(Map<String, Long> param) {
Map<String, Set<Long>> productWarehouseMap = this.getProductBelongWarehouse(param.keySet());
Set<String> res = new HashSet<>();
for (String key : param.keySet()) {
Set<Long> set = productWarehouseMap.get(key);
if (set == null || !set.contains(param.get(key))){
res.add(key);
}
}
return res;
}
@Override
public Set<String> checkGoodsDirectBelongWarehouse(Map<String, Long> param) {
Map<String, Set<Long>> productWarehouseMap = this.getProductDirectBelongWarehouse(param.keySet());
Set<String> res = new HashSet<>();
for (String key : param.keySet()) {
Set<Long> set = productWarehouseMap.get(key);
if (set == null || !set.contains(param.get(key))){
res.add(key);
}
}
return res;
}
/**
* 获取产品直接归属仓库<sku,warehouseId>
* @param param
* @return
*/
public Map<String, Set<Long>> getProductBelongWarehouse(Collection<String> param){
Map<String, Set<Long>> res = new HashMap<>();
List<Map<String, Object>> list = customWarehouseInfoDomainService.getProductBelongWarehouse(param);
if (CollectionUtils.isNotEmpty(list)){
for (Map<String, Object> item : list){
String sku = (String) item.get("sku");
Long warehouseId = (Long) item.get("warehouseId");
Set<Long> temp = res.computeIfAbsent(sku, k -> new HashSet<>());
if(warehouseId != null){
temp.add(warehouseId);
}
}
}
return res;
}
/**
* 获取产品直接归属仓库<sku,warehouseId>
* @param param
* @return
*/
public Map<String, Set<Long>> getProductDirectBelongWarehouse(Collection<String> param){
Map<String, Set<Long>> res = new HashMap<>();
List<Map<String, Object>> list = customWarehouseInfoDomainService.getProductDirectBelongWarehouse(param);
if (CollectionUtils.isNotEmpty(list)){
for (Map<String, Object> item : list){
String sku = (String) item.get("sku");
Long warehouseId = (Long) item.get("warehouseId");
Set<Long> temp = res.computeIfAbsent(sku, k -> new HashSet<>());
if(warehouseId != null){
temp.add(warehouseId);
}
}
}
return res;
}
@Override
public CustomWarehouseInfoVO selectCustomWarehouseInfoById(Long id) {
CustomWarehouseInfoEntity byId = customWarehouseInfoDomainService.getById(id);
CustomWarehouseInfoVO convert = BeanMapper.snakeCase().convert(byId, CustomWarehouseInfoVO.class);
return convert;
}
@Override
public List<CustomWarehouseInfoVO> getByIds(Collection<Long> ids) {
LambdaQueryWrapper<CustomWarehouseInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(CustomWarehouseInfoEntity::getId, ids);
List<CustomWarehouseInfoEntity> list = customWarehouseInfoDomainService.list(queryWrapper);
List<CustomWarehouseInfoVO> customWarehouseInfoVOS = BeanMapper.snakeCase().convertList(list, CustomWarehouseInfoVO.class);
return customWarehouseInfoVOS;
}
} }
...@@ -4,6 +4,10 @@ import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity; ...@@ -4,6 +4,10 @@ import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity;
import com.jomalls.custom.mapper.BaseMapper; import com.jomalls.custom.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* @author Lizh * @author Lizh
* @version 0.01 * @version 0.01
...@@ -12,4 +16,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -12,4 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface CustomWarehouseInfoMapper extends BaseMapper<CustomWarehouseInfoEntity> { public interface CustomWarehouseInfoMapper extends BaseMapper<CustomWarehouseInfoEntity> {
List<Map<String, Object>> getProductDirectBelongWarehouse(Collection<String> param);
List<Map<String, Object>> getProductBelongWarehouse(Collection<String> param);
} }
...@@ -3,6 +3,10 @@ package com.jomalls.custom.domain.service.warehouse; ...@@ -3,6 +3,10 @@ package com.jomalls.custom.domain.service.warehouse;
import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity; import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity;
import com.jomalls.custom.service.IBaseService; import com.jomalls.custom.service.IBaseService;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* @author Lizh * @author Lizh
* @version 0.01 * @version 0.01
...@@ -11,5 +15,8 @@ import com.jomalls.custom.service.IBaseService; ...@@ -11,5 +15,8 @@ import com.jomalls.custom.service.IBaseService;
*/ */
public interface CustomWarehouseInfoDomainService extends IBaseService<CustomWarehouseInfoEntity> { public interface CustomWarehouseInfoDomainService extends IBaseService<CustomWarehouseInfoEntity> {
List<Map<String, Object>> getProductDirectBelongWarehouse(Collection<String> param);
List<Map<String, Object>> getProductBelongWarehouse(Collection<String> param);
} }
...@@ -8,6 +8,10 @@ import org.apache.ibatis.session.SqlSessionFactory; ...@@ -8,6 +8,10 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* @author Lizh * @author Lizh
...@@ -22,6 +26,19 @@ public class CustomWarehouseInfoDomainServiceImpl extends BaseServiceImpl<Custom ...@@ -22,6 +26,19 @@ public class CustomWarehouseInfoDomainServiceImpl extends BaseServiceImpl<Custom
public CustomWarehouseInfoDomainServiceImpl(SqlSessionFactory sqlSessionFactory) { public CustomWarehouseInfoDomainServiceImpl(SqlSessionFactory sqlSessionFactory) {
super(sqlSessionFactory); super(sqlSessionFactory);
} }
// 自定义方法或者基础方法重写
@Override
public List<Map<String, Object>> getProductDirectBelongWarehouse(Collection<String> param) {
return baseMapper.getProductDirectBelongWarehouse(param);
}
@Override
public List<Map<String, Object>> getProductBelongWarehouse(Collection<String> param) {
return baseMapper.getProductBelongWarehouse(param);
}
} }
\ No newline at end of file
...@@ -87,4 +87,31 @@ ...@@ -87,4 +87,31 @@
(#{item.warehouseName}, #{item.warehouseCode}, #{item.overallLogistics}, #{item.superFactory}, #{item.systemLogistics}, #{item.overallLogisticsScope}, #{item.contactName}, #{item.contactPhone}, #{item.contactEmail}, #{item.countryCode}, #{item.countryName}, #{item.province}, #{item.provinceCode}, #{item.provinceAbb}, #{item.city}, #{item.cityCode}, #{item.district}, #{item.street}, #{item.postcode}, #{item.companyName}, #{item.socialCreditCode}, #{item.remarks}, #{item.updateTime}, #{item.createTime}, #{item.status}, #{item.contactNameCn}, #{item.countryNameCn}, #{item.provinceCn}, #{item.cityCn}, #{item.districtCn}, #{item.streetCn}, #{item.formal}, #{item.settlementCurrency}, #{item.companyNameCn}) (#{item.warehouseName}, #{item.warehouseCode}, #{item.overallLogistics}, #{item.superFactory}, #{item.systemLogistics}, #{item.overallLogisticsScope}, #{item.contactName}, #{item.contactPhone}, #{item.contactEmail}, #{item.countryCode}, #{item.countryName}, #{item.province}, #{item.provinceCode}, #{item.provinceAbb}, #{item.city}, #{item.cityCode}, #{item.district}, #{item.street}, #{item.postcode}, #{item.companyName}, #{item.socialCreditCode}, #{item.remarks}, #{item.updateTime}, #{item.createTime}, #{item.status}, #{item.contactNameCn}, #{item.countryNameCn}, #{item.provinceCn}, #{item.cityCn}, #{item.districtCn}, #{item.streetCn}, #{item.formal}, #{item.settlementCurrency}, #{item.companyNameCn})
</foreach> </foreach>
</insert> </insert>
<select id="getProductDirectBelongWarehouse" resultType="java.util.Map">
select info.sku sku,warehouse.id warehouseId
from custom_product_info info
left join custom_product_warehouse_rel rel on info.id = rel.product_id
left join custom_warehouse_info warehouse on rel.warehouse_id = warehouse.id
<where>
info.sku in
<foreach collection="param" index="index" separator="," close=")" open="(" item="item">
#{item}
</foreach>
</where>
</select>
<select id="getProductBelongWarehouse" resultType="java.util.HashMap">
select distinct info.sku sku,warehouse.id warehouseId
from custom_product_info info
left join custom_product_factory_price_rel rel on info.id = rel.product_id
left join db_factory factory on rel.factory_id = factory.id
left join custom_warehouse_info warehouse on factory.id = warehouse.super_factory
<where>
info.sku in
<foreach collection="param" index="index" separator="," close=")" open="(" item="item">
#{item}
</foreach>
</where>
</select>
</mapper> </mapper>
package com.jomalls.custom.webapp.controller.rest;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.jomalls.custom.app.service.warehouse.CustomWarehouseInfoService;
import com.jomalls.custom.app.utils.IdUtils;
import com.jomalls.custom.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import static com.jomalls.custom.utils.AjaxResult.success;
/**
* custom仓库信息提供的rest接口
*/
@RestController
@RequestMapping("api/v2/rest/customWarehouse")
public class CustomWarehouseInfoRestController{
@Autowired
private CustomWarehouseInfoService customWarehouseInfoService;
@Operation(summary = "查询已上线仓库")
@GetMapping("/all")
public AjaxResult all(@RequestParam(required = true,value = "namespace")String namespace) {
return AjaxResult.success(customWarehouseInfoService.getOnlineWarehouse(namespace));
}
@Operation(summary = "查询所有状态的仓库")
@GetMapping("/allStatus")
public AjaxResult allStatus() {
return AjaxResult.success(customWarehouseInfoService.allStatusList());
}
@Operation(summary = "校验商品是否属于对应仓库(商品-工厂-仓库)")
@PostMapping("/checkGoodsBelongWarehouse")
public AjaxResult checkGoodsBelongWarehouse(@RequestBody Map<String, Long> param) {
return AjaxResult.success(customWarehouseInfoService.checkGoodsBelongWarehouse(param));
}
@Operation(summary = "校验商品直接属于仓库(商品-仓库)")
@PostMapping("/checkGoodsDirectBelongWarehouse")
public AjaxResult checkGoodsDirectBelongWarehouse(@RequestBody Map<String, Long> param) {
return AjaxResult.success(customWarehouseInfoService.checkGoodsDirectBelongWarehouse(param));
}
@Operation(summary = "根据ID获取仓库信息")
@GetMapping("/getById")
public AjaxResult getById(@RequestParam Long id) {
return AjaxResult.success(customWarehouseInfoService.selectCustomWarehouseInfoById(id));
}
@Operation(summary = "根据IDS获取仓库信息")
@GetMapping("/getByIds")
public AjaxResult getByIds(@RequestParam("ids") String ids) {
if (StringUtils.isBlank(ids)){
return AjaxResult.error("参数错误");
}
List<Long> idList = IdUtils.idsConvertToLongList(ids);
if (CollectionUtils.isEmpty(idList)){
return AjaxResult.error("参数错误");
}
return success(customWarehouseInfoService.getByIds(idList));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment