关于推荐库位 java前端与SQL语句后面的结合

Posted chengjunde

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于推荐库位 java前端与SQL语句后面的结合相关的知识,希望对你有一定的参考价值。

-----------------------------------------------------------------------------------

select a1.id,a1.name,a1.sort,a1.type,a3.value - (a1.nums/a2.nums)*100 as nums,a3.value,a1.nums,a2.nums,a1.packageNum
from (

select swr.id,swr.name,swr.sort,srscm.area_id as type,count(swl.id) as nums,ifnull(sum(swl.package_num),0) packageNum
from sys_warehouse_roadway swr
join sys_warehouse_location swl on swr.id = swl.roadway_id
and swl.status = 1 and swl.delete_status = 0 and swl.package_num > 0
join sys_recommend_store_code_mapping srscm on srscm.area_id = swr.area_id
where swr.status = 1 AND swr.delete_status = 0 and swr.name=‘A10‘
GROUP BY swr.id,swr.name,swr.sort,srscm.area_id
) a1,
(
select swr.id,swr.name,swr.sort,srscm.area_id as type,count(1) as nums
from sys_warehouse_roadway swr
left join sys_warehouse_location swl on swr.id = swl.roadway_id and swl.status = 1 and swl.delete_status = 0
left join sys_recommend_store_code_mapping srscm on srscm.area_id = swr.area_id
where swr.status = 1 AND swr.delete_status = 0 and swr.name=‘A10‘
GROUP BY swr.id,swr.name,swr.sort,srscm.area_id
) a2,
(
select * from sys_key_value skv where skv.key = ‘RecommandStorePercent‘
) a3
where a1.id = a2.id
-- -------------------------------------------------------------------------------------

 

select swr.id,swr.name,swr.sort as type,count(swl.id) as nums,ifnull(sum(swl.package_num),0) packageNum
from sys_warehouse_roadway swr
left join sys_warehouse_location swl on swr.id = swl.roadway_id
and swl.status = 1 and swl.delete_status = 0 and swl.package_num > 0
where swr.status = 1 AND swr.delete_status = 0
GROUP BY swr.id,swr.name,swr.sort


select swr.id,swr.name,swr.sort,count(1) as nums,count(swl.id) as nums2
from sys_warehouse_roadway swr
left join sys_warehouse_location swl on swr.id = swl.roadway_id and swl.status = 1 and swl.delete_status = 0
where swr.status = 1 AND swr.delete_status = 0
GROUP BY swr.id,swr.name,swr.sort



-- --巷道是通过(包裹类型 国家等决定选取那个巷道).
-- --说明:1.首先统计巷道下包裹库存率在80%以下的巷道 (swl.package_num>0 查询此巷道下的有包裹的库位(swl.package_num>0)数/ 此巷道下的总库位数)

---选择库位:(在库位表 根据库位包裹数的升序 查到最少包裹巷道的库位)

select swl.id,swl.name from sys_warehouse_location swl

where swl.roadway_id = #{roadWayId} and swl.status = 1

ORDER BY swl.package_num
LIMIT 1

-------------------------------------------------------------------------在JaVA 里面的写法


// 过滤巷道是否饱和
List<RoadWayInfoRecommendDTO> baoheList = roadWayInfoList.stream().filter(a -> a.getNums() > 0).collect(Collectors.toList());

//记录日志
logDTO.setRequest("a.getNums() > 0,过滤掉已经饱和的巷道");
logDTO.setResponse("过滤已经饱和的巷道" + JSONObject.toJSON(baoheList));
recommendStoreCodeManager.insertRecommendStoreCodeLog(logDTO);

List<RoadWayInfoRecommendDTO> serchList = new ArrayList<>();

if (CollectionUtils.isNotEmpty(baoheList)) {
// 未饱和
ListUtils.sort(baoheList, "nums", true);

ListUtils.sort(baoheList, "sort", true);

serchList = baoheList;
} else {
// 已饱和
ListUtils.sort(roadWayInfoList, "packageNum", true);

serchList = roadWayInfoList;
}

long roadwayId = serchList.get(0).getId();

// 获取开始时间
startTime = System.currentTimeMillis();

LocationInfoRecommendDTO randomLocationInfo = recommendDAO.getRandomLocation(roadwayId, 0);

// 获取结束时间
endTime = System.currentTimeMillis();
runTime = (endTime - startTime) + "ms";
logDTO.setRequest("首单根据巷道获取任意库位查询时间");
logDTO.setResponse(runTime);
recommendStoreCodeManager.insertRecommendStoreCodeLog(logDTO);

if (randomLocationInfo == null) {
message = "根据巷道" + roadwayId + "未获取到任意库位";
logDTO.setRequest("{\"roadwayId\":\"" + roadwayId + "\"}");
logDTO.setResponse(message);
recommendStoreCodeManager.insertRecommendStoreCodeLog(logDTO);

response.setSucess(false);
response.setMessage(message);
response.setRecommendStoreCode("");
return response;
}

//记录日志
logDTO.setRequest("{\"roadwayId\":\"" + roadwayId + "\"}");
logDTO.setResponse("根据巷道,获取库位信息" + JSONObject.toJSON(randomLocationInfo));
recommendStoreCodeManager.insertRecommendStoreCodeLog(logDTO);

response.setSucess(true);
response.setRecommendStoreCode(randomLocationInfo.getName());
response.setMessage("");
return response;

-----------------------------------------------------------------

 





































































以上是关于关于推荐库位 java前端与SQL语句后面的结合的主要内容,如果未能解决你的问题,请参考以下文章

[转帖]关于Java中SQL语句的拼接规则

[mybatis]动态sql_set_与if结合的动态更新

关于if语句后面的花括号

java反射与注解结合使用(根据传入对象输出查询sql)

Slick:如何将 SQL LIKE 语句与 SQL IN 语句结合使用

使用mybatis框架中mapper Mysql Sql语句错误