?? customeraction.java
字號:
* @throws ApplicationException
*/
public ActionForward newOption(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
// 可用選項
List<String> enableOptions = new ArrayList<String>();
enableOptions.add(Constants.CREATETIME);
enableOptions.add(Constants.REPRESENT);
enableOptions.add(Constants.BIZTYPE);
enableOptions.add(Constants.REGISTERCAPITAL);
enableOptions.add(Constants.EMPLOYEENUM);
enableOptions.add(Constants.REGIONOF);
enableOptions.add(Constants.FAX);
enableOptions.add(Constants.ZIPCODE);
enableOptions.add(Constants.WEBSITE);
enableOptions.add(Constants.EMAIL);
enableOptions.add(Constants.HONESTGRADE);
enableOptions.add(Constants.MANAGERLEVEL);
enableOptions.add(Constants.BREEDVISUALIZE);
enableOptions.add(Constants.CUSTOMERSTATE);
enableOptions.add(Constants.CUSTOMERSOURCE);
enableOptions.add(Constants.REMARK);
// 預選選項
List<String> preOptions = new ArrayList<String>();
preOptions.add(Constants.CUSTOMER_NAME);
preOptions.add(Constants.INDUSTRYOf);
preOptions.add(Constants.COMMUNADDR);
preOptions.add(Constants.PHONE);
request.setAttribute("enableOptions", enableOptions);
request.setAttribute("preOptions", preOptions);
return mapping.findForward("newOption");
}
/**
* 創建客戶新選項
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward newCreateOption(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ApplicationException {
String optionName = request.getParameter("optionName");
User user = SessionMgr.getCustSession(request);
UserDefined ud = null;
UserFilter uf = null;
if (user != null) {
ud = new UserDefined();
ud.setDefinedName(optionName);
ud.setType(Constants.ALLCUSTOMER_INT);// 設置選項類型
ud.setUser(user);
customerMgr.addUserDefined(ud); // 保存用戶選項
for (int i = 1; i <= 20; i++) {
uf = new UserFilter();
String fieldId = request.getParameter("field" + i);// 字段
String operatorPre = request.getParameter("operator" + i);// 預運算符
String value = request.getParameter("value" + i);// 值
uf.setOperatorName(operatorPre);// 保存操作名
uf.setFilter(value);// 保存值
if (!StringTool.isNotBlank(fieldId)
|| !StringTool.isNotBlank(operatorPre)
|| !StringTool.isNotBlank(value)) {// 若字段為空
break;
}
String field = StringTool.getStringByField(fieldId);// 字段
String operator = StringTool.transformStr(operatorPre);// 轉換運算符
if (operatorPre.equals(Constants.STARTCHAR)) {// 若運算符是起始字符
value = "'" + value + "%'";
} else if (operator.equals("like") || operator.equals("!like")) {// 若是模糊查詢
value = "'%" + value + "%'";
} else {// 其余為數值或字符
value = StringTool.transformString(fieldId, value);
}
uf.setFilterName(field);
uf.setOperator(operator);
uf.setFilterValue(value);
uf.setUserDefined(ud);
customerMgr.addUserFilter(uf);// 保存過濾條件
}
String optionFields = request.getParameter("preOptions"); // 分離預選項
UserField userField = new UserField();
;
userField.setFieldName(optionFields);
userField.setUserDefined(ud);
customerMgr.addUserField(userField);// 保存顯示字段
System.out.println("顯示字段" + userField.getFieldName());
request.setAttribute("isSuccess", Constants.SAVESUCCESS);
}
return mapping.findForward("newOptionAgain");
}
/**
* 搜索所有的選項
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward searchOption(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
User user = SessionMgr.getCustSession(request);
List<UserDefined> options = customerMgr.getOptionsByUserAndType(user,
Constants.ALLCUSTOMER_INT);
request.setAttribute("options", options);
return mapping.findForward("customerList");
}
/**
* 修改客戶信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward modifyCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
CustomerForm cForm = (CustomerForm)form;
// String customerId = request.getParameter("id");
String customerId = cForm.getId();
String forward = "login";
// 前置條件
if (!StringTool.isNotBlank(customerId)) {
request.setAttribute(Constants.ERRMSG, Constants.INPUTBANK);
throw new ApplicationException("the param you input is illegal");
}
try {
Customer customer = customerMgr.getCustomerDao().getById(
Integer.parseInt(customerId));
CustomerVo customerVo = new CustomerVo();
// 將客戶實體的屬性復制給客戶VO
BeanUtils.copyProperties(customerVo, customer);
//2009-02-25 add
customerVo.setDelRights(cForm.getDelRights());
customerVo.setModifyRights(cForm.getModifyRights());
//end add
request.setAttribute("customerVo", customerVo);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute(Constants.ERRMSG, Constants.WITHOUTDATA);
throw new ApplicationException("not find data!");
}
forward = "editCustomer";
return mapping.findForward(forward);
}
/**
* 刪除客戶---只更改客戶的狀態
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward deleteCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
String customerId = request.getParameter("id");
logger.debug("有到這里嗎..." + customerId);
if (!StringTool.isNotBlank(customerId)) {
throw new ApplicationException("the param you input is illegal!!!");
}
User user = SessionMgr.getCustSession(request);
// 刪除客戶
relationManage.updateEntitysStates(user.getId(), DateTimeTool
.getCurrentDate("yyyy-MM-dd HH:mm:ss"),
ClassCodeMgr.CUSTOMERINT, Integer.parseInt(customerId),
Constants.DELETESELF, Constants.PASSIVITY);
logger.debug("有到這里嗎...呵呵");
return mapping.findForward("customerAll");
}
/**
* 編輯客戶選項
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward editOption(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
String optionId = request.getParameter("optionId");
UserDefined customerDefined = null;
if (StringTool.isNotBlank(optionId)) {// 若選項id不空
// 根據選項id搜索客戶選項
customerDefined = customerMgr.getUserDefinedById(Integer
.parseInt(optionId));
}
// 將選項封裝成vo
CustomerDefinedVo customerDefinedVo = customerMgr
.transaformCustomerDefinedPoToVo(customerDefined);
System.out.println("可選字段" + customerDefinedVo.getNoUserFields());
request.setAttribute("customerDefinedVo", customerDefinedVo);
return mapping.findForward("editOption");
}
/**
* 修改客戶選項
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward modifyOption(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
String optionId = request.getParameter("optionId");
UserDefined ud = null;
if (StringTool.isNotBlank(optionId)) {// 若選項不為空
ud = customerMgr.getUserDefinedById(Integer.parseInt(optionId));
}
String optionName = request.getParameter("optionName");
User user = SessionMgr.getCustSession(request);
if (user != null) {
ud.setDefinedName(optionName);//視圖名稱
ud.setType(Constants.ALLCUSTOMER_INT);// 設置選項類型
ud.setUser(user);
ud.setInDate(new Date());
customerMgr.updateOption(ud);// 保存用戶選項(視圖)
UserFilter uf = null;
for (int i = 1; i <= 20; i++) {// 遍歷所有的過濾條件
/**過濾條件id*/
String filterId = request.getParameter("filterId" + i);
String fieldId = request.getParameter("field" + i);// 字段
String operatorPre = request.getParameter("operator" + i);// 預運算符名
System.out.println("運算符為空嗎" + operatorPre);
String value = request.getParameter("value" + i);// 值
boolean isDel = false;//要刪除該過濾條件嗎,初始值不為
if (StringTool.isNotBlank(filterId)) {// 若過濾條件不為空,則從數據庫中搜索該過濾條件
uf = customerMgr.getUserFilterById(filterId);
// 若字段名或運算符為空,則刪除該過濾條件
if (fieldId.equals("") || operatorPre.equals("")) {
customerMgr.deleteFilter(uf);
isDel = true;
}
} else {
//初始化一個過濾條件
uf = new UserFilter();
System.out.println("有到這里嗎1..." + uf);
}
//若沒有刪除,則保存當前過濾條件
if(!isDel) {
uf.setOperatorName(operatorPre);// 保存運算符名
uf.setFilter(value);// 保存SQL值
String field = StringTool.getStringByField(fieldId);// 字段
String operator = StringTool.transformStr(operatorPre);// 轉換運算符
if (operatorPre.equals(Constants.STARTCHAR)) {// 若運算符是起始字符
value = "'" + value + "%'";
} else if (operatorPre.equals(Constants.INCLUDE) || operatorPre.equals(Constants.EXCLUDE)) {// 若是模糊查詢
value = "'%" + value + "%'";
} else {// 其余為數值或字符
value = StringTool.transformString(fieldId, value);
}
uf.setFilterName(field);//過濾字段名稱
uf.setOperator(operator);//經轉換后的運算符值
uf.setFilterValue(value);//組合后的SQL值
uf.setUserDefined(ud);
if (StringTool.isNotBlank(filterId)) {// 若過濾條件不為空,則修改該過濾條件
customerMgr.updateUserFilter(uf);// 修改過濾條件
} else {
customerMgr.addUserFilter(uf);// 保存過濾條件
System.out.println("保存..." + uf);
}
}
}
String optionFields = request.getParameter("preOptions"); // 分離預選項
UserField userField = customerMgr.getUserFieldByOption(ud);
userField.setFieldName(optionFields);
userField.setUserDefined(ud);
customerMgr.updateUserField(userField);// 修改顯示字段
System.out.println(userField.getFieldName());
request.setAttribute("isSuccess", Constants.SAVESUCCESS);
}
return mapping.findForward("editOptionAgain");
}
/**
* 羅列左邊頁面的客戶列表;
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward leftCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
List<Customer> topCustomerList = customerMgr.getTopCustomer();
request.setAttribute("topCustomerList", topCustomerList);
System.out.println("測試:" + topCustomerList);
return mapping.findForward("leftCustomer");
}
/**
* 根據客戶名稱搜索客戶;
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward findCustomerByName(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ApplicationException {
String nameLike = "";
try {
nameLike = URLDecoder.decode(request.getParameter("nameLike"),
"utf-8");// 傳中文參數轉編碼;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
User user = SessionMgr.getCustSession(request);
List<UserDefined> options = customerMgr.getOptionsByUserAndType(user,
Constants.ALLCUSTOMER_INT);// 根據用戶獲取所有用戶自定義選項
request.setAttribute("options", options);
String forward = "customerList";
System.out.println(nameLike);
List<Customer> customers = null;
if (user != null) {
customers = customerMgr.getCustomerByName(nameLike);
System.out.println("一共有幾個選項:" + customers.size());
String currentPage = request.getParameter("currentPage");
XPage xpage = new XPage(request.getContextPath()
+ "/customer.do?method=findCustomerByName&nameLike="
+ nameLike, customers.size(), 1, 8, customers);
if (currentPage != null && !currentPage.equals("")) {
xpage.setCurrentItems(Integer.parseInt(currentPage));
} else {
xpage.setCurrentItems(1);
}
xpage.setPageBar();
request.setAttribute("xpage", xpage);
} else {
request.setAttribute("loginerror", Constants.MESSAGE);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -