Commit 5a47a71c by manxiaoqiang

大后台token改为redis存储

parent d474f3bd
......@@ -15,10 +15,11 @@ import security.RedisLoginStatusManager;
import security.TokenManager;
import security.annotation.CurrentAccount;
import util.CipherUtil;
import util.ResultModel;
import security.interceptor.AuthorizationInterceptor;
import util.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
......@@ -73,10 +74,25 @@ public class LoginController {
}
@RequestMapping(value = "logout", method = RequestMethod.GET)
@ResponseBody
public ResultModel logout(HttpServletResponse response, @CurrentAccount User user ) {
System.out.println(user);
public ResultModel logout(HttpServletRequest request, HttpServletResponse response, @CurrentAccount User user ) {
if (user != null) {
Cookie cookie = new Cookie("TOKEN", user.getId().toString());
String token = request.getHeader("Authorization");
if(!ValidateUtil.isValid(token)){
Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("TOKEN")) {
token = cookie.getValue();
}
}
}
}
//删除session,token
request.getSession().removeAttribute(Constant.CURRENT_ACCOUNT);
tokenManager.delRelationshipByToken(token);
redisLoginStatusManager.deleteLoginStatus(token);
Cookie cookie = new Cookie("TOKEN", null);
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
......
......@@ -15,8 +15,11 @@ public class BackVisit {
private String email;
private String platform;
private Long visitTime;
private String visitDesc;
private Long user;
private Date visitDate;
private String ds;
private String userName;
@Id
@GeneratedValue
......@@ -76,6 +79,30 @@ public class BackVisit {
this.visitDate = visitDate;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getVisitDesc() {
return visitDesc;
}
public void setVisitDesc(String visitDesc) {
this.visitDesc = visitDesc;
}
@Override
public String toString() {
return "BackVisit{" +
......
......@@ -18,6 +18,8 @@ public class Payment {
private Long money;
private Long user;
private Date payDate;
private String ds;
private String userName;
@Id
@GeneratedValue
......@@ -84,4 +86,20 @@ public class Payment {
public void setPayDate(Date payDate) {
this.payDate = payDate;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
......@@ -16,7 +16,9 @@ public class Reminder {
private String platform;
private Boolean remindStatus;
private Long user;
private String userName;
private Date modifyTime;
private String ds;
@Id
@GeneratedValue
......@@ -75,4 +77,20 @@ public class Reminder {
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
......@@ -3,6 +3,7 @@ package common.repository;
import common.model.Auth;
import common.model.BackVisit;
import common.model.KeyValue;
import common.model.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
......@@ -15,4 +16,7 @@ public interface BackVisitRepository extends JpaRepository<BackVisit, Long> {
@Query(value = "SELECT * from back_visit", nativeQuery = true)
List<BackVisit> findAllCount();
@Query(value = "select * from back_visit where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<BackVisit> findAll(Long accountId, String startDate, String endDate, String platform);
}
package common.repository;
import common.model.Auth;
import common.model.BackVisit;
import common.model.Payment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface PaymentRepository extends JpaRepository<Payment, Long> {
@Query(value = "select * from payment where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<Payment> findAll(Long accountId, String startDate, String endDate, String platform);
}
......@@ -3,9 +3,15 @@ package common.repository;
import common.model.Auth;
import common.model.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface ReminderRepository extends JpaRepository<Reminder, Long> {
@Query(value = "select * from reminder where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<Reminder> findAll(Long accountId, String startDate, String endDate, String platform);
}
......@@ -30,69 +30,79 @@ public class TkioAccountController {
}
//关闭到期提醒
@RequestMapping(value = "/forbiden/", method = RequestMethod.PUT)
@RequestMapping(value = "/forbiden", method = RequestMethod.PUT)
@ResponseBody
public ResultModel forbiden(@CurrentAccount User loginAccount, @RequestBody Reminder resource) {
tkioAccountService.forbiden(loginAccount, resource);
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.forbiden(loginAccount, resource));
}
//开启到期提醒
@RequestMapping(value = "/enable/", method = RequestMethod.PUT)
@RequestMapping(value = "/enable", method = RequestMethod.PUT)
@ResponseBody
public ResultModel enable(@CurrentAccount User loginAccount, @RequestBody Reminder resource) {
tkioAccountService.enable(loginAccount, resource);
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.enable(loginAccount, resource));
}
//缴费
@RequestMapping(value = "/pay/", method = RequestMethod.PUT)
@RequestMapping(value = "/pay", method = RequestMethod.PUT)
@ResponseBody
public ResultModel pay(@CurrentAccount User loginAccount, @RequestBody Payment resource) {
tkioAccountService.pay(loginAccount, resource);
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.pay(loginAccount, resource));
}
//回访
@RequestMapping(value = "/visit/", method = RequestMethod.PUT)
@RequestMapping(value = "/visit", method = RequestMethod.PUT)
@ResponseBody
public ResultModel visit(@CurrentAccount User loginAccount, @RequestBody BackVisit resource) {
tkioAccountService.visit(loginAccount, resource);
return ResultModel.OK();
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
return ResultModel.OK( tkioAccountService.visit(loginAccount, resource));
}
//功能使用查询
@RequestMapping(value = "/find/function/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel updateName(@CurrentAccount User loginAccount, @RequestParam String name, @PathVariable Long id) {
public ResultModel updateName(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.findFunTimes(accountId,startDate,endDate));
}
@RequestMapping(value = "/update/{id}/pwd", method = RequestMethod.PUT)
//功能使用查询
@RequestMapping(value = "/find/pv/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel updatePwd(@CurrentAccount User loginAccount, @RequestParam String pwd, @PathVariable Long id) {
public ResultModel pv(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.findPv(accountId,startDate,endDate));
}
@RequestMapping(value = "/update/pwd", method = RequestMethod.PUT)
//到期提醒查询
@RequestMapping(value = "/find/reminder/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel updatePwd(@RequestParam String email, @RequestParam String pwd) {
public ResultModel findRed(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.findRed(accountId,startDate,endDate));
}
@RequestMapping(value = "forget/", method = RequestMethod.GET)
//回访查询
@RequestMapping(value = "/find/visit/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel sengCode(@RequestParam String email) {
public ResultModel findVisit(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.findVisit(accountId,startDate,endDate));
}
@RequestMapping(value = "valid/code", method = RequestMethod.GET)
//缴费查询
@RequestMapping(value = "/find/pay/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel validCode(@RequestParam String email, @RequestParam String code) {
public ResultModel findPay(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK();
return ResultModel.OK(tkioAccountService.findPay(accountId,startDate,endDate));
}
}
package tkio.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
@Entity
public class Campaign
{
private Long id;
private Long app;
private String os;
private String type;
private Long channel;
private String channelCategory;
private String channelType;
private String campaignid;
private String name;
private String callback;
private String url;
private String surl;
private Integer addParam;
private String campaignpackid;
private String specialKeys;
private String advertiserid;
private String bundleid;
private Boolean awssuccess = false;
private Date createTime;
private Long createAccount;
private Date modifyTime;
private Long modifyAccount;
private Boolean delFlag = false;
private Long account;
private String holderids;
private String pack_channelid;
private int batchNumber;
private int startNumber;
private String campaignName;
@Transient
public int getStartNumber() {
return startNumber;
}
public void setStartNumber(int startNumber) {
this.startNumber = startNumber;
}
@Transient
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
@Transient
public int getBatchNumber()
{
return batchNumber;
}
public void setBatchNumber(int batchNumber)
{
this.batchNumber = batchNumber;
}
@Transient
public String getHolderids()
{
return holderids;
}
public void setHolderids(String holderids)
{
this.holderids = holderids;
}
public Long getAccount()
{
return account;
}
public void setAccount(Long account)
{
this.account = account;
}
public Campaign()
{
super();
}
public Campaign(String campaignid, String name)
{
this.campaignid = campaignid;
this.name = name;
}
public Long getApp()
{
return app;
}
public String getCallback()
{
return callback;
}
/* public Long getCampaignGroup() {
return campaignGroup;
}*/
public Long getChannel()
{
return channel;
}
@Id
@GeneratedValue
public Long getId()
{
return id;
}
public String getName()
{
return name;
}
public String getSurl()
{
return surl;
}
public String getType()
{
return type;
}
public String getUrl()
{
return url;
}
public void setApp(Long app)
{
this.app = app;
}
public void setCallback(String callback)
{
this.callback = callback;
}
/* public void setCampaignGroup(Long campaignGroup) {
this.campaignGroup = campaignGroup;
}*/
public void setChannel(Long channel)
{
this.channel = channel;
}
public String getChannelCategory()
{
return channelCategory;
}
public void setChannelCategory(String channelCategory)
{
this.channelCategory = channelCategory;
}
public String getChannelType()
{
return channelType;
}
public void setChannelType(String channelType)
{
this.channelType = channelType;
}
public void setId(Long id)
{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
public void setSurl(String surl)
{
this.surl = surl;
}
public void setType(String type)
{
this.type = type;
}
public void setUrl(String url)
{
this.url = url;
}
public String getSpecialKeys()
{
return specialKeys;
}
public void setSpecialKeys(String specialKeys)
{
this.specialKeys = specialKeys;
}
public Integer getAddParam()
{
return addParam;
}
public void setAddParam(Integer addParam)
{
this.addParam = addParam;
}
public String getOs()
{
return os;
}
public void setOs(String os)
{
this.os = os;
}
public boolean isAwssuccess()
{
return awssuccess;
}
public void setAwssuccess(boolean awssuccess)
{
this.awssuccess = awssuccess;
}
public String getCampaignpackid()
{
return campaignpackid;
}
public void setCampaignpackid(String campaignpackid)
{
this.campaignpackid = campaignpackid;
}
public String getAdvertiserid()
{
return advertiserid;
}
public void setAdvertiserid(String advertiserid)
{
this.advertiserid = advertiserid;
}
public String getBundleid()
{
return bundleid;
}
public void setBundleid(String bundleid)
{
this.bundleid = bundleid;
}
public Date getCreateTime()
{
return createTime;
}
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
public Date getModifyTime()
{
return modifyTime;
}
public void setModifyTime(Date modifyTime)
{
this.modifyTime = modifyTime;
}
public Boolean getDelFlag()
{
return delFlag;
}
public void setDelFlag(Boolean delFlag)
{
this.delFlag = delFlag;
}
public String getCampaignid()
{
return campaignid;
}
public void setCampaignid(String campaignid)
{
this.campaignid = campaignid;
}
public Long getCreateAccount()
{
return createAccount;
}
public void setCreateAccount(Long createAccount)
{
this.createAccount = createAccount;
}
public Long getModifyAccount()
{
return modifyAccount;
}
public void setModifyAccount(Long modifyAccount)
{
this.modifyAccount = modifyAccount;
}
public String getPack_channelid()
{
return pack_channelid;
}
public void setPack_channelid(String pack_channelid)
{
this.pack_channelid = pack_channelid;
}
public Boolean getAwssuccess()
{
return awssuccess;
}
public void setAwssuccess(Boolean awssuccess)
{
this.awssuccess = awssuccess;
}
@Override
public String toString()
{
return "Campaign{" +
"id=" + id +
", app=" + app +
", os='" + os + '\'' +
", type='" + type + '\'' +
", channel=" + channel +
", channelCategory='" + channelCategory + '\'' +
", channelType='" + channelType + '\'' +
", campaignid='" + campaignid + '\'' +
", name='" + name + '\'' +
", callback='" + callback + '\'' +
", url='" + url + '\'' +
", surl='" + surl + '\'' +
", addParam=" + addParam +
", campaignpackid='" + campaignpackid + '\'' +
", specialKeys='" + specialKeys + '\'' +
", advertiserid='" + advertiserid + '\'' +
", bundleid='" + bundleid + '\'' +
", awssuccess=" + awssuccess +
", createTime=" + createTime +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
", modifyAccount=" + modifyAccount +
", delFlag=" + delFlag +
", account=" + account +
", holderids='" + holderids + '\'' +
", pack_channelid='" + pack_channelid + '\'' +
", batchNumber=" + batchNumber +
'}';
}
}
package tkio.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class Channel {
private Long id;
private String name;
private String category;
private Long account;
private String url;
private String type;
private String uniqueName;
private String firstchar;
private boolean ishttps=false;
private Boolean osAndroid;
private Boolean osIos;
private Boolean osWeb;
private String trackurl;
private String androidparam;
private String iosparam;
private boolean istrackurlspecial=false;
private Date createTime;
private Long createAccount;
private Date modifyTime;
private Long modifyAccount;
private Boolean delFlag;
private String specialParams;
private String nodeUrl;
public String getNodeUrl() {
return nodeUrl;
}
public void setNodeUrl(String nodeUrl) {
this.nodeUrl = nodeUrl;
}
private boolean isintegrate = false;
private Integer iscostrecovery; //0:没对接,1:API,2:爬虫。
private Integer orderindex;
//0 正常渠道 1 被合并渠道,不再显示
private Boolean isNotShow;
//0 正常渠道 1 未覆盖中国,不再显示 例如:Search Ads
private Boolean isNotCover;
public Channel() {
super();
}
public Channel(String name, String category, String url) {
super();
this.name = name;
this.category = category;
this.url = url;
}
public Channel(Long channelId, String name){
super();
this.id = channelId;
this.name = name;
}
public String getCategory() {
return category;
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public void setCategory(String category) {
this.category = category;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setUrl(String url) {
this.url = url;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUniqueName() {
return uniqueName;
}
public void setUniqueName(String uniqueName) {
this.uniqueName = uniqueName;
}
public String getFirstchar() {
return firstchar;
}
public void setFirstchar(String firstchar) {
this.firstchar = firstchar;
}
public boolean isIshttps() {
return ishttps;
}
public void setIshttps(boolean ishttps) {
this.ishttps = ishttps;
}
public Boolean getOsAndroid() {
return osAndroid;
}
public void setOsAndroid(Boolean osAndroid) {
this.osAndroid = osAndroid;
}
public Boolean getOsIos() {
return osIos;
}
public void setOsIos(Boolean osIos) {
this.osIos = osIos;
}
public Boolean getOsWeb() {
return osWeb;
}
public void setOsWeb(Boolean osWeb) {
this.osWeb = osWeb;
}
public String getTrackurl() {
return trackurl;
}
public void setTrackurl(String trackurl) {
this.trackurl = trackurl;
}
public String getAndroidparam() {
return androidparam;
}
public void setAndroidparam(String androidparam) {
this.androidparam = androidparam;
}
public String getIosparam() {
return iosparam;
}
public void setIosparam(String iosparam) {
this.iosparam = iosparam;
}
public boolean isIstrackurlspecial() {
return istrackurlspecial;
}
public void setIstrackurlspecial(boolean istrackurlspecial) {
this.istrackurlspecial = istrackurlspecial;
}
public boolean isIsintegrate() {
return isintegrate;
}
public void setIsintegrate(boolean isintegrate) {
this.isintegrate = isintegrate;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
public Long getCreateAccount() {
return createAccount;
}
public void setCreateAccount(Long createAccount) {
this.createAccount = createAccount;
}
public Long getModifyAccount() {
return modifyAccount;
}
public void setModifyAccount(Long modifyAccount) {
this.modifyAccount = modifyAccount;
}
public Long getAccount() {
return account;
}
public void setAccount(Long account) {
this.account = account;
}
public String getSpecialParams() {
return specialParams;
}
public void setSpecialParams(String specialParams) {
this.specialParams = specialParams;
}
public Integer getIscostrecovery() {
return iscostrecovery;
}
public void setIscostrecovery(Integer iscostrecovery) {
this.iscostrecovery = iscostrecovery;
}
public Integer getOrderindex()
{
return orderindex;
}
public void setOrderindex(Integer orderindex)
{
this.orderindex = orderindex;
}
public Boolean getNotShow() {
return isNotShow;
}
public void setNotShow(Boolean notShow) {
isNotShow = notShow;
}
public Boolean getNotCover() {
return isNotCover;
}
public void setNotCover(Boolean notCover) {
isNotCover = notCover;
}
}
......@@ -25,4 +25,9 @@ public interface AccountRepository extends JpaRepository<Account, Long> {
@Query(value = "SELECT * from account where is_super_user is true and bussinessman = ?1", nativeQuery = true)
List<Account> findBussnissMan(List<Integer> bussinussIds);
@Query(value = "select * from account where root_parent = ?1", nativeQuery = true)
List<Account> findByRootParent(Long accountId);
@Query(value = "select count(*) from account where root_parent = ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByRootParent(Long accountId, String startDate, String endDate);
}
......@@ -5,63 +5,17 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import tkio.model.App;
import java.math.BigInteger;
import java.util.List;
public interface AppRepository extends JpaRepository<App, Long> {
@Query(value = "select * from app where account in (select id from account where parent = ?1 or id = ?1) and del_flag is not true", nativeQuery = true)
List<App> listAppByRootAccount(Long account);
@Query(value="select appkey from app where id = ?1",nativeQuery=true)
String findAppkeyById(Long id);
List<App> findByAccount(Long account);
@Query(value = "select * from app where account =?1 and bundleid = ?2 and del_flag is not true", nativeQuery = true)
App findByBundleidInNotDel(Long account, String bundleid);
@Query(value = "select * from app where account =?1 and name = ?2 and del_flag is not true", nativeQuery = true)
App findByNameNotDel(Long account, String name);
@Query(value = "select count(*) from app where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
@Query(value = "select * from app where sync_ddb is false and del_flag is not true", nativeQuery = true)
List<App> findNotSyncAppDebug();
@Query(value = "select * from app where token = ?1 limit 1", nativeQuery = true)
App findOneByAppToken(String token);
@Query(value = "select * from app where id in ?1", nativeQuery = true)
List<App> findByIds(List<Long> ids);
@Query(value = "SELECT DISTINCT t2.* FROM campaign t0 JOIN channel t1 ON t0.channel = t1.id JOIN app t2 ON t0.app = t2.id WHERE t0.del_flag is not true and (t1.type!='ry_coop' or t1.type is NULL) and t1.category = 'ADVERTISING' and t2.id in ?1 and t2.platform = ?2 and t2.del_flag is not TRUE" , nativeQuery = true)
List<App> findAppsFromOnelink(List<Long> appids, String platform);
@Query(value = "SELECT DISTINCT t2.* FROM campaign t0 JOIN channel t1 ON t0.channel = t1.id JOIN app t2 ON t0.app = t2.id WHERE t0.del_flag is not true and (t1.type!='ry_coop' or t1.type is NULL) and t1.category = 'ADVERTISING' and t2.id = ?1" , nativeQuery = true)
App findAppFromOnelink(Long appid);
@Query(value = "select * from app where appkey in ?1", nativeQuery = true)
List<App> findByAppkeys(List<String> appkeys);
@Query(value = "select * from app a join auth b on a.id = b.app where b.account = ?1 and b.create_account in (select id from account where root_parent = ?2) ", nativeQuery = true)
List<App> findAuthAppByRootParent(Long subAccountId, Long rootParent);
@Query(value = "select * from app a join auth b on a.id = b.app where b.account = ?1 ", nativeQuery = true)
List<App> findAuthApp(Long subAccountId);
@Query(value="select platform from app where id = ?1",nativeQuery=true)
String findPlatformByAppId(Long appId);
@Query(value="select categoryname from category where categoryid=(select game_genre from app where id=?1);",nativeQuery=true)
String findGameCategoryByAppID(Long appId);
@Query(value="select categoryname from category where categoryid=(select app_genre from app where id=?1);",nativeQuery=true)
String findAppGenreNameByAppID(Long id);
@Query(value = "select DISTINCT a.* from app a right join data_auth d on a.id = d.app where d.account = ?1 and d.app in ?2 and d.channel = ?3 and (d.all_campaign is true or d.channel_permit is true)", nativeQuery = true)
List<App> listTotalAuthorizedApp(Long accountId, List<Long> appIdList, Long channelId);
@Query(value = "select create_account from app where appkey=?1", nativeQuery = true)
String findCreateAccountByAppkey(String appKey);
@Query(value = "select DISTINCT a.* from app a right join data_auth d on a.id = d.app where d.account = ?1 and d.channel = ?2 and (d.all_campaign is true or d.channel_permit is true)", nativeQuery = true)
List<App> listApps(Long accountId, Long channelId);
@Query(value = "select appkey from app where account in ?1", nativeQuery = true)
List<String> findAppkeys(List<Long> accountId);
}
package tkio.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Campaign;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface CampaignRepository extends JpaRepository<Campaign, Long> {
Iterable<Campaign> findByApp(Long id);
@Query(value = "select count(*) from campaign where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
}
package tkio.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Channel;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface ChannelRepository extends JpaRepository<Channel, Long> {
@Query(value = "select count(*) from channel where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
}
......@@ -3,6 +3,7 @@ package tkio.service;
import common.model.*;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2017/12/26.
......@@ -22,4 +23,16 @@ public interface TkioAccountService {
//回访
BackVisit visit(User user, BackVisit resource);
//查询功能使用情况
Map<String, Integer> findFunTimes(Long account, String startDate, String endDate);
//查询功能使用情况
List<Map<String, Object>> findPv(Long account, String startDate, String endDate);
List<Reminder> findRed(Long account, String startDate, String endDate);
List<BackVisit> findVisit(Long account, String startDate, String endDate);
List<Payment> findPay(Long account, String startDate, String endDate);
}
......@@ -5,15 +5,25 @@ import common.model.*;
import common.repository.*;
import dic.RoleEnum;
import dic.RoleTypeEnum;
import org.apache.commons.collections.map.AbstractMapDecorator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tkio.model.Account;
import tkio.model.SalesManLeader;
import tkio.repository.AccountRepository;
import tkio.repository.SalesManLeaderRepository;
import tkio.repository.*;
import tkio.service.AccountFlowRestrictService;
import tkio.service.TkioAccountService;
import util.Constant;
import util.DateUtil;
import util.HttpClientUtil;
import util.ValidateUtil;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
/**
......@@ -22,23 +32,31 @@ import java.util.*;
@Service
public class TkioAccountServiceImpl implements TkioAccountService {
//查询URI
private final static String URI_REPORT_BY_SQL = "/api/trackingio/bysql";
@Autowired
Account4WebRepository account4WebRepository;
@Autowired
SalesManLeaderRepository salesManLeaderRepository;
@Autowired
AccountRepository accountRepository;
@Autowired
BackVisitRepository backVisitRepository;
@Autowired
PaymentRepository paymentRepository;
@Autowired
ReminderRepository reminderRepository;
@Autowired
CampaignRepository campaignRepository;
@Autowired
ChannelRepository channelRepository;
@Autowired
AppRepository appRepository;
@Autowired
AccountFlowRestrictService accountFlowRestrictService;
@Autowired
UserRepository userRepository;
@Override
public List<Account4Web> findAll(User user) {
......@@ -96,6 +114,7 @@ public class TkioAccountServiceImpl implements TkioAccountService {
resource.setModifyTime(new Date());
resource.setPlatform("tkio");
resource.setRemindStatus(false);
resource.setDs(DateUtil.getBeforeDays(0));
return reminderRepository.save(resource);
}
......@@ -105,6 +124,7 @@ public class TkioAccountServiceImpl implements TkioAccountService {
resource.setModifyTime(new Date());
resource.setPlatform("tkio");
resource.setRemindStatus(true);
resource.setDs(DateUtil.getBeforeDays(0));
return reminderRepository.save(resource);
}
......@@ -112,6 +132,7 @@ public class TkioAccountServiceImpl implements TkioAccountService {
public Payment pay(User user, Payment resource) {
resource.setUser(user.getId());
resource.setPayDate(new Date());
resource.setDs(DateUtil.getBeforeDays(0));
return paymentRepository.save(resource);
}
......@@ -119,9 +140,136 @@ public class TkioAccountServiceImpl implements TkioAccountService {
public BackVisit visit(User user, BackVisit resource) {
resource.setUser(user.getId());
resource.setVisitDate(new Date());
resource.setDs(DateUtil.getBeforeDays(0));
return backVisitRepository.save(resource);
}
@Override
public Map<String, Integer> findFunTimes(Long account, String startDate, String endDate) {
Map<String, Integer> result = new HashMap<>();
List<Account> accountList = accountRepository.findByRootParent(account);
List<Long> idList = new ArrayList<>();
for(Account ac : accountList){
idList.add(ac.getId());
}
List<String> appkeys = appRepository.findAppkeys(idList);
String appkeyStr = String.join("','", appkeys);
BigInteger numAccount = accountRepository.countByRootParent(account, startDate, endDate);
BigInteger numApp = appRepository.countByAccount(idList, startDate, endDate);
BigInteger numCampaign = campaignRepository.countByAccount(idList, startDate, endDate);
BigInteger numChannel = channelRepository.countByAccount(idList, startDate, endDate);
BigInteger event_sum = accountFlowRestrictService.getTotalNum(startDate, endDate, "'" + appkeyStr + "'", "account_io_flow_restrict", "event_sum");
BigInteger click_sum =accountFlowRestrictService.getTotalNum(startDate, endDate, "'" + appkeyStr + "'","account_track_flow_restrict","click_sum");
result.put("numAccount", numAccount.intValue());
result.put("numApp", numApp.intValue());
result.put("numCampaign", numCampaign.intValue());
result.put("numChannel", numChannel.intValue());
result.put("event_sum", event_sum.intValue());
result.put("click_sum", click_sum.intValue());
return result;
}
@Override
public List<Map<String, Object>> findPv(Long account, String startDate, String endDate) {
List<Map<String, Object>> result = new ArrayList<>();
List<Account> accountList = accountRepository.findByRootParent(account);
List<Long> idList = new ArrayList<>();
for(Account ac : accountList){
idList.add(ac.getId());
}
List<String> appkeys = appRepository.findAppkeys(idList);
String appkeyStr = String.join("','", appkeys);
String querySql = "select menu, count(*) as pv, count(distinct(xwho)) as uv, count(*)/count(distinct(xwho)) as puv " +
"from tkio_bigtable_view.event_f0f251af10e66a0c94d2e923d8863105 where user_appkey in ('" + appkeyStr + "') " +
"AND ds >= '" + startDate + "' AND ds <= '" + endDate + "' group by menu;";
String url = Constant.reportUrl + URI_REPORT_BY_SQL;
Map<String, String> conditions = new HashMap<>();
conditions.put("sql", querySql);
conditions.put("dbtype", "presto");
conditions.put("datatype", "list");
conditions.put("iscache", "0");
String responseJson = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
if(responseJson.contains("val")){
try {
JSONObject jsonObject = new JSONObject(responseJson);
JSONArray valArr = jsonObject.getJSONArray("val");
if(null != valArr && valArr.length() > 0){
for(int i = 0; i < valArr.length(); i++){
JSONObject val = valArr.getJSONObject(i);
Map<String, Object> map = new HashMap<>();
map.put("menu", val.getString("menu"));
map.put("pv", val.getInt("pv"));
map.put("uv", val.getInt("uv"));
map.put("puv", val.getInt("puv"));
result.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return result;
}
@Override
public List<Reminder> findRed(Long account, String startDate, String endDate) {
List<Reminder> result = new ArrayList<>();
List<User> userList = userRepository.findAll();
Map<Long, String> userMap = new HashMap<>();
for(User u : userList){
userMap.put(u.getId(), u.getName());
}
List<Reminder> list = reminderRepository.findAll(account, startDate, endDate, "tkio");
if (ValidateUtil.isValid(list)) {
for(Reminder re : list){
re.setUserName(userMap.get(re.getUser()));
result.add(re);
}
}
return result;
}
@Override
public List<BackVisit> findVisit(Long account, String startDate, String endDate) {
List<BackVisit> result = new ArrayList<>();
List<User> userList = userRepository.findAll();
Map<Long, String> userMap = new HashMap<>();
for(User u : userList){
userMap.put(u.getId(), u.getName());
}
List<BackVisit> list = backVisitRepository.findAll(account, startDate, endDate, "tkio");
if (ValidateUtil.isValid(list)) {
for(BackVisit re : list){
re.setUserName(userMap.get(re.getUser()));
result.add(re);
}
}
return result;
}
@Override
public List<Payment> findPay(Long account, String startDate, String endDate) {
List<Payment> result = new ArrayList<>();
List<User> userList = userRepository.findAll();
Map<Long, String> userMap = new HashMap<>();
for(User u : userList){
userMap.put(u.getId(), u.getName());
}
List<Payment> list = paymentRepository.findAll(account, startDate, endDate, "tkio");
if (ValidateUtil.isValid(list)) {
for(Payment re : list){
re.setUserName(userMap.get(re.getUser()));
result.add(re);
}
}
return result;
}
public Map<String, Integer> getBackTime(){
......
......@@ -89,7 +89,8 @@ public class AccountTask {
account4Web.setTrack("----");
account4Web.setIoStatus(false);
account4Web.setTrackStatus(false);
account4Web.setUser(ac.getBussinessman().toString());
account4Web.setUser(ac.getName());
account4Web.setTell(ac.getPhone());
list.add(account4Web);
}
}
......
......@@ -14,6 +14,6 @@
<task:scheduled-tasks>
<!--//定时同步短链数据(每5分钟执行一次)-->
<task:scheduled ref="tkioAccountTask" method="task" cron="0 32 19 * * ?"/>
<task:scheduled ref="tkioAccountTask" method="task" cron="0 26 10 * * ?"/>
</task:scheduled-tasks>
</beans>
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