@ -1,32 +1,29 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi ;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesShippingKanbanCfgService ;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.CustQtyByTimeChartDataModel ;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanCfgModel ;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanModel ;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanViewModel ;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords ;
import cn.estsh.i3plus.mes.pcn.util.DateUtil ;
import cn.estsh.i3plus.platform.common.convert.ConvertBean ;
import cn.estsh.i3plus.platform.common.tool.TimeTool ;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean ;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil ;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack ;
import cn.estsh.i3plus.pojo.mes.bean.MesCustQtyByTime ;
import cn.estsh.i3plus.pojo.mes.bean.MesPartShippingGroup ;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord ;
import cn.estsh.i3plus.pojo.mes.bean.seres.MesCimSeresJisVinOverPoint ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesLoadingListDetail ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingKanbanCfg ;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingKanbanCfgDetail ;
import cn.estsh.i3plus.pojo.mes. bean.shipping.MesShippingOrderManagement ;
import cn.estsh.i3plus.pojo.mes. repository.MesCustQtyByTimeRepository ;
import cn.estsh.i3plus.pojo.mes.repository.MesPartShippingGroupRepository ;
import cn.estsh.i3plus.pojo.mes.repository.MesShippingKanbanCfgDetailRepository ;
import cn.estsh.i3plus.pojo.mes.repository.MesShippingKanbanCfgRepository ;
import cn.estsh.i3plus.pojo.mes.repository.seres.IMesCimSeresJisVinOverPointRepository ;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.LocalDateTimeUtil ;
import cn.hutool.core.util.NumberUtil ;
import cn.hutool.core.util.StrUtil ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.util.CollectionUtils ;
@ -51,6 +48,8 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
@Autowired
private IMesCimSeresJisVinOverPointRepository vinOverPointRDao ;
@Autowired
private MesCustQtyByTimeRepository custQtyByTimeRDao ;
@Autowired
private EntityManager entityManager ;
@Override
@ -113,6 +112,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
oldCfg . setCustStartShift ( cfg . getCustStartShift ( ) ) ;
oldCfg . setInterStartShift ( cfg . getInterStartShift ( ) ) ;
oldCfg . setCustJph ( cfg . getCustJph ( ) ) ;
oldCfg . setCarouselTime ( cfg . getCarouselTime ( ) ) ;
ConvertBean . serviceModelUpdate ( oldCfg , username ) ;
shippingKanbanCfgRDao . update ( oldCfg ) ;
@ -188,7 +188,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
List < String > values = null ;
switch ( index ) {
case CLIENT_STOCK_QTY :
values = getClientStockQty ( cfg , cfgDetail );
values = getClientStockQty ( cfg );
break ;
case WAIT_SHIPPING_QTY :
values = getWaitShippingQty ( cfg , cfgDetail ) ;
@ -244,6 +244,107 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
return model ;
}
/ * *
* 定 时 根 据 发 运 组 获 取 客 户 端 库 存
* @param cfg 发 运 组 配 置 参 数
* @param shippingGroupCode 发 运 组 编 码
* @return 返 回 客 户 端 库 存 数 据
* /
private int getClientStockQtyForJob ( MesShippingKanbanCfg cfg , String shippingGroupCode ) {
if ( StringUtils . isEmpty ( shippingGroupCode ) ) {
return 0 ;
}
// 获取赛力斯上线的最新流水号
String onNumber = "" ;
if ( ! StringUtils . isEmpty ( cfg . getOnlinePoint ( ) ) ) {
StringBuilder onNumberHql = new StringBuilder ( ) ;
onNumberHql . append ( "select max(serialNumber) from " ) . append ( MesCimSeresJisVinOverPoint . class . getName ( ) ) ;
onNumberHql . append ( " where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid " ) ;
onNumberHql . append ( " and overPoint = :overPoint " ) ;
try {
onNumber = entityManager . createQuery ( onNumberHql . toString ( ) , String . class )
. setParameter ( "organizeCode" , cfg . getOrganizeCode ( ) )
. setParameter ( "isValid" , CommonEnumUtil . VALID )
. setParameter ( "isDeleted" , CommonEnumUtil . FALSE )
. setParameter ( "overPoint" , cfg . getOnlinePoint ( ) )
. getSingleResult ( ) ;
} catch ( NoResultException ignored ) {
}
}
if ( StringUtils . isEmpty ( onNumber ) ) {
onNumber = "0" ;
}
List < String > strShippingGroupList = new ArrayList < > ( ) ;
strShippingGroupList . add ( shippingGroupCode ) ;
String offNumber = getMaxOffNumber ( cfg . getOrganizeCode ( ) , strShippingGroupList ) ;
if ( StringUtils . isEmpty ( offNumber ) ) {
offNumber = "0" ;
}
int adjustValue = cfg . getAdjustValue ( ) ! = null ? cfg . getAdjustValue ( ) : 0 ;
return Integer . parseInt ( offNumber ) - Integer . parseInt ( onNumber ) + adjustValue ;
}
@Override
public List < CustQtyByTimeChartDataModel > queryCustQtyByTimeChartData ( String organizeCode , String shippingGroupCode ) {
List < CustQtyByTimeChartDataModel > result = new ArrayList < > ( ) ;
if ( StringUtils . isEmpty ( organizeCode ) | | StringUtils . isEmpty ( shippingGroupCode ) ) {
return result ;
}
for ( String groupCode : shippingGroupCode . split ( "," ) ) {
Date endTime = DateUtil . now ( ) ;
Date startTime = DateUtil . addDays ( endTime , - 1 ) ;
DdlPackBean packBean = DdlPackBean . getDdlPackBean ( organizeCode ) ;
DdlPreparedPack . getStringEqualPack ( groupCode , "shippingGroupCode" , packBean ) ;
DdlPreparedPack . getStringBiggerPack ( DateUtil . formatDate ( startTime ) , "createDatetime" , packBean ) ;
DdlPreparedPack . getStringSmallerPack ( DateUtil . formatDate ( endTime ) , "createDatetime" , packBean ) ;
DdlPreparedPack . getOrderBy ( "createDatetime" , CommonEnumUtil . ASC_OR_DESC . ASC . getValue ( ) , packBean ) ;
List < MesCustQtyByTime > custQtyByTimes = custQtyByTimeRDao . findByHqlWhere ( packBean ) ;
if ( CollectionUtils . isEmpty ( custQtyByTimes ) ) {
continue ;
}
CustQtyByTimeChartDataModel model = new CustQtyByTimeChartDataModel ( ) ;
model . setTitle ( groupCode ) ;
for ( MesCustQtyByTime byTime : custQtyByTimes ) {
Date createDate = DateUtil . parse ( byTime . getCreateDatetime ( ) ) ;
model . getXAxis ( ) . add ( TimeTool . getDay ( createDate ) + "日" + TimeTool . getHour ( createDate ) + "时" ) ;
model . getSeries ( ) . add ( byTime . getCustQty ( ) ) ;
}
result . add ( model ) ;
}
return result ;
}
@Override
public void doCreateCustQtyByTime ( String organizeCode , String username ) {
DdlPackBean packBean = DdlPackBean . getDdlPackBean ( organizeCode ) ;
Set < String > handleShippingGroup = new HashSet < > ( ) ;
List < MesShippingKanbanCfg > kanbanCfg = shippingKanbanCfgRDao . findByHqlWhere ( packBean ) ;
for ( MesShippingKanbanCfg cfg : kanbanCfg ) {
if ( StringUtils . isEmpty ( cfg . getShippingGroupCode ( ) ) ) {
continue ;
}
for ( String shippingGroupCode : cfg . getShippingGroupCode ( ) . split ( "," ) ) {
if ( handleShippingGroup . contains ( shippingGroupCode ) ) {
continue ;
}
handleShippingGroup . add ( shippingGroupCode ) ;
int custQty = getClientStockQtyForJob ( cfg , shippingGroupCode ) ;
MesCustQtyByTime byTime = new MesCustQtyByTime ( ) ;
byTime . setShippingGroupCode ( shippingGroupCode ) ;
byTime . setCustQty ( custQty ) ;
byTime . setOrganizeCode ( organizeCode ) ;
ConvertBean . serviceModelInitialize ( byTime , username ) ;
custQtyByTimeRDao . insert ( byTime ) ;
}
}
}
private String getColor ( MesShippingKanbanCfgDetail cfgDetail , List < String > values ) {
if ( CollectionUtils . isEmpty ( values ) ) {
return cfgDetail . getDefaultColor ( ) ;
@ -306,17 +407,25 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
hql . append ( "select sd.vin" ) ;
hql . append ( " from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid " ) ;
hql . append ( " and s.status in (:status) " ) ;
hql . append ( " and s.shippingGroupCode in (:shippingGroupCode) " ) ;
if ( shippingGroupCodes . size ( ) = = 1 ) {
hql . append ( " and s.shippingGroupCode = :shippingGroupCode " ) ;
} else {
hql . append ( " and s.shippingGroupCode in (:shippingGroupCode) " ) ;
}
hql . append ( " ORDER BY sd.id desc" ) ;
try {
return entityManager . createQuery ( hql . toString ( ) , String . class )
. setParameter ( "organizeCode" , organizeCode )
. setParameter ( "isValid" , CommonEnumUtil . VALID )
. setParameter ( "isDeleted" , CommonEnumUtil . FALSE )
. setParameter ( "status" , status )
. setParameter ( "shippingGroupCode" , shippingGroupCodes )
. setMaxResults ( 1 )
. getSingleResult ( ) ;
Query query = entityManager . createQuery ( hql . toString ( ) , String . class ) ;
query . setParameter ( "organizeCode" , organizeCode ) ;
query . setParameter ( "isValid" , CommonEnumUtil . VALID ) ;
query . setParameter ( "isDeleted" , CommonEnumUtil . FALSE ) ;
query . setParameter ( "status" , status ) ;
if ( shippingGroupCodes . size ( ) = = 1 ) {
query . setParameter ( "shippingGroupCode" , shippingGroupCodes . get ( 0 ) ) ;
} else {
query . setParameter ( "shippingGroupCode" , shippingGroupCodes ) ;
}
query . setMaxResults ( 1 ) ;
return query . getSingleResult ( ) . toString ( ) ;
} catch ( NoResultException e ) {
return "" ;
}
@ -334,7 +443,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
return "" ;
}
StringBuilder offNumberHql = new StringBuilder ( ) ;
offNumberHql . append ( "select max(serialNumber) from " + MesCimSeresJisVinOverPoint . class . getName ( ) ) ;
offNumberHql . append ( "select max(serialNumber) from " ) . append ( MesCimSeresJisVinOverPoint . class . getName ( ) ) ;
offNumberHql . append ( " where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid " ) ;
offNumberHql . append ( " and vin = :vin " ) ;
try {
@ -353,10 +462,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
* 客 户 端 库 存
* 最 新 下 线 的 排 序 发 运 单 客 户 流 水 号 ( SERIAL_NUMBER ) - 赛 力 斯 上 线 的 最 新 流 水 号 + 调 整 值 。
* @param cfg
* @param cfgDetail
* @return
* /
private List < String > getClientStockQty ( MesShippingKanbanCfg cfg , MesShippingKanbanCfgDetail cfgDetail ) {
private List < String > getClientStockQty ( MesShippingKanbanCfg cfg ) {
List < String > values = new ArrayList < > ( ) ;
List < String > strShippingGroupList = Arrays . asList ( cfg . getShippingGroupCode ( ) . split ( "," ) ) ;
if ( CollectionUtils . isEmpty ( strShippingGroupList ) ) {
@ -368,7 +476,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
String onNumber = "" ;
if ( ! StringUtils . isEmpty ( cfg . getOnlinePoint ( ) ) ) {
StringBuilder onNumberHql = new StringBuilder ( ) ;
onNumberHql . append ( "select max(serialNumber) from " + MesCimSeresJisVinOverPoint . class . getName ( ) ) ;
onNumberHql . append ( "select max(serialNumber) from " ) . append ( MesCimSeresJisVinOverPoint . class . getName ( ) ) ;
onNumberHql . append ( " where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid " ) ;
onNumberHql . append ( " and overPoint = :overPoint " ) ;
try {
@ -708,7 +816,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
List < String > values = new ArrayList < > ( ) ;
Date nowTime = DateUtil . now ( ) ;
//获取客户端库存
List < String > clientStockValue = getClientStockQty ( cfg , cfgDetail );
List < String > clientStockValue = getClientStockQty ( cfg );
if ( StringUtils . isEmpty ( clientStockValue ) ) {
return values ;
}