Commit 5fe78d99 authored by 赵啸非's avatar 赵啸非

添加初始化数据库脚本

parent afcdc30e
...@@ -76,5 +76,6 @@ public interface OperLogService extends ICRUDService<OperLogEntity,Long> { ...@@ -76,5 +76,6 @@ public interface OperLogService extends ICRUDService<OperLogEntity,Long> {
void insertOperLog(HttpServletRequest request, IUser user, BaseEntity oldEntity, BaseEntity newEntity, OperTypeEnum operType, String content, String id); void insertOperLog(HttpServletRequest request, IUser user, BaseEntity oldEntity, BaseEntity newEntity, OperTypeEnum operType, String content, String id);
void insertOperLog(String ip, String requestUrl, Long userId, String userName, String loginName, String content); void insertOperLog(String ip, String requestUrl, Long userId, String userName, String loginName, String content);
} }
\ No newline at end of file
...@@ -63,4 +63,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> { ...@@ -63,4 +63,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @param userType * @param userType
*/ */
List<ResourceEntity> findAll(int userType); List<ResourceEntity> findAll(int userType);
void updateUserList();
} }
\ No newline at end of file
...@@ -8,15 +8,30 @@ ...@@ -8,15 +8,30 @@
package com.mortals.xhx.base.system.resource.service.impl; package com.mortals.xhx.base.system.resource.service.impl;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.resource.dao.ResourceDao; import com.mortals.xhx.base.system.resource.dao.ResourceDao;
import com.mortals.xhx.base.system.resource.model.ResourceEntity; import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery; import com.mortals.xhx.base.system.resource.model.ResourceQuery;
import com.mortals.xhx.base.system.resource.service.ResourceService; import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.common.utils.SyncTreeSiteThread;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -33,6 +48,13 @@ import java.util.Set; ...@@ -33,6 +48,13 @@ import java.util.Set;
@Service("resourceService") @Service("resourceService")
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,ResourceEntity,Long> implements ResourceService { public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,ResourceEntity,Long> implements ResourceService {
@Autowired
private IUserFeign userFeign;
@Autowired
private SiteService siteService;
@Autowired
private UserService userService;
@Override @Override
public List<ResourceEntity> findAllEnable() throws AppException { public List<ResourceEntity> findAllEnable() throws AppException {
ResourceQuery params = new ResourceQuery(); ResourceQuery params = new ResourceQuery();
...@@ -69,5 +91,37 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res ...@@ -69,5 +91,37 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res
public List<ResourceEntity> findAll(int userType) { public List<ResourceEntity> findAll(int userType) {
return dao.getAll(userType); return dao.getAll(userType);
} }
@Override
public void updateUserList() {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
//更新本地用户信息,并且更新用户站点树
list.getData().getData().forEach(user -> {
UserEntity tempUserEntity =userService.selectOne(new UserQuery().loginName(user.getLoginName()));
if (ObjectUtils.isEmpty(tempUserEntity)) {
//新增
UserEntity entity = new UserEntity();
entity.initAttrValue();
BeanUtils.copyProperties(user, entity, BeanUtil.getNullPropertyNames(user));
userService.save(entity);
Context context = new Context();
context.setUser(entity);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(siteService,context));
}else{
//更新
UserEntity userEntity = new UserEntity();
BeanUtils.copyProperties(user, userEntity, new String[]{"loginPwd","userType","status","lastLoginTime", "lastLoginAddress"});
userService.updateWidthDao(userEntity);
Context context = new Context();
context.setUser(userEntity);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(siteService,context));
}
});
}
} }
\ No newline at end of file
...@@ -115,6 +115,5 @@ public interface UserService extends ICRUDService<UserEntity,Long> { ...@@ -115,6 +115,5 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
void updateUserList(); void updateWidthDao(UserEntity userEntity);
} }
\ No newline at end of file
...@@ -65,10 +65,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -65,10 +65,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
private MenuService menuService; private MenuService menuService;
@Autowired @Autowired
private ResourceService resourceService; private ResourceService resourceService;
@Autowired
private IUserFeign userFeign;
@Autowired
private SiteService siteService;
private void doHandlerUser(UserEntity entity) throws AppException { private void doHandlerUser(UserEntity entity) throws AppException {
if (StringUtils.isNotEmpty(entity.getLoginPwd())) { if (StringUtils.isNotEmpty(entity.getLoginPwd())) {
...@@ -293,36 +290,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -293,36 +290,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
} }
@Override @Override
public void updateUserList() { public void updateWidthDao(UserEntity userEntity) {
UserPdu userPdu = new UserPdu(); dao.update(userEntity);
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> list = userFeign.list(userPdu);
//更新本地用户信息,并且更新用户站点树
list.getData().getData().forEach(user -> {
UserEntity tempUserEntity =this.selectOne(new UserQuery().loginName(user.getLoginName()));
if (ObjectUtils.isEmpty(tempUserEntity)) {
//新增
UserEntity entity = new UserEntity();
entity.initAttrValue();
BeanUtils.copyProperties(user, entity, BeanUtil.getNullPropertyNames(user));
this.save(entity);
Context context = new Context();
context.setUser(entity);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(siteService,context));
}else{
//更新
UserEntity userEntity = new UserEntity();
BeanUtils.copyProperties(user, userEntity, new String[]{"loginPwd","userType","status","lastLoginTime", "lastLoginAddress"});
dao.update(userEntity);
Context context = new Context();
context.setUser(userEntity);
ThreadPool.getInstance().execute(new SyncTreeSiteThread(siteService,context));
}
});
} }
......
...@@ -13,6 +13,7 @@ import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; ...@@ -13,6 +13,7 @@ import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.DataUtil; import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.util.ThreadPool; import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
...@@ -31,6 +32,7 @@ import com.mortals.xhx.module.site.model.SiteTreeSelect; ...@@ -31,6 +32,7 @@ import com.mortals.xhx.module.site.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -65,6 +67,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -65,6 +67,8 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
private IUserFeign userFeign; private IUserFeign userFeign;
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private ResourceService resourceService;
@Override @Override
protected void validData(SiteEntity entity, Context context) throws AppException { protected void validData(SiteEntity entity, Context context) throws AppException {
...@@ -194,7 +198,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -194,7 +198,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
Rest<String> rest = userFeign.synchSiteAuth(); Rest<String> rest = userFeign.synchSiteAuth();
if(rest.getCode().equals(YesNoEnum.YES.getValue())){ if(rest.getCode().equals(YesNoEnum.YES.getValue())){
//更新用户站点id,并更新站点树 //更新用户站点id,并更新站点树
userService.updateUserList(); resourceService.updateUserList();
} }
super.updateAfter(entity, context); super.updateAfter(entity, context);
} }
...@@ -207,7 +211,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -207,7 +211,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
Rest<String> rest = userFeign.synchSiteAuth(); Rest<String> rest = userFeign.synchSiteAuth();
if(rest.getCode().equals(YesNoEnum.YES.getValue())){ if(rest.getCode().equals(YesNoEnum.YES.getValue())){
//更新用户站点id,并更新站点树 //更新用户站点id,并更新站点树
userService.updateUserList(); resourceService.updateUserList();
} }
super.saveAfter(entity, context); super.saveAfter(entity, context);
...@@ -220,7 +224,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE ...@@ -220,7 +224,7 @@ public class SiteServiceImpl extends AbstractCRUDCacheServiceImpl<SiteDao, SiteE
Rest<String> rest = userFeign.synchSiteAuth(); Rest<String> rest = userFeign.synchSiteAuth();
if(rest.getCode().equals(YesNoEnum.YES.getValue())){ if(rest.getCode().equals(YesNoEnum.YES.getValue())){
//更新用户站点id,并更新站点树 //更新用户站点id,并更新站点树
userService.updateUserList(); resourceService.updateUserList();
} }
super.removeAfter(ids, context, result); super.removeAfter(ids, context, 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