ZQRepair\src\org\anyline\def\web\refer\InvTypesAction.java
package org.anyline.def.web.refer;
import java.io.IOException;
import org.anyline.def.web.base.BaseAction;
import org.anyline.def.web.comm.DataHelp;
import org.anyline.def.web.refer.json.InvTypesJson;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
@ParentPackage("def-web")
@Namespace("/cm/refer/invtypes")
@Scope("prototype")
public class InvTypesAction extends BaseAction{
/**
*
*/
private static final long serialVersionUID = 1L;
/*
* 部门树结构图
*/
@Action(value = "tree", results = { @Result(type = "json") })
public void GetTree() throws IOException {
InvTypesJson json = new InvTypesJson(mvcService);
String retjson = json.GetTreeJson();
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(retjson);
response.flushBuffer();
}
/*
* 加载检修单位
*/
@Action(value = "companyinfo", results = { @Result(type = "json") })
public void GetInfo() throws IOException{
String companyid = DataHelp.null2empty(getParam("companyid"));
InvTypesJson json = new InvTypesJson(mvcService);
String retjson = json.GetInfoJson(companyid);
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(retjson);
response.flushBuffer();
}
/*
* 车种类型对应的设备分类树结构
*/
@Action(value = "traintype2invtypestree", results = { @Result(type = "json") })
public void GetTrainType2InvTypesTree() throws IOException {
String billid= getParam("billid");
InvTypesJson json = new InvTypesJson(mvcService);
String retjson = json.GetTrainType2InvTypesTreeJson(billid);
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(retjson);
response.flushBuffer();
}
}
ZQRepair\src\org\anyline\def\web\refer\json\InvTypesJson.java
package org.anyline.def.web.refer.json;
import java.util.ArrayList;
import java.util.List;
import org.anyline.def.web.comm.BaseJson;
import org.anyline.def.web.comm.DataHelp;
import org.anyline.def.web.pub.entity.ModelInvtypes;
import org.anyline.def.web.refer.entity.ModelCompany;
import org.anyline.def.web.refer.entity.ModelInvTypes;
import org.anyline.def.web.refer.entity.ModelTree;
import org.anyline.def.web.refer.entity.ModelTreeForImport;
import com.google.gson.Gson;
import com.inmvc.config.db.Procedure;
import com.inmvc.entity.DataRow;
import com.inmvc.entity.DataSet;
import com.inmvc.service.MVCService;
public class InvTypesJson extends BaseJson{
public InvTypesJson(MVCService mvcService) {
super(mvcService);
// TODO Auto-generated constructor stub
}
/**
* 树结构加载
*/
public String GetTreeJson() {
List<ModelTreeForImport> listtree = new ArrayList<ModelTreeForImport>();
try{
Procedure procedure = new Procedure("pub_spinvtypestree");
DataSet dsrows = this.mvcService.queryProcedure(procedure);
@SuppressWarnings("unchecked")
List<ModelInvtypes> list = (List<ModelInvtypes>)DataHelp.DataSetToList(dsrows, ModelInvtypes.class);
for(ModelInvtypes m:list){
if(m.getInvtypeid().equals("0")){
ModelTreeForImport mt = new ModelTreeForImport();
mt.setId(m.getInvtypesid());
mt.setText(m.getInvtypesname());
mt.setChildren(GetChild(list,m.getInvtypesid()));
listtree.add(mt);
}
}
} catch(Exception e){
e.printStackTrace();
log.error(e);
listtree = new ArrayList<ModelTreeForImport>();
}
Gson gson = new Gson();
String retjson = gson.toJson(listtree);
return retjson;
}
private List<ModelTreeForImport> GetChild(List<ModelInvtypes> list, String invtypeid){
List<ModelTreeForImport> l = new ArrayList<ModelTreeForImport>();
for(ModelInvtypes m:list){
if(m.getInvtypeid().equals(invtypeid)){
ModelTreeForImport mt = new ModelTreeForImport();
mt.setId(m.getInvtypesid());
mt.setText(m.getInvtypesname());
mt.setCompanyid(m.getCompanyid());
mt.setChildren(GetChild(list,m.getInvtypesid()));
l.add(mt);
}
}
return l;
}
/*
* 加载检修单位
*/
public String GetInfoJson(String companyid) {
ModelCompany company = new ModelCompany();
try {
Procedure procedure = new Procedure("pub_spcompanyinfo");
procedure.addInput(companyid);
DataSet dtrows = mvcService.queryProcedure(procedure);
if(dtrows.size() == 1){
DataRow row = dtrows.getRow(0);
company = (ModelCompany) DataHelp.DataRowToObject(row, ModelCompany.class);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e);
company = new ModelCompany();
}
Gson gson = new Gson();
String retjson=gson.toJson(company);
return retjson;
}
/**
* 车种类型对应的设备分类树结构
*/
public String GetTrainType2InvTypesTreeJson(String billid) {
List<ModelTree> listtree = new ArrayList<ModelTree>();
try{
Procedure procedure = new Procedure("pub_sptraintype2invtypestree");
if(billid.equals("0") || billid.equals("")){
procedure.addInput(null);
} else{
procedure.addInput(billid);
}
DataSet dsrows = this.mvcService.queryProcedure(procedure);
@SuppressWarnings("unchecked")
List<ModelInvTypes> list = (List<ModelInvTypes>)DataHelp.DataSetToList(dsrows, ModelInvTypes.class);
for(ModelInvTypes m:list){
if(m.getInvtypeid().equals("0")){
ModelTree mt = new ModelTree();
mt.setId(m.getInvtypesid());
mt.setText(m.getInvtypesname());
mt.setChecked(m.isChecked());
mt.setChildren(GetTrainType2InvTypesChild(list,m.getInvtypesid()));
listtree.add(mt);
}
}
} catch(Exception e){
e.printStackTrace();
log.error(e);
listtree = new ArrayList<ModelTree>();
}
Gson gson = new Gson();
String retjson = gson.toJson(listtree);
return retjson;
}
private List<ModelTree> GetTrainType2InvTypesChild(List<ModelInvTypes> list, String invtypesid){
List<ModelTree> l = new ArrayList<ModelTree>();
for(ModelInvTypes m:list){
if(m.getInvtypeid().equals(invtypesid)){
ModelTree mt = new ModelTree();
mt.setId(m.getInvtypesid());
mt.setText(m.getInvtypesname());
mt.setChecked(m.isChecked());
l.add(mt);
}
}
return l;
}
}
ZQRepair\src\org\anyline\def\web\pub\entity\ModelInvtypes.java
package org.anyline.def.web.pub.entity;
import java.io.Serializable;
public class ModelInvtypes implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String invtypesid;
private String invtypescode;
private String invtypesname;
private String invtypename;
private String invtypeid;
private String dist;
private String cyclevalue;
private String userids;
private String username;
private String invstr;
private String companyid;
private String companyname;
public String getInvtypesid() {
return invtypesid;
}
public void setInvtypesid(String invtypesid) {
this.invtypesid = invtypesid;
}
public String getInvtypescode() {
return invtypescode;
}
public void setInvtypescode(String invtypescode) {
this.invtypescode = invtypescode;
}
public String getInvtypesname() {
return invtypesname;
}
public void setInvtypesname(String invtypesname) {
this.invtypesname = invtypesname;
}
public String getInvtypeid() {
return invtypeid;
}
public void setInvtypeid(String invtypeid) {
this.invtypeid = invtypeid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getDist() {
return dist;
}
public void setDist(String dist) {
this.dist = dist;
}
public String getCyclevalue() {
return cyclevalue;
}
public void setCyclevalue(String cyclevalue) {
this.cyclevalue = cyclevalue;
}
public String getInvtypename() {
return invtypename;
}
public void setInvtypename(String invstypename) {
this.invtypename = invstypename;
}
public String getUserids() {
return userids;
}
public void setUserids(String userids) {
this.userids = userids;
}
public String getInvstr() {
return invstr;
}
public void setInvstr(String invstr) {
this.invstr = invstr;
}
public String getCompanyid() {
return companyid;
}
public void setCompanyid(String companyid) {
this.companyid = companyid;
}
public String getCompanyname() {
return companyname;
}
public void setCompanyname(String companyname) {
this.companyname = companyname;
}
}
ZQRepair\src\org\anyline\def\web\refer\entity\ModelTreeForImport.java
package org.anyline.def.web.refer.entity;
import java.util.List;
public class ModelTreeForImport {
private String companyid;
public String getCompanyid() {
return companyid;
}
public void setCompanyid(String companyid) {
this.companyid = companyid;
}
private String id;
private String text;
private String state;
private boolean checked;
private String parentid;
private List<ModelTreeForImport> children;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public List<ModelTreeForImport> getChildren() {
return children;
}
public void setChildren(List<ModelTreeForImport> children) {
this.children = children;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public String getParentid() {
return parentid;
}
public void setParentid(String parentid) {
this.parentid = parentid;
}
}
ZQRepair\src\org\anyline\def\web\refer\entity\ModelInvtypeTree.java
package org.anyline.def.web.refer.entity;
import java.util.List;
public class ModelInvtypeTree {
private String id;
private String text;
private String state;
private List<ModelInvtypeTree> children;
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public List<ModelInvtypeTree> getChildren() {
return children;
}
public void setChildren(List<ModelInvtypeTree> children) {
this.children = children;
}
}