init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk;
|
||||
|
||||
import org.springblade.core.cloud.client.BladeCloudApplication;
|
||||
import org.springblade.core.launch.BladeApplication;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
|
||||
/**
|
||||
* Desk启动器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@BladeCloudApplication
|
||||
public class DeskApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BladeApplication.run(AppConstant.APPLICATION_DESK_NAME, DeskApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.controller;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.cache.CacheNames;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.desk.entity.ProcessLeave;
|
||||
import org.springblade.desk.service.ILeaveService;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@Hidden
|
||||
@RestController
|
||||
@RequestMapping("/process/leave")
|
||||
@AllArgsConstructor
|
||||
public class LeaveController extends BladeController implements CacheNames {
|
||||
|
||||
private final ILeaveService leaveService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param businessId 主键
|
||||
*/
|
||||
@GetMapping("detail")
|
||||
public R<ProcessLeave> detail(Long businessId) {
|
||||
ProcessLeave detail = leaveService.getById(businessId);
|
||||
detail.getFlow().setAssigneeName(UserCache.getUser(detail.getCreateUser()).getName());
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改
|
||||
*
|
||||
* @param leave 请假信息
|
||||
*/
|
||||
@PostMapping("start-process")
|
||||
public R startProcess(@RequestBody ProcessLeave leave) {
|
||||
return R.status(leaveService.startProcess(leave));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.BladePage;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.tenant.annotation.TenantDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.jackson.BladeView;
|
||||
import org.springblade.core.tool.jackson.Views;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.xss.annotation.XssIgnore;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.feign.INoticeClient;
|
||||
import org.springblade.desk.service.INoticeService;
|
||||
import org.springblade.desk.pojo.vo.NoticeVO;
|
||||
import org.springblade.desk.wrapper.NoticeWrapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@TenantDS
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@PreAuth(menu = "notice")
|
||||
@RequestMapping("notice")
|
||||
@Tag(name = "用户博客", description = "博客接口")
|
||||
public class NoticeController extends BladeController {
|
||||
|
||||
private final INoticeService noticeService;
|
||||
|
||||
private final INoticeClient noticeClient;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@BladeView(Views.Detail.class)
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "详情", description = "传入notice")
|
||||
public R<NoticeVO> detail(Notice notice) {
|
||||
Notice detail = noticeService.getOne(Condition.getQueryWrapper(notice));
|
||||
return R.data(NoticeWrapper.build().entityVO(detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@BladeView(Views.Summary.class)
|
||||
@Parameters({
|
||||
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||
})
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入notice")
|
||||
public R<IPage<NoticeVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> notice, Query query) {
|
||||
NoticeWrapper.build().noticeQuery(notice);
|
||||
IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
|
||||
return R.data(NoticeWrapper.build().pageVO(pages));
|
||||
}
|
||||
|
||||
/**
|
||||
* 多表联合查询自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@BladeView(Views.Summary.class)
|
||||
@Parameters({
|
||||
@Parameter(name = "category", description = "公告类型", in = ParameterIn.QUERY, schema = @Schema(type = "integer")),
|
||||
@Parameter(name = "title", description = "公告标题", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||
})
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "分页", description = "传入notice")
|
||||
public R<IPage<NoticeVO>> page(@Parameter(hidden = true) NoticeVO notice, Query query) {
|
||||
IPage<NoticeVO> pages = noticeService.selectNoticePage(Condition.getPage(query), notice);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增", description = "传入notice")
|
||||
public R save(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.save(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "修改", description = "传入notice")
|
||||
public R update(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.updateById(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改
|
||||
*/
|
||||
@XssIgnore
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "新增或修改", description = "传入notice")
|
||||
public R submit(@RequestBody Notice notice) {
|
||||
return R.status(noticeService.saveOrUpdate(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "逻辑删除", description = "传入notice")
|
||||
public R remove(@Parameter(description = "主键集合") @RequestParam String ids) {
|
||||
boolean temp = noticeService.deleteLogic(Func.toLongList(ids));
|
||||
return R.status(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程调用分页接口
|
||||
*/
|
||||
@GetMapping("/top")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "分页远程调用", description = "传入current,size")
|
||||
public R<BladePage<Notice>> top(@Parameter(description = "当前页") @RequestParam Integer current, @Parameter(description = "每页显示条数") @RequestParam Integer size) {
|
||||
BladePage<Notice> page = noticeClient.top(current, size);
|
||||
return R.data(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springblade.flow.core.pojo.entity.FlowEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 请假流程实体类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@TableName("blade_process_leave")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ProcessLeave extends FlowEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 流程定义id
|
||||
*/
|
||||
private String processDefinitionId;
|
||||
/**
|
||||
* 流程实例id
|
||||
*/
|
||||
private String processInstanceId;
|
||||
/**
|
||||
* 请假开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
/**
|
||||
* 请假结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
/**
|
||||
* 请假理由
|
||||
*/
|
||||
private String reason;
|
||||
/**
|
||||
* 审批人
|
||||
*/
|
||||
private String taskUser;
|
||||
/**
|
||||
* 流程申请时间
|
||||
*/
|
||||
private Date applyTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.feign;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.mp.support.BladePage;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.service.INoticeService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
||||
/**
|
||||
* Notice Feign
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@Hidden()
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class NoticeClient implements INoticeClient {
|
||||
|
||||
private final INoticeService service;
|
||||
|
||||
@Override
|
||||
@GetMapping(TOP)
|
||||
public BladePage<Notice> top(Integer current, Integer size) {
|
||||
Query query = new Query();
|
||||
query.setCurrent(current);
|
||||
query.setSize(size);
|
||||
IPage<Notice> page = service.page(Condition.getPage(query));
|
||||
return BladePage.of(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.desk.entity.ProcessLeave;
|
||||
|
||||
/**
|
||||
* Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface LeaveMapper extends BaseMapper<ProcessLeave> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.springblade.desk.mapper.LeaveMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.pojo.vo.NoticeVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||
|
||||
/**
|
||||
* 前N条数据
|
||||
*
|
||||
* @param number 数量
|
||||
* @return List<Notice>
|
||||
*/
|
||||
List<Notice> topList(Integer number);
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页
|
||||
* @param notice 实体
|
||||
* @return List<NoticeVO>
|
||||
*/
|
||||
List<NoticeVO> selectNoticePage(IPage page, NoticeVO notice);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.springblade.desk.mapper.NoticeMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="noticeResultMap" type="org.springblade.desk.pojo.entity.Notice">
|
||||
<result column="id" property="id"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="release_time" property="releaseTime"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="content" property="content"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="noticeVOResultMap" type="org.springblade.desk.pojo.vo.NoticeVO">
|
||||
<result column="id" property="id"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="release_time" property="releaseTime"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="content" property="content"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="topList" resultMap="noticeResultMap">
|
||||
select * from blade_notice limit #{number}
|
||||
</select>
|
||||
|
||||
<select id="selectNoticePage" resultMap="noticeVOResultMap">
|
||||
SELECT
|
||||
n.*,
|
||||
d.dict_value AS categoryName
|
||||
FROM
|
||||
blade_notice n
|
||||
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
|
||||
WHERE
|
||||
n.is_deleted = 0 and n.tenant_id = #{notice.tenantId}
|
||||
<if test="notice.title!=null">
|
||||
and n.title like concat(concat('%', #{notice.title}), '%')
|
||||
</if>
|
||||
<if test="notice.category!=null">
|
||||
and n.category = #{notice.category}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.service;
|
||||
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.desk.entity.ProcessLeave;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface ILeaveService extends BaseService<ProcessLeave> {
|
||||
|
||||
/**
|
||||
* 开启流程
|
||||
*
|
||||
* @param leave 请假实体
|
||||
* @return boolean
|
||||
*/
|
||||
boolean startProcess(ProcessLeave leave);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.pojo.vo.NoticeVO;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface INoticeService extends BaseService<Notice> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
* @param page
|
||||
* @param notice
|
||||
* @return
|
||||
*/
|
||||
IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.service.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.support.Kv;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.desk.entity.ProcessLeave;
|
||||
import org.springblade.desk.mapper.LeaveMapper;
|
||||
import org.springblade.desk.service.ILeaveService;
|
||||
import org.springblade.flow.core.constant.ProcessConstant;
|
||||
import org.springblade.flow.core.pojo.entity.BladeFlow;
|
||||
import org.springblade.flow.core.feign.IFlowClient;
|
||||
import org.springblade.flow.core.utils.FlowUtil;
|
||||
import org.springblade.flow.core.utils.TaskUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class LeaveServiceImpl extends BaseServiceImpl<LeaveMapper, ProcessLeave> implements ILeaveService {
|
||||
|
||||
private final IFlowClient flowClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
// @GlobalTransactional
|
||||
public boolean startProcess(ProcessLeave leave) {
|
||||
String businessTable = FlowUtil.getBusinessTable(ProcessConstant.LEAVE_KEY);
|
||||
if (Func.isEmpty(businessTable)) {
|
||||
throw new ServiceException("流程启动失败,未找到相关业务表");
|
||||
}
|
||||
if (Func.isEmpty(leave.getId())) {
|
||||
// 保存leave
|
||||
leave.setApplyTime(DateUtil.now());
|
||||
save(leave);
|
||||
// 启动流程
|
||||
Kv variables = Kv.create()
|
||||
.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName())
|
||||
.set("taskUser", TaskUtil.getTaskUser(leave.getTaskUser()))
|
||||
.set("days", DateUtil.between(leave.getStartTime(), leave.getEndTime()).toDays());
|
||||
R<BladeFlow> result = flowClient.startProcessInstanceById(leave.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(leave.getId())), variables);
|
||||
if (result.isSuccess()) {
|
||||
log.debug("流程已启动,流程ID:" + result.getData().getProcessInstanceId());
|
||||
// 返回流程id写入leave
|
||||
leave.setProcessInstanceId(result.getData().getProcessInstanceId());
|
||||
updateById(leave);
|
||||
} else {
|
||||
throw new ServiceException("开启流程失败");
|
||||
}
|
||||
} else {
|
||||
|
||||
updateById(leave);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.mapper.NoticeMapper;
|
||||
import org.springblade.desk.service.INoticeService;
|
||||
import org.springblade.desk.pojo.vo.NoticeVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
||||
|
||||
@Override
|
||||
public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice) {
|
||||
// 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入
|
||||
notice.setTenantId(AuthUtil.getTenantId());
|
||||
return page.setRecords(baseMapper.selectNoticePage(page, notice));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.desk.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.desk.pojo.entity.Notice;
|
||||
import org.springblade.desk.pojo.vo.NoticeVO;
|
||||
import org.springblade.system.cache.DictCache;
|
||||
import org.springblade.system.pojo.enums.DictEnum;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Notice包装类,返回视图层所需的字段
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class NoticeWrapper extends BaseEntityWrapper<Notice, NoticeVO> {
|
||||
|
||||
public static NoticeWrapper build() {
|
||||
return new NoticeWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoticeVO entityVO(Notice notice) {
|
||||
NoticeVO noticeVO = Objects.requireNonNull(BeanUtil.copyProperties(notice, NoticeVO.class));
|
||||
String dictValue = DictCache.getValue(DictEnum.NOTICE, noticeVO.getCategory());
|
||||
noticeVO.setCategoryName(dictValue);
|
||||
return noticeVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件处理
|
||||
*/
|
||||
public void noticeQuery(Map<String, Object> notice) {
|
||||
// 此场景仅在 pg数据库 map类型传参的情况下需要处理,entity传参已经包含数据类型,则无需关心
|
||||
// 针对 pg数据库 int类型字段查询需要强转的处理示例
|
||||
String searchKey = "category";
|
||||
if (Func.isNotEmpty(notice.get(searchKey))) {
|
||||
// 数据库字段为int类型,设置"="查询,具体查询参数请见 @org.springblade.core.mp.support.SqlKeyword
|
||||
notice.put(searchKey.concat("_equal"), Func.toInt(notice.get(searchKey)));
|
||||
// 默认"like"查询,pg数据库 场景会报错,所以将其删除
|
||||
notice.remove(searchKey);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#服务器端口
|
||||
server:
|
||||
port: 8105
|
||||
|
||||
#数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
url: ${blade.datasource.dev.url}
|
||||
username: ${blade.datasource.dev.username}
|
||||
password: ${blade.datasource.dev.password}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#服务器端口
|
||||
server:
|
||||
port: 8105
|
||||
|
||||
#数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
url: ${blade.datasource.prod.url}
|
||||
username: ${blade.datasource.prod.username}
|
||||
password: ${blade.datasource.prod.password}
|
||||
@@ -0,0 +1,10 @@
|
||||
#服务器端口
|
||||
server:
|
||||
port: 8105
|
||||
|
||||
#数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
url: ${blade.datasource.test.url}
|
||||
username: ${blade.datasource.test.username}
|
||||
password: ${blade.datasource.test.password}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.springblade.test.secure.SecureTestBuilder.*;
|
||||
|
||||
/**
|
||||
* Secure安全框架 - 基础认证测试类
|
||||
* 测试HTTP Basic Authentication
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureBasicTest {
|
||||
|
||||
/**
|
||||
* Basic认证用户名
|
||||
*/
|
||||
private static final String BASIC_USERNAME = "admin";
|
||||
|
||||
/**
|
||||
* Basic认证密码
|
||||
*/
|
||||
private static final String BASIC_PASSWORD = "admin123";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置日志级别,方便调试
|
||||
initHttpLog();
|
||||
|
||||
printHeader("Secure 基础认证测试");
|
||||
|
||||
// 测试1: 获取Token
|
||||
String accessToken = getToken();
|
||||
|
||||
// 测试2: 使用Token调用受保护API
|
||||
if (StringUtil.isNotBlank(accessToken)) {
|
||||
testCallApiWithToken(accessToken);
|
||||
}
|
||||
|
||||
// 测试3: Basic认证调用受保护API
|
||||
testBasicAuth();
|
||||
|
||||
printFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
private static void testCallApiWithToken(String accessToken) {
|
||||
printSection(2, "使用 Token 调用受保护 API");
|
||||
callApiWithToken("/blade-desk/notice/list", accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试Basic认证调用受保护API
|
||||
* 认证原理: Authorization: Basic {Base64(username:password)}
|
||||
*/
|
||||
private static void testBasicAuth() {
|
||||
printSection(1, "Basic 认证调用受保护 API");
|
||||
|
||||
try {
|
||||
// 1. 生成Basic Auth凭证
|
||||
String credentials = BASIC_USERNAME + ":" + BASIC_PASSWORD;
|
||||
String encoded = Base64.getEncoder().encodeToString(credentials.getBytes());
|
||||
String basicAuth = "Basic " + encoded;
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Basic Auth Parameters:");
|
||||
printKeyValue(" username", BASIC_USERNAME);
|
||||
printKeyValue(" password", BASIC_PASSWORD);
|
||||
printKeyValue(" credentials", credentials);
|
||||
printKeyValue(" encoded", encoded);
|
||||
printKeyValue(" Authorization", basicAuth);
|
||||
|
||||
// 2. 发送带Basic认证的请求
|
||||
String response = HttpRequest.get(BASE_URL + "/blade-test/info/basic")
|
||||
.addHeader("Authorization", basicAuth)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("Basic 认证请求发送成功");
|
||||
} catch (Exception e) {
|
||||
printError("Basic 认证异常 - " + e.getMessage());
|
||||
printWarning("如果Basic认证接口未配置或不存在会报错,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springblade.test.secure.SecureTestBuilder.*;
|
||||
|
||||
/**
|
||||
* Secure安全框架 - 签名认证测试类
|
||||
* 测试获取Token以及签名认证(nonce+timestamp)
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureSignTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置日志级别,方便调试
|
||||
initHttpLog();
|
||||
|
||||
printHeader("Secure 签名认证测试");
|
||||
|
||||
// 测试1: 获取Token
|
||||
String accessToken = getToken();
|
||||
|
||||
// 测试2: 使用Token调用受保护API
|
||||
if (StringUtil.isNotBlank(accessToken)) {
|
||||
testCallApiWithToken(accessToken);
|
||||
}
|
||||
|
||||
// 测试3: 签名认证(nonce+timestamp)
|
||||
testSignAuth();
|
||||
|
||||
printFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
private static void testCallApiWithToken(String accessToken) {
|
||||
printSection(2, "使用 Token 调用受保护 API");
|
||||
callApiWithToken("/blade-desk/notice/list", accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试签名认证(nonce+timestamp)
|
||||
* 签名规则: signature = SHA1(timestamp + nonce)
|
||||
*/
|
||||
private static void testSignAuth() {
|
||||
printSection(3, "签名认证 (nonce + timestamp)");
|
||||
|
||||
try {
|
||||
// 1. 生成签名参数
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String nonce = UUID.randomUUID().toString().replace("-", "");
|
||||
String signature = DigestUtil.sha1Hex(timestamp + nonce);
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Signature Parameters:");
|
||||
printKeyValue(" timestamp", timestamp);
|
||||
printKeyValue(" nonce", nonce);
|
||||
printKeyValue(" signature", signature);
|
||||
printKeyValue(" algorithm", "SHA1(timestamp + nonce)");
|
||||
|
||||
// 2. 发送带签名的请求
|
||||
String response = HttpRequest.get(BASE_URL + "/blade-test/info/sign")
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.addHeader("timestamp", timestamp)
|
||||
.addHeader("nonce", nonce)
|
||||
.addHeader("signature", signature)
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("签名认证请求发送成功");
|
||||
} catch (Exception e) {
|
||||
printError("签名认证异常 - " + e.getMessage());
|
||||
printWarning("如果签名认证接口未配置或不存在会报错,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.LogLevel;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Secure安全框架测试工具类
|
||||
* 提供通用的Token获取、API调用及打印辅助方法
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureTestBuilder {
|
||||
|
||||
/**
|
||||
* 分隔线
|
||||
*/
|
||||
public static final String LINE = "─".repeat(60);
|
||||
public static final String DOUBLE_LINE = "═".repeat(60);
|
||||
|
||||
/**
|
||||
* 服务地址
|
||||
*/
|
||||
public static final String BASE_URL = "http://localhost";
|
||||
|
||||
/**
|
||||
* 客户端认证信息 (saber3:saber3_secret 的 Base64 编码)
|
||||
*/
|
||||
public static final String CLIENT_AUTH = "Basic c2FiZXIzOnNhYmVyM19zZWNyZXQ=";
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
public static final String TENANT_ID = "000000";
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public static final String USERNAME = "admin";
|
||||
|
||||
/**
|
||||
* 密码(国密加密后的字符串,具体见 @org.springblade.test.sm.Sm2Test)
|
||||
*/
|
||||
public static final String PASSWORD = "";
|
||||
|
||||
/**
|
||||
* 初始化HTTP日志级别
|
||||
*/
|
||||
public static void initHttpLog() {
|
||||
HttpRequest.setGlobalLog(LogLevel.BODY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试头部
|
||||
*
|
||||
* @param title 测试标题
|
||||
*/
|
||||
public static void printHeader(String title) {
|
||||
System.out.println();
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println(" " + title);
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试尾部
|
||||
*/
|
||||
public static void printFooter() {
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println(" 测试执行完毕");
|
||||
System.out.println(DOUBLE_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试章节
|
||||
*
|
||||
* @param testNo 测试编号
|
||||
* @param title 章节标题
|
||||
*/
|
||||
public static void printSection(int testNo, String title) {
|
||||
System.out.println(LINE);
|
||||
System.out.printf(" [TEST-%d] %s%n", testNo, title);
|
||||
System.out.println(LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印键值对
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public static void printKeyValue(String key, Object value) {
|
||||
System.out.printf(" %-16s: %s%n", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印成功消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printSuccess(String message) {
|
||||
System.out.printf("%n [SUCCESS] %s%n%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印错误消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printError(String message) {
|
||||
System.out.printf("%n [FAILED] %s%n%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印警告消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printWarning(String message) {
|
||||
System.out.printf(" [WARN] %s%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token
|
||||
* 通用方法,供签名认证等场景复用
|
||||
*
|
||||
* @return accessToken,获取失败返回null
|
||||
*/
|
||||
public static String getToken() {
|
||||
printSection(1, "获取 Token");
|
||||
|
||||
try {
|
||||
String response = HttpRequest.post(BASE_URL + "/blade-auth/oauth/token")
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.formBuilder()
|
||||
.add("grant_type", "password")
|
||||
.add("tenant_id", TENANT_ID)
|
||||
.add("username", USERNAME)
|
||||
.add("password", PASSWORD)
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
|
||||
if (StringUtil.isNotBlank(response)) {
|
||||
Map<String, Object> result = JsonUtil.readMap(response, String.class, Object.class);
|
||||
if (result != null && result.containsKey("access_token")) {
|
||||
String accessToken = (String) result.get("access_token");
|
||||
String tokenType = (String) result.get("token_type");
|
||||
Object expiresIn = result.get("expires_in");
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Token Details:");
|
||||
printKeyValue(" token_type", tokenType);
|
||||
printKeyValue(" access_token", accessToken.substring(0, Math.min(50, accessToken.length())) + "...");
|
||||
printKeyValue(" expires_in", expiresIn + " seconds");
|
||||
|
||||
printSuccess("Token 获取成功");
|
||||
return accessToken;
|
||||
} else {
|
||||
printError("Token 获取失败 - " + result);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
printError("Token 获取异常 - " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param url API地址(相对路径,如 /blade-desk/notice/list)
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
public static void callApiWithToken(String url, String accessToken) {
|
||||
try {
|
||||
String response = HttpRequest.get(BASE_URL + url)
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Blade-Auth", "bearer " + accessToken)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("API 调用成功");
|
||||
} catch (Exception e) {
|
||||
printError("API 调用异常 - " + e.getMessage());
|
||||
printWarning("如果接口不存在会返回 404,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package org.springblade.test.sm;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springblade.core.tool.utils.SM2Util;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* SM2Test
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class Sm2Test {
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
System.out.println("================== SM2 加解密与签名测试 ==================");
|
||||
|
||||
// 1. 生成SM2密钥对
|
||||
AsymmetricCipherKeyPair keyPair = SM2Util.generateKeyPair();
|
||||
String publicKeyString = SM2Util.getPublicKeyString(keyPair);
|
||||
String privateKeyString = SM2Util.getPrivateKeyString(keyPair);
|
||||
System.out.println("1. 生成SM2密钥对:");
|
||||
System.out.println(" 公钥 (16进制): " + publicKeyString);
|
||||
System.out.println(" 公钥长度: " + publicKeyString.length());
|
||||
System.out.println(" 私钥 (16进制): " + privateKeyString);
|
||||
System.out.println(" 私钥长度: " + privateKeyString.length());
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 2. 从字符串恢复密钥
|
||||
System.out.println("2. 从字符串恢复密钥...");
|
||||
ECPublicKeyParameters publicKey = SM2Util.stringToPublicKey(publicKeyString);
|
||||
ECPrivateKeyParameters privateKey = SM2Util.stringToPrivateKey(privateKeyString);
|
||||
System.out.println(" 密钥恢复成功!");
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 3. 准备待加密的原文
|
||||
String originalText = "Hello BladeX! 这是一段需要被国密SM2算法加密和签名的敏感信息。1234567890";
|
||||
System.out.println("3. 待加密的原文: " + originalText);
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 4. 执行加密
|
||||
System.out.println("4. 正在执行加密操作...");
|
||||
byte[] encryptedData = SM2Util.encrypt(originalText, publicKey);
|
||||
if (encryptedData != null && encryptedData.length > 0) {
|
||||
System.out.println(" 加密成功!");
|
||||
System.out.println(" 加密后的密文 (16进制): " + Hex.toHexString(encryptedData));
|
||||
System.out.println(" 密文长度: " + encryptedData.length + " 字节");
|
||||
} else {
|
||||
System.out.println(" 加密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 5. 执行解密
|
||||
System.out.println("5. 正在执行解密操作...");
|
||||
String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
||||
if (StringUtil.isNotBlank(decryptedText)) {
|
||||
System.out.println(" 解密成功!");
|
||||
System.out.println(" 解密后的明文: " + decryptedText);
|
||||
} else {
|
||||
System.out.println(" 解密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 6. 执行数字签名
|
||||
System.out.println("6. 正在执行数字签名...");
|
||||
byte[] signature = SM2Util.sign(originalText, privateKey);
|
||||
if (signature != null && signature.length > 0) {
|
||||
System.out.println(" 签名成功!");
|
||||
System.out.println(" 数字签名 (16进制): " + Hex.toHexString(signature));
|
||||
System.out.println(" 签名长度: " + signature.length + " 字节");
|
||||
} else {
|
||||
System.out.println(" 签名失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 7. 验证签名
|
||||
System.out.println("7. 正在验证数字签名...");
|
||||
boolean isVerified = SM2Util.verify(originalText, signature, publicKey);
|
||||
System.out.println(" 签名验证结果: " + (isVerified ? "有效" : "无效"));
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 8. 校验加解密结果
|
||||
System.out.println("8. 正在校验原文与解密后的明文是否一致...");
|
||||
boolean isDecryptMatch = originalText.equals(decryptedText);
|
||||
System.out.println(" 加解密校验结果: " + (isDecryptMatch ? "一致" : "不一致"));
|
||||
|
||||
System.out.println("==================================================");
|
||||
|
||||
// 9. 最终结果汇总
|
||||
if (isDecryptMatch && isVerified) {
|
||||
System.out.println("\n[成功] SM2加解密与签名流程验证通过!");
|
||||
System.out.println(" ✓ 密钥对生成成功");
|
||||
System.out.println(" ✓ 加解密功能正常");
|
||||
System.out.println(" ✓ 数字签名验证通过");
|
||||
} else {
|
||||
System.out.println("\n[失败] SM2加解密与签名流程验证失败!");
|
||||
if (!isDecryptMatch) {
|
||||
System.out.println(" ✗ 加解密校验失败");
|
||||
}
|
||||
if (!isVerified) {
|
||||
System.out.println(" ✗ 数字签名验证失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.springblade.test.sm;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springblade.core.tool.utils.SM4Util;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* Sm4Test
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class Sm4Test {
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
System.out.println("================== SM4 加解密测试 ==================");
|
||||
|
||||
// 1. 生成SM4密钥
|
||||
String sm4Key = SM4Util.generateKey();
|
||||
System.out.println("1. 生成SM4密钥 (16进制): " + sm4Key);
|
||||
System.out.println(" 密钥长度 (Hex): " + sm4Key.length());
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 2. 准备待加密的原文
|
||||
String originalText = "Hello BladeX! 这是一段需要被国密SM4算法加密的敏感信息。1234567890";
|
||||
System.out.println("2. 待加密的原文: " + originalText);
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 3. 执行加密
|
||||
System.out.println("3. 正在执行加密操作...");
|
||||
String encryptedText = SM4Util.encrypt(originalText, sm4Key);
|
||||
if (StringUtil.isNotBlank(encryptedText)) {
|
||||
System.out.println(" 加密成功!");
|
||||
System.out.println(" 加密后的密文 (16进制): " + encryptedText);
|
||||
} else {
|
||||
System.out.println(" 加密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 4. 执行解密
|
||||
System.out.println("4. 正在执行解密操作...");
|
||||
String decryptedText = SM4Util.decrypt(encryptedText, sm4Key);
|
||||
if (StringUtil.isNotBlank(decryptedText)) {
|
||||
System.out.println(" 解密成功!");
|
||||
System.out.println(" 解密后的明文: " + decryptedText);
|
||||
} else {
|
||||
System.out.println(" 解密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 5. 校验结果
|
||||
System.out.println("5. 正在校验原文与解密后的明文是否一致...");
|
||||
boolean isMatch = originalText.equals(decryptedText);
|
||||
System.out.println(" 校验结果: " + (isMatch ? "一致" : "不一致"));
|
||||
|
||||
System.out.println("==================================================");
|
||||
|
||||
if (isMatch) {
|
||||
System.out.println("\n[成功] SM4加解密流程验证通过!");
|
||||
} else {
|
||||
System.out.println("\n[失败] SM4加解密流程验证失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user