@ -1,5 +1,8 @@
package com.productionboard.service.impl ;
package com.productionboard.service.impl ;
import cn.hutool.http.HttpRequest ;
import cn.hutool.http.HttpResponse ;
import cn.hutool.http.HttpUtil ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
@ -26,123 +29,146 @@ import java.util.stream.Collectors;
@Service
@Service
public class BaseLocationServiceImpl implements IBaseLocationService {
public class BaseLocationServiceImpl implements IBaseLocationService {
@Autowired
@Autowired private BaseLocationInfoMapper lcoationMapper ;
private BaseLocationInfoMapper lcoationMapper ;
@Autowired private RecordTaskMapper recordTaskMapper ;
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
@Override
public String getStoreStatistics ( String ids ) {
String STORE_CODE = "A" ;
QueryWrapper < BaseLocationInfo > wrapper = new QueryWrapper < > ( ) ;
switch ( ids ) {
case "0" :
wrapper . eq ( "STORE_CODE" , "B" ) ;
STORE_CODE = "B" ;
break ;
case "1" :
wrapper . eq ( "STORE_CODE" , "A" ) ;
STORE_CODE = "A" ;
break ;
default :
break ;
}
List < BaseLocationInfo > baseLocationInfos = lcoationMapper . SelectLocationInfo ( STORE_CODE ) ;
List < String > materialType =
baseLocationInfos . stream ( )
. map ( BaseLocationInfo : : getMaterialType )
. distinct ( )
. collect ( Collectors . toList ( ) ) ;
Map < String , List < BaseLocationInfo > > collect =
baseLocationInfos . stream ( )
. collect ( Collectors . groupingBy ( BaseLocationInfo : : getMaterialType ) ) ;
List < JSONObject > result = new ArrayList < > ( ) ;
for ( String item : materialType ) {
JSONObject jsonObject = new JSONObject ( ) ;
jsonObject . put ( "materialName" , item ) ;
jsonObject . put ( "lineStoreAmount" , lcoationMapper . SelectLocationInfoByArea ( STORE_CODE , "1" , item ) . size ( ) ) ;
jsonObject . put ( "hullStoreAmount" , lcoationMapper . SelectLocationInfoByArea ( STORE_CODE , "2" , item ) . size ( ) ) ;
result . add ( jsonObject ) ;
}
String s = JSONArray . toJSONString ( result ) ;
System . out . println ( "物料库存统计:" + s ) ;
return s ;
}
@Override
public String getParamJson ( String ids ) {
@Autowired
String urlStr = "http://10.100.71.119:8012/system/NorthWareHouse/getStoreInfo" ;
private RecordTaskMapper recordTaskMapper ;
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
switch ( ids ) {
case "0" :
urlStr = "http://10.100.71.119:8012/system/NorthWareHouse/getStoreInfo" ;
break ;
case "1" :
urlStr = "http://10.100.71.119:8012/system/SouthWareHouse/getStoreInfo" ;
break ;
default :
break ;
}
String param =
"{\"StartTime\":\"2018-10-10 09:42:02\",\"EndTime\":\"2018-10-29 09:42:02\",\"StartIndex\":\"0\",\"PageSize\":\"30\"}" ;
String response = HttpUtil . post ( urlStr , param ) ;
return response ;
@Override
/ * String [ ] result = new String [ 12 ] ;
public String getStoreStatistics ( String ids ) {
String STORE_CODE = "A" ;
QueryWrapper < BaseLocationInfo > wrapper = new QueryWrapper < > ( ) ;
try {
QueryWrapper < BaseLocationInfo > locationWrapper = new QueryWrapper < BaseLocationInfo > ( ) ;
QueryWrapper < RecordTask > taskWrapper = new QueryWrapper < > ( ) ;
switch ( ids ) {
switch ( ids ) {
case "0" :
case "0" :
wrapper . eq ( "STORE_CODE" , "B" ) ;
locationWrapper . eq ( "STORE_CODE" , "B" ) ;
STORE_CODE = "B" ;
break ;
break ;
case "1" :
case "1" :
wrapper . eq ( "STORE_CODE" , "A" ) ;
locationWrapper . eq ( "STORE_CODE" , "A" ) ;
STORE_CODE = "A" ;
break ;
break ;
default :
default :
break ;
break ;
}
}
List < BaseLocationInfo > baseLocationInfos = lcoationMapper . selectList ( wrapper ) ;
int inAmount1 = recordTaskMapper . SelectRecordTaskByTaskType ( "A" , "1" , "1" ) . size ( ) ;
Map < String , List < BaseLocationInfo > > collect = baseLocationInfos . stream ( ) . collect ( Collectors . groupingBy ( BaseLocationInfo : : getMaterialType ) ) ;
int outAmount1 = recordTaskMapper . SelectRecordTaskByTaskType ( "A" , "1" , "2" ) . size ( ) ;
List < JSONObject > result = new ArrayList < > ( ) ;
//2号库入库数量、出库数量:1入库2出库
int inAmount2 = recordTaskMapper . SelectRecordTaskByTaskType ( "A" , "2" , "1" ) . size ( ) ;
for ( String item : collect . keySet ( ) ) {
int outAmount2 = recordTaskMapper . SelectRecordTaskByTaskType ( "A" , "2" , "2" ) . size ( ) ;
JSONObject jsonObject = new JSONObject ( ) ;
result [ 0 ] = inAmount1 + "" ;
jsonObject . put ( "materialName" , item ) ;
result [ 1 ] = outAmount1 + "" ;
jsonObject . put ( "lineStoreAmount" , collect . get ( item ) . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ) ;
result [ 2 ] = inAmount2 + "" ;
jsonObject . put ( "hullStoreAmount" , collect . get ( item ) . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ) ;
result [ 3 ] = outAmount2 + "" ;
result . add ( jsonObject ) ;
List < BaseLocationInfo > baseLocationInfos = lcoationMapper . selectList ( locationWrapper ) ;
if ( baseLocationInfos . size ( ) > 0 ) {
//正在使用
int inUse = lcoationMapper . SelectInUseLocationInfo ( STORE_CODE ) . size ( ) ;
System . out . println ( "正在使用:" + inUse ) ;
//未使用
int unUse = baseLocationInfos . size ( ) - inUse ;
//1#正在使用
int size1 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int size2 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int inUse1 = lcoationMapper . SelectInUseLocationInfoByArea ( STORE_CODE , "1" ) . size ( ) ;
int inUse2 = lcoationMapper . SelectInUseLocationInfoByArea ( STORE_CODE , "2" ) . size ( ) ;
int unUse1 = size1 - inUse1 ;
int unUse2 = size2 - inUse2 ;
result [ 4 ] = inUse1 + "" ;
result [ 5 ] = unUse1 + "" ;
result [ 6 ] = inUse2 + "" ;
result [ 7 ] = unUse2 + "" ;
result [ 8 ] = unUse + "" ;
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat . getInstance ( ) ;
// 设置精确到小数点后2位
numberFormat . setMaximumFractionDigits ( 2 ) ;
String unUsePercentage = numberFormat . format ( ( float ) unUse / ( float ) baseLocationInfos . size ( ) * 100 ) ;
System . out . println ( "diliverNum和queryMailNum的百分比为:" + result + "%" ) ;
result [ 9 ] = unUsePercentage + "%" ;
result [ 10 ] = inUse + "" ;
String inUsePercentage = numberFormat . format ( ( float ) inUse / ( float ) baseLocationInfos . size ( ) * 100 ) ;
result [ 11 ] = inUsePercentage + "%" ;
}
}
String s = JSONArray . toJSONString ( result ) ;
} catch ( Exception e ) {
System . out . println ( "物料库存统计:" + s ) ;
System . out . println ( "门体库参数统计getParamJson异常: " + e . getMessage ( ) ) ;
return s ;
for ( int i = 0 ; i < 12 ; i + + ) {
//
result [ i ] = i + "" ;
}
}
}
@Override
return JSONArray . toJSONString ( result ) ; * /
public String getParamJson ( String ids ) {
}
String [ ] result = new String [ 12 ] ;
try {
QueryWrapper < BaseLocationInfo > locationWrapper = new QueryWrapper < BaseLocationInfo > ( ) ;
QueryWrapper < RecordTask > taskWrapper = new QueryWrapper < > ( ) ;
switch ( ids ) {
case "0" :
locationWrapper . eq ( "STORE_CODE" , "B" ) ;
taskWrapper . eq ( "STORE_CODE" , "B" ) ;
break ;
case "1" :
locationWrapper . eq ( "STORE_CODE" , "A" ) ;
taskWrapper . eq ( "STORE_CODE" , "A" ) ;
break ;
default :
break ;
}
taskWrapper . like ( "RECORD_TIME" , simpleDateFormat . format ( new Date ( ) ) ) ;
List < RecordTask > recordTasks = recordTaskMapper . selectList ( taskWrapper ) ;
if ( recordTasks . size ( ) > 0 ) {
//1号库入库数量、出库数量:1入库2出库
int inAmount1 = recordTasks . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) & & x . getTaskType ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int outAmount1 = recordTasks . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) & & x . getTaskType ( ) . equals ( "2" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
//2号库入库数量、出库数量:1入库2出库
int inAmount2 = recordTasks . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) & & x . getTaskType ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int outAmount2 = recordTasks . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) & & x . getTaskType ( ) . equals ( "2" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
result [ 0 ] = inAmount1 + "" ;
result [ 1 ] = outAmount1 + "" ;
result [ 2 ] = inAmount2 + "" ;
result [ 3 ] = outAmount2 + "" ;
}
List < BaseLocationInfo > baseLocationInfos = lcoationMapper . selectList ( locationWrapper ) ;
if ( baseLocationInfos . size ( ) > 0 ) {
//正在使用
int inUse = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationStatus ( ) = = 1L ) . collect ( Collectors . toList ( ) ) . size ( ) ;
System . out . println ( "正在使用:" + inUse ) ;
//未使用
int unUse = baseLocationInfos . size ( ) - inUse ;
//1#正在使用
int size1 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int size2 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int inUse1 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "1" ) & & x . getLocationStatus ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int inUse2 = baseLocationInfos . stream ( ) . filter ( x - > x . getLocationArea ( ) . equals ( "2" ) & & x . getLocationStatus ( ) . equals ( "1" ) ) . collect ( Collectors . toList ( ) ) . size ( ) ;
int unUse1 = size1 - inUse1 ;
int unUse2 = size2 - inUse2 ;
result [ 4 ] = inUse1 + "" ;
result [ 5 ] = unUse1 + "" ;
result [ 6 ] = inUse2 + "" ;
result [ 7 ] = unUse2 + "" ;
result [ 8 ] = unUse + "" ;
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat . getInstance ( ) ;
// 设置精确到小数点后2位
numberFormat . setMaximumFractionDigits ( 2 ) ;
String unUsePercentage = numberFormat . format ( ( float ) unUse / ( float ) baseLocationInfos . size ( ) * 100 ) ;
System . out . println ( "diliverNum和queryMailNum的百分比为:" + result + "%" ) ;
result [ 9 ] = unUsePercentage + "%" ;
result [ 10 ] = inUse + "" ;
String inUsePercentage = numberFormat . format ( ( float ) inUse / ( float ) baseLocationInfos . size ( ) * 100 ) ;
result [ 11 ] = inUsePercentage + "%" ;
}
} catch ( Exception e ) {
System . out . println ( "门体库参数统计getParamJson异常: " + e . getMessage ( ) ) ;
for ( int i = 0 ; i < 12 ; i + + ) {
//
result [ i ] = i + "" ;
}
}
return JSONArray . toJSONString ( result ) ;
}
}
}