step 6、 Struts Action 类
java 代码
- /**
- * 地理信息
- */
- package com.fzfx88.base.action;
- import java.util.ArrayList;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.log4j.Logger;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import com.fzfx88.base.form.GeographyForm;
- import com.fzfx88.base.service.DictService;
- import com.fzfx88.base.service.GeographyService;
- import com.fzfx88.common.Constants;
- import com.fzfx88.common.UserInfo;
- import com.fzfx88.common.base.BaseAction;
- import com.fzfx88.po.base.DimGeography;
- /**
- * @author huguoqing
- *
- */
- public class GeographyAction extends BaseAction {
- public static Logger log=Logger.getLogger(GeographyAction.class);
- /**
- * 地理信息树结构初始化参数设置
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- public ActionForward inittree(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- return mapping.findForward("inittree");
- }
- /**
- * 地理信息初始化
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward init(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- GeographyForm gForm = (GeographyForm)form;
- DimGeography po = gForm.getGeography();
- GeographyService gService = new GeographyService();
- DictService dService = new DictService();
- /**取得cityType和cityType2列表**/
- List cityList1 = dService.queryDictItem(Constants.CITY_TYPE1,true);
- List cityList2 = dService.queryDictItem(Constants.CITY_TYPE2,true);
- gForm.setCityTypeList1(cityList1);
- gForm.setCityTypeList2(cityList2);
- /**取得当前节点下所有字节点**/
- List geographyList = new ArrayList();
- if(gForm.getGeographyID()!=null&&!gForm.getGeographyID().equals("")){
- int geographyId = Integer.parseInt(gForm.getGeographyID());
- String usageFlag = "1";
- geographyList = gService.queryGeographyByParentId(geographyId,usageFlag);
- }
- gForm.setGeographyList(geographyList);
- /**根据页面传来的地理信息id,获得对应地理信的相关信息**/
- if(gForm.getId()!=null&&!gForm.getId().equals("")){
- po = gService.queryGeography(Integer.valueOf(gForm.getId()));
- }
- gForm.setGeography(po);
- return mapping.findForward("init");
- }
- /**
- * 新增地理信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward create(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- GeographyForm gForm = (GeographyForm)form;
- DimGeography po = gForm.getGeography();
- GeographyService gService = new GeographyService();
- UserInfo user = this.getCurrentUser(request);
- /**
- * 设置po的treeCode
- */
- if(gForm.getGeographyID()!=null&&!gForm.getGeographyID().equals("")){
- String parentId = gForm.getGeographyID();
- /**取得当前节点对应的 地理信息类**/
- DimGeography graphy = gService.queryGeography(Integer.valueOf(parentId));
- /**设置GeographyLevel**/
- String level = String.valueOf(graphy.getGeographyLevel().intValue()+1);
- po.setGeographyLevel(Integer.valueOf(level));
- /**取得当前节点的treeCode**/
- String treeCode = graphy.getGeoTreeCode();
- String usageFlag = "1";
- /**取得当前节点下所有字节点列表**/
- List childGeo = gService.queryGeographyByParentId(Integer.parseInt(parentId),usageFlag);
- if(childGeo.isEmpty()){
- po.setGeoTreeCode(treeCode+"001");
- }else{
- /**取得当前子列表里面treeCode最大的节点**/
- DimGeography maxGraphy = (DimGeography)childGeo.get(0);
- /**取得当前最大子节点的treeCode**/
- String maxBrothorTreeCode = maxGraphy.getGeoTreeCode();
- /**将当前treeCode拆分为俩个字符串**/
- String subFirstTreeCode = maxBrothorTreeCode.substring(0,maxBrothorTreeCode.length()-3);
- String subSecondTreeCode = maxBrothorTreeCode.substring(maxBrothorTreeCode.length()-3,maxBrothorTreeCode.length());
- String currentCode = String.valueOf(1000 + Integer.parseInt(subSecondTreeCode) + 1);
- String newTreeCode = currentCode.substring(1,currentCode.length());
- String poTreeCode =subFirstTreeCode + newTreeCode;
- po.setGeoTreeCode(poTreeCode);
- }
- }
- /**设置po的父id**/
- DictService dictService = new DictService();
- po.setParentGeographyId(Integer.valueOf(gForm.getGeographyID()));
- po.setParentGeo(Integer.valueOf(gForm.getGeographyID()));
- if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){
- po.setCityType1(dictService.retrieveDictitem(gForm.getCityType1()));
- }
- if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){
- po.setCityType2(dictService.retrieveDictitem(gForm.getCityType2()));
- }
- /********字符处理***********/
- String geoName = po.getGeographyName();
- String newGeoName = geoName.replace('\'','’').trim();
- po.setGeographyName(newGeoName);
- String geoNameEN = po.getGeographyNameEn();
- String newGeoNameEN = geoNameEN.replace('\'','’').trim();
- po.setGeographyNameEn(newGeoNameEN);
- String geoCode = po.getGeographyCode();
- String newGeoCode = geoCode.replace('\'','’').trim();
- po.setGeographyCode(newGeoCode);
- /********数据提交*************/
- gService.createGeography(po,user);
- return mapping.findForward("success");
- }
- /**
- * 修改地理信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward modify(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- GeographyForm gForm = (GeographyForm)form;
- UserInfo user = this.getCurrentUser(request);
- DimGeography po = gForm.getGeography();
- GeographyService gService = new GeographyService();
- DimGeography vo = gService.queryGeography(Integer.valueOf(gForm.getListId()));
- vo.setGeographyName(po.getGeographyName().replace('\'','’').trim());
- vo.setGeographyNameEn(po.getGeographyNameEn().replace('\'','’').trim());
- vo.setGeographyCode(po.getGeographyCode().replace('\'','’').trim());
- DictService dictService = new DictService();
- if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){
- vo.setCityType1(dictService.retrieveDictitem(gForm.getCityType1()));
- }
- if(gForm.getCityType2()!=null&&!gForm.getCityType2().equals("")){
- vo.setCityType2(dictService.retrieveDictitem(gForm.getCityType2()));
- }
- gService.updateGeography(vo,user);
- return mapping.findForward("success");
- }
- /**
- * 作废地理信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward delete(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- GeographyForm gForm = (GeographyForm)form;
- UserInfo user = this.getCurrentUser(request);
- // DimGeography po = gForm.getGeography();
- GeographyService gService = new GeographyService();
- DimGeography vo = gService.queryGeography(Integer.valueOf(gForm.getListId()));
- String usageFlag = "0";
- vo.setUsageFlag(usageFlag);
- gService.updateGeography(vo,user);
- return mapping.findForward("success");
- }
- }
step 7、Form 类
java 代码
- /**
- * 地理信息
- */
- package com.winchannel.base.form;
- import java.util.List;
- import com.winchannel.common.base.BaseForm;
- import com.winchannel.po.base.DimGeography;
- /**
- * @author huguoqing
- *
- */
- public class GeographyForm extends BaseForm {
- private DimGeography geography = new DimGeography();
- private List geographyList;
- private String geographyTypeID;
- private List cityTypeList1;
- private String cityType1;
- private List cityTypeList2;
- private String cityType2;
- private String geographyID;//页面传来的 id值
- private String graphyName;
- private String graphyNameEn;
- private String graphyCode;
- private String cityLevel;
- private String graphyLevel;
- private String id;
- private String state;
- private String listId;
- /**
- * @return Returns the state.
- */
- public String getState() {
- return state;
- }
- /**
- * @param state The state to set.
- */
- public void setState(String state) {
- this.state = state;
- }
- /**
- * @return Returns the geography.
- */
- public DimGeography getGeography() {
- return geography;
- }
- /**
- * @param geography The geography to set.
- */
- public void setGeography(DimGeography geography) {
- this.geography = geography;
- }
- /**
- * @return Returns the id.
- */
- public String getId() {
- return id;
- }
- /**
- * @param id The id to set.
- */
- public void setId(String id) {
- this.id = id;
- }
- /**
- * @return Returns the cityLevel.
- */
- public String getCityLevel() {
- return cityLevel;
- }
- /**
- * @param cityLevel The cityLevel to set.
- */
- public void setCityLevel(String cityLevel) {
- this.cityLevel = cityLevel;
- }
- /**
- * @return Returns the graphyCode.
- */
- public String getGraphyCode() {
- return graphyCode;
- }
- /**
- * @param graphyCode The graphyCode to set.
- */
- public void setGraphyCode(String graphyCode) {
- this.graphyCode = graphyCode;
- }
- /**
- * @return Returns the graphyLevel.
- */
- public String getGraphyLevel() {
- return graphyLevel;
- }
- /**
- * @param graphyLevel The graphyLevel to set.
- */
- public void setGraphyLevel(String graphyLevel) {
- this.graphyLevel = graphyLevel;
- }
- /**
- * @return Returns the graphyName.
- */
- public String getGraphyName() {
- return graphyName;
- }
- /**
- * @param graphyName The graphyName to set.
- */
- public void setGraphyName(String graphyName) {
- this.graphyName = graphyName;
- }
- /**
- * @return Returns the graphyNameEn.
- */
- public String getGraphyNameEn() {
- return graphyNameEn;
- }
- /**
- * @param graphyNameEn The graphyNameEn to set.
- */
- public void setGraphyNameEn(String graphyNameEn) {
- this.graphyNameEn = graphyNameEn;
- }
- /**
- * @return Returns the geographyID.
- */
- public String getGeographyID() {
- return geographyID;
- }
- /**
- * @param geographyID The geographyID to set.
- */
- public void setGeographyID(String geographyID) {
- this.geographyID = geographyID;
- }
- /**
- * @return Returns the geographyList.
- */
- public List getGeographyList() {
- return geographyList;
- }
- /**
- * @param geographyList The geographyList to set.
- */
- public void setGeographyList(List geographyList) {
- this.geographyList = geographyList;
- }
- /**
- * @return Returns the geographyTypeID.
- */
- public String getGeographyTypeID() {
- return geographyTypeID;
- }
- /**
- * @param geographyTypeID The geographyTypeID to set.
- */
- public void setGeographyTypeID(String geographyTypeID) {
- this.geographyTypeID = geographyTypeID;
- }
- /**
- * @return Returns the cityType1.
- */
- public String getCityType1() {
- return cityType1;
- }
- /**
- * @param cityType1 The cityType1 to set.
- */
- public void setCityType1(String cityType1) {
- this.cityType1 = cityType1;
- }
- /**
- * @return Returns the cityType2.
- */
- public String getCityType2() {
- return cityType2;
- }
- /**
- * @param cityType2 The cityType2 to set.
- */
- public void setCityType2(String cityType2) {
- this.cityType2 = cityType2;
- }
- /**
- * @return Returns the cityTypeList1.
- */
- public List getCityTypeList1() {
- return cityTypeList1;
- }
- /**
- * @param cityTypeList1 The cityTypeList1 to set.
- */
- public void setCityTypeList1(List cityTypeList1) {
- this.cityTypeList1 = cityTypeList1;
- }
- /**
- * @return Returns the cityTypeList2.
- */
- public List getCityTypeList2() {
- return cityTypeList2;
- }
- /**
- * @param cityTypeList2 The cityTypeList2 to set.
- */
- public void setCityTypeList2(List cityTypeList2) {
- this.cityTypeList2 = cityTypeList2;
- }
- /**
- * @return Returns the listId.
- */
- public String getListId() {
- return listId;
- }
- /**
- * @param listId The listId to set.
- */
- public void setListId(String listId) {