/**
*
*/
package com.wisco.pb.bo;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
import org.m6.base.BaseBO;
import org.m6.exception.AppException;
import org.m6.log.AppLogger;
import org.marmot.security.service.PaginationSupport;
import org.marmot.view.DataSet;
import org.springframework.stereotype.Component;
import com.bstek.dorado.stk.common.lang.utils.CollectionUtils;
import com.bstek.dorado.utils.StringHelper;
import com.wisco.framework.utils.AppUtils;
import com.wisco.pb.domain.Tbpbc35;
import com.wisco.pb.domain.Tbpbc36;
/**
* @author Administrator
*
*/
@Component("pbjcc365BO")
public class Pbjcc365BO extends BaseBO {
public final static String CLASS_VERSION = "$Id: Pbjcc365BO.java,v 1.0 2015-1-17,上午8:17:36 $";
private static final Logger log = AppLogger.getLogger("Pbjcc365BO",
"DEBUG", true)
/**
* LOT
*
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-19
* @version 1.0
*/
public void executeLotSplitY06(Map datasetMap, Object param)
throws Exception {
List<Tbpbc35> listsC35=new ArrayList();
List<Tbpbc36> listsC36=new ArrayList();
DataSet ds = (DataSet) datasetMap.get("datasetTbpbc36");
Map<String, Object> map = (Map<String, Object>) param;
String pbc35Id = map.get("pbc35Id") == null ? "" : map.get("pbc35Id")
.toString();// 被切割的lot
String lotSNo = map.get("lotNo") == null ? "" : map.get("lotNo")
.toString();// 被切割的lot号
String currLine = map.get("currLine") == null ? "" : map.get("currLine")
.toString();// 被切割的lot号机组
Collection<Tbpbc36> coll = ds.getRecords();// 切割出去的排程
List<Tbpbc36> sc36List=new ArrayList();
String c36S_minCoilIndex = "";// 切割的最小顺序号
String c36S_maxCoilIndex = "";// 切割的最大顺序号
Tbpbc36 c36S_min=null;//切割的最小记录
Tbpbc36 c36S_max=null;//切割的最大记录
Long c36S_workTotalTime = 0l;// 切割的总时长;
Long sc36TotalentryCoilWgt=0l;//切割的排程明细表的总入侧重量
List<String> c36idList = new ArrayList();// 分割的主键集合
String compId=AppUtils.getLoginUserCompanyId();
Tbpbc35 sC35=this.getC35(compId, currLine, pbc35Id);//被切割的主表记录
if (coll.size() > 0) {
List<String> str_c36CoilIndex = new ArrayList();// 材料顺序号
int i=0;
for (Tbpbc36 c36 : coll) {
// if(i==0){
// sc36List.add(c36);
// }else if(i==coll.size()-1){
// sc36List.add(c36);
// }
// i++;
sc36List.add(c36);
str_c36CoilIndex.add(c36.getCoilIndex());
c36S_workTotalTime += c36.getWorkTotalTime();
sc36TotalentryCoilWgt+=c36.getEntryCoilWgt();
c36idList.add(c36.getPbc36Id());
}
// Collections.sort(str_c36CoilIndex);
c36S_min=sc36List.get(0);//最小的记录
c36S_max=sc36List.get(sc36List.size()-1);//最大的记录
c36S_minCoilIndex = str_c36CoilIndex.get(0);
c36S_maxCoilIndex = str_c36CoilIndex.get(str_c36CoilIndex.size()-1);
}
// List listC35 = this.getTbpbc36ByKey(pbc35Id, null, null);
// 取出最小和最大顺序号前面的和后面的明细表数据
List<Tbpbc36> bC36List=this.getBAc36(pbc35Id, c36S_minCoilIndex, null);//分割前面的部分
List<Tbpbc36> aC36List=this.getBAc36(pbc35Id, null, c36S_maxCoilIndex);//分割后面的部分,这一部分要变
String maxLotNo=this.getMaxLotNo(compId, currLine);//最大的lot号
//得到要分割的材料之间没有分割的材料
List<Tbpbc36> outSc36List=this.getOutS36(compId,currLine,pbc35Id, c36idList, c36S_minCoilIndex, c36S_maxCoilIndex);
/*
* 如果最小和最大都有材料的话,取出最小前面的一个钢卷的结束时间和顺序号,前面的材料不变,后面没有分割的时间按顺序排(以前一个结束时间为
* 下一个开始时间,然后+时间差作为结束时间,继续循环),产生的新lot为主表lotz最大值后面,所有的该lot后面的顺序号和开始结束时间都要
* 重算;相关的从表的信息也要改变
*/
if (!CollectionUtils.isEmpty(bC36List) && !CollectionUtils.isEmpty(aC36List)) {
Tbpbc36 bmaxc36=bC36List.get(bC36List.size()-1);//分割前面部分的最大值
Date psd=bmaxc36.getProdEndDate();//从表分割之间,后部分钢卷排程开始时间
String nc36CoilIndex=bmaxc36.getCoilIndex();//分割前部分最大的index;
//先主表被切割的lot,接着计算从表中的记录
Long oldWttSeconds=sC35.getWorkTotalTime().longValue()*60;
int betweenSeconds=(int) (oldWttSeconds-c36S_workTotalTime*60);
Date let=DateUtils.addSeconds(sC35.getLotStartTime(), betweenSeconds);
sC35.setLotEndTime(let);
sC35.setLotWgt(sC35.getLotWgt()-sc36TotalentryCoilWgt);
BigDecimal ttm=new BigDecimal(betweenSeconds/60);
sC35.setWorkTotalTime(ttm);
// this.getHibernateTemplate().update(sC35);
// this.getHibernateTemplate().evict(sC35);
listsC35.add(sC35);
//新lot主表和从表的计算
this.saveNewTbc35(compId,currLine,sC35, maxLotNo,sc36TotalentryCoilWgt, c36S_workTotalTime,sc36List);
// 如果最大值和最小值中间有没有分割出去的值,后面一部分的要变,首先得到被切割的主表lot,对主表的数据进行操作修改被分割的数据,然后产生新的lot,最后对被分割后面的进行排序
if(CollectionUtils.isEmpty(outSc36List)){//中间没有明细记录
log.debug("--------------------分割的材料前后都有,切割的中间没有为切割的-------------------------");
//分割记录从表的改变:开始时间为分割前部分的最大时间,lotIndex接着排
for(Tbpbc36 ac36:aC36List){
int c36betweenSecons=(int)(ac36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
ac36.setProdStartDate(psd);
ac36.setProdEndDate(ped);
String b6coilIndex=nc36CoilIndex.substring(0,6);
String a3coilIndex=String.format("%03d",Integer.parseInt(nc36CoilIndex.substring(nc36CoilIndex.length()-3,nc36CoilIndex.length()))+1);
ac36.setCoilIndex(b6coilIndex+a3coilIndex);
// this.getHibernateTemplate().update(ac36);
// this.getHibernateTemplate().evict(ac36);
listsC36.add(ac36);
psd=ac36.getProdEndDate();
nc36CoilIndex=ac36.getCoilIndex();
}
}else{// 如果最大值和最小值中间有分割出去的值,之间的和后面一部分的要变
log.debug("--------------------分割的材料前后都有,切割的中间有为切割的-------------------------");
for(Tbpbc36 oc36:outSc36List){
int oc36BetweenSeconds=(int)(oc36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,oc36BetweenSeconds);
oc36.setProdStartDate(psd);
oc36.setProdEndDate(ped);
String b6coilIndex=nc36CoilIndex.substring(0,6);
String a3coilIndex=String.format("%03d",Integer.parseInt(nc36CoilIndex.substring(nc36CoilIndex.length()-3,nc36CoilIndex.length()))+1);
oc36.setCoilIndex(b6coilIndex+a3coilIndex);
// this.getHibernateTemplate().update(oc36);
// this.getHibernateTemplate().evict(oc36);
listsC36.add(oc36);
nc36CoilIndex=oc36.getCoilIndex();
psd=oc36.getProdEndDate();
}
for(Tbpbc36 ac36:aC36List){
int c36betweenSecons=(int)(ac36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
ac36.setProdStartDate(psd);
ac36.setProdEndDate(ped);
String b6coilIndex=nc36CoilIndex.substring(0,6);
String a3coilIndex=String.format("%03d",Integer.parseInt(nc36CoilIndex.substring(nc36CoilIndex.length()-3,nc36CoilIndex.length()))+1);
ac36.setCoilIndex(b6coilIndex+a3coilIndex);
// this.getHibernateTemplate().update(ac36);
// this.getHibernateTemplate().evict(ac36);
listsC36.add(ac36);
nc36CoilIndex=ac36.getCoilIndex();
psd=ac36.getProdEndDate();
}
}
}
/*
* 如果最小的前面有材料则,最大的后面没有钢卷,前面的不变,改变的lot总量和结束时间重算,产生的新lot为主表lot的最大值,所有该lot后
* 面的顺序和开始结束时间都要重算;相关的从表的信息也要改变
*/
else if (!CollectionUtils.isEmpty(bC36List)
&& CollectionUtils.isEmpty(aC36List)) {
Tbpbc36 bmaxc36=bC36List.get(bC36List.size()-1);//分割前面部分的最大值
Date psd=bmaxc36.getProdEndDate();//从表分割之间,后部分钢卷排程开始时间为前部分的最大值得结束时间
String nc36CoilIndex=bmaxc36.getCoilIndex();//分割前部分最大的index;
//先主表被切割的lot,接着计算从表中的记录
Long oldWttSeconds=sC35.getWorkTotalTime().longValue()*60;
int betweenSeconds=(int) (oldWttSeconds-c36S_workTotalTime*60);
Date let=DateUtils.addSeconds(sC35.getLotStartTime(), betweenSeconds);
sC35.setLotEndTime(let);
sC35.setLotWgt(sC35.getLotWgt()-sc36TotalentryCoilWgt);
BigDecimal ttm=new BigDecimal(betweenSeconds/60);
sC35.setWorkTotalTime(ttm);
// this.getHibernateTemplate().update(sC35);
// this.getHibernateTemplate().evict(sC35);
listsC35.add(sC35);
//新lot主表和从表的计算
this.saveNewTbc35(compId,currLine,sC35, maxLotNo,sc36TotalentryCoilWgt, c36S_workTotalTime,sc36List);
// 如果最大值和最小值中间没有没分割
if(CollectionUtils.isEmpty(outSc36List)){
log.debug("--------------------分割的材料前有后没有,切割的中间没有为切割的-------------------------");
}else{// 如果最大值和最小值中间有没分割,之间的要变
log.debug("--------------------分割的材料前有后没有,切割的中间有为切割的-------------------------");
for(Tbpbc36 oc36:outSc36List){
int oc36BetweenSeconds=(int)(oc36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,oc36BetweenSeconds);
oc36.setProdStartDate(psd);
oc36.setProdEndDate(ped);
String b6coilIndex=nc36CoilIndex.substring(0,6);
String a3coilIndex=String.format("%03d",Integer.parseInt(nc36CoilIndex.substring(nc36CoilIndex.length()-3,nc36CoilIndex.length()))+1);
oc36.setCoilIndex(b6coilIndex+a3coilIndex);
// this.getHibernateTemplate().update(oc36);
// this.getHibernateTemplate().evict(oc36);
listsC36.add(oc36);
nc36CoilIndex=oc36.getCoilIndex();
psd=oc36.getProdEndDate();
}
}
}
/*
* 如果最小的前面没有材料,最大的后面有材料,后面的钢卷开始和结束时间重算,主表中新产生的lot为主表lot的最大值,该lot顺序号为切割lot
* 后面,该lot后面开始和结束时间都要重算,lot顺序号也要重算,相关的从表的信息也要改变
*/
else if (CollectionUtils.isEmpty(bC36List)
&& !CollectionUtils.isEmpty(aC36List)) {
//先主表被切割的lot,接着计算从表中的记录
Long oldWttSeconds=sC35.getWorkTotalTime().longValue()*60;
int betweenSeconds=(int) (oldWttSeconds-c36S_workTotalTime*60);
Date let=DateUtils.addSeconds(sC35.getLotStartTime(), betweenSeconds);
sC35.setLotEndTime(let);
sC35.setLotWgt(sC35.getLotWgt()-sc36TotalentryCoilWgt);
BigDecimal ttm=new BigDecimal(betweenSeconds/60);
sC35.setWorkTotalTime(ttm);
// this.getHibernateTemplate().update(sC35);
// this.getHibernateTemplate().evict(sC35);
listsC35.add(sC35);
//新lot主表和从表的计算
this.saveNewTbc35(compId,currLine,sC35, maxLotNo,sc36TotalentryCoilWgt, c36S_workTotalTime,sc36List);
Date psd=sC35.getLotStartTime();//材料开始时间
String a3coilIndex="-001";//材料顺序号
// 如果最大值和最小值中间有没有分割出去的值,后面一部分的要变
if(CollectionUtils.isEmpty(outSc36List)){
log.debug("--------------------分割的材料前没有后有,切割的中间没有为切割的-------------------------");
for(Tbpbc36 c36:aC36List){
int c35WttSeconds=(int)(c36.getWorkTotalTime()*60);
Date pet=DateUtils.addSeconds(psd,c35WttSeconds);
c36.setProdStartDate(psd);
c36.setProdEndDate(pet);
String b6coilIndex=c36.getCoilIndex().substring(0,6);//前6位
String rec=String.format("%03d", Integer.parseInt(a3coilIndex)+1);
c36.setCoilIndex(b6coilIndex+rec);
// this.getHibernateTemplate().update(c36);
// this.getHibernateTemplate().evict(c36);
listsC36.add(c36);
a3coilIndex=c36.getCoilIndex().substring(c36.getCoilIndex().length()-3,c36.getCoilIndex().length());
psd=c36.getProdEndDate();
}
}else{// 如果最大值和最小值中间有没分割出去的值,之间的和后面一部分的要变
log.debug("--------------------分割的材料前没有后有,切割的中间有为切割的-------------------------");
for(Tbpbc36 oc36:outSc36List){
int oc36BetweenSeconds=(int)(oc36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,oc36BetweenSeconds);
oc36.setProdStartDate(psd);
oc36.setProdEndDate(ped);
String b6coilIndex=oc36.getCoilIndex().substring(0,6);//前6位
String rec=String.format("%03d",Integer.parseInt(a3coilIndex)+1);
oc36.setCoilIndex(b6coilIndex+rec);
// this.getHibernateTemplate().update(oc36);
// this.getHibernateTemplate().evict(oc36);
listsC36.add(oc36);
psd=oc36.getProdEndDate();
a3coilIndex=oc36.getCoilIndex().substring(oc36.getCoilIndex().length()-3,oc36.getCoilIndex().length());
}
for(Tbpbc36 ac36:aC36List){
int c36betweenSecons=(int)(ac36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
ac36.setProdStartDate(psd);
ac36.setProdEndDate(ped);
String b6coilIndex=ac36.getCoilIndex().substring(0,6);//前6位
String rec=String.format("%03d",Integer.parseInt(a3coilIndex)+1);
ac36.setCoilIndex(b6coilIndex+rec);
// this.getHibernateTemplate().update(ac36);
// this.getHibernateTemplate().evict(ac36);
listsC36.add(ac36);
psd=ac36.getProdEndDate();
a3coilIndex=ac36.getCoilIndex().substring(ac36.getCoilIndex().length()-3,ac36.getCoilIndex().length());
}
}
}
/*
* 如果最大值和最小值得前后都为空的话,就是把真个
*/
else {
Date psd=sC35.getLotStartTime();//材料开始时间
String a3coilIndex="-001";//材料顺序号
// 如果最大值和最小值中间有没有分割出去的值
if(CollectionUtils.isEmpty(outSc36List)){
log.debug("--------------------分割的材料前没有后没有,切割的中间没有为切割的-------------------------");
throw new AppException("不能分割所有的钢卷出去");
}else{// 如果最大值和最小值中间有没分割出去的值,之间的要变
log.debug("--------------------分割的材料前没有后没有,切割的中间有为切割的-------------------------");
//先主表被切割的lot,接着计算从表中的记录
Long oldWttSeconds=sC35.getWorkTotalTime().longValue()*60;
int betweenSeconds=(int) (oldWttSeconds-c36S_workTotalTime*60);
Date let=DateUtils.addSeconds(sC35.getLotStartTime(), betweenSeconds);
sC35.setLotEndTime(let);
sC35.setLotWgt(sC35.getLotWgt()-sc36TotalentryCoilWgt);
BigDecimal ttm=new BigDecimal(betweenSeconds/60);
sC35.setWorkTotalTime(ttm);
// this.getHibernateTemplate().update(sC35);
// this.getHibernateTemplate().evict(sC35);
listsC35.add(sC35);
//新lot主表和从表的计算
this.saveNewTbc35(compId,currLine,sC35, maxLotNo,sc36TotalentryCoilWgt, c36S_workTotalTime,sc36List);
//从表切割剩余计算
for(Tbpbc36 ac36:outSc36List){
int c36betweenSecons=(int)(ac36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
ac36.setProdStartDate(psd);
ac36.setProdEndDate(ped);
String b6coilIndex=ac36.getCoilIndex().substring(0,6);//前6位
String rec=String.format("%03d",Integer.parseInt(a3coilIndex)+1);
ac36.setCoilIndex(b6coilIndex+rec);
// this.getHibernateTemplate().update(ac36);
// this.getHibernateTemplate().evict(ac36);
listsC36.add(ac36);
}
}
}
this.getHibernateTemplate().saveOrUpdateAll(listsC35);
this.getHibernateTemplate().flush();
this.getHibernateTemplate().saveOrUpdateAll(listsC36);
this.getHibernateTemplate().flush();
}
// /**
// * 根据主键Id,最大值,最小值,取从表相关的所有数据
// *
// * @file Pbjcc365BO.java
// * @author hunter
// * @date 2015-1-19
// * @version 1.0
// */
// public List<Tbpbc36> getTbpbc36ByKey(String pbc35Id, String minCoilIndex,
// String maxCoilIndex) throws Exception {
// String hql = "from Tbpbc36 where pbc35Id=?";
// List listParams = new ArrayList();
// listParams.add(pbc35Id);
// if (StringHelper.isNotEmpty(minCoilIndex)) {
// hql += " and coilIndex=?";
// listParams.add(minCoilIndex);
// }
// if (StringHelper.isNotEmpty(maxCoilIndex)) {
// hql += " and coilIndex=?";
// listParams.add(maxCoilIndex);
// }
// hql += " order by coilIndex";
// List<Tbpbc36> c36List = this.getHibernateTemplate().find(hql,
// listParams.toArray());
// if (!CollectionUtils.isEmpty(c36List)) {
// return c36List;
// } else {
// return null;
// }
// }
/**
* 得到要分割的材料之间没有分割的材料
*
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public List<Tbpbc36> getOutS36(String compId,String currLine,String pbc35Id, List<String> list,
String minIndex, String maxIndex) throws Exception {
String conStr = "";
for (String str:list) {
if (conStr.equals("")) {
conStr = "'" + str + "'";
} else {
conStr = conStr + "," + "'" + str + "'";
}
}
String hql = "from Tbpbc36 where compId=? and currLine=? and pbc35Id=? and coilIndex >? and coilIndex<? and pbc36Id not in("+conStr+") order by coilIndex";
log.debug("排除分割的钢卷,分割钢卷之间的钢卷"+hql);
List<Tbpbc36> outSc36=this.getHibernateTemplate().find(hql,new Object[]{compId,currLine,pbc35Id,minIndex,maxIndex});
if(!CollectionUtils.isEmpty(outSc36)){
return outSc36;
}
return null;
}
/**
*
* 取分割部分前面,后面的值
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public List<Tbpbc36> getBAc36(String pbc35Id,String minSc36CoilIndex,String maxSc36CoilIndex)throws Exception{
String hql="from Tbpbc36 where pbc35Id=?";
List listParams=new ArrayList();
listParams.add(pbc35Id);
if(StringHelper.isNotEmpty(minSc36CoilIndex)){
hql+=" and coilIndex <? ";
listParams.add(minSc36CoilIndex);
}
if(StringHelper.isNotEmpty(maxSc36CoilIndex)){
hql+=" and coilIndex >? ";
listParams.add(maxSc36CoilIndex);
}
hql+=" order by coilIndex ASC";
List<Tbpbc36> list=this.getHibernateTemplate().find(hql,listParams.toArray());
if(!CollectionUtils.isEmpty(list)){
return list;
}
return null;
}
/**
* 产生一个新的lot:新的lot号为当前机组的最大lot号+1,lot顺序号为被切割lot顺序号+1;
*
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public String getMaxLotNo(String compId,String currLine) throws Exception{
String hql="from Tbpbc35 where compId=? and currLine=? order by lotNo desc";
List<Tbpbc35> list=this.getHibernateTemplate().find(hql,new Object[]{compId,currLine});
String maxLotNo="";//最大顺序号
if(!CollectionUtils.isEmpty(list)){
maxLotNo=list.get(0).getLotNo();
return maxLotNo;
}else{
return null;
}
}
/**
* 先找到切割lot后的前6位相同,顺序号大于切割lot的lot,
* sC35 主表被分割的lot
* sc36TotalentryCoilWgt 切割排程的总重量
* s36totalWorkTime 切割的总时长
* aC36List 主表分割lot从表后面部分需要改变的部分
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
// public Tbpbc35 updateSc35AndSc36(Tbpbc35 sC35,Long s36totalWorkTime,Long sc36TotalentryCoilWgt,List<Tbpbc36> aC36List)throws Exception{
// Long oldWttSeconds=sC35.getWorkTotalTime().longValue()*60;
// int betweenSeconds=(int) (oldWttSeconds-s36totalWorkTime*60);
// Date let=DateUtils.addSeconds(sC35.getLotStartTime(), betweenSeconds);
// sC35.setLotEndTime(let);
// sC35.setLotWgt(sC35.getLotWgt()-sc36TotalentryCoilWgt);
// this.getHibernateTemplate().update(sC35);
// this.getHibernateTemplate().evict(sC35);
// //分割记录从表的改变:开始时间为分割前部分的最大时间,lotIndex接着排
// for(Tbpbc36 ac36:aC36List){
// int c36betweenSecons=(int)(ac36.getWorkTotalTime()*60);
// Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
// ac36.setProdStartDate(psd);
// ac36.setProdEndDate(ped);
// String b6coilIndex=nc36CoilIndex.substring(0,6);
// String a3coilIndex=String.format("%03d",Integer.parseInt(nc36CoilIndex.substring(nc36CoilIndex.length()-3,nc36CoilIndex.length()))+1);
// ac36.setCoilIndex(b6coilIndex+a3coilIndex);
// this.getHibernateTemplate().update(ac36);
// this.getHibernateTemplate().evict(ac36);
// nc36CoilIndex=ac36.getCoilIndex();
// }
//
// return null;
// }
/**
* 新产生的lot
* c35 被切割的lot
* maxLotNo 最大顺序号
* c36 切割出来的排程
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public void saveNewTbc35(String compId,String currLine,Tbpbc35 c35,String maxLotNo,Long sc36TotalentryCoilWgt,Long c36S_workTotalTime,List<Tbpbc36> c36List)throws Exception{
List<Tbpbc35> listC35=new ArrayList();
List<Tbpbc36> listC36=new ArrayList();
Tbpbc35 newC35=new Tbpbc35();
newC35.setPbc35Id(AppUtils.generateUniqueKey());
newC35.setCompId(c35.getCompId());
newC35.setFactoryId(c35.getFactoryId());
newC35.setCurrLine(c35.getCurrLine());
newC35.setCurrMill(c35.getCurrMill());
//lotNo为当前机组最大值+1
String b4newLotNo=maxLotNo.substring(0,4);
String newLotNo=this.getLotNo(maxLotNo);
newC35.setLotNo(newLotNo);
newC35.setLotName(c35.getLotName());
//顺序号
int resoultIndex= Integer.parseInt(c35.getLotIndex().substring(c35.getLotIndex().length()-3, c35.getLotIndex().length()))+1;
String a3=String.format("%03d",resoultIndex);
newC35.setLotIndex(c35.getLotIndex().substring(0,6)+a3);
newC35.setLotWgt(sc36TotalentryCoilWgt);
newC35.setWorkTotalTime(new BigDecimal(c36S_workTotalTime));
newC35.setLotStartTime(c35.getLotEndTime());
int betweenSeconds=(int) (c36S_workTotalTime*60);
Date pet=DateUtils.addSeconds(c35.getLotEndTime(), betweenSeconds);
newC35.setLotEndTime(pet);//结束时间
newC35.setCreateEmp(AppUtils.getLoginUserName());
newC35.setCreateDate(AppUtils.getCurrentDate());
newC35.setLotStatus("01");
// this.getHibernateTemplate().save(newC35);
// this.getHibernateTemplate().evict(newC35);
listC35.add(newC35);
log.debug("--------------------产生新lot完成-------------------------");
//如果切割的后面有排程的话,主表顺序号改变,否则就不需要操作
List<Tbpbc35> listAc35=this.getAC35(newC35,c35, compId, currLine);
if(!CollectionUtils.isEmpty(listAc35)){
String intolotIndex=newC35.getLotIndex();//LotIndex
Date lst=newC35.getLotEndTime();
for(Tbpbc35 ac35:listAc35){
String b6lotIndex=intolotIndex.substring(0,6);
int a3lotIndex=Integer.parseInt(intolotIndex.substring(intolotIndex.length()-3,intolotIndex.length()))+1;
String a3cl=String.format("%03d",a3lotIndex);
ac35.setLotIndex(b6lotIndex+a3cl);
int sb35betweenSeconds=(int) (ac35.getWorkTotalTime().longValue()*60);
Date let=DateUtils.addSeconds(lst,sb35betweenSeconds);
ac35.setLotEndTime(let);
// this.getHibernateTemplate().update(ac35);
// this.getHibernateTemplate().evict(ac35);
listC35.add(ac35);
intolotIndex=ac35.getLotIndex();//重新赋值
lst=ac35.getLotEndTime();
//c36修改
List<Tbpbc36> nuC36List=this.getBAc36(ac35.getPbc35Id(),null, null);
if(!CollectionUtils.isEmpty(nuC36List)){
Date psd=ac35.getLotStartTime();
for(Tbpbc36 c36:nuC36List){
int c36betweenSecons=(int)(c36.getWorkTotalTime()*60);
Date ped=DateUtils.addSeconds(psd,c36betweenSecons);//结束时间
c36.setProdStartDate(psd);
c36.setProdEndDate(ped);
listC36.add(c36);
psd=c36.getProdEndDate();
}
}else{
throw new AppException("this LOT hasn't data , please check! ");
}
}
}else{
}
//新lot的明细数据
Date psd=newC35.getLotStartTime();
String b6nCoilIndex=newC35.getLotIndex().substring(0,6);
String a3nCoilIndex="-001";
for(Tbpbc36 c36:c36List){
c36.setPbc35Id(newC35.getPbc35Id());
c36.setLotNo(newC35.getLotNo());
c36.setLotName(newC35.getLotName());
//顺序
int n=Integer.parseInt(a3nCoilIndex)+1;
String a3nci=String.format("%03d",n);
c36.setCoilIndex(b6nCoilIndex+a3nci);
c36.setCurrLine(newC35.getCurrLine());
c36.setCurrMill(newC35.getCurrMill());
c36.setProdStartDate(psd);
Date ped=DateUtils.addSeconds(psd,(int)(c36.getWorkTotalTime()*60));
c36.setProdEndDate(ped);
c36.setUpdateEmp(AppUtils.getLoginUserName());
c36.setUpdateDate(AppUtils.getCurrentDate());
// this.getHibernateTemplate().saveOrUpdate(c36);
// this.getHibernateTemplate().evict(c36);
listC36.add(c36);
a3nCoilIndex=c36.getCoilIndex().substring(c36.getCoilIndex().length()-3, c36.getCoilIndex().length());
psd=c36.getProdEndDate();
}
this.getHibernateTemplate().saveOrUpdateAll(listC35);
this.getHibernateTemplate().flush();
this.getHibernateTemplate().saveOrUpdateAll(listC36);
this.getHibernateTemplate().flush();
log.debug("--------------------产生新lot明细完成-------------------------");
}
/**
* 根据相应的条件得到一条主表记录,被切割的主表记录
*
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public Tbpbc35 getC35(String compId,String currLine,String pbc35Id) throws Exception{
String hql="from Tbpbc35 where compId=? and currLine=? and pbc35Id=?";
List params=new ArrayList();
params.add(compId);
params.add(currLine);
params.add(pbc35Id);
Tbpbc35 c35=(Tbpbc35) this.getHibernateTemplate().find(hql,params.toArray()).get(0);
return c35;
}
/**
*
* 先找到切割lot后的前6位相同,顺序号大于切割lot的lot,
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-20
* @version 1.0
*/
public List<Tbpbc35> getAC35(Tbpbc35 newC35,Tbpbc35 c35,String compId,String currLine)throws Exception{
String lotIndexLike=newC35.getLotIndex().substring(0,6).toString()+"%";
String notLot="'"+newC35.getPbc35Id()+"'";
String hql="from Tbpbc35 where compId=? and currLine=? and lotIndex like ? and lotIndex >? and pbc35Id not in("+notLot+") order by lotIndex asc";
System.out.println("--------------------------"+c35.getLotIndex());
log.debug("hql:"+hql);
List<Tbpbc35> list=this.getHibernateTemplate().find(hql,new Object[]{compId,currLine,lotIndexLike,c35.getLotIndex()});
if(!CollectionUtils.isEmpty(list)){
return list;
}
return null;
}
/**
*
* 根据最大的lot号
* @file Pbjcc365BO.java
* @author hunter
* @date 2015-1-21
* @version 1.0
*/
public String getLotNo(String maxLotNo)throws Exception{
String newLotNo=null;
String oLotNo=maxLotNo.substring(0,1);
String sLotNo=maxLotNo.substring(1,2);
String tLotNo=maxLotNo.substring(2,3);
String fLotNo=maxLotNo.substring(3,4);
int lastNum=Integer.parseInt(maxLotNo.substring(4,6));
if( (maxLotNo== null)||"ZZZZ99".equals(maxLotNo)) {
newLotNo = "AAAA00";
} else if(0<=lastNum &&lastNum<10){
int newLastNum=lastNum+1;
newLotNo=oLotNo+sLotNo+tLotNo+fLotNo+"0"+newLastNum;
} else if(10<=lastNum&&lastNum<99){
int newLastNum=lastNum+1;
newLotNo=oLotNo+sLotNo+tLotNo+fLotNo+newLastNum;
} else if(lastNum==99){//判断前4位
if(!"Z".equals(fLotNo)){//第四位不为Z,那么最后一位的字母往后排一个
char fLotNoChar=fLotNo.charAt(0);
int fLotNoInt=(int)fLotNoChar;//类型转换后+1
fLotNoInt++;
char newChar=(char)fLotNoInt;
String newString=String.valueOf(newChar);
newLotNo=oLotNo+sLotNo+tLotNo+newString+"00";
}else{ //最后一位为“z”
if(!"Z".equals(tLotNo)){//最后一位为z,且倒数第二位不为z
char tLotNoChar=tLotNo.charAt(0);
int tLotNoInt=(int)tLotNoChar;
tLotNoInt++;
char newChar=(char)tLotNoInt;
String newString=String.valueOf(newChar);
newLotNo=oLotNo+sLotNo+newString+"A"+"00";
}else{//最后一位为z,倒数第二位为z
if(!"Z".equals(sLotNo)){//最后一位为z,倒数第二位为z,且第二位不为z
char sLotNoChar=sLotNo.charAt(0);
int sLotNoInt=(int)sLotNoChar;
sLotNoInt++;
char newChar=(char)sLotNoInt;
String newString=String.valueOf(newChar);
newLotNo=oLotNo+newString+"A"+"A"+"00";
}else{//最后一位为z,倒数第二位为z,且第二位为z
if(!"Z".equals(oLotNo)){//最后一位为z,倒数第二位为z,且第二位为z,第一位不为z
char oLotNoChar=oLotNo.charAt(0);
int oLotNoInt=(int)oLotNoChar;
oLotNoInt++;
char newChar=(char)oLotNoInt;
String newString=String.valueOf(newChar);
newLotNo=newChar+"A"+"A"+"A"+"00";
}
}
}
}
}
return newLotNo;
}
}
逻辑代码片段(自认为很严谨,有兴趣可以看看,提高初学者的代码能力)
原文:http://blog.csdn.net/u011182301/article/details/43153473