Merge remote-tracking branch 'origin/test-training2' into test-training2

This commit is contained in:
joylink_zhangsai 2022-11-07 17:08:59 +08:00
commit f132220891
8 changed files with 155 additions and 66 deletions

View File

@ -66,6 +66,9 @@ public class UserController {
@Role({RoleEnum.SuperAdmin, RoleEnum.Admin})
@GetMapping(path = "sync")
public String sync( HttpServletResponse response){
if(!this.syncService.initData()){
return "正在同步。。。";
}
File file = this.syncService.sync();
if(Objects.isNull(file) || !file.exists()){
return "未找到统计的同步文件";

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.entity.permission.PermissionSubjectExample;
import club.joylink.rtss.vo.permission.PermissionSubjectStatusEnum;
import club.joylink.rtss.vo.permission.subject.PermissionSubjectQueryVO;
import club.joylink.rtss.vo.permission.subject.PermissionSubjectVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -81,6 +82,19 @@ public interface PermissionSubjectDAO {
int insert(PermissionSubject record);
@Insert("<script>" +
"insert into rts_permission_subject (permission_id, subject_type, subject_id, amount, remains, `status`,forever, start_time, end_time,create_time, distribute_id, parent_id,is_sync)" +
" values " +
"<foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\"> " +
"(#{item.permissionId,jdbcType=BIGINT}, #{item.subjectType,jdbcType=VARCHAR}, #{item.subjectId,jdbcType=BIGINT}," +
" #{item.amount,jdbcType=INTEGER}, #{item.remains,jdbcType=INTEGER}, #{item.status,jdbcType=INTEGER}, " +
" #{item.forever,jdbcType=BIT}, #{item.startTime,jdbcType=TIMESTAMP}, #{item.endTime,jdbcType=TIMESTAMP}," +
" #{item.createTime,jdbcType=TIMESTAMP}, #{item.distributeId,jdbcType=BIGINT}, #{item.parentId,jdbcType=BIGINT}," +
" #{item.isSync,jdbcType=BIT})" +
"</foreach>" +
"</script>")
void batchInsert(@Param("list") List<PermissionSubject> list);
int insertSelective(PermissionSubject record);
List<PermissionSubject> selectByExample(PermissionSubjectExample example);

View File

@ -1,8 +1,11 @@
package club.joylink.rtss.dao.permission;
import club.joylink.rtss.entity.permission.PermissionSubject;
import club.joylink.rtss.entity.permission.PermissionSystemAbility;
import club.joylink.rtss.entity.permission.PermissionSystemAbilityExample;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -16,6 +19,14 @@ public interface PermissionSystemAbilityDAO {
int deleteByPrimaryKey(Long id);
@Insert("<script>" +
"insert into rts_permission_system_ability (permission_id, system_ability_id, is_sync)" +
" values " +
"<foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\"> " +
"(#{item.permissionId,jdbcType=BIGINT}, #{item.systemAbilityId,jdbcType=BIGINT}, #{item.isSync,jdbcType=BIT})" +
"</foreach>" +
"</script>")
void batchInsert(@Param("list") List<PermissionSystemAbility> list);
int insert(PermissionSystemAbility record);
int insertSelective(PermissionSystemAbility record);
@ -31,4 +42,4 @@ public interface PermissionSystemAbilityDAO {
int updateByPrimaryKeySelective(PermissionSystemAbility record);
int updateByPrimaryKey(PermissionSystemAbility record);
}
}

View File

@ -135,6 +135,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return msgList;
}
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
@Override
public List<String> generateLpf(long mapId, long creatorId) {
List<MapPassengerFlowVO> pfDataList = mapPassengerFlowDataService.queryAllPassengerFlowBaseDataOfMap(mapId);

View File

@ -38,6 +38,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -68,14 +69,16 @@ public class OldPermissionDataSyncService {
@Autowired
private MapInfoDAO mapInfoDAO;
static final Map<Long,Simulation.Type> MAPID_TYPE_MAP = Maps.newHashMap();
private final static AtomicBoolean ISRUN = new AtomicBoolean(false);
static final Map<Long,GgenerateType> MAPID_TYPE_MAP = Maps.newHashMap();
static final List<ErrorMsgVO> SYNC_RESULT_LIST = Lists.newArrayList();
static{
MAPID_TYPE_MAP.put(154L,Simulation.Type.RAILWAY); //大铁标准站
// MAPID_TYPE_MAP.put(81L,Simulation.Type.RAILWAY); //北交大客流
MAPID_TYPE_MAP.put(161L,Simulation.Type.EMERGENCY); //武汉8号线应急调度
MAPID_TYPE_MAP.put(154L,GgenerateType.RAILWAY); //大铁标准站
MAPID_TYPE_MAP.put(81L,GgenerateType.DAKE_STREAM); //北交大客流
MAPID_TYPE_MAP.put(161L,GgenerateType.EMERGENCY); //武汉8号线应急调度
}
private void truncateAllTable(){
syncDAO.clearRtsPermission();
syncDAO.clearRtsDistribute();
@ -83,42 +86,69 @@ public class OldPermissionDataSyncService {
syncDAO.clearRtsPermissionSystemAbility();
syncDAO.clearRtsPermissionSubject();
}
public boolean initData(){
if(ISRUN.compareAndSet(false,true)){
SYNC_RESULT_LIST.clear();
try{
truncateAllTable();
MapInfoExample example = new MapInfoExample();
example.createCriteria().andStatusEqualTo("1" );
List<MapInfo> mapInfoList = this.mapInfoDAO.selectByExample(example);
for (MapInfo mapInfo : mapInfoList) {
this.generate(mapInfo);
}
this.abilityService.autoSynchMapSystemData(0L);
}catch (Exception e){
log.error("用户权限初始化失败 msg:" + e.getMessage(),e);
ISRUN.compareAndSet(true,false);
}
return true;
}else{
return false;
}
}
@Transactional(rollbackFor = Exception.class)
public File sync(){
SYNC_RESULT_LIST.clear();
truncateAllTable();
List<UserPermissionVO> userPermissionList = syncDAO.findCanUsedData();
List<SyncVO> syncVOList = findAllPermission(userPermissionList);
List<DistributeDataVO> distributeDataVOList = distributeData(syncVOList);
List<PermissionSubject> psList = this.userPermission(userPermissionList);
insertPermission(syncVOList);
insertDistribute(distributeDataVOList);
insertUserPermission(psList);
return outErrorMsg();
try{
List<UserPermissionVO> userPermissionList = syncDAO.findCanUsedData();
Map<Long,List<SystemAbility>> funMapIdMap = this.findSystemAbilityGroupMapId();
List<SyncVO> syncVOList = findAllPermission(userPermissionList,funMapIdMap);
List<DistributeDataVO> distributeDataVOList = distributeData(syncVOList);
List<PermissionSubject> psList = this.userPermission(userPermissionList,funMapIdMap);
insertPermission(syncVOList);
insertDistribute(distributeDataVOList);
insertUserPermission(psList);
File file = outErrorMsg();
return file;
}catch (Exception e){
log.error("用户权限同步失败 msg:" + e.getMessage(),e);
throw e;
}finally {
ISRUN.compareAndSet(true,false);
}
}
private File outErrorMsg(){
List<Long> createMapErrorList = SYNC_RESULT_LIST.stream().filter(d->d.errorType == ErrorType.CREATE_MAP).map(d->d.getPermissionVO().getMapId()).distinct().collect(Collectors.toList());
MapInfoExample example = new MapInfoExample();
example.createCriteria().andIdIn(createMapErrorList);
List<MapInfo> mapInfoList = this.mapInfoDAO.selectByExample(example);
List<String> xiajiaList = mapInfoList.stream().filter(d->!Objects.equals(d.getStatus(),"1")).map(d->String.format("%s [%s] [%s]",d.getId(),d.getName(),Objects.equals(d.getStatus(),"1")?"正常":"下架")).collect(Collectors.toList());
List<String> zhengchangList = mapInfoList.stream().filter(d->Objects.equals(d.getStatus(),"1")).map(d->String.format("%s [%s] [%s]",d.getId(),d.getName(),Objects.equals(d.getStatus(),"1")?"正常":"下架")).collect(Collectors.toList());
BufferedWriter bw = null;
try{
File file = File.createTempFile("error",".txt");
bw = new BufferedWriter(new FileWriter(file));
bw.write("------------------------------\n");
bw.write("创建子系统错误【下架】的数据\n");
bw.write(Joiner.on(",").join(xiajiaList));
bw.write("\n\n");
bw.write("------------------------------\n");
bw.write("创建子系统正常【创建失败】的数据\n");
bw.write(Joiner.on(",").join(zhengchangList));
bw.write("\n\n\n\n");
// bw.write("创建子系统错误【下架】的数据\n");
// bw.write(Joiner.on(",").join(xiajiaList));
// bw.write("\n\n");
// bw.write("------------------------------\n");
// bw.write("创建子系统正常【创建失败】的数据\n");
// bw.write(Joiner.on(",").join(zhengchangList));
// bw.write("\n\n\n\n");
bw.write("------------------------------\n");
for (ErrorMsgVO errorMsgVO : SYNC_RESULT_LIST) {
bw.write(errorMsgVO.toString());
@ -144,11 +174,10 @@ public class OldPermissionDataSyncService {
for (SyncVO syncVO : syncVOList) {
syncVO.permission.setIsSync(true);
this.acPermissionDAO.customerSyncInsert(syncVO.permission);
for (PermissionSystemAbility sa : syncVO.getSystemAbility()) {
sa.setIsSync(true);
permissionSystemAbilityDAO.insert(sa);
}
syncVO.getSystemAbility().forEach(d->d.setIsSync(true));
}
List<PermissionSystemAbility> tmpList = syncVOList.stream().map(d->d.getSystemAbility()).flatMap(d->d.stream()).collect(Collectors.toList());
this.permissionSystemAbilityDAO.batchInsert(tmpList);
}
private void insertDistribute(List<DistributeDataVO> distributeDataVOList){
@ -164,15 +193,19 @@ public class OldPermissionDataSyncService {
}
}
private void insertUserPermission(List<PermissionSubject> psList){
if(CollectionUtils.isEmpty(psList)){
return;
}
for (PermissionSubject ps : psList) {
ps.setIsSync(true);
this.subjectDAO.insert(ps);
// this.subjectDAO.insert(ps);
}
this.subjectDAO.batchInsert(psList);
}
private List<PermissionSubject> userPermission(List<UserPermissionVO> voList){
private List<PermissionSubject> userPermission(List<UserPermissionVO> voList,Map<Long,List<SystemAbility>> funMapIdMap){
List<PermissionSubject> psList = Lists.newArrayList();
Map<Long,List<SystemAbility>> funMapIdMap = this.findSystemAbilityGroupMapId();
for (UserPermissionVO userPermissionVO : voList) {
List<SystemAbility> mapList = funMapIdMap.get(userPermissionVO.getMapId());
if(CollectionUtils.isEmpty(mapList)){
@ -197,18 +230,15 @@ public class OldPermissionDataSyncService {
return datavoList;
}
private List<SyncVO> findAllPermission(List<UserPermissionVO> userPermissionList){
private List<SyncVO> findAllPermission(List<UserPermissionVO> userPermissionList,Map<Long,List<SystemAbility>> funMapIdMap){
List<UserPermissionVO> handleDataList = this.easyBeforehand(userPermissionList);
this.abilityService.autoSynchMapSystemData(0L);
Map<Long,List<SystemAbility>> funMapIdMap = this.findSystemAbilityGroupMapId();
List<SyncVO> syncVOList = Lists.newArrayList();
Set<Long> existPermissionIdSet = Sets.newHashSet();
for (UserPermissionVO permissionVO : handleDataList) {
List<SystemAbility> mapList = funMapIdMap.get(permissionVO.getMapId());
if(CollectionUtils.isEmpty(mapList)){
log.error("{} 为找到对应的功能",permissionVO.getMapId());
SYNC_RESULT_LIST.add(new ErrorMsgVO(ErrorType.PERSSION_NOTFIND_MAP,permissionVO,""));
SYNC_RESULT_LIST.add(new ErrorMsgVO(ErrorType.PERSSION_NOTFIND_MAP,permissionVO,String.format("mapid[%s] 未在 rts_permission_system_ability 表中找到对应的数据",permissionVO.getMapId())));
continue;
}
if(!existPermissionIdSet.add(permissionVO.getPermissionId())){
@ -251,29 +281,50 @@ public class OldPermissionDataSyncService {
return null;
}
private List<UserPermissionVO> easyBeforehand(List<UserPermissionVO> userPermissionList){
Set<Long> existMapIdSet = Sets.newHashSet();
userPermissionList.forEach(d-> {
if(Objects.isNull(d.getMapId())){
d.setErrorData(true);
}else{
if(existMapIdSet.add(d.getMapId())){
Simulation.Type type = Objects.isNull(MAPID_TYPE_MAP.get(d.getMapId())) ? Simulation.Type.METRO : MAPID_TYPE_MAP.get(d.getMapId());
RtsMapFunctionGenerateParamVO paramVO = new RtsMapFunctionGenerateParamVO();
paramVO.setSimTypes(Arrays.asList(type));
try{
this.rtsMapFunctionService.generate(d.getMapId(),paramVO,0L);
}catch(Exception e){
private void generate(MapInfo mi){
Simulation.Type type = Simulation.Type.METRO;
GgenerateType gt = MAPID_TYPE_MAP.get(mi.getId());
if(gt == GgenerateType.RAILWAY){
type = Simulation.Type.RAILWAY;
this.generate(type,mi);
}else if(gt == GgenerateType.EMERGENCY){
type = Simulation.Type.EMERGENCY;
this.generate(type,mi);
}else if(gt == GgenerateType.DAKE_STREAM){
this.generateLpf(mi);
return;
}else{
this.generate(type,mi);
}
}
d.setErrorData(true);
SYNC_RESULT_LIST.add(new ErrorMsgVO(ErrorType.CREATE_MAP,d,e.getMessage()));
}
}
if(Objects.isNull(d.getIsPackage())) d.setIsPackage(false);
private void generateLpf(MapInfo mi){
try{
this.rtsMapFunctionService.generateLpf(mi.getId(),0L);
}catch(Exception e){
SYNC_RESULT_LIST.add(new ErrorMsgVO(ErrorType.CREATE_MAP,mi,e.getMessage()));
}
}
private void generate(Simulation.Type type,MapInfo mi){
RtsMapFunctionGenerateParamVO paramVO = new RtsMapFunctionGenerateParamVO();
paramVO.setSimTypes(Arrays.asList(type));
try{
this.rtsMapFunctionService.generate(mi.getId(),paramVO,0L);
}catch(Exception e){
SYNC_RESULT_LIST.add(new ErrorMsgVO(ErrorType.CREATE_MAP,mi,e.getMessage()));
}
}
private List<UserPermissionVO> easyBeforehand(List<UserPermissionVO> userPermissionList){
// Set<Long> existMapIdSet = Sets.newHashSet();
for (UserPermissionVO d : userPermissionList) {
if(Objects.isNull(d.getIsPackage())) d.setIsPackage(false);
if(Objects.isNull(d.getMapId())){
// d.setErrorData(true);
continue;
}
});
userPermissionList.stream().filter(UserPermissionVO::isErrorData).collect(Collectors.toList());
Map<Boolean,List<UserPermissionVO>> userPermissionMapList = userPermissionList.stream().filter(d->!d.getIsPackage()).collect(Collectors.groupingBy(UserPermissionVO::getIsPackage));
}
Map<Boolean,List<UserPermissionVO>> userPermissionMapList = userPermissionList.stream().collect(Collectors.groupingBy(UserPermissionVO::getIsPackage));
List<UserPermissionVO> voList = userPermissionMapList.get(false);
List<UserPermissionVO> packAgeVOList = userPermissionMapList.get(true);
if(!CollectionUtils.isEmpty(packAgeVOList)){
@ -390,7 +441,15 @@ public class OldPermissionDataSyncService {
}
}
public enum GgenerateType {
/** 地铁 */
METRO,
/** 铁路/大铁 */
RAILWAY,
/** 应急调度Emergency dispatching command system */
EMERGENCY,
DAKE_STREAM,
}
public enum ErrorType{
CREATE_MAP,
PERSSION_NOTFIND_MAP;
@ -400,7 +459,7 @@ public class OldPermissionDataSyncService {
@AllArgsConstructor
public static class ErrorMsgVO{
ErrorType errorType;
UserPermissionVO permissionVO;
Object permissionVO;
String msg;
@Override
public String toString(){

View File

@ -34,6 +34,6 @@ public class UserPermissionVO {
private Integer amount;
private Integer remains;
private String mapName;
private boolean errorData;
// private boolean errorData;
private List<PermissionVO> permissionVO;
}

View File

@ -7,6 +7,6 @@
,A.forever,A.amount,A.remains,C.name as map_name
from user_permission A left join permission B on A.permission_id = B.id
left join map_info C on B.map_id = C.id
where 1 = 1 and C.id is not null
where 1 = 1 and C.id is not null and C.status = '1'
</select>
</mapper>

View File

@ -14,6 +14,7 @@ public class SyncServiceTest {
private OldPermissionDataSyncService syncService;
@Test
public void sync(){
this.syncService.initData();
File file = this.syncService.sync();
if(Objects.isNull(file)){