/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2019-12-19
 * 描述            ：酸洗重量保存
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Pickle.Performance.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Executors;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmHzTempMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmHzTemp;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Performance.vo.MesPrdDetailReport;
import market.Mes.Pickle.Performance.mapper.MesPlmDMapper;
import market.Mes.Pickle.Performance.mapper.MesPlmMMapper;
import market.Mes.Pickle.Performance.mapper.MesPlmWgtMapper;
import market.Mes.Pickle.Performance.mapper.Tbs02L2PltcmReceiveDataMapper;
import market.Mes.Pickle.Performance.service.MesSxWeightService;
import market.Mes.Pickle.Performance.vo.MesPlmD;
import market.Mes.Pickle.Performance.vo.MesPlmM;
import market.Mes.Pickle.Performance.vo.MesSxWeight;
import market.Mes.Pickle.Performance.vo.Tbs02L2PltcmProSeq;
import market.Mes.Pickle.Performance.vo.Tbs02L2PltcmReceiveData;
import market.Mes.Pickle.Performance.vo.Tbs02PltcmL2SendPrdData;

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

@RemoteService(path="MesSxWeightService")
public class MesSxWeightServiceImpl extends BaseServiceImpl<MesSxWeight,Object> implements MesSxWeightService {
		
	/**
	  * 关闭酸洗二级的资源
	  * @param rs
	  * @param conn
	  * @param stmt
	  */
	public void close(ResultSet rs, Connection conn, Statement stmt) {
		try {
			if (rs != null)
				rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (stmt != null)
				stmt.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (conn != null)
				conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	 
	 /**
	  * 建立酸洗二级的连接
	  * @return
	  */
	public Connection getConnection(){
		Connection conn=null;		  
		try {
//			System.out.println("开始连接。。。");
			// 设置连接超时时间为15000毫秒 20240318刘侣 
			DriverManager.setLoginTimeout(15);
			// ?oracle.net.CONNECT_TIMEOUT=20000
			String url="jdbc:oracle:thin:@10.160.82.122:1521:pcs";
			String user="PCS";
			String password="newbrp666";			  
			Class.forName("oracle.jdbc.driver.OracleDriver");//加载数据驱动
			
//			Date startTime = new Date();
			
			conn = DriverManager.getConnection(url, user, password);// 连接数据库
			
//			Date endTime = new Date();
	        
	        // 计算时间差并打印
//	        long timeDifference = endTime.getTime() - startTime.getTime();
//	        System.out.println("连接数据库时间差为：" + timeDifference + "毫秒");
			
			conn.setNetworkTimeout(Executors.newSingleThreadExecutor(), 30000);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("加载酸洗二级数据库驱动失败");
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("连接酸洗二级数据库失败");
		}
		return conn;
	}
	
	 /**
	  * 发送酸洗顺序
	  * @param t
	  */
	public ResultModel doSendSxSeqInfo(Tbs02L2PltcmProSeq t) {
		ResultModel rm = new ResultModel();		 
		Connection connection=getConnection();
	 	String sql="insert into tbs02_l2_pltcm_pro_seq(trans_dtime,seq_no,msg_flag,no_coils,coil_id1,coil_id2,coil_id3,coil_id4,coil_id5,coil_id6,coil_id7,coil_id8,coil_id9,coil_id10,"
	     		+ "coil_id11,coil_id12,coil_id13,coil_id14,coil_id15,coil_id16,coil_id17,coil_id18,coil_id19,coil_id20,"
	     		+ "coil_id21,coil_id22,coil_id23,coil_id24,coil_id25,coil_id26,coil_id27,coil_id28,coil_id29,coil_id30,"
	     		+ "coil_id31,coil_id32,coil_id33,coil_id34,coil_id35,coil_id36,coil_id37,coil_id38,coil_id39,coil_id40,"
	     		+ "coil_id41,coil_id42,coil_id43,coil_id44,coil_id45,coil_id46,coil_id47,coil_id48,coil_id49,coil_id50,"
	     		+ "coil_id51,coil_id52,coil_id53,coil_id54,coil_id55,coil_id56,coil_id57,coil_id58,coil_id59,coil_id60,"
	     		+ "coil_id61,coil_id62,coil_id63,coil_id64,coil_id65,coil_id66,coil_id67,coil_id68,coil_id69,coil_id70,"
	     		+ "coil_id71,coil_id72,coil_id73,coil_id74,coil_id75,coil_id76,coil_id77,coil_id78,coil_id79,coil_id80,"
	     		+ "coil_id81,coil_id82,coil_id83,coil_id84,coil_id85,coil_id86,coil_id87,coil_id88,coil_id89,coil_id90,"
	     		+ "coil_id91,coil_id92,coil_id93,coil_id94,coil_id95,coil_id96,coil_id97,coil_id98,coil_id99,coil_id100)values(?,?,?,?,"
	     		+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
	     		+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
	     		+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
	     		+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
	     		+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement preparedStatement = null;
	 	try {	    	 
	    	preparedStatement = connection.prepareStatement(sql);
	    	
            // 设置查询超时时间为15秒：20240929刘侣
//         	preparedStatement.setQueryTimeout(30);
	    	
	    	preparedStatement.setDate(1, new java.sql.Date(System.currentTimeMillis()));//记录传送时间
	    	preparedStatement.setLong(2, t.getSeq_no());//有效标志
	    	preparedStatement.setString(3, "1");//访问标识
	    	preparedStatement.setLong(4, t.getNo_coils());//钢卷数
	    	preparedStatement.setString(5, t.getCoil_id1());//卷1
	    	preparedStatement.setString(6, t.getCoil_id2());//卷2
	    	preparedStatement.setString(7, t.getCoil_id3());//卷3
	    	preparedStatement.setString(8, t.getCoil_id4());//卷4
	    	preparedStatement.setString(9, t.getCoil_id5());//卷5
	    	preparedStatement.setString(10, t.getCoil_id6());//卷6
	    	preparedStatement.setString(11, t.getCoil_id7());//卷7
	    	preparedStatement.setString(12, t.getCoil_id8());//卷8
	    	preparedStatement.setString(13, t.getCoil_id9());//卷9
	    	preparedStatement.setString(14, t.getCoil_id10());//卷10
	         
	    	preparedStatement.setString(15, t.getCoil_id11());//卷1
	    	preparedStatement.setString(16, t.getCoil_id12());//卷2
	    	preparedStatement.setString(17, t.getCoil_id13());//卷3
	    	preparedStatement.setString(18, t.getCoil_id14());//卷4
	    	preparedStatement.setString(19, t.getCoil_id15());//卷5
	    	preparedStatement.setString(20, t.getCoil_id16());//卷6
	    	preparedStatement.setString(21, t.getCoil_id17());//卷7
	    	preparedStatement.setString(22, t.getCoil_id18());//卷8
	    	preparedStatement.setString(23, t.getCoil_id19());//卷9
	    	preparedStatement.setString(24, t.getCoil_id20());//卷10
         
	    	preparedStatement.setString(25, t.getCoil_id21());//卷1
	    	preparedStatement.setString(26, t.getCoil_id22());//卷2
	    	preparedStatement.setString(27, t.getCoil_id23());//卷3
	    	preparedStatement.setString(28, t.getCoil_id24());//卷4
	    	preparedStatement.setString(29, t.getCoil_id25());//卷5
	    	preparedStatement.setString(30, t.getCoil_id26());//卷6
	    	preparedStatement.setString(31, t.getCoil_id27());//卷7
	    	preparedStatement.setString(32, t.getCoil_id28());//卷8
	    	preparedStatement.setString(33, t.getCoil_id29());//卷9
	    	preparedStatement.setString(34, t.getCoil_id30());//卷10
	         
	    	preparedStatement.setString(35, t.getCoil_id31());//卷1
	    	preparedStatement.setString(36, t.getCoil_id32());//卷2
	    	preparedStatement.setString(37, t.getCoil_id33());//卷3
	    	preparedStatement.setString(38, t.getCoil_id34());//卷4
	    	preparedStatement.setString(39, t.getCoil_id35());//卷5
	    	preparedStatement.setString(40, t.getCoil_id36());//卷6
	    	preparedStatement.setString(41, t.getCoil_id37());//卷7
	    	preparedStatement.setString(42, t.getCoil_id38());//卷8
	    	preparedStatement.setString(43, t.getCoil_id39());//卷9
	    	preparedStatement.setString(44, t.getCoil_id40());//卷10
         
	    	preparedStatement.setString(45, t.getCoil_id41());//卷1
	    	preparedStatement.setString(46, t.getCoil_id42());//卷2
	    	preparedStatement.setString(47, t.getCoil_id43());//卷3
	    	preparedStatement.setString(48, t.getCoil_id44());//卷4
         	preparedStatement.setString(49, t.getCoil_id45());//卷5
         	preparedStatement.setString(50, t.getCoil_id46());//卷6
         	preparedStatement.setString(51, t.getCoil_id47());//卷7
         	preparedStatement.setString(52, t.getCoil_id48());//卷8
         	preparedStatement.setString(53, t.getCoil_id49());//卷9
         	preparedStatement.setString(54, t.getCoil_id50());//卷10
         
         	preparedStatement.setString(55, t.getCoil_id51());//卷1
         	preparedStatement.setString(56, t.getCoil_id52());//卷2
         	preparedStatement.setString(57, t.getCoil_id53());//卷3
         	preparedStatement.setString(58, t.getCoil_id54());//卷4
         	preparedStatement.setString(59, t.getCoil_id55());//卷5
         	preparedStatement.setString(60, t.getCoil_id56());//卷6
         	preparedStatement.setString(61, t.getCoil_id57());//卷7
         	preparedStatement.setString(62, t.getCoil_id58());//卷8
         	preparedStatement.setString(63, t.getCoil_id59());//卷9
         	preparedStatement.setString(64, t.getCoil_id60());//卷10
         
         	preparedStatement.setString(65, t.getCoil_id61());//卷1
         	preparedStatement.setString(66, t.getCoil_id62());//卷2
         	preparedStatement.setString(67, t.getCoil_id63());//卷3
         	preparedStatement.setString(68, t.getCoil_id64());//卷4
         	preparedStatement.setString(69, t.getCoil_id65());//卷5
         	preparedStatement.setString(70, t.getCoil_id66());//卷6
         	preparedStatement.setString(71, t.getCoil_id67());//卷7
         	preparedStatement.setString(72, t.getCoil_id68());//卷8
         	preparedStatement.setString(73, t.getCoil_id69());//卷9
         	preparedStatement.setString(74, t.getCoil_id70());//卷10
         
         	preparedStatement.setString(75, t.getCoil_id71());//卷1
         	preparedStatement.setString(76, t.getCoil_id72());//卷2
         	preparedStatement.setString(77, t.getCoil_id73());//卷3
         	preparedStatement.setString(78, t.getCoil_id74());//卷4
         	preparedStatement.setString(79, t.getCoil_id75());//卷5
         	preparedStatement.setString(80, t.getCoil_id76());//卷6
         	preparedStatement.setString(81, t.getCoil_id77());//卷7
         	preparedStatement.setString(82, t.getCoil_id78());//卷8
         	preparedStatement.setString(83, t.getCoil_id79());//卷9
         	preparedStatement.setString(84, t.getCoil_id80());//卷10
	         
         	preparedStatement.setString(85, t.getCoil_id81());//卷1
         	preparedStatement.setString(86, t.getCoil_id82());//卷2
         	preparedStatement.setString(87, t.getCoil_id83());//卷3
         	preparedStatement.setString(88, t.getCoil_id84());//卷4
         	preparedStatement.setString(89, t.getCoil_id85());//卷5
         	preparedStatement.setString(90, t.getCoil_id86());//卷6
         	preparedStatement.setString(91, t.getCoil_id87());//卷7
         	preparedStatement.setString(92, t.getCoil_id88());//卷8
         	preparedStatement.setString(93, t.getCoil_id89());//卷9
         	preparedStatement.setString(94, t.getCoil_id90());//卷10
	         
         	preparedStatement.setString(95, t.getCoil_id91());//卷1
         	preparedStatement.setString(96, t.getCoil_id92());//卷2
         	preparedStatement.setString(97, t.getCoil_id93());//卷3
         	preparedStatement.setString(98, t.getCoil_id94());//卷4
         	preparedStatement.setString(99, t.getCoil_id95());//卷5
         	preparedStatement.setString(100, t.getCoil_id96());//卷6
         	preparedStatement.setString(101, t.getCoil_id97());//卷7
         	preparedStatement.setString(102, t.getCoil_id98());//卷8
         	preparedStatement.setString(103, t.getCoil_id99());//卷9
         	preparedStatement.setString(104, t.getCoil_id100());//卷10
         	preparedStatement.executeUpdate();
         	System.out.println("插入酸洗顺序成功");	         
	 	} catch (SQLException e) {
        	rm.setState("500");
            e.printStackTrace();
        }finally{
        	close(null, connection, preparedStatement);
        }
		rm.setState("200");
		rm.setMsgInfo("插入酸洗计划接收表成功");
	 	return rm;
    }
	 
	 /**
	  * 发送酸洗计划
	  * @param t
	  */
	 public ResultModel doSendSxPlanInfo(Tbs02L2PltcmReceiveData t) {
		 ResultModel rm = new ResultModel();	
		 rm.setState("200");
	     rm.setMsgInfo("插入酸洗计划接收表成功");
		 Connection connection=getConnection();
	     String sql="insert into tbs02_l2_pltcm_receive_data(fid,flag,coil_no,alloy_grd,coil_wth,coil_thk,coil_india,coil_outdia,reser1,reser2,reser3,c_coil_no,standard_no,order_wth,order_thk,coil_wgt,coil_len)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	     PreparedStatement preparedStatement = null;
	     try {	    	 
	    	 preparedStatement = connection.prepareStatement(sql);
	    	 
             // 设置查询超时时间为15秒：20240929刘侣
//         	 preparedStatement.setQueryTimeout(15);
	    	 
	         preparedStatement.setString(1, t.getFid());//主键ID
	         preparedStatement.setString(2, "1");//有效标志
	         preparedStatement.setString(3, t.getCoil_no());//钢卷编号
	         // 避免牌号过长导致下发不了二级，故对传入二级牌号长度做限制：20220715 treals
	         // s.length() > 10 ? s.substring(0, 10) : s  t.getAlloy_grd()
	         preparedStatement.setString(4, t.getAlloy_grd().length() > 10 ? t.getAlloy_grd().substring(0, 10) : t.getAlloy_grd());//合金牌号
	         preparedStatement.setString(5, t.getCoil_wth());//宽度(mm)
	         preparedStatement.setString(6, t.getCoil_thk());//厚度(mm)
	         preparedStatement.setString(7, t.getCoil_india());//内径(mm)
	         preparedStatement.setString(8, t.getCoil_outdia());//外径(mm)
	         preparedStatement.setString(9, null);//预留1
	         preparedStatement.setString(10, t.getReser2());//预留2
	         preparedStatement.setString(11, t.getReser3());//预留3
	         preparedStatement.setString(12, t.getC_coil_no());//成品卷号
	         preparedStatement.setString(13, t.getStandard_no());//标准号
	         preparedStatement.setString(14, t.getOrder_wth());//订单宽度(mm)
	         preparedStatement.setString(15, t.getOrder_thk());//订单厚度(mm)
	         preparedStatement.setString(16, t.getCoil_wgt());//热卷重量(kg)
	         preparedStatement.setString(17, t.getCoil_len());//热卷长度(m)
	         preparedStatement.executeUpdate();
	         System.out.println("插入酸洗计划接收表成功");	         
        } catch (SQLException e) {
        	rm.setState("500");
   	     	rm.setMsgInfo("插入酸洗二级计划接收表失败");
            e.printStackTrace();
        }finally{
        	close(null, connection, preparedStatement);
        }
	     
	    return rm;
    }
	  
	 /**
	  * 删除酸洗计划
	  * @param id
	  */
	 public ResultModel doCancelSendPlanSxInfo(String fid) {
		 ResultModel rm = new ResultModel();
		 Connection connection=getConnection();
	     String sql="delete from tbs02_l2_pltcm_receive_data where fid=?";
	     PreparedStatement preparedStatement=null;
	     try {	    	 
	         preparedStatement=connection.prepareStatement(sql);
	         
             // 设置查询超时时间为15秒：20240929刘侣
//         	 preparedStatement.setQueryTimeout(15);
	         
	         preparedStatement.setString(1,fid);
	         preparedStatement.executeQuery();
	         System.out.println("删除酸洗计划成功");
	     } catch (SQLException e) {	    	 
             e.printStackTrace();
         }finally {
        	 close(null, connection, preparedStatement);
         }	 
	     rm.setState("200");
	     rm.setMsgInfo("删除酸洗计划成功");
	     return rm;
    }
	 
	 /**
	  * 删除酸洗计划by coil_no
	  * @param id
	  */
	 public ResultModel doCancelSendPlanSxInfoByCoilno(String coil_no) {
		 ResultModel rm = new ResultModel();
		 Connection connection=getConnection();
	     String sql="delete from tbs02_l2_pltcm_receive_data where C_COIL_NO=?";
	     PreparedStatement preparedStatement=null;
	     try {	    	 
	         preparedStatement=connection.prepareStatement(sql);
	         
	         // 设置查询超时时间为15秒：20240929刘侣
//	         preparedStatement.setQueryTimeout(15);
	         
	         preparedStatement.setString(1,coil_no);
	         preparedStatement.executeQuery();
	         System.out.println("删除酸洗计划成功");
	     } catch (SQLException e) {	    	 
             e.printStackTrace();
         }finally {
        	 close(null, connection, preparedStatement);
         }	 
	     rm.setState("200");
	     rm.setMsgInfo("删除酸洗计划成功coilno");
	     return rm;
    }
	 
	 /**
	  * 删除酸洗顺序
	  * @param id
	  */
	 public ResultModel doCancelSendSeqInfo(String seqno) {
		 ResultModel rm = new ResultModel();
		 Connection connection=getConnection();
	     String sql="delete from tbs02_l2_pltcm_pro_seq where seq_no = ?";
	     PreparedStatement preparedStatement=null;
	     try {	    	 
	         preparedStatement=connection.prepareStatement(sql);
	         
	         // 设置查询超时时间为15秒：20240929刘侣
//	         preparedStatement.setQueryTimeout(15);
	         
	         preparedStatement.setString(1,seqno);
	         preparedStatement.executeQuery();
	         System.out.println("删除酸洗顺序成功");
	     } catch (SQLException e) {	    	 
             e.printStackTrace();
         }finally {
        	 close(null, connection, preparedStatement);
         }	  
	     rm.setState("200");
	     rm.setMsgInfo("删除酸洗顺序成功");
	     return rm;
    }
	 
	 /**
	  * 删除酸洗二级卷信息
	  * @param coil_id
	  * @return
	  */
	 public ResultModel doCancelSendCoilInfo(String coil_id) {
		 ResultModel rm = new ResultModel();
		 Connection connection=getConnection();
	     String sql="delete from tbl_coil_pdi where coil_id = ?";
	     PreparedStatement preparedStatement=null;
	     try {	    	 
	         preparedStatement=connection.prepareStatement(sql);
	         
	         // 设置查询超时时间为15秒：20240929刘侣
//	         preparedStatement.setQueryTimeout(15);
	         
	         preparedStatement.setString(1,coil_id+"0");
	         preparedStatement.executeQuery();
	         System.out.println("删除酸洗卷信息成功");
	     } catch (SQLException e) {	    	 
             e.printStackTrace();
         }finally {
        	 close(null, connection, preparedStatement);
         }	
	     rm.setState("200");
	     rm.setMsgInfo("删除酸洗卷信息成功");
	     return rm;
    }
	 
	 /**
	  * MES系统的二级称重数据自动获取
	  * @param cp
	  * @return
	  */
	 public ResultModel doUpdateMesPlmDInfo(CommonPage<Tbs02PltcmL2SendPrdData> cp) {
			ResultModel rm = new ResultModel();
			String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			rm.setState("200");
	        rm.setMsgInfo("获取2级数据成功");
	        Tbs02PltcmL2SendPrdData send  = cp.getObject();

	        // 判断该用户是不是属于酸洗机组的，不是的话就不用去获取了；
	        int userNum = this.getMapper(MesPlmMMapper.class).getUserOrg(username);
	        if (userNum <= 0) {
	        	rm.setState("200");
				rm.setMsgInfo("该用户不属于酸洗机组，不需要触发自动获取二级数据");
				return rm;
	        }
	        
	        MesPlmD mpd1 = this.getMapper(MesPlmDMapper.class).findById(send.getCoil_no());
	        if (mpd1==null) {
	        	rm.setState("500");
				rm.setMsgInfo("子卷信息未找到");
				return rm;
			}
	        //1.判断是否手动保存过重量
	        String condition = "process_no = '"+mpd1.getProcess_no()+"'";
	        int count = this.getMapper(MesPlmWgtMapper.class).countWithCondition(null, condition);
	        if (count > 0) {
				rm.setState("500");
				rm.setMsgInfo("卷号【"+mpd1.getCoil_no()+"】存在手动保存的重量记录，无法自动更新重量信息，请在【酸洗称重作业】界面修改重量");
				return rm;
			}
	        //2.判断物料是否交工（20200727 出现过自动改了重量，但是数据已经进库存的问题）
	        condition = "process_no = '"+mpd1.getProcess_no()+"' and hand_over_status = '1'";
	        int count1 = this.getMapper(MesPlmMMapper.class).countWithCondition(null, condition);
	        if (count1 > 0) {
				rm.setState("500");
				//20200729 去除提示消息，防止提示信息重复
				//rm.setMsgInfo("卷号【"+mpd1.getCoil_no()+"】已经交工，无法自动更新重量信息，请先取消交工");
				return rm;
			}
	        
	        //3.获取酸洗二级的重量信息
	        Connection connection = getConnection();
	        //准备sql语句
	        String sql = "select * from tbs02_pltcm_l2_send_prd_data where coil_no = ?";
	        //创建语句传输对象
	        PreparedStatement preparedStatement = null;
	        ResultSet resultSet = null;
	        try {
	            preparedStatement = connection.prepareStatement(sql);
	            
	            // 设置查询超时时间为15秒：20240929刘侣
//	         	preparedStatement.setQueryTimeout(15);
	            
	            preparedStatement.setString(1, send.getCoil_no());
	            resultSet = preparedStatement.executeQuery();
	            
	            while(resultSet.next()) {
	            	String coil_wgt = resultSet.getString("COIL_WGT");
	            	String coil_thk = resultSet.getString("COIL_THK");
	            	String coil_wth = resultSet.getString("COIL_WTH");
	            	String coil_len = resultSet.getString("COIL_LEN");
	            	String coil_inn = resultSet.getString("COIL_INDIA");
	            	String coil_out = resultSet.getString("COIL_OUTDIA");
	            	Date create_time = resultSet.getTimestamp("CREATE_TIME");
	            	
	            	MesPlmD mpd = new MesPlmD();
	   	    	 	mpd.setCoil_no(send.getCoil_no());
	   	    	 	mpd.setCoil_act_wgt(coil_wgt==null?0:Double.parseDouble(coil_wgt));
	   	    	 	mpd.setCoil_thr_wgt(coil_wgt==null?0:Double.parseDouble(coil_wgt));
	   	    	 	mpd.setAct_thk(coil_thk==null?0:Double.parseDouble(coil_thk));
	   	    	 	mpd.setAct_wdt(coil_wth==null?0:Double.parseDouble(coil_wth));
	   	    	 	mpd.setAct_len(coil_len==null?0:1000 * Double.parseDouble(coil_len));//长度m转换为mm
	   	    	 	mpd.setAct_inn_dia(coil_inn==null?0:Double.parseDouble(coil_inn));
	   	    	 	mpd.setAct_out_dia(coil_out==null?0:Double.parseDouble(coil_out));
	   	    	 	mpd.setCoil_wgt_time(create_time);//保存称重时间
	   	    	 	this.getMapper(MesPlmDMapper.class).update(mpd);  
	   	    	 	
	   	    	 	//调整主表的时间，方便酸洗人员进行外观和公差的检验
	   	    	 	MesPlmM mpm = new MesPlmM();
	   	    	 	mpm.setProcess_no(mpd1.getProcess_no());
	   	    	 	mpm.setFeeding_time(create_time);
	   	    	 	this.getMapper(MesPlmMMapper.class).update(mpm);
	   	    	 	//rm.setData(coil_wgt);//返回重量值给前端，防止酸洗二级不给重量
	            }
	        } catch (SQLException e) {
	            e.printStackTrace();
	            rm.setState("500");
				rm.setMsgInfo(e.getMessage());
	        }finally {
	        	close(resultSet, connection, preparedStatement);
	        }
	        
	        return  rm;
		}
	 
	 /**
	  * 获取二级系统还未酸洗的数据
	  * @param cp
	  * @return
	  */
	 public List<String> doQuaryCoilPdiInfo() {
		 Connection connection = getConnection();
		 List<String> coilList = new ArrayList<String>();
		 //准备sql语句
		 String sql = "select * from tbl_coil_pdi where status_id = '1' order by seq";
		 //创建语句传输对象
		 PreparedStatement preparedStatement = null;
		 ResultSet resultSet = null;
		 try {
			 preparedStatement = connection.prepareStatement(sql);
			 
	         // 设置查询超时时间为15秒：20240929刘侣
//	         preparedStatement.setQueryTimeout(15);
			 
			 //preparedStatement.setString(1, send.getCoil_no());
			 resultSet = preparedStatement.executeQuery();
			 while(resultSet.next()) {
				  
				 String coil_no = resultSet.getString("COIL_ID");
				 //卷号需要去除最后一位(2级系统默认新增了最后一位)
				 coil_no = coil_no.substring(0, coil_no.length()-1);
				 coilList.add(coil_no);	            		   	    	 		    	 
			 }
		 } catch (SQLException e) {
			 e.printStackTrace();
		 } finally {
			 close(resultSet, connection, preparedStatement);
		 }	         
		 return  coilList;
 	}
	 
	/**
	 * 酸洗钢卷管理查询
	 * @return
	 */
	public ResultModel doQuaryCoilPdiInfo2() {
		ResultModel rm = new ResultModel();
		rm.setState("200");
		rm.setMsgInfo("查询成功");
		Connection connection = getConnection();
		List<HashMap<String,String>> infoList = new ArrayList<>();//返回的结果集
		//准备sql语句
		String sql = "select * from tbl_coil_pdi order by seq";
		//创建语句传输对象
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		try {
			preparedStatement = connection.prepareStatement(sql);
			
            // 设置查询超时时间为15秒：20240929刘侣
//         	preparedStatement.setQueryTimeout(3);
			
			//preparedStatement.setString(1, send.getCoil_no());
			resultSet = preparedStatement.executeQuery();
			while(resultSet.next()) {
				HashMap<String, String> info = new HashMap<String, String>();
				info.put("seq", resultSet.getRow()+"");
				String coil_no = resultSet.getString("COIL_ID");
				//卷号需要去除最后一位(2级系统默认新增了最后一位)
				coil_no = coil_no.substring(0, coil_no.length()-1);
				info.put("materailcoilno", coil_no);//原料卷号
				info.put("steel_name", resultSet.getString("GRADE_ID"));//牌号
				info.put("width", resultSet.getString("WIDTH"));//宽度
				info.put("thick", resultSet.getString("THICKNESS"));//厚度
				info.put("diameter_in", resultSet.getString("DIAMETER_IN"));//内径
				info.put("diameter_out", resultSet.getString("DIAMETER_OUT"));//外径
				info.put("coilno", resultSet.getString("COIL_ID_NEW"));//子卷号
				info.put("standard_no", resultSet.getString("STANDARD_NO"));//标准
				info.put("order_width", resultSet.getString("ORDER_WIDTH"));//订单宽度
				info.put("order_thick", resultSet.getString("ORDER_THICKNESS"));//订单厚度
				info.put("coil_wgt", resultSet.getString("COIL_WGT"));//原卷重量
				info.put("coil_len", resultSet.getString("COIL_LEN"));//原卷长度
				String create_time = resultSet.getString("CREATE_TIME");
				info.put("create_time", create_time.substring(0, create_time.length()-2));//创建时间
				String status = resultSet.getString("STATUS_ID");//状态
				if ("1".equals(status)) {
					status = "待酸洗";
				}else if ("5".equals(status)) {
					status = "已酸洗";
				}else if ("4".equals(status)) {
					status = "酸洗中";
				}else if ("3".equals(status)) {
					status = "已上卷";
				}else if ("2".equals(status)) {
					status = "入口称重";
				}else if ("0".equals(status)) {
					status = "已删除";
				}else if ("-1".equals(status)) {
					status = "待确认";
				}else if ("6".equals(status)) {
					status = "出口称重";
				}				
				info.put("status_id", status);
				infoList.add(info);	            		   	    	 		    	 
			}
			rm.setData(infoList);
		} catch (SQLException e) {
			e.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		} finally {
			close(resultSet, connection, preparedStatement);
		}
		
		
		return  rm;
 	}
	
	/**
	 * 酸洗二级停机日志查询：20240130刘侣
	 * @return
	 */
	public ResultModel querySxStopInfo(CommonPage<Tbs02PltcmL2SendPrdData> cp) {
		ResultModel rm = new ResultModel();
		rm.setState("200");
        rm.setMsgInfo("获取2级数据成功");
		//3.获取酸洗二级的重量信息
        Connection connection = getConnection();
        //准备sql语句
        String sql = "select * from TBL_DELAY_NEW where start_time >= to_date(?, 'yyyy-MM-dd HH24:mi:ss') and end_time <= to_date(?, 'yyyy-MM-dd HH24:mi:ss')";
        //创建语句传输对象
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
		
        try {
        	
        	String start_time = cp.getStartTime();
        	String end_time = cp.getEndTime();
        	if (start_time == null || end_time == null) {
        		throw new Exception("开始时间或结束时间不能为空");
        	}
        	
            preparedStatement = connection.prepareStatement(sql);
            
            // 设置查询超时时间为15秒
//         	preparedStatement.setQueryTimeout(15);
            
            preparedStatement.setString(1, start_time);
            preparedStatement.setString(2, end_time);
            resultSet = preparedStatement.executeQuery();
            List<HashMap<String,String>> infoList = new ArrayList<>();//返回的结果集
            while(resultSet.next()) {
            	HashMap<String, String> info = new HashMap<String, String>();
            	info.put("NR_STOPS", resultSet.getString("NR_STOPS"));
            	info.put("START_TIME", resultSet.getString("START_TIME"));
            	info.put("END_TIME", resultSet.getString("END_TIME"));
            	info.put("REASON_ID", resultSet.getString("REASON_ID"));
            	info.put("DELAY_COMMENT", resultSet.getString("DELAY_COMMENT"));
            	info.put("DURATION", resultSet.getString("DURATION"));
            	info.put("COIL_ID", resultSet.getString("COIL_ID"));
            	infoList.add(info);
            }
            rm.setData(infoList);
        } catch (Exception e) {
            rm.setState("500");
            rm.setMsgInfo(e.getMessage());
        }finally {
        	close(resultSet, connection, preparedStatement);
        }
        
        return  rm;
	}
	
	/**
	 * 清理酸洗二级历史残留数据：20240422刘侣
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteSXHisData(CommonPage<YdmProductDetail> cp) {
//				Date now = new Date();
//				String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		ResultModel rm = new ResultModel("200", "清理酸洗二级历史残留数据成功");
		
		try {
			
			List<YdmProductDetail> list = cp.getObjectList();
			if (list.size() <= 0) {
				throw new Exception("请传入参数");
			}
			for(YdmProductDetail ypd : list) {
				// 清理酸洗二级残留数据： 
				// 删除酸洗计划：
				rm = this.getBean(MesSxWeightServiceImpl.class).doCancelSendPlanSxInfoByCoilno(ypd.getCoilno());
				if (!"200".equals(rm.getState())) {
					rm.setState("500");
					rm.setMsgInfo("删除酸洗计划接收表失败");
					return rm;
				}
				// 删除酸洗钢卷信息：
				YdmProductDetail ypdQ = this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), null);
				if (ypdQ != null) {
					rm = this.getBean(MesSxWeightServiceImpl.class).doCancelSendCoilInfo(ypdQ.getMaterailcoilno()); 
					if (!"200".equals(rm.getState())) {
						rm.setState("500");
						rm.setMsgInfo("删除酸洗卷信息表失败");
						return rm;
					}
				}
				
			}
			
			
		} catch(Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		
		return rm;
	}
	 
	
	 /**
	  * 查询二级退卷信息
	  * @param cp
	  * @return
	 * @throws Exception 
	  */
	public ResultModel doQuaryCoilPdiRemovedInfo(CommonPage<MesPrdDetailReport> cp) throws Exception {
		ResultModel rm = new ResultModel();
		List<HashMap<String,String>> infoList = new ArrayList<>();//返回的结果集
		if (cp.getStartTime()==null || "".equals(cp.getStartTime())) {
			throw new Exception("开始时间不能为空");
		}
		if (cp.getEndTime()==null || "".equals(cp.getEndTime())) {
			throw new Exception("结束时间不能为空");
		}
		Connection connection = getConnection();
		//准备sql语句
		String sql = "select * from tbl_coil_pdi_removed t "
		 	+ "where t.create_time >= to_date(?,'yyyy-MM-dd HH24:mi:ss') "
		 	+ "and t.create_time <= to_date(?,'yyyy-MM-dd HH24:mi:ss') "
		 	//+ "and not exists (select 1 from tbs02_pltcm_l2_send_prd_data d where t.coil_id_new = d.coil_no)"
		 	+ "order by t.create_time desc";
		//创建语句传输对象
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		try {			
			preparedStatement = connection.prepareStatement(sql);
			
            // 设置查询超时时间为15秒：20240929刘侣
//         	preparedStatement.setQueryTimeout(15);
			
			preparedStatement.setString(1, cp.getStartTime()); //开始时间
			preparedStatement.setString(2, cp.getEndTime());//结束时间
			resultSet = preparedStatement.executeQuery();
			while(resultSet.next()) {
				HashMap<String, String> info = new HashMap<String, String>();
				String coil_no = resultSet.getString("COIL_ID");
				//卷号需要去除最后一位(2级系统默认新增了最后一位)
				coil_no = coil_no.substring(0, coil_no.length()-1);
				info.put("COIL_ID", coil_no);
				info.put("COIL_ID_NEW", resultSet.getString("COIL_ID_NEW"));//子卷号
				info.put("GRADE_ID", resultSet.getString("GRADE_ID"));//牌号
				info.put("COIL_WGT", resultSet.getString("COIL_WGT"));//重量
				info.put("WIDTH", resultSet.getString("WIDTH")); //宽度
				info.put("THICKNESS", resultSet.getString("THICKNESS"));//厚度
				info.put("COIL_LEN", resultSet.getString("COIL_LEN"));//长度
				info.put("ORDER_WIDTH", resultSet.getString("ORDER_WIDTH"));//订单宽度
				info.put("ORDER_THICKNESS", resultSet.getString("ORDER_THICKNESS"));//订单厚度
				info.put("STANDARD_NO", resultSet.getString("STANDARD_NO"));//标准
				info.put("DIAMETER_IN", resultSet.getString("DIAMETER_IN"));//内径
				info.put("DIAMETER_OUT", resultSet.getString("DIAMETER_OUT"));//外径
				info.put("CREATE_TIME", resultSet.getString("CREATE_TIME"));//废卷时间
				infoList.add(info);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(resultSet, connection, preparedStatement);
		}	
		//只保留还未交工的数据
		List<HashMap<String,String>> infoList2 = new ArrayList<>();
		if (infoList!=null &&infoList.size()>0) {
			for (HashMap<String, String> info : infoList) {
				String coilno = info.get("COIL_ID_NEW");
				YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(coilno, null);
				if (ypd==null) {
					infoList2.add(info);
				}
			}
		}
		rm.setState("200");
		rm.setData(infoList2);
		return  rm;
	}
	 
	 
}
