package com.kingdee.eas.custom.facade.worktime;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.utils.SendUtils;
import com.kingdee.eas.mobile.BOSMsgTypeEnum;
import com.kingdee.eas.mobile.MimeTypeEnum;
import com.kingdee.eas.mobile.PriorityEnum;
import com.kingdee.eas.mobile.msg.util.MsgUtil;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;

//import com.kingdee.bos.metadata.entity.EntityViewInfo;

//import com.kingdee.bos.dao.IObjectPK;
// 加班审批预警
public class WorktimeFacdeControllerBean extends AbstractWorktimeFacdeControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.facade.worktime.WorktimeFacdeControllerBean");
 
	
	@Override
	public void __becomeWork(Context ctx) {

		// LocalDate today = LocalDate.now(); // 获取当前日期
		// 判断当前日期是几号

		String sql = "select s.FPERSONUSERID,p.fid,t.fname_l1 as personname,t.FApplyDate  from T_BAS_AssignRead r left join T_WFR_Assign s on r.FASSIGNID = s.FASSIGNID  left join T_PM_User c on c.fid=s.FPERSONUSERID left join T_BD_Person p on c.FPersonId =p.fid\r\n"
				+ "left join (SELECT b.fid,b.fname_l1,a.FApplyDate FROM T_HR_ATS_OverTimeBill a left join T_BD_Person b on a.FProposer=b.fid)t on t.fid=p.fid\r\n"
				+ "					where r.FBOSTYPE = 'C46A580E' and s.FBIZOBJID in(select fid from T_HR_ATS_OverTimeBill FBillState where FBillState='1')";
		logger.error("获取加班单审批人SQL：" + sql);
		try {
			IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
			while (rowSet.next()) {
				StringBuffer strBuffer = new StringBuffer();
				String title = "Workflow "+rowSet.getString("personname")+" Overtime Approval Form awaiting your approval";
				// 内容
				strBuffer.append("Please go to the Workspace Application to view transaction details and act on pending approval tasks");
				strBuffer.append("\n");
				strBuffer.append("\n");
				strBuffer.append("\n");
				strBuffer.append("<html><head></head><body>");
				strBuffer.append("<a href=\"https://gtiit.kdeascloud.com/shr\">https://gtiit.kdeascloud.com/shr</a>");
				strBuffer.append("</body></html>");
				strBuffer.append("\n");
				strBuffer.append("\n");
				strBuffer.append("\n");
				strBuffer.append("\r\n" + 
						"This is an automatic workflow email. Do not reply to this mail.");
				String content = strBuffer.toString();
//				MsgUtil.msgSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, content, rowSet.getString("fid"),
//						BOSMsgTypeEnum.V_TYPE_EMAIL, null, null, MimeTypeEnum.HTML);
				SendUtils.msgSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, content, rowSet.getString("fid"),
						BOSMsgTypeEnum.V_TYPE_EMAIL, null, null, MimeTypeEnum.HTML);
				System.out.println("发送成功");
			}

		} catch (EASBizException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} catch (BOSException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} catch (Exception e) {
			logger.error("加班申请提醒通知失败：" + e.getMessage());
		}

	}

}