修复服务器权限的bug

This commit is contained in:
2024-07-19 13:09:04 +08:00
parent d94080955b
commit cd7ac1a7b1
9 changed files with 192 additions and 116 deletions
@@ -11,8 +11,10 @@ import com.gxwebsoft.cms.entity.*;
import com.gxwebsoft.cms.param.*;
import com.gxwebsoft.cms.service.*;
import com.gxwebsoft.common.core.security.JwtUtil;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.Menu;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.UserService;
import com.gxwebsoft.oa.entity.Company;
@@ -28,6 +30,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -42,6 +45,8 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.gxwebsoft.common.core.utils.CommonUtil.toTreeData;
/**
* 网站信息记录表控制器
*
@@ -71,12 +76,6 @@ public class WebsiteController extends BaseController {
@Resource
private RedisUtil redisUtil;
@Resource
private UserService userService;
@Resource
private MerchantService merchantService;
@Resource
private MerchantAccountService merchantAccountService;
@Resource
private MpMenuService mpMenuService;
@Resource
private OrderService orderService;
@@ -88,18 +87,13 @@ public class WebsiteController extends BaseController {
String key = "SiteInfo:" + tenantId;
final String siteInfo = redisUtil.get(key);
String access_token = JwtUtil.getAccessToken(request);
// redisUtil.set("Domain:ffai.cn",10157);
// redisUtil.set("Domain:www.xn--15qx69a6lbn8t0tlmve.com",10157);
// redisUtil.set("Domain:xn--15qx69a6lbn8t0tlmve.com",10157);
// redisUtil.set("Domain:oa.gxwebsoft.com",5);
// redisUtil.set("Domain:gxwebsoft.com",5);
if(tenantId.equals(0)){
return fail("租户ID不存在",null);
}
// 从缓存读取信息
if(StrUtil.isNotBlank(siteInfo)){
return success(JSONObject.parseObject(siteInfo,Website.class));
// return success(JSONObject.parseObject(siteInfo,Website.class));
}
// 获取站点信息
@@ -221,6 +215,43 @@ public class WebsiteController extends BaseController {
navigation.setType(1);
navigation.setPosition(1);
navigationService.save(navigation);
// 网站配置参数
List<WebsiteField> fields = new ArrayList<>();
WebsiteField field = new WebsiteField();
field.setType(0);
field.setName("siteLogo");
field.setValue(company.getCompanyLogo());
field.setComments("网站LOGO");
fields.add(field);
field.setName("siteName");
field.setValue(company.getShortName());
field.setComments("网站名称");
fields.add(field);
field.setName("icpNo");
field.setValue("-");
field.setComments("备案号");
fields.add(field);
field.setName("qrcode");
field.setValue("");
field.setComments("公众号二维码");
fields.add(field);
field.setName("bottomBg");
field.setValue("https://oss.wsdns.cn/20240717/13165035c35e4f25a6c9fbd3636c6292.png");
field.setComments("网站底部背景图");
fields.add(field);
field.setName("address");
field.setValue(company.getAddress());
field.setComments("办公地址");
fields.add(field);
field.setName("tel");
field.setValue(company.getTel());
field.setComments("公司电话");
fields.add(field);
field.setName("domain");
field.setValue(company.getDomain());
field.setComments("网站域名");
fields.add(field);
websiteFieldService.saveBatch(fields);
}
// 获取站点信息
@@ -228,7 +259,8 @@ public class WebsiteController extends BaseController {
final Website website = websites.get(0);
// 附加自定义字段
website.setFields(websiteFieldService.list());
// website.setFields(fields);
// 小程序端导航图标
final MpMenuParam mpMenuParam = new MpMenuParam();
website.setMpMenus(mpMenuService.listRel(mpMenuParam));
@@ -236,12 +268,30 @@ public class WebsiteController extends BaseController {
// 附加自定义导航
final NavigationParam navigationParam = new NavigationParam();
navigationParam.setHide(0);
website.setNavigations(navigationService.listRel(navigationParam));
final List<Navigation> navigations = navigationService.listRel(navigationParam);
final Map<Integer, List<Navigation>> collect = navigations.stream().collect(Collectors.groupingBy(Navigation::getPosition));
website.setNavigations(navigations);
// 封装网站顶部菜单
if(!CollectionUtils.isEmpty(collect.get(1))){
final List<Navigation> topNavs = toTreeData(collect.get(1), 0, Navigation::getParentId, Navigation::getNavigationId, Navigation::setChildren);
website.setTopNavs(topNavs);
}
// 封装网站底部菜单
if (!CollectionUtils.isEmpty(collect.get(2))) {
final List<Navigation> bottomNavs = toTreeData(collect.get(2), 0, Navigation::getParentId, Navigation::getNavigationId, Navigation::setChildren);
website.setBottomNavs(bottomNavs);
}
// 读取幻灯片广告
final AdParam adParam = new AdParam();
final PageResult<Ad> adPageResult = adService.pageRel(adParam);
website.setAds(adPageResult.getList());
final List<Ad> list = adService.list(new LambdaQueryWrapper<Ad>().eq(Ad::getAdType,"幻灯片"));
if (!CollectionUtils.isEmpty(list)) {
final Ad ad = list.get(0);
final String images = ad.getImages();
System.out.println("images = " + images);
final JSONObject jsonObject = JSONObject.parseObject(images);
System.out.println("jsonObject = " + jsonObject);
// website.setSlide(jsonObject);
}
// 首页布局
final Design design = designService.getOne(new LambdaQueryWrapper<Design>().eq(Design::getHome, 1).last("limit 1"));
@@ -249,37 +299,19 @@ public class WebsiteController extends BaseController {
website.setLayout(design.getLayout());
}
// 提取文章分类作为网站导航
final ArticleCategoryParam param = new ArticleCategoryParam();
param.setDeleted(0);
param.setStatus(0);
website.setCategoryList(articleCategoryService.listRel(param));
// 读取友情链接
final LinkParam linkParam = new LinkParam();
linkParam.setLinkType("友情链接");
website.setLinks(linkService.listRel(linkParam));
// 读取会员信息
if(access_token != null){
// 请求主服务器获取租户信息
String result = HttpRequest.get("https://server.gxwebsoft.com/api/auth/user")
.header("Authorization", access_token)
.header("Tenantid", tenantId.toString())
.timeout(20000)//超时,毫秒
.execute().body();
JSONObject jsonObject = JSONObject.parseObject(result);
final String data = jsonObject.getString("data");
final User user = JSONObject.parseObject(data, User.class);
// 商户账号
website.setMerchantAccount(merchantAccountService.getOne(new LambdaQueryWrapper<MerchantAccount>().eq(MerchantAccount::getPhone, user.getPhone()).last("limit 1")));
website.setUserInfo(user);
}
// 授权信息
// 配置信息
HashMap<String, Object> config = new HashMap<>();
config.put("LICENSE_CODE", "");
config.put("MAP_KEY", "");
final List<WebsiteField> fields = websiteFieldService.list();
fields.forEach(d -> {
config.put(d.getName(),d.getValue());
});
website.setConfig(config);
// 服务器时间
@@ -296,12 +328,12 @@ public class WebsiteController extends BaseController {
// 今天星期几
final int week = DateUtil.thisDayOfWeek();
final DateTime nextWeek = DateUtil.nextWeek();
serverTime.put("now",DateUtil.now());
serverTime.put("today",today);
serverTime.put("tomorrow",tomorrow);
serverTime.put("afterDay",afterDay);
serverTime.put("week",week);
serverTime.put("nextWeek",nextWeek);
serverTime.put("now",DateUtil.now()); // 2024-07-18 22:06:36
serverTime.put("today",today); // 2024-07-18
serverTime.put("tomorrow",tomorrow); // 2024-07-19
serverTime.put("afterDay",afterDay); // 2024-07-20
serverTime.put("nextWeek",nextWeek); // 2024-07-25 22:06:36
serverTime.put("week",week); // 5
website.setServerTime(serverTime);
redisUtil.set(key,website,1L, TimeUnit.DAYS);
return success(website);
@@ -328,28 +360,6 @@ public class WebsiteController extends BaseController {
vo.setHasNoPayOrder(true);
}
}
System.out.println("hour = " + hour);
// DateUtil.between(DateUtil.date(), , DateUnit.DAY);
// HashMap<String, Object> serverTime = new HashMap<>();
// // 今天日期
// DateTime date = DateUtil.date();
// String today= DateUtil.today();
// // 明天日期
// final DateTime dateTime = DateUtil.tomorrow();
// String tomorrow = DateUtil.format(dateTime, "yyyy-MM-dd");
// // 后天日期
// final DateTime dateTime2 = DateUtil.offsetDay(date, 2);
// final String afterDay = DateUtil.format(dateTime2, "yyyy-MM-dd");
// // 今天星期几
// final int week = DateUtil.thisDayOfWeek();
// final DateTime nextWeek = DateUtil.nextWeek();
// serverTime.put("now",DateUtil.now());
// serverTime.put("today",today);
// serverTime.put("tomorrow",tomorrow);
// serverTime.put("afterDay",afterDay);
// serverTime.put("week",week);
// serverTime.put("nextWeek",nextWeek);
return success(vo);
}
@@ -401,19 +411,15 @@ public class WebsiteController extends BaseController {
@ApiOperation("查询全部网站信息记录表")
@GetMapping()
public ApiResult<List<Website>> list(WebsiteParam param) {
PageParam<Website, WebsiteParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(websiteService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(websiteService.listRel(param));
return success(websiteService.listRel(param));
}
@ApiOperation("根据id查询网站信息记录表")
@GetMapping("/{id}")
public ApiResult<Website> get(@PathVariable("id") Integer id) {
return success(websiteService.getById(id));
// 使用关联查询
//return success(websiteService.getByIdRel(id));
return success(websiteService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('cms:website:save')")
@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 网站导航记录表
@@ -114,4 +115,8 @@ public class Navigation implements Serializable {
@TableField(exist = false)
private String pageName;
@ApiModelProperty("子菜单")
@TableField(exist = false)
private List<Navigation> children;
}
@@ -1,6 +1,7 @@
package com.gxwebsoft.cms.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.gxwebsoft.common.system.entity.Menu;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.entity.UserInfo;
import com.gxwebsoft.oa.entity.Link;
@@ -10,11 +11,13 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.poi.ss.formula.functions.T;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 网站信息记录表
@@ -145,6 +148,19 @@ public class Website implements Serializable {
@TableField(exist = false)
private List<Navigation> navigations;
@ApiModelProperty(value = "顶部菜单")
@TableField(exist = false)
private List<Navigation> topNavs;
@ApiModelProperty(value = "底部菜单")
@TableField(exist = false)
private List<Navigation> bottomNavs;
@ApiModelProperty(value = "幻灯片广告")
@TableField(exist = false)
private List<String> slide;
@ApiModelProperty(value = "站点广告")
@TableField(exist = false)
private List<Ad> ads;
@@ -153,25 +169,25 @@ public class Website implements Serializable {
@TableField(exist = false)
private String layout;
@ApiModelProperty(value = "文章分类")
@TableField(exist = false)
private List<ArticleCategory> categoryList;
// @ApiModelProperty(value = "文章分类")
// @TableField(exist = false)
// private List<ArticleCategory> categoryList;
@ApiModelProperty(value = "友情链接")
@TableField(exist = false)
private List<Link> links;
@ApiModelProperty(value = "用户信息")
@TableField(exist = false)
private User userInfo;
// @ApiModelProperty(value = "用户信息")
// @TableField(exist = false)
// private User userInfo;
@ApiModelProperty(value = "商户信息")
@TableField(exist = false)
private Merchant merchant;
@ApiModelProperty(value = "商户账号")
@TableField(exist = false)
private MerchantAccount merchantAccount;
// @ApiModelProperty(value = "商户信息")
// @TableField(exist = false)
// private Merchant merchant;
//
// @ApiModelProperty(value = "商户账号")
// @TableField(exist = false)
// private MerchantAccount merchantAccount;
@ApiModelProperty(value = "配置信息")
@TableField(exist = false)
@@ -1,5 +1,6 @@
package com.gxwebsoft.oa.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.utils.BtUtil;
@@ -7,6 +8,7 @@ import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Role;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.oa.entity.Assets;
import com.gxwebsoft.oa.entity.AssetsUser;
@@ -19,6 +21,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -44,24 +47,54 @@ public class AssetsController extends BaseController {
@ApiOperation("统计信息")
@GetMapping("/data")
public ApiResult<Map<String, Integer>> data() {
final User loginUser = getLoginUser();
final Integer userId = loginUser.getUserId();
final List<String> collect1 = loginUser.getRoles().stream().map(Role::getRoleCode).collect(Collectors.toList());
Map<String, Integer> data = new HashMap<>();
if (collect1.contains("superAdmin") || collect1.contains("admin")) {
Integer totalNum = assetsService.count(
new LambdaQueryWrapper<Assets>()
);
Integer totalNum1 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.gt(Assets::getEndTime, LocalDateTime.now())
// .eq(Assets::getStatus, "运行中")
);
Integer totalNum2 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.lt(Assets::getEndTime, LocalDateTime.now())
);
Integer totalNum3 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.eq(Assets::getStatus, "已销毁")
);
data.put("totalNum", totalNum);
data.put("totalNum1", totalNum1);
data.put("totalNum2", totalNum2);
data.put("totalNum3", totalNum3);
return success(data);
}
// 非管理员
final List<AssetsUser> list = assetsUserService.list(new LambdaQueryWrapper<AssetsUser>().eq(AssetsUser::getUserId, userId));
final Set<Integer> collect = list.stream().map(AssetsUser::getAssetsId).collect(Collectors.toSet());
Integer totalNum = assetsService.count(
new LambdaQueryWrapper<Assets>()
new LambdaQueryWrapper<Assets>().in(Assets::getAssetsId,collect)
);
Integer totalNum1 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.eq(Assets::getStatus, "运行中")
.gt(Assets::getEndTime, LocalDateTime.now())
.in(Assets::getAssetsId,collect)
);
Integer totalNum2 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.eq(Assets::getStatus, "已到期")
.lt(Assets::getEndTime, LocalDateTime.now())
.in(Assets::getAssetsId,collect)
);
Integer totalNum3 = assetsService.count(
new LambdaQueryWrapper<Assets>()
.eq(Assets::getStatus, "已销毁")
.in(Assets::getAssetsId,collect)
);
data.put("totalNum", totalNum);
data.put("totalNum1", totalNum1);
data.put("totalNum2", totalNum2);
@@ -74,26 +107,28 @@ public class AssetsController extends BaseController {
public ApiResult<PageResult<Assets>> page(AssetsParam param) {
final User loginUser = getLoginUser();
final Integer userId = loginUser.getUserId();
loginUser.getRoles().forEach(d -> {
if(!StrUtil.equals(d.getRoleCode(),"superAdmin") && !StrUtil.equals(d.getRoleCode(),"admin")){
// 非管理员按项目成员权限显示
param.setSceneType("NotAdministrator");
final List<AssetsUser> list = assetsUserService.list(new LambdaQueryWrapper<AssetsUser>().eq(AssetsUser::getUserId, userId));
final Set<Integer> collect = list.stream().map(AssetsUser::getAssetsId).collect(Collectors.toSet());
if(!CollectionUtils.isEmpty(collect)){
param.setAssetsIds(collect);
}
}
});
// 非管理员并且无分配资源
if(param.getSceneType() != null && param.getSceneType().equals("NotAdministrator") && CollectionUtils.isEmpty(param.getAssetsIds())){
final PageResult<Assets> result = new PageResult<>();
result.setList(new ArrayList<>());
result.setCount(0L);
return success(result);
final List<String> collect1 = loginUser.getRoles().stream().map(Role::getRoleCode).collect(Collectors.toList());
if (param.getStatus() != null) {
if (param.getStatus().equals("运行中")) {
param.setStartTime(LocalDateTime.now());
param.setStatus(null);
}
if (param.getStatus().equals("已到期")) {
param.setEndTime(LocalDateTime.now());
param.setStatus(null);
}
}
if (collect1.contains("superAdmin") || collect1.contains("admin")) {
// 返回查询结果
return success(assetsService.pageRel(param));
}
final List<AssetsUser> list = assetsUserService.list(new LambdaQueryWrapper<AssetsUser>().eq(AssetsUser::getUserId, userId));
final Set<Integer> collect = list.stream().map(AssetsUser::getAssetsId).collect(Collectors.toSet());
if(!CollectionUtils.isEmpty(collect)){
param.setAssetsIds(collect);
}
return success(assetsService.pageRel(param));
}
@ApiOperation("查询全部服务器资产记录表")
@@ -78,10 +78,10 @@
AND a.content LIKE CONCAT('%', #{param.content}, '%')
</if>
<if test="param.startTime != null">
AND a.start_time LIKE CONCAT('%', #{param.startTime}, '%')
AND a.end_time &gt;= #{param.startTime}
</if>
<if test="param.endTime != null">
AND a.end_time LIKE CONCAT('%', #{param.endTime}, '%')
AND a.end_time &lt;= #{param.endTime}
</if>
<if test="param.isTop != null">
AND a.is_top LIKE CONCAT('%', #{param.isTop}, '%')
@@ -122,6 +122,12 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.assetsIds != null">
AND a.assets_id IN
<foreach collection="param.assetsIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.keywords != null">
AND (a.code LIKE CONCAT('%', #{param.keywords}, '%')
OR a.name LIKE CONCAT('%', #{param.keywords}, '%')
@@ -11,6 +11,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Set;
/**
@@ -101,10 +103,12 @@ public class AssetsParam extends BaseParam {
private String content;
@ApiModelProperty(value = "购买时间")
private String startTime;
@QueryField(type = QueryType.GE)
private LocalDateTime startTime;
@ApiModelProperty(value = "到期时间")
private String endTime;
@QueryField(type = QueryType.LE)
private LocalDateTime endTime;
@ApiModelProperty(value = "置顶状态")
private String isTop;
@@ -60,6 +60,10 @@
</if>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
OR a.phone LIKE CONCAT('%', #{param.keywords}, '%')
OR a.nickname LIKE CONCAT('%', #{param.keywords}, '%')
OR a.real_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.id_card LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
@@ -34,7 +34,7 @@ public class OrderInfoTask extends BaseController {
/**
* 自动处理过期订单任务
*/
// @Scheduled(cron="*/10 * * * * *")
@Scheduled(cron="*/10 * * * * *")
@Transactional(rollbackFor = {Exception.class})
public void settledExpirationOrder() {
final Order order = new Order();
@@ -57,7 +57,7 @@ public class OrderInfoTask extends BaseController {
* 自动处理过期订单任务(游泳馆专用)
* Scheduled(cron="0 30 21 * * ?")
*/
// @Scheduled(cron="*/30 * * * * *")
@Scheduled(cron="*/30 * * * * *")
@Transactional(rollbackFor = {Exception.class})
public void settledExpirationOrderBy3028() {
final Order order = new Order();
@@ -32,7 +32,7 @@ public class OrderTask extends BaseController {
/**
* 自动处理过期订单任务
*/
// @Scheduled(fixedDelay = 2000, initialDelay = 2000)
@Scheduled(fixedDelay = 2000, initialDelay = 2000)
@Transactional(rollbackFor = {Exception.class})
public void settledExpirationOrder() {
final OrderParam p = new OrderParam();