Commit 5fc73721 by 周海峰

优化

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