Commit 656d9834 authored by xiexy's avatar xiexy

Default Changelist

parents
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>cftech-platform</artifactId>
<groupId>com.cftech</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>accounts-module-web</artifactId>
<packaging>war</packaging>
<name>accounts-module-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.cftech</groupId>
<artifactId>accounts-module</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>accounts-module-web</finalName>
</build>
</project>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<base href="#springUrl('/assets/adminlte/')" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>工作台</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
name="viewport">
<!-- Bootstrap 3.3.5 -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet"
href="plugins/font-awesome/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet"
href="plugins/ionicons/css/ionicons.min.css">
<!-- DataTables -->
<link rel="stylesheet"
href="plugins/datatables/dataTables.bootstrap.css">
<!-- Theme style -->
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
<!-- iCheck -->
<link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
<!-- Morris chart -->
<link rel="stylesheet" href="plugins/morris/morris.css">
<!-- jvectormap -->
<link rel="stylesheet"
href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
<!-- Date Picker -->
<link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
<!-- Daterange picker -->
<link rel="stylesheet"
href="plugins/daterangepicker/daterangepicker-bs3.css">
<!-- bootstrap wysihtml5 - text editor -->
<link rel="stylesheet"
href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- END HEAD -->
<div class="wrapper">
<div class="content-wrapper" style="margin-left: 0;">
<section class="content-header">
<h1>
公众号管理 <small>公众号信息</small>
</h1>
<ol class="breadcrumb">
<li><a href="#springUrl('/page/user/showstatics')"><i
class="fa fa-dashboard"></i>首页</a></li>
<li><a class="active">添加公众号</a></li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<!-- general form elements disabled -->
<div class="box box-primary">
<form role="form" id="accountForm">
<div class="box-body">
<div class="form-group form-md-line-input">
<label for="description">公众号描述:</label> <input
type="text" class="form-control" name="description"
id="description" placeholder="请输入描述信息">
</div>
<div class="form-group form-md-line-input">
<label for="appid">公众号AppId:</label> <input type="text"
class="form-control" id="appid" name="appid" maxlength="20"
placeholder="请输入appid">
</div>
<div class="form-group form-md-line-input">
<label for="secret">公众号secret:</label> <input type="text"
class="form-control" name="secret" id="secret"
placeholder="请输入secret">
</div>
<div class="form-group form-md-line-input">
<label for="encodingaeskey">公众号encodingaeskey:</label> <input
type="text" class="form-control" name="encodingaeskey"
id="encodingaeskey" placeholder="请输入encodingaeskey">
</div>
<div class="form-group form-md-line-input">
<label for="token">公众号token:</label> <input type="text"
class="form-control" name="token" id="token"
placeholder="请输入token">
</div>
<div class="form-group form-md-line-input">
<label>账号类型</label>
<input type="radio" name="wctype" value="1" placeholder="">企业号
<input type="radio" name="wctype" value="0" checked placeholder="">服务号
</div>
<input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
<input type="text" style="display: none" name="_csrf_header" value="${_csrf.headerName}"/>
</div>
<div class="box-footer">
<input class="btn btn-primary" id="save" type="submit" value="保存"> <a
href="#springUrl('/a/manageaccounts/accountslist')" class="btn btn-default">取消</a>
</div>
</form>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- Add the sidebar's background. This div must be placed
immediately after the control sidebar -->
<div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js"
type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="plugins/jquery-validation/js/localization/messages_zh.js"></script>
<script src="pages/scripts/manageaccounts/accountadd.js"></script>
<script src="common/js/cfapp.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
jQuery(document).ready(function() {
Cfapp.init();
AccountAdd.init();
});
function formSubmit (data) {
$.post("#springUrl('/a/manageaccounts/addaccounts')",data, function(returnobj) {
if (returnobj.errorCode == '0') {
Cfapp.confirm({
message: "新公众号创建成功",
btnoktext: "确定",
btncanceltext: "关闭",
success: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
},
cancel: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
}
});
}else if(returnobj.errorCode == '1'){
Cfapp.confirm({
message: "新公众号已经存在并已管理,不可新增",
btnoktext: "确定",
btncanceltext: "关闭",
success: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
},
cancel: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
}
});
}else if(returnobj.errorCode == '2'){
Cfapp.confirm({
message: "公众号信息存在异常",
btnoktext: "确定",
btncanceltext: "关闭",
success: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
},
cancel: function () {
location.href = "#springUrl('/a/manageaccounts/accountslist')";
}
});
}
});
};
</script>
</body>
<!-- END BODY -->
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cftech-platform</artifactId>
<groupId>com.cftech</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>accounts-module</artifactId>
<dependencies>
<dependency>
<groupId>com.cftech</groupId>
<artifactId>sys-module</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cftech</groupId>
<artifactId>codingrule-module</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.cftech.accounts.controller;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.core.util.OutputJSONUtil;
import com.cftech.core.util.StringUtils;
import com.cftech.sys.model.User;
import com.cftech.sys.security.UserUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author lisw
* @date 2016年8月26日 下午2:28:30
*/
@Controller
@RequestMapping(value = "/a/manageaccounts")
public class MpAccountsController {
@Autowired
private MpAccountsService mpAccountsService;
@RequestMapping(value = "/accountslist",method = {RequestMethod.GET,RequestMethod.POST})
public String useradd(HttpServletRequest request,
HttpServletResponse response) {
return "manageaccounts/accountslist";
}
@RequestMapping(value = "/accountsaddform",method ={RequestMethod.GET,RequestMethod.POST})
public String accountsaddform(HttpServletRequest request,
HttpServletResponse response) {
return "manageaccounts/accountsadd";
}
// 插入账户
@RequestMapping(value = "/addaccounts",method = RequestMethod.POST)
@ResponseBody
public JSONObject addAccounts(MpAccountsEntity accounts,
HttpServletResponse response) {
JSONObject returnObj = new JSONObject();
returnObj.put("errorCode", 0);
User user = UserUtils.getUser();//获得当前用户
accounts.setUserid(user.getId());
if (StringUtils.isNotBlank(accounts.getSecret())) {
mpAccountsService.insert(accounts);
}
return returnObj;
}
// 获取数据
@RequestMapping(value = "/accounts/fetchdata",method = {RequestMethod.GET,RequestMethod.POST})
@ResponseBody
public void getUsers(int iDisplayStart, int iDisplayLength,
HttpServletResponse response) {
User user = UserUtils.getUser();// 获得当前用户
List<MpAccountsEntity> users = null;
if (user.getId() == 1) {//超级管理员获取所有的公众号
List<MpAccountsEntity> accounts = mpAccountsService.getAllMpAccounts();
List<MpAccountsEntity> qyAccounts = mpAccountsService.getAllQpAccounts();
accounts.addAll(qyAccounts);
users=accounts;
} else {
users = mpAccountsService.getAllAccounts(user.getId());
}
JSONObject returnObj = new JSONObject();
returnObj.put("aaData", JSONArray.fromObject(users));
OutputJSONUtil.convertoJSONStream(response, returnObj.toString());
}
// 修改账户
@RequestMapping(value = "/updateaccounts",method = RequestMethod.POST)
@ResponseBody
public JSONObject updateaccounts(MpAccountsEntity accounts,
String oldappid, HttpServletResponse response) {
JSONObject returnObj = new JSONObject();
returnObj.put("errorCode", 0);
User user = UserUtils.getUser();// 获得当前用户
MpAccountsEntity isexist = mpAccountsService
.getMpAccountsAppid(accounts.getAppid());// 新的公众号是否存在
mpAccountsService.updateByPrimaryKey(accounts);
if (accounts != null && StringUtils.isNotBlank(accounts.getAppid())) {
if (StringUtils.equals(accounts.getAppid(), oldappid)) {// appid未做修改
accounts.setUpdatetime(new Date());
accounts.setAccesstoken(isexist.getAccesstoken());
mpAccountsService.updateByPrimaryKey(accounts);
} else {
if (isexist != null) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("userid", user.getId());
params.put("accountsid", accounts.getAppid());
int count = mpAccountsService.getUserAccounts(params);// 新的公众号此人是否已经在管理
if (count > 0) {
returnObj.put("errorCode", 1); // 新公众号此人已经在管理
} else {// 将此人与新的公众号进行关联
Map<String, Object> param = new HashMap<String, Object>();
param.put("userid", user.getId());
param.put("accountsid", isexist.getId());
mpAccountsService.insertUserAccounts(param);
}
} else {
returnObj.put("errorCode", 2);// 新公众号不存在,需添加
}
}
} else {
returnObj.put("errorCode", 3);// 参数错误
}
return returnObj;
}
// //启用账户
// @RequestMapping(value = "startaccounts")
// @ResponseBody
// public JSONObject startaccounts(Long id,
// HttpServletResponse response) {
// JSONObject returnObj = new JSONObject();
// returnObj.put("errorCode", 0);
// mpAccountsService.startByPrimaryKey(id);
// return returnObj;
// }
// 删除账户
@RequestMapping(value = "/deleteaccounts",method = RequestMethod.POST)
@ResponseBody
public JSONObject deleteaccounts(String id) {
JSONObject returnObj = new JSONObject();
User user = UserUtils.getUser();// 获得当前用户
returnObj.put("errorCode", 0);
Map<String, Object> params = new HashMap<String, Object>();
params.put("userid", user.getId());
params.put("accountsid", id);
//mpAccountsService.deleteByUserAccount(params);
mpAccountsService.deleteByPrimaryKey(Long.valueOf(id));
return returnObj;
}
// 获取详细信息
@RequestMapping(value = "/getaccountdetail",method = RequestMethod.GET)
public String getaccountdetail(Long id, HttpServletResponse response,
Model model) {
MpAccountsEntity accountsEntity = mpAccountsService.getDetail(id);
model.addAttribute("accountsEntity", accountsEntity);
return "manageaccounts/detail";
}
}
package com.cftech.accounts.dao;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.core.generic.GenericDao;
import java.util.List;
import java.util.Map;
public interface MpAccountsMapper extends GenericDao<MpAccountsEntity> {
long insert(MpAccountsEntity mpAccounts);
List<MpAccountsEntity> getMpAccounts(Long userid);
List<MpAccountsEntity> getQyAccounts(Long userid);
long updateByPrimaryKey(MpAccountsEntity mpAccounts);
int deleteByPrimaryKey(Long id);
MpAccountsEntity getDetail(Long userid);
List<MpAccountsEntity> getAllMpAccounts();
List<MpAccountsEntity> getAllQyAccounts();
List<MpAccountsEntity> getAllAccounts(Long userid);
MpAccountsEntity getMpAccountsAppid(String appId);
int deleteByUserAccount(Map<String, Object> params);
int insertUserAccount(Map<String, Object> params);
int getUserAccounts(Map<String, Object> params);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cftech.accounts.dao.MpAccountsMapper">
<resultMap id="BaseResultMap" type="com.cftech.accounts.model.MpAccountsEntity">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="appid" property="appid" jdbcType="VARCHAR" />
<result column="secret" property="secret" jdbcType="CHAR" />
<result column="token" property="token" jdbcType="VARCHAR" />
<result column="jsapi_ticket" property="jsapi_ticket" jdbcType="VARCHAR" />
<result column="encodingaeskey" property="encodingaeskey"
jdbcType="VARCHAR" />
<result column="wctype" property="wctype"
jdbcType="VARCHAR" />
<result column="createtime" property="createtime" jdbcType="TIMESTAMP" />
<result column="updatetime" property="updatetime" jdbcType="TIMESTAMP" />
<result column="upload_type" property="uploadType" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, description, appid, secret,
token,encodingaeskey,createtime,updatetime,delflag,accesstoken,jsapi_ticket,wctype,upload_type
</sql>
<!-- 插入用户服务号 -->
<insert id="insert" parameterType="com.cftech.accounts.model.MpAccountsEntity">
insert into wx_mp_accounts ( appid, secret,
encodingaeskey,token,accesstoken,delflag,
createtime,timestamp,updatetime,description, wctype)
values (#{appid,jdbcType=VARCHAR}, #{secret,jdbcType=VARCHAR},
#{encodingaeskey,jdbcType=VARCHAR},#{token,jdbcType=VARCHAR},
#{accesstoken,jdbcType=VARCHAR},
#{delflag,jdbcType=INTEGER},
#{createtime,jdbcType=TIMESTAMP},
#{timestamp,jdbcType=BIGINT},
#{updatetime,jdbcType=TIMESTAMP},
#{description,jdbcType=VARCHAR},
#{wctype,jdbcType=VARCHAR}),
</insert>
<!-- 关联表插入 -->
<insert id="insertUserAccount" parameterType="java.util.Map">
insert into user_accounts values (id,#{userid},#{accountsid},0);
</insert>
<select id="getMpAccounts" resultMap="BaseResultMap"
parameterType="java.lang.Long">
select
accounts.id, accounts.description, accounts.appid, accounts.secret,
accounts.token,accounts.encodingaeskey,accounts.createtime,accounts.delflag,accounts.accesstoken,wctype
from wx_mp_accounts accounts
left join user_role user on user.accounts_id=accounts.id
where user.user_id = #{userid,jdbcType=BIGINT} and accounts.delflag=0 and accounts.wctype='0'
group by accounts.id
order
by accounts.createtime desc
</select>
<select id="getQyAccounts" resultMap="BaseResultMap"
parameterType="java.lang.Long">
select
accounts.id, accounts.description, accounts.appid, accounts.secret,
accounts.token,accounts.encodingaeskey,accounts.createtime,accounts.delflag,accounts.accesstoken,wctype
from wx_mp_accounts accounts
left join user_role user on user.accounts_id=accounts.id
where user.user_id = #{userid,jdbcType=BIGINT} and accounts.delflag=0 and accounts.wctype='1'
group by accounts.id
order
by accounts.createtime desc
</select>
<select id="getAllAccounts" resultMap="BaseResultMap"
parameterType="java.lang.Long">
select
accounts.id, accounts.description, accounts.appid, accounts.secret,
accounts.token,accounts.encodingaeskey,accounts.createtime,accounts.delflag,accounts.accesstoken,wctype
from wx_mp_accounts accounts
left join user_role user on user.accounts_id=accounts.id
where user.user_id = #{userid,jdbcType=BIGINT} and accounts.delflag=0
group by accounts.id
order
by accounts.createtime desc
</select>
<select id="getMpAccountsAppid" resultMap="BaseResultMap"
parameterType="java.lang.String">
select
<include refid="Base_Column_List" />
from wx_mp_accounts where appid = #{appid,jdbcType=VARCHAR} and delflag=0 order by
id asc limit 0,1
</select>
<select id="getAllMpAccounts" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List" />
from wx_mp_accounts where delflag = 0 and wctype='0' order by delflag asc,createtime
desc
</select>
<select id="getAllQyAccounts" resultMap="BaseResultMap"
parameterType="java.lang.Long">
select
<include refid="Base_Column_List" />
from wx_mp_accounts where delflag = 0 and wctype='1' order by delflag asc,createtime
desc
</select>
<select id="getDetail" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List" />
from wx_mp_accounts where id = #{id,jdbcType=BIGINT}
</select>
<select id="getUserAccounts" parameterType="java.util.Map" resultType="java.lang.Integer">
select count(1) from user_accounts accounts where userid=#{userid} and accountsid=#{accountsid} and delflag=0
</select>
<!-- 更新账户信息 -->
<update id="updateByPrimaryKey" parameterType="com.cftech.accounts.model.MpAccountsEntity">
update wx_mp_accounts
<set>
<if test="encodingaeskey != null">
encodingaeskey = #{encodingaeskey,jdbcType=VARCHAR},
</if>
<if test="token != null">
token = #{token,jdbcType=CHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="delflag != null">
delflag = #{delflag,jdbcType=VARCHAR},
</if>
<if test="secret != null">
secret = #{secret,jdbcType=VARCHAR},
</if>
<if test="accesstoken != null">
accesstoken = #{accesstoken,jdbcType=VARCHAR},
</if>
<if test="jsapi_ticket !=null">
jsapi_ticket = #{jsapi_ticket,jdbcType=VARCHAR},
</if>
<if test="wctype !=null">
wctype = #{wctype,jdbcType=VARCHAR},
</if>
updatetime =now()
</set>
where appid = #{appid,jdbcType=BIGINT}
</update>
<!-- 逻辑删除账户 -->
<update id="deleteByPrimaryKey" parameterType="java.lang.Long">
update wx_mp_accounts
<set>
delflag = 1,
updatetime = now()
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<!--删除关联数据 -->
<update id="deleteByUserAccount" parameterType="java.util.Map">
update user_accounts
<set>
delflag = 1
</set>
where userid = #{userid} and accountsid = #{accountsid}
</update>
</mapper>
\ No newline at end of file
package com.cftech.accounts.dao;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.model.RamJob;
import com.cftech.accounts.model.SysJob;
import com.cftech.accounts.model.TemplateTransfer;
import com.cftech.core.generic.GenericDao;
import java.util.List;
/**
* Created by kingdee-001 on 2018/7/16.
*/
public interface SysJobMapper extends GenericDao<SysJob> {
public void updateStatus(SysJob sysJob);
public void insertRamJob(RamJob ramJob);
public List<RamJob> getRamJob();
public void deleteTemplate(String id);
public Long saveTemplate(TemplateTransfer templateTransfer);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cftech.accounts.dao.SysJobMapper">
<resultMap id="resultMap" type="com.cftech.accounts.model.SysJob">
<id column="id" property="id" />
<result column="job_name" jdbcType="VARCHAR" property="jobName" />
<result column="cron" jdbcType="VARCHAR" property="cron" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="clazz_path" jdbcType="VARCHAR" property="clazzPath" />
<result column="job_desc" jdbcType="VARCHAR" property="jobDesc" />
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="create_by" property="createBy"/>
<result column="update_by" property="updateBy"/>
<result column="description" property="description"/>
<result column="jobuid" property="jobuid" />
<result column="accounts_id" property="accountsId"/>
</resultMap>
<resultMap id="resultRamMap" type="com.cftech.accounts.model.RamJob">
<id column="id" property="id" />
<result column="job_json" property="jobJSON"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="create_by" property="createBy"/>
<result column="update_by" property="updateBy"/>
<result column="description" property="description"/>
<result column="accounts_id" property="accountsId"/>
</resultMap>
<sql id="sqlWhere">
<if test="conds!=null">
<trim prefix="WHERE" prefixOverrides="AND|OR">
<foreach collection="conds.conds" index="index" item="cond">
${cond.linkType}
<if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
<if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
<if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
<if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
<if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
<if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
<if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND
#{cond.endValue}
</if>
<if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
<if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
<if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
<if test="cond.condType == 'IN'">${cond.param} IN
<foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</foreach>
</trim>
</if>
</sql>
<sql id="sqlColumns">
id, job_name, cron,accounts_id, status, create_time, update_time, description, del_flag, create_by, update_by, clazz_path, job_desc, jobuid
</sql>
<insert id="save" parameterType="com.cftech.accounts.model.SysJob" keyProperty="id" useGeneratedKeys="true">
insert into sys_job
(
id, job_name, cron,accounts_id, status, create_time, update_time, description, del_flag, create_by, update_by, clazz_path, job_desc, jobuid
)
values
(
#{id, jdbcType=BIGINT}, #{jobName, jdbcType=VARCHAR}, #{cron, jdbcType=VARCHAR}, #{accountsId, jdbcType=BIGINT}, #{status, jdbcType=VARCHAR},
now(), now(), #{description, jdbcType=VARCHAR}, #{delFlag, jdbcType=TINYINT},
#{createBy, jdbcType=BIGINT}, #{updateBy, jdbcType=BIGINT}, #{clazzPath, jdbcType=VARCHAR}, #{jobDesc, jdbcType=VARCHAR},
#{jobuid, jdbcType=VARCHAR}
)
</insert>
<insert id="insertRamJob" parameterType="com.cftech.accounts.model.RamJob">
Replace into sys_ram_job
(
id, accounts_id, create_time, update_time, description, del_flag, create_by, update_by, job_json
)
values
(
1, #{accountsId, jdbcType=BIGINT},
now(), now(), #{description, jdbcType=VARCHAR}, 0,
#{createBy, jdbcType=BIGINT}, #{updateBy, jdbcType=BIGINT},
#{jobJSON, jdbcType=VARCHAR}
)
</insert>
<select id="getRamJob" resultMap="resultRamMap">
SELECT
job_json,update_time
FROM sys_ram_job
</select>
<select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
SELECT
<include refid="sqlColumns"/>
FROM sys_job t
WHERE t.id=#{id}
</select>
<select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
SELECT COUNT(1) FROM sys_job
<include refid="sqlWhere"/>
</select>
<select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
SELECT
<include refid="sqlColumns"/>
FROM sys_job t
<include refid="sqlWhere"/>
<if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
<if test="limit>0">limit #{offset},#{limit}</if>
</select>
<update id="update" parameterType="com.cftech.accounts.model.SysJob">
update sys_job
<set>
<if test="id != null">
id = #{id, jdbcType=BIGINT},
</if>
<if test="jobName != null">
job_name = #{jobName, jdbcType=VARCHAR},
</if>
<if test="accountsId != null">
accounts_id = #{accountsId, jdbcType=BIGINT},
</if>
<if test="status != null">
status = #{status, jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime, jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time=now(),
</if>
<if test="description != null">
description = #{description, jdbcType=VARCHAR},
</if>
<if test="delFlag != null">
del_flag = #{delFlag, jdbcType=TINYINT},
</if>
<if test="createBy != null">
create_by = #{createBy, jdbcType=BIGINT},
</if>
<if test="updateBy != null">
update_by = #{updateBy, jdbcType=BIGINT},
</if>
<if test="clazzPath != null">
clazz_path = #{clazzPath, jdbcType=VARCHAR},
</if>
<if test="jobDesc != null">
job_desc = #{jobDesc, jdbcType=VARCHAR},
</if>
<if test="jobuid != null">
jobuid = #{jobuid, jdbcType=VARCHAR},
</if>
</set>
where id=#{id,jdbcType=BIGINT}
</update>
<update id="delete" parameterType="java.lang.Long">
update sys_job set delflag=1 where id=#{id,jdbcType=BIGINT}
</update>
<update id="updateStatus" parameterType="com.cftech.accounts.model.SysJob">
update sys_job set status = 0 where jobuid=#{jobuid,jdbcType=VARCHAR}
</update>
<update id="deleteTemplate" parameterType="java.lang.String">
update wx_mp_meeting_template set del_flag=1 where uuid=#{uuid,jdbcType=VARCHAR}
</update>
<insert id="saveTemplate" parameterType="com.cftech.accounts.model.TemplateTransfer" useGeneratedKeys="true"
keyProperty="id">
insert into wx_mp_meeting_template
(
id,
type,
send_time,
accounts_id,
del_flag,
status,
create_time,
update_time,
description,
create_by,
update_by,
meeting_id,
uuid,
name,
template_id,
content,
send_message,
url
)
values
(
#{id, jdbcType=BIGINT},
#{type, jdbcType=VARCHAR},
#{sendTime},
#{accountsId, jdbcType=BIGINT},
#{delFlag, jdbcType=TINYINT},
#{status, jdbcType=VARCHAR},
now(),
now(),
#{description, jdbcType=VARCHAR},
#{createBy, jdbcType=BIGINT},
#{updateBy, jdbcType=BIGINT},
#{meetingId,jdbcType=BIGINT},
#{uuid,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{templateId,jdbcType=VARCHAR},
#{content,jdbcType=CLOB},
#{sendMessage,jdbcType=VARCHAR},
#{url}
)
</insert>
</mapper>
\ No newline at end of file
package com.cftech.accounts.model;
import com.cftech.sys.model.BasicEntity;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
* 服务号账户
* @author Jasper Huang
*
*/
@JsonSerialize
@JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
public class MpAccountsEntity extends BasicEntity {
private static final long serialVersionUID = 6796396505275489918L;
private String appid;
private String secret;
private String encodingaeskey;
private String token;
private Long userid;//创建人ID
private String accesstoken;
private String wctype; // 服务号和企业号, 0是服务号,1是企业号
private String jsapi_ticket;//微信jssdk
private String uploadType;
public String getUploadType() {
return uploadType;
}
public void setUploadType(String uploadType) {
this.uploadType = uploadType;
}
public String getWctype() {
return wctype;
}
public void setWctype(String wctype) {
this.wctype = wctype;
}
public String getJsapi_ticket() {
return jsapi_ticket;
}
public void setJsapi_ticket(String jsapi_ticket) {
this.jsapi_ticket = jsapi_ticket;
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getEncodingaeskey() {
return encodingaeskey;
}
public void setEncodingaeskey(String encodingaeskey) {
this.encodingaeskey = encodingaeskey;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public Long getUserid() {
return userid;
}
public void setUserid(Long userid) {
this.userid = userid;
}
public String getAccesstoken() {
return accesstoken;
}
public void setAccesstoken(String accesstoken) {
this.accesstoken = accesstoken;
}
}
package com.cftech.accounts.model;
import com.cftech.core.generic.GenericEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
@Data
@NoArgsConstructor
@ToString
public class RamJob extends GenericEntity implements Serializable {
private String jobJSON;
/* 所属的账号 */
private Long accountsId;
}
\ No newline at end of file
package com.cftech.accounts.model;
import com.cftech.core.generic.GenericEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
@Data
@NoArgsConstructor
@ToString
public class SysJob extends GenericEntity implements Serializable {
private String jobuid;
private String jobName;
private String cron;
/**
* 状态:0未启动false/1启动true
*/
private String status;
private String clazzPath;
private String jobDesc;
/* 所属的账号 */
private Long accountsId;
private String type;//类型
}
\ No newline at end of file
package com.cftech.accounts.model;
import com.cftech.core.poi.ExportConfig;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 研讨会模板消息,为了可以在ACCOUNTS中引用,增加的类,必须和TEMPLATE中的BEAN一样
*
* @author lisw
* @date: 2018-07-18 16:45
*/
@Data
public class TemplateTransfer implements Serializable {
/* 主键id */
private Long id;
/* 模板类型 */
@ExportConfig(value = "模板类型", width = 100)
private String type;
/* 模板推送时间 */
@ExportConfig(value = "模板推送时间", width = 100)
private Date sendTime;
/* 所属的账号 */
private Long accountsId;
/* 删除标识 */
private boolean delFlag;
/* 状态 */
private String status;
/* 创建时间 */
private Date createTime;
/* 更新时间 */
private Date updateTime;
/* 备注 */
private String description;
/* 创建人 */
private Long createBy;
/* 更新人 */
private Long updateBy;
private String uuid;
private String name;
private String sendTimeStr;
private String content;
private String jobname;
private String sendMessage;
private String meetingId;
private String templateId;
private String url;
public TemplateTransfer() {
this.delFlag = false;
this.status = "0";
}
}
\ No newline at end of file
package com.cftech.accounts.service;
import java.util.List;
import com.cftech.accounts.model.SysJob;
import com.cftech.core.redis.RedisCacheConfig;
import com.cftech.core.sql.Conds;
import com.cftech.core.util.DESUtil;
import com.cftech.core.util.SpringContextHolder;
import com.cftech.core.util.SystemConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* @author KangLiang Huang
* 启动数据库中已经设定为 启动状态(status:true)的任务 项目启动时init
*/
@Service
//@Component
@Slf4j
public class DataSourceJobThread extends Thread {
@Autowired
JobService jobService;
@Autowired
JobTask jobTask;
@Autowired
private RedisSubPubListener redisSubPubListener;
@Autowired
JedisPool jedisPool;
@Override
public void run() {
try {
boolean isCluster = Boolean.valueOf(SystemConfig.p.getProperty("quartz.isCluster"));
if(!isCluster)
{
return;
}
Thread.sleep(5000);
//需要添加判断
if(SpringContextHolder.getApplicationContext()==null)
{
Thread.sleep(10000);
}
log.info("---------定时任务线程启动---------");
Conds cond = new Conds();
cond.equal("status","1");
cond.equal("del_flag",0);
List<SysJob> jobList = jobService.fetchSearchByPage(cond,null,0,0);
//开启任务
try {
jobList.forEach(jobs -> {
log.info("---任务[" + jobs.getJobuid()+ "]系统 init--开始启动---------");
jobTask.startJob(jobs);
}
);
}catch (Exception e)
{
log.error("自动启动,初始化开始执行任务异常",e);
}
if (jobList.size() == 0) {
log.info("---数据库暂无启动的任务---------");
} else
{
System.out.println("---任务启动完毕---------");
}
log.info("---------启动消息队-------");
//修改问直接访问REDIS 2018-09-25 后续有问题,还原成直接获得JEDIS对象模式
// Jedis jedis = new Jedis(SystemConfig.r.getProperty("spring.redis.host"), 6379);
// jedis.auth(DESUtil.decrypt( SystemConfig.r.getProperty("spring.redis.password"),DESUtil.KEY));
Jedis jedis = null;//jedisPool.getResource();
//jedis.subscribe(redisSubPubListener,"job_listener");
while (true)
{
try {
jedis = jedisPool.getResource();
log.info("订阅REDIS JOB");
jedis.subscribe(redisSubPubListener,"job_listener");
}catch (Exception subScribeException)
{
log.error("监听REDIS,定时任务失败",subScribeException);
}finally {
if(jedis!=null)
{
jedis.close();
}
}
}
} catch (Exception e) {
log.error("初始化启动任务异常",e);
}
}
}
package com.cftech.accounts.service;
/**
* Created by kingdee-001 on 2018/7/16.
*/
import com.cftech.accounts.model.RamJob;
import com.cftech.accounts.model.SysJob;
import com.cftech.core.generic.GenericService;
import java.util.List;
public interface JobService extends GenericService<SysJob> {
public void updateStatus(SysJob sysJob);
public List<RamJob> getRamJob();
}
package com.cftech.accounts.service;
import com.cftech.accounts.model.SysJob;
import com.cftech.core.util.StringUtils;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author KangLiang Huang
* <p>
* 定时任务类 增删改 可参考api:http://www.quartz-scheduler.org/api/2.2.1/
* <p>
* 任务名称 默认为 SysJob 类 id
*/
@Service
@Slf4j
public class JobTask {
@Autowired
SchedulerFactoryBean schedulerFactoryBean;
/**
* 查看目前内存中的Job 信息
*/
// public List<String> getRAMJobs()
// {
// List<String> infos = new ArrayList<String>();
// Scheduler scheduler = schedulerFactoryBean.getScheduler();
// try {
// List<JobExecutionContext> jobsContexts = scheduler.getCurrentlyExecutingJobs();
// for(JobExecutionContext jobsContext:jobsContexts)
// {
// JobDetail jobDetail = jobsContext.getJobDetail();
// infos.add(jobDetail.getJobDataMap().get("uid").toString());
// }
// } catch (SchedulerException e) {
// e.printStackTrace();
// }
// return infos;
// }
public Set<String> getRAMJOBS()
{
Set<String> infos = new HashSet<String>();
Scheduler scheduler = schedulerFactoryBean.getScheduler();
try {
for (String groupName : scheduler.getJobGroupNames()) {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
String jobName = jobKey.getName();
String jobGroup = jobKey.getGroup();
//get job's trigger
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
for(Trigger tt:triggers)
{
infos.add(tt.getKey().getName());
}
// Date nextFireTime = triggers.get(0).getNextFireTime();
// System.out.println("[jobName] : " + jobName + " [groupName] : "
// + jobGroup + " - " + nextFireTime);
}
}
}catch (SchedulerException e) {
e.printStackTrace();
}
return infos;
}
/**
* true 存在 false 不存在
*
* @param
* @return
*/
public boolean checkJob(SysJob job) {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobuid(), Scheduler.DEFAULT_GROUP);
try {
if (scheduler.checkExists(triggerKey)) {
return true;
}
} catch (SchedulerException e) {
e.printStackTrace();
}
return false;
}
/**
* 开启
*/
public boolean startJob(SysJob job) {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
try {
Class clazz = Class.forName(job.getClazzPath());
JobDetail jobDetail = JobBuilder.newJob(clazz).usingJobData("uid",job.getJobuid()).usingJobData("type",job.getType()).build();
// 触发器
TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobuid(), Scheduler.DEFAULT_GROUP);
//修改出发器,只执行一次任务
Trigger trigger = null;
if(StringUtils.isNotBlank(job.getCron()))
{
trigger = TriggerBuilder.newTrigger()
.withIdentity(triggerKey)
.withSchedule(CronScheduleBuilder.cronSchedule(job.getCron())).build();
}else if(StringUtils.isNotBlank(job.getJobDesc()))
{
//获得时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = sdf.parse(job.getJobDesc()+":00");
trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey)
.startAt(startDate).withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(0)).build();
}
scheduler.scheduleJob(jobDetail, trigger);
// 启动
if (scheduler.isShutdown()) {
scheduler.start();
log.info("---任务[" + triggerKey.getName() + "]启动成功-------");
} else {
log.info("---任务[" + triggerKey.getName() + "]已经调度运行成功,请勿再次启动主线程-------");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return true;
}
/**
* 更新
*/
public boolean updateJob(SysJob job) {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
String createTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobuid(), Scheduler.DEFAULT_GROUP);
try {
if (scheduler.checkExists(triggerKey)) {
return false;
}
JobKey jobKey = JobKey.jobKey(job.getJobuid(), Scheduler.DEFAULT_GROUP);
CronScheduleBuilder schedBuilder = CronScheduleBuilder.cronSchedule(job.getCron())
.withMisfireHandlingInstructionDoNothing();
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey)
.withDescription(createTime).withSchedule(schedBuilder).build();
Class clazz = null;
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
HashSet<Trigger> triggerSet = new HashSet<>();
triggerSet.add(trigger);
scheduler.scheduleJob(jobDetail, triggerSet, true);
log.info("---任务[" + triggerKey.getName() + "]更新成功-------");
return true;
} catch (SchedulerException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 删除
*/
public boolean remove(SysJob job) {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobuid(), Scheduler.DEFAULT_GROUP);
try {
if (checkJob(job)) {
scheduler.pauseTrigger(triggerKey);
scheduler.unscheduleJob(triggerKey);
scheduler.deleteJob(JobKey.jobKey(job.getJobuid(), Scheduler.DEFAULT_GROUP));
log.info("---任务[" + triggerKey.getName() + "]删除成功-------");
return true;
}
} catch (SchedulerException e) {
e.printStackTrace();
}
return false;
}
}
package com.cftech.accounts.service;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.core.generic.GenericService;
import java.util.List;
import java.util.Map;
public interface MpAccountsService extends GenericService<MpAccountsEntity> {
long insert(MpAccountsEntity record);
List<MpAccountsEntity> getMpAccounts(Long userid);
List<MpAccountsEntity> getAllAccounts(Long userid);
List<MpAccountsEntity> getQyAccounts(Long userid);
void updateByPrimaryKey(MpAccountsEntity mpAccounts);
int deleteByPrimaryKey(Long id);
MpAccountsEntity getDetail(Long id);
List<MpAccountsEntity> getAllMpAccounts();
List<MpAccountsEntity> getAllQpAccounts();
MpAccountsEntity getMpAccountsAppid(String appId);
int deleteByUserAccount(Map<String, Object> params);
int insertUserAccounts(Map<String, Object> params);
int getUserAccounts(Map<String, Object> params);
}
package com.cftech.accounts.service;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
public class MyJobFactory extends AdaptableJobFactory{
// @Autowired
private AutowireCapableBeanFactory capableBeanFactory;
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
capableBeanFactory.autowireBean(job);
return job;
}
}
\ No newline at end of file
package com.cftech.accounts.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;
//@Configuration
public class MySchedulerListener {
// @Autowired
MyJobFactory myJobFactory;
// @Bean(name ="schedulerFactoryBean")
public SchedulerFactoryBean schedulerFactory() {
SchedulerFactoryBean bean = new SchedulerFactoryBean();
bean.setJobFactory(myJobFactory);
bean.setConfigLocation(new ClassPathResource("quartz.properties"));
// System.out.print(bean.PROP_THREAD_COUNT);
return bean;
}
}
\ No newline at end of file
package com.cftech.accounts.service;
import com.alibaba.fastjson.JSONObject;
import com.cftech.accounts.dao.SysJobMapper;
import com.cftech.accounts.model.RamJob;
import com.cftech.accounts.model.SysJob;
import com.cftech.accounts.model.TemplateTransfer;
import com.cftech.core.scope.OrderType;
import com.cftech.core.sql.Conds;
import com.cftech.core.sql.Sort;
import com.cftech.core.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPubSub;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Redis 监听器
* Created by Jasper Huang on 2018/8/17.
*/
@Service
public class RedisSubPubListener extends JedisPubSub {
@Autowired
SysJobMapper sysJobMapper;
@Autowired
JobTask jobTask;
@Autowired
private JobService jobService;
public void onMessage(String channel, String message) {
System.out.println(channel + "=" + message);
try
{
JSONObject object = JSONObject.parseObject(message);
if("1".equals(object.getString("status")))
{
object = object.getJSONObject("data");
SysJob job = new SysJob();
job.setStatus("1");
job.setDelFlag(false);
job.setCreateBy(1L);
job.setUpdateBy(1L);
job.setJobuid(object.getString("uuid"));
job.setAccountsId(object.getLong("accountsId"));
job.setJobDesc(object.getString("sendTimeStr"));
job.setJobName(object.getString("jobname"));
job.setType(object.getString("type"));
job.setClazzPath("com.cftech.workshop.template.service.JobDemo2");
sysJobMapper.save(job);
jobTask.startJob(job);
TemplateTransfer templateTransfer = JSONObject.toJavaObject(object, TemplateTransfer.class);
sysJobMapper.saveTemplate(templateTransfer);
}else if("0".equals(object.getString("status")))
{
object = object.getJSONObject("data");
SysJob job = new SysJob();
job.setJobuid(object.getString("uuid"));
sysJobMapper.deleteTemplate(object.getString("uuid"));
jobTask.remove(job);
job.setStatus("0");
sysJobMapper.updateStatus(job);
}else if("3".equals(object.getString("status")))
{
object = object.getJSONObject("data");
//查看实际内存中的信息
Conds conds = new Conds();
conds.equal("del_flag", Constants.DEL_FLAG_0);
Set<String> uuids = jobTask.getRAMJOBS();
Object [] objs = new Object[uuids.size()];
Iterator<String> itr =uuids.iterator();
int i=0;
while(itr.hasNext())
{
objs[i] = itr.next();
i++;
}
if(uuids.size()==0)
{
objs = new Object[1];
objs[0] = '1';
}
conds.in("jobuid",objs);
Sort sort = new Sort("create_time", OrderType.DESC);
List<SysJob> list = jobService.fetchSearchByPage(conds, sort, 0, 0);
Integer userCounts = jobService.count(conds);
JSONObject rtnJson = new JSONObject();
rtnJson.put("iTotalRecords", userCounts);
rtnJson.put("iTotalDisplayRecords", userCounts);
rtnJson.put("aaData", list);
//写入到数据库中
RamJob rj = new RamJob();
rj.setAccountsId(object.getLong("accountsId"));
rj.setJobJSON(rtnJson.toJSONString());
rj.setCreateBy(1L);
rj.setUpdateBy(1L);
sysJobMapper.insertRamJob(rj);
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}
package com.cftech.accounts.service.impl;
import com.cftech.accounts.dao.MpAccountsMapper;
import com.cftech.accounts.dao.SysJobMapper;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.model.RamJob;
import com.cftech.accounts.model.SysJob;
import com.cftech.accounts.service.JobService;
import com.cftech.core.generic.GenericDao;
import com.cftech.core.generic.GenericServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by kingdee-001 on 2018/7/16.
*/
@Service
public class JobServiceImpl extends GenericServiceImpl<SysJob> implements JobService {
@Autowired
private SysJobMapper sysJobMapper;
@Override
protected GenericDao<SysJob> getGenericMapper() {
return sysJobMapper;
}
@Override
public void updateStatus(SysJob sysJob)
{
sysJobMapper.updateStatus(sysJob);
}
@Override
public List<RamJob> getRamJob()
{
List<RamJob> ramJobList = sysJobMapper.getRamJob();
return ramJobList;
}
}
package com.cftech.accounts.service.impl;
import com.cftech.accounts.dao.MpAccountsMapper;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.core.generic.GenericDao;
import com.cftech.core.generic.GenericServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class MpAccountsServiceImpl extends GenericServiceImpl<MpAccountsEntity> implements MpAccountsService{
@Autowired
private MpAccountsMapper accountsMapper;
@Override
public List<MpAccountsEntity> getMpAccounts(Long userid) {
return accountsMapper.getMpAccounts(userid);
}
@Override
public List<MpAccountsEntity> getQyAccounts(Long userid) {
return accountsMapper.getQyAccounts(userid);
}
@Override
public List<MpAccountsEntity> getAllAccounts(Long userid) {
return accountsMapper.getAllAccounts(userid);
}
@Override
public long insert(MpAccountsEntity model) {
return accountsMapper.insert(model);
}
@Override
public void updateByPrimaryKey(MpAccountsEntity mpAccounts) {
accountsMapper.updateByPrimaryKey(mpAccounts);
}
@Override
public int deleteByPrimaryKey(Long id) {
return accountsMapper.deleteByPrimaryKey(id);
}
@Override
public MpAccountsEntity getDetail(Long id) {
return accountsMapper.getDetail(id);
}
@Override
public List<MpAccountsEntity> getAllMpAccounts() {
// TODO Auto-generated method stub
return accountsMapper.getAllMpAccounts();
}
@Override
public List<MpAccountsEntity> getAllQpAccounts() {
return accountsMapper.getAllQyAccounts();
}
@Override
protected GenericDao<MpAccountsEntity> getGenericMapper() {
return accountsMapper;
}
@Override
public MpAccountsEntity getMpAccountsAppid(String appId) {
return accountsMapper.getMpAccountsAppid(appId);
}
@Override
public int insertUserAccounts(Map<String, Object> params) {
return accountsMapper.insertUserAccount(params);
}
@Override
public int deleteByUserAccount(Map<String, Object> params) {
return accountsMapper.deleteByUserAccount(params);
}
@Override
public int getUserAccounts(Map<String, Object> params) {
return accountsMapper.getUserAccounts(params);
}
}
package com.cftech.core.util;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import java.util.List;
//@Component
public class InstantiationTracingBeanPostProcessor
// implements ApplicationListener<ContextRefreshedEvent>
{
private static Logger logger = Logger.getLogger(InstantiationTracingBeanPostProcessor.class);
// @Autowired
private MpAccountsService mpAccountService;
// @Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if(event.getApplicationContext().getParent() == null)
{
//root application context
//需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。
logger.info("Init token start ");
List<MpAccountsEntity> mpAccounts = mpAccountService.getAllMpAccounts(); // MpAccountsEntity accountsEntity
for(MpAccountsEntity accountsEntity:mpAccounts)
{
// String accessToken = accountsEntity.getAccesstoken();
// try
// {
// accessToken = JwTokenAPI.getAccessToken(accountsEntity.getAppid(), accountsEntity.getSecret());
// accountsEntity.setJsapi_ticket(JwThirdAPI.args(accessToken));
// accountsEntity.setAccesstoken(accessToken);
// mpAccountService.updateByPrimaryKey(accountsEntity);
// } catch (WexinReqException e)
// {
// logger.error("启动更新TOKEN失败"+accountsEntity.getId(), e);
// }
}
logger.info("Init token do end ");
}
}
}
package com.cftech.sys.controller;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.sys.model.Permission;
import com.cftech.sys.model.User;
import com.cftech.sys.model.UserRole;
import com.cftech.sys.security.UserUtils;
import com.cftech.sys.service.PermissionService;
import com.cftech.sys.service.RoleService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 公共视图控制器
*
**/
@Controller
@RequestMapping("/a")
public class CommonController {
@Autowired
private PermissionService permissionService;
@Autowired
private MpAccountsService mpAccountService;
@Autowired
private RoleService roleService;
/**
* 首页
*
* @param request
* @return
*/
@RequestMapping(value = "index",method = {RequestMethod.GET,RequestMethod.POST})
public String index(HttpServletRequest request, Model model) {
Subject subject = SecurityUtils.getSubject();
String accountsId = request.getParameter("accountsId");
User currentUser = UserUtils.getUser();
List<MpAccountsEntity> qyList = mpAccountService.getQyAccounts(currentUser.getId());
model.addAttribute("qyList", qyList);
List<MpAccountsEntity> mpList = mpAccountService.getMpAccounts(currentUser.getId());
model.addAttribute("mpList", mpList);
model.addAttribute("defaultAccountsId",accountsId);
MpAccountsEntity accountsEntity = null;
if (StringUtils.isNotBlank(accountsId)) {
accountsEntity = mpAccountService.getDetail(Long.valueOf(accountsId));
} else {
if (currentUser.getDefaultAccId() != null) {
accountsEntity = mpAccountService.getDetail(currentUser.getDefaultAccId());
}
}
if (accountsEntity != null) {
String roleids = "";
List<UserRole> userRole = roleService.selectRolesByUserAccountsId(currentUser.getId(), accountsEntity.getId());
for (int i = 0; i < userRole.size(); i++) {
if (i == userRole.size() - 1) {
roleids += userRole.get(i).getRoleId();
} else {
roleids += userRole.get(i).getRoleId() + ",";
}
}
if (StringUtils.isNotBlank(roleids)) {
List<Permission> permissions = permissionService.getMenuByRoles(roleids);
model.addAttribute("permission", permissions);
List<Permission> allPerms = permissionService.getPermissionsByRoles(roleids);
request.getSession().setAttribute("permission", allPerms);
}
//获得当前账号
request.getSession().setAttribute("mpaccounts", accountsEntity.getId());
request.getSession().setAttribute("isshow", "2");//不显示,首页报表图
return "index";
} else {
return "welcome";
}
}
@RequestMapping(value = "showpage",method = {RequestMethod.GET,RequestMethod.POST})
public String showpage(HttpServletRequest request,Model model,Long id)
{
if(id==null){
id= UserUtils.getmpaccounts(request);
}
User currentUser = UserUtils.getUser();
String roleids= "";
List<UserRole> userRole = roleService.selectRolesByUserAccountsId(currentUser.getId(), id);
for(int i =0;i<userRole.size();i++){
if(i==userRole.size()-1){
roleids+=userRole.get(i).getRoleId();
}else{
roleids+=userRole.get(i).getRoleId()+",";
}
}
if(StringUtils.isNotBlank(roleids))
{
model.addAttribute("permission",permissionService.getMenuByRoles(roleids));
}
//获得当前账号
MpAccountsEntity mpAccount=mpAccountService.getDetail(id);
request.getSession().setAttribute("mpaccountsDescription", mpAccount.getDescription());
request.getSession().setAttribute("mpaccounts", id);
//调用微信接口获得 关注数据 详情
return "index";
}
@RequestMapping("501")
public String functioning(){
return "501";
}
}
\ No newline at end of file
package com.cftech.sys.controller;
import com.alibaba.fastjson.JSONObject;
import com.cftech.core.annotation.CSRFTokenRef;
import com.cftech.core.config.MpGlobalConfig;
import com.cftech.sys.filter.McCsrfTokenRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
/**
* 基于注解形式的返回拦截器
* Created by Jasper Huang on 2018/6/5.
*/
@ControllerAdvice
public class McResponseBodyAnnoController implements ResponseBodyAdvice {
private static Logger logger = LoggerFactory.getLogger(McResponseBodyAnnoController.class);
@Autowired
private McCsrfTokenRepository mcCsrfTokenRepository;
@Override
public boolean supports(MethodParameter methodParameter, Class aClass) {
Method method = methodParameter.getMethod();
if(method.isAnnotationPresent(CSRFTokenRef.class))
{
// RequestMapping rm = method.getAnnotation(RequestMapping.class);
return true;
}
return false;
}
@Override
public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
if (serverHttpRequest.getMethod() == HttpMethod.POST) {
if (o instanceof JSONObject) {
if (MpGlobalConfig.TOKEN_REFRESH) {
CsrfToken token = getCsrfToekn(serverHttpRequest,serverHttpResponse);
JSONObject rtnJson = (JSONObject) o;
rtnJson.put("_csrf_header", token.getHeaderName());
rtnJson.put("_csrf", token.getToken());
return rtnJson;
}
} else if (o instanceof net.sf.json.JSONObject) {
if (MpGlobalConfig.TOKEN_REFRESH) {
CsrfToken token = getCsrfToekn( serverHttpRequest,serverHttpResponse);
net.sf.json.JSONObject rtnJson = (net.sf.json.JSONObject) o;
rtnJson.put("_csrf_header", token.getHeaderName());
rtnJson.put("_csrf", token.getToken());
return rtnJson;
}
} else if (o instanceof org.json.JSONObject) {
CsrfToken token = getCsrfToekn(serverHttpRequest,serverHttpResponse);
org.json.JSONObject rtnJson = (org.json.JSONObject) o;
rtnJson.put("_csrf_header", token.getHeaderName());
rtnJson.put("_csrf", token.getToken());
return rtnJson;
}
}
return o;
}
private CsrfToken getCsrfToekn(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse)
{
HttpServletRequest request = ((ServletServerHttpRequest)serverHttpRequest).getServletRequest();
HttpServletResponse response = ((ServletServerHttpResponse)serverHttpResponse).getServletResponse();
CsrfToken token = mcCsrfTokenRepository.generateTokenWithSave(request, response);
return token;
}
}
//package com.cftech.sys.controller;
//
//import com.alibaba.fastjson.JSONObject;
//import com.cftech.core.config.MpGlobalConfig;
//import com.cftech.sys.filter.McCsrfTokenRepository;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.http.server.ServletServerHttpRequest;
//import org.springframework.http.server.ServletServerHttpResponse;
//import org.springframework.security.web.csrf.CsrfToken;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.lang.reflect.Method;
//
///**
// * 取消针对移动端刷新TOKEN,移动端TOKEN CSRF TOKEN刷新 采用单独的JWT进行开发
// * Created by Jasper Huang on 2018/6/4.
// */
////@ControllerAdvice
//public class McResponseBodyController implements ResponseBodyAdvice {
// private static Logger logger = LoggerFactory.getLogger(McResponseBodyController.class);
// @Autowired
// private McCsrfTokenRepository mcCsrfTokenRepository;
// @Override
// public boolean supports(MethodParameter methodParameter, Class aClass) {
//
// boolean isBackEnd = false;
// if(aClass.isAnnotationPresent(RequestMapping.class))
// {
// RequestMapping oo = (RequestMapping) aClass.getAnnotation(RequestMapping.class);
// if(oo!=null)
// {
// String[] requestUrl = oo.value();
// if(requestUrl!=null)
// {
// for(String str:requestUrl)
// {
// if(str.startsWith("/a"))
// {
// isBackEnd = true;
// break;
// }
// }
// }
// }
// }
// if(isBackEnd)
// {
// Method method = methodParameter.getMethod();
// boolean rbMethod = false;
// try
// {
// if(method.isAnnotationPresent(ResponseBody.class))
// {
// rbMethod = true;
// }else
// {
// return false;
// }
// if(method.isAnnotationPresent(RequestMapping.class))
// {
// RequestMapping rm = method.getAnnotation(RequestMapping.class);
// RequestMethod[] methodInfo = rm.method();
// if(methodInfo!=null)
// {
// for(RequestMethod me:methodInfo)
// {
// if(RequestMethod.POST==me)
// {
// if(rbMethod)
// {
// return true;
// }
// }
// }
// }
// }
// }catch (Exception e)
// {
// logger.error("拦截器获取返回RESPONSE BODY数据:",e);
// }
// }
// return false;
// }
//
// @Override
// public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
//// return null;
// if ( serverHttpRequest.getMethod() == HttpMethod.POST) {
// if (o instanceof JSONObject) {
// if (MpGlobalConfig.TOKEN_REFRESH) {
// CsrfToken token = getCsrfToekn(serverHttpRequest,serverHttpResponse);
// JSONObject rtnJson = (JSONObject) o;
// rtnJson.put("_csrf_header", token.getHeaderName());
// rtnJson.put("_csrf", token.getToken());
// return rtnJson;
// }else
// {
// return o;
// }
// } else if (o instanceof net.sf.json.JSONObject) {
// if (MpGlobalConfig.TOKEN_REFRESH) {
// CsrfToken token = getCsrfToekn( serverHttpRequest,serverHttpResponse);
// net.sf.json.JSONObject rtnJson = (net.sf.json.JSONObject) o;
// rtnJson.put("_csrf_header", token.getHeaderName());
// rtnJson.put("_csrf", token.getToken());
// return rtnJson;
// }
// else
// {
// return o;
// }
// } else if (o instanceof org.json.JSONObject) {
// CsrfToken token = getCsrfToekn(serverHttpRequest,serverHttpResponse);
// org.json.JSONObject rtnJson = (org.json.JSONObject) o;
// rtnJson.put("_csrf_header", token.getHeaderName());
// rtnJson.put("_csrf", token.getToken());
// return rtnJson;
// } else {
// return o;
// }
// }else {
// return o;
// }
// }
//
// private CsrfToken getCsrfToekn(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse)
// {
// HttpServletRequest request = ((ServletServerHttpRequest)serverHttpRequest).getServletRequest();
// HttpServletResponse response = ((ServletServerHttpResponse)serverHttpResponse).getServletResponse();
// CsrfToken token = mcCsrfTokenRepository.generateTokenWithSave(request, response);
// return token;
// }
//}
package com.cftech.sys.controller;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.sys.model.MobileViewlog;
import com.cftech.sys.service.MobileViewlogService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.Date;
/**
* @author 作者 lisw:
* @version 创建时间:2016年10月24日 下午1:34:10
* 后台日志操作Controller
*/
@Controller
@RequestMapping("/mobile/auth/mobilestaticlog")
public class MobileStaticLogController {
@Autowired
private MobileViewlogService mobileViewlogService;
@Autowired
private MpAccountsService mpAccountService;
@RequestMapping(value="/save",method=RequestMethod.POST)
@ResponseBody
public JSONObject save(String params,String appid,HttpServletRequest request){
//判断请求参数
System.out.println(params);
System.out.println(appid);
JSONObject rtnJson = new JSONObject();
rtnJson.put("errorNo", 1);
if(StringUtils.isBlank(appid)){
return rtnJson;
}
Long accountsid = checkappid(appid);
MobileViewlog mobileViewlog =new MobileViewlog();
mobileViewlog.setRemoteAddr(com.cftech.core.util.StringUtils.getRemoteAddr(request));
mobileViewlog.setUserAgent(request.getHeader("user-agent"));
mobileViewlog.setRequestUri(request.getRequestURI());
mobileViewlog.setAppid(request.getParameter("appid"));
mobileViewlog.setCreateDate(new Timestamp(new Date().getTime()));
mobileViewlog.setParenturl(request.getHeader("REFERER"));
mobileViewlog.setParams(params);
mobileViewlog.setAccountsid(accountsid);
try {
mobileViewlogService.save(mobileViewlog);
rtnJson.put("errorNo", 0);
} catch (Exception e) {
rtnJson.put("errorNo", 1);
}
return rtnJson;
}
/**
* 根据appid获取accountsid
* */
private Long checkappid(String appid) {
MpAccountsEntity accountEntity = mpAccountService
.getMpAccountsAppid(appid);
if (accountEntity != null) {
return accountEntity.getId();
} else {
return null;
}
}
}
\ No newline at end of file
package com.cftech.sys.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cftech.accounts.model.MpAccountsEntity;
import com.cftech.accounts.service.MpAccountsService;
import com.cftech.core.mongo.Pager;
import com.cftech.core.util.DateUtils;
import com.cftech.core.util.ExcelUtils;
import com.cftech.core.util.JsonDateValueProcessor;
import com.cftech.sys.model.MobileLog;
import com.cftech.sys.param.SysLogListParam;
import com.cftech.sys.security.PermissionSign;
import com.cftech.sys.security.UserUtils;
import com.cftech.sys.service.MobileLogService;
import com.cftech.sys.service.MobileViewlogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
/**
* @author 作者 lisw:
* @version 创建时间:2016年10月24日 下午1:34:10
* 后台日志操作Controller
*/
@Controller
@RequestMapping("/a/mobileviewlog")
public class MobileViewLogController {
@Autowired
private MobileViewlogService mobileViewlogService;
@Autowired
private MobileLogService mobileLogService;
@Autowired
private MpAccountsService mpAccountsService;
//访问日志
@RequestMapping(value="/list",method=RequestMethod.GET)
@RequiresPermissions(value = PermissionSign.SYSLOG_VIEWS)
public String sysLogList(HttpServletRequest request,SysLogListParam sysLogListParam,Model model){
model.addAttribute("sysLogListParam",sysLogListParam);
return "managerlog/mobileviewloglist";
}
//操作日志
@RequestMapping(value="/listStatic",method=RequestMethod.GET)
@RequiresPermissions(value = PermissionSign.SYSLOG_VIEWS)
public String sysLogListStatic(HttpServletRequest request,SysLogListParam sysLogListParam,Model model){
model.addAttribute("sysLogListParam",sysLogListParam);
return "managerlog/mobileloglist";
}
@RequestMapping(value="/fetchData",method=RequestMethod.GET)
@RequiresPermissions(value = PermissionSign.SYSLOG_VIEWS)
@ResponseBody
public JSONObject fetchData(int iDisplayStart, int iDisplayLength,
MobileLog log, SysLogListParam sysLogListParam, HttpServletRequest request){
// Sort sort = new Sort("t.create_date", OrderType.DESC);
// Conds conds = new Conds();
// //请求参数
// if(sysLogListParam != null){
// if(StringUtils.isNoneBlank(sysLogListParam.getBrithdayStarttime()) && StringUtils.isNoneBlank(sysLogListParam.getBrithdayEndtime())){
// conds.between("t.create_date", sysLogListParam.getBrithdayStarttime(),sysLogListParam.getBrithdayEndtime());
// }else if(StringUtils.isNoneBlank(sysLogListParam.getBrithdayStarttime())){
// conds.greatEqual("t.create_date",sysLogListParam.getBrithdayStarttime());
// }else if(StringUtils.isNoneBlank(sysLogListParam.getBrithdayEndtime())){
// conds.lessEqual("t.create_date",sysLogListParam.getBrithdayEndtime());
// }
// }
// // 获取列表数据
// List<MobileViewlog> activityList = mobileViewlogService.fetchSearchByPage(conds, sort, iDisplayStart, iDisplayLength);
// // 获得总数
// Integer userCounts = mobileViewlogService.count(conds);
MpAccountsEntity account =mpAccountsService.getDetail(UserUtils.getmpaccounts(request));
log.setAppid(account.getAppid());
Pager pager = new Pager();
pager.setPageNum(iDisplayStart/iDisplayLength);
pager.setPageSize(iDisplayLength);
Pager page =mobileLogService.selectPage(log, pager);
// if(page!=null && page.getResult()!=null && page.getResult().size()>0){
// List<MobileLog> logs = page.getResult();
// for(MobileLog mobile : logs){
// System.out.println(mobile.getOpenid());
// }
// }else{
// System.out.println("未查询到数据");
// }
JSONObject rtnJson = new JSONObject();
rtnJson.put("iTotalRecords", page.getTotal());
rtnJson.put("iTotalDisplayRecords", page.getTotal());
rtnJson.put("aaData", page.getResult());
return rtnJson;
}
@RequestMapping("/export")
public void export(MobileLog log,SysLogListParam sysLogListParam,HttpServletRequest request,HttpServletResponse response){
MpAccountsEntity account = mpAccountsService.getDetail(UserUtils.getmpaccounts(request));
log.setAppid(account.getAppid());
Pager pager = new Pager();
pager.setPageNum(0);
pager.setPageSize(50000);
Pager page =mobileLogService.selectPage(log, pager);
List list = page.getResult();
// if(page.getTotal()>50000){//仅截取50000条
// list=list.subList(0, 49999);
// }
// 参数
try {
ExcelUtils.export(request, response,"访问日志报表-" + DateUtils.formatDate(new Date(), "yyyy-MM-dd"),list, "logview");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//清空前端访问日志
@RequestMapping(value="/deleteAllMobileViewLog",method=RequestMethod.POST)
@ResponseBody
public JSONObject deleteAllMobileLog(){
JSONObject rtnJson = new JSONObject();
rtnJson.put("errorNo", 0);
try {
mobileViewlogService.deleteAllMobileViewLog();
} catch (Exception e) {
rtnJson.put("errorNo", 1);
}
return rtnJson;
}
}
\ No newline at end of file
package com.cftech.sys.controller;
import com.cftech.accounts.service.DataSourceJobThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.XmlWebApplicationContext;
/**
* @author zhuxiaomeng
* @date 2018/1/6.
* @email 154040976@qq.com
* <p>
* 通过监听,开辟线程,执行定时任务 当然 也可以执行其他
*/
@Component
@Slf4j
public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent applicationEvent) {
if(applicationEvent.getApplicationContext().getParent() == null)
{
//只在初始化“根上下文”的时候执行
if (applicationEvent.getSource() instanceof XmlWebApplicationContext) {
if (((XmlWebApplicationContext) applicationEvent.getSource()).getDisplayName().equals("Root WebApplicationContext")) {
log.info("-------------bean初始化完毕-------------");
/**
* 通过线程开启数据库中已经开启的定时任务 灵感来自spring
* spring boot继续执行 mythread开辟线程,延迟后执行
*/
DataSourceJobThread myThread = (DataSourceJobThread) applicationEvent.getApplicationContext().getBean(
"dataSourceJobThread");
myThread.start();
}
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>activity-modules</artifactId>
<groupId>com.cftech</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>activity-core-module</artifactId>
</project>
\ No newline at end of file
package com.cftech.module.activity.core.dao;
import com.cftech.core.generic.GenericDao;
import com.cftech.module.activity.core.model.ActivityBaseResultDto;
import com.cftech.module.activity.core.model.ActivityBaseResultEntity;
import java.util.List;
import java.util.Map;
/**
* Created by liuling on 2017/4/19.
*/
public interface ActivityBaseResultMapper extends GenericDao<ActivityBaseResultEntity> {
void prizeLog(Map<String, Object> map);
/**
* 导出
*
* @param params
* @return
*/
List<ActivityBaseResultDto> fetchSearchByPageExport(Map<String, Object> params);
List<ActivityBaseResultEntity> selectmywin(Map<String, Object> params);
}
package com.cftech.module.activity.core.enums;
/**
* Created by liuling on 2017/4/18.
* <pre>
* 1.PERSONNUM
* 按人数算概率,以人数和奖品作为概率计算依据,实际就是算出,第几位是什么奖品
* 2.NORMAL
* 一般概率算法,以0-1算随机数及,概率落点 譬如0.4 那出现的随机数如果在0.4以内,则中奖
* 3.TIMELINE
* 时间分布算法,按开始时间至结束时间的区间,以奖品数量做均分,然后以时间顺序依次发奖
* </pre>
*/
public enum ProbabilityMethod {
PERSONNUM, NORMAL, TIMELINE
}
package com.cftech.module.activity.core.model;
import com.cftech.core.generic.GenericEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* Created by liuling on 2017/4/19.
* 活动访问记录的基础类
* 记录时间直接用createtime
*/
@Data
@NoArgsConstructor
@ToString
public class ActivityBaseLogEntity extends GenericEntity {
/**
* 所属的账号
*/
private Long accountsId;
//属于哪个活动,直接从className取值
private String from;
//活动的Id
private Long activityId;
//活动名称
private String title;
//访问的openId
private String openId;
}
package com.cftech.module.activity.core.service;
import com.alibaba.fastjson.JSONObject;
import com.cftech.core.generic.GenericService;
/**
* Created by liuling on 2017/4/18.
* 活动基础的Service类
*/
public interface ActivityBaseService<T> extends GenericService<T> {
//开始活动
boolean startActivity(T t);
//玩一次
JSONObject play(String openId, T t);
//结束活动
void endActivity(T t);
}
This diff is collapsed.
This diff is collapsed.
package com.cftech.activity.eggs.dao;
import com.cftech.activity.eggs.model.Eggs;
import com.cftech.core.generic.GenericDao;
/**
* 砸金蛋活动Mapper
*
* @author wuxf
* @date: 2017-04-27
*/
public interface EggsMapper extends GenericDao<Eggs> {
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment