Package com.adm.biz

Source Code of com.adm.biz.TplService

package com.adm.biz;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.yfsoft.comm.util.BizResult;
import org.yfsoft.comm.util.TimeUtil;

import com.adm.ctl.GlobalKey;
import com.adm.ctl.ResultType;
import com.adm.dao.CommonDao;

public class TplService extends Service {

  protected CommonDao dao;
 
  @Override
  public void setDao(CommonDao dao) {
    this.dao = dao;
  }
 
  public BizResult list(Map<String,String> input){
    String m_id = input.get("m_id");
    Map<String,Object> m = this.dao.query("sys_model",null,"m_id = "+m_id).getData();
    this.setReqAttr("model", m);
    BizResult rst = this.dao.injoin(new String[]{"sys_model_control mc","sys_control c"},
        new String[]{"mc.*","c.*"},
        "mc.mc_control_id = c.c_id",
        "mc.mc_model_id = "+m_id,
        null,100,0);
    List<Map<String,Object>> controls = rst.getData();
    if(controls.size()<1){
      this.setReqAttr("msg", "未设置栏位信息");
      rst.setType(String.valueOf(ResultType.REDIRECT));
      rst.setPage("tpl/list.jsp");
      return rst;
    }
    this.setReqAttr("controls", controls);
    Map<String,Object> user = this.getSion(GlobalKey.USER);
    String where = null;
    if("1".equals(m.get("m_private").toString())){
      where = m.get("m_user").toString() + " = " +user.get("ui_id");
    }
    //获取到用户的配置信息
    Map<String,String> profile = (Map<String,String>)user.get("ui_profile");
   
    String view = m.get("m_view").toString();
   
    //根据用户的配置信息来决定视图的排序方式
    List<Map<String,Object>> entrys = this.dao.list(view,null,where,profile.containsKey(view)?profile.get(view):"",100,0).getData();
    for(Map<String,Object> c : controls){
      Object ds_id = c.get("mc_ds");
      if(null == ds_id) continue;
      if("0".equals(ds_id)) continue;
      for(int i = 0 ;i < entrys.size();i++){
        Map<String,Object> e = entrys.get(i);
        try {
          e.put(c.get("mc_attr_name").toString(),this.dao.getDataValue(Integer.parseInt(ds_id.toString()), e.get(c.get("mc_attr_name"))));
          entrys.set(i, e);
        catch (Throwable e1) {
        }
      }
    }
    this.setReqAttr("es", entrys);
    rst.setType(String.valueOf(ResultType.REDIRECT));
    rst.setPage("tpl/list.jsp");
    return rst;
  }
 
  protected Map<String,String> getControls(String m_id){
    Map<String,String> tmp = new HashMap<String,String>();
    Map<String,Object> m = this.dao.query("sys_model",null,"m_id = "+m_id).getData();
    tmp.put("v",m.get("m_view").toString());
    this.setReqAttr("model", m);
    List<Map<String,Object>> controls = this.dao.injoin(new String[]{"sys_model_control mc","sys_control c"},
        new String[]{"mc.*","c.*"},
        "mc.mc_control_id = c.c_id",
        "mc.mc_model_id = "+m_id,
        null,100,0).getData();
    for(int i = 0;i<controls.size();i++){
      Map<String,Object> c = controls.get(i);
      if("1".equals(c.get("mc_pri").toString()))
        tmp.put("pri",c.get("mc_attr_name").toString());
      Object ds_id = c.get("mc_ds");
      if(null == ds_id) continue;
      if("0".equals(ds_id)) continue;
      try {
        StringBuffer sb = new StringBuffer();
        List<Map<String,Object>> ds = this.dao.getDataSource(ds_id);
        for(Map<String,Object> d : ds){
          sb.append("<option value='").append(d.get("k")).append("' >").append(d.get("v")).append("</option>");
        }
        c.put("mc_ds", sb.toString());
        controls.set(i, c);
      } catch (Throwable e) {
      }
    }
    this.setReqAttr("controls", controls);
    return tmp;
  }
 
  public BizResult form(Map<String,String> input){
    String m_id = input.get("m_id");
    getControls(m_id);
    String p =input.get("p");
    if("add".equals(p)){
      //添加表单
      this.setReqAttr("p", "add");
    }else if("edit".equals(p)){
      //修改表单
      //TODO..加载属性
      String e_id = input.get("key");
      String pri = input.get("pri");
      String v = input.get("v");
      this.setReqAttr("e", this.dao.query(v,null,pri+"="+e_id).getData());
      this.setReqAttr("p", "edit");
      this.setReqAttr("pri", pri);
      this.setReqAttr("key", e_id);
      this.setReqAttr("v",v);
    }
    BizResult rst = new BizResult().setCode("0");
    rst.setType(String.valueOf(ResultType.REDIRECT));
    rst.setPage("tpl/form.jsp");
    return rst;
  }
 
  public BizResult delete(Map<String,String> input){
    String key = input.get("key");
    //可处理多个值,'_'
    String[] keys = key.split("_");
    String pri = input.get("pri");
    String where;
    if(keys.length>1){
      where = pri+" in " + Arrays.toString(keys).replace("[", "(").replace("]", ")");
    }else{
      where = pri+"="+key;
    }
    BizResult rst = this.dao.delete(input.get("v"),where);
    if("0".equals(rst.getCode())){
      this.setReqAttr("msg", "OK");
    }else{
      this.setReqAttr("msg", rst.getMsg());
    }
    //如果是员工业务办理删除,则要删除流程信息
    if("usr_matter".equals(input.get("v"))){
      if(keys.length>1){
        where = "e_ref_id in " + Arrays.toString(keys).replace("[", "(").replace("]", ")");
      }else{
        where = "e_ref_id ="+key;
      }
      this.dao.delete("wf_entry",where);
    }
    return list(input);
  }
 
  public BizResult detail(Map<String,String> input){
    String m_id = input.get("m_id");
    Map<String,String> tmp = getControls(m_id);
    String e_id = input.get("key");
    String pri = tmp.get("pri");
    String v = tmp.get("v");
    String log = input.get("log");
    if("1".equals(log)){
      this.setReqAttr("logs",
          this.dao.injoin(new String[]{"wf_process p","usr_userinfo u"} ,
              new String[]{"p.*","u.*"},
              "p.p_deal_user = u.ui_id",
              "p.p_entry = "+input.get("e_id"), "p.p_deal_date desc", 10, 0).getData());
    }
    this.setReqAttr("e", this.dao.query(v,null,pri+"="+e_id).getData());
    BizResult rst = new BizResult();
    rst.setType(String.valueOf(ResultType.REDIRECT));
    rst.setPage("tpl/detail.jsp");
    return rst;
  }
 
 
  public BizResult edit(Map<String,String> input){
    String key = input.get("key");
    String pri = input.get("pri");
    String v = input.get("v");
    BizResult rst = this.dao.update(input, pri+"="+key, v);
    if("0".equals(rst.getCode())){
      this.setReqAttr("msg", "OK");
    }else{
      this.setReqAttr("msg", rst.getMsg());
    }
    return list(input);
  }
 
  public BizResult add(Map<String,String> input){
    String m_id = input.get("m_id");
    Object ref_id = null;
    Map<String,Object> model = this.dao.query("sys_model",null,"m_id = "+m_id).getData();
    this.setReqAttr("model", model);
    this.dao.insert(input,model.get("m_view").toString() );
    ref_id = this.dao.getLastId();
    //模型带有文档
    if(1==Integer.parseInt(model.get("m_upload").toString())){
      input.put("createtime",TimeUtil.getNow());
      input.put("view", model.get("m_view").toString() );
      input.put("filename",input.get("guid")+"."+input.get("file_type"));
      this.dao.insert(input,"usr_upload");
    }
    //用户自发创建的工作流程
    if(input.containsKey("m_title")){
      input.put("title", input.get("m_title"));
    }
    return workflow(input,"add",ref_id.toString());
  }
 
  /**
   * 业务触发工作流
   * @param input
   * @return
   */
  public BizResult workflow(Map<String,String> input,String o,String ref_id){
    Map<String,Object> model = this.getReqAttr("model");
    //是否需要挂接工作流
    Map<String,Object> wf = this.dao.query("wf_tpl_model",null,"tm_act = '"+o+"' and tm_m = "+model.get("m_id")).getData();
    String wf_id = "";
    if(wf==null){
      if(!input.containsKey("wf")){
        return list(input);
      }
      wf_id = input.get("wf");
    }else{
      wf_id = wf.get("tm_t").toString();
    }
    Map<String,Object> user = this.getSion(GlobalKey.USER);
    Map<String,String> entry = new HashMap<String,String>();
    String title = null;
    if(input.containsKey("title")){
      title = input.get("title");
    }else{
      title = user.get("ui_nickname")+"提交:"+model.get("m_title");
    }
    entry.put("e_title",title);
    entry.put("e_status","process");
    entry.put("e_node","1");
    entry.put("e_create_date",TimeUtil.getNow());
    entry.put("e_update_date",TimeUtil.getNow());
    entry.put("e_cur_user",user.get("ui_id").toString());
    entry.put("e_tpl",wf_id);
    entry.put("e_model_id", model.get("m_id").toString());
    entry.put("e_ref_id",ref_id.toString());
    this.dao.insert(entry, "wf_entry");
    this.setReqAttr(GlobalKey.WF_CHECK, "c?s=tpl&o=detail&m_id="+model.get("m_id").toString()+"&key="+ref_id.toString());
    this.setReqAttr("e_id", this.dao.getLastId());
    this.setReqAttr("remarks",this.dao.list("wf_node",null, "n_tpl = "+wf_id, "n_code asc", 30, 0).getData());
    //加载工作流模板的送审节点,跳转到前台进行流程送审
    Map<String,Object> process = this.dao.query("sys_model",new String[]{"m_id"},"m_view='wf_process'").getData();
    input.put("m_id", process.get("m_id").toString());
    BizResult rst = form(input);
    rst.setType(String.valueOf(ResultType.REDIRECT));
    rst.setPage("workflow/process.jsp");
    this.setReqAttr("t", "todo");
    return rst;
  }

}
TOP

Related Classes of com.adm.biz.TplService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.