@ -1,7 +1,9 @@
package org.jeecg.modules.productplan.service.impl ;
import com.alibaba.fastjson.JSON ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import org.apache.commons.lang3.StringUtils ;
import org.jeecg.common.exception.JeecgBootException ;
@ -15,28 +17,21 @@ import org.jeecg.modules.demo.ordergoods.entity.OrderGoods;
import org.jeecg.modules.demo.ordergoods.service.IOrderGoodsService ;
import org.jeecg.modules.demo.pro.entity.ZyProcessAccessories ;
import org.jeecg.modules.demo.pro.entity.ZyProcessFabric ;
import org.jeecg.modules.demo.pro.entity.ZyProcessMachine ;
import org.jeecg.modules.demo.pro.service.IZyProcessAccessoriesService ;
import org.jeecg.modules.demo.pro.service.IZyProcessFabricService ;
import org.jeecg.modules.demo.pro.service.IZyProcessMachineService ;
import org.jeecg.modules.demo.zyorders.entity.ZyOrders ;
import org.jeecg.modules.demo.zyorders.service.IZyOrdersService ;
import org.jeecg.modules.product.pdaccessories.entity.ProductAccessories ;
import org.jeecg.modules.product.pdaccessories.service.IProductAccessoriesService ;
import org.jeecg.modules.product.pdfabric.entity.ProductFabric ;
import org.jeecg.modules.product.pdfabric.service.IProductFabricService ;
import org.jeecg.modules.product.zyproductprocess.entity.ZyProductProcess ;
import org.jeecg.modules.product.zyproductprocess.service.IZyProductProcessService ;
import org.jeecg.modules.productplan.entity.ZyPlanProcess ;
import org.jeecg.modules.productplan.entity.ZyPlanProcessAccessories ;
import org.jeecg.modules.productplan.entity.ZyPlanProcessFabric ;
import org.jeecg.modules.productplan.entity.ZyProductPlan ;
import org.jeecg.modules.productplan.entity.vo.PaiWeiTuVo ;
import org.jeecg.modules.productplan.entity.* ;
import org.jeecg.modules.productplan.entity.vo.ProcessDataVo ;
import org.jeecg.modules.productplan.enums.ProductPlanStatusEnum ;
import org.jeecg.modules.productplan.mapper.ZyPlanProcessAccessoriesMapper ;
import org.jeecg.modules.productplan.mapper.ZyPlanProcessFabricMapper ;
import org.jeecg.modules.productplan.mapper.ZyPlanProcessMapper ;
import org.jeecg.modules.productplan.service.IZyPlanProcessAccessoriesService ;
import org.jeecg.modules.productplan.service.IZyPlanProcessFabricService ;
import org.jeecg.modules.productplan.service.IZyPlanProcessService ;
import org.jeecg.modules.productplan.service.IZyProductPlanService ;
import org.jeecg.modules.productplan.service.* ;
import org.jeecg.modules.system.entity.SysDepart ;
import org.jeecg.modules.system.entity.SysUser ;
import org.jeecg.modules.system.service.ISysDepartService ;
@ -44,8 +39,10 @@ import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.team.entity.Groupx ;
import org.jeecg.modules.team.entity.GroupxMember ;
import org.jeecg.modules.team.entity.Station ;
import org.jeecg.modules.team.entity.StationMachine ;
import org.jeecg.modules.team.service.IGroupxMemberService ;
import org.jeecg.modules.team.service.IGroupxService ;
import org.jeecg.modules.team.service.IStationMachineService ;
import org.jeecg.modules.team.service.IStationService ;
import org.jeecg.modules.team.vo.GroupxMemeberVo ;
import org.jeecg.modules.team.vo.StationVo ;
@ -60,6 +57,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.ObjectUtils ;
import java.math.BigDecimal ;
import java.util.* ;
import java.util.stream.Collectors ;
@ -115,6 +113,12 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
@Autowired
private IZyPlanProcessFabricService iZyPlanProcessFabricService ;
@Autowired
private ZyPlanProcessFabricMapper zyPlanProcessFabricMapper ;
@Autowired
private ZyPlanProcessAccessoriesMapper zyPlanProcessAccessoriesMapper ;
@Autowired
private IZyPlanProcessAccessoriesService iZyPlanProcessAccessoriesService ;
@ -130,6 +134,18 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
@Autowired
private IZyAccessoriesService iZyAccessoriesService ;
@Autowired
private IZyProcessMachineService iZyProcessMachineService ;
@Autowired
private IStationMachineService iStationMachineService ;
@Autowired
private IZyPlanFabricService iZyPlanFabricService ;
@Autowired
private IZyPlanAccessoriesService iZyPlanAccessoriesService ;
public List < ZyPlanProcess > getProcessDatalist ( ZyPlanProcess zyPlanProcess ) {
//生产计划id
String planId = zyPlanProcess . getPlanId ( ) ;
@ -145,7 +161,7 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
if ( ObjectUtils . isEmpty ( zyProduct ) ) {
throw new JeecgBootException ( "产品不存在!" ) ;
}
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , planId ) ) ;
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , planId ) . orderByAsc ( ZyPlanProcess : : getStationNum ) ) ;
if ( ! ObjectUtils . isEmpty ( planProcessList ) ) {
List < Station > stationList = iStationService . list ( new LambdaQueryWrapper < Station > ( ) . eq ( Station : : getDepartId , departId ) ) ;
List < StationVo > stationVoList = new LinkedList < > ( ) ;
@ -159,7 +175,7 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
stationVoList . add ( stationVo ) ;
} ) ;
}
Groupx groupx = iGroupxService . getOne ( new LambdaQueryWrapper < Groupx > ( ) . eq ( Groupx : : getDepartId , departId ) . eq ( Groupx : : getId , zyProductPlan . getTeamId ( ) ) ) ;
Groupx groupx = iGroupxService . getOne ( new LambdaQueryWrapper < Groupx > ( ) . eq ( Groupx : : getDepartId , departId ) . eq ( Groupx : : getId , zyProductPlan . getTeamId ( ) ) ) ;
List < GroupxMember > groupMembers = iGroupxMemberService . list ( new LambdaQueryWrapper < GroupxMember > ( ) . eq ( GroupxMember : : getGroupxId , groupx . getId ( ) ) ) ;
List < GroupxMemeberVo > groupxMemeberVoList = new LinkedList < > ( ) ;
@ -184,6 +200,96 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
return planProcessList ;
}
@Override
public void autoFilling ( ZyPlanProcess zyPlanProcess ) {
ZyProductPlan zyProductPlan = iZyProductPlanService . getById ( zyPlanProcess . getPlanId ( ) ) ;
if ( ObjectUtils . isEmpty ( zyProductPlan ) ) {
throw new JeecgBootException ( "生产计划不存在!" ) ;
}
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
//是否有计划工序
if ( ObjectUtils . isEmpty ( planProcessList ) ) return ;
//生产计划车间工位列表
List < Station > stationList = iStationService . list ( new LambdaQueryWrapper < Station > ( ) . eq ( Station : : getDepartId , zyProductPlan . getWorkshopId ( ) ) ) ;
/ * *
* 遍历计划工序 :
* 用工序设备表数据与工位设备进行匹配
* 依次用该生产计划的车间工位设备循环与工序设备比对 【 ( 工位设备包含工序设备即是匹配成功 , 则自动填充工位 、 设备字段数据 , 匹配不上则不自动填充 , 由用户自己录入 ) 】
* 根据工序 , 查询工序设备表zy_process_machine ,
* /
Optional . ofNullable ( planProcessList ) . orElse ( new ArrayList < > ( ) ) . forEach ( e - > {
List < ZyProcessMachine > machineList = iZyProcessMachineService . list ( new LambdaQueryWrapper < ZyProcessMachine > ( ) . eq ( ZyProcessMachine : : getProcessId , e . getProcessId ( ) ) ) ;
this . diffMachine ( e , stationList , machineList ) ;
} ) ;
}
@Override
public void createMaterialBill ( ZyPlanProcess zyPlanProcess ) {
ZyProductPlan zyProductPlan = iZyProductPlanService . getById ( zyPlanProcess . getPlanId ( ) ) ;
if ( ObjectUtils . isEmpty ( zyProductPlan ) ) {
throw new JeecgBootException ( "生产计划不存在!" ) ;
}
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
if ( ObjectUtils . isEmpty ( planProcessList ) ) return ;
this . delBillData ( zyPlanProcess ) ;
List < String > idList = planProcessList . stream ( ) . map ( ZyPlanProcess : : getId ) . collect ( Collectors . toList ( ) ) ;
QueryWrapper qw = new QueryWrapper ( ) ;
qw . select ( "fabric_id" , "sum(amount) as count" ) ;
qw . in ( "plan_process_id" , idList ) ;
qw . groupBy ( "fabric_id" ) ;
List < Map < String , Object > > maplist = zyPlanProcessFabricMapper . selectMaps ( qw ) ;
List < ZyPlanFabric > zyPlanFabricList = new LinkedList < > ( ) ;
for ( Map < String , Object > mp : maplist ) {
ZyPlanFabric zyPlanFabric = new ZyPlanFabric ( ) ;
zyPlanFabric . setPlanId ( zyPlanProcess . getPlanId ( ) ) ;
zyPlanFabric . setFabricId ( mp . get ( "fabric_id" ) . toString ( ) ) ;
zyPlanFabric . setAmount ( new BigDecimal ( mp . get ( "count" ) . toString ( ) ) ) ;
zyPlanFabricList . add ( zyPlanFabric ) ;
}
iZyPlanFabricService . saveBatch ( zyPlanFabricList ) ;
QueryWrapper qw2 = new QueryWrapper ( ) ;
qw2 . select ( "accessories_id" , "sum(amount) as count" ) ;
qw2 . in ( "plan_process_id" , idList ) ;
qw2 . groupBy ( "accessories_id" ) ;
List < Map < String , Object > > maplist2 = zyPlanProcessAccessoriesMapper . selectMaps ( qw2 ) ;
List < ZyPlanAccessories > zyPlanAccessoriesList = new LinkedList < > ( ) ;
for ( Map < String , Object > mp : maplist2 ) {
ZyPlanAccessories zyPlanAccessories = new ZyPlanAccessories ( ) ;
zyPlanAccessories . setPlanId ( zyPlanProcess . getPlanId ( ) ) ;
zyPlanAccessories . setAccessoriesId ( mp . get ( "accessories_id" ) . toString ( ) ) ;
zyPlanAccessories . setAmount ( new BigDecimal ( mp . get ( "count" ) . toString ( ) ) ) ;
zyPlanAccessoriesList . add ( zyPlanAccessories ) ;
}
iZyPlanAccessoriesService . saveBatch ( zyPlanAccessoriesList ) ;
}
void diffMachine ( ZyPlanProcess zyPlanProcess , List < Station > stationList , List < ZyProcessMachine > machineList ) {
if ( ! ObjectUtils . isEmpty ( machineList ) ) {
List < String > machineList1 = machineList . stream ( ) . map ( ZyProcessMachine : : getMachineId ) . collect ( Collectors . toList ( ) ) ;
Optional . ofNullable ( stationList ) . orElse ( new ArrayList < > ( ) ) . forEach ( e - > {
List < StationMachine > stationMachineList = iStationMachineService . list ( new LambdaQueryWrapper < StationMachine > ( ) . eq ( StationMachine : : getStationId , e . getId ( ) ) ) ;
List < String > machineList2 = Optional . ofNullable ( stationMachineList ) . orElse ( new ArrayList < > ( ) ) . stream ( ) . map ( StationMachine : : getMachineId ) . collect ( Collectors . toList ( ) ) ;
if ( machineList2 . containsAll ( machineList1 ) ) {
String collect = machineList1 . stream ( ) . collect ( Collectors . joining ( "," ) ) ;
zyPlanProcess . setMachineIds ( collect ) ;
zyPlanProcess . setMachineNames ( iStationMachineService . convertByMachineIds ( machineList1 ) ) ;
zyPlanProcess . setStationId ( e . getId ( ) ) ;
zyPlanProcess . setStationName ( e . getStationName ( ) ) ;
zyPlanProcess . setStationNum ( e . getStationNum ( ) ) ;
this . updateById ( zyPlanProcess ) ;
return ;
}
} ) ;
}
}
@Override
@Transactional ( readOnly = false , rollbackFor = Exception . class )
public List < ZyPlanProcess > syncProductBaseProcess ( ZyPlanProcess zyPlanProcess ) {
@ -267,17 +373,36 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
}
/ * *
* 删除工序面料 & 工序辅料表 & 生产计划工序表数据
*
* @param zyPlanProcess
* /
@Transactional ( readOnly = false , rollbackFor = Exception . class )
public void delSyncData ( ZyPlanProcess zyPlanProcess ) {
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
if ( ! ObjectUtils . isEmpty ( planProcessList ) ) {
List < String > collect = Optional . ofNullable ( planProcessList ) . orElse ( new ArrayList < > ( ) ) . stream ( ) . map ( ZyPlanProcess : : getProcessId ) . collect ( Collectors . toList ( ) ) ;
List < String > collect = Optional . ofNullable ( planProcessList ) . orElse ( new ArrayList < > ( ) ) . stream ( ) . map ( ZyPlanProcess : : getId ) . collect ( Collectors . toList ( ) ) ;
iZyPlanProcessFabricService . remove ( new LambdaQueryWrapper < ZyPlanProcessFabric > ( ) . in ( ZyPlanProcessFabric : : getPlanProcessId , collect ) ) ;
iZyPlanProcessAccessoriesService . remove ( new LambdaQueryWrapper < ZyPlanProcessAccessories > ( ) . in ( ZyPlanProcessAccessories : : getPlanProcessId , collect ) ) ;
this . remove ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
}
}
/ * *
* 删除物料单 ( 生产计划面料 & 生产计划辅料 ) 数据
*
* @param zyPlanProcess
* /
@Transactional ( readOnly = false , rollbackFor = Exception . class )
public void delBillData ( ZyPlanProcess zyPlanProcess ) {
List < ZyPlanProcess > planProcessList = this . list ( new LambdaQueryWrapper < ZyPlanProcess > ( ) . eq ( ZyPlanProcess : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
if ( ! ObjectUtils . isEmpty ( planProcessList ) ) {
iZyPlanFabricService . remove ( new LambdaQueryWrapper < ZyPlanFabric > ( ) . eq ( ZyPlanFabric : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
iZyPlanAccessoriesService . remove ( new LambdaQueryWrapper < ZyPlanAccessories > ( ) . eq ( ZyPlanAccessories : : getPlanId , zyPlanProcess . getPlanId ( ) ) ) ;
}
}
void saveBatchAccessoriesByProcessIdList ( List < ZyPlanProcess > planProcessList ) {
Optional . ofNullable ( planProcessList ) . orElse ( new ArrayList < > ( ) ) . forEach ( e - > {
List < ZyProcessAccessories > accessoriesList = this . iZyProcessAccessoriesService . list ( new LambdaQueryWrapper < ZyProcessAccessories > ( )
@ -285,7 +410,7 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
List < ZyPlanProcessAccessories > list = new LinkedList < > ( ) ;
Optional . ofNullable ( accessoriesList ) . orElse ( new ArrayList < > ( ) ) . forEach ( obj - > {
ZyPlanProcessAccessories en = new ZyPlanProcessAccessories ( ) ;
en . setPlanProcessId ( e . getProcess Id ( ) ) ;
en . setPlanProcessId ( e . getId ( ) ) ;
en . setPlanId ( e . getPlanId ( ) ) ;
en . setAccessoriesId ( obj . getAccessoriesId ( ) ) ;
ZyAccessories zyAccessories = iZyAccessoriesService . getById ( obj . getAccessoriesId ( ) ) ;
@ -297,7 +422,6 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
}
void saveBatchFabricByProcessIdList ( List < ZyPlanProcess > planProcessList ) {
if ( ! org . springframework . util . StringUtils . isEmpty ( planProcessList ) ) {
planProcessList . forEach ( e - > {
List < ZyProcessFabric > fabricList = this . iZyProcessFabricService . list ( new LambdaQueryWrapper < ZyProcessFabric > ( )
@ -306,7 +430,7 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
if ( ! org . springframework . util . StringUtils . isEmpty ( fabricList ) ) {
fabricList . forEach ( obj - > {
ZyPlanProcessFabric en = new ZyPlanProcessFabric ( ) ;
en . setPlanProcessId ( e . getProcess Id ( ) ) ;
en . setPlanProcessId ( e . getId ( ) ) ;
en . setPlanId ( e . getPlanId ( ) ) ;
en . setFabricId ( obj . getFabricId ( ) ) ;
ZyFabric zyFabric = iZyFabricService . getById ( obj . getFabricId ( ) ) ;
@ -317,19 +441,6 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
}
} ) ;
}
// Optional.ofNullable(planProcessList).orElse(null).forEach(e -> {
// Optional.ofNullable(fabricList).orElse(null).forEach(obj -> {
// ZyPlanProcessFabric en = new ZyPlanProcessFabric();
// en.setPlanProcessId(e.getProcessId());
// en.setPlanId(e.getPlanId());
// en.setFabricId(obj.getFabricId());
// ZyFabric zyFabric = iZyFabricService.getById(obj.getFabricId());
// en.setFabricName(StringUtils.isNotBlank(zyFabric.getName()) ? zyFabric.getName() : "");
// list.add(en);
// });
// iZyPlanProcessFabricService.saveBatch(list);
// });
}
@ -443,4 +554,6 @@ public class ZyPlanProcessServiceImpl extends ServiceImpl<ZyPlanProcessMapper, Z
}
return result ;
}
}