@ -24,7 +24,7 @@ import java.io.IOException;
import java.math.BigDecimal ;
import java.nio.charset.StandardCharsets ;
import java.util.* ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.* ;
/ * *
* @author Dreamchaser
@ -108,7 +108,12 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
// 获取当前填写的生产日期
Long producedDate = Long . valueOf ( 0 ) ;
if ( map . containsKey ( "producedDate" ) ) {
producedDate = DateUtil . DateTimeByMonthToTimeStamp ( map . get ( "producedDate" ) . toString ( ) ) ;
Object s = map . get ( "producedDate" ) ;
if ( s = = null | | "" . equals ( s . toString ( ) ) ) {
producedDate = Long . valueOf ( 0 ) ;
} else {
producedDate = DateUtil . DateTimeByMonthToTimeStamp ( s . toString ( ) ) ;
}
}
Map < String , Object > param = new HashMap < > ( ) ;
param . put ( "depositoryId" , depositoryId ) ;
@ -227,13 +232,70 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
* @return
* /
@Override
public Double CalculateAllApplicationInCount ( ) {
List < ApplicationInRecordP > applicationInRecordPAll = depositoryRecordMapper . findApplicationInRecordPAll ( ) ;
Double sum = 0 . 0 ;
for ( int i = 0 ; i < applicationInRecordPAll . size ( ) ; i + + ) {
sum + = ( double ) applicationInRecordPAll . get ( i ) . getQuantity ( ) ;
}
return sum ;
public Map < String , Object > CalculateAllApplicationInCount ( ) {
// 获取当前时间
long now = System . currentTimeMillis ( ) ;
// 获取今天凌晨的时间
Long nowTimeForCalc = DateUtil . getNowTimeForCalc ( ) ;
// 获取昨天时间
Long yesterdayTimeForCalc = DateUtil . getYesterdayTimeForCalc ( ) ;
// 用于查询今天到现在的入库记录
Map < String , Object > mapForToday = new HashMap < > ( ) ;
mapForToday . put ( "start" , nowTimeForCalc ) ;
mapForToday . put ( "end" , now ) ;
// 用于查询昨天的入库记录
Map < String , Object > mapForYesterday = new HashMap < > ( ) ;
mapForYesterday . put ( "start" , yesterdayTimeForCalc ) ;
mapForYesterday . put ( "end" , nowTimeForCalc ) ;
// 查询今天目前为止的入库
List < ApplicationInRecordP > applicationInRecordPForToday = depositoryRecordMapper . findApplicationInRecordPForAPeriodOfTime ( mapForToday ) ;
// 查询昨天的入库
List < ApplicationInRecordP > applicationInRecordPForYesterday = depositoryRecordMapper . findApplicationInRecordPForAPeriodOfTime ( mapForYesterday ) ;
// 今天的入库数量
Integer sumForToday = 0 ;
// 今天的入库额度
Double priceForToday = 0 . 0 ;
// 昨天的入库数量
Integer sumForYesterDay = 0 ;
// 昨天的入库额度
Double priceForYesterDay = 0 . 0 ;
for ( int i = 0 ; i < applicationInRecordPForToday . size ( ) ; i + + ) {
ApplicationInRecordP applicationInRecordP = applicationInRecordPForToday . get ( i ) ;
sumForToday + = applicationInRecordP . getQuantity ( ) ;
priceForToday + = applicationInRecordP . getPrice ( ) * applicationInRecordP . getQuantity ( ) ;
}
for ( int i = 0 ; i < applicationInRecordPForYesterday . size ( ) ; i + + ) {
ApplicationInRecordP applicationInRecordP = applicationInRecordPForYesterday . get ( i ) ;
sumForYesterDay + = applicationInRecordP . getQuantity ( ) ;
priceForYesterDay + = applicationInRecordP . getPrice ( ) * applicationInRecordP . getQuantity ( ) ;
}
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( "total" , sumForToday ) ;
Double ratioForCount = 0 . 0 ;
Double ratioForPrice = 0 . 0 ;
if ( Double . compare ( sumForYesterDay , 0 . 0 ) ! = 0 ) {
ratioForCount = ( ( sumForToday - sumForYesterDay ) / Double . parseDouble ( sumForYesterDay . toString ( ) ) ) ;
}
if ( Double . compare ( priceForYesterDay , 0 . 0 ) ! = 0 ) {
ratioForPrice = ( priceForToday - priceForYesterDay ) / Double . parseDouble ( priceForYesterDay . toString ( ) ) ;
}
BigDecimal bgForSum = new BigDecimal ( ratioForCount ) ;
BigDecimal bgForPrice = new BigDecimal ( ratioForPrice ) ;
ratioForCount = bgForSum . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
ratioForPrice = bgForPrice . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
result . put ( "ratioForSum" , ratioForCount * 100 ) ;
result . put ( "ratioForPrice" , ratioForPrice * 100 ) ;
BigDecimal bgPrice = new BigDecimal ( priceForToday / 100 ) ;
priceForToday = bgPrice . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
result . put ( "price" , priceForToday ) ;
return result ;
}
/ * *
@ -243,26 +305,213 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
* @return
* /
@Override
public Double CalculateAllApplicationOutCount ( String state ) {
List < ApplicationOutRecordP > applicationOutRecordPAll = depositoryRecordMapper . findApplicationOutRecordPAll ( ) ;
Double sum = 0 . 0 ;
public Map < String , Object > CalculateAllApplicationOutCount ( String state ) {
// 获取昨天出库订单
// 获取当前时间
long now = System . currentTimeMillis ( ) ;
// 获取今天凌晨的时间
Long nowTimeForCalc = DateUtil . getNowTimeForCalc ( ) ;
// 获取昨天时间
Long yesterdayTimeForCalc = DateUtil . getYesterdayTimeForCalc ( ) ;
// 用于查询今天到现在的出库记录
Map < String , Object > mapForToday = new HashMap < > ( ) ;
mapForToday . put ( "start" , nowTimeForCalc ) ;
mapForToday . put ( "end" , now ) ;
// 用于查询昨天的出库记录
Map < String , Object > mapForYesterday = new HashMap < > ( ) ;
mapForYesterday . put ( "start" , yesterdayTimeForCalc ) ;
mapForYesterday . put ( "end" , nowTimeForCalc ) ;
// 用于最终的结果
Map < String , Object > result = new HashMap < > ( ) ;
// 获取今天的额度
Double priceForToday = 0 . 0 ;
// 获取今天的总数
Integer countForToday = 0 ;
// 获取昨天的额度
Double priceForYesterday = 0 . 0 ;
// 获取昨天的总数
Integer countForYesterday = 0 ;
if ( state . isEmpty ( ) ) {
// 如果要获取要出库的所有数量
for ( int i = 0 ; i < applicationOutRecordPAll . size ( ) ; i + + ) {
sum + = ( double ) applicationOutRecordPAll . get ( i ) . getQuantity ( ) ;
// 获取今天为止的出库记录
List < ApplicationOutRecordP > applicationOutRecordPForToday = depositoryRecordMapper . findApplicationOutRecordPForAPeriodOfTime ( mapForToday ) ;
// 今天的出库记录数
int todaySize = applicationOutRecordPForToday . size ( ) ;
// 获取昨天的出库记录
List < ApplicationOutRecordP > applicationOutRecordPForYesterday = depositoryRecordMapper . findApplicationOutRecordPForAPeriodOfTime ( mapForYesterday ) ;
// 昨天的出库记录数
int yesterdaySize = applicationOutRecordPForYesterday . size ( ) ;
if ( todaySize > 0 ) {
// 定义线程用于计算今天的记录
ExecutorService exsForToday = Executors . newFixedThreadPool ( todaySize ) ;
// 结果集
List < Future < Object > > futureListForToday = new ArrayList < Future < Object > > ( ) ;
// 1.定义CompletionService
CompletionService < Object > completionServiceForToday = new ExecutorCompletionService < Object > ( exsForToday ) ;
// 开启线程计算今天的额度
for ( int i = 0 ; i < todaySize ; i + + ) {
// 获取当前主记录
ApplicationOutRecordP recordP = applicationOutRecordPForToday . get ( i ) ;
Future < Object > submit = completionServiceForToday . submit ( new CalcApplicationOutInfo ( recordP ) ) ;
futureListForToday . add ( submit ) ;
}
// 获取今天的结果
for ( int i = 0 ; i < todaySize ; i + + ) {
Object o = null ;
try {
o = completionServiceForToday . take ( ) . get ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
} catch ( ExecutionException e ) {
e . printStackTrace ( ) ;
}
countForToday + = ObjectFormatUtil . toInteger ( ( ( Map < String , Object > ) o ) . get ( "count" ) ) ;
priceForToday + = Double . parseDouble ( ( ( Map < String , Object > ) o ) . get ( "price" ) . toString ( ) ) ;
}
}
if ( yesterdaySize > 0 ) {
// 定义线程用于计算昨天的记录
ExecutorService exsForYesterday = Executors . newFixedThreadPool ( yesterdaySize ) ;
// 结果集
List < Future < Object > > futureListForYesterday = new ArrayList < Future < Object > > ( ) ;
// 1.定义CompletionService
CompletionService < Object > completionServiceForYesterday = new ExecutorCompletionService < Object > ( exsForYesterday ) ;
// 开启线程计算昨天的额度
for ( int i = 0 ; i < yesterdaySize ; i + + ) {
ApplicationOutRecordP recordP = applicationOutRecordPForYesterday . get ( i ) ;
Future < Object > submit = completionServiceForYesterday . submit ( new CalcApplicationOutInfo ( recordP ) ) ;
futureListForYesterday . add ( submit ) ;
}
// 获取昨天的结果
for ( int i = 0 ; i < yesterdaySize ; i + + ) {
Object o = null ;
try {
o = completionServiceForYesterday . take ( ) . get ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
} catch ( ExecutionException e ) {
e . printStackTrace ( ) ;
}
countForYesterday + = ObjectFormatUtil . toInteger ( ( ( Map < String , Object > ) o ) . get ( "count" ) ) ;
priceForYesterday + = Double . parseDouble ( ( ( Map < String , Object > ) o ) . get ( "price" ) . toString ( ) ) ;
}
}
// 设置今天的额度
result . put ( "price" , priceForToday ) ;
result . put ( "count" , countForToday ) ;
Double ratioForCount = 0 . 0 ;
Double ratioForPrice = 0 . 0 ;
if ( Double . compare ( countForYesterday , 0 . 0 ) ! = 0 ) {
ratioForCount = ( ( countForToday - countForYesterday ) / Double . parseDouble ( countForYesterday . toString ( ) ) ) ;
}
if ( Double . compare ( priceForYesterday , 0 . 0 ) ! = 0 ) {
ratioForPrice = ( priceForToday - priceForYesterday ) / Double . parseDouble ( priceForYesterday . toString ( ) ) ;
}
BigDecimal bgForSum = new BigDecimal ( ratioForCount ) ;
BigDecimal bgForPrice = new BigDecimal ( ratioForPrice ) ;
ratioForCount = bgForSum . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
ratioForPrice = bgForPrice . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
// 获取数量比值
result . put ( "radioForCount" , ratioForCount * 100 ) ;
// 获取金额比值
result . put ( "radioForPrice" , ratioForPrice * 100 ) ;
} else {
// 如果获取已经出库的数量
List < ApplicationOutRecordMin > applicationOutMinForComplete = depositoryRecordMapper . findApplicationOutMinForComplete ( ) ;
for ( int i = 0 ; i < applicationOutMinForComplete . size ( ) ; i + + ) {
ApplicationOutRecordMin recordMin = applicationOutMinForComplete . get ( i ) ;
sum + = ( double ) recordMin . getQuantity ( ) ;
// 如果获取已经出库的数量(今天)
List < ApplicationOutRecordMin > applicationOutMinForCompleteForToday = depositoryRecordMapper . findApplicationOutMinForComplete ( mapForToday ) ;
// 如果获取已经出库的数量(昨天)
List < ApplicationOutRecordMin > applicationOutMinForCompleteForYesterday = depositoryRecordMapper . findApplicationOutMinForComplete ( mapForYesterday ) ;
for ( int i = 0 ; i < applicationOutMinForCompleteForToday . size ( ) ; i + + ) {
ApplicationOutRecordMin recordMin = applicationOutMinForCompleteForToday . get ( i ) ;
countForToday + = recordMin . getQuantity ( ) ;
// 获取当前出库物料
Material materialById = materialMapper . findMaterialById ( recordMin . getMid ( ) ) ;
// 计算当前出库金额
double price_out = materialById . getPrice ( ) * recordMin . getQuantity ( ) ;
BigDecimal bg = new BigDecimal ( price_out / 100 ) ;
price_out = bg . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
priceForToday + = price_out ;
}
for ( int i = 0 ; i < applicationOutMinForCompleteForYesterday . size ( ) ; i + + ) {
ApplicationOutRecordMin recordMin = applicationOutMinForCompleteForYesterday . get ( i ) ;
countForYesterday + = recordMin . getQuantity ( ) ;
// 获取当前出库物料
Material materialById = materialMapper . findMaterialById ( recordMin . getMid ( ) ) ;
// 计算当前出库金额
double price_out = materialById . getPrice ( ) * recordMin . getQuantity ( ) ;
BigDecimal bg = new BigDecimal ( price_out / 100 ) ;
price_out = bg . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
priceForYesterday + = price_out ;
}
// 设置今天的额度
result . put ( "price" , priceForToday ) ;
result . put ( "count" , countForToday ) ;
Double ratioForCount = 0 . 0 ;
Double ratioForPrice = 0 . 0 ;
if ( Double . compare ( countForYesterday , 0 . 0 ) ! = 0 ) {
ratioForCount = ( ( countForToday - countForYesterday ) / Double . parseDouble ( countForYesterday . toString ( ) ) ) ;
}
if ( Double . compare ( priceForYesterday , 0 . 0 ) ! = 0 ) {
ratioForPrice = ( priceForToday - priceForYesterday ) / Double . parseDouble ( priceForYesterday . toString ( ) ) ;
}
BigDecimal bgForSum = new BigDecimal ( ratioForCount ) ;
BigDecimal bgForPrice = new BigDecimal ( ratioForPrice ) ;
ratioForCount = bgForSum . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
ratioForPrice = bgForPrice . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
// 获取数量比值
result . put ( "radioForCount" , ratioForCount * 100 ) ;
// 获取金额比值
result . put ( "radioForPrice" , ratioForPrice * 100 ) ;
}
return result ;
}
/ * *
* 用于计算当前主记录下的总额与数量
* /
class CalcApplicationOutInfo implements Callable < Object > {
ApplicationOutRecordP mainRecord ;
CalcApplicationOutInfo ( ApplicationOutRecordP mainRecord ) {
this . mainRecord = mainRecord ;
}
@Override
public Object call ( ) throws Exception {
Map < String , Object > result = new HashMap < > ( ) ;
// 获取当前订单的子订单
List < ApplicationOutRecordMin > minList = depositoryRecordMapper . findApplicationOutRecordMinByParent ( mainRecord . getId ( ) ) ;
// 额度
Double price = 0 . 0 ;
// 数量
Integer count = 0 ;
for ( int i = 0 ; i < minList . size ( ) ; i + + ) {
ApplicationOutRecordMin recordMin = minList . get ( i ) ;
count + = recordMin . getQuantity ( ) ;
// 获取当前出库物料
Material materialById = materialMapper . findMaterialById ( recordMin . getMid ( ) ) ;
// 计算当前出库金额
double price_out = materialById . getPrice ( ) * recordMin . getQuantity ( ) ;
BigDecimal bg = new BigDecimal ( price_out / 100 ) ;
price_out = bg . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
price + = price_out ;
}
result . put ( "count" , count ) ;
result . put ( "price" , price ) ;
return result ;
}
return sum ;
}
/ * *
* 将物料入库到库位
*
@ -297,9 +546,15 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
insertProducedDate . put ( "inid" , InId ) ;
insertProducedDate . put ( "mid" , newInMid ) ;
if ( map . containsKey ( "producedDate" ) ) {
Long producedDate = DateUtil . DateTimeByMonthToTimeStamp ( map . get ( "producedDate" ) . toString ( ) ) ;
Long producedDate = Long . valueOf ( 0 ) ;
Object s = map . get ( "producedDate" ) ;
if ( s = = null | | "" . equals ( s . toString ( ) ) ) {
producedDate = Long . valueOf ( 0 ) ;
} else {
producedDate = DateUtil . DateTimeByMonthToTimeStamp ( s . toString ( ) ) ;
insertProducedDate . put ( "producedDate" , producedDate ) ;
}
}
// 查找当前物料id与生产日期的对应关系
MaterialAndProducedDate materialAndProducedDateByMidAndProducedDate = materialMapper . findMaterialAndProducedDateByMidAndProducedDate ( insertProducedDate ) ;
@ -1838,16 +2093,22 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
* @return
* /
@Override
public Double CalculateAllApplicationInPrice ( ) {
public Map < String , Object > CalculateAllApplicationInAll ( ) {
Map < String , Object > result = new HashMap < > ( ) ;
List < ApplicationInRecordP > applicationInRecordPAll = depositoryRecordMapper . findApplicationInRecordPAll ( ) ;
Double sum = 0 . 0 ;
Integer count = 0 ;
for ( int i = 0 ; i < applicationInRecordPAll . size ( ) ; i + + ) {
double price = applicationInRecordPAll . get ( i ) . getPrice ( ) ;
sum + = price * applicationInRecordPAll . get ( i ) . getQuantity ( ) / 100 ;
ApplicationInRecordP applicationInRecordP = applicationInRecordPAll . get ( i ) ;
double price = applicationInRecordP . getPrice ( ) ;
sum + = price * applicationInRecordP . getQuantity ( ) / 100 ;
count + = applicationInRecordP . getQuantity ( ) ;
}
BigDecimal bg = new BigDecimal ( sum ) ;
sum = bg . setScale ( 2 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ;
return sum ;
result . put ( "price" , sum ) ;
result . put ( "count" , count ) ;
return result ;
}
/ * *
@ -1878,7 +2139,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
} else {
// 如果要获取已完成的金额
List < ApplicationOutRecordMin > applicationOutMinForComplete = depositoryRecordMapper . findApplicationOutMinForComplete ( ) ;
List < ApplicationOutRecordMin > applicationOutMinForComplete = depositoryRecordMapper . findApplicationOutMinForComplete ( null ) ;
for ( int i = 0 ; i < applicationOutMinForComplete . size ( ) ; i + + ) {
ApplicationOutRecordMin recordMin = applicationOutMinForComplete . get ( i ) ;
Integer mid = recordMin . getMid ( ) ;