📄 endapplyhandler.java.svn-base
字号:
package com.chinacars.oss.data.appform.workflow.handler;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.sf.jaype.persistence.hibernate.SpringForHibernate3Dao;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.web.context.WebApplicationContext;
import com.chinacars.oss.data.appform.domain.Task;
import com.chinacars.oss.data.appform.services.BusinessService;
import com.chinacars.oss.data.appform.util.ApplyDataItems;
import com.chinacars.oss.data.appform.util.DataUseWay;
import com.chinacars.oss.data.appform.util.Mail;
import com.chinacars.oss.data.appform.util.OtherUtil;
import com.chinacars.oss.domain.coder.Region;
public class EndApplyHandler implements ActionHandler {
private WebApplicationContext wac = null;
/**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
public void execute(ExecutionContext executionContext) throws Exception {
ContextInstance ci = executionContext.getContextInstance();
Map<String,Object> params = null;
params = ci.getTransientVariables();
Task task = (Task)params.get("BUSINESS_TASK");
//生成申请数据
wac = (WebApplicationContext)params.get("WEB_APPLICATION_CONTEXT");
BusinessService bService = (BusinessService) wac.getBean("businessService");
String actor = getOssProvider();
Map<String,String> p = new HashMap<String,String>();
p.put("PROVINCE", task.getProvince());
p.put("CITY", task.getCity());
p.put("BEGINDATE", OtherUtil.ymdDate(task.getBegindate()));
p.put("ENDDATE", OtherUtil.ymdDate(task.getEnddate()));
p.put("DEMAND", task.getDemand());
p.put("TASKID", task.getId().toString());
p.put("OSS_CHARGE", actor);
bService.saveQueryResult(p);
//发送短信
if (task.getUseway().equals("DW_SM")) {
//只需要将待发短信保存到数据库中,定时器会自动发送,此处不需要处理
}
//外呼
if (task.getUseway().equals("DW_CALL")) {
doCall(params);
}
if (task.getUseway().equals("DW_MAIL")) {
doMail();
}
}
/**
* 外呼处理
*/
private void doCall(Map<String,Object> params) throws Exception{
Task task = (Task)params.get("BUSINESS_TASK");
if (!OtherUtil.isMail(task.getRuemail())) {
//throw new ApplicationException("数据接收人E-MAIL未设置,不能发送邮件");
return;
}
SpringForHibernate3Dao hibDao = (SpringForHibernate3Dao)wac.getBean("hibDao");
Region city = (Region)hibDao.get(Region.class, task.getCity());
//邮件内容设置
String[] temp = task.getDemand().split(",");
StringBuffer sb = new StringBuffer();
//需求选项
for (int j=0;j<temp.length;j++) {
String title = ApplyDataItems.get(temp[j]);
sb.append(title+",");
}
if (sb.charAt(sb.length()-1)==',') {
sb.deleteCharAt(sb.length()-1);
}
//邮件正文
StringBuffer message = new StringBuffer();
message.append("数据使用方式: " + DataUseWay.get(task.getUseway()));
message.append("\n");
message.append("数据查询范围: " + OtherUtil.ymdDate(task.getBegindate()) + "--->" + OtherUtil.ymdDate(task.getEnddate()));
message.append("\n");
message.append("需求选项: " + sb.toString());
message.append("\n");
message.append("数据区域: " + city.getProvince().getName() + "/" + city.getName());
message.append("\n");
//生成申请数据-----邮件附件
Random random = new Random(System. currentTimeMillis());
String filePath = System.getProperty("java.io.tmpdir") + random.nextLong() + ".csv";
FileWriter fw = null;
try{
BusinessService bService = (BusinessService) wac.getBean("businessService");
String content = bService.makeXls(String.valueOf(task.getProcessId()));
fw = new FileWriter(filePath);
fw.write(content);
}catch(Exception e) {
//记录日志发送邮件失败!
return;
}finally {
if (fw!=null) {
fw.close();
}
}
String mailHost = org.jbpm.JbpmConfiguration.Configs.getString("mail.smtp.host");
String mailSender = org.jbpm.JbpmConfiguration.Configs.getString("mail.smtp.sender");
try {
//发送邮件
Mail sendmail = new Mail(
task.getRuemail(),
mailSender,
mailHost,
"数据使用申请结果",
message.toString()
);
sendmail.attachfile(filePath);
sendmail.startSend();
}catch(Exception ex) {
throw ex;
}finally {
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
}
}
/**
* MAIL方式,目前不做处理
*/
private void doMail() {
}
/**
* 返回OSS部门主管
* @return
*/
private String getOssProvider() {
return "yitao-sun";
/*
UserService userService = (UserService) wac.getBean("userService");
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("isDeptPrincipal", "true");
List<User> list2 = userService.findByOrgan("0315", map2, Integer.valueOf("0"));
if (list2==null || list2.size()==0){
return null;
}
return list2.get(0).getName();
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -