/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2020-05-26
 * 描述            ：电量分配
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.tcp.impl;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import market.Com.pb.DoubleUtil;
import market.Com.vo.ResultModel;
import market.tcp.mapper.TcpEleDstMapper;
import market.tcp.service.TcpEleDstService;
import market.tcp.vo.TcpEleDst;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path="TcpEleDstService")
public class TcpEleDstServiceImpl extends BaseServiceImpl<TcpEleDst,Object> implements TcpEleDstService {
	
	
//	@Scheduled(cron="0/1 * * * * ? *")//每天中午9点触发
//	public void doceshi() {
//		System.out.println("每天上午9点触发。。。测试ce's");
//	}
	
	/**
	 * 获取电表的某天的消耗量
	 * @param cp
	 * @return
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	@Scheduled(cron="0 0 9 * * ?")//每天中午9点触发
	public void doInsertEleByMeterno() {
		System.out.println("每天上午9点电量计算触发。。。");
		Date now = new Date();
		String create_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);//归集时间
		//获取时间，昨天
		Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,-1);        
		String work_date = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
		// 本地跑时可用：
		//String work_date = "2022-09-27";// 平时需要注释掉
		// end;
		this.getMapper(TcpEleDstMapper.class).doDeleteTcpEleDst(work_date);
		
		//35kv
		//Ⅰ段进线柜受自6总降6323柜 + Ⅱ段进线柜受自6总降6347柜
		Double ele35Kv1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766681");
		Double ele35Kv2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766689");
			ele35Kv1 = ele35Kv1==null?0d:ele35Kv1;
			ele35Kv2 = ele35Kv2==null?0d:ele35Kv2;
		Double ele35Kv = ele35Kv1 + ele35Kv2;
		doInsertTcpEleDst(work_date, "35kv", "35kv电表采集值", "041709766681 + 041709766689", ele35Kv, "0", null, create_time);
		//中冶新材
		//中冶新材Ⅰ段馈线-轧机 + 中冶新材Ⅱ段馈线-连退
		Double eleZyxc1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041905933198");
		Double eleZyxc2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041905933194");
			eleZyxc1 = eleZyxc1==null?0d:eleZyxc1;
			eleZyxc2 = eleZyxc2==null?0d:eleZyxc2;
		Double eleZyxc = eleZyxc1 + eleZyxc2;
		doInsertTcpEleDst(work_date, "中冶新材", "中冶新材电表采集值", "041905933198 + 041905933194", eleZyxc, "0", null, create_time);		
		//轧机
		//轧机Ⅰ段进线柜 + 轧机Ⅱ段进线柜 
		Double eleZj1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041809905510");
		Double eleZj2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041809905515");
			eleZj1 = eleZj1==null?0d:eleZj1;
			eleZj2 = eleZj2==null?0d:eleZj2;
		Double eleZj = eleZj1 + eleZj2;
		doInsertTcpEleDst(work_date, "轧机", "轧机电表采集值", "041809905510 + 041809905515", eleZj, "0", null, create_time);
		//平整机
		//平整690V整流变压器 + 平整动力变压器 - 7#MCC控制柜（CD跨行车）
		Double elePz1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746201");
		Double elePz2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746199");
			elePz1 = elePz1==null?0d:elePz1;
			elePz2 = elePz2==null?0d:elePz2;
		Double elePz = elePz1 + elePz2;
		doInsertTcpEleDst(work_date, "平整机", "平整机电表采集值", "041701746201 + 041701746199", elePz, "0", null, create_time);
		//退火炉
		//罩退炉1#动力变压器 + 罩退炉2#动力变压器
		Double eleTh1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746207");
		Double eleTh2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746197");
			eleTh1 = eleTh1==null?0d:eleTh1;
			eleTh2 = eleTh2==null?0d:eleTh2;
		Double eleTh = eleTh1 + eleTh2;
		doInsertTcpEleDst(work_date, "退火炉", "退火炉电表采集值", "041701746207 + 041701746197", eleTh, "0", null, create_time);
		//12mm纵剪:12mm纵剪机电源柜
		Double ele12mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053608");
			ele12mm = ele12mm==null?0d:ele12mm;
		doInsertTcpEleDst(work_date, "12mm纵剪", "12mm纵剪电表采集值", "000000053608", ele12mm, "0", null, create_time);	
		//4mm纵剪:4mm纵剪机电源柜
		Double ele4mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053605");
			ele4mm = ele4mm==null?0d:ele4mm;
		doInsertTcpEleDst(work_date, "4mm纵剪", "4mm纵剪电表采集值", "000000053605", ele4mm, "0", null, create_time);
		//3mm横剪:3mm横剪机电源柜
		Double ele3mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053606");
			ele3mm = ele3mm==null?0d:ele3mm;
		doInsertTcpEleDst(work_date, "3mm横剪", "3mm横剪电表采集值", "000000053606", ele3mm, "0", null, create_time);
		//AB跨行车:AB跨行车
		Double eleAB = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053603");
			eleAB = eleAB==null?0d:eleAB;
		doInsertTcpEleDst(work_date, "AB跨行车", "AB跨行车电表采集值", "000000053603", eleAB, "0", null, create_time);
		//BC跨行车:BC跨行车
		Double eleBC = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053602");
			eleBC = eleBC==null?0d:eleBC;	
		doInsertTcpEleDst(work_date, "BC跨行车", "BC跨行车电表采集值", "000000053602", eleBC, "0", null, create_time);
		//CD跨行车:7#MCC控制柜（CD跨行车）
		Double eleCD = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "001403473324");
			eleCD = eleCD==null?0d:eleCD;
		doInsertTcpEleDst(work_date, "CD跨行车", "CD跨行车电表采集值", "001403473324", eleCD, "0", null, create_time);
		//磨辊间:磨辊间
		Double eleMg = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766700");
			eleMg = eleMg==null?0d:eleMg;
		doInsertTcpEleDst(work_date, "磨辊间", "磨辊间电表采集值", "041709766700", eleMg, "0", null, create_time);
		//水泵房
		//循环水泵站Ⅰ段进线柜 + 循环水泵站Ⅱ段进线柜
		Double eleSb1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746202");
		Double eleSb2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746203");
			eleSb1 = eleSb1==null?0d:eleSb1;
			eleSb2 = eleSb2==null?0d:eleSb2;
		Double eleSb = eleSb1 + eleSb2;
		doInsertTcpEleDst(work_date, "水泵房", "水泵房电表采集值", "041701746202 + 041701746203", eleSb, "0", null, create_time);
		//酸洗
		//酸洗1段进线 + 酸洗2段进线 - 冷轧酸再生动力变压器
		Double eleSx1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041703747878");
		Double eleSx2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041703747874");
		Double eleSx3 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041712775514");
			eleSx1 = eleSx1==null?0d:eleSx1;
			eleSx2 = eleSx2==null?0d:eleSx2;
			eleSx3 = eleSx3==null?0d:eleSx3;
		Double eleSx = eleSx1 + eleSx2 - eleSx3;
		doInsertTcpEleDst(work_date, "酸洗", "酸洗电表采集值", "041703747878 + 041703747874 - 041712775514", eleSx, "2", null, create_time);
		
		//************************************		一次分摊			*************************************
		Double eZj = DoubleUtil.round(eleZj /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "轧机", null, null, eZj, "1", null, create_time);
		Double ePz = DoubleUtil.round(elePz /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "平整机", null, null, ePz, "1", null, create_time);
		Double eTh = DoubleUtil.round(eleTh /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "退火炉", null, null, eTh, "1", null, create_time);
		Double e12mm = DoubleUtil.round(ele12mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "12mm纵剪", null, null, e12mm, "1", null, create_time);
		Double e3mm = DoubleUtil.round(ele3mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "3mm横剪", null, null, e3mm, "1", null, create_time);
		Double e4mm = DoubleUtil.round(ele4mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "4mm纵剪", null, null, e4mm, "1", null, create_time);
		Double eAB = DoubleUtil.round(eleAB /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "AB跨行车", null, null, eAB, "1", null, create_time);
		Double eBC = DoubleUtil.round(eleBC /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "BC跨行车", null, null, eBC, "1", null, create_time);
		Double eCD = DoubleUtil.round(eleCD /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "CD跨行车", null, null, eCD, "1", null, create_time);
		Double eMg = DoubleUtil.round(eleMg /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "磨辊间", null, null, eMg, "1", null, create_time);
		Double eSb = DoubleUtil.round(eleSb /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
		doInsertTcpEleDst(work_date, "水泵房", null, null, eSb, "1", null, create_time);
		
		//************************************		二次分摊			*************************************	
		//获取产量
		Double a = this.getMapper(TcpEleDstMapper.class).doGetPz(work_date);//平整机产量=a
		Double b = this.getMapper(TcpEleDstMapper.class).doGetTh(work_date);//退火炉产量=b
		Double c = this.getMapper(TcpEleDstMapper.class).doGet12mm(work_date);//12mm产量=c
		Double d = this.getMapper(TcpEleDstMapper.class).doGet3mm(work_date);//3mm产量=d
		Double e = this.getMapper(TcpEleDstMapper.class).doGet4mm(work_date);//4mm产量=e	
		
		doInsertTcpEleDst(work_date, "轧机", null, null, DoubleUtil.round(eZj + eCD,4), "2", null, create_time);
		//防止产量为0
		if (a+b > 0) {			
			doInsertTcpEleDst(work_date, "平整机", null, null, DoubleUtil.round(ePz + a/(a+b) * eBC,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "退火炉", null, null, DoubleUtil.round(eTh + b/(a+b) * eBC,4), "2", null, create_time);
		}else {
			doInsertTcpEleDst(work_date, "平整机", null, null, DoubleUtil.round(ePz,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "退火炉", null, null, DoubleUtil.round(eTh,4), "2", null, create_time);
		}
		//防止产量为0
		if (c+d+e > 0) {			
			doInsertTcpEleDst(work_date, "12mm纵剪", null, null, DoubleUtil.round(e12mm + c/(c+d+e) * eAB,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "4mm纵剪", null, null, DoubleUtil.round(e4mm + e/(c+d+e) * eAB,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "3mm横剪", null, null, DoubleUtil.round(e3mm + d/(c+d+e) * eAB,4), "2", null, create_time);
		}else {
			doInsertTcpEleDst(work_date, "12mm纵剪", null, null, DoubleUtil.round(e12mm,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "4mm纵剪", null, null, DoubleUtil.round(e4mm,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "3mm横剪", null, null, DoubleUtil.round(e3mm,4), "2", null, create_time);
		}
		doInsertTcpEleDst(work_date, "磨辊间", null, null, DoubleUtil.round(eMg,4), "2", null, create_time);
		doInsertTcpEleDst(work_date, "水泵房", null, null, DoubleUtil.round(eSb,4), "2", null, create_time);
	}
	
	/**
	 * 新增到电表采集表
	 * @param work_date 日期
	 * @param ele_name 采集名称(机台)
	 * @param ele_desc 采集说明
	 * @param meter_no 采集表号
	 * @param ele_num 采集值
	 * @param dst_num 分配次数
	 * @param memo 备注
	 * @param create_time 归集时间
	 */
	private void doInsertTcpEleDst(String work_date,String ele_name,String ele_desc,String meter_no,Double ele_num,String dst_num,String memo,String create_time){
		TcpEleDst ted = new TcpEleDst();
		ted.setWork_date(work_date);
		ted.setEle_name(ele_name);
		ted.setEle_desc(ele_desc);
		ted.setMeter_no(meter_no);
		ted.setEle_num(ele_num);
		ted.setDst_num(dst_num);
		ted.setMemo(memo);
		ted.setCreate_time(create_time);
		this.getMapper(TcpEleDstMapper.class).insert(ted);
	}
	
	public ResultModel doIn() throws Exception{
		ResultModel rm = new ResultModel();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		List<String> dateList = new ArrayList<String>();
		Date dateOne = sdf.parse("2020-05-01");
		Date dateTwo = sdf.parse("2020-10-20");

		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTwo);

		dateList.add("2020-10-20");
		while(calendar.getTime().after(dateOne)){ //倒序时间,顺序after改before其他相应的改动。
			calendar.add(Calendar.DAY_OF_MONTH, -1);
			dateList.add(sdf.format(calendar.getTime()));
		}
		Date now = new Date();
		String create_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);//归集时间
		for (String work_date : dateList) {
			//获取时间，昨天
			Calendar cal=Calendar.getInstance();
	        cal.add(Calendar.DATE,-1);        
			//String work_date = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
			this.getMapper(TcpEleDstMapper.class).doDeleteTcpEleDst(work_date);
			
			//35kv
			//Ⅰ段进线柜受自6总降6323柜 + Ⅱ段进线柜受自6总降6347柜
			Double ele35Kv1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766681");
			Double ele35Kv2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766689");
				ele35Kv1 = ele35Kv1==null?0d:ele35Kv1;
				ele35Kv2 = ele35Kv2==null?0d:ele35Kv2;
			Double ele35Kv = ele35Kv1 + ele35Kv2;
			doInsertTcpEleDst(work_date, "35kv", "35kv电表采集值", "041709766681 + 041709766689", ele35Kv, "0", null, create_time);
			//中冶新材
			//中冶新材Ⅰ段馈线-轧机 + 中冶新材Ⅱ段馈线-连退
			Double eleZyxc1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041905933198");
			Double eleZyxc2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041905933194");
				eleZyxc1 = eleZyxc1==null?0d:eleZyxc1;
				eleZyxc2 = eleZyxc2==null?0d:eleZyxc2;
			Double eleZyxc = eleZyxc1 + eleZyxc2;
			doInsertTcpEleDst(work_date, "中冶新材", "中冶新材电表采集值", "041905933198 + 041905933194", eleZyxc, "0", null, create_time);		
			//轧机
			//轧机Ⅰ段进线柜 + 轧机Ⅱ段进线柜 
			Double eleZj1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041809905510");
			Double eleZj2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041809905515");
				eleZj1 = eleZj1==null?0d:eleZj1;
				eleZj2 = eleZj2==null?0d:eleZj2;
			Double eleZj = eleZj1 + eleZj2;
			doInsertTcpEleDst(work_date, "轧机", "轧机电表采集值", "041809905510 + 041809905515", eleZj, "0", null, create_time);
			//平整机
			//平整690V整流变压器 + 平整动力变压器 - 7#MCC控制柜（CD跨行车）
			Double elePz1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746201");
			Double elePz2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746199");
				elePz1 = elePz1==null?0d:elePz1;
				elePz2 = elePz2==null?0d:elePz2;
			Double elePz = elePz1 + elePz2;
			doInsertTcpEleDst(work_date, "平整机", "平整机电表采集值", "041701746201 + 041701746199", elePz, "0", null, create_time);
			//退火炉
			//罩退炉1#动力变压器 + 罩退炉2#动力变压器
			Double eleTh1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746207");
			Double eleTh2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746197");
				eleTh1 = eleTh1==null?0d:eleTh1;
				eleTh2 = eleTh2==null?0d:eleTh2;
			Double eleTh = eleTh1 + eleTh2;
			doInsertTcpEleDst(work_date, "退火炉", "退火炉电表采集值", "041701746207 + 041701746197", eleTh, "0", null, create_time);
			//12mm纵剪:12mm纵剪机电源柜
			Double ele12mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053608");
				ele12mm = ele12mm==null?0d:ele12mm;
			doInsertTcpEleDst(work_date, "12mm纵剪", "12mm纵剪电表采集值", "000000053608", ele12mm, "0", null, create_time);	
			//4mm纵剪:4mm纵剪机电源柜
			Double ele4mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053605");
				ele4mm = ele4mm==null?0d:ele4mm;
			doInsertTcpEleDst(work_date, "4mm纵剪", "4mm纵剪电表采集值", "000000053605", ele4mm, "0", null, create_time);
			//3mm横剪:3mm横剪机电源柜
			Double ele3mm = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053606");
				ele3mm = ele3mm==null?0d:ele3mm;
			doInsertTcpEleDst(work_date, "3mm横剪", "3mm横剪电表采集值", "000000053606", ele3mm, "0", null, create_time);
			//AB跨行车:AB跨行车
			Double eleAB = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053603");
				eleAB = eleAB==null?0d:eleAB;
			doInsertTcpEleDst(work_date, "AB跨行车", "AB跨行车电表采集值", "000000053603", eleAB, "0", null, create_time);
			//BC跨行车:BC跨行车
			Double eleBC = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "000000053602");
				eleBC = eleBC==null?0d:eleBC;	
			doInsertTcpEleDst(work_date, "BC跨行车", "BC跨行车电表采集值", "000000053602", eleBC, "0", null, create_time);
			//CD跨行车:7#MCC控制柜（CD跨行车）
			Double eleCD = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "001403473324");
				eleCD = eleCD==null?0d:eleCD;
			doInsertTcpEleDst(work_date, "CD跨行车", "CD跨行车电表采集值", "001403473324", eleCD, "0", null, create_time);
			//磨辊间:磨辊间
			Double eleMg = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041709766700");
				eleMg = eleMg==null?0d:eleMg;
			doInsertTcpEleDst(work_date, "磨辊间", "磨辊间电表采集值", "041709766700", eleMg, "0", null, create_time);
			//水泵房
			//循环水泵站Ⅰ段进线柜 + 循环水泵站Ⅱ段进线柜
			Double eleSb1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746202");
			Double eleSb2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041701746203");
				eleSb1 = eleSb1==null?0d:eleSb1;
				eleSb2 = eleSb2==null?0d:eleSb2;
			Double eleSb = eleSb1 + eleSb2;
			doInsertTcpEleDst(work_date, "水泵房", "水泵房电表采集值", "041701746202 + 041701746203", eleSb, "0", null, create_time);
			//酸洗
			//酸洗1段进线 + 酸洗2段进线 - 冷轧酸再生动力变压器
			Double eleSx1 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041703747878");
			Double eleSx2 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041703747874");
			Double eleSx3 = this.getMapper(TcpEleDstMapper.class).doQueryEleByMeterno(work_date, "041712775514");
				eleSx1 = eleSx1==null?0d:eleSx1;
				eleSx2 = eleSx2==null?0d:eleSx2;
				eleSx3 = eleSx3==null?0d:eleSx3;
			Double eleSx = eleSx1 + eleSx2 - eleSx3;
			doInsertTcpEleDst(work_date, "酸洗", "酸洗电表采集值", "041703747878 + 041703747874 - 041712775514", eleSx, "2", null, create_time);
			
			//************************************		一次分摊			*************************************
			Double eZj = DoubleUtil.round(eleZj /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "轧机", null, null, eZj, "1", null, create_time);
			Double ePz = DoubleUtil.round(elePz /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "平整机", null, null, ePz, "1", null, create_time);
			Double eTh = DoubleUtil.round(eleTh /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "退火炉", null, null, eTh, "1", null, create_time);
			Double e12mm = DoubleUtil.round(ele12mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "12mm纵剪", null, null, e12mm, "1", null, create_time);
			Double e3mm = DoubleUtil.round(ele3mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "3mm横剪", null, null, e3mm, "1", null, create_time);
			Double e4mm = DoubleUtil.round(ele4mm /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "4mm纵剪", null, null, e4mm, "1", null, create_time);
			Double eAB = DoubleUtil.round(eleAB /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "AB跨行车", null, null, eAB, "1", null, create_time);
			Double eBC = DoubleUtil.round(eleBC /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "BC跨行车", null, null, eBC, "1", null, create_time);
			Double eCD = DoubleUtil.round(eleCD /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "CD跨行车", null, null, eCD, "1", null, create_time);
			Double eMg = DoubleUtil.round(eleMg /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "磨辊间", null, null, eMg, "1", null, create_time);
			Double eSb = DoubleUtil.round(eleSb /(eleZj + elePz + eleTh+ ele12mm + ele4mm + ele3mm + eleAB + eleBC + eleCD + eleMg + eleSb) * (ele35Kv - eleZyxc), 4);
			doInsertTcpEleDst(work_date, "水泵房", null, null, eSb, "1", null, create_time);
			
			//************************************		二次分摊			*************************************	
			//获取产量
			Double a = this.getMapper(TcpEleDstMapper.class).doGetPz(work_date);//平整机产量=a
			Double b = this.getMapper(TcpEleDstMapper.class).doGetTh(work_date);//退火炉产量=b
			Double c = this.getMapper(TcpEleDstMapper.class).doGet12mm(work_date);//12mm产量=c
			Double d = this.getMapper(TcpEleDstMapper.class).doGet3mm(work_date);//3mm产量=d
			Double e = this.getMapper(TcpEleDstMapper.class).doGet4mm(work_date);//4mm产量=e	
			
			doInsertTcpEleDst(work_date, "轧机", null, null, DoubleUtil.round(eZj + eCD,4), "2", null, create_time);
			//防止产量为0
			if (a+b > 0) {			
				doInsertTcpEleDst(work_date, "平整机", null, null, DoubleUtil.round(ePz + a/(a+b) * eBC,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "退火炉", null, null, DoubleUtil.round(eTh + b/(a+b) * eBC,4), "2", null, create_time);
			}else {
				doInsertTcpEleDst(work_date, "平整机", null, null, DoubleUtil.round(ePz,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "退火炉", null, null, DoubleUtil.round(eTh,4), "2", null, create_time);
			}
			//防止产量为0
			if (c+d+e > 0) {			
				doInsertTcpEleDst(work_date, "12mm纵剪", null, null, DoubleUtil.round(e12mm + c/(c+d+e) * eAB,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "4mm纵剪", null, null, DoubleUtil.round(e4mm + e/(c+d+e) * eAB,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "3mm横剪", null, null, DoubleUtil.round(e3mm + d/(c+d+e) * eAB,4), "2", null, create_time);
			}else {
				doInsertTcpEleDst(work_date, "12mm纵剪", null, null, DoubleUtil.round(e12mm,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "4mm纵剪", null, null, DoubleUtil.round(e4mm,4), "2", null, create_time);
				doInsertTcpEleDst(work_date, "3mm横剪", null, null, DoubleUtil.round(e3mm,4), "2", null, create_time);
			}
			doInsertTcpEleDst(work_date, "磨辊间", null, null, DoubleUtil.round(eMg,4), "2", null, create_time);
			doInsertTcpEleDst(work_date, "水泵房", null, null, DoubleUtil.round(eSb,4), "2", null, create_time);
		
		}
		rm.setState("200");
		rm.setMsgInfo("重新归集成功");
		return rm;
	}
		
	

}
