package com.engine.kq.cmd.hrmAttProcSet;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType4Hrm;
import com.engine.common.constant.BizLogType;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.wfset.attendance.manager.HrmAttProcSetManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.common.StringUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 考勤流程 删除校验规则
 * @author pzy
 *
 */
public class DelStateProcCheckRuleCmd extends AbstractCommonCommand<Map<String, Object>>{

  private SimpleBizLogger logger;

  public DelStateProcCheckRuleCmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
  }

  @Override
  public BizLogContext getLogContext() {
    return null;
  }

  @Override
  public List<BizLogContext> getLogContexts() {
    return logger.getBizLogContexts();
  }

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String,Object> retmap = new HashMap<String,Object>();
		 
		List<Object> lsGroup = new ArrayList<Object>();
		Map<String,Object> groupitem = null;
		List<Object> itemlist = null;
		try {
      RecordSet rs = new RecordSet();
      RecordSet rs1 = new RecordSet();
      RecordSet rs2 = new RecordSet();
      RecordSet rs3 = new RecordSet();
			String ids = StringUtil.vString(params.get("ids"));
      List<String> idList = Util.splitString2List(ids, ",");
      for(String id : idList){
        String sql = "select * from kq_att_checkrule_set where id = ? ";
        rs.executeQuery(sql,id);
        if(rs.next()){
          String ruleid = rs.getString("ruleid");
          String rule_type_uuid = rs.getString("rule_type_uuid");
          String sql1 = "select * from kq_att_checkrule_type where uuid=? ";
          rs1.executeQuery(sql1,rule_type_uuid);
          boolean isDel = false;
          if (rs1.next()) {
            String rule_table = rs1.getString("rule_table");
            String sql2 = "delete from " +rule_table+" where id = ? ";
            isDel = rs2.executeUpdate(sql2,ruleid);
          }
          if(isDel){
            String sql3 = "delete from kq_att_checkrule_set where id=? ";
            isDel = rs3.executeUpdate(sql3,id);
          }
        }
      }

			retmap.put("status", "1");
		} catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
			
		return retmap;
	}
}
