package nccloud.web.hrwa.paydata.action;

import com.alibaba.fastjson.JSONObject;

import nc.itf.hr.wa.IPaydataExService;
import nc.itf.hr.wa.IPaydataManageService;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.wa.paydata.DataVO;
import nc.vo.wa.pub.WaLoginContext;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.container.IRequest;
import nccloud.web.hr.pub.HRCommonAction;
import nccloud.web.hr.pub.HRNccTemplateUtils;
import nccloud.web.hrwa.helper.WaLoginContextUtils;
import nccloud.web.hrwa.pub.WaClassState;
import nccloud.web.uapbd.commons.web.ParamUtils;

/**
 * 审核数据
 * <p>
 * {@link nc.ui.wa.paydata.action.CheckAction}
 * </p>
 * 
 * @author liuyuan
 * @date 2018-5-22
 */
public class SendMsgAction extends HRCommonAction {

	/**
	 * 审核数据
	 * 
	 * @param arg0
	 *            请求参数，包含参数，year，period，pk_org，node_type
	 * @param isRangeAll
	 *            是否时全部计算，true为全部计算，false为部分计算
	 * @return
	 * @throws BusinessException
	 */
	@Override
	public <T> Object execute(IRequest request, T para) throws Exception {

		JSONObject result = new JSONObject();
		result.put("status", 200);
		ParamUtils param = new ParamUtils(request);
		boolean isRangeAll = UFBoolean.valueOf(param.getString("isRangeAll", "true")).booleanValue();
		boolean sure = param.getBoolean("sure", false);
		IPaydataManageService service = ServiceLocator.find(IPaydataManageService.class);

		WaLoginContext loginContext = WaLoginContextUtils.getWaLoginContext(param);
		// 判断薪资档案数据状态是否发生了改变20200410
//		new WaClassState().validateWaClassStatus(loginContext, "check");
		// 当前页数据，用于时间戳校验
		JSONObject jo = JSONObject.parseObject(request.read());
		DataVO[] dataVos = HRNccTemplateUtils.getVOFromGrid(DataVO.class, jo.getString("modelInfo"));
		String whereCondition = isRangeAll ? null : WaPaydataQueryHelper.getWhereCondition(param);

		IPaydataExService serviceEx = ServiceLocator.find(IPaydataExService.class);
		//判断已经发放
		Boolean checkFlag = serviceEx.checkPeriodstate(loginContext.getWaLoginVO());
//		checkFlag = Boolean.TRUE;
		if (checkFlag) {
			//发送员工通知
			serviceEx.onSendMsg(loginContext.getWaLoginVO(), whereCondition);
			result.put("msg", "发送成功");
			return result;

		}
		throw new BusinessException("薪资未发放，不允许发送消息");
	}

}
