update:develop3

This commit is contained in:
zzy
2021-07-30 17:08:17 +08:00
parent faef2cdf59
commit 30859dd3af
9 changed files with 92 additions and 56 deletions
@@ -53,6 +53,13 @@ public class TsResourceController extends BaseController<TsResource> {
return Result.success(tsResources);
}
// @ApiOperation("查询所有资源")
// @GetMapping("/getDefault")
// public ResponseMessage<List<TsResource>> getDefault(){
// List<String> tsResources=tsResourceService.getDefaultByName();
// return Result.success(tsResources);
// }
@ApiOperation("添加资源")
@PostMapping("/add")
public ResponseMessage<Object> addResource(@RequestBody TsResource tsResource){
@@ -3,6 +3,7 @@ package com.adc.da.slrs.sarResource.dao;
import com.adc.da.slrs.sarResource.entity.TsResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.HashMap;
import java.util.List;
/**
@@ -19,4 +20,6 @@ public interface TsResourceDao extends BaseMapper<TsResource> {
List<TsResource> selectMenuByRole(TsResource sarMenuEO);
int insertTsRoleResource(HashMap<String,Object> map);
}
@@ -34,6 +34,8 @@ public interface ITsResourceService extends IService<TsResource> {
List<TsResource> getAll(TsResource tsResource);
List<String> getDefaultByName();
ResponseMessage<Object> addResource(TsResource tsResource);
ResponseMessage<Object> updateResource(TsResource tsResource);
@@ -155,6 +155,19 @@ public class TsResourceServiceImpl extends ServiceImpl<TsResourceDao, TsResource
return TsResources;
}
@Override
public List<String> getDefaultByName() {
List<String> menusNames=new ArrayList<>();
menusNames.add("海外标准法规");
menusNames.add("国内标准法规");
QueryWrapper<TsResource> tsResourceQueryWrapper=new QueryWrapper<>();
tsResourceQueryWrapper.in("MENU_NAME",menusNames);
List<TsResource> TsResources=dao.selectList(tsResourceQueryWrapper);
List<String> res=new ArrayList<>();
TsResources.forEach(tsResource -> res.add(tsResource.getId()));
return res;
}
/**
* 添加菜单
* @param TsResource:菜单信息
@@ -6,6 +6,8 @@ import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.login.util.UserUtils;
import com.adc.da.slrs.sarMenu.entity.SarMenu;
import com.adc.da.slrs.sarResource.entity.TsResource;
import com.adc.da.slrs.sarResource.service.ITsResourceService;
import com.adc.da.slrs.sarRole.entity.TsRoleMenuVO;
import com.adc.da.slrs.sarRole.entity.TsRoleResourceVO;
import com.adc.da.slrs.sarRole.service.ITsRoleService;
@@ -4,6 +4,7 @@ import com.adc.da.slrs.sarRole.entity.TsRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@@ -75,7 +76,7 @@ public interface TsRoleDao extends BaseMapper<TsRole> {
* @param resourceId:权限ID
*/
@Insert("insert into ts_role_resource (role_id,resource_id) values (#{roleId},#{resourceId})")
void addResource(String roleId, String resourceId);
void addResource(@Param("roleId") String roleId, @Param("resourceId") String resourceId);
/**
* 删除权限
@@ -83,7 +84,7 @@ public interface TsRoleDao extends BaseMapper<TsRole> {
* @param resourceId:权限ID
*/
@Delete("delete from ts_role_resource where role_id=#{roleId} and resource_id=#{resourceId}")
void delResource(String roleId, String resourceId);
void delResource(@Param("roleId") String roleId,@Param("resourceId") String resourceId);
/**
* 通过角色Id列表查询资源Id列表
@@ -6,6 +6,7 @@ import com.adc.da.slrs.sarMenu.dao.SarMenuDao;
import com.adc.da.slrs.sarMenu.entity.SarMenu;
import com.adc.da.slrs.sarMenu.service.ISarMenuService;
import com.adc.da.slrs.sarPersonalCenter.service.ISarUserPersonalMenuService;
import com.adc.da.slrs.sarResource.service.ITsResourceService;
import com.adc.da.slrs.sarRole.entity.TsRole;
import com.adc.da.slrs.sarRole.dao.TsRoleDao;
import com.adc.da.slrs.sarRole.entity.TsRoleMenuVO;
@@ -42,6 +43,9 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
@Autowired
@Lazy
private ISarUserPersonalMenuService sarUserPersonalMenuService;
@Autowired
private ITsResourceService tsResourceService;
/**
* 查询所有角色
* @return List<TsRole>
@@ -105,6 +109,10 @@ public class TsRoleServiceImpl extends ServiceImpl<TsRoleDao, TsRole> implements
tsRole.setRoleHierarchy(parentRole.getRoleHierarchy()+1);
}
tsRoleDao.insert(tsRole);
List<String> as=tsResourceService.getDefaultByName();
as.forEach(s -> {
tsRoleDao.addResource(tsRole.getId(),s);
});
return Result.success();
}
@@ -17,7 +17,7 @@ import java.util.Map;
*/
public interface ISarStandardsInfoService extends IService<SarStandardsInfo> {
void reverseQueryStand(List<String> ids, String standName,String type);
// void reverseQueryStand(List<String> ids, String standName,String type);
List<SarStandardsInfo> getSarStandardsInfoPage(SarStandardsInfoEOPage page) throws Exception;
@@ -194,59 +194,59 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
@Autowired
private StandLawsSearchService standLawsSearchService;
/**
* 反向操作标准
*/
@Override
@Async
public void reverseQueryStand(List<String> ids, String standName,String type){
String fieldInfo = InitStandAttrUtil.queryField;
if (StringUtils.isNotBlank(fieldInfo) && StringUtils.isNotBlank(type)) {
List<Map<String, Object>> getAttrListMap = sarStandAttrInfoEODao.selectStandFieldAndDataListMap(fieldInfo, ids);
getAttrListMap.forEach(attrMap -> {
List<String> list = Collections.singletonList(attrMap.get(type).toString());
list.add(standName);
String reverseStandName = list.stream().map(String::toString).collect(Collectors.joining(","));
attrMap.put(type,reverseStandName);
SarStandAttrInfo sarStandAttrInfo = map2Object(attrMap,SarStandAttrInfo.class);
sarStandAttrInfoEODao.updateById(sarStandAttrInfo);
});
}
}
public static <T> T map2Object(Map<String, Object> map, Class<T> clazz) {
T obj = null;
try {
BeanInfo bean = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] propertyDescriptorArr = bean.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptorArr.length; i++) {
PropertyDescriptor propertyDescriptor = propertyDescriptorArr[i];
String name = propertyDescriptor.getName();
if(map.containsKey(name)) {
Object value = map.get(name);
if("null".equals(value)) {
value = null;
}
Object[] objArr = new Object[0];
objArr[0] = value;
try {
propertyDescriptor.getWriteMethod().invoke(obj, objArr);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
} catch (IntrospectionException e) {
e.printStackTrace();
}
return obj;
}
// /**
// * 反向操作标准
// */
// @Override
// @Async
// public void reverseQueryStand(List<String> ids, String standName,String type){
// String fieldInfo = InitStandAttrUtil.queryField;
// if (StringUtils.isNotBlank(fieldInfo) && StringUtils.isNotBlank(type)) {
// List<Map<String, Object>> getAttrListMap = sarStandAttrInfoEODao.selectStandFieldAndDataListMap(fieldInfo, ids);
// getAttrListMap.forEach(attrMap -> {
// List<String> list = Collections.singletonList(attrMap.get(type).toString());
// list.add(standName);
// String reverseStandName = list.stream().map(String::toString).collect(Collectors.joining(","));
// attrMap.put(type,reverseStandName);
// SarStandAttrInfo sarStandAttrInfo = map2Object(attrMap,SarStandAttrInfo.class);
// sarStandAttrInfoEODao.updateById(sarStandAttrInfo);
// });
// }
// }
//
// public static <T> T map2Object(Map<String, Object> map, Class<T> clazz) {
//
// T obj = null;
// try {
// BeanInfo bean = Introspector.getBeanInfo(clazz);
// PropertyDescriptor[] propertyDescriptorArr = bean.getPropertyDescriptors();
// for (int i = 0; i < propertyDescriptorArr.length; i++) {
// PropertyDescriptor propertyDescriptor = propertyDescriptorArr[i];
// String name = propertyDescriptor.getName();
// if(map.containsKey(name)) {
// Object value = map.get(name);
// if("null".equals(value)) {
// value = null;
// }
// Object[] objArr = new Object[0];
// objArr[0] = value;
// try {
// propertyDescriptor.getWriteMethod().invoke(obj, objArr);
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// } catch (InvocationTargetException e) {
// e.printStackTrace();
// }
// }
//
// }
// } catch (IntrospectionException e) {
// e.printStackTrace();
// }
// return obj;
// }
/***