YxyMailStencilServiceImpl.java
6.7 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
package com.espeed.service.impl;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.espeed.dao.YxyMailStencilDao;
import com.espeed.dao.YxyMailStencilHtmlDao;
import com.espeed.dao.YxyMailStencilTypeDao;
import com.espeed.pojo.YxyMailStencil;
import com.espeed.pojo.YxyMailStencilHtml;
import com.espeed.pojo.YxyMailStencilType;
import com.espeed.service.YxyMailStencilService;
import com.espeed.tool.ConfigPath;
import com.espeed.tool.createAndDeleteFile;
import com.espeed.vo.PageBean;
public class YxyMailStencilServiceImpl implements YxyMailStencilService {
/**条件查询模版*/
public List<YxyMailStencil> findByCondition(String loginid, String domain, PageBean pb,int condition, String conditionvalue) throws Exception {
String hql="from YxyMailStencil where 1=1";
String hqlcount="select count(*) from YxyMailStencil where 1=1";
if(condition==1){//系统模版
hql+=" and stencil_level=1";
hqlcount+=" and stencil_level=1";
}else if(condition==2){//企业模版
hql+=" and stencil_level=2 and stencil_domain='"+domain+"'";
hqlcount+=" and stencil_level=2 and stencil_domain='"+domain+"'";
}else if(condition==3){//个人模版
hql+=" and stencil_level=3 and stencil_domain='"+domain+"' and stencil_loginid='"+loginid+"'";
hqlcount+=" and stencil_level=3 and stencil_domain='"+domain+"' and stencil_loginid='"+loginid+"'";
}else if(condition==4){//系统模版分类查看
hql+=" and stencil_level=1 and stencil_type="+conditionvalue;
hqlcount+=" and stencil_level=1 and stencil_type="+conditionvalue;
}else if(condition==5){//企业模版分类查看
hql+=" and stencil_level=2 and stencil_domain='"+domain+"' and stencil_type="+conditionvalue;
hqlcount+=" and stencil_level=2 and stencil_domain='"+domain+"' and stencil_type="+conditionvalue;
}else if(condition==6){//个人模版分类查看
hql+=" and stencil_level=3 and stencil_domain='"+domain+"' and stencil_loginid='"+loginid+"' and stencil_type="+conditionvalue;
hqlcount+=" and stencil_level=3 and stencil_domain='"+domain+"' and stencil_loginid='"+loginid+"' and stencil_type="+conditionvalue;
}else{
return new ArrayList<YxyMailStencil>();
}
hql+=" order by stencil_time desc";
hqlcount+=" order by stencil_time desc";
return mailstencildao.findByHqlPage(hql, hqlcount, pb);
}
/**添加编辑模版*/
public void addEditStencil(YxyMailStencil o) throws Exception {
if(o.getStencil_id()>0){//编辑
mailstencildao.updatePojo(o);
}else{//添加
mailstencildao.addPojo(o);
}
}
/**删除模版*/
public void delStencil(String stencilidstr) throws Exception {
String hql="delete from YxyMailStencil where stencil_id in("+stencilidstr+")";
mailstencildao.updateByHql(hql);
}
/**详细信息*/
public YxyMailStencil findinfo(int stencilid) throws Exception {
String hql="from YxyMailStencil where stencil_id="+stencilid;
List<YxyMailStencil> list=mailstencildao.findByHql(hql);
if(list.size()>0){
YxyMailStencil stencil = list.get(0);
hql = "from YxyMailStencilHtml where stencil_id = "+stencilid;
List<YxyMailStencilHtml> htmls = yxymailstencilhtmldao.findByHql(hql);
if(htmls.size() > 0){
stencil.setWeb_url(ConfigPath.getStencilDomain()+htmls.get(0).getWeb_url());
}
return stencil;
}else{
return null;
}
}
/**条件查询模版分类*/
public List<YxyMailStencilType> findByConditionType(String loginid,String domain,int condition)throws Exception{
String hql="from YxyMailStencilType where 1=1";
if(condition==1){//系统级分类
hql+=" and level=1";
}else if(condition==2){//企业级分类
hql+=" and level=2 and domain='"+domain+"'";
}else if(condition==3){//个人级分类
hql+=" and level=3 and domain='"+domain+"' and loginid='"+loginid+"'";
}
return mailstenciltypedao.findByHql(hql);
}
/**添加模版分类*/
public void addStencilType(YxyMailStencilType o)throws Exception{
if(o.getTypeid()>0){
String hql="update YxyMailStencilType set typename='"+o.getTypename()+"' where typeid="+o.getTypeid();
mailstenciltypedao.updateByHql(hql);
}else{
mailstenciltypedao.addPojo(o);
}
}
/**删除编辑模版分类*/
public void delStencilType(int typeid,int condition)throws Exception{
if(condition==1){//删除模版
String hql="delete YxyMailStencil where stencil_type="+typeid;
mailstencildao.updateByHql(hql);
}
String hql="delete YxyMailStencilType where typeid="+typeid;
mailstenciltypedao.updateByHql(hql);
}
/**验证模版分类是否重复*/
public int findIsExits(String typename,int level,String domain,String loginid)throws Exception{
String hql="select count(*) from YxyMailStencilType where";
if(level==1){//系统
hql+=" typename='"+typename+"'";
}else if(level==2){//企业
hql+=" typename='"+typename+"' and domain='"+domain+"'";
}else if(level==3){//个人
hql+=" typename='"+typename+"' and domain='"+domain+"' and loginid='"+loginid+"'";
}
int count=mailstenciltypedao.findByHqlCount(hql);
if(count>0){
return 0;
}else{
return 1;
}
}
/**上传模板缩略图*/
public String uploadStencilThumbnail(int user_id,String filePath,String fileName)throws Exception{
File f = new File(filePath);
//项目路径
String pathew = this.getClass().getResource("/").getPath();
pathew = pathew.substring(1, pathew.length());
pathew = pathew.replace("/", "//");
pathew = pathew.replace("//WEB-INF//classes//", "");
String type = fileName.substring(fileName.lastIndexOf("."),fileName.length());
String picname = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
String newsave = user_id+picname+type;
File create = new File(pathew+"//thumbnail");
if(!create.exists()){
create.mkdirs();
}
File newf = new File(pathew+"//thumbnail//"+newsave);//新文件
createAndDeleteFile.filecopy(f, newf);
newsave = newsave.replace("//", "/");
newsave = "thumbnail/" + newsave;
return newsave;
}
private YxyMailStencilDao mailstencildao;//模版dao
private YxyMailStencilTypeDao mailstenciltypedao;//模版分类dao
private YxyMailStencilHtmlDao yxymailstencilhtmldao;//模板对应的网页dao
public YxyMailStencilDao getMailstencildao() {
return mailstencildao;
}
public void setMailstencildao(YxyMailStencilDao mailstencildao) {
this.mailstencildao = mailstencildao;
}
public YxyMailStencilTypeDao getMailstenciltypedao() {
return mailstenciltypedao;
}
public void setMailstenciltypedao(YxyMailStencilTypeDao mailstenciltypedao) {
this.mailstenciltypedao = mailstenciltypedao;
}
public YxyMailStencilHtmlDao getYxymailstencilhtmldao() {
return yxymailstencilhtmldao;
}
public void setYxymailstencilhtmldao(YxyMailStencilHtmlDao yxymailstencilhtmldao) {
this.yxymailstencilhtmldao = yxymailstencilhtmldao;
}
}