添加邮件邀请功能

pull/3/head
rekoe 2016-04-28 09:28:48 +08:00
parent f9fca1b2cc
commit caac23c80a
5 changed files with 199 additions and 0 deletions

View File

@ -1,9 +1,14 @@
package com.rekoe.module.admin;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.aop.interceptor.async.Async;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
@ -13,11 +18,18 @@ import org.nutz.mvc.annotation.Param;
import com.rekoe.annotation.PermissionTag;
import com.rekoe.common.Message;
import com.rekoe.common.page.Pagination;
import com.rekoe.domain.Pj;
import com.rekoe.domain.PjGrUsr;
import com.rekoe.domain.ProjectConfig;
import com.rekoe.domain.Usr;
import com.rekoe.module.BaseAction;
import com.rekoe.service.EmailService;
import com.rekoe.service.ProjectConfigService;
import com.rekoe.service.ProjectGroupUsrService;
import com.rekoe.service.ProjectService;
import com.rekoe.service.SvnService;
import com.rekoe.service.SvnUserService;
import com.rekoe.utils.EncryptUtil;
@IocBean
@At("/admin/project/group/usr")
@ -85,4 +97,60 @@ public class AdminProjectGroupUsrAct extends BaseAction {
svnService.exportConfig(pj);
return Message.success("ok", req);
}
@Inject
private EmailService emailService;
@Inject
private ProjectService projectService;
@Inject
private ProjectConfigService projectConfigService;
@At
@Ok("json")
@RequiresPermissions("project.group:add")
@PermissionTag(name = "添加项目组用户", tag = "SVN账号管理", enable = false)
public Message all_email(@Param("pj") String pj, HttpServletRequest req) {
Pj project = projectService.get(pj);
ProjectConfig conf = projectConfigService.get();
List<Usr> getList = svnUserService.listSelected(pj);
sendProjectOpenEmail(project, conf, getList, emailService);
return Message.success("ok", req);
}
@At
@Ok("json")
@RequiresPermissions("project.group:add")
@PermissionTag(name = "添加项目组用户", tag = "SVN账号管理", enable = false)
public Message email(@Param("pj") String pj, @Param("usr") String usr, HttpServletRequest req) {
Pj project = projectService.get(pj);
ProjectConfig conf = projectConfigService.get();
sendProjectOpenEmail(project, conf, svnUserService.get(usr), emailService);
return Message.success("ok", req);
}
@Async
public void sendProjectOpenEmail(Pj project, ProjectConfig conf, List<Usr> getList, EmailService emailService) {
for (Usr usr : getList) {
Map<String, Object> root = new HashMap<>();
root.put("usr", usr.getUsr());
root.put("name", usr.getName());
root.put("pwd", EncryptUtil.decrypt(usr.getPsw()));
root.put("project", project.getDes());
root.put("url", conf.getDomainPath() + project.getPj());
emailService.projectOpen(usr.getEmail(), root);
}
}
@Async
public void sendProjectOpenEmail(Pj project, ProjectConfig conf, Usr usr, EmailService emailService) {
Map<String, Object> root = new HashMap<>();
root.put("usr", usr.getUsr());
root.put("name", usr.getName());
root.put("pwd", EncryptUtil.decrypt(usr.getPsw()));
root.put("project", project.getDes());
root.put("url", conf.getDomainPath() + project.getPj());
emailService.projectOpen(usr.getEmail(), root);
}
}

View File

@ -48,6 +48,9 @@ public class SvnUserService extends BaseService<Usr> {
return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("usr", "=", name)));
}
public Usr get(String usr){
return dao().fetch(getEntityClass(), Cnd.where("usr", "=", usr));
}
/**
*
*
@ -85,12 +88,31 @@ public class SvnUserService extends BaseService<Usr> {
return list;
}
public List<Usr> listSelected(String pj) {
Sql sql = Sqls.create("select * from usr a where a.usr <> '*' " + " and exists (select usr from pj_gr_usr b where a.usr = b.usr and b.pj=@pj) order by a.usr");
sql.setParam("pj", pj);
final List<Usr> list = new ArrayList<Usr>();
sql.setCallback(new SqlCallback() {
@Override
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
while (rs.next()) {
list.add(readUsr(rs));
}
return list;
}
});
dao().execute(sql);
return list;
}
Usr readUsr(ResultSet rs) throws SQLException {
Usr result = new Usr();
result.setUsr(rs.getString("usr"));
result.setName(rs.getString("name"));
result.setPsw(rs.getString("psw"));
result.setRole(rs.getString("role"));
result.setEmail(rs.getString("email"));
return result;
}

View File

@ -0,0 +1,61 @@
<p><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning />
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas />
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL />
<w:BalanceSingleByteDoubleByteWidth />
<w:DoNotLeaveBackslashAlone />
<w:ULTrailSpace />
<w:DoNotExpandShiftReturn />
<w:AdjustLineHeightInTable />
<w:BreakWrappedTables />
<w:SnapToGridInCell />
<w:WrapTextWithPunct />
<w:UseAsianBreakRules />
<w:DontGrowAutofit />
<w:UseFELayout />
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--></p>
<p><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
${name}: 您好 <br/>
所属项目${project}
svn ${url}
&nbsp;&nbsp;
账号:${usr}<br/>
密码:${pwd}<br/><br/>
&nbsp;&nbsp;&nbsp;&nbsp;密码信息请妥善保管。系统邮件请勿回复
</p>

View File

@ -33,6 +33,27 @@ function init(pj){
});
return false;
}
function all_email(pj){
$.dialog({
type: "warn",
content: '确定要执行?',
ok: 'Ok',
cancel: 'Cancel',
onOk: function() {
$.ajax({
url: "${base}/admin/project/group/usr/all_email.rk",
type: "POST",
data: {"pj":pj},
dataType: "json",
cache: false,
success: function(message) {
$.message(message);
}
});
}
});
return false;
}
</script>
</head>
<body>
@ -61,6 +82,9 @@ function init(pj){
<a href="javascript:void(0);" onclick="Cms.deleted('${project.pj}')" class="pn-opt">删除</a><#rt/>
</@p.column><#t/>
</@shiro.hasPermission>
<@p.column title="发项目邀请邮件" align="center">
<a href="javascript:void(0);" onclick="all_email('${project.pj}')" class="pn-opt">发送</a><#rt/>
</@p.column><#t/>
</@p.table>
</@p.form>
</div>

View File

@ -33,6 +33,27 @@ function deleted(pj,gr,usr){
});
return false;
}
function email(pj,usr){
$.dialog({
type: "warn",
content: '确定要执行?',
ok: 'Ok',
cancel: 'Cancel',
onOk: function() {
$.ajax({
url: "${base}/admin/project/group/usr/email.rk",
type: "POST",
data: {"pj":pj,"usr":usr},
dataType: "json",
cache: false,
success: function(message) {
$.message(message);
}
});
}
});
return false;
}
</script>
</head>
<body>
@ -59,6 +80,9 @@ function deleted(pj,gr,usr){
<a href="javascript:void(0);" onclick="deleted('${group.pj}','${group.gr}')" class="pn-opt">删除</a><#rt/>
</@p.column><#t/>
</@shiro.hasPermission>
<@p.column title="发项目邀请邮件" align="center">
<a href="javascript:void(0);" onclick="email('${group.pj}','${group.usr}')" class="pn-opt">发送</a><#rt/>
</@p.column><#t/>
</@p.table>
</@p.form>
</div>