📄 contactaction.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.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.customer.CustomerContact;
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.ContactMgr;
import com.yuanchung.sales.struts.customer.form.ContactForm;
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.CustomerVo;
import com.yuanchung.sales.vo.busiOpport.BusinessOpportunityVo;
import com.yuanchung.sales.vo.contact.ContactDefinedVo;
import com.yuanchung.sales.vo.contact.ContactVo;
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 ContactAction extends DispatchAction {
private static Logger logger = Logger.getLogger(ContactAction.class);
private ContactMgr contactMgr;
private AuthorizationMgr authorizationMgr;
public void setAuthorizationMgr(AuthorizationMgr authorizationMgr) {
this.authorizationMgr = authorizationMgr;
}
public void setContactMgr(ContactMgr contactMgr) {
this.contactMgr = contactMgr;
}
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 newCreateContact(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ApplicationException {
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
ContactForm contactForm = (ContactForm) form;
CustomerContact contact = new CustomerContact();
// 先保存联系人 ,后保存用户-联系人
User user = SessionMgr.getCustSession(request);
contact.setName(contactForm.getName());// 姓名
contact.setSatulation(contactForm.getSatulation()); // 称谓
contact.setDomicile(contactForm.getDomicile());// 籍贯
contact.setBirthday(contactForm.getBirthday());// 生日
contact.setEducation(contactForm.getEducation());// 学历
contact.setPosition(contactForm.getPosition());// 职务
contact.setDepartMent(contactForm.getDepartMent());// 所在部门
contact.setMobilePhone(contactForm.getMobilePhone());// 手机
contact.setIsSmoke(contactForm.getIsSmoke());// 是否吸烟
contact.setIsWine(contactForm.getIsWine());// 是否喝酒
contact.setEntertainment(contactForm.getEntertainment());// 喜欢的娱乐场所
contact.setAssistant(contactForm.getAssistant());// 助理
contact.setAssiPhone(contactForm.getAssiPhone());// 助理电话
contact.setComPhone(contactForm.getComPhone());// 办公电话
contact.setEmail(contactForm.getEmail());// 电子邮件
contact.setMsn(contactForm.getMsn());// msn
contact.setFax(contactForm.getFax());// 传真
contact.setHomeAddr(contactForm.getHomePhone());
contact.setHomePhone(contactForm.getHomePhone());// 家庭电话
contact.setInterests(contactForm.getInterests());// 性趣爱好
contact.setCharacters(contactForm.getCharacter());// 性格特征
contact.setRemark(contactForm.getRemark());
// 保存时间
contact.setInDate(DateTimeTool.getDateByStr(DateTimeTool
.dateToStrFormat("yyyy-MM-dd HH:mm:ss", new Date())));
contact.setFlag(1);// 默认为激活
// 添加客户
Customer customer = contactMgr.getCustomerById(contactForm
.getCustomerId());
contact.setCustomer(customer);
// 上次修改时间
contact.setLastModifyTime(DateTimeTool.dateToStrFormat(
"yyyy-MM-dd HH:mm:ss", new Date()));
contact.setModifyManId(user.getId());// 上次修改的用户ID
contact.setUser(user);
// 保存联系人
contactMgr.addContact(contact);
String forward = "contactCorrelation";
String param = request.getParameter("param");
if (param != null && param.equals("newAgain")) {// 若是保存并新建
forward = "newContact";
} else {
// 跳转到联系人关联信息页面
// 查找到当前联系人
CustomerContact contactCurrent = contactMgr.getContactDao()
.findContactLastest();
ContactVo contactVo = new ContactVo();
try {
BeanUtils.copyProperties(contactVo, contactCurrent);
Customer c = contactCurrent.getCustomer();
if (c != null) {
contactVo.setCustomerId(c.getId());
contactVo.setCustomerName(c.getCustomerName());
}
// 查找上次修改人
User lastModifyMan = contactMgr.getContactDao()
.findLastModifyMan(contactCurrent.getModifyManId());
request.setAttribute("modifyUser", new UserVo(lastModifyMan
.getId(), lastModifyMan.getFamilyName()));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
request.setAttribute("contactVo", contactVo);
}
return mapping.findForward(forward);
}
/**
* 快速添加联系人;
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward addContact(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);// 当前正在操作的用户;
ContactForm contactForm = (ContactForm) form;// 从页面上快速获取form对象;
CustomerContact customerContact = new CustomerContact();// 实例一个联系人pojo对象;
try {
BeanUtils.copyProperties(customerContact, contactForm);// 把form的属性拷贝到pojo对象上面;
customerContact.setUser(user);// 设置创建用户;
customerContact.setModifyManId(user.getId());// 设置修改时间;
customerContact.setInDate(DateTimeTool.getDateByStr(DateTimeTool
.dateToStrFormat("yyyy-MM-dd HH:mm:ss", new Date())));
customerContact.setLastModifyTime(DateTimeTool.dateToStrFormat(
"yyyy-MM-dd HH:mm:ss", new Date()));// 设置修改时间;
customerContact.setFlag(Constants.ACTIVEFLAG);// 设置联系人激活状态;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
try {
contactMgr.addContact(customerContact);// 保存联系人;
} catch (Exception e) {
e.printStackTrace();
logger.error(Constants.UNABLESAVEUSER);
request.setAttribute(Constants.ERRMSG, Constants.UNABLESAVEUSER);
throw new PersistentObjException(Constants.PERSISTENT_OBJEXCEPTION);
}
logger.debug("联系的ID" + customerContact.getId());
String contactId = request.getParameter("contactId");
String contactName = request.getParameter("contactName");
// 把联系人的名字和id回填到打开页面的空上;
out.print("<script>window.opener.document.getElementById('" + contactId
+ "').value ='" + customerContact.getId()
+ "';window.opener.document.getElementById('" + contactName
+ "').value ='" + customerContact.getName()
+ "';window.close();</script>");// 关闭被打开的页面;
return null;
}
/**
* 为联系人添加而搜索客户
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward allCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
User user = SessionMgr.getCustSession(request);
String forward = "customerList";
if (user != null) {
List<CustomerVo> customers = contactMgr.getCustomerByUser(user,
Constants.ACTIVEFLAG);
String currentPage = request.getParameter("currentPage");
XPage xpage = new XPage(request.getContextPath()
+ "/contact.do?method=allCustomer", 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);
forward = "userLogin";
}
return mapping.findForward(forward);
}
/**
* 查找所有联系人
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws ApplicationException
*/
public ActionForward contactAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ApplicationException {
String forward = "contactList";
try {
User user = SessionMgr.getCustSession(request);
// 2009-02-25 add
Rights rights = SessionMgr.getJspRightsControl(request).get("2")
.getRightsMap().get("204");
String style = rights.getStyle();
String userIds = authorizationMgr.findUserDataRange(rights.getId(),
user);
logger.debug("userIds : " + userIds);
// end add
List<UserDefined> contactOptions = new ArrayList<UserDefined>();
if (Constants.STYLE_BLOCK.equals(style)) {// 2009-02-25 add 数据范围
contactOptions = contactMgr.getOptionsByUserAndType(user,
Constants.ALLCONTACT_INT);// 根据用户获取所有用户自定义选项
}
request.setAttribute("contactOptions", contactOptions);
// 查找用户的所有联系人
// 2009-02-25 modify
// List<ContactVo> contacts = contactMgr.getContactByUser(user);
List<ContactVo> contacts = contactMgr.getContactByUser(userIds,
request);
// end modify
// List<ContactVo> contacts = contactMgr.getContact();
String currentPage = request.getParameter("currentPage");
XPage xpage = new XPage(request.getContextPath()
+ "/contact.do?method=contactAll", contacts.size(), 1, 10,
contacts);
if (currentPage != null && !currentPage.equals("")) {
xpage.setCurrentItems(Integer.parseInt(currentPage));
} else {
xpage.setCurrentItems(1);
}
xpage.setPageBar();
request.setAttribute("xpage", xpage);
} catch (Exception e) {
e.printStackTrace();
request.setAttribute(Constants.ERRMSG, Constants.FNINNOCONTACT);
}
return mapping.findForward(forward);
}
/**
* 创建客户新选项
*
* @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("contactOptionName");
User user = SessionMgr.getCustSession(request);
// 初始化用户自定义选项
UserDefined userDefined = contactMgr.initUserDefined(user, optionName,
Constants.ALLCONTACT_INT, new Date());
contactMgr.addUserDefined(userDefined);// 保存自定义选项
UserFilter uf = null;
for (int i = 1; i <= 20; i++) {
uf = new UserFilter();
String fieldId = request.getParameter("field" + i);// 字段
String operatorPre = request.getParameter("operator" + i);// SW运算符
String valuePre = request.getParameter("value" + i);// 值
// 判断输入条件是否为空
if (!StringTool.isNotBlank(fieldId)
|| !StringTool.isNotBlank(operatorPre)
|| !StringTool.isNotBlank(valuePre)) {// 若字段为空
break;
}
String field = contactMgr.getStringByField(fieldId);// 字段转换
String operator = StringTool.transformStr(operatorPre);// 转换运算符
String filerValue = "";
if (operatorPre.equals(Constants.STARTCHAR)) {// 若运算符是起始字符
filerValue = "'" + valuePre + "%'";
} else if (operator.equals("like") || operator.equals("!like")) {// 若是模糊查询
filerValue = "'%" + valuePre + "%'";
} else {// 其余为数值或字符
filerValue = StringTool.transformString(fieldId, valuePre);
}
// 初始化用户过滤条件
UserFilter userFilter = contactMgr.initUserFilter(userDefined,
field, operator, filerValue, operatorPre, valuePre);
contactMgr.addUserFilter(userFilter);// 保存过滤条件
}
String optionFields = request.getParameter("preOptions"); // 分离预选项
UserField userField = contactMgr.initUserFiled(userDefined,
optionFields);
contactMgr.addUserFiled(userField);// 保存显示字段
System.out.println("显示字段" + userField.getFieldName());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -