package com.test.action; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.test.common.Util; import com.test.dao.IDeptDao; import com.test.entity.Deptinfo; import com.test.entity.Empinfo; public class DeptAction extends ActionSupport { private String result; private IDeptDao deptdao; public IDeptDao getDeptdao() { return deptdao; } public void setDeptdao(IDeptDao deptdao) { this.deptdao = deptdao; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } private String deptid; private String deptfid; private String deptname; public String getDeptid() { return deptid; } public void setDeptid(String deptid) { this.deptid = deptid; } public String getDeptfid() { return deptfid; } public void setDeptfid(String deptfid) { this.deptfid = deptfid; } public String getDeptname() { return deptname; } public void setDeptname(String deptname) { this.deptname = deptname; } public String[] sid; public String[] getSid() { return sid; } public void setSid(String[] sid) { this.sid = sid; } public String queryDept() { Map<String, String> content = new HashMap<String, String>(); content.put("deptid", "%"+Util.checkValid(deptid)+"%"); Empinfo emp = (Empinfo)ActionContext.getContext().getSession().get("currentemp"); if(null==emp){ try { JSONObject jsonObject = new JSONObject(); jsonObject.put("result", "error"); jsonObject.put("dataSets", "没有指定数据"); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); result = jsonObject.toString(); System.out.println(result); this.setResult(result); response.getWriter().append(result); } catch (IOException e) { System.out.println("转换json异常"); } }else{ content.put("empdeptid", emp.getEmpdeptid()); System.out.println(content); List<Deptinfo> list = deptdao.queryDept(content); System.out.println(list); if (list.size() > 0) { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("result", "success"); jsonObject.put("dataSets", list); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); result = jsonObject.toString(); System.out.println(result); this.setResult(result); response.getWriter().append(result); } catch (IOException e) { System.out.println("转换json异常"); } } else { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("result", "error"); jsonObject.put("dataSets", "没有指定数据"); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); result = jsonObject.toString(); System.out.println(result); this.setResult(result); response.getWriter().append(result); } catch (IOException e) { System.out.println("转换json异常"); } }} setNull(); return NONE; } public String getDept() { String []ids = sid; String idsstr = "0"; for(int i=0;i<ids.length;i++){ idsstr=ids[i]; } HttpServletRequest request = ServletActionContext.getRequest(); Deptinfo dept = deptdao.getDept(idsstr); if (null == dept) { dept = new Deptinfo(); } ServletActionContext.getActionContext(request).getSession() .put("deptinfo", dept); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); System.out.println(result); this.setResult(result); setNull(); return "success"; } public String addDept() { Map<String, String> content = new HashMap<String, String>(); content.put("deptid", Util.dateStr()); content.put("deptfid", deptfid); content.put("deptname", deptname); int num = deptdao.addDept(content); if(num>0){ result="添加部门信息成功"; }else{ result="添加部门信息失败"; } HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); System.out.println(result); this.setResult(result); setNull(); return "success"; } public String updateDept() { return "success"; } public String saveDept() { Map<String, String> content = new HashMap<String, String>(); content.put("deptid", deptid); content.put("deptfid", deptfid); content.put("deptname", deptname); int num = deptdao.saveDept(content); if(num>0){ result="更新部门信息成功"; }else{ result="更新部门信息失败"; } HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); System.out.println(result); this.setResult(result); setNull(); return "success"; } public String deleteDept() { String []ids = sid; // String idsstr="0"; // for(int i=0;i<ids.length;i++){ // idsstr += ","+ids[i]; // } int num = deptdao.deleteDept(ids); if(num>0){ result="删除部门信息成功"; }else{ result="删除部门信息失败"; } HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); System.out.println(result); this.setResult(result); setNull(); return "success"; } public void setNull(){ deptid=""; deptfid=""; deptname=""; } }

1763316068 LV2
2019年6月12日
dingdehong LV10
2018年12月27日
lxl1234 LV9
2018年10月28日
陈铳123456 LV1
2018年7月4日
zxd456 LV7
2018年5月28日
1579199398 LV2
2018年4月1日
xiaodada LV7
2017年12月11日
huixian LV1
2017年10月20日
CHK141 LV2
2017年10月16日
1147870524 LV2
2017年10月1日