📄 onlineordermgrimpl.java
字号:
package com.yuanchung.sales.service.service.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
import com.yuanchung.sales.config.ConfigMgr;
import com.yuanchung.sales.dao.service.ServiceOrderDAO;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.model.customer.Customer;
import com.yuanchung.sales.model.customer.CustomerContact;
import com.yuanchung.sales.model.service.Category;
import com.yuanchung.sales.model.service.CustAccount;
import com.yuanchung.sales.model.service.ServiceOrder;
import com.yuanchung.sales.model.service.ServiceOrderFile;
import com.yuanchung.sales.model.user.User;
import com.yuanchung.sales.service.service.OnlineOrderMgr;
import com.yuanchung.sales.struts.service.form.ServiceOrderForm;
import com.yuanchung.sales.util.Constants;
import com.yuanchung.sales.util.DateTimeTool;
import com.yuanchung.sales.util.OnlineSessionMgr;
import com.yuanchung.sales.util.Page;
import com.yuanchung.sales.util.Upload;
import com.yuanchung.sales.vo.service.XMLFileVo;
public class OnlineOrderMgrImpl implements OnlineOrderMgr {
private static Logger logger = Logger.getLogger(OnlineOrderMgrImpl.class);
private ServiceOrderDAO serviceOrderDAO;
public ServiceOrderDAO getServiceOrderDAO() {
return serviceOrderDAO;
}
public void setServiceOrderDAO(ServiceOrderDAO serviceOrderDAO) {
this.serviceOrderDAO = serviceOrderDAO;
}
// 在线获取客户服务单
public Page getMyOnlineOrder(String state, int flag, int customerId,
String path, int currentPage, int rowsPerPage) {
Page page = null;
List<ServiceOrder> serviceOrderList = null;
int count = 0;
try{
serviceOrderList = serviceOrderDAO.getMyOnlineOrder(state, flag, customerId, path, currentPage, rowsPerPage);
count = serviceOrderDAO.getMyOnlineOrderCount(state, flag, customerId);
page = new Page(path,count,currentPage,rowsPerPage,serviceOrderList);
}catch(Exception e){
logger.error(e.getMessage());
throw new ApplicationException(e.getMessage());
}
return page;
}
// 更新服务单
public void updateOnlineOrder(ServiceOrder serviceOrder) {
serviceOrderDAO.attachDirty(serviceOrder);
}
public void saveSOFile(ServiceOrderFile soFile) {
serviceOrderDAO.saveSOFile(soFile);
}
// 保存服务单
public void saveServiceOrder(ServiceOrder serviceOrder) {
serviceOrderDAO.save(serviceOrder);
}
// 查看用户信息
public String[] viewUser(int id) {
User user = null;
try {
user = serviceOrderDAO.getUserById(id);
System.out.println("在线查看用户的名字是:" + user.getFamilyName());
String[] userInfo = { user.getFamilyName(), user.getPhone(),
user.getEmail(), user.getPosition() };
return userInfo;
} catch (Exception re) {
re.printStackTrace();
throw new ApplicationException(re.getMessage());
}
}
// 保存在线填的问题单
public void newOnlineOrder(ServiceOrderForm serviceOrderForm,
HttpServletRequest request, ActionForm form) {
ServiceOrder serviceOrder = new ServiceOrder();
serviceOrder.setSerialNum(serviceOrderForm.getSerialNum());
serviceOrder.setContent(serviceOrderForm.getContent());
serviceOrder.setState(Constants.SERVICE_ORDER_STATE_NO_ASSIGN);// 默认为未处理服务单
int flag = Constants.SERVICE_ORDER_OUTER;
serviceOrder.setFlag(flag);// online在线填的单
serviceOrder.setCreateTime(new Date());
CustAccount custAccount = OnlineSessionMgr
.getCustAccountSession(request);
Customer customer = custAccount.getCustomer();
if (customer != null) {
serviceOrder.setCustomer(customer);
}
ServiceOrder justSaveSO = null;
// 联系人的保存操作
String contactIdStr = request.getParameter("contactId");
try {
if (contactIdStr != null && !"".equals(contactIdStr)) {
serviceOrder.setCustomerContact(serviceOrderDAO
.getContactById(Integer.parseInt(contactIdStr)));
} else {
CustomerContact customerContact = new CustomerContact();
customerContact.setName(request
.getParameter("otherContactName"));
customerContact.setMobilePhone(request
.getParameter("mobilePhone"));
customerContact.setEmail(request.getParameter("email"));
customerContact.setFax(request.getParameter("fax"));
customerContact.setComPhone(request.getParameter("comPhone"));
// 设置联系人的flag = 4为临时联系人
customerContact.setFlag(Constants.CASUAL_FLAG);
customerContact.setInDate(new Date());
customerContact.setCustomer(customer);
customerContact.setUser(customer.getUser());
customerContact.setModifyManId(0);//客户创建的联系人
serviceOrderDAO.saveCustomerContact(customerContact);
CustomerContact justSaveCC = serviceOrderDAO.getCustomerContactByMaxId();//取得刚保存的联系人
if(justSaveCC!=null){
serviceOrder.setCustomerContact(justSaveCC);
}
}
// end
serviceOrderDAO.save(serviceOrder);
logger.debug("保存成功了");
justSaveSO = serviceOrderDAO.getServiceOrderByMaxId();
logger.debug("保存成功了");
} catch (Exception re) {
logger.debug(re.getMessage());
throw new ApplicationException(re.getMessage());
}
// 上传
logger.debug("开始上传");
Set<ServiceOrderFile> serviceOrderFileSet = new HashSet<ServiceOrderFile>();
Hashtable fileh = form.getMultipartRequestHandler().getFileElements();// form是传过来的参数
for (Iterator it = fileh.keySet().iterator(); it.hasNext();) {
ServiceOrderFile soFile = new ServiceOrderFile();
String key = (String) it.next();
FormFile formfile = (FormFile) fileh.get(key);// 获取一个FormFile
String fileName = "";
if (formfile.getFileName() != null
&& !"".equals(formfile.getFileName())) {
String path = ConfigMgr.getInstance().getXmlFileVo().getPath();// 取得上传的路径
logger.debug(formfile.getFileName());
logger.debug("要上传的路径是:" + path);
fileName = Upload.upload(formfile, path);
soFile.setFileName(fileName);
soFile.setPath(path);
if (justSaveSO != null) {
soFile.setServiceOrder(justSaveSO);
}
try {
serviceOrderDAO.saveSOFile(soFile);
} catch (Exception re) {
logger.debug(re.getMessage());
throw new ApplicationException(
Constants.ADD_SERVICEORDER_EXCEPTION);
}
serviceOrderFileSet.add(soFile);
}
}
logger.debug("上传的数量=====" + serviceOrderFileSet.size());
}
//判断要上传的文件是否附合条件
public String checkFile(ActionForm form){
String resultMsg = null;
XMLFileVo XMLFileVo = ConfigMgr.getInstance().getXmlFileVo();
int size = XMLFileVo.getSize();
logger.debug("系统限制的大小为:"+size);
String [] expandNames = XMLFileVo.getExpandNames().split(",");
List<String> lString = new ArrayList<String>();
for(int i=0;i<expandNames.length;i++){
lString.add(expandNames[i]);
}
Hashtable fileh = form.getMultipartRequestHandler().getFileElements();// form是传过来的参数
for (Iterator it = fileh.keySet().iterator(); it.hasNext();) {
String key = (String) it.next();
FormFile formfile = (FormFile) fileh.get(key);// 获取一个FormFile
logger.debug("上传的文件大小是:"+formfile.getFileSize());
if(formfile.getFileSize()>size){
resultMsg = Constants.OVER_SIZE_FILE_EXCEPTION;
break;
}
if (formfile.getFileName() != null && !"".equals(formfile.getFileName())) {
String expandName = formfile.getFileName().substring(formfile.getFileName().lastIndexOf('.')+1);
if(!lString.contains(expandName)){
resultMsg = Constants.NO_UPLOAD_FILE_EXCEPTION;
break;
}
}
}
return resultMsg;
}
//取最大ID的问题单
public ServiceOrder getServiceOrderByMaxId(){
return serviceOrderDAO.getServiceOrderByMaxId();
}
//通过客户ID查找联系人
public List<CustomerContact> getContactByCustomerId(int customerId){
return serviceOrderDAO.getContactByCustomerId(customerId);
}
// 编辑在线问题单
public void editOnlineOrder(ActionForm form, HttpServletRequest request) {
ServiceOrderForm serviceOrderForm = (ServiceOrderForm) form;
int id = 0;
String idStr = request.getParameter("id");
if (idStr != null && !"".equals(idStr)) {
id = Integer.parseInt(idStr);
}
CustAccount custAccount = OnlineSessionMgr
.getCustAccountSession(request);
Customer customer = custAccount.getCustomer();
ServiceOrder serviceOrder = null;
try {
serviceOrder = serviceOrderDAO.findById(id);
serviceOrder.setContent(serviceOrderForm.getContent());
logger.debug("打印联系人ID" + serviceOrderForm.getContactId());
// 判断联系人ID是否为0,0表示用户有指定非系统存在的联系人
if (serviceOrderForm.getContactId() == 0) {
CustomerContact customerContact = new CustomerContact();
customerContact.setName(request
.getParameter("otherContactName"));
customerContact.setMobilePhone(request
.getParameter("mobilePhone"));
customerContact.setEmail(request.getParameter("email"));
customerContact.setFax(request.getParameter("fax"));
customerContact.setComPhone(request.getParameter("comPhone"));
// 设置联系人的flag = 4为临时联系人
customerContact.setFlag(Constants.CASUAL_FLAG);
customerContact.setInDate(new Date());
if(customer!=null){
customerContact.setCustomer(customer);
}
customerContact.setUser(customer.getUser());
customerContact.setModifyManId(0);// 客户创建的联系人
serviceOrderDAO.saveCustomerContact(customerContact);
CustomerContact justSaveCC = serviceOrderDAO
.getCustomerContactByMaxId();// 取得刚保存的联系人
if(justSaveCC!=null){
serviceOrder.setCustomerContact(justSaveCC);
}
}else if(serviceOrder.getCustomerContact().getId()!=serviceOrderForm.getContactId()){//客户有重新选择联系人
serviceOrder.setCustomerContact(serviceOrderDAO.getContactById(serviceOrderForm.getContactId()));
}
} catch (Exception re) {
logger.debug(re.getMessage());
throw new ApplicationException(re.getMessage());
}
/****************附件信息的修改************/
Set<ServiceOrderFile> ServiceOrderFileSet = serviceOrder.getServiceOrderFiles();
Iterator<ServiceOrderFile> sofIterator = ServiceOrderFileSet.iterator();
if(ServiceOrderFileSet.size()>0){
while(sofIterator.hasNext()){
ServiceOrderFile serviceOrderFile = sofIterator.next();
//判断该文件是否要删除
String delFlag = request.getParameter("delFlag"+serviceOrderFile.getId());
if(delFlag!=null){
serviceOrderDAO.deleteSOFileById(serviceOrderFile.getId());//删除数据库文件
//同时删除硬盘上的文件
String path = ConfigMgr.getInstance().getXmlFileVo().getPath();// 取得上传的路径
String file = path+serviceOrderFile.getFileName();
if(new File(file).exists()){
new File(file).delete();
logger.debug("删除硬盘上的文件成功");
}
}
}
}
// 上传
Hashtable fileh = form.getMultipartRequestHandler().getFileElements();// form是传过来的参数
for (Iterator it = fileh.keySet().iterator(); it.hasNext();) {
ServiceOrderFile soFile = new ServiceOrderFile();
String key = (String) it.next();
FormFile formfile = (FormFile) fileh.get(key);// 获取一个FormFile
String fileName = "";
if (formfile.getFileName() != null
&& !"".equals(formfile.getFileName())) {
String path = ConfigMgr.getInstance().getXmlFileVo().getPath();// 取得上传的路径
logger.debug(formfile.getFileName());
logger.debug("要上传的路径是:" + path);
fileName = Upload.upload(formfile, path);
soFile.setFileName(fileName);
soFile.setPath(path);
soFile.setServiceOrder(serviceOrder);
try {
saveSOFile(soFile);
} catch (RuntimeException re) {
logger.debug(re.getMessage());
throw new ApplicationException(
Constants.ADD_SERVICEORDER_EXCEPTION);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -