package com.engine.kq.cmd.reportfielddefine;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import java.util.HashMap;
import java.util.Map;

public class SaveReportMoudleCmd extends AbstractCommonCommand<Map<String, Object>> {

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

  @Override
  public Map<String, Object> execute(CommandContext commandContext) {
    Map<String, Object> retmap = new HashMap<String, Object>();
    String sql = "";
    RecordSet rs = new RecordSet();
    try {
      String id = Util.null2String(params.get("id"));
      String moudlename = Util.null2String(params.get("moudlename"));
      String moudledata = Util.null2String(params.get("moudledata"));
      if (id.length() > 0) {
        sql = " update kq_report_moudle set moudledata=? where id=?";
        rs.executeUpdate(sql, moudledata, id);
      } else {
        sql = "insert into kq_report_moudle (moudlename, moudledata,resourceid) values (?,?,?)";
        rs.executeUpdate(sql, moudlename, moudledata, user.getUID());

        rs.executeQuery("select max(id) from kq_report_moudle");
        if (rs.next()) {
          id = rs.getString(1);
        }
        sql = " update kq_report_moudle set showorder=id where id = ? ";
        rs.executeUpdate(sql, id);
      }
      retmap.put("id", id);
      retmap.put("status", "1");
    } catch (Exception e) {
      this.writeLog(e);
      retmap.put("status", "-1");
      retmap.put("message", SystemEnv.getHtmlLabelName(382661, this.user.getLanguage()));
    }
    return retmap;
  }

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

}
