?? customeraction.java
字號:
package com.yuanchung.sales.struts.customer.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.yuanchung.sales.config.ClassCodeMgr;
import com.yuanchung.sales.config.ConfigMgr;
import com.yuanchung.sales.constants.CorrelationConstant;
import com.yuanchung.sales.constants.SystemConstant;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.exception.IllegalParameterException;
import com.yuanchung.sales.exception.PersistentObjException;
import com.yuanchung.sales.model.admin.Rights;
import com.yuanchung.sales.model.customer.Customer;
import com.yuanchung.sales.model.user.User;
import com.yuanchung.sales.model.userDefined.UserDefined;
import com.yuanchung.sales.model.userDefined.UserField;
import com.yuanchung.sales.model.userDefined.UserFilter;
import com.yuanchung.sales.service.RelationManage;
import com.yuanchung.sales.service.admin.authorization.AuthorizationMgr;
import com.yuanchung.sales.service.customer.CustomerMgr;
import com.yuanchung.sales.struts.customer.form.CustomerForm;
import com.yuanchung.sales.util.Constants;
import com.yuanchung.sales.util.DateTimeTool;
import com.yuanchung.sales.util.SessionMgr;
import com.yuanchung.sales.util.StringTool;
import com.yuanchung.sales.util.XPage;
import com.yuanchung.sales.vo.CustomerDefinedVo;
import com.yuanchung.sales.vo.CustomerVo;
import com.yuanchung.sales.vo.busiOpport.BusinessOpportunityVo;
import com.yuanchung.sales.vo.contact.ContactVo;
import com.yuanchung.sales.vo.right.WebRightsView;
import com.yuanchung.sales.vo.taskEvent.ActivityTaskVo;
import com.yuanchung.sales.vo.taskEvent.CorrelationVo;
import com.yuanchung.sales.vo.taskEvent.EventVo;
import com.yuanchung.sales.vo.user.UserVo;
public class CustomerAction extends DispatchAction {
private static Logger logger = Logger.getLogger(CustomerAction.class);
private CustomerMgr customerMgr;
private AuthorizationMgr authorizationMgr;
public void setAuthorizationMgr(AuthorizationMgr authorizationMgr) {
this.authorizationMgr = authorizationMgr;
}
public void setCustomerMgr(CustomerMgr customerMgr) {
this.customerMgr = customerMgr;
}
private RelationManage relationManage;
public RelationManage getRelationManage() {
return relationManage;
}
public void setRelationManage(RelationManage relationManage) {
this.relationManage = relationManage;
}
/**
* 快速添加客戶;
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward addCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
PrintWriter out = null;
try {
out = response.getWriter();// 設置out輸出流;
} catch (IOException e1) {
e1.printStackTrace();
}
User user = SessionMgr.getCustSession(request);// 當前正在操作的用戶;
CustomerForm customerForm = (CustomerForm) form;
Customer customer = new Customer();
// 拷貝值;
customer.setCustomerName(customerForm.getCustomerName());
customer.setEmail(customerForm.getEmail());
customer.setFax(customerForm.getFax());
customer.setPhone(customerForm.getPhone());
customer.setCommunAddr(customerForm.getCommunAddr());
customer.setUser(user);
customer.setModifyManId(user.getId());
// 插入記錄的時間
customer.setInDate(DateTimeTool.dateToStrFormat("yyyy-MM-dd HH:mm:ss",
new Date()));
// 上次修改的時間
customer.setModifyManId(user.getId());
customer.setLastModifyTime(DateTimeTool.dateToStrFormat(
"yyyy-MM-dd HH:mm:ss", new Date()));
customer.setFlag(Constants.ACTIVEFLAG);// 設置激活狀態;
try {
// 保存客戶
customerMgr.addCustomer(customer);
} catch (Exception e) {
e.printStackTrace();
logger.error(Constants.UNABLESAVEUSER);
request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
throw new PersistentObjException(Constants.PERSISTENT_OBJEXCEPTION);
}
out
.print("<script>window.opener.document.getElementById('recordId').value ='"
+ customer.getId()
+ "';window.opener.document.getElementById('recordName').value ='"
+ customer.getCustomerName()
+ "';window.close();</script>");// 關閉被打開的頁面;
return null;
}
/**
* 新建客戶
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward newCreate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
CustomerForm customerForm = (CustomerForm) form;
Customer customer = new Customer();
String id = customerForm.getId();
if (StringTool.isNotBlank(id)) {// 修改客戶資料
customer = customerMgr.getCustomerById(Integer.parseInt(id));
}
customer.setCustomerName(customerForm.getCustomerName());// 客戶名稱
customer.setCreateTime(customerForm.getCreateTime());// 客戶公司成立時間
customer.setLegalRepresent(customerForm.getLegalRepresent());// 法人代表
customer.setBizType(customerForm.getBizType());// 企業類型
String registerCapital = customerForm.getRegisterCapital();
if (registerCapital != null) {// 判斷注冊的地方是否是為空;
String[] registerCapitals = registerCapital.split(",");
StringBuffer formatCapital = new StringBuffer();
for (int i = 0; i < registerCapitals.length; i++) {
formatCapital.append(registerCapitals[i]);
}
if (StringTool.isNotBlank(formatCapital.toString())) {
customer.setRegisterCapital(Integer.parseInt(formatCapital
.toString()));// 注冊資金
}
}
String industryType = customerForm.getIndustryType();
String industryOf = customerForm.getIndustryOf();
if (StringTool.isNotBlank(industryType)) {// 如果所屬行業不為空
customer.setIndustryOf(industryOf);// 所屬行業
customer.setIndustryType(industryType + "/" + industryOf);// 行業類別
}
logger.debug("行業類別:" + customerForm.getIndustryType());
// 職員數
String employeeNum = customerForm.getEmployeeNum();
customer.setEmployeeNum(employeeNum);
if (employeeNum != null && employeeNum.equals(Constants.MINEMPLOYEE)) {
customer.setEmployeeMinNum(0);
customer.setEmployeeMaxNum(8);
} else if (employeeNum != null
&& employeeNum.equals(Constants.MAXEMPLOYEE)) {
customer.setEmployeeMinNum(2000);
customer.setEmployeeMaxNum(Constants.MAXINT);
} else if (employeeNum != null && !employeeNum.equals("")) {
String[] nums = employeeNum.split("-");
customer.setEmployeeMinNum(Integer.parseInt(nums[0]));
customer.setEmployeeMaxNum(Integer.parseInt(nums[1]));
}
// 區域
StringBuffer regionOf = new StringBuffer();
String s1 = customerForm.getS1();
String s2 = customerForm.getS2();
String s3 = customerForm.getS3();
if (s1 != null && !s1.equals(Constants.PROVINCE)) {
regionOf.append(s1);
customer.setProvince(s1);
}
if (s2 != null && !s2.equals(Constants.CITY)) {
regionOf.append(s2);
customer.setCity(s2);
}
if (s3 != null && !s3.equals(Constants.COUNTY)) {
regionOf.append(s3);
customer.setCounty(s3);
}
customer.setRegionOf(regionOf.toString());
customer.setCommunAddr(customerForm.getCommunAddr());// 通信地址
customer.setPhone(customerForm.getPhone());// 聯系電話
customer.setFax(customerForm.getFax());// 傳真
customer.setZipCode(customerForm.getZipCode());// 郵政編碼
customer.setWebSite(customerForm.getWebSite());// 網址
customer.setEmail(customerForm.getEmail());// 電子郵件
customer.setHonestGrade(customerForm.getHonestGrade());// 誠信等級
customer.setManagerLevel(customerForm.getManagerLevel());// 管理水平
customer.setBreedVisualize(customerForm.getBreedVisualize());// 品牌形象
customer.setCustomerState(customerForm.getCustomerState());// 客戶狀態
customer.setCustomerSource(customerForm.getCustomerSource());// 客戶來源
customer.setRemark(customerForm.getRemark());// 備注
customer.setFlag(Constants.ACTIVEFLAG);// 默認為激活
// 插入記錄的時間
customer.setInDate(DateTimeTool.dateToStrFormat("yyyy-MM-dd HH:mm:ss",
new Date()));
// 上次修改的時間
customer.setLastModifyTime(DateTimeTool.dateToStrFormat(
"yyyy-MM-dd HH:mm:ss", new Date()));
User user = SessionMgr.getCustSession(request);// 會話用戶默認為客戶所屬用戶
customer.setUser(user);// 所屬用戶
customer.setModifyManId(user.getId());// 做修改的用戶ID
try {
// 保存客戶
customerMgr.addCustomer(customer);
} catch (Exception e) {
e.printStackTrace();
logger.error(Constants.UNABLESAVEUSER);
request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
throw new PersistentObjException("can not persistent obj!");
}
String forward = "customerCorrelation";
String param = request.getParameter("param");
if (param != null && param.equals("newAgain")) {// 若是保存并新建
forward = "newCustomer";
} else {
try {
CustomerVo customerVo = new CustomerVo();
if (StringTool.isNotBlank(id)) {// 若客戶ID不為空
// 根據ID查找所要的客戶
// 跳轉到客戶相關action
return new ActionForward("/customer.do?method=correlation");
} else {
// 查找最新保存的客戶
Customer customerLastest = customerMgr.getCustomerDao()
.getCustomerLastest();
BeanUtils.copyProperties(customerVo, customerLastest);
}
request.setAttribute("customerVo", customerVo);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute(Constants.ERRMSG, Constants.ERRORSYSTEM);
throw new ApplicationException("no find data");
}
}
return mapping.findForward(forward);
}
/**
* 根據用戶取得所有的客戶
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
@SuppressWarnings("unchecked")
public ActionForward customerAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
User user = SessionMgr.getCustSession(request);
// 2009-02-05 add 數據范圍
Rights rights = SessionMgr.getJspRightsControl(request).get("1")
.getRightsMap().get("104");
String style = rights.getStyle();
String userIds = authorizationMgr.findUserDataRange(rights.getId(),
user);
// if(!"".equals(userIds)){
// userIds = userIds + "," + user.getId();
// }else{
// userIds = user.getId().toString();
// }
logger.debug("userIds : " + userIds);
// 刪除(數據范圍)
Rights delRights = SessionMgr.getJspRightsControl(request).get("1")
.getRightsMap().get("103");
String delUserIds = authorizationMgr.findUserDataRange(delRights
.getId(), user);
logger.debug("delUserIds : " + delUserIds);
// 修改(數據范圍)
Rights modifyRights = SessionMgr.getJspRightsControl(request).get("1")
.getRightsMap().get("102");
String modifyUserIds = authorizationMgr.findUserDataRange(modifyRights
.getId(), user);
// end
List<UserDefined> options = new ArrayList<UserDefined>();
if (Constants.STYLE_BLOCK.equals(style)) {// 2009-02-05 add 數據范圍
options = customerMgr.getOptionsByUserAndType(user,
Constants.ALLCUSTOMER_INT);// 根據用戶獲取所有用戶自定義選項
}
request.setAttribute("options", options);
String forward = "customerList";
List<Customer> customers = null;
if (user != null) {
// 根據用戶搜索所屬客戶
// 2009-02-06 modify
// customers = customerMgr.getCustomerByUser(user,
// Constants.ACTIVEFLAG);
customers = customerMgr.getCustomerByUser(userIds,
Constants.ACTIVEFLAG);
for (int i = 0; i < customers.size(); i++) {
if (authorizationMgr.isRights(customers.get(i).getUser()
.getId(), delUserIds)) {
customers.get(i).setDelRights("y");
}
if (authorizationMgr.isRights(customers.get(i).getUser()
.getId(), modifyUserIds)) {
customers.get(i).setModifyRights("y");
}
}
// end modify
String currentPage = request.getParameter("currentPage");
XPage xpage = new XPage(request.getContextPath()
+ "/customer.do?method=customerAll", customers.size(), 1,
10, 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);
forward = "userLogin";
}
return mapping.findForward(forward);
}
/**
* 創建一個新選項
*
* @param mapping
* @param form
* @param request
* @param response
* @return
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -