Commit e2bf0dab by carrieyzzhang

Merge branch 'master' of git.minrow.com:reyun/saasio

parents c0488e0a 953fa23a
package com.reyun.controller;
import com.reyun.service.IDicService;
import com.reyun.util.ResultModel;
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;
/**
* description:
*
* @author nolan
* @date 25/12/2017
*/
@Controller
@RequestMapping("dic")
public class DicController
{
@Autowired
private IDicService iDicService;
@RequestMapping(value = "findbycampaign", method = RequestMethod.GET)
@ResponseBody
public ResultModel findDicsByCampaign() {
return ResultModel.OK(iDicService.findByCampaign());
}
}
package com.reyun.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
@Entity
public class App {
......@@ -21,7 +31,7 @@ public class App {
private String appkey;
private String url;
private Long account;
// private boolean sync;
private boolean sync;
// private boolean isActive;
private Long origiApp;
private String bundleid;
......@@ -35,17 +45,22 @@ public class App {
private String modifyAccount;
private Boolean delFlag;
//是否同步DDB
// private Boolean syncDdb;
private Boolean syncDdb;
private Long installNum;
private Long registerNum;
//是够是debug模式 true 是测试,false不是测试
private Boolean isDebug;
private Boolean ioExhaust;
private Boolean trackAndIoBothExhaust;
private Boolean mainAccountExpire;
private Boolean distributeTask;
private Date distributeTime;
private String tagType;
private List<AppTag> appTagList;
public App() {
super();
......@@ -59,7 +74,7 @@ public class App {
}
public App(String name, String platform, String appGenre, String gameGenre,
Long account) {
Long account) {
this.name = name;
this.platform = platform;
this.appGenre = appGenre;
......@@ -125,6 +140,9 @@ public class App {
return url;
}
public boolean isSync() {
return sync;
}
public void setAccount(Long account) {
this.account = account;
......@@ -154,6 +172,10 @@ public class App {
this.platform = platform;
}
public void setSync(boolean sync) {
this.sync = sync;
}
public void setUrl(String url) {
this.url = url;
}
......@@ -246,16 +268,21 @@ public class App {
this.isDebug = isDebug;
}
public Boolean getSyncDdb() {
return syncDdb;
}
public void setSyncDdb(Boolean syncDdb) {
this.syncDdb = syncDdb;
}
@Transient
public Boolean getIoExhaust()
{
return ioExhaust;
public Boolean getTrackAndIoBothExhaust() {
return trackAndIoBothExhaust;
}
public void setIoExhaust(Boolean ioExhaust)
{
this.ioExhaust = ioExhaust;
public void setTrackAndIoBothExhaust(Boolean trackAndIoBothExhaust) {
this.trackAndIoBothExhaust = trackAndIoBothExhaust;
}
@Transient
......@@ -285,12 +312,54 @@ public class App {
this.registerNum = registerNum;
}
@Override
public Boolean getDebug() {
return isDebug;
}
public void setDebug(Boolean debug) {
isDebug = debug;
}
public Boolean getDistributeTask() {
return distributeTask;
}
public void setDistributeTask(Boolean distributeTask) {
this.distributeTask = distributeTask;
}
public Date getDistributeTime() {
return distributeTime;
}
public void setDistributeTime(Date distributeTime) {
this.distributeTime = distributeTime;
}
@OneToMany(targetEntity = AppTag.class,fetch = FetchType.EAGER, cascade = CascadeType.DETACH)
@JoinColumn(name = "app", referencedColumnName = "id", insertable = false, updatable = false)
public List<AppTag> getAppTagList() {
return appTagList;
}
public void setAppTagList(List<AppTag> appTagList) {
this.appTagList = appTagList;
}
public String getTagType() {
return tagType;
}
public void setTagType(String tagType) {
this.tagType = tagType;
}
@Override
public String toString() {
return "App [id=" + id + ", name=" + name + ", platform=" + platform
+ ", appGenre=" + appGenre + ", gameGenre=" + gameGenre
+ ", appkey=" + appkey + ", url=" + url + ", account="
+ account + ", origiApp=" + origiApp
+ account + ", sync=" + sync + ", origiApp=" + origiApp
+ ", bundleid=" + bundleid + ", token=" + token
+ ", installtoken=" + installtoken + ", regedbutton="
+ regedbutton + ", createTime=" + createTime
......
package com.reyun.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* description:
*
* @author nolan
* @date 26/12/2017
*/
@Entity
public class AppTag implements java.io.Serializable{
private Long id;
private Long app;
private String tagId;
private String tagName;
private String parentTagId;
private String parentTagName;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getApp() {
return app;
}
public void setApp(Long app) {
this.app = app;
}
public String getTagId() {
return tagId;
}
public void setTagId(String tagId) {
this.tagId = tagId;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
public String getParentTagId() {
return parentTagId;
}
public void setParentTagId(String parentTagId) {
this.parentTagId = parentTagId;
}
public String getParentTagName() {
return parentTagName;
}
public void setParentTagName(String parentTagName) {
this.parentTagName = parentTagName;
}
}
package com.reyun.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* description:
*
* @author nolan
* @date 25/12/2017
*/
@Entity
@IdClass(SyDicItemPK.class)
public class SyDicItem
{
@NotNull
@Id
private String itemCode;
@NotNull
private String itemValue;
@NotNull
private Integer itemOrder;
@NotNull
private Integer itemLevel;
private String itemPid;
@NotNull
@Id
private String dicCode;
@Transient
private List<SyDicItem> child;
public String getItemCode() {
return itemCode;
}
public void setItemCode(String itemCode) {
this.itemCode = itemCode;
}
public String getItemValue() {
return itemValue;
}
public void setItemValue(String itemValue) {
this.itemValue = itemValue;
}
public Integer getItemOrder() {
return itemOrder;
}
public void setItemOrder(Integer itemOrder) {
this.itemOrder = itemOrder;
}
public Integer getItemLevel() {
return itemLevel;
}
public void setItemLevel(Integer itemLevel) {
this.itemLevel = itemLevel;
}
public String getItemPid() {
return itemPid;
}
public void setItemPid(String itemPid) {
this.itemPid = itemPid;
}
public String getDicCode() {
return dicCode;
}
public void setDicCode(String dicCode) {
this.dicCode = dicCode;
}
public List<SyDicItem> getChild() {
return child;
}
public void setChild(List<SyDicItem> child) {
this.child = child;
}
}
package com.reyun.repository;
import java.util.List;
import com.reyun.model.App;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.reyun.model.App;
import java.util.List;
public interface AppRepository extends JpaRepository<App, Long> {
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);
......@@ -18,10 +18,13 @@ public interface AppRepository extends JpaRepository<App, Long> {
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);
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);
App findByNameNotDel(Long account, String name);
@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);
......@@ -29,6 +32,12 @@ public interface AppRepository extends JpaRepository<App, Long> {
@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);
......@@ -53,4 +62,6 @@ public interface AppRepository extends JpaRepository<App, Long> {
@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);
}
package com.reyun.repository;
import com.reyun.model.AppTag;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* description:
*
* @author nolan
* @date 26/12/2017
*/
public interface AppTagRepository extends CrudRepository<AppTag, Long>
{
List<AppTag> findByApp(Long app);
Long deleteByApp(Long app);
}
package com.reyun.repository;
import com.reyun.model.SyDicItem;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* description:
*
* @author nolan
* @date 25/12/2017
*/
public interface SyDicItemRepository
extends JpaRepository<SyDicItem, String>
{
List<SyDicItem> findByDicCodeIn(List<String> dicCodes);
List<SyDicItem> findByDicCode(String dicCode);
List<SyDicItem> findByItemCodeIn(List<String> itemCodes);
}
\ No newline at end of file
package com.reyun.service;
import com.reyun.model.AppTag;
import java.util.List;
/**
* description:
*
* @author nolan
* @date 26/12/2017
*/
public interface IAppTagService
{
/**
*
* @param app
* @return
*/
List<AppTag> findByApp(Long app);
void saveOrUpdate(Long app, List<AppTag> appTagList);
}
package com.reyun.service;
import com.reyun.model.SyDicItem;
import java.util.List;
import java.util.Map;
/**
* description:
*
* @author nolan
* @date 25/12/2017
*/
public interface IDicService
{
/**
* {
* "game": {
* itemCode: "",
* itemName: "",
* child: {
* {
* itemCode: "",
* ItemName: "",
* child: {
*
* }
* }
* }
* },
* "app": {
* ......
* },
* "test": {
* ......
* }
* }
*/
Map<String,Object> findByCampaign();
List<SyDicItem> find(List<String> tagIds) ;
}
......@@ -12,6 +12,8 @@ import com.reyun.repository.*;
import com.reyun.service.AppService;
import com.reyun.service.AuthService;
import com.reyun.service.ConfigParamService;
import com.reyun.service.IAppTagService;
import com.reyun.service.IDicService;
import com.reyun.util.CipherUtil;
import com.reyun.util.Constant;
import com.reyun.util.DateUtil;
......@@ -27,6 +29,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class AppServiceImpl implements AppService {
......@@ -49,6 +52,12 @@ public class AppServiceImpl implements AppService {
@Autowired
ConfigParamService configParamService;
@Autowired
private IDicService iDicService;
@Autowired
private IAppTagService iAppTagService;
@Override
public List<App> listAuthAppByAccount(Account account, Long subAccountId) {
......@@ -112,7 +121,10 @@ public class AppServiceImpl implements AppService {
@Override
public App findById(Long id) {
return appRepository.findOne(id);
App one = appRepository.findOne(id);
one.setAppTagList(iAppTagService.findByApp(id));
return one;
}
@Override
......@@ -141,6 +153,30 @@ public class AppServiceImpl implements AppService {
/*//同步DDB,同步APP的测试模式状态
this.syncAppDebugStatus(app);*/
if (app.getAppTagList() != null && app.getAppTagList().size() > 0) {
List<String> tagIdsList = app.getAppTagList().stream().map(AppTag::getTagId).collect(Collectors.toList());
final List<SyDicItem> subNodeList = iDicService.find(tagIdsList);
List<String> parentTagIdsList = subNodeList.stream().map(SyDicItem::getItemPid).collect(Collectors.toList());
final List<SyDicItem> parentNodeList = iDicService.find(parentTagIdsList);
Map<String, SyDicItem> dicMap = Maps.uniqueIndex(subNodeList, SyDicItem::getItemCode);
Map<String, SyDicItem> dicParentMap = Maps.uniqueIndex(parentNodeList, SyDicItem::getItemCode);
app.getAppTagList().forEach(appTag -> {
SyDicItem syDicItem = dicMap.get(appTag.getTagId());
if (syDicItem != null) {
appTag.setTagName(syDicItem.getItemValue());
appTag.setParentTagId(syDicItem.getItemPid());
if (dicParentMap.containsKey(syDicItem.getItemPid())) {
appTag.setParentTagName(dicParentMap.get(syDicItem.getItemPid()).getItemValue());
}
}
});
this.iAppTagService.saveOrUpdate(app.getId(), app.getAppTagList());
}
return app;
}
......@@ -154,6 +190,23 @@ public class AppServiceImpl implements AppService {
app.setName(resource.getName());
app.setBundleid(resource.getBundleid());
app.setUrl(resource.getUrl());
app.setAppTagList(resource.getAppTagList());
app.setTagType(resource.getTagType());
final List<AppTag> appTagList = resource.getAppTagList();
if (appTagList != null && appTagList.size() > 0) {
List<String> tagIdsList = appTagList.stream().map(AppTag::getTagId).collect(Collectors.toList());
Map<String,SyDicItem> dicMap = Maps.uniqueIndex(iDicService.find(tagIdsList), SyDicItem::getItemCode);
appTagList.forEach(appTag -> {
SyDicItem syDicItem = dicMap.get(appTag.getTagId());
if (syDicItem != null) {
appTag.setTagName(syDicItem.getItemValue());
appTag.setParentTagId(syDicItem.getItemPid());
}
});
this.iAppTagService.saveOrUpdate(resource.getId(), appTagList);
}
return appRepository.save(app);
}
......
package com.reyun.service.impl;
import com.reyun.model.AppTag;
import com.reyun.repository.AppTagRepository;
import com.reyun.service.IAppTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* description:
*
* @author nolan
* @date 26/12/2017
*/
@Service
public class AppTagServiceImpl
implements IAppTagService{
@Autowired
private AppTagRepository appTagRepository;
@Override
public List<AppTag> findByApp(Long app) {
return appTagRepository.findByApp(app);
}
@Override
public void saveOrUpdate(Long app, List<AppTag> appTagList) {
appTagRepository.deleteByApp(app);
appTagList.forEach(appTag -> {
appTag.setApp(app);
});
this.appTagRepository.save(appTagList);
}
}
package com.reyun.service.impl;
import com.beust.jcommander.internal.Maps;
import com.google.common.collect.Lists;
import com.reyun.model.SyDicItem;
import com.reyun.repository.SyDicItemRepository;
import com.reyun.service.IDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* description:
*
* @author nolan
* @date 25/12/2017
*/
@Service
public class DicServiceImpl
implements IDicService
{
private static final String DIC_GAME_CODE = "02";
private static final String DIC_APP_CODE = "04";
@Autowired
private SyDicItemRepository syDicItemRepository;
@Override
public Map<String, Object> findByCampaign() {
Map<String, Object> rtnMap = Maps.newHashMap();
List<SyDicItem> dicItemList = syDicItemRepository.findByDicCode(DIC_GAME_CODE);
rtnMap.put("game", buildTree(null, dicItemList));
dicItemList = syDicItemRepository.findByDicCode(DIC_APP_CODE);
rtnMap.put("app", buildTree(null, dicItemList));
rtnMap.put("test", "");
return rtnMap;
}
@Override
public List<SyDicItem> find(List<String> tagIds) {
return this.syDicItemRepository.findByItemCodeIn(tagIds);
}
private List<SyDicItem> buildTree(String pid, List<SyDicItem> menuList) {
if (pid == null) {
List<SyDicItem> rtnList = Lists.newArrayList();
List subSyDicItemList = menuList.stream().filter(menu -> menu.getItemPid() != null).collect(Collectors.toList());
menuList.stream().filter(menu -> menu.getItemPid() == null).forEach(menu -> {
List<SyDicItem> subList = buildTree(menu.getItemCode(), subSyDicItemList);
menu.setChild(subList);
rtnList.add(menu);
});
return rtnList;
} else {
List<SyDicItem> result = Lists.newArrayList();
for (SyDicItem menuItem : menuList) {
if (menuItem.getItemPid().equals(pid)) {
List<SyDicItem> children = buildTree(menuItem.getItemCode(), menuList);
if (null != children && 0 < children.size()) {
menuItem.setChild(children);
}
result.add(menuItem);
}
}
return result;
}
}
}
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