78598defb58d3064b76ef3f112fb500e052abbea.svn-base 18.0 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
package com.espeed.action;
 
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.espeed.centre.pojo.YxyUserInfo;
import com.espeed.log.LogClass;
import com.espeed.pojo.YxyMarketingPlan;
import com.espeed.pojo.YxyMarketingWeek;
import com.espeed.service.MailSendVerificationService;
import com.espeed.service.YxyMarketingPlanService;
import com.espeed.service.YxyNoshieldEmailService;
import com.espeed.service.YxySendFilterAddressService;
import com.espeed.service.YxyShieldDomainService;
import com.espeed.service.YxySysParamaterService;
import com.espeed.service.YxyUnsubscribeInfoService;
import com.espeed.tool.DateFormat;
import com.espeed.vo.PageBean;
import com.opensymphony.xwork2.ActionContext;

/***
 * 
 * @author 谢勇
 * 营销计划action
 */
public class YxyMarketingPlanAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	/**判断CRM库发送量是否超标,0超标,1不超标*/
	public String getMonthSendLimit(){
		try {
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			importaddress = marketingplanservice.getMonthSendLimit(user.getUser_id(), crmtype, plangroupid, planweekmodel);
		} catch (Exception e) {
			importaddress.put("result", "0");
			importaddress.put("reason","未知错误,请联系客服人员!");
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "map";
	}
	
	/**添加执行的营销计划前的发送量判断*/
	public String beforeAddMarketingPlan(){
		try {
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			//控制参数
			Map<String,String> usergraph=yxysysparamaterservice.findParamaterByLevel(4, loginid,domain);//查询控制参数(用户级)
			importaddress = marketingplanservice.beforeAddMarketingPlan(loginid,domain,addressnum,usergraph,planweekmodel);
		}catch(Exception e) {
			importaddress.put("result", "0");
			importaddress.put("reason","未知错误,请联系客服人员!");
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "map";
	}
	
	/**增加营销计划或提醒计划*/
	public String addMarketingPlan(){
		try {
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			//当前时间
			SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String nowdate=df.format(new Date());
			String nowday=nowdate.split(" ")[0];//yyyy-mm-dd
			//实体赋值
			YxyMarketingPlan plan=new YxyMarketingPlan();
			//plan.setPlan_uid(user.getUid());
			plan.setDomain(domain);
			plan.setLoginid(loginid);
			plan.setPlan_cycle(plancycle);
			plan.setPlan_groupid(plangroupid);
			plan.setPlan_executetime(planexecutetime);
			plan.setPlan_type(plantype);
			plan.setPlan_createtime(nowdate);
			plan.setPlan_begintime(nowday);
			plan.setPlan_title(plantitle);
			plan.setPlan_differen(plan_differen);
			plan.setOther_name(other_name);
			//几个时间处理
			if(plancycle==1){//每月 
				String monthlast=DateFormat.getMonthLastDay();
				plan.setPlan_endtime(monthlast);
			}else if(plancycle==2){//一周内 
				String sunday=DateFormat.getWeekLastTime();
				plan.setPlan_endtime(sunday);
			}else if(plancycle==3){//30天内 
				String lasttime=DateFormat.nDaysAfterOneDateString(nowdate,30);
				plan.setPlan_endtime(lasttime.split(" ")[0]);
			}else if(plancycle==4){//指定时间内
				plan.setPlan_begintime(begintime);
				plan.setPlan_endtime(endtime);
			}else if(plancycle==5){//特殊节假日
				plan.setPlan_endtime(endtime);
//				String halidayTime = DateFormat.getHoliday(); 
//				plan.setPlan_endtime(halidayTime);
			}else if(plancycle==6){//指定具体日期
				plan.setPlan_begintime(begintime);
				plan.setPlan_endtime(endtime);
			}
			marketingplanservice.addMarketingPlan(user.getUser_id(),plan,planweekmodel);
			result=1;
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return SUCCESS;
	}
	
	/**列表查询营销计划*/
	public String findMarketingPlanTable(){
		try {
			//获取用户session
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			pagebean.setCurrentPage(currpage);
			pagebean.setPageSize(pagesize);
			markeplanlist=marketingplanservice.findMarketingPlanTable(loginid,domain,condition,conditionvalue,pagebean);
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "list";
	}
	
	/**查询营销计划*/
	public String findMarketingPlan(){
		try {
			//获取用户session1
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			pagebean.setCurrentPage(currpage);
			pagebean.setPageSize(pagesize);
			markeplanweeklist=marketingplanservice.findMarketingPlan(loginid,domain,pagebean);
			//组装成map前端需求
			for(int i=0;i<markeplanweeklist.size();i++){
				String day=markeplanweeklist.get(i).getWeek_day();
				Iterator<Entry<String, List<YxyMarketingWeek>>> iter = planweekmap.entrySet().iterator();
				boolean ishave=false;
				while(iter.hasNext()){
					Entry<String, List<YxyMarketingWeek>> entry =(Entry<String, List<YxyMarketingWeek>>)iter.next();
					String key = entry.getKey();//键
					List<YxyMarketingWeek> val = entry.getValue();//值
					if(day.equals(key)){//相同
						ishave=true;
						val.add(markeplanweeklist.get(i));
						break;
					}
				}
				//是否存在 
				if(!ishave){
					List<YxyMarketingWeek> newlist=new ArrayList<YxyMarketingWeek>();
					newlist.add(markeplanweeklist.get(i));
					planweekmap.put(day,newlist);
				}
			}
			SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
			nowday=df.format(new Date());
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "weeklist";
	}
	
	/**删除营销计划(当天的)*/
	public String delMarketingPlanDay(){
		try {
			//获取用户session1
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			marketingplanservice.delMarketingPlanDay(planid);
			result=1;
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return SUCCESS;
	}
	
	/**删除营销计划(整个)*/
	public String delMarketingPlan(){
		try {
			//获取用户session1
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			marketingplanservice.delMarketingPlan(planid);
			result=1;
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return SUCCESS;
	}
	
	/**查询单条营销计划*/
	public String getMarketingPlan(){
		try {
			//获取用户session1
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			plan=marketingplanservice.getMarketingPlan(planid);
		} catch (Exception e) {
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return "pojo";
	}
	
	/**撤销营销计划(整个)*/
	public String editMarketingPlan(){
		try {
			//获取用户session1
			ActionContext ac = ActionContext.getContext();
			Map<String,Object> sess = ac.getSession();			
			YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
			loginid=user.getLogin_id();//用户账号
			domain=user.getDomain();//用户所属域名
			marketingplanservice.editMarketingPlan(user,planid);
			result=1;
		} catch (Exception e) {
			result=0;
			StringWriter sw = new StringWriter();
			e.printStackTrace(new PrintWriter(sw, true));
	        String str = sw.toString();
	        LogClass.errolog(str,loginid+"@"+domain);
		}
		return SUCCESS;
	}
	
	private YxyMarketingPlanService marketingplanservice;//营销计划service
	private YxySysParamaterService yxysysparamaterservice;//控制参数serviec
	private MailSendVerificationService sendverificationService;//发送量验证service
	private YxyUnsubscribeInfoService yxyunsubscribeinfoservice;//退订地址service
	private YxySendFilterAddressService filteraddressservice;//过滤分组地址service
	private YxyNoshieldEmailService noshieldemailservice;//不屏蔽的邮件地址service
	private YxyShieldDomainService shielddomainservice;//屏蔽的域名service
	private Map<String,Integer> importmap=new HashMap<String, Integer>();
	private Map<String,String> importaddress=new HashMap<String, String>();
	private List<YxyMarketingPlan> markeplanlist;//计划集合
	private List<YxyMarketingWeek> markeplanweeklist;//计划周期集合
	private Map<String,List<YxyMarketingWeek>> planweekmap=new LinkedHashMap<String, List<YxyMarketingWeek>>();//计划周期集合map
	private PageBean pagebean;//分页
	private int pagesize;//每页量
	private int currpage;//当前页
	private int result;
	private int plantype;//计划类型0.提醒1,计划
	private int plancycle;//计划周期1:每月 2:一周内 3:30天内 4:指定时间内
	private String planexecutetime;//执行具体时间
	private int plangroupid;//计划地址分组id
	private String planweekmodel;//计划选择的周几与模版字符格式:1(周一),模版id#2(周二),模版id
	private String planweek;//计划选择的周期多个例如:1,2,3代表周一,周二,周三
	private String loginid="erro";
	private String domain="erro";
	private String begintime;
	private String endtime;
	private String plantitle;
	private String nowday;
	private int filterid;//过滤类别ID
	private int planid;//计划id
	private String planday;//计划时间多个,号分割
	private int condition;//条件
	private String conditionvalue;//条件值
	private int plan_differen;//营销计划区分:0:本地库 1:CRM库
	private YxyMarketingPlan plan;
	private int crmtype;//0客户分类,1客户状态,2客户来源,3意向产品
	private String other_name;//针对于采购偏好或个性营销邮的条件
	private int addressnum;//提交的营销地址数量
	public int getCrmtype() {
		return crmtype;
	}
	public void setCrmtype(int crmtype) {
		this.crmtype = crmtype;
	}
	public YxyMarketingPlan getPlan() {
		return plan;
	}
	public void setPlan(YxyMarketingPlan plan) {
		this.plan = plan;
	}
	public int getPlan_differen() {
		return plan_differen;
	}
	public void setPlan_differen(int plan_differen) {
		this.plan_differen = plan_differen;
	}
	public YxyMarketingPlanService getMarketingplanservice() {
		return marketingplanservice;
	}
	public void setMarketingplanservice(YxyMarketingPlanService marketingplanservice) {
		this.marketingplanservice = marketingplanservice;
	}
	public int getResult() {
		return result;
	}
	public void setResult(int result) {
		this.result = result;
	}
	public int getPlantype() {
		return plantype;
	}
	public void setPlantype(int plantype) {
		this.plantype = plantype;
	}
	public int getPlancycle() {
		return plancycle;
	}
	public void setPlancycle(int plancycle) {
		this.plancycle = plancycle;
	}
	public int getPlangroupid() {
		return plangroupid;
	}
	public void setPlangroupid(int plangroupid) {
		this.plangroupid = plangroupid;
	}
	public String getPlanexecutetime() {
		return planexecutetime;
	}
	public void setPlanexecutetime(String planexecutetime) {
		this.planexecutetime = planexecutetime;
	}
	public String getLoginid() {
		return loginid;
	}
	public void setLoginid(String loginid) {
		this.loginid = loginid;
	}
	public String getDomain() {
		return domain;
	}
	public void setDomain(String domain) {
		this.domain = domain;
	}
	public String getBegintime() {
		return begintime;
	}
	public void setBegintime(String begintime) {
		this.begintime = begintime;
	}
	public String getEndtime() {
		return endtime;
	}
	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}
	public String getPlantitle() {
		return plantitle;
	}
	public void setPlantitle(String plantitle) {
		this.plantitle = plantitle;
	}
	public YxySysParamaterService getYxysysparamaterservice() {
		return yxysysparamaterservice;
	}
	public void setYxysysparamaterservice(
			YxySysParamaterService yxysysparamaterservice) {
		this.yxysysparamaterservice = yxysysparamaterservice;
	}
	public MailSendVerificationService getSendverificationService() {
		return sendverificationService;
	}
	public void setSendverificationService(
			MailSendVerificationService sendverificationService) {
		this.sendverificationService = sendverificationService;
	}
	public Map<String, Integer> getImportmap() {
		return importmap;
	}
	public void setImportmap(Map<String, Integer> importmap) {
		this.importmap = importmap;
	}
	public Map<String, String> getImportaddress() {
		return importaddress;
	}
	public void setImportaddress(Map<String, String> importaddress) {
		this.importaddress = importaddress;
	}
	public String getPlanweek() {
		return planweek;
	}
	public void setPlanweek(String planweek) {
		this.planweek = planweek;
	}
	public YxyUnsubscribeInfoService getYxyunsubscribeinfoservice() {
		return yxyunsubscribeinfoservice;
	}
	public void setYxyunsubscribeinfoservice(
			YxyUnsubscribeInfoService yxyunsubscribeinfoservice) {
		this.yxyunsubscribeinfoservice = yxyunsubscribeinfoservice;
	}
	public YxySendFilterAddressService getFilteraddressservice() {
		return filteraddressservice;
	}
	public void setFilteraddressservice(
			YxySendFilterAddressService filteraddressservice) {
		this.filteraddressservice = filteraddressservice;
	}
	public YxyNoshieldEmailService getNoshieldemailservice() {
		return noshieldemailservice;
	}
	public void setNoshieldemailservice(YxyNoshieldEmailService noshieldemailservice) {
		this.noshieldemailservice = noshieldemailservice;
	}
	public YxyShieldDomainService getShielddomainservice() {
		return shielddomainservice;
	}
	public void setShielddomainservice(YxyShieldDomainService shielddomainservice) {
		this.shielddomainservice = shielddomainservice;
	}
	public int getFilterid() {
		return filterid;
	}
	public void setFilterid(int filterid) {
		this.filterid = filterid;
	}
	public PageBean getPagebean() {
		return pagebean;
	}
	public void setPagebean(PageBean pagebean) {
		this.pagebean = pagebean;
	}
	public int getPagesize() {
		return pagesize;
	}
	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	public int getCurrpage() {
		return currpage;
	}
	public void setCurrpage(int currpage) {
		this.currpage = currpage;
	}
	public List<YxyMarketingPlan> getMarkeplanlist() {
		return markeplanlist;
	}
	public void setMarkeplanlist(List<YxyMarketingPlan> markeplanlist) {
		this.markeplanlist = markeplanlist;
	}
	public List<YxyMarketingWeek> getMarkeplanweeklist() {
		return markeplanweeklist;
	}
	public void setMarkeplanweeklist(List<YxyMarketingWeek> markeplanweeklist) {
		this.markeplanweeklist = markeplanweeklist;
	}
	public int getPlanid() {
		return planid;
	}
	public void setPlanid(int planid) {
		this.planid = planid;
	}
	public String getPlanday() {
		return planday;
	}
	public void setPlanday(String planday) {
		this.planday = planday;
	}
	public String getNowday() {
		return nowday;
	}
	public void setNowday(String nowday) {
		this.nowday = nowday;
	}
	public Map<String, List<YxyMarketingWeek>> getPlanweekmap() {
		return planweekmap;
	}
	public void setPlanweekmap(Map<String, List<YxyMarketingWeek>> planweekmap) {
		this.planweekmap = planweekmap;
	}
	public String getPlanweekmodel() {
		return planweekmodel;
	}
	public void setPlanweekmodel(String planweekmodel) {
		this.planweekmodel = planweekmodel;
	}
	public int getCondition() {
		return condition;
	}
	public void setCondition(int condition) {
		this.condition = condition;
	}
	public String getConditionvalue() {
		return conditionvalue;
	}
	public void setConditionvalue(String conditionvalue) {
		this.conditionvalue = conditionvalue;
	}
	public String getOther_name() {
		return other_name;
	}
	public void setOther_name(String other_name) {
		this.other_name = other_name;
	}
	public int getAddressnum() {
		return addressnum;
	}
	public void setAddressnum(int addressnum) {
		this.addressnum = addressnum;
	}
}