Commit 5fc73721 by 周海峰

优化

parent c21f6a50
......@@ -57,6 +57,12 @@ public class PlatformApplicationsController {
List<PlatformApplications> list = platformApplicationsService.getPlatformApplicationsListByRole(roleid);
return ResultJson.ok(list);
}
/**
* 根据用户ID获取应用列表
* @param userid 用户ID
* @return 应用列表
*/
@GetMapping("/platformapplications/listbyuserid/{userid}")
public ResultJson listbyuserid(@PathVariable String userid){
List<PlatformApplications> list = platformApplicationsService.getPlatformApplicationsListByUserid(userid);
......
......@@ -5,7 +5,6 @@ import org.springframework.data.annotation.Transient;
import java.io.Serializable;
/**
*
* This class was generated by MyBatis Generator.
* This class corresponds to the database table platform_applications
*
......@@ -13,7 +12,6 @@ import java.io.Serializable;
*/
public class PlatformApplications implements Serializable {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.id
*
......@@ -24,7 +22,7 @@ public class PlatformApplications implements Serializable {
/**
* Database Column Remarks:
* 名称
*
* <p>
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.title
*
......@@ -35,7 +33,7 @@ public class PlatformApplications implements Serializable {
/**
* Database Column Remarks:
* 图标
*
* <p>
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.img
*
......@@ -46,7 +44,7 @@ public class PlatformApplications implements Serializable {
/**
* Database Column Remarks:
* 连接
*
* <p>
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.href
*
......@@ -57,7 +55,7 @@ public class PlatformApplications implements Serializable {
/**
* Database Column Remarks:
* 添加时间
*
* <p>
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.addtime
*
......@@ -68,7 +66,7 @@ public class PlatformApplications implements Serializable {
/**
* Database Column Remarks:
* 是否提示
*
* <p>
* This field was generated by MyBatis Generator.
* This field corresponds to the database column platform_applications.tishi
*
......@@ -107,6 +105,19 @@ public class PlatformApplications implements Serializable {
*/
private String wechatUrl;
/**
* 应用排序编号
*/
private String num;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getWechatUrl() {
return wechatUrl;
}
......@@ -160,7 +171,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.id
*
* @return the value of platform_applications.id
*
* @mbg.generated
*/
public Integer getId() {
......@@ -172,7 +182,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.id
*
* @param id the value for platform_applications.id
*
* @mbg.generated
*/
public void setId(Integer id) {
......@@ -184,7 +193,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.title
*
* @return the value of platform_applications.title
*
* @mbg.generated
*/
public String getTitle() {
......@@ -196,7 +204,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.title
*
* @param title the value for platform_applications.title
*
* @mbg.generated
*/
public void setTitle(String title) {
......@@ -208,7 +215,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.img
*
* @return the value of platform_applications.img
*
* @mbg.generated
*/
public String getImg() {
......@@ -220,7 +226,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.img
*
* @param img the value for platform_applications.img
*
* @mbg.generated
*/
public void setImg(String img) {
......@@ -232,7 +237,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.href
*
* @return the value of platform_applications.href
*
* @mbg.generated
*/
public String getHref() {
......@@ -244,7 +248,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.href
*
* @param href the value for platform_applications.href
*
* @mbg.generated
*/
public void setHref(String href) {
......@@ -256,7 +259,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.addtime
*
* @return the value of platform_applications.addtime
*
* @mbg.generated
*/
public String getAddtime() {
......@@ -268,7 +270,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.addtime
*
* @param addtime the value for platform_applications.addtime
*
* @mbg.generated
*/
public void setAddtime(String addtime) {
......@@ -280,7 +281,6 @@ public class PlatformApplications implements Serializable {
* This method returns the value of the database column platform_applications.tishi
*
* @return the value of platform_applications.tishi
*
* @mbg.generated
*/
public Integer getTishi() {
......@@ -292,7 +292,6 @@ public class PlatformApplications implements Serializable {
* This method sets the value of the database column platform_applications.tishi
*
* @param tishi the value for platform_applications.tishi
*
* @mbg.generated
*/
public void setTishi(Integer tishi) {
......
......@@ -105,19 +105,11 @@
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, title, img, href, addtime, tishi, databasename, databasepassword, databasecon, qyflag, appid, secret,
openmail, mailtype, group_code, wechat_url
openmail, mailtype, group_code, wechat_url, num
</sql>
<select id="selectByExample" parameterType="com.metro.auth.platform.domain.auth.PlatformApplicationsExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
......
......@@ -16,10 +16,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class PlatformApplicationsServiceImpl implements PlatformApplicationsService {
......@@ -28,13 +26,14 @@ public class PlatformApplicationsServiceImpl implements PlatformApplicationsServ
PlatformApplicationsMapper platformApplicationsMapper;
@Resource
PlatformSysRoleMapper platformSysRoleMapper;
@Override
public PageInfo<PlatformApplications> pagedlist(PlatformApplications platformApplications, int pageNum, int pageSize){
public PageInfo<PlatformApplications> pagedlist(PlatformApplications platformApplications, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
PlatformApplicationsExample platformApplicationsExample = new PlatformApplicationsExample();
if(platformApplications!=null&&!EmptyUtilHelper.isEmpty(platformApplications.getTitle())){
platformApplicationsExample.createCriteria().andTitleLike("%"+platformApplications.getTitle()+"%");
if (platformApplications != null && !EmptyUtilHelper.isEmpty(platformApplications.getTitle())) {
platformApplicationsExample.createCriteria().andTitleLike("%" + platformApplications.getTitle() + "%");
}
List<PlatformApplications> list = platformApplicationsMapper.selectByExample(platformApplicationsExample);
......@@ -51,7 +50,7 @@ public class PlatformApplicationsServiceImpl implements PlatformApplicationsServ
if ("1".equals(platformApplications.getOpenmail()) && StringUtils.isEmpty(platformApplications.getMailtype())) {
throw new Exception("启用待办标识不能为空");
}
if(StringUtils.isNotEmpty(platformApplications.getMailtype())){
if (StringUtils.isNotEmpty(platformApplications.getMailtype())) {
//所有应用
List<PlatformApplications> attlist = platformApplicationsMapper.selectListByMailType(platformApplications.getMailtype(), platformApplications.getId());
if (attlist.size() > 0) {
......@@ -60,19 +59,19 @@ public class PlatformApplicationsServiceImpl implements PlatformApplicationsServ
}
int count =0;
if(platformApplications!=null&& !EmptyUtilHelper.isEmpty(platformApplications.getId())){
int count = 0;
if (platformApplications != null && !EmptyUtilHelper.isEmpty(platformApplications.getId())) {
//更新
PlatformApplicationsExample platformApplicationsExample =new PlatformApplicationsExample();
PlatformApplicationsExample platformApplicationsExample = new PlatformApplicationsExample();
platformApplicationsExample.createCriteria().andIdEqualTo(platformApplications.getId());
count =platformApplicationsMapper.updateByExample(platformApplications,platformApplicationsExample);
}else {
count = platformApplicationsMapper.updateByExample(platformApplications, platformApplicationsExample);
} else {
//主键
// platformApplications.setId(StrUtil.makePramykey());
// platformApplications.setAppid(StrUtil.makePramykey());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
platformApplications.setAddtime(sdf.format(new Date()));
count =platformApplicationsMapper.insert(platformApplications);
count = platformApplicationsMapper.insert(platformApplications);
}
return count;
......@@ -85,66 +84,76 @@ public class PlatformApplicationsServiceImpl implements PlatformApplicationsServ
}
@Override
public List<PlatformApplications> getPlatformApplicationsList(){
public List<PlatformApplications> getPlatformApplicationsList() {
return platformApplicationsMapper.getPlatformApplicationsList();
}
@Override
public List<PlatformApplications> getPlatformApplicationsListByUserid(String userid){
PlatformApplicationsExample platformApplicationsExample = new PlatformApplicationsExample();
PlatformApplicationsExample.Criteria criteria = platformApplicationsExample.createCriteria();
criteria.andQyflagEqualTo("1");
//所有应用
List<PlatformApplications> attlist = platformApplicationsMapper.selectByExample(platformApplicationsExample);
//根据userid查询用户所有角色
String roleidlist="";
List<String> names= new ArrayList<>();
try{
int intuser=Integer.parseInt(userid);
List<PlatformSysRole> idealist = platformSysRoleMapper.selectByUserId(intuser);
for (int i=0;i<idealist.size();i++){
names.add(idealist.get(i).getId());
public List<PlatformApplications> getPlatformApplicationsListByUserid(String userid) {
// 1. 查询所有启用的应用
PlatformApplicationsExample example = new PlatformApplicationsExample();
example.createCriteria().andQyflagEqualTo("1");
List<PlatformApplications> allApplications = platformApplicationsMapper.selectByExample(example);
// 2. 将所有应用转换为以ID为Key的Map,方便后续快速查找
// 使用 Collectors.toMap 是一个高效且清晰的做法
Map<Integer, PlatformApplications> appMap = allApplications.stream()
.collect(Collectors.toMap(PlatformApplications::getId, app -> app));
// 3. 安全地解析userid并查询用户角色
Set<String> roleIds = new HashSet<>();
int userIdInt = Integer.parseInt(userid);
// 直接查询出角色ID列表,避免在Java代码中循环提取
roleIds = platformSysRoleMapper.selectByUserId(userIdInt)
.stream().map(PlatformSysRole::getId)
.collect(Collectors.toSet());
// 4. 根据角色ID列表查询可见应用
List<PlatformApplications> visibleApplications;
if (roleIds.isEmpty()) {
visibleApplications = Collections.emptyList(); // 如果没有角色,则可见应用列表为空
} else {
visibleApplications = platformApplicationsMapper.getPlatformApplicationsListByRoleList(new ArrayList<>(roleIds));
}
// 提取可见应用的ID集合,用于快速判断
Set<Integer> visibleAppIds = visibleApplications.stream()
.map(PlatformApplications::getId)
.collect(Collectors.toSet());
// 遍历所有应用,根据其ID是否在可见应用ID集合中来更新状态
allApplications.forEach(app -> {
if (visibleAppIds.contains(app.getId())) {
app.setRoleUseStatue(app.getId()); // 可见
} else {
app.setRoleUseStatue(0); // 不可见
}
}catch (Exception ex){
ex.printStackTrace();
}
//当前角色可见应用
List<PlatformApplications> rolelist= platformApplicationsMapper.getPlatformApplicationsListByRoleList(names);
if(rolelist!=null&&rolelist.size()>0){
for (int i=0;i<rolelist.size();i++){
int finalI = i;
attlist.stream().forEach(t->{
if (t.getId().equals(rolelist.get(finalI).getId())){
t.setRoleUseStatue(t.getId());
}
});
}
}else{
attlist.stream().forEach(t->{
t.setRoleUseStatue(0);
});
return allApplications.stream()
.sorted(Comparator.comparing(app -> StringUtils.isEmpty(app.getNum()) ? 0 : Integer.parseInt(app.getNum())))
.collect(Collectors.toList());
}
return attlist;
}
@Override
public List<PlatformApplications> getPlatformApplicationsListByRole(String roleid){
public List<PlatformApplications> getPlatformApplicationsListByRole(String roleid) {
PlatformApplicationsExample platformApplicationsExample = new PlatformApplicationsExample();
//所有应用
List<PlatformApplications> alllist = platformApplicationsMapper.selectByExample(platformApplicationsExample);
//当前角色可见应用
List<PlatformApplications> rolelist= platformApplicationsMapper.getPlatformApplicationsListByRole(roleid);
if(rolelist!=null&&rolelist.size()>0){
for (int i=0;i<rolelist.size();i++){
List<PlatformApplications> rolelist = platformApplicationsMapper.getPlatformApplicationsListByRole(roleid);
if (rolelist != null && rolelist.size() > 0) {
for (int i = 0; i < rolelist.size(); i++) {
int finalI = i;
alllist.stream().forEach(t->{
if (t.getId().equals(rolelist.get(finalI).getId())){
alllist.stream().forEach(t -> {
if (t.getId().equals(rolelist.get(finalI).getId())) {
t.setRoleUseStatue(t.getId());
}
});
}
}else{
alllist.stream().forEach(t->{
} else {
alllist.stream().forEach(t -> {
t.setRoleUseStatue(0);
});
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论