|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.daoimpl;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.dao.ISapProductPlanDao;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.dao.IMesProductPlanDao;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.util.StringUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.SapProductPlan;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProductPlan;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProductPlan;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -26,34 +27,34 @@ import java.util.Objects;
|
|
|
|
|
**/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class SapProductPlanDaoImpl implements ISapProductPlanDao {
|
|
|
|
|
public class MesProductPlanDaoImpl implements IMesProductPlanDao {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ListPager<SapProductPlan> querySapProductPlanPager(SapProductPlan sapProductPlan, Pager pager) {
|
|
|
|
|
public ListPager<MesProductPlan> queryMesProductPlanPager(MesProductPlan mesProductPlan, Pager pager) {
|
|
|
|
|
//查询数据
|
|
|
|
|
StringBuffer dataHql = new StringBuffer("select sap.plnum,sap.plmat,ifnull(sap.gsmng,0) as sumQty," +
|
|
|
|
|
"ifnull(mes.reported_qty,0) as completeQty,sap.meins,sap.psttr,sap.pedtr,sap.l_str," +
|
|
|
|
|
"sap.plwrk,sap.create_date_time,sap.create_user,sap.modify_date_time,sap.modify_user");
|
|
|
|
|
StringBuffer dataHql = new StringBuffer("select sap.plan_order_no,sap.plan_part_no,ifnull(sap.plan_qty,0) as sumQty," +
|
|
|
|
|
"ifnull(mes.reported_qty,0) as completeQty,sap.unit,sap.plan_start_date,sap.plan_end_date,sap.part_mapping_work_center_code," +
|
|
|
|
|
"sap.plan_organize_code,sap.create_date_time,sap.create_user,sap.modify_date_time,sap.modify_user");
|
|
|
|
|
StringBuilder hql = new StringBuilder();
|
|
|
|
|
hql.append(" from sap_product_plan sap left join mes_work_order mes on sap.plnum = mes.plan_order_no and sap.plmat = mes.part_no " +
|
|
|
|
|
hql.append(" from mes_plan_sap sap left join mes_work_order mes on sap.plan_order_no = mes.plan_order_no and sap.plan_part_no = mes.part_no " +
|
|
|
|
|
"where sap.is_deleted=:isDeleted and sap.is_valid=:isValid and sap.organize_code=:organizeCode " +
|
|
|
|
|
" and ((mes.is_deleted=:isDeleted and mes.is_valid=:isValid and mes.organize_code=:organizeCode) or mes.id is null)");
|
|
|
|
|
//拼接查询条件
|
|
|
|
|
packWhere(sapProductPlan, hql);
|
|
|
|
|
StringBuffer unionDataHql = new StringBuffer("select sap.plnum,mes.part_no,ifnull(mes.qty,0) as sumQty," +
|
|
|
|
|
"ifnull(mes.reported_qty,0) as completeQty,part.unit,sap.psttr,sap.pedtr,sap.l_str," +
|
|
|
|
|
"sap.plwrk,mes.create_date_time,mes.create_user,mes.modify_date_time,mes.modify_user");
|
|
|
|
|
packWhere(mesProductPlan, hql);
|
|
|
|
|
StringBuffer unionDataHql = new StringBuffer("select sap.plan_order_no,mes.part_no,ifnull(mes.qty,0) as sumQty," +
|
|
|
|
|
"ifnull(mes.reported_qty,0) as completeQty,part.unit,sap.plan_start_date,sap.plan_end_date,sap.part_mapping_work_center_code," +
|
|
|
|
|
"sap.plan_organize_code,mes.create_date_time,mes.create_user,mes.modify_date_time,mes.modify_user");
|
|
|
|
|
StringBuilder unionHql = new StringBuilder();
|
|
|
|
|
unionHql.append(" from sap_product_plan sap right join mes_work_order mes on sap.plnum = mes.plan_order_no and sap.plmat = mes.part_no " +
|
|
|
|
|
unionHql.append(" from mes_plan_sap sap right join mes_work_order mes on sap.plan_order_no = mes.plan_order_no and sap.plan_part_no = mes.part_no " +
|
|
|
|
|
" left join mes_part part on part.part_no = mes.part_no " +
|
|
|
|
|
"where mes.is_deleted=:isDeleted and mes.is_valid=:isValid and mes.organize_code=:organizeCode and sap.id is null ");
|
|
|
|
|
//拼接查询条件
|
|
|
|
|
packWhere(sapProductPlan, unionHql);
|
|
|
|
|
packWhere(mesProductPlan, unionHql);
|
|
|
|
|
//查询行数
|
|
|
|
|
int count = getCount(sapProductPlan, hql) + getCount(sapProductPlan, unionHql);
|
|
|
|
|
int count = getCount(mesProductPlan, hql) + getCount(mesProductPlan, unionHql);
|
|
|
|
|
pager = PagerHelper.getPager(pager, count);
|
|
|
|
|
if (count <= 0) {
|
|
|
|
|
return new ListPager<>(new ArrayList<>(), pager);
|
|
|
|
@ -63,12 +64,12 @@ public class SapProductPlanDaoImpl implements ISapProductPlanDao {
|
|
|
|
|
//查询数据
|
|
|
|
|
Query query = entityManager.createNativeQuery(dataHql.append(hql) + " union all " + unionDataHql.append(unionHql) + orderBy);
|
|
|
|
|
//赋值
|
|
|
|
|
setParameter(sapProductPlan, query);
|
|
|
|
|
setParameter(mesProductPlan, query);
|
|
|
|
|
List resultList = query.setFirstResult(pager.getStartRow()).setMaxResults(pager.getPageSize()).getResultList();
|
|
|
|
|
List<SapProductPlan> list = new ArrayList<>();
|
|
|
|
|
List<MesProductPlan> list = new ArrayList<>();
|
|
|
|
|
for (Object result : resultList) {
|
|
|
|
|
Object[] cells = (Object[]) result;
|
|
|
|
|
SapProductPlan tjMgnBoardModel = new SapProductPlan(
|
|
|
|
|
MesProductPlan tjMgnBoardModel = new MesProductPlan(
|
|
|
|
|
Objects.isNull(cells[0])?"":String.valueOf(cells[0]),
|
|
|
|
|
Objects.isNull(cells[1])?"":String.valueOf(cells[1]),
|
|
|
|
|
Objects.isNull(cells[2])?0:Double.parseDouble(String.valueOf(cells[2])),
|
|
|
|
@ -87,69 +88,69 @@ public class SapProductPlanDaoImpl implements ISapProductPlanDao {
|
|
|
|
|
return new ListPager<>(list, pager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getCount(SapProductPlan sapProductPlan, StringBuilder hql) {
|
|
|
|
|
private int getCount(MesProductPlan mesProductPlan, StringBuilder hql) {
|
|
|
|
|
Query query = entityManager.createNativeQuery("select count(1) " + hql);
|
|
|
|
|
//赋值
|
|
|
|
|
setParameter(sapProductPlan, query);
|
|
|
|
|
setParameter(mesProductPlan, query);
|
|
|
|
|
return Integer.parseInt(query.getSingleResult() + "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setParameter(SapProductPlan sapProductPlan, Query query) {
|
|
|
|
|
query.setParameter("organizeCode", sapProductPlan.getOrganizeCode());
|
|
|
|
|
private void setParameter(MesProductPlan mesProductPlan, Query query) {
|
|
|
|
|
query.setParameter("organizeCode", mesProductPlan.getOrganizeCode());
|
|
|
|
|
query.setParameter("isDeleted", CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
|
|
|
|
|
query.setParameter("isValid", CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPlnum())) {
|
|
|
|
|
query.setParameter("plnum", sapProductPlan.getPlnum());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanOrderNo())) {
|
|
|
|
|
query.setParameter("planOrderNo", mesProductPlan.getPlanOrderNo());
|
|
|
|
|
}
|
|
|
|
|
//计划物料
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPlmat())) {
|
|
|
|
|
query.setParameter("plmat", sapProductPlan.getPlmat());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanPartNo())) {
|
|
|
|
|
query.setParameter("planPartNo", mesProductPlan.getPlanPartNo());
|
|
|
|
|
}
|
|
|
|
|
//生产线
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getLStr())) {
|
|
|
|
|
query.setParameter("lStr", sapProductPlan.getLStr());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPartMappingWorkCenterCode())) {
|
|
|
|
|
query.setParameter("partMappingWorkCenterCode", mesProductPlan.getPartMappingWorkCenterCode());
|
|
|
|
|
}
|
|
|
|
|
//计划开始&结束
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPsttr())) {
|
|
|
|
|
query.setParameter("psttr", sapProductPlan.getPsttr());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanStartDate())) {
|
|
|
|
|
query.setParameter("planStartDate", mesProductPlan.getPlanStartDate());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPedtr())) {
|
|
|
|
|
query.setParameter("pedtr", sapProductPlan.getPedtr());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanEndDate())) {
|
|
|
|
|
query.setParameter("planEndDate", mesProductPlan.getPlanEndDate());
|
|
|
|
|
}
|
|
|
|
|
//开始创建&结束日期
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getCreateDateTimeStart())) {
|
|
|
|
|
query.setParameter("createDateTimeStart", sapProductPlan.getCreateDateTimeStart());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getCreateDateTimeStart())) {
|
|
|
|
|
query.setParameter("createDateTimeStart", mesProductPlan.getCreateDateTimeStart());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getCreateDateTimeEnd())) {
|
|
|
|
|
query.setParameter("createDateTimeEnd", sapProductPlan.getCreateDateTimeEnd());
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getCreateDateTimeEnd())) {
|
|
|
|
|
query.setParameter("createDateTimeEnd", mesProductPlan.getCreateDateTimeEnd());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void packWhere(SapProductPlan sapProductPlan, StringBuilder hql) {
|
|
|
|
|
private void packWhere(MesProductPlan mesProductPlan, StringBuilder hql) {
|
|
|
|
|
//计划订单号
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPlnum())) {
|
|
|
|
|
hql.append(" and sap.plnum = :plnum");
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanOrderNo())) {
|
|
|
|
|
hql.append(" and sap.plan_order_no = :planOrderNo");
|
|
|
|
|
}
|
|
|
|
|
//计划物料
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPlmat())) {
|
|
|
|
|
hql.append(" and sap.plmat = :plmat");
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanPartNo())) {
|
|
|
|
|
hql.append(" and sap.plan_part_no = :planPartNo");
|
|
|
|
|
}
|
|
|
|
|
//生产线
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getLStr())) {
|
|
|
|
|
hql.append(" and sap.l_str = :lStr");
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPartMappingWorkCenterCode())) {
|
|
|
|
|
hql.append(" and sap.part_mapping_work_center_code = :partMappingWorkCenterCode");
|
|
|
|
|
}
|
|
|
|
|
//计划开始&结束
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPsttr())) {
|
|
|
|
|
hql.append(" and sap.psttr >= :psttr");
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanStartDate())) {
|
|
|
|
|
hql.append(" and sap.plan_start_date >= :planStartDate");
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getPedtr())) {
|
|
|
|
|
hql.append(" and sap.pedtr <= :pedtr");
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getPlanEndDate())) {
|
|
|
|
|
hql.append(" and sap.plan_end_date <= :planEndDate");
|
|
|
|
|
}
|
|
|
|
|
//开始创建&结束日期
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getCreateDateTimeStart())) {
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getCreateDateTimeStart())) {
|
|
|
|
|
hql.append(" and sap.create_date_time >= :createDateTimeStart");
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtil.isEmpty(sapProductPlan.getCreateDateTimeEnd())) {
|
|
|
|
|
if (!StringUtil.isEmpty(mesProductPlan.getCreateDateTimeEnd())) {
|
|
|
|
|
hql.append(" and sap.create_date_time <= :createDateTimeEnd");
|
|
|
|
|
}
|
|
|
|
|
}
|