📄 areainfo.java
字号:
package com.saas.biz.AreaInfoMgr;
import java.util.*;
import net.sf.json.JSONArray;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.*;
import com.saas.sys.dbm.Dbtable;
import com.saas.biz.dao.areaDAO.*;
import com.saas.biz.JavaScriptObject.TreeNode;
import com.saas.biz.JavaScriptObject.TreeObject;
import com.saas.biz.commen.commMethodMgr;
public class AreaInfo {
Logger log;
Buffers inBuffer;
Buffers outBuffer;
Dbtable tradeQuery;
commMethodMgr commen;
ArrayList queryResult = new ArrayList();
public AreaInfo() {
log = new Logger(this);
tradeQuery = new Dbtable();
commen = new commMethodMgr();
}
public void setOutBuffer(Buffers outBuffer) {
this.outBuffer = outBuffer;
}
public Buffers getOutBuffer() {
return this.outBuffer;
}
public void setTradeQuery(Dbtable tradeQuery) {
this.tradeQuery = tradeQuery;
}
public Dbtable getTradeQuery() {
return this.tradeQuery;
}
public ArrayList getQueryResult() {
return this.queryResult;
}
public void setQueryResult(ArrayList queryResult) {
this.queryResult = queryResult;
}
public void addAreaInfo(Buffers inbuffer) {
this.outBuffer = inbuffer;
this.inBuffer = inbuffer;
log.LOG_INFO("进入addAreaInfo方法...");
int iResult = -1;
try {
AreaDAO areaDao = new AreaDAO();
iResult = addAreaInfo(areaDao);
}
catch (SaasApplicationException e) {
log.LOG_INFO(e.getMessage());
}
if (iResult != 0) {
this.outBuffer.setInt("RESULT_CODE", -1);
this.outBuffer.setString("RESULT_INFO", "业务处理失败!");
}
else {
this.outBuffer.setInt("RESULT_CODE", 0);
this.outBuffer.setString("RESULT_INFO", "业务处理成功!");
}
log.LOG_INFO("退出addAreaInfo方法...");
}
public int addAreaInfo(AreaDAO areaDao) throws SaasApplicationException {
commMethodMgr comm = new commMethodMgr();
String idx = comm.GenTradeId();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VID", idx);
tradeQuery.executeBy(areaExt.insBy("INS_BY_CONTACT"));
return 0;
}
/**
* 字段说明:[USER_AREA_CODE ]code:cn代表中文 en:代表英文 wt:代表台湾 [PARENT_AREA_CODE]中家(111111)
*/
public Map getCountryAllByCode(String code) throws SaasApplicationException {
Map countryMap = new HashMap();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VUSER_AREA_CODE", code);
ArrayList countryList = areaExt.selByList("SEL_COUNTRY_BY_CODE");
if (countryList != null && countryList.size() > 0) {
for (int i = 0; i < countryList.size(); i++) {
HashMap c_map = (HashMap) countryList.get(i);
String country_id = "";
String country_name = "";
if (c_map.get("area_code") != null) {
country_id = c_map.get("area_code").toString();
}
if (c_map.get("area_name") != null) {
country_name = c_map.get("area_name").toString();
}
countryMap.put(country_id, country_name);
}
}
return countryMap;
}
// 取出省份/城市/县、区信息
public Map getAreaByParent(String parent_id) throws SaasApplicationException {
Map childMap = new HashMap();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VPARENT_AREA_CODE", parent_id);
ArrayList childList = areaExt.selByList("SEL_BY_PARENT");
if (childList != null && childList.size() > 0) {
for (int i = 0; i < childList.size(); i++) {
HashMap c_map = (HashMap) childList.get(i);
String child_id = "";
String child_name = "";
if (c_map.get("area_code") != null) {
child_id = c_map.get("area_code").toString();
}
if (c_map.get("area_name") != null) {
child_name = c_map.get("area_name").toString();
}
childMap.put(child_id, child_name);
}
}
return childMap;
}
/**
* @param param_code
* @return 返回国家信息
* @throws SaasApplicationException
*/
public String getCountrySelect(String param_code) throws SaasApplicationException {
ArrayList list = getInfoByUpId(param_code);
String selectItems = "";
for (int i = 0; i < list.size(); i++) {
HashMap objMap = (HashMap) list.get(i);
String sKey = "";
String sValue = "";
if (objMap.get("area_code") != null) {
sKey = objMap.get("area_code").toString();
}
if (objMap.get("area_name") != null) {
sValue = objMap.get("area_name").toString();
}
selectItems = selectItems + "<option value=" + sKey + ">" + sValue + "</option>";
}
return selectItems;
}
/**
* @param province
* @return 通过省份取出城市
* @throws SaasApplicationException
*/
public ArrayList getCity(String province) throws SaasApplicationException {
ArrayList list = new ArrayList();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VPROVINCE", province);
list = areaExt.selByList("SEL_BY_CITY_QU");
log.LOG_INFO("getCity===========end");
return list;
}
public ArrayList getAll() throws SaasApplicationException {
ArrayList list = new ArrayList();
AreaExt areaExt = new AreaExt();
list = areaExt.selByList("SEL_BY_CITY_ALL");
log.LOG_INFO("===" + list.size());
return list;
}
public ArrayList getQu(String city, String qu) throws SaasApplicationException {
ArrayList list = new ArrayList();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VPROVINCE", city);
areaExt.setParam(":VQU", qu);
list = areaExt.selByList("SEL_BY_CITY_QU_NEW");
log.LOG_INFO("getQu===========end");
return list;
}
public int upAreaInfo() throws SaasApplicationException {
log.LOG_INFO("==begin.........");
ArrayList list = getAll();
if (list != null && list.size() > 0)
for (int i = 0; i < list.size(); i++) {
HashMap map = (HashMap) list.get(i);
String city = map.get("rsvalue1").toString();
ArrayList list1 = getCity(city);
if (list1 != null && list1.size() > 0)
for (int r = 1; r < list1.size(); r++) {
HashMap map1 = (HashMap) list1.get(r);
String qu = map1.get("remark").toString();
String area_code = map1.get("area_code").toString();
ArrayList list2 = getQu(city, qu);
if (list2 != null && list2.size() > 0)
for (int j = 1; j < list2.size(); j++) {
HashMap map2 = (HashMap) list2.get(j);
String code = map2.get("area_code").toString();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VPARENT_AREA_CODE", area_code);
areaExt.setParam(":VAREA_CODE", code);
tradeQuery.executeBy(areaExt.insBy("UPDATE_BY_CONTACT"));
}
}
}
return 0;
}
public static void main(String[] args) throws SaasApplicationException {
AreaInfo a = new AreaInfo();
int i = a.upAreaInfo();
System.out.println(i);
}
// update
public void upAreaInfo(Buffers inbuffer) {
this.outBuffer = inbuffer;
this.inBuffer = inbuffer;
log.LOG_INFO("进入upAreaInfo方法...");
int iResult = -1;
try {
iResult = upAreaInfo();
}
catch (SaasApplicationException e) {
log.LOG_INFO(e.getMessage());
}
if (iResult != 0) {
this.outBuffer.setInt("RESULT_CODE", -1);
this.outBuffer.setString("RESULT_INFO", "业务处理失败!");
}
else {
this.outBuffer.setInt("RESULT_CODE", 0);
this.outBuffer.setString("RESULT_INFO", "业务处理成功!");
}
log.LOG_INFO("退出upAreaInfo方法...");
}
public ArrayList getInfoByUpId(String parent_id) throws SaasApplicationException {
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VPARENT_AREA_CODE", parent_id);
ArrayList childList = areaExt.selByList("SEL_BY_PARENT");
return childList;
}
/**
* @param cust_id
* @param up_id
* @param img
* @return json data
* @throws SaasApplicationException
*/
public String getJsonDataForTree(String up_id, String img) throws SaasApplicationException {
String iconCls = img;
JSONArray jsonList = new JSONArray();
ArrayList rootList = getInfoByUpId(up_id);
if (rootList != null && rootList.size() > 0) {
for (int i = 0; i < rootList.size(); i++) {
HashMap map = (HashMap) rootList.get(i);
TreeObject tree = new TreeObject();
String text = map.get("area_name").toString();
String id = map.get("area_code").toString();
tree.setIconCls(iconCls);
tree.setId(id);
tree.setText(text);
TreeNode node = isLeaf(id);
tree.setChildren(node.getChildren());
tree.setLeaf(node.isLeaf());
jsonList.add(tree);
}
}
return jsonList.toString();
}
/**
* @param cust_id
* @param root_id
* @param nextList
* @return children
* @throws SaasApplicationException
*/
public JSONArray getChildrenNodes(String root_id, ArrayList nextList) throws SaasApplicationException {
JSONArray children = new JSONArray();
if (nextList != null && nextList.size() > 0) {
for (int i = 0; i < nextList.size(); i++) {
HashMap map = (HashMap) nextList.get(i);
TreeObject tree = new TreeObject();
String text = map.get("area_name").toString();
String id = map.get("area_code").toString();
tree.setId(id);
tree.setText(text);
TreeNode node = isLeaf(id);
tree.setChildren(node.getChildren());
tree.setLeaf(node.isLeaf());
children.add(tree);
}
}
return children;
}
/**
* @param cust_id
* @param up_id
* @return TreeNode
* @throws SaasApplicationException
*/
public TreeNode isLeaf(String up_id) throws SaasApplicationException {
ArrayList nextList = getInfoByUpId(up_id);
TreeNode node = new TreeNode();
if (nextList != null && nextList.size() > 0) {
node.setLeaf(false);
JSONArray children = getChildrenNodes(up_id, nextList);
node.setChildren(children);
}
return node;
}
public String getAreaNameByCode(String areaCode) {
ArrayList List = new ArrayList();
AreaExt areaExt = new AreaExt();
areaExt.setParam(":VAREACODE", areaCode);
List = areaExt.selByList("SEL_AREANAME_BY_CODE");
HashMap map = (HashMap) List.get(0);
String areaName = "";
areaName = map.get("area_name").toString();
return areaName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -