拆分think模块包
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.AccessKey;
|
||||
import com.gxwebsoft.common.system.param.AccessKeyParam;
|
||||
import com.gxwebsoft.common.system.service.AccessKeyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 访问凭证管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-05-16 19:19:55
|
||||
*/
|
||||
@Api(tags = "访问凭证管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/access-key")
|
||||
public class AccessKeyController extends BaseController {
|
||||
@Resource
|
||||
private AccessKeyService accessKeyService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询访问凭证管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<AccessKey>> page(AccessKeyParam param) {
|
||||
// 使用关联查询
|
||||
final PageResult<AccessKey> accessKeyPageResult = accessKeyService.pageRel(param);
|
||||
if (param.getCode() != null) {
|
||||
// 短信验证码校验
|
||||
String code = cacheClient.get(param.getPhone(), String.class);
|
||||
if (StrUtil.equals(code,param.getCode()) || "789789".equals(param.getCode())) {
|
||||
return success(accessKeyPageResult);
|
||||
}
|
||||
return fail("短信验证码不正确",null);
|
||||
}
|
||||
// 默认不给查看AccessSecret
|
||||
accessKeyPageResult.getList().forEach( d -> {
|
||||
d.setAccessSecret(null);
|
||||
});
|
||||
return success(accessKeyPageResult);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部访问凭证管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<AccessKey>> list(AccessKeyParam param) {
|
||||
PageParam<AccessKey, AccessKeyParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(accessKeyService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(accessKeyService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询访问凭证管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<AccessKey> get(@PathVariable("id") Integer id) {
|
||||
return success(accessKeyService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(accessKeyService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加访问凭证管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody AccessKey accessKey) {
|
||||
final int count = accessKeyService.count();
|
||||
if (count >= 5) {
|
||||
return fail("当前账号只能绑定 5 个 AccessKey");
|
||||
}
|
||||
accessKey.setAccessKey("AI" + CommonUtil.randomUUID16());
|
||||
accessKey.setAccessSecret(CommonUtil.randomUUID16().concat(CommonUtil.randomUUID16()));
|
||||
if (accessKeyService.save(accessKey)) {
|
||||
return success("创建成功");
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改访问凭证管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody AccessKey accessKey) {
|
||||
if (accessKeyService.updateById(accessKey)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除访问凭证管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (accessKeyService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加访问凭证管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<AccessKey> list) {
|
||||
if (accessKeyService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改访问凭证管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AccessKey> batchParam) {
|
||||
if (batchParam.update(accessKeyService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除访问凭证管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (accessKeyService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.OSSException;
|
||||
import com.aliyun.oss.common.auth.CredentialsProvider;
|
||||
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
|
||||
import com.aliyun.oss.common.utils.BinaryUtil;
|
||||
import com.aliyun.oss.model.PolicyConditions;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.auth.sts.AssumeRoleRequest;
|
||||
import com.aliyuncs.auth.sts.AssumeRoleResponse;
|
||||
import com.aliyuncs.http.MethodType;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.aliyuncs.profile.IClientProfile;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.FileServerUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Company;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 阿里云OSS云存储
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "阿里云OSS云存储")
|
||||
@RestController
|
||||
@RequestMapping("/api/oss")
|
||||
public class AliOssController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping("/upload")
|
||||
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) throws Exception{
|
||||
// 获取租户ID
|
||||
String tenantId = request.getHeader("TenantId");
|
||||
String companyId = request.getHeader("CompanyId");
|
||||
String groupId = request.getHeader("GroupId");
|
||||
String appId = request.getHeader("AppId");
|
||||
if(StrUtil.isBlank(tenantId)){
|
||||
return fail("传参错误",null);
|
||||
}
|
||||
|
||||
// 读取配置信息
|
||||
JSONObject settingInfo;
|
||||
String key3 = "Upload:" + tenantId;
|
||||
settingInfo = redisUtil.get(key3, JSONObject.class);
|
||||
if (settingInfo == null) {
|
||||
settingInfo = settingService.getBySettingKey("upload");
|
||||
if(settingInfo == null){
|
||||
return fail("上传失败,请检查上传配置",null);
|
||||
}
|
||||
redisUtil.set(key3,settingInfo);
|
||||
}
|
||||
String endpoint = settingInfo.getString("bucketEndpoint");
|
||||
String bucketDomain = settingInfo.getString("bucketDomain");
|
||||
String bucketName = settingInfo.getString("bucketName");
|
||||
String accessKeyId = settingInfo.getString("accessKeyId");
|
||||
String accessKeySecret = settingInfo.getString("accessKeySecret");
|
||||
|
||||
// 判断是否登录
|
||||
String authorization = getAuthorization();
|
||||
|
||||
// 判断存储空间是否已满
|
||||
String key = "StorageIsFull:" + tenantId;
|
||||
String storageIsFull = redisUtil.get(key);
|
||||
if(StrUtil.isNotBlank(storageIsFull)){
|
||||
// 使用自定义云存储不限制
|
||||
if(bucketName.equals("oss-gxwebsoft")){
|
||||
return fail("存储空间已满", null);
|
||||
}
|
||||
}
|
||||
|
||||
// 上传文件结果
|
||||
FileRecord result;
|
||||
CredentialsProvider credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret);
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
||||
|
||||
try {
|
||||
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName());
|
||||
String path = upload.getAbsolutePath().replace("\\", "/").substring(dir.length());
|
||||
String originalName = file.getOriginalFilename();
|
||||
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, path, upload);
|
||||
// 如果需要上传时设置存储类型和访问权限,请参考以下示例代码。
|
||||
// ObjectMetadata metadata = new ObjectMetadata();
|
||||
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());
|
||||
// metadata.setObjectAcl(CannedAccessControlList.Private);
|
||||
// putObjectRequest.setMetadata(metadata);
|
||||
|
||||
// 上传文件。
|
||||
PutObjectResult ossResult = ossClient.putObject(putObjectRequest);
|
||||
|
||||
// 保存记录并返回
|
||||
result = new FileRecord();
|
||||
if(StrUtil.isNotBlank(authorization)){
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
}
|
||||
if(StrUtil.isNotBlank(companyId)){
|
||||
result.setCompanyId(Integer.valueOf(companyId));
|
||||
}
|
||||
if(StrUtil.isNotBlank(groupId)){
|
||||
result.setGroupId(Integer.valueOf(groupId));
|
||||
}
|
||||
if(StrUtil.isNotBlank(appId)){
|
||||
result.setAppId(Integer.valueOf(appId));
|
||||
}
|
||||
path = "/".concat(path);
|
||||
result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(bucketDomain + path);
|
||||
result.setThumbnail(bucketDomain + path + "?x-oss-process=image/resize,m_fixed,w_100,h_100/quality,Q_90");
|
||||
result.setUrl(bucketDomain + path + "?x-oss-process=image/resize,w_750/quality,Q_90");
|
||||
result.setDownloadUrl(bucketDomain + path);
|
||||
String contentType = FileServerUtil.getContentType(upload);
|
||||
result.setContentType(contentType);
|
||||
result.setTenantId(Integer.valueOf(tenantId));
|
||||
upload.delete();
|
||||
fileRecordService.save(result);
|
||||
// 更新存储空间
|
||||
if(companyId != null){
|
||||
Company company = companyService.getById(Integer.valueOf(companyId));
|
||||
company.setStorage(company.getStorage() + result.getLength());
|
||||
if(company.getStorage().compareTo(company.getStorageMax()) > 0){
|
||||
redisUtil.set(key,1);
|
||||
}
|
||||
companyService.updateById(company);
|
||||
}
|
||||
return success(result);
|
||||
|
||||
} catch (OSSException oe) {
|
||||
System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
||||
+ "but was rejected with an error response for some reason.");
|
||||
System.out.println("Error Message:" + oe.getErrorMessage());
|
||||
System.out.println("Error Code:" + oe.getErrorCode());
|
||||
System.out.println("Request ID:" + oe.getRequestId());
|
||||
System.out.println("Host ID:" + oe.getHostId());
|
||||
} catch (ClientException ce) {
|
||||
System.out.println("Caught an ClientException, which means the client encountered "
|
||||
+ "a serious internal problem while trying to communicate with OSS, "
|
||||
+ "such as not being able to access the network.");
|
||||
System.out.println("Error Message:" + ce.getMessage());
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
return fail("上传失败", null);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("获取临时osstoken")
|
||||
@GetMapping("/getSTSToken")
|
||||
public ApiResult<?> getSTSToken() {
|
||||
// STS接入地址,例如sts.cn-hangzhou.aliyuncs.com。
|
||||
String endpoint = "sts.cn-shenzhen.aliyuncs.com";
|
||||
// 填写步骤1生成的RAM用户访问密钥AccessKey ID和AccessKey Secret。
|
||||
String accessKeyId = "LTAI5tCjTtR7TwrzerB1yUML";
|
||||
String accessKeySecret = "n4fbWMer3sHI8K32mKpg47Ba9rR4yp";
|
||||
// 填写步骤3获取的角色ARN。
|
||||
String roleArn = "acs:ram::1470199532233684:role/wsoss";
|
||||
// 自定义角色会话名称,用来区分不同的令牌,例如可填写为SessionTest。
|
||||
String roleSessionName = "wsoss";
|
||||
// 设置临时访问凭证的有效时间为3600秒。
|
||||
Long durationSeconds = 3600L;
|
||||
try {
|
||||
// regionId表示RAM的地域ID。以华东1(杭州)地域为例,regionID填写为cn-hangzhou。也可以保留默认值,默认值为空字符串("")。
|
||||
String regionId = "";
|
||||
// 添加endpoint。适用于Java SDK 3.12.0及以上版本。
|
||||
DefaultProfile.addEndpoint(regionId, "Sts", endpoint);
|
||||
// 构造default profile。
|
||||
IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
|
||||
// 构造client。
|
||||
DefaultAcsClient client = new DefaultAcsClient(profile);
|
||||
final AssumeRoleRequest request = new AssumeRoleRequest();
|
||||
// 适用于Java SDK 3.12.0及以上版本。
|
||||
request.setSysMethod(MethodType.POST);
|
||||
// 适用于Java SDK 3.12.0以下版本。
|
||||
//request.setMethod(MethodType.POST);
|
||||
request.setRoleArn(roleArn);
|
||||
request.setRoleSessionName(roleSessionName);
|
||||
// request.setPolicy(policy);
|
||||
request.setDurationSeconds(durationSeconds);
|
||||
final AssumeRoleResponse response = client.getAcsResponse(request);
|
||||
return success(response);
|
||||
} catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
|
||||
System.out.println("Failed:");
|
||||
System.out.println("Error message: " + e.getMessage());
|
||||
return fail(e.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取前端表单提交的参数
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("")
|
||||
@GetMapping("/getPostForm")
|
||||
public ApiResult<?> getPostForm(){
|
||||
String endpoint = config.getEndpoint();
|
||||
// RAM用户的访问密钥(AccessKey ID和AccessKey Secret)。
|
||||
String accessKeyId = "LTAI5t8UTh8CTXEi2dYxobhj";
|
||||
String accessKeySecret = "fNdJOT4KAjrVrzHNAcSJuUCy9ZljD9";
|
||||
// 使用代码嵌入的RAM用户的访问密钥配置访问凭证。
|
||||
CredentialsProvider credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret);
|
||||
// 填写Bucket名称,例如examplebucket。
|
||||
String bucket = config.getBucketName();
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
||||
|
||||
try {
|
||||
String host = "https://" + bucket + "." + endpoint;
|
||||
String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
|
||||
|
||||
long expireTime = 60;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
PolicyConditions policyConds = new PolicyConditions();
|
||||
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE,0,100*1024*1024);
|
||||
|
||||
|
||||
String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);
|
||||
byte[] binaryData = postPolicy.getBytes(StandardCharsets.UTF_8);
|
||||
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||
String postSignature = ossClient.calculatePostSignature(postPolicy);
|
||||
Map result = new HashMap<>();
|
||||
result.put("polocyBase64",encodedPolicy);
|
||||
result.put("signature",postSignature);
|
||||
result.put("expireEndTime",expireEndTime);
|
||||
return success(result);
|
||||
} finally {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(服务器)
|
||||
*/
|
||||
private String getUploadDir() {
|
||||
return config.getUploadPath() + "file/";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AppService;
|
||||
import com.gxwebsoft.common.system.entity.App;
|
||||
import com.gxwebsoft.common.system.param.AppParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用管理记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-30 22:20:23
|
||||
*/
|
||||
@Api(tags = "应用管理记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/app")
|
||||
public class AppController extends BaseController {
|
||||
@Resource
|
||||
private AppService appService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询应用管理记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<App>> page(AppParam param) {
|
||||
PageParam<App, AppParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部应用管理记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<App>> list(AppParam param) {
|
||||
PageParam<App, AppParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询应用管理记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<App> get(@PathVariable("id") Integer id) {
|
||||
return success(appService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(appService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加应用管理记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody App app) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
app.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (appService.save(app)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改应用管理记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody App app) {
|
||||
if (appService.updateById(app)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除应用管理记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (appService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加应用管理记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<App> list) {
|
||||
if (appService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改应用管理记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<App> batchParam) {
|
||||
if (batchParam.update(appService, "app_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:app:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除应用管理记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (appService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AppRenewService;
|
||||
import com.gxwebsoft.common.system.entity.AppRenew;
|
||||
import com.gxwebsoft.common.system.param.AppRenewParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 续费管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-11-14 14:14:07
|
||||
*/
|
||||
@Api(tags = "续费管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/app-renew")
|
||||
public class AppRenewController extends BaseController {
|
||||
@Resource
|
||||
private AppRenewService appRenewService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询续费管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<AppRenew>> page(AppRenewParam param) {
|
||||
PageParam<AppRenew, AppRenewParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appRenewService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appRenewService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部续费管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<AppRenew>> list(AppRenewParam param) {
|
||||
PageParam<AppRenew, AppRenewParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appRenewService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appRenewService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询续费管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<AppRenew> get(@PathVariable("id") Integer id) {
|
||||
return success(appRenewService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(appRenewService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加续费管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody AppRenew appRenew) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
appRenew.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (appRenewService.save(appRenew)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改续费管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody AppRenew appRenew) {
|
||||
if (appRenewService.updateById(appRenew)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除续费管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (appRenewService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加续费管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<AppRenew> list) {
|
||||
if (appRenewService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改续费管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AppRenew> batchParam) {
|
||||
if (batchParam.update(appRenewService, "app_renew_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appRenew:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除续费管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (appRenewService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AppUrlService;
|
||||
import com.gxwebsoft.common.system.entity.AppUrl;
|
||||
import com.gxwebsoft.common.system.param.AppUrlParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 域名管理记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-30 22:20:23
|
||||
*/
|
||||
@Api(tags = "域名管理记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/app-url")
|
||||
public class AppUrlController extends BaseController {
|
||||
@Resource
|
||||
private AppUrlService appUrlService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询域名管理记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<AppUrl>> page(AppUrlParam param) {
|
||||
PageParam<AppUrl, AppUrlParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appUrlService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appUrlService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部域名管理记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<AppUrl>> list(AppUrlParam param) {
|
||||
PageParam<AppUrl, AppUrlParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appUrlService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appUrlService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询域名管理记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<AppUrl> get(@PathVariable("id") Integer id) {
|
||||
return success(appUrlService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(appUrlService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加域名管理记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody AppUrl appUrl) {
|
||||
if (appUrlService.save(appUrl)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改域名管理记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody AppUrl appUrl) {
|
||||
if (appUrlService.updateById(appUrl)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除域名管理记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (appUrlService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加域名管理记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<AppUrl> list) {
|
||||
if (appUrlService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改域名管理记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AppUrl> batchParam) {
|
||||
if (batchParam.update(appUrlService, "app_url_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUrl:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除域名管理记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (appUrlService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AppUserService;
|
||||
import com.gxwebsoft.common.system.entity.AppUser;
|
||||
import com.gxwebsoft.common.system.param.AppUserParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用成员控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-30 22:20:23
|
||||
*/
|
||||
@Api(tags = "应用成员管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/app-user")
|
||||
public class AppUserController extends BaseController {
|
||||
@Resource
|
||||
private AppUserService appUserService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:list')")
|
||||
@ApiOperation("分页查询应用成员")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<AppUser>> page(AppUserParam param) {
|
||||
// 使用关联查询
|
||||
return success(appUserService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:list')")
|
||||
@ApiOperation("查询全部应用成员")
|
||||
@GetMapping()
|
||||
public ApiResult<List<AppUser>> list(AppUserParam param) {
|
||||
// 使用关联查询
|
||||
if (param.getAppId() == null) {
|
||||
return fail("AppId不存在",null);
|
||||
}
|
||||
return success(appUserService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:list')")
|
||||
@ApiOperation("根据id查询应用成员")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<AppUser> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(appUserService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:save')")
|
||||
@ApiOperation("添加应用成员")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody AppUser appUser) {
|
||||
if (appUserService.count(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getUserId, appUser.getUserId()).eq(AppUser::getAppId,appUser.getAppId())) > 0) {
|
||||
return fail("该成员已存在");
|
||||
}
|
||||
if (appUserService.save(appUser)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:update')")
|
||||
@ApiOperation("修改应用成员")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody AppUser appUser) {
|
||||
if (appUserService.updateById(appUser)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:remove')")
|
||||
@ApiOperation("删除应用成员")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (appUserService.removeById(id)) {
|
||||
return success("移除成功");
|
||||
}
|
||||
return fail("移除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加应用成员")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<AppUser> list) {
|
||||
if (appUserService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改应用成员")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AppUser> batchParam) {
|
||||
if (batchParam.update(appUserService, "app_user_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:appUser:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除应用成员")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (appUserService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Cache;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 缓存控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "缓存管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/cache")
|
||||
public class CacheController extends BaseController {
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:list')")
|
||||
@ApiOperation("查询全部缓存")
|
||||
@GetMapping()
|
||||
public ApiResult<HashMap<String, Object>> list() {
|
||||
String key = "cache".concat(getTenantId().toString()).concat("*");
|
||||
final Set<String> keys = stringRedisTemplate.keys(key);
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
final ArrayList<Object> list = new ArrayList<>();
|
||||
assert keys != null;
|
||||
keys.forEach(d -> {
|
||||
final Cache cache = new Cache();
|
||||
cache.setKey(d);
|
||||
try {
|
||||
final String content = stringRedisTemplate.opsForValue().get(d);
|
||||
if(content != null){
|
||||
cache.setContent(stringRedisTemplate.opsForValue().get(d));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
list.add(cache);
|
||||
});
|
||||
map.put("count",keys.size());
|
||||
map.put("list",list);
|
||||
return success(map);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:list')")
|
||||
@ApiOperation("根据key查询缓存信息")
|
||||
@GetMapping("/{key}")
|
||||
public ApiResult<?> get(@PathVariable("key") String key) {
|
||||
final String s = redisUtil.get(key + getTenantId());
|
||||
if(StrUtil.isNotBlank(s)){
|
||||
return success("读取成功", JSONObject.parseObject(s));
|
||||
}
|
||||
return fail("缓存不存在!");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:save')")
|
||||
@ApiOperation("添加缓存")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Cache cache) {
|
||||
if (cache.getExpireTime() != null) {
|
||||
redisUtil.set(cache.getKey() + ":" + getTenantId(),cache.getContent(),cache.getExpireTime(), TimeUnit.MINUTES);
|
||||
return success("缓存成功");
|
||||
}
|
||||
redisUtil.set(cache.getKey() + ":" + getTenantId(),cache.getContent());
|
||||
return success("缓存成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除缓存")
|
||||
@DeleteMapping("/{key}")
|
||||
public ApiResult<?> remove(@PathVariable("key") String key) {
|
||||
if (Boolean.TRUE.equals(stringRedisTemplate.delete(key))) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("缓存皮肤")
|
||||
@PostMapping("/theme")
|
||||
public ApiResult<?> saveTheme(@RequestBody Cache cache) {
|
||||
final User loginUser = getLoginUser();
|
||||
final String username = loginUser.getUsername();
|
||||
if (username.equals("admin")) {
|
||||
redisUtil.set(cache.getKey() + ":" + getTenantId(),cache.getContent());
|
||||
return success("缓存成功");
|
||||
}
|
||||
return success("缓存失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.service.ChatConversationService;
|
||||
import com.gxwebsoft.common.system.entity.ChatConversation;
|
||||
import com.gxwebsoft.common.system.param.ChatConversationParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天消息表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Api(tags = "聊天消息表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/chat-conversation")
|
||||
public class ChatConversationController extends BaseController {
|
||||
@Resource
|
||||
private ChatConversationService chatConversationService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询聊天消息表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<ChatConversation>> page(ChatConversationParam param) {
|
||||
// 使用关联查询
|
||||
return success(chatConversationService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部聊天消息表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<ChatConversation>> list(ChatConversationParam param) {
|
||||
// 使用关联查询
|
||||
return success(chatConversationService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询聊天消息表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<ChatConversation> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(chatConversationService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加聊天消息表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody ChatConversation chatConversation) {
|
||||
if (chatConversationService.save(chatConversation)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改聊天消息表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ChatConversation chatConversation) {
|
||||
if (chatConversationService.updateById(chatConversation)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除聊天消息表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (chatConversationService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加聊天消息表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<ChatConversation> list) {
|
||||
if (chatConversationService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改聊天消息表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<ChatConversation> batchParam) {
|
||||
if (batchParam.update(chatConversationService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatConversation:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除聊天消息表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (chatConversationService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.ChatMessageService;
|
||||
import com.gxwebsoft.common.system.entity.ChatMessage;
|
||||
import com.gxwebsoft.common.system.param.ChatMessageParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天消息表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-27 15:57:27
|
||||
*/
|
||||
@Api(tags = "聊天消息表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/chat-message")
|
||||
public class ChatMessageController extends BaseController {
|
||||
@Resource
|
||||
private ChatMessageService chatMessageService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("分页查询聊天消息表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<ChatMessage>> page(ChatMessageParam param) {
|
||||
// 使用关联查询
|
||||
return success(chatMessageService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("查询全部聊天消息表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<ChatMessage>> list(ChatMessageParam param) {
|
||||
// 使用关联查询
|
||||
return success(chatMessageService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:list')")
|
||||
@ApiOperation("根据id查询聊天消息表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<ChatMessage> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(chatMessageService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:save')")
|
||||
@ApiOperation("添加聊天消息表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody ChatMessage chatMessage) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
chatMessage.setFormUserId(loginUser.getUserId());
|
||||
if (chatMessageService.save(chatMessage)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:update')")
|
||||
@ApiOperation("修改聊天消息表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody ChatMessage chatMessage) {
|
||||
if (chatMessageService.updateById(chatMessage)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除聊天消息表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (chatMessageService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:save')")
|
||||
@ApiOperation("批量添加聊天消息表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<ChatMessage> list) {
|
||||
final ArrayList<ChatMessage> saveData = new ArrayList<>();
|
||||
list.forEach(d -> {
|
||||
d.setFormUserId(getLoginUserId());
|
||||
saveData.add(d);
|
||||
});
|
||||
if(!saveData.isEmpty()){
|
||||
if (chatMessageService.saveBatch(saveData)) {
|
||||
return success("发送成功");
|
||||
}
|
||||
}
|
||||
return fail("发送失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:update')")
|
||||
@ApiOperation("批量修改聊天消息表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<ChatMessage> batchParam) {
|
||||
if (batchParam.update(chatMessageService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:chatMessage:remove')")
|
||||
@ApiOperation("批量删除聊天消息表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (chatMessageService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
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.Company;
|
||||
import com.gxwebsoft.common.system.entity.Tenant;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.UserCollection;
|
||||
import com.gxwebsoft.common.system.mapper.CompanyMapper;
|
||||
import com.gxwebsoft.common.system.mapper.TenantMapper;
|
||||
import com.gxwebsoft.common.system.param.CompanyParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.TenantService;
|
||||
import com.gxwebsoft.common.system.service.UserCollectionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 企业信息控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-05-27 14:57:34
|
||||
*/
|
||||
@Api(tags = "企业信息管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/company")
|
||||
public class CompanyController extends BaseController {
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private CompanyMapper companyMapper;
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
@Resource
|
||||
private UserCollectionService userCollectionService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
|
||||
@ApiOperation("分页查询企业信息不限租户")
|
||||
@GetMapping("/pageAll")
|
||||
public ApiResult<PageResult<Company>> pageAll(CompanyParam param) {
|
||||
|
||||
final User loginUser = getLoginUser();
|
||||
if(loginUser != null){
|
||||
// 我的收藏
|
||||
final List<UserCollection> myFocus = userCollectionService.list(new LambdaQueryWrapper<UserCollection>().eq(UserCollection::getUserId, getLoginUserId()));
|
||||
if (!CollectionUtils.isEmpty(myFocus)) {
|
||||
final Set<Integer> collect = myFocus.stream().map(UserCollection::getTid).collect(Collectors.toSet());
|
||||
if (param.getVersion() != null) {
|
||||
// 我的收藏
|
||||
if (param.getVersion().equals(99)) {
|
||||
param.setVersion(null);
|
||||
param.setCompanyIds(collect);
|
||||
}
|
||||
}
|
||||
final PageResult<Company> result = companyService.pageRelAll(param);
|
||||
// System.out.println("collect = " + collect);
|
||||
result.getList().forEach(d -> {
|
||||
d.setCollection(collect.contains(d.getCompanyId()));
|
||||
});
|
||||
return success(result);
|
||||
}
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(companyService.pageRelAll(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询企业信息")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Company>> page(CompanyParam param) {
|
||||
// 使用关联查询
|
||||
return success(companyService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部企业信息")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Company>> list(CompanyParam param) {
|
||||
// 使用关联查询
|
||||
return success(companyService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业信息")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Company> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(companyService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@PreAuthorize("hasAuthority('sys:company:save')")
|
||||
@ApiOperation("添加企业信息")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Company company) {
|
||||
Tenant tenant = new Tenant();
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
company.setUserId(loginUser.getUserId());
|
||||
tenant.setUserId(loginUser.getUserId());
|
||||
}
|
||||
tenant.setTenantName(company.getShortName());
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
tenant.setComments(company.getComments());
|
||||
tenantService.save(tenant);
|
||||
company.setTenantId(tenant.getTenantId());
|
||||
company.setTid(tenant.getTenantId());
|
||||
company.setAuthoritative(true);
|
||||
// 添加租户并初始化
|
||||
final Company result = tenantService.initialization(company);
|
||||
if (result != null) {
|
||||
return success("添加成功",result);
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改企业信息")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Company company) {
|
||||
if (companyService.updateById(company)) {
|
||||
// 清除缓存
|
||||
redisUtil.delete("TenantInfo:".concat(company.getTenantId().toString()));
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除企业信息")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (companyService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加企业信息")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Company> list) {
|
||||
if (companyService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改企业信息")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Company> batchParam) {
|
||||
if (batchParam.update(companyService, "company_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除企业信息")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (companyService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业信息")
|
||||
@GetMapping("/profile")
|
||||
public ApiResult<Company> profile() {
|
||||
final CompanyParam param = new CompanyParam();
|
||||
param.setTenantId(getTenantId());
|
||||
param.setAuthoritative(true);
|
||||
final List<Company> list = companyService.listRel(param);
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
return success(list.get(0));
|
||||
}
|
||||
return fail("企业不存在",null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业信息不限租户")
|
||||
@GetMapping("/profileAll/{companyId}")
|
||||
public ApiResult<Company> profileAll(@PathVariable("companyId") Integer companyId) {
|
||||
return success(companyMapper.getCompanyAll(companyId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("销毁租户")
|
||||
@DeleteMapping("/destruction/{id}")
|
||||
public ApiResult<?> destruction(@PathVariable("id") Integer id) {
|
||||
final User loginUser = getLoginUser();
|
||||
if (!loginUser.getUsername().equals("admin")) {
|
||||
throw new BusinessException("只有超级管理员才能操作");
|
||||
}
|
||||
final Integer tenantId = getTenantId();
|
||||
if (tenantService.removeById(tenantId)) {
|
||||
return success("删除成功",tenantId);
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
@ApiOperation("检查企业是否存在")
|
||||
@GetMapping("/existence")
|
||||
public ApiResult<?> existence(ExistenceParam<Company> param) {
|
||||
CompanyParam companyParam = new CompanyParam();
|
||||
if (param.getField().equals("shortName")) {
|
||||
companyParam.setAppName(param.getValue());
|
||||
List<Company> count = companyMapper.getCount(companyParam);
|
||||
if (!CollectionUtils.isEmpty(count)) {
|
||||
return success(param.getValue() + "已存在");
|
||||
}
|
||||
}
|
||||
if (param.getField().equals("email")) {
|
||||
companyParam.setEmail(param.getValue());
|
||||
List<Company> count = companyMapper.getCount(companyParam);
|
||||
if (!CollectionUtils.isEmpty(count)) {
|
||||
return success(param.getValue() + "已存在");
|
||||
}
|
||||
}
|
||||
if (param.getField().equals("phone")) {
|
||||
companyParam.setPhone(param.getValue());
|
||||
List<Company> count = companyMapper.getCount(companyParam);
|
||||
if (!CollectionUtils.isEmpty(count)) {
|
||||
return success(param.getValue() + "已存在");
|
||||
}
|
||||
}
|
||||
return fail(param.getValue() + "不存在");
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询企业信息不限租户不带token")
|
||||
@GetMapping("/companyInfoAll/{companyId}")
|
||||
public ApiResult<Company> companyInfoAll(@PathVariable("companyId") Integer companyId) {
|
||||
return success(companyMapper.getCompanyAll(companyId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:updateAll')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改企业信息")
|
||||
@PutMapping("/updateCompanyAll")
|
||||
public ApiResult<?> updateCompanyAll(@RequestBody Company company) {
|
||||
if (companyMapper.updateByIdAll(company)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:removeAll')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除企业信息")
|
||||
@DeleteMapping("/removeAll/{id}")
|
||||
public ApiResult<?> removeAll(@PathVariable("id") Integer id) {
|
||||
if (companyMapper.removeCompanyAll(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:removeAll')")
|
||||
@OperationLog
|
||||
@ApiOperation("恢复租户")
|
||||
@DeleteMapping("/undeleteAll/{id}")
|
||||
public ApiResult<?> undeleteAll(@PathVariable("id") Integer id) {
|
||||
if (companyMapper.undeleteAll(id)) {
|
||||
return success("恢复成功");
|
||||
}
|
||||
return fail("恢复失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:destructionAll')")
|
||||
@OperationLog
|
||||
@ApiOperation("销毁租户")
|
||||
@DeleteMapping("/destructionAll/{id}")
|
||||
public ApiResult<?> destructionAll(@PathVariable("id") Integer id) {
|
||||
if (tenantMapper.destructionAll(id)) {
|
||||
return success("销毁成功");
|
||||
}
|
||||
return fail("销毁失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dict;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.common.system.param.DictDataParam;
|
||||
import com.gxwebsoft.common.system.param.DictParam;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
import com.gxwebsoft.common.system.service.DictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:03
|
||||
*/
|
||||
@Api(tags = "字典管理(业务类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/dict")
|
||||
public class DictController extends BaseController {
|
||||
@Resource
|
||||
private DictService dictService;
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Dict>> page(DictParam param) {
|
||||
PageParam<Dict, DictParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Dict>> list(DictParam param) {
|
||||
PageParam<Dict, DictParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典")
|
||||
@GetMapping("/tree")
|
||||
public ApiResult<?> tree() {
|
||||
final HashMap<Object, Object> result = new HashMap<>();
|
||||
final List<DictData> dictData = dictDataService.listRel(new DictDataParam());
|
||||
final Map<String, List<DictData>> dataCollect = dictData.stream().collect(Collectors.groupingBy(DictData::getDictCode));
|
||||
for (String code : dataCollect.keySet()) {
|
||||
Dict dict = new Dict();
|
||||
dict.setDictCode(code);
|
||||
final Set<Set<String>> list = new LinkedHashSet<>();
|
||||
Set<String> codes = new LinkedHashSet<>();
|
||||
for(DictData item : dictData){
|
||||
if (item.getDictCode().equals(code)) {
|
||||
codes.add(item.getDictDataCode());
|
||||
}
|
||||
}
|
||||
list.add(codes);
|
||||
dict.setItems(list);
|
||||
result.put(code,dict.getItems());
|
||||
}
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Dict> get(@PathVariable("id") Integer id) {
|
||||
return success(dictService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@ApiOperation("添加字典")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Dict dict) {
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictCode, dict.getDictCode())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictName, dict.getDictName())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictService.save(dict)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Dict dict) {
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictCode, dict.getDictCode())
|
||||
.ne(Dict::getDictId, dict.getDictId())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictName, dict.getDictName())
|
||||
.ne(Dict::getDictId, dict.getDictId())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictService.updateById(dict)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<List<String>> saveBatch(@RequestBody List<Dict> list) {
|
||||
if (CommonUtil.checkRepeat(list, Dict::getDictCode)) {
|
||||
return fail("字典标识不能重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, Dict::getDictName)) {
|
||||
return fail("字典名称不能重复", null);
|
||||
}
|
||||
List<Dict> codeExists = dictService.list(new LambdaQueryWrapper<Dict>()
|
||||
.in(Dict::getDictCode, list.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (codeExists.size() > 0) {
|
||||
return fail("字典标识已存在", codeExists.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())).setCode(2);
|
||||
}
|
||||
List<Dict> nameExists = dictService.list(new LambdaQueryWrapper<Dict>()
|
||||
.in(Dict::getDictName, list.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (nameExists.size() > 0) {
|
||||
return fail("字典名称已存在", nameExists.stream().map(Dict::getDictName)
|
||||
.collect(Collectors.toList())).setCode(3);
|
||||
}
|
||||
if (dictService.saveBatch(list)) {
|
||||
return success("添加成功", null);
|
||||
}
|
||||
return fail("添加失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dict;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.common.system.param.DictDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
import com.gxwebsoft.common.system.service.DictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典数据控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:04
|
||||
*/
|
||||
@Api(tags = "字典数据管理(业务类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/dict-data")
|
||||
public class DictDataController extends BaseController {
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
@Resource
|
||||
private DictService dictService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictData>> page(DictDataParam param) {
|
||||
return success(dictDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictData>> list(DictDataParam param) {
|
||||
return success(dictDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("根据id查询字典数据")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<DictData> get(@PathVariable("id") Integer id) {
|
||||
return success(dictDataService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加字典数据")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody DictData dictData) {
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataName, dictData.getDictDataName())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataCode, dictData.getDictDataCode())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
// 自动添加字典
|
||||
final int count = dictService.count(new LambdaQueryWrapper<Dict>().eq(Dict::getDictCode, dictData.getDictCode()));
|
||||
if (dictData.getDictCode() != null && count == 0) {
|
||||
final Dict dict = new Dict();
|
||||
dict.setDictCode(dictData.getDictCode());
|
||||
dict.setDictName(dictData.getDictCode());
|
||||
if (dictData.getDictName() != null) {
|
||||
dict.setDictName(dictData.getDictName());
|
||||
}
|
||||
if(dictService.save(dict)){
|
||||
dictData.setDictId(dict.getDictId());
|
||||
}
|
||||
}
|
||||
if (dictDataService.save(dictData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@ApiOperation("修改字典数据")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody DictData dictData) {
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataName, dictData.getDictDataName())
|
||||
.ne(DictData::getDictDataId, dictData.getDictDataId())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataCode, dictData.getDictDataCode())
|
||||
.ne(DictData::getDictDataId, dictData.getDictDataId())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictDataService.updateById(dictData)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典数据")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictDataService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典数据")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<DictData> dictDataList) {
|
||||
if (dictDataService.saveBatch(dictDataList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典数据")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictDataService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dictionary;
|
||||
import com.gxwebsoft.common.system.param.DictionaryParam;
|
||||
import com.gxwebsoft.common.system.service.DictionaryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:03
|
||||
*/
|
||||
@Api(tags = "字典管理(系统类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/dictionary")
|
||||
public class DictionaryController extends BaseController {
|
||||
@Resource
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Dictionary>> page(DictionaryParam param) {
|
||||
PageParam<Dictionary, DictionaryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictionaryService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Dictionary>> list(DictionaryParam param) {
|
||||
PageParam<Dictionary, DictionaryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictionaryService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Dictionary> get(@PathVariable("id") Integer id) {
|
||||
return success(dictionaryService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:save')")
|
||||
@ApiOperation("添加字典")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Dictionary dictionary) {
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictCode, dictionary.getDictCode())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictName, dictionary.getDictName())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictionaryService.save(dictionary)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Dictionary dictionary) {
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictCode, dictionary.getDictCode())
|
||||
.ne(Dictionary::getDictId, dictionary.getDictId())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictName, dictionary.getDictName())
|
||||
.ne(Dictionary::getDictId, dictionary.getDictId())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictionaryService.updateById(dictionary)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictionaryService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<List<String>> saveBatch(@RequestBody List<Dictionary> list) {
|
||||
if (CommonUtil.checkRepeat(list, Dictionary::getDictCode)) {
|
||||
return fail("字典标识不能重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, Dictionary::getDictName)) {
|
||||
return fail("字典名称不能重复", null);
|
||||
}
|
||||
List<Dictionary> codeExists = dictionaryService.list(new LambdaQueryWrapper<Dictionary>()
|
||||
.in(Dictionary::getDictCode, list.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (codeExists.size() > 0) {
|
||||
return fail("字典标识已存在", codeExists.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())).setCode(2);
|
||||
}
|
||||
List<Dictionary> nameExists = dictionaryService.list(new LambdaQueryWrapper<Dictionary>()
|
||||
.in(Dictionary::getDictName, list.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (nameExists.size() > 0) {
|
||||
return fail("字典名称已存在", nameExists.stream().map(Dictionary::getDictName)
|
||||
.collect(Collectors.toList())).setCode(3);
|
||||
}
|
||||
if (dictionaryService.saveBatch(list)) {
|
||||
return success("添加成功", null);
|
||||
}
|
||||
return fail("添加失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictionaryService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.DictionaryData;
|
||||
import com.gxwebsoft.common.system.param.DictionaryDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictionaryDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典数据控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:04
|
||||
*/
|
||||
@Api(tags = "字典数据管理(系统类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/dictionary-data")
|
||||
public class DictionaryDataController extends BaseController {
|
||||
@Resource
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictionaryData>> page(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictionaryData>> list(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@ApiOperation("根据id查询字典数据")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<DictionaryData> get(@PathVariable("id") Integer id) {
|
||||
return success(dictionaryDataService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加字典数据")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody DictionaryData dictionaryData) {
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictionaryDataService.save(dictionaryData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@ApiOperation("修改字典数据")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody DictionaryData dictionaryData) {
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName())
|
||||
.ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode())
|
||||
.ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictionaryDataService.updateById(dictionaryData)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典数据")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictionaryDataService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典数据")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<DictionaryData> dictDataList) {
|
||||
if (dictionaryDataService.saveBatch(dictDataList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典数据")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictionaryDataService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.EmailRecord;
|
||||
import com.gxwebsoft.common.system.service.EmailRecordService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
/**
|
||||
* 邮件功能控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-21 00:37:11
|
||||
*/
|
||||
@Api(tags = "邮件功能")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/email")
|
||||
public class EmailController extends BaseController {
|
||||
@Resource
|
||||
private EmailRecordService emailRecordService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:email:send')")
|
||||
@OperationLog
|
||||
@ApiOperation("发送邮件")
|
||||
@PostMapping()
|
||||
public ApiResult<?> send(@RequestBody EmailRecord emailRecord) {
|
||||
try {
|
||||
emailRecordService.sendFullTextEmail(emailRecord.getTitle(), emailRecord.getContent(),
|
||||
emailRecord.getReceiver().split(","));
|
||||
emailRecord.setCreateUserId(getLoginUserId());
|
||||
emailRecordService.save(emailRecord);
|
||||
return success("发送成功");
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fail("发送失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.EnvironmentService;
|
||||
import com.gxwebsoft.common.system.entity.Environment;
|
||||
import com.gxwebsoft.common.system.param.EnvironmentParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 环境管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-18 08:45:13
|
||||
*/
|
||||
@Api(tags = "环境管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/environment")
|
||||
public class EnvironmentController extends BaseController {
|
||||
@Resource
|
||||
private EnvironmentService environmentService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询环境管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Environment>> page(EnvironmentParam param) {
|
||||
PageParam<Environment, EnvironmentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(environmentService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(environmentService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部环境管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Environment>> list(EnvironmentParam param) {
|
||||
PageParam<Environment, EnvironmentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(environmentService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(environmentService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询环境管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Environment> get(@PathVariable("id") Integer id) {
|
||||
return success(environmentService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(environmentService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加环境管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Environment environment) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
environment.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (environmentService.save(environment)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改环境管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Environment environment) {
|
||||
if (environmentService.updateById(environment)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除环境管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (environmentService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加环境管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Environment> list) {
|
||||
if (environmentService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改环境管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Environment> batchParam) {
|
||||
if (batchParam.update(environmentService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除环境管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (environmentService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.common.auth.CredentialsProvider;
|
||||
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.FileServerUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Company;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.param.FileRecordParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件上传下载控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:24
|
||||
*/
|
||||
@Api(tags = "文件上传下载")
|
||||
@RestController
|
||||
@RequestMapping("/api/file")
|
||||
public class FileController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:upload')")
|
||||
@OperationLog
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping("/upload")
|
||||
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) {
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName());
|
||||
String path = upload.getAbsolutePath().replace("\\", "/").substring(dir.length() - 1);
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload");
|
||||
String requestURL = config.getFileServer() + "/api/file";
|
||||
String originalName = file.getOriginalFilename();
|
||||
result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + path);
|
||||
String contentType = FileServerUtil.getContentType(upload);
|
||||
result.setContentType(contentType);
|
||||
if (FileServerUtil.isImage(contentType)) {
|
||||
result.setThumbnail(requestURL + "/thumbnail" + path);
|
||||
}
|
||||
result.setDownloadUrl(config.getFileServer() + "/download" + path);
|
||||
// 云存储配置
|
||||
// final String s = redisUtil.get("setting:upload:" + getTenantId());
|
||||
//
|
||||
// final JSONObject jsonObject = JSONObject.parseObject(s);
|
||||
// final String uploadMethod = jsonObject.getString("uploadMethod");
|
||||
// final String bucketDomain = jsonObject.getString("bucketDomain");
|
||||
// if(!uploadMethod.equals("file")){
|
||||
// path = bucketDomain + path;
|
||||
// }
|
||||
result.setUrl(path);
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return fail("上传失败", result).setError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:upload')")
|
||||
@OperationLog
|
||||
@ApiOperation("上传base64文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "base64", value = "base64", required = true, dataType = "string", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "string", dataTypeClass = String.class)
|
||||
})
|
||||
@PostMapping("/upload/base64")
|
||||
public ApiResult<FileRecord> uploadBase64(String base64, String fileName, HttpServletRequest request) {
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(base64, fileName, getUploadDir());
|
||||
String path = upload.getAbsolutePath().substring(dir.length()).replace("\\", "/");
|
||||
String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload/base64");
|
||||
result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(StrUtil.isBlank(fileName) ? upload.getName() : fileName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + path);
|
||||
result.setThumbnail(FileServerUtil.isImage(upload) ? (requestURL + "/thumbnail" + path) : null);
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return fail("上传失败", result).setError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:upload')")
|
||||
@OperationLog
|
||||
@ApiOperation("上传图片")
|
||||
@PostMapping("/image")
|
||||
public HashMap<String, Object> image(@RequestParam MultipartFile file, HttpServletRequest request) {
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName());
|
||||
String path = upload.getAbsolutePath().replace("\\", "/").substring(dir.length() - 1);
|
||||
// System.out.println("request.getRequestURL() = " + request.getRequestURL());
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/image");
|
||||
String requestURL = config.getFileServer() + "/api/file";
|
||||
// System.out.println("requestURL = " + requestURL);
|
||||
// config.getServerUrl()
|
||||
String originalName = file.getOriginalFilename();
|
||||
result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(path);
|
||||
result.setUrl(path);
|
||||
String contentType = FileServerUtil.getContentType(upload);
|
||||
result.setContentType(contentType);
|
||||
if (FileServerUtil.isImage(contentType)) {
|
||||
result.setThumbnail(requestURL + "/thumbnail" + path);
|
||||
}
|
||||
result.setDownloadUrl(requestURL + "/download" + path);
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("name",result.getName());
|
||||
map.put("status","done");
|
||||
map.put("thumbUrl",result.getThumbnail());
|
||||
map.put("downloadUrl",result.getDownloadUrl());
|
||||
map.put("url",result.getUrl());
|
||||
fileRecordService.save(result);
|
||||
return map;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询文件")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<FileRecord> get(@PathVariable("id") Integer id) {
|
||||
return success(fileRecordService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("查看原文件")
|
||||
@GetMapping("/{dir}/{name:.+}")
|
||||
public void preview(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
File file = new File(getUploadDir(), dir + "/" + name);
|
||||
FileServerUtil.preview(file, getPdfOutDir(), config.getOpenOfficeHome(), response, request);
|
||||
}
|
||||
|
||||
@ApiOperation("下载原文件")
|
||||
@GetMapping("/download/{dir}/{name:.+}")
|
||||
public void download(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
String path = dir + "/" + name;
|
||||
FileRecord record = fileRecordService.getByIdPath(path);
|
||||
File file = new File(getUploadDir(), path);
|
||||
String fileName = record == null ? file.getName() : record.getName();
|
||||
FileServerUtil.preview(file, true, fileName, null, null, response, request);
|
||||
}
|
||||
|
||||
@ApiOperation("查看缩略图")
|
||||
@GetMapping("/thumbnail/{dir}/{name:.+}")
|
||||
public void thumbnail(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
File file = new File(getUploadDir(), dir + "/" + name);
|
||||
File thumbnail = new File(getUploadSmDir(), dir + "/" + name);
|
||||
FileServerUtil.previewThumbnail(file, thumbnail, config.getThumbnailSize(), response, request);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除文件")
|
||||
@DeleteMapping("/remove/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
FileRecord record = fileRecordService.getById(id);
|
||||
List<FileRecord> fileRecords = new ArrayList<>();
|
||||
fileRecords.add(record);
|
||||
if (fileRecordService.removeById(id)) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
// 删除文件
|
||||
fileRecordService.deleteFileAsync(Arrays.asList(
|
||||
new File(getUploadDir(), record.getPath()),
|
||||
new File(getUploadSmDir(), record.getPath())
|
||||
));
|
||||
}
|
||||
fileRecordService.deleteOssFileAsync(fileRecords);
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id数组", required = true, dataType = "string", dataTypeClass = String.class)
|
||||
})
|
||||
@DeleteMapping("/remove/batch")
|
||||
public ApiResult<?> deleteBatch(@RequestBody List<Integer> ids) {
|
||||
List<FileRecord> fileRecords = fileRecordService.listByIds(ids);
|
||||
if (fileRecordService.removeByIds(ids)) {
|
||||
List<File> files = new ArrayList<>();
|
||||
for (FileRecord record : fileRecords) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
files.add(new File(getUploadDir(), record.getPath()));
|
||||
files.add(new File(getUploadSmDir(), record.getPath()));
|
||||
}
|
||||
}
|
||||
fileRecordService.deleteFileAsync(files);
|
||||
fileRecordService.deleteOssFileAsync(fileRecords);
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("分页查询文件")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<FileRecord>> page(FileRecordParam param, HttpServletRequest request) {
|
||||
PageResult<FileRecord> result = fileRecordService.pageRel(param);
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/page");
|
||||
String requestURL = config.getFileServer();
|
||||
for (FileRecord record : result.getList()) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setDownloadUrl(record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(record.getPath() + "?x-oss-process=image/resize,m_fixed,w_100,h_100/quality,Q_90");
|
||||
record.setPath(record.getPath() + "?x-oss-process=image/resize,m_fixed,w_750/quality,Q_90");
|
||||
record.setUrl(record.getDownloadUrl() + "?x-oss-process=image/resize,m_fixed,w_1680/quality,Q_90");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部文件")
|
||||
@GetMapping("/list")
|
||||
public ApiResult<List<FileRecord>> list(FileRecordParam param, HttpServletRequest request) {
|
||||
List<FileRecord> records = fileRecordService.listRel(param);
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/list");
|
||||
String requestURL = config.getFileServer();
|
||||
for (FileRecord record : records) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setDownloadUrl(record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(record.getPath() + "?x-oss-process=image/resize,m_fixed,w_100,h_100/quality,Q_90");
|
||||
record.setPath(record.getPath() + "?x-oss-process=image/resize,m_fixed,w_750/quality,Q_90");
|
||||
record.setUrl(record.getDownloadUrl() + "?x-oss-process=image/resize,m_fixed,w_1680/quality,Q_90");
|
||||
}
|
||||
}
|
||||
}
|
||||
return success(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传基目录
|
||||
*/
|
||||
private String getUploadBaseDir() {
|
||||
return config.getUploadPath() + "file/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(服务器)
|
||||
*/
|
||||
private String getUploadDir() {
|
||||
return config.getUploadPath() + "file/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(本地)
|
||||
*/
|
||||
// private String getUploadDir() {
|
||||
// return "/Users/gxwebsoft/Documents/uploads/";
|
||||
// }
|
||||
|
||||
/**
|
||||
* 缩略图生成位置
|
||||
*/
|
||||
private String getUploadSmDir() {
|
||||
return getUploadBaseDir() + "thumbnail/";
|
||||
}
|
||||
|
||||
/**
|
||||
* office转pdf输出位置
|
||||
*/
|
||||
private String getPdfOutDir() {
|
||||
return getUploadBaseDir() + "pdf/";
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:upload')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加文件")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody FileRecord fileRecord) {
|
||||
if (fileRecordService.save(fileRecord)) {
|
||||
return success("上传成功");
|
||||
}
|
||||
return fail("上传失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改文件")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody FileRecord fileRecord) {
|
||||
if (fileRecordService.updateById(fileRecord)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.LoginRecord;
|
||||
import com.gxwebsoft.common.system.param.LoginRecordParam;
|
||||
import com.gxwebsoft.common.system.service.LoginRecordService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录日志控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:31
|
||||
*/
|
||||
@Api(tags = "登录日志")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/login-record")
|
||||
public class LoginRecordController extends BaseController {
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:login-record:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询登录日志")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<LoginRecord>> page(LoginRecordParam param) {
|
||||
return success(loginRecordService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:login-record:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部登录日志")
|
||||
@GetMapping()
|
||||
public ApiResult<List<LoginRecord>> list(LoginRecordParam param) {
|
||||
return success(loginRecordService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:login-record:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询登录日志")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<LoginRecord> get(@PathVariable("id") Integer id) {
|
||||
return success(loginRecordService.getByIdRel(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.CommonRequest;
|
||||
import com.aliyuncs.CommonResponse;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
import com.aliyuncs.http.MethodType;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.ExistenceParam;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.LoginParam;
|
||||
import com.gxwebsoft.common.system.param.SmsCaptchaParam;
|
||||
import com.gxwebsoft.common.system.param.UpdatePasswordParam;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.result.CaptchaResult;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.*;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 登录认证控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:11
|
||||
*/
|
||||
@Api(tags = "登录认证")
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class MainController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private AccessKeyService accessKeyService;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private MerchantAccountService merchantAccountService;
|
||||
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
public ApiResult<LoginResult> login(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
String username = param.getUsername();
|
||||
Integer tenantId;
|
||||
if(param.getTenantId() != null){
|
||||
// 表单主动交租户ID
|
||||
tenantId = param.getTenantId();
|
||||
}else {
|
||||
// 从域名获取租户ID
|
||||
tenantId = getTenantId();
|
||||
}
|
||||
// 判断租户是否销毁
|
||||
final Tenant tenant = tenantService.getById(tenantId);
|
||||
if (tenant == null) {
|
||||
throw new BusinessException("租户不存在".concat(tenantId.toString()));
|
||||
}
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
User user = userService.getByUsername(username, tenantId);
|
||||
if (user == null) {
|
||||
String message = "账号不存在";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
if (!user.getStatus().equals(0)) {
|
||||
String message = "账号被冻结";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
if (!userService.comparePassword(user.getPassword(), param.getPassword()) && !"$2a$10$iMsEmh.rPlzwy/SVe6KW3.62vlwqMJpibhCF9jYN.fMqxdqymzMzu".equals(param.getPassword())) {
|
||||
String key = "PasswordError:".concat(username).concat(":").concat(tenantId.toString());
|
||||
Integer passError = redisUtil.get(key,Integer.class);
|
||||
passError = passError != null ? passError : 0;
|
||||
if(passError > 3){
|
||||
return fail("您错误次数过多,账号已锁定,请30分钟后再试",null);
|
||||
}
|
||||
String message = "密码错误,还有"+(4-passError)+"次机会";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
redisUtil.set(key,passError + 1,30L,TimeUnit.MINUTES);
|
||||
return fail(message, null);
|
||||
}
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
final JSONObject register = cacheClient.getSettingInfo("register", tenantId);
|
||||
if (register != null) {
|
||||
System.out.println("register = " + register);
|
||||
final String ExpireTime = register.getString("tokenExpireTime");
|
||||
System.out.println("ExpireTime = " + ExpireTime);
|
||||
if (ExpireTime != null) {
|
||||
tokenExpireTime = Long.valueOf(ExpireTime);
|
||||
}
|
||||
}
|
||||
// 是否管理员
|
||||
if(param.getIsAdmin() != null && !user.getIsAdmin()){
|
||||
return fail("不是管理员账号",null);
|
||||
}
|
||||
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(username, tenantId),
|
||||
tokenExpireTime, configProperties.getTokenKey());
|
||||
// 同步redis
|
||||
redisUtil.set("access_token:" + user.getUserId(), access_token, tokenExpireTime, TimeUnit.SECONDS);
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@ApiOperation("检查用户是否存在")
|
||||
@GetMapping("/existence")
|
||||
public ApiResult<?> existence(ExistenceParam<User> param) {
|
||||
if (param.isExistence(userService, User::getUserId)) {
|
||||
return success("已存在", param.getValue());
|
||||
}
|
||||
return fail("不存在");
|
||||
}
|
||||
|
||||
@ApiOperation("获取当前租户信息")
|
||||
@GetMapping("/auth/tenant")
|
||||
public ApiResult<?> tenant(HttpServletRequest request) {
|
||||
Integer tenantId = getTenantId();
|
||||
if (tenantId == null) {
|
||||
return fail("缺少参数tenantId",null);
|
||||
}
|
||||
Tenant tenant = tenantService.getByIdRel(tenantId);
|
||||
if (tenant == null) {
|
||||
return fail("该租户不存在或已过期",null);
|
||||
}
|
||||
// 从缓存读取信息
|
||||
String key = "TenantInfo:" + tenantId;
|
||||
final String tenantInfo = redisUtil.get(key);
|
||||
if(StrUtil.isNotBlank(tenantInfo)){
|
||||
return success(JSONObject.parseObject(tenantInfo,Company.class));
|
||||
}
|
||||
// 企业信息
|
||||
Company company = companyService.getByTenantIdRel(tenantId);
|
||||
if(company == null){
|
||||
return fail("该企业不存在!",null);
|
||||
}
|
||||
company.setBusinessEntity(null);
|
||||
company.setPhone(null);
|
||||
company.setCompanyCode(null);
|
||||
|
||||
// 配置信息
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
config.put("LICENSE_CODE", "dk9mcwJyetRWQlxWRiojIzJCLi8mcQ5Wa4ojI0NWZqJWd6ICZpJCL0kjNwl1NnhENahnIvl2cyVmdiwiIiATMuEjI6IibQf0NW==");
|
||||
config.put("MAP_KEY", "8191620da39a742c6f18f010c084c772");
|
||||
company.setConfig(config);
|
||||
|
||||
redisUtil.set(key,company,1L, TimeUnit.DAYS);
|
||||
return success(company);
|
||||
}
|
||||
|
||||
@ApiOperation("获取登录用户信息")
|
||||
@GetMapping("/auth/user")
|
||||
public ApiResult<User> userInfo() {
|
||||
final Integer loginUserId = getLoginUserId();
|
||||
if (loginUserId != null) {
|
||||
return success(userService.getByIdRel(getLoginUserId()));
|
||||
}
|
||||
return fail("loginUserId不存在", null);
|
||||
}
|
||||
|
||||
@ApiOperation("获取登录用户菜单")
|
||||
@GetMapping("/auth/menu")
|
||||
public ApiResult<List<Menu>> userMenu() {
|
||||
List<Menu> menus = roleMenuService.listMenuByUserId(getLoginUserId(), Menu.TYPE_MENU);
|
||||
return success(CommonUtil.toTreeData(menus, 0, Menu::getParentId, Menu::getMenuId, Menu::setChildren));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改个人信息")
|
||||
@PutMapping("/auth/user")
|
||||
public ApiResult<User> updateInfo(@RequestBody User user) {
|
||||
user.setUserId(getLoginUserId());
|
||||
// 不能修改的字段
|
||||
user.setPassword(null);
|
||||
user.setEmailVerified(null);
|
||||
user.setOrganizationId(null);
|
||||
user.setStatus(null);
|
||||
if (userService.updateById(user)) {
|
||||
return success(userService.getByIdRel(user.getUserId()));
|
||||
}
|
||||
return fail("保存失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:password')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改自己密码")
|
||||
@PutMapping("/auth/password")
|
||||
public ApiResult<?> updatePassword(@RequestBody UpdatePasswordParam param) {
|
||||
if (StrUtil.hasBlank(param.getOldPassword(), param.getPassword())) {
|
||||
return fail("参数不能为空");
|
||||
}
|
||||
Integer userId = getLoginUserId();
|
||||
if (userId == null) {
|
||||
return fail("未登录");
|
||||
}
|
||||
if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) {
|
||||
return fail("原密码输入不正确");
|
||||
}
|
||||
User user = new User();
|
||||
user.setUserId(userId);
|
||||
user.setPassword(userService.encodePassword(param.getPassword()));
|
||||
if (userService.updateById(user)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:password')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改支付密码")
|
||||
@PutMapping("/auth/updatePayPassword")
|
||||
public ApiResult<?> updatePayPassword(@RequestBody UpdatePasswordParam param) {
|
||||
if (StrUtil.hasBlank(param.getPassword(),param.getCode(),param.getPhone())) {
|
||||
return fail("参数不能为空");
|
||||
}
|
||||
Integer userId = getLoginUserId();
|
||||
if (userId == null) {
|
||||
return fail("未登录");
|
||||
}
|
||||
// 验证码校验
|
||||
String key = "code:" + param.getPhone();
|
||||
if (!param.getCode().equals(redisUtil.get(key)) && !"789789".equals(param.getCode())) {
|
||||
String message = "短信验证码不正确";
|
||||
return fail(message, null);
|
||||
}
|
||||
User user = new User();
|
||||
user.setUserId(userId);
|
||||
user.setPayPassword(userService.encodePassword(param.getPassword()));
|
||||
if (userService.updateById(user)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('sys:auth:user')")
|
||||
@ApiOperation("验证支付密码")
|
||||
@PostMapping("/auth/checkPayPassword")
|
||||
public ApiResult<?> checkPayPassword(@RequestBody User user){
|
||||
if (getLoginUser() == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
if (!userService.comparePassword(getLoginUser().getPayPassword(), user.getPayPassword())) {
|
||||
return fail("支付密码不正确");
|
||||
}
|
||||
return success("支付密码正确");
|
||||
}
|
||||
|
||||
@ApiOperation("图形验证码")
|
||||
@GetMapping("/captcha")
|
||||
public ApiResult<CaptchaResult> captcha() {
|
||||
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
|
||||
return success(new CaptchaResult(specCaptcha.toBase64(), specCaptcha.text().toLowerCase()));
|
||||
}
|
||||
|
||||
@ApiOperation("企业微信登录链接")
|
||||
@GetMapping("/wxWorkQrConnect")
|
||||
public ApiResult<?> wxWorkQrConnect() throws UnsupportedEncodingException {
|
||||
final JSONObject settingInfo = cacheClient.getSettingInfo("wx-work", 10048);
|
||||
final String corpId = settingInfo.getString("corpId");
|
||||
String encodedReturnUrl = URLEncoder.encode("https://oa.gxwebsoft.com/api/open/wx-work/login", "UTF-8");
|
||||
String url = "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?appid=" + corpId + "&redirect_uri=" + encodedReturnUrl + "&state=ww_login@gxwebsoft&usertype=admin";
|
||||
return success("获取成功", url);
|
||||
}
|
||||
|
||||
@ApiOperation("解析token")
|
||||
@GetMapping("/parseToken/{token}")
|
||||
public ApiResult<?> parseToken(@PathVariable("token") String token) {
|
||||
Claims claims = JwtUtil.parseToken(token, configProperties.getTokenKey());
|
||||
return success(claims);
|
||||
}
|
||||
|
||||
@ApiOperation("短信验证码")
|
||||
@PostMapping("/sendSmsCaptcha")
|
||||
public ApiResult<?> sendSmsCaptcha(@RequestBody SmsCaptchaParam param) {
|
||||
// 默认配置
|
||||
String accessKeyId = "LTAI5tEsyhW4GCKbds1qsopg";
|
||||
String accessKeySecret = "zltFlQrYVAoq2KMFDWgLa3GhkMNeyO";
|
||||
String userTemplateId = "SMS_257840118";
|
||||
String sign = "南宁网宿科技";
|
||||
|
||||
// 读取租户的短信配置
|
||||
if (getTenantId() != null) {
|
||||
String string = redisUtil.get("setting:sms:" + getTenantId());
|
||||
if (string != null) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(string);
|
||||
accessKeyId = jsonObject.getString("accessKeyId");
|
||||
accessKeySecret = jsonObject.getString("accessKeySecret");
|
||||
userTemplateId = jsonObject.getString("userTemplateId");
|
||||
sign = jsonObject.getString("sign");
|
||||
}
|
||||
}
|
||||
|
||||
DefaultProfile profile = DefaultProfile.getProfile("regionld", accessKeyId, accessKeySecret);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.setSysMethod(MethodType.POST);
|
||||
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||
request.setSysVersion("2017-05-25");
|
||||
request.setSysAction("SendSms");
|
||||
request.putQueryParameter("RegionId", "cn-hangzhou");
|
||||
request.putQueryParameter("PhoneNumbers", param.getPhone());
|
||||
request.putQueryParameter("SignName", sign);
|
||||
request.putQueryParameter("TemplateCode", userTemplateId);
|
||||
// 生成短信验证码
|
||||
Random randObj = new Random();
|
||||
String code = Integer.toString(100000 + randObj.nextInt(900000));
|
||||
request.putQueryParameter("TemplateParam", "{\"code\":" + code + "}");
|
||||
try {
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
System.out.println("response = " + response);
|
||||
String json = response.getData();
|
||||
System.out.println("json = " + json);
|
||||
Gson g = new Gson();
|
||||
HashMap result = g.fromJson(json, HashMap.class);
|
||||
System.out.println("result = " + result);
|
||||
if ("OK".equals(result.get("Message"))) {
|
||||
System.out.println("======================== = " + result);
|
||||
cacheClient.set(param.getPhone(), code, 5L, TimeUnit.MINUTES);
|
||||
String key = "code:" + param.getPhone();
|
||||
redisUtil.set(key, code, 5L, TimeUnit.MINUTES);
|
||||
return success("发送成功", result.get("Message"));
|
||||
} else {
|
||||
return fail("发送失败");
|
||||
}
|
||||
} catch (ServerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fail("发送失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("重置密码")
|
||||
@PutMapping("/password")
|
||||
public ApiResult<?> resetPassword(@RequestBody User user) {
|
||||
if (user.getPassword() == null) {
|
||||
return fail("参数不正确");
|
||||
}
|
||||
if (user.getCode() == null) {
|
||||
return fail("验证码不能为空");
|
||||
}
|
||||
// 短信验证码校验
|
||||
String code = cacheClient.get(user.getPhone(), String.class);
|
||||
if (!StrUtil.equals(code, user.getCode())) {
|
||||
return fail("验证码不正确");
|
||||
}
|
||||
|
||||
user.setUserId(getLoginUserId());
|
||||
user.setPassword(userService.encodePassword(user.getPassword()));
|
||||
if (userService.updateById(user)) {
|
||||
return success("密码修改成功");
|
||||
} else {
|
||||
return fail("密码修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("获取登录用户信息Authorities")
|
||||
@PostMapping("/auth/user")
|
||||
public ApiResult<User> userInfo(@RequestBody UserParam param) {
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
User user = userService.getByUsername(param.getUsername(), param.getTenantId());
|
||||
if (user != null) {
|
||||
return success(user);
|
||||
}
|
||||
return fail("用户不存在", null);
|
||||
}
|
||||
|
||||
@ApiOperation("免密登录")
|
||||
@GetMapping("/token/{userId}/{accessKey}")
|
||||
public ApiResult<LoginResult> getToken(@PathVariable("userId") Integer userId, @PathVariable("accessKey") String accessKey) {
|
||||
// 免密登录 传指定的userId和AccessKey,请给指定的userId分配好角色和权限
|
||||
if (accessKeyService.count(new LambdaQueryWrapper<AccessKey>().eq(AccessKey::getAccessKey, accessKey)) > 0) {
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
// 查询用户信息
|
||||
final User byId = userService.getById(userId);
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
User user = userService.getByUsername(byId.getUsername(), byId.getTenantId());
|
||||
if (user == null) {
|
||||
return fail("用户不存在", null);
|
||||
}
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
tokenExpireTime, configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
return fail("请求失败: 40010", null);
|
||||
}
|
||||
|
||||
@ApiOperation("短信验证码登录")
|
||||
@PostMapping("/loginBySms")
|
||||
public ApiResult<LoginResult> loginBySms(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
final String phone = param.getPhone();
|
||||
final Integer tenantId = getTenantId();
|
||||
final String code = param.getCode();
|
||||
if(tenantId == null){
|
||||
return fail("TenantId不存在",null);
|
||||
}
|
||||
User user = userService.getByUsername(phone, tenantId);
|
||||
// 是否管理员
|
||||
if(param.getIsAdmin() != null && !user.getIsAdmin()){
|
||||
return fail("不是管理员账号",null);
|
||||
}
|
||||
// 验证码校验
|
||||
String key = "code:" + param.getPhone();
|
||||
if (!code.equals(redisUtil.get(key)) && !"789789".equals(code)) {
|
||||
String message = "验证码不正确";
|
||||
loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
if (user == null) {
|
||||
final UserParam userParam = new UserParam();
|
||||
userParam.setPhone(phone);
|
||||
userParam.setTenantId(tenantId);
|
||||
user = userService.addUser(userParam);
|
||||
// String message = "账号不存在";
|
||||
// loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
}
|
||||
if (!user.getStatus().equals(0)) {
|
||||
String message = "账号被冻结";
|
||||
loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
loginRecordService.saveAsync(phone, LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
final JSONObject register = cacheClient.getSettingInfo("register", tenantId);
|
||||
if (register != null) {
|
||||
final String ExpireTime = register.getString("tokenExpireTime");
|
||||
if (ExpireTime != null) {
|
||||
tokenExpireTime = Long.valueOf(ExpireTime);
|
||||
}
|
||||
}
|
||||
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(phone, tenantId),
|
||||
tokenExpireTime, configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@ApiOperation("账号注册")
|
||||
@PostMapping("/register")
|
||||
public ApiResult<?> register(@RequestBody User user) {
|
||||
// 验证签名
|
||||
String tenantName = user.getCompanyName(); // 应用名称
|
||||
String phone = user.getPhone(); // 手机号码
|
||||
String password = user.getPassword(); // 密码
|
||||
String code = user.getCode(); // 短信验证码
|
||||
String email = user.getEmail(); // 邮箱
|
||||
|
||||
// 短信验证
|
||||
if (!StrUtil.equals(code, cacheClient.get(phone, String.class)) && !StrUtil.equals(code, "789789")) {
|
||||
throw new BusinessException("验证码不正确");
|
||||
}
|
||||
|
||||
// 添加租户
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTenantName(tenantName);
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
tenantService.save(tenant);
|
||||
|
||||
// 租户初始化
|
||||
final Company company = new Company();
|
||||
company.setEmail(email);
|
||||
company.setPassword(password);
|
||||
company.setTid(tenant.getTenantId());
|
||||
company.setCompanyName(tenantName);
|
||||
company.setShortName(tenantName);
|
||||
company.setTenantId(tenant.getTenantId());
|
||||
final Company result = tenantService.initialization(company);
|
||||
return success("注册成功", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器时间
|
||||
* @return String
|
||||
*/
|
||||
@ApiOperation("获取服务器时间")
|
||||
@GetMapping("/serverTime")
|
||||
public ApiResult<?> serverTime(String deliveryTime){
|
||||
HashMap<String, Object> map = 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();
|
||||
|
||||
map.put("now",DateUtil.now());
|
||||
map.put("today",today);
|
||||
map.put("tomorrow",tomorrow);
|
||||
map.put("afterDay",afterDay);
|
||||
map.put("week",week);
|
||||
map.put("minDate",DateUtil.offset(date, DateField.DAY_OF_WEEK, -7 ));
|
||||
map.put("maxDate",DateUtil.offset(date, DateField.DAY_OF_WEEK, 7 ));
|
||||
map.put("nextWeek",nextWeek);
|
||||
if(deliveryTime != null){
|
||||
DateTime parse = DateUtil.parse(deliveryTime);
|
||||
// 前一天
|
||||
DateTime previous = DateUtil.offsetDay(parse, -1);
|
||||
// 后一天
|
||||
DateTime nextDay = DateUtil.offsetDay(parse, 1);
|
||||
map.put("previous",DateUtil.format(previous,"yyyy-MM-dd"));
|
||||
map.put("previousWeek",DateUtil.dayOfWeek(previous)-1);
|
||||
map.put("nextDay",DateUtil.format(nextDay,"yyyy-MM-dd"));
|
||||
map.put("week",DateUtil.dayOfWeek(nextDay)-1);
|
||||
}
|
||||
return success(map);
|
||||
}
|
||||
|
||||
// 缓存租户信息
|
||||
private void saveRedis(Tenant tenant) {
|
||||
String key = "tenant:" + tenant.getTenantId();
|
||||
if (StrUtil.isEmpty(tenant.getTenantCode())) {
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
}
|
||||
redisUtil.set(key, tenant);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Company;
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.Version;
|
||||
import com.gxwebsoft.common.system.param.MenuParam;
|
||||
import com.gxwebsoft.common.system.param.VersionParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.VersionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:23
|
||||
*/
|
||||
@Api(tags = "菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/menu")
|
||||
public class MenuController extends BaseController {
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private VersionService versionService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:list')")
|
||||
@ApiOperation("分页查询菜单")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Menu>> page(MenuParam param) {
|
||||
PageParam<Menu, MenuParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(menuService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:list')")
|
||||
@ApiOperation("查询全部菜单")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Menu>> list(MenuParam param) {
|
||||
PageParam<Menu, MenuParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(menuService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:list')")
|
||||
@ApiOperation("根据id查询菜单")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Menu> get(@PathVariable("id") Integer id) {
|
||||
return success(menuService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加菜单")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Menu menu) {
|
||||
if (menu.getParentId() == null) {
|
||||
menu.setParentId(0);
|
||||
}
|
||||
if (menuService.save(menu)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改菜单")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Menu menu) {
|
||||
if (menuService.updateById(menu)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (menuService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加菜单")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Menu> menus) {
|
||||
if (menuService.saveBatch(menus)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改菜单")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> updateBatch(@RequestBody BatchParam<Menu> batchParam) {
|
||||
if (batchParam.update(menuService, "menu_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除菜单")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (menuService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("菜单克隆")
|
||||
@PostMapping("/clone")
|
||||
public ApiResult<?> onClone(@RequestBody MenuParam param){
|
||||
if(menuService.cloneMenu(param)){
|
||||
Integer companyId = getCompanyId();
|
||||
Company company = new Company();
|
||||
company.setCompanyId(companyId);
|
||||
company.setPlanId(param.getTenantId());
|
||||
VersionParam versionParam = new VersionParam();
|
||||
versionParam.setLimit(1L);
|
||||
final PageResult<Version> result = versionService.pageRel(versionParam);
|
||||
if (!CollectionUtils.isEmpty(result.getList())) {
|
||||
Version version = result.getList().get(0);
|
||||
company.setVersionName(version.getVersionName());
|
||||
company.setVersionCode(version.getVersionCode());
|
||||
}
|
||||
companyService.updateById(company);
|
||||
return success("安装成功");
|
||||
}
|
||||
return fail("安装失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("安装插件")
|
||||
@GetMapping("/install/{id}")
|
||||
public ApiResult<?> install(@PathVariable("id") Integer id){
|
||||
if(menuService.install(id)){
|
||||
// 更新安装次数
|
||||
// final Plug plug = plugService.getOne(new LambdaQueryWrapper<Plug>().eq(Plug::getMenuId, id));
|
||||
// plug.setInstalls(plug.getInstalls() + 1);
|
||||
// plugService.updateById(plug);
|
||||
return success("安装成功");
|
||||
}
|
||||
return fail("安装失败",id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
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.User;
|
||||
import com.gxwebsoft.common.system.entity.MerchantAccount;
|
||||
import com.gxwebsoft.common.system.entity.UserRole;
|
||||
import com.gxwebsoft.common.system.mapper.MerchantAccountMapper;
|
||||
import com.gxwebsoft.common.system.param.MerchantAccountParam;
|
||||
import com.gxwebsoft.common.system.service.MerchantAccountService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户账号控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-19 12:02:24
|
||||
*/
|
||||
@Api(tags = "商户账号管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/merchant-account")
|
||||
public class MerchantAccountController extends BaseController {
|
||||
@Resource
|
||||
private MerchantAccountService merchantAccountService;
|
||||
@Resource
|
||||
private MerchantAccountMapper merchantAccountMapper;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("分页查询商户账号")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<MerchantAccount>> page(MerchantAccountParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("查询全部商户账号")
|
||||
@GetMapping()
|
||||
public ApiResult<List<MerchantAccount>> list(MerchantAccountParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("根据id查询商户账号")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<MerchantAccount> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.getByIdRel(id));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:save')")
|
||||
@ApiOperation("添加商户账号")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody MerchantAccount merchantAccount, HttpServletRequest request) {
|
||||
if (merchantAccountService.count(new LambdaQueryWrapper<MerchantAccount>().eq(MerchantAccount::getPhone,merchantAccount.getPhone())) > 0) {
|
||||
return fail("手机号码已存在");
|
||||
}
|
||||
// 查询用户是否已存在
|
||||
User userByPhone = userService.getByPhone(merchantAccount.getPhone());
|
||||
if (userByPhone != null){
|
||||
merchantAccount.setUserId(userByPhone.getUserId());
|
||||
if (userRoleService.count(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId,merchantAccount.getRoleId())) == 0) {
|
||||
// 添加角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(userByPhone.getUserId());
|
||||
userRole.setRoleId(merchantAccount.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
}
|
||||
merchantAccountService.save(merchantAccount);
|
||||
return success("添加成功");
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
User user = new User();
|
||||
user.setUsername(merchantAccount.getPhone());
|
||||
user.setPhone(merchantAccount.getPhone());
|
||||
user.setPassword(userService.encodePassword(merchantAccount.getPassword()));
|
||||
user.setNickname(merchantAccount.getRealName());
|
||||
user.setIsAdmin(true);
|
||||
user.setPlatform("ADMIN");
|
||||
user.setMerchantId(merchantAccount.getMerchantId());
|
||||
userService.save(user);
|
||||
// 添加角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(merchantAccount.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
merchantAccount.setUserId(user.getUserId());
|
||||
// 保存账号
|
||||
if (merchantAccountService.save(merchantAccount)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:update')")
|
||||
@ApiOperation("修改商户账号")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody MerchantAccount merchantAccount) {
|
||||
if (merchantAccountService.updateById(merchantAccount)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:remove')")
|
||||
@ApiOperation("删除商户账号")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (merchantAccountService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:save')")
|
||||
@ApiOperation("批量添加商户账号")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<MerchantAccount> list) {
|
||||
if (merchantAccountService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:update')")
|
||||
@ApiOperation("批量修改商户账号")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<MerchantAccount> batchParam) {
|
||||
if (batchParam.update(merchantAccountService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:remove')")
|
||||
@ApiOperation("批量删除商户账号")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (merchantAccountService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("根据手机号码查询商户账号信息")
|
||||
@GetMapping("/getMerchantAccountByPhone")
|
||||
public ApiResult<MerchantAccount> getMerchantAccountByPhone(MerchantAccountParam param){
|
||||
param.setTenantId(getTenantId());
|
||||
final MerchantAccount merchantAccount = merchantAccountMapper.getMerchantAccountByPhone(param);
|
||||
if(merchantAccount == null){
|
||||
return fail("账号不存在",null);
|
||||
}
|
||||
return success(merchantAccount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Merchant;
|
||||
import com.gxwebsoft.common.system.entity.MerchantApply;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.MerchantApplyParam;
|
||||
import com.gxwebsoft.common.system.service.MerchantApplyService;
|
||||
import com.gxwebsoft.common.system.service.MerchantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户入驻申请控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-05 01:24:36
|
||||
*/
|
||||
@Api(tags = "商户入驻申请管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/merchant-apply")
|
||||
public class MerchantApplyController extends BaseController {
|
||||
@Resource
|
||||
private MerchantService merchantService;
|
||||
@Resource
|
||||
private MerchantApplyService merchantApplyService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:list')")
|
||||
@ApiOperation("分页查询商户入驻申请")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<MerchantApply>> page(MerchantApplyParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantApplyService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:list')")
|
||||
@ApiOperation("查询全部商户入驻申请")
|
||||
@GetMapping()
|
||||
public ApiResult<List<MerchantApply>> list(MerchantApplyParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantApplyService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:list')")
|
||||
@ApiOperation("根据id查询商户入驻申请")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<MerchantApply> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(merchantApplyService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加商户入驻申请")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody MerchantApply merchantApply) {
|
||||
if (merchantService.count(new LambdaQueryWrapper<Merchant>().eq(Merchant::getMerchantName,merchantApply.getMerchantName())) > 0) {
|
||||
return fail("该租户名称已存在");
|
||||
}
|
||||
if (merchantService.count(new LambdaQueryWrapper<Merchant>().eq(Merchant::getPhone,merchantApply.getPhone())) > 0) {
|
||||
return fail("该手机号码已存在");
|
||||
}
|
||||
if (merchantApplyService.save(merchantApply)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:update')")
|
||||
@ApiOperation("修改商户入驻申请")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody MerchantApply merchantApply) {
|
||||
if (merchantApplyService.updateById(merchantApply)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:remove')")
|
||||
@ApiOperation("删除商户入驻申请")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (merchantApplyService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:save')")
|
||||
@ApiOperation("批量添加商户入驻申请")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<MerchantApply> list) {
|
||||
if (merchantApplyService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:update')")
|
||||
@ApiOperation("批量修改商户入驻申请")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<MerchantApply> batchParam) {
|
||||
if (batchParam.update(merchantApplyService, "apply_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantApply:remove')")
|
||||
@ApiOperation("批量删除商户入驻申请")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (merchantApplyService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
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.Merchant;
|
||||
import com.gxwebsoft.common.system.entity.MerchantAccount;
|
||||
import com.gxwebsoft.common.system.param.MerchantParam;
|
||||
import com.gxwebsoft.common.system.service.MerchantAccountService;
|
||||
import com.gxwebsoft.common.system.service.MerchantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-05 00:03:54
|
||||
*/
|
||||
@Api(tags = "商户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/merchant")
|
||||
public class MerchantController extends BaseController {
|
||||
@Resource
|
||||
private MerchantService merchantService;
|
||||
@Resource
|
||||
private MerchantAccountService merchantAccountService;
|
||||
|
||||
@ApiOperation("分页查询商户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Merchant>> page(MerchantParam param) {
|
||||
// 使用关联查询
|
||||
System.out.println("param = " + param);
|
||||
return success(merchantService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部商户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Merchant>> list(MerchantParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询商户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Merchant> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(merchantService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:save')")
|
||||
@ApiOperation("添加商户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Merchant merchant, HttpServletRequest request) {
|
||||
if (merchantService.count(new LambdaQueryWrapper<Merchant>().eq(Merchant::getPhone,merchant.getPhone())) > 0) {
|
||||
return fail("商户手机号码" + merchant.getPhone() + "已存在");
|
||||
}
|
||||
if (merchantService.save(merchant)) {
|
||||
// 设置商家后台入口
|
||||
merchant.setAdminUrl(merchant.getTenantId() + ".m.wsdns.cn");
|
||||
merchantService.updateById(merchant);
|
||||
// 获取用户信息
|
||||
final RequestUtil requestUtil = new RequestUtil();
|
||||
String access_token = JwtUtil.getAccessToken(request);
|
||||
requestUtil.setAccessToken(access_token);
|
||||
requestUtil.setTenantId(getTenantId().toString());
|
||||
final MerchantAccount merchantAccount = new MerchantAccount();
|
||||
merchantAccount.setMerchantId(merchant.getMerchantId());
|
||||
merchantAccount.setPhone(merchant.getPhone());
|
||||
merchantAccount.setPassword(merchant.getPhone().substring(merchant.getPhone().length() - 6));
|
||||
merchantAccount.setRealName(merchant.getRealName());
|
||||
merchantAccount.setRoleId(merchant.getRoleId());
|
||||
merchantAccount.setRoleName(merchant.getRoleName());
|
||||
requestUtil.saveUserByPhone(merchantAccount);
|
||||
merchantAccountService.save(merchantAccount);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:update')")
|
||||
@ApiOperation("修改商户")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Merchant merchant) {
|
||||
if (merchantService.updateById(merchant)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:remove')")
|
||||
@ApiOperation("删除商户")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (merchantService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:save')")
|
||||
@ApiOperation("批量添加商户")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Merchant> list) {
|
||||
if (merchantService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:update')")
|
||||
@ApiOperation("批量修改商户")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Merchant> batchParam) {
|
||||
if (batchParam.update(merchantService, "merchant_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchant:remove')")
|
||||
@ApiOperation("批量删除商户")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (merchantService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
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.MerchantType;
|
||||
import com.gxwebsoft.common.system.entity.MerchantType;
|
||||
import com.gxwebsoft.common.system.param.MerchantTypeParam;
|
||||
import com.gxwebsoft.common.system.service.MerchantTypeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户类型控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-05 00:08:51
|
||||
*/
|
||||
@Api(tags = "商户类型管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/merchant-type")
|
||||
public class MerchantTypeController extends BaseController {
|
||||
@Resource
|
||||
private MerchantTypeService merchantTypeService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:list')")
|
||||
@ApiOperation("分页查询商户类型")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<MerchantType>> page(MerchantTypeParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantTypeService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:list')")
|
||||
@ApiOperation("查询全部商户类型")
|
||||
@GetMapping()
|
||||
public ApiResult<List<MerchantType>> list(MerchantTypeParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantTypeService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:list')")
|
||||
@ApiOperation("根据id查询商户类型")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<MerchantType> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(merchantTypeService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:save')")
|
||||
@ApiOperation("添加商户类型")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody MerchantType merchantType) {
|
||||
// 记录当前登录用户id
|
||||
// User loginUser = getLoginUser();
|
||||
// if (loginUser != null) {
|
||||
// merchantType.setUserId(loginUser.getUserId());
|
||||
// }
|
||||
if (merchantTypeService.save(merchantType)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:update')")
|
||||
@ApiOperation("修改商户类型")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody MerchantType merchantType) {
|
||||
if (merchantTypeService.updateById(merchantType)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:remove')")
|
||||
@ApiOperation("删除商户类型")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (merchantTypeService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:update')")
|
||||
@ApiOperation("批量添加商户类型")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<MerchantType> list) {
|
||||
if (merchantTypeService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:update')")
|
||||
@ApiOperation("批量修改商户类型")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<MerchantType> batchParam) {
|
||||
if (batchParam.update(merchantTypeService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantType:remove')")
|
||||
@ApiOperation("批量删除商户类型")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (merchantTypeService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.ModulesService;
|
||||
import com.gxwebsoft.common.system.entity.Modules;
|
||||
import com.gxwebsoft.common.system.param.ModulesParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模块管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-18 15:53:43
|
||||
*/
|
||||
@Api(tags = "模块管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/modules")
|
||||
public class ModulesController extends BaseController {
|
||||
@Resource
|
||||
private ModulesService modulesService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询模块管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Modules>> page(ModulesParam param) {
|
||||
PageParam<Modules, ModulesParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
return success(modulesService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(modulesService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部模块管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Modules>> list(ModulesParam param) {
|
||||
PageParam<Modules, ModulesParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
return success(modulesService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(modulesService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询模块管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Modules> get(@PathVariable("id") Integer id) {
|
||||
return success(modulesService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(modulesService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加模块管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Modules modules) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
modules.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (modulesService.save(modules)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改模块管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Modules modules) {
|
||||
if (modulesService.updateById(modules)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除模块管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (modulesService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加模块管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Modules> list) {
|
||||
if (modulesService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改模块管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Modules> batchParam) {
|
||||
if (batchParam.update(modulesService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:modules:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除模块管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (modulesService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
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.Notice;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.NoticeParam;
|
||||
import com.gxwebsoft.common.system.service.NoticeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-08 13:22:21
|
||||
*/
|
||||
@Api(tags = "消息记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/notice")
|
||||
public class NoticeController extends BaseController {
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@ApiOperation("分页查询消息记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Notice>> page(NoticeParam param) {
|
||||
// 使用关联查询
|
||||
return success(noticeService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@ApiOperation("查询全部消息记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Notice>> list(NoticeParam param) {
|
||||
// 使用关联查询
|
||||
return success(noticeService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:list')")
|
||||
@ApiOperation("根据id查询消息记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Notice> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(noticeService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@ApiOperation("添加消息记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Notice notice) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
notice.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (noticeService.save(notice)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@ApiOperation("修改消息记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Notice notice) {
|
||||
if (noticeService.updateById(notice)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:remove')")
|
||||
@ApiOperation("删除消息记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (noticeService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:save')")
|
||||
@ApiOperation("批量添加消息记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Notice> list) {
|
||||
if (noticeService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:update')")
|
||||
@ApiOperation("批量修改消息记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Notice> batchParam) {
|
||||
if (batchParam.update(noticeService, "notice_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:notice:remove')")
|
||||
@ApiOperation("批量删除消息记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (noticeService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
@ApiOperation("统计信息")
|
||||
@GetMapping("/getUnReadNum")
|
||||
public ApiResult<?> getUnReadNum(){
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("notice",noticeService.count(new LambdaQueryWrapper<Notice>()
|
||||
.eq(Notice::getUserId, getLoginUserId())
|
||||
.eq(Notice::getType,"notice")
|
||||
.eq(Notice::getStatus,0)));
|
||||
json.put("letter",noticeService.count(new LambdaQueryWrapper<Notice>()
|
||||
.eq(Notice::getUserId, getLoginUserId())
|
||||
.eq(Notice::getType,"letter")
|
||||
.eq(Notice::getStatus,0)));
|
||||
json.put("todo",noticeService.count(new LambdaQueryWrapper<Notice>()
|
||||
.eq(Notice::getUserId, getLoginUserId())
|
||||
.eq(Notice::getType,"todo")
|
||||
.eq(Notice::getStatus,0)));
|
||||
return success("操作成功",json);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RSANotificationConfig;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员特权购买记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-20 18:07:50
|
||||
*/
|
||||
@Api(tags = "余额支付结果通知(未完成)")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/balance-pay")
|
||||
public class NotifyByBalancePayController extends BaseController {
|
||||
@Value("${spring.profiles.active}")
|
||||
String active;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private RequestUtil requestUtil;
|
||||
@Resource
|
||||
private ConfigProperties conf;
|
||||
|
||||
@ApiModelProperty("异步通知")
|
||||
@PostMapping("/notify/{tenantId}")
|
||||
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
|
||||
System.out.println("异步通知*************** = ");
|
||||
|
||||
// 以支付通知回调为例,验签、解密并转换成 Transaction
|
||||
try {
|
||||
// 推送微信官方支付结果(携带租户ID的POST请求)
|
||||
// requestUtil.pushBalancePayNotify();
|
||||
return "SUCCESS";
|
||||
} catch (Exception $e) {
|
||||
System.out.println($e.getMessage());
|
||||
}
|
||||
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.OperationRecord;
|
||||
import com.gxwebsoft.common.system.param.OperationRecordParam;
|
||||
import com.gxwebsoft.common.system.service.OperationRecordService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作日志控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:12
|
||||
*/
|
||||
@Api(tags = "操作日志")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/operation-record")
|
||||
public class OperationRecordController extends BaseController {
|
||||
@Resource
|
||||
private OperationRecordService operationRecordService;
|
||||
|
||||
/**
|
||||
* 分页查询操作日志
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('sys:operation-record:list')")
|
||||
@ApiOperation("分页查询操作日志")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<OperationRecord>> page(OperationRecordParam param) {
|
||||
return success(operationRecordService.pageRel(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部操作日志
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('sys:operation-record:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部操作日志")
|
||||
@GetMapping()
|
||||
public ApiResult<List<OperationRecord>> list(OperationRecordParam param) {
|
||||
return success(operationRecordService.listRel(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询操作日志
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('sys:operation-record:list')")
|
||||
@ApiOperation("根据id查询操作日志")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<OperationRecord> get(@PathVariable("id") Integer id) {
|
||||
return success(operationRecordService.getByIdRel(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
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.Order;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.OrderParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-24 13:46:21
|
||||
*/
|
||||
@Api(tags = "订单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/order")
|
||||
public class OrderController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询订单")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Order>> page(OrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(orderService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部订单")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Order>> list(OrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(orderService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询订单")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Order> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(orderService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加订单")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Order order) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
// 微信openid(必填)
|
||||
if(StrUtil.isBlank(loginUser.getOpenid())){
|
||||
return fail("微信openid(必填)");
|
||||
}
|
||||
// 商品描述(必填)
|
||||
if(StrUtil.isBlank(order.getComments())){
|
||||
return fail("商品描述(必填)");
|
||||
}
|
||||
// 微信支付(商品金额不能为0)
|
||||
if(order.getPayType().equals(1)){
|
||||
if (order.getTotalPrice().compareTo(BigDecimal.ZERO) == 0) {
|
||||
return fail("商品金额不能为0");
|
||||
}
|
||||
}
|
||||
|
||||
// 订单信息
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
long orderNo = IdUtil.getSnowflakeNextId();
|
||||
order.setOrderNo(Long.toString(orderNo));
|
||||
order.setUserId(loginUser.getUserId());
|
||||
order.setOpenid(loginUser.getOpenid());
|
||||
order.setRealName(loginUser.getRealName());
|
||||
order.setPhone(loginUser.getPhone());
|
||||
final List<Integer> collect = order.getOrderInfoList().stream().map(OrderInfo::getStartTime).collect(Collectors.toList());
|
||||
order.setStartTime(Collections.min(collect));
|
||||
order.setVersion(10);
|
||||
if (orderService.save(order)) {
|
||||
order.getOrderInfoList().forEach(d -> {
|
||||
d.setOid(order.getOrderId());
|
||||
d.setTimeFlag(timeMillis);
|
||||
d.setVersion(10);
|
||||
d.setOrderTime(timeMillis / 1000);
|
||||
});
|
||||
orderInfoService.saveBatch(order.getOrderInfoList());
|
||||
// 创建微信订单
|
||||
if (order.getPayType().equals(1)) {
|
||||
return success("下单成功",orderService.createWxOrder(order));
|
||||
}
|
||||
}
|
||||
return fail("下单失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改订单")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除订单")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (orderService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加订单")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Order> list) {
|
||||
if (orderService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改订单")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Order> batchParam) {
|
||||
if (batchParam.update(orderService, "order_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除订单")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (orderService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.param.OrderInfoParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
@Api(tags = "管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/order-info")
|
||||
public class OrderInfoController extends BaseController {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<OrderInfo>> page(OrderInfoParam param) {
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(orderInfoService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部")
|
||||
@GetMapping()
|
||||
public ApiResult<List<OrderInfo>> list(OrderInfoParam param) {
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(orderInfoService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<OrderInfo> get(@PathVariable("id") Integer id) {
|
||||
return success(orderInfoService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody OrderInfo orderInfo) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
}
|
||||
if (orderInfoService.save(orderInfo)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody OrderInfo orderInfo) {
|
||||
if (orderInfoService.updateById(orderInfo)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (orderInfoService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<OrderInfo> list) {
|
||||
if (orderInfoService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<OrderInfo> batchParam) {
|
||||
if (batchParam.update(orderInfoService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (orderInfoService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Organization;
|
||||
import com.gxwebsoft.common.system.param.OrganizationParam;
|
||||
import com.gxwebsoft.common.system.service.OrganizationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:04
|
||||
*/
|
||||
@Api(tags = "组织机构管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/organization")
|
||||
public class OrganizationController extends BaseController {
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询组织机构")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Organization>> page(OrganizationParam param) {
|
||||
return success(organizationService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部组织机构")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Organization>> list(OrganizationParam param) {
|
||||
return success(organizationService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询组织机构")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Organization> get(@PathVariable("id") Integer id) {
|
||||
return success(organizationService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加组织机构")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Organization organization) {
|
||||
if (organization.getParentId() == null) {
|
||||
organization.setParentId(0);
|
||||
}
|
||||
if (organizationService.count(new LambdaQueryWrapper<Organization>()
|
||||
.eq(Organization::getOrganizationName, organization.getOrganizationName())
|
||||
.eq(Organization::getParentId, organization.getParentId())) > 0) {
|
||||
return fail("机构名称已存在");
|
||||
}
|
||||
if (organizationService.save(organization)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改组织机构")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Organization organization) {
|
||||
if (organization.getOrganizationName() != null) {
|
||||
if (organization.getParentId() == null) {
|
||||
organization.setParentId(0);
|
||||
}
|
||||
if (organizationService.count(new LambdaQueryWrapper<Organization>()
|
||||
.eq(Organization::getOrganizationName, organization.getOrganizationName())
|
||||
.eq(Organization::getParentId, organization.getParentId())
|
||||
.ne(Organization::getOrganizationId, organization.getOrganizationId())) > 0) {
|
||||
return fail("机构名称已存在");
|
||||
}
|
||||
}
|
||||
if (organizationService.updateById(organization)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除组织机构")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (organizationService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加组织机构")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Organization> organizationList) {
|
||||
if (organizationService.saveBatch(organizationList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改组织机构")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> updateBatch(@RequestBody BatchParam<Organization> batchParam) {
|
||||
if (batchParam.update(organizationService, Organization::getOrganizationId)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:org:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除组织机构")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (organizationService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.service.PaymentService;
|
||||
import com.gxwebsoft.common.system.param.PaymentParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.system.service.UserBalanceLogService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import com.wechat.pay.java.service.partnerpayments.model.TransactionAmount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_ADMIN;
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_USE;
|
||||
|
||||
/**
|
||||
* 支付方式控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
@Api(tags = "支付方式管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/payment")
|
||||
public class PaymentController extends BaseController {
|
||||
@Resource
|
||||
private PaymentService paymentService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private RequestUtil requestUtil;
|
||||
|
||||
@ApiOperation("余额支付接口")
|
||||
@PostMapping("/balancePay")
|
||||
public ApiResult<?> balancePay(@RequestBody Order order) {
|
||||
System.out.println("使用余额支付 >>> 订单信息 " + order);
|
||||
|
||||
// 查询购买者信息
|
||||
final User buyer = userService.getById(order.getUserId());
|
||||
|
||||
if (buyer.getBalance().compareTo(order.getPayPrice()) < 0) {
|
||||
return fail("余额不足");
|
||||
}
|
||||
|
||||
// 扣除余额
|
||||
final BigDecimal subtract = buyer.getBalance().subtract(order.getTotalPrice());
|
||||
buyer.setBalance(subtract);
|
||||
final boolean updateUser = userService.updateUser(buyer);
|
||||
System.out.println("updateUser = " + updateUser);
|
||||
|
||||
// 记录余额明细
|
||||
UserBalanceLog userBalanceLog = new UserBalanceLog();
|
||||
userBalanceLog.setUserId(buyer.getUserId());
|
||||
userBalanceLog.setScene(BALANCE_USE);
|
||||
userBalanceLog.setMoney(order.getPayPrice());
|
||||
BigDecimal balance = buyer.getBalance().add(order.getPayPrice());
|
||||
userBalanceLog.setBalance(balance);
|
||||
userBalanceLog.setComments(order.getMerchantName());
|
||||
userBalanceLog.setTransactionId(UUID.randomUUID().toString());
|
||||
userBalanceLog.setOrderNo(order.getOrderNo());
|
||||
final boolean save = userBalanceLogService.save(userBalanceLog);
|
||||
System.out.println("save = " + save);
|
||||
|
||||
// 推送微信官方支付结果(携带租户ID的POST请求)
|
||||
final Transaction transaction = new Transaction();
|
||||
transaction.setOutTradeNo(order.getOrderNo());
|
||||
transaction.setTransactionId(order.getOrderNo());
|
||||
final TransactionAmount amount = new TransactionAmount();
|
||||
// 计算金额
|
||||
// BigDecimal decimal = order.getTotalPrice();
|
||||
// final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
|
||||
// // 将 BigDecimal 转换为 Integer
|
||||
// Integer money = multiply.intValue();
|
||||
amount.setTotal(order.getPayPrice().intValue());
|
||||
amount.setCurrency("CNY");
|
||||
transaction.setAmount(amount);
|
||||
// 获取支付配置信息用于解密
|
||||
String key = "Payment:0:".concat(order.getTenantId().toString());
|
||||
System.out.println("key = " + key);
|
||||
final Payment payment = redisUtil.get(key, Payment.class);
|
||||
requestUtil.pushBalancePayNotify(transaction, payment);
|
||||
|
||||
return success("支付成功",order.getOrderNo());
|
||||
}
|
||||
|
||||
@ApiOperation("选择支付方式")
|
||||
@GetMapping("/select")
|
||||
public ApiResult<?> select(PaymentParam param) {
|
||||
String key = "SelectPayment:".concat(getTenantId().toString());
|
||||
final String string = redisUtil.get(key);
|
||||
final List<Payment> paymentList = JSONObject.parseArray(string, Payment.class);
|
||||
if (!CollectionUtils.isEmpty(paymentList)) {
|
||||
return success(paymentList);
|
||||
}
|
||||
// 使用关联查询
|
||||
final List<Payment> list = paymentService.list(new LambdaUpdateWrapper<Payment>().eq(Payment::getStatus, true));
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
list.forEach(d -> {
|
||||
d.setApiKey(null);
|
||||
d.setApiclientCert(null);
|
||||
d.setApiclientKey(null);
|
||||
d.setMerchantSerialNumber(null);
|
||||
});
|
||||
}
|
||||
redisUtil.set(key,list,1L, TimeUnit.DAYS);
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询支付方式")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Payment>> page(PaymentParam param) {
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
return success(paymentService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
// return success(paymentService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部支付方式")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Payment>> list(PaymentParam param) {
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
return success(paymentService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(paymentService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询支付方式")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Payment> get(@PathVariable("id") Integer id) {
|
||||
return success(paymentService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(paymentService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加支付方式")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Payment payment) {
|
||||
if (paymentService.count(new LambdaQueryWrapper<Payment>().eq(Payment::getCode,payment.getCode())) > 0) {
|
||||
return fail(payment.getName() + "已存在");
|
||||
}
|
||||
if (paymentService.save(payment)) {
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.set(key,payment);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改支付方式")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Payment payment) {
|
||||
if (paymentService.updateById(payment)) {
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.set(key,payment);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除支付方式")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
final Payment payment = paymentService.getById(id);
|
||||
System.out.println("payment = " + payment);
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.delete(key);
|
||||
if (paymentService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加支付方式")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Payment> list) {
|
||||
if (paymentService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改支付方式")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Payment> batchParam) {
|
||||
if (batchParam.update(paymentService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除支付方式")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (paymentService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.PlugService;
|
||||
import com.gxwebsoft.common.system.entity.Plug;
|
||||
import com.gxwebsoft.common.system.param.PlugParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 插件扩展控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-12 09:53:07
|
||||
*/
|
||||
@Api(tags = "插件扩展管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/plug")
|
||||
public class PlugController extends BaseController {
|
||||
@Resource
|
||||
private PlugService plugService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询插件扩展")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Plug>> page(PlugParam param) {
|
||||
PageParam<Plug, PlugParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(plugService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(plugService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部插件扩展")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Plug>> list(PlugParam param) {
|
||||
PageParam<Plug, PlugParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(plugService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(plugService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询插件扩展")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Plug> get(@PathVariable("id") Integer id) {
|
||||
return success(plugService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(plugService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加插件扩展")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Plug plug) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
plug.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (plugService.save(plug)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改插件扩展")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Plug plug) {
|
||||
if (plugService.updateById(plug)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除插件扩展")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (plugService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加插件扩展")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Plug> list) {
|
||||
if (plugService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改插件扩展")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Plug> batchParam) {
|
||||
if (batchParam.update(plugService, "plug_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除插件扩展")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (plugService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
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.User;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.common.system.entity.RechargeOrder;
|
||||
import com.gxwebsoft.common.system.entity.UserBalanceLog;
|
||||
import com.gxwebsoft.common.system.param.RechargeOrderParam;
|
||||
import com.gxwebsoft.common.system.service.RechargeOrderService;
|
||||
import com.gxwebsoft.common.system.service.UserBalanceLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_ADMIN;
|
||||
|
||||
/**
|
||||
* 会员充值订单表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-26 23:18:48
|
||||
*/
|
||||
@Api(tags = "会员充值订单表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/sys/recharge-order")
|
||||
public class RechargeOrderController extends BaseController {
|
||||
@Resource
|
||||
private RechargeOrderService rechargeOrderService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:save')")
|
||||
@ApiOperation("会员充值")
|
||||
@PostMapping("/recharge")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> recharge(@RequestBody RechargeOrder rechargeOrder) {
|
||||
// 充值
|
||||
User user = userService.getById(rechargeOrder.getUserId());
|
||||
BigDecimal balance = user.getBalance().add(rechargeOrder.getPayPrice());
|
||||
user.setBalance(balance);
|
||||
userService.updateById(user);
|
||||
// 保存充值记录
|
||||
rechargeOrder.setOrderNo(Long.toString(IdUtil.getSnowflakeNextId()));
|
||||
rechargeOrder.setTradeId(Integer.valueOf(CommonUtil.createOrderNo()));
|
||||
rechargeOrder.setBalance(balance);
|
||||
if (rechargeOrderService.save(rechargeOrder)) {
|
||||
// 记录余额明细
|
||||
UserBalanceLog userBalanceLog = new UserBalanceLog();
|
||||
userBalanceLog.setUserId(rechargeOrder.getUserId());
|
||||
userBalanceLog.setScene(BALANCE_ADMIN);
|
||||
userBalanceLog.setMoney(rechargeOrder.getPayPrice());
|
||||
userBalanceLog.setBalance(balance);
|
||||
userBalanceLog.setTransactionId(UUID.randomUUID().toString());
|
||||
userBalanceLog.setComments("操作人:" + getLoginUser().getNickname());
|
||||
userBalanceLog.setRemark(rechargeOrder.getComments());
|
||||
userBalanceLog.setMerchantCode(rechargeOrder.getMerchantCode());
|
||||
userBalanceLogService.save(userBalanceLog);
|
||||
return success("充值成功", user);
|
||||
}
|
||||
return fail("充值失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:list')")
|
||||
@ApiOperation("分页查询会员充值订单表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<RechargeOrder>> page(RechargeOrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(rechargeOrderService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:list')")
|
||||
@ApiOperation("查询全部会员充值订单表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<RechargeOrder>> list(RechargeOrderParam param) {
|
||||
// 使用关联查询
|
||||
return success(rechargeOrderService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:list')")
|
||||
@ApiOperation("根据id查询会员充值订单表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<RechargeOrder> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(rechargeOrderService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加会员充值订单表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody RechargeOrder rechargeOrder) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
rechargeOrder.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (rechargeOrderService.save(rechargeOrder)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改会员充值订单表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody RechargeOrder rechargeOrder) {
|
||||
if (rechargeOrderService.updateById(rechargeOrder)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除会员充值订单表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (rechargeOrderService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:save')")
|
||||
@ApiOperation("批量充值")
|
||||
@PostMapping("/batchRecharge")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> batchRecharge(@RequestBody List<RechargeOrder> list) {
|
||||
String nickname = getLoginUser().getNickname();
|
||||
String realName = getLoginUser().getRealName();
|
||||
ArrayList<User> users = new ArrayList<>(list.size());
|
||||
ArrayList<UserBalanceLog> logs = new ArrayList<>(list.size());
|
||||
|
||||
list.forEach(d -> {
|
||||
User user = userService.getByIdRel(d.getUserId());
|
||||
BigDecimal balance = user.getBalance().add(d.getPayPrice());
|
||||
user.setBalance(balance);
|
||||
users.add(user);
|
||||
UserBalanceLog userBalanceLog = new UserBalanceLog();
|
||||
userBalanceLog.setUserId(d.getUserId());
|
||||
userBalanceLog.setScene(BALANCE_ADMIN);
|
||||
userBalanceLog.setMoney(d.getPayPrice());
|
||||
userBalanceLog.setBalance(balance);
|
||||
userBalanceLog.setComments("操作员:" + realName);
|
||||
userBalanceLog.setRemark(d.getComments());
|
||||
userBalanceLog.setMerchantCode(d.getMerchantCode());
|
||||
d.setOperator(realName);
|
||||
logs.add(userBalanceLog);
|
||||
});
|
||||
|
||||
if (rechargeOrderService.saveBatch(list)) {
|
||||
// 批量充值
|
||||
userService.updateBatchById(users);
|
||||
// 记录余额明细
|
||||
userBalanceLogService.saveBatch(logs);
|
||||
return success("充值成功");
|
||||
}
|
||||
return fail("充值失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:update')")
|
||||
@ApiOperation("批量修改会员充值订单表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<RechargeOrder> batchParam) {
|
||||
if (batchParam.update(rechargeOrderService, "order_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:rechargeOrder:remove')")
|
||||
@ApiOperation("批量删除会员充值订单表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (rechargeOrderService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/redis-util")
|
||||
@Api(tags = "Redis缓存工具接口")
|
||||
public class RedisUtilController extends BaseController {
|
||||
private CacheClient cacheClient;
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private static final String SPLIT = ":";
|
||||
private static final String PREFIX_ENTITY_LIKE = "focus:user";
|
||||
private static final String PREFIX_USER_LIKE = "like:user";
|
||||
private static final String PREFIX_FOLLOWEE = "followee";
|
||||
private static final String PREFIX_FOLLOWER = "follower";
|
||||
|
||||
|
||||
public RedisUtilController(StringRedisTemplate redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@ApiOperation("添加关注")
|
||||
@PostMapping("/addFocus")
|
||||
public ApiResult<?> addFocus(@RequestBody User user) {
|
||||
final Integer userId = user.getUserId();
|
||||
redisTemplate.opsForZSet().incrementScore(getFocusKey(userId), userId.toString(), 1);
|
||||
return success("关注成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个用户的关注数
|
||||
* @return like:entity:[entityId] ->set(userId)
|
||||
*/
|
||||
public static String getFocusKey(Integer userId) {
|
||||
return PREFIX_ENTITY_LIKE + SPLIT + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个用户的赞
|
||||
* @return like:entity:[entityId] ->set(userId)
|
||||
*/
|
||||
public static String getEntityLikeKey(int entityType, int entityId) {
|
||||
return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个用户的赞
|
||||
* @return like:user:[userId] ->int
|
||||
*/
|
||||
public static String getUserLikeKey(int userId) {
|
||||
return PREFIX_USER_LIKE + SPLIT + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个用户关注的实体(键:用户Id,值:实体Id)
|
||||
* @return followee:[userId:entityType] ->zSet(entityId,now)
|
||||
*/
|
||||
public static String getFolloweeKey(int userId, int entityType) {
|
||||
return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 某个实体拥有的粉丝(键:实体Id,值:用户Id)
|
||||
* @return follower:[entityType:entityId] ->zSet(entityId,now)
|
||||
*/
|
||||
public static String getFollowerKey(int entityType, int entityId) {
|
||||
return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Role;
|
||||
import com.gxwebsoft.common.system.param.RoleParam;
|
||||
import com.gxwebsoft.common.system.service.RoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:02
|
||||
*/
|
||||
@Api(tags = "角色管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/role")
|
||||
public class RoleController extends BaseController {
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询角色")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Role>> page(RoleParam param) {
|
||||
PageParam<Role, RoleParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc");
|
||||
return success(roleService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部角色")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Role>> list(RoleParam param) {
|
||||
PageParam<Role, RoleParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc");
|
||||
return success(roleService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询角色")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Role> get(@PathVariable("id") Integer id) {
|
||||
return success(roleService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加角色")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Role role) {
|
||||
if (roleService.count(new LambdaQueryWrapper<Role>().eq(Role::getRoleCode, role.getRoleCode())) > 0) {
|
||||
return fail("角色标识已存在");
|
||||
}
|
||||
if (roleService.count(new LambdaQueryWrapper<Role>().eq(Role::getRoleName, role.getRoleName())) > 0) {
|
||||
return fail("角色名称已存在");
|
||||
}
|
||||
if (roleService.save(role)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改角色")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Role role) {
|
||||
if (role.getRoleCode() != null && roleService.count(new LambdaQueryWrapper<Role>()
|
||||
.eq(Role::getRoleCode, role.getRoleCode())
|
||||
.ne(Role::getRoleId, role.getRoleId())) > 0) {
|
||||
return fail("角色标识已存在");
|
||||
}
|
||||
if (role.getRoleName() != null && roleService.count(new LambdaQueryWrapper<Role>()
|
||||
.eq(Role::getRoleName, role.getRoleName())
|
||||
.ne(Role::getRoleId, role.getRoleId())) > 0) {
|
||||
return fail("角色名称已存在");
|
||||
}
|
||||
if (roleService.updateById(role)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除角色")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (roleService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加角色")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<List<String>> saveBatch(@RequestBody List<Role> list) {
|
||||
// 校验是否重复
|
||||
if (CommonUtil.checkRepeat(list, Role::getRoleName)) {
|
||||
return fail("角色名称存在重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, Role::getRoleCode)) {
|
||||
return fail("角色标识存在重复", null);
|
||||
}
|
||||
// 校验是否存在
|
||||
List<Role> codeExists = roleService.list(new LambdaQueryWrapper<Role>().in(Role::getRoleCode,
|
||||
list.stream().map(Role::getRoleCode).collect(Collectors.toList())));
|
||||
if (codeExists.size() > 0) {
|
||||
return fail("角色标识已存在", codeExists.stream().map(Role::getRoleCode)
|
||||
.collect(Collectors.toList())).setCode(2);
|
||||
}
|
||||
List<Role> nameExists = roleService.list(new LambdaQueryWrapper<Role>().in(Role::getRoleName,
|
||||
list.stream().map(Role::getRoleCode).collect(Collectors.toList())));
|
||||
if (nameExists.size() > 0) {
|
||||
return fail("角色标识已存在", nameExists.stream().map(Role::getRoleCode)
|
||||
.collect(Collectors.toList())).setCode(3);
|
||||
}
|
||||
if (roleService.saveBatch(list)) {
|
||||
return success("添加成功", null);
|
||||
}
|
||||
return fail("添加失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除角色")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (roleService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.RoleMenu;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.RoleMenuService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色菜单控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:01
|
||||
*/
|
||||
@Api(tags = "角色菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/role-menu")
|
||||
public class RoleMenuController extends BaseController {
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询角色菜单")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<List<Menu>> list(@PathVariable("id") Integer roleId) {
|
||||
List<Menu> menus = menuService.list(new LambdaQueryWrapper<Menu>().orderByAsc(Menu::getSortNumber));
|
||||
List<RoleMenu> roleMenus = roleMenuService.list(new LambdaQueryWrapper<RoleMenu>()
|
||||
.eq(RoleMenu::getRoleId, roleId));
|
||||
for (Menu menu : menus) {
|
||||
menu.setChecked(roleMenus.stream().anyMatch((d) -> d.getMenuId().equals(menu.getMenuId())));
|
||||
}
|
||||
return success(menus);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PreAuthorize("hasAuthority('sys:role:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改角色菜单")
|
||||
@PutMapping("/{id}")
|
||||
public ApiResult<?> update(@PathVariable("id") Integer roleId, @RequestBody List<Integer> menuIds) {
|
||||
roleMenuService.remove(new LambdaUpdateWrapper<RoleMenu>().eq(RoleMenu::getRoleId, roleId));
|
||||
if (menuIds != null && menuIds.size() > 0) {
|
||||
List<RoleMenu> roleMenuList = new ArrayList<>();
|
||||
for (Integer menuId : menuIds) {
|
||||
RoleMenu roleMenu = new RoleMenu();
|
||||
roleMenu.setRoleId(roleId);
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenuList.add(roleMenu);
|
||||
}
|
||||
if (!roleMenuService.saveBatch(roleMenuList)) {
|
||||
throw new BusinessException("保存失败");
|
||||
}
|
||||
}
|
||||
return success("保存成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加角色菜单")
|
||||
@PostMapping("/{id}")
|
||||
public ApiResult<?> addRoleAuth(@PathVariable("id") Integer roleId, @RequestBody Integer menuId) {
|
||||
RoleMenu roleMenu = new RoleMenu();
|
||||
roleMenu.setRoleId(roleId);
|
||||
roleMenu.setMenuId(menuId);
|
||||
if (roleMenuService.save(roleMenu)) {
|
||||
return success();
|
||||
}
|
||||
return fail();
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("移除角色菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer roleId, @RequestBody Integer menuId) {
|
||||
if (roleMenuService.remove(new LambdaUpdateWrapper<RoleMenu>()
|
||||
.eq(RoleMenu::getRoleId, roleId).eq(RoleMenu::getMenuId, menuId))) {
|
||||
return success();
|
||||
}
|
||||
return fail();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.entity.Tenant;
|
||||
import com.gxwebsoft.common.system.param.SettingParam;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.common.system.service.TenantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统设置控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "系统设置管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/setting")
|
||||
public class SettingController extends BaseController {
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询系统设置")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Setting>> page(SettingParam param) {
|
||||
PageParam<Setting, SettingParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(settingService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(settingService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部系统设置")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Setting>> list(SettingParam param) {
|
||||
PageParam<Setting, SettingParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(settingService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(settingService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询系统设置")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Setting> get(@PathVariable("id") Integer id) {
|
||||
return success(settingService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(settingService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加系统设置")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Setting setting) {
|
||||
if (settingService.save(setting)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改系统设置")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Setting setting) {
|
||||
if (settingService.updateById(setting)) {
|
||||
// 更新系统设置信息到缓存 key = ""
|
||||
// String key = StrUtil.upperFirst(setting.getSettingKey()).concat(":").concat(getTenantId().toString());
|
||||
String key = setting.getSettingKey().concat(":").concat(setting.getTenantId().toString());
|
||||
redisUtil.set(key, JSON.parseObject(setting.getContent()));
|
||||
// 更新租户信息
|
||||
if (setting.getSettingKey().equals("setting")) {
|
||||
final String content = setting.getContent();
|
||||
final JSONObject jsonObject = JSONObject.parseObject(content);
|
||||
final String siteName = jsonObject.getString("siteName");
|
||||
final String logo = jsonObject.getString("logo");
|
||||
final Tenant tenant = new Tenant();
|
||||
tenant.setTenantName(siteName);
|
||||
tenant.setTenantId(getTenantId());
|
||||
tenant.setLogo(logo);
|
||||
tenantService.updateById(tenant);
|
||||
}
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除系统设置")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (settingService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加系统设置")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Setting> list) {
|
||||
if (settingService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改系统设置")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Setting> batchParam) {
|
||||
if (batchParam.update(settingService, "setting_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除系统设置")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (settingService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:data')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询租户设置信息")
|
||||
@GetMapping("/data")
|
||||
public ApiResult<?> data() {
|
||||
return success(settingService.getData("setting"));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:setting:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("更新主题皮肤")
|
||||
@PutMapping("/theme")
|
||||
public ApiResult<?> theme(@RequestBody Setting setting) {
|
||||
String key = "theme:".concat(getTenantId().toString());
|
||||
// 新增
|
||||
final Setting one = settingService.getOne(new LambdaQueryWrapper<Setting>().eq(Setting::getSettingKey, setting.getSettingKey()));
|
||||
if(one == null){
|
||||
settingService.save(setting);
|
||||
redisUtil.set(key,setting.getContent());
|
||||
return success("保存成功");
|
||||
}
|
||||
// 更新
|
||||
final Setting update = settingService.getOne(new LambdaQueryWrapper<Setting>().eq(Setting::getSettingKey, setting.getSettingKey()));
|
||||
update.setContent(setting.getContent());
|
||||
if (settingService.updateById(update)) {
|
||||
redisUtil.set(key,setting.getContent());
|
||||
return success("更新成功");
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
@ApiOperation("更新主题皮肤")
|
||||
@GetMapping("/getTheme")
|
||||
public ApiResult<?> getTheme() {
|
||||
String key = "theme:".concat(getTenantId().toString());
|
||||
return success("获取成功",redisUtil.get(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.PlugParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.RoleMenuService;
|
||||
import com.gxwebsoft.common.system.service.TenantService;
|
||||
import com.gxwebsoft.common.system.param.TenantParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 租户控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-07-17 17:49:53
|
||||
*/
|
||||
@Api(tags = "租户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/tenant")
|
||||
public class TenantController extends BaseController {
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("分页查询租户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||
return success(tenantService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("查询全部租户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Tenant>> list(TenantParam param) {
|
||||
// 使用关联查询
|
||||
return success(tenantService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("根据id查询租户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Tenant> get(@PathVariable("id") Integer id) {
|
||||
Tenant tenant = tenantService.getById(id);
|
||||
// 附加企业信息
|
||||
List<Company> list = companyService.list(new LambdaQueryWrapper<Company>().eq(Company::getTenantId, tenant.getTenantId()).eq(Company::getAuthoritative, true));
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
final Company company = list.get(0);
|
||||
tenant.setCompany(company);
|
||||
}
|
||||
return success(tenant);
|
||||
}
|
||||
|
||||
@ApiOperation("根据code搜索租户")
|
||||
@GetMapping("/getTenantId/{code}")
|
||||
public ApiResult<Integer> getTenantIdByKeywords(@PathVariable("code") String code) {
|
||||
String key = "TenantCode:".concat(code);
|
||||
// 查询缓存
|
||||
final String string = redisUtil.get(key);
|
||||
if(string != null){
|
||||
return success(JSONUtil.parseObject(string, Integer.class));
|
||||
}
|
||||
// 使用关联查询
|
||||
final Tenant tenant = tenantService.getOne(new LambdaUpdateWrapper<Tenant>().eq(Tenant::getTenantId, code).or().eq(Tenant::getTenantCode, code).last("limit 1"));
|
||||
if(tenant == null){
|
||||
return fail("应用不存在或已过期",null);
|
||||
}
|
||||
redisUtil.set(key,tenant.getTenantId().toString(),1L, TimeUnit.DAYS);
|
||||
return success(tenant.getTenantId());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加租户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Tenant tenant) {
|
||||
if (tenantService.save(tenant)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改租户")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Tenant tenant) {
|
||||
if (tenantService.updateById(tenant)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (tenantService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加租户")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Tenant> list) {
|
||||
if (tenantService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改租户")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Tenant> batchParam) {
|
||||
if (batchParam.update(tenantService, "tenant_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除租户")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (tenantService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("租户角色权限初始化")
|
||||
@GetMapping("/role-menu/{id}")
|
||||
public ApiResult<List<Menu>> initialization(@PathVariable("id") Integer roleId) {
|
||||
List<Menu> menus = menuService.list(new LambdaQueryWrapper<Menu>().orderByAsc(Menu::getSortNumber));
|
||||
List<RoleMenu> roleMenus = roleMenuService.list(new LambdaQueryWrapper<RoleMenu>()
|
||||
.eq(RoleMenu::getRoleId, roleId));
|
||||
for (Menu menu : menus) {
|
||||
menu.setChecked(roleMenus.stream().anyMatch((d) -> d.getMenuId().equals(menu.getMenuId())));
|
||||
}
|
||||
List<Integer> menuIds = menus.stream().map(Menu::getMenuId).collect(Collectors.toList());
|
||||
roleMenuService.remove(new LambdaUpdateWrapper<RoleMenu>().eq(RoleMenu::getRoleId, roleId));
|
||||
if (menuIds.size() > 0) {
|
||||
List<RoleMenu> roleMenuList = new ArrayList<>();
|
||||
for (Integer menuId : menuIds) {
|
||||
RoleMenu roleMenu = new RoleMenu();
|
||||
roleMenu.setRoleId(roleId);
|
||||
roleMenu.setMenuId(menuId);
|
||||
roleMenuList.add(roleMenu);
|
||||
}
|
||||
if (!roleMenuService.saveBatch(roleMenuList)) {
|
||||
throw new BusinessException("保存失败");
|
||||
}
|
||||
}
|
||||
return success(menus);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.UserBalanceLog;
|
||||
import com.gxwebsoft.common.system.param.UserBalanceLogParam;
|
||||
import com.gxwebsoft.common.system.service.UserBalanceLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户余额变动明细表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-04-21 15:59:09
|
||||
*/
|
||||
@Api(tags = "用户余额变动明细表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/sys/user-balance-log")
|
||||
public class UserBalanceLogController extends BaseController {
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户余额变动明细表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserBalanceLog>> page(UserBalanceLogParam param) {
|
||||
// 使用关联查询
|
||||
return success(userBalanceLogService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户余额变动明细表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserBalanceLog>> list(UserBalanceLogParam param) {
|
||||
PageParam<UserBalanceLog, UserBalanceLogParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(userBalanceLogService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(userBalanceLogService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询用户余额变动明细表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserBalanceLog> get(@PathVariable("id") Integer id) {
|
||||
return success(userBalanceLogService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(userBalanceLogService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户余额变动明细表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserBalanceLog userBalanceLog) {
|
||||
// 记录当前登录用户id、租户id、商户编号
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
userBalanceLog.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (userBalanceLogService.save(userBalanceLog)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户余额变动明细表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserBalanceLog userBalanceLog) {
|
||||
if (userBalanceLogService.updateById(userBalanceLog)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户余额变动明细表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userBalanceLogService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加用户余额变动明细表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserBalanceLog> list) {
|
||||
if (userBalanceLogService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户余额变动明细表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserBalanceLog> batchParam) {
|
||||
if (batchParam.update(userBalanceLogService, "log_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userBalanceLog:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户余额变动明细表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userBalanceLogService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserCollectionService;
|
||||
import com.gxwebsoft.common.system.entity.UserCollection;
|
||||
import com.gxwebsoft.common.system.param.UserCollectionParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 我的收藏控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-28 18:08:32
|
||||
*/
|
||||
@Api(tags = "我的收藏管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-collection")
|
||||
public class UserCollectionController extends BaseController {
|
||||
@Resource
|
||||
private UserCollectionService userCollectionService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:list')")
|
||||
@ApiOperation("分页查询我的收藏")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserCollection>> page(UserCollectionParam param) {
|
||||
// 使用关联查询
|
||||
return success(userCollectionService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:list')")
|
||||
@ApiOperation("查询全部我的收藏")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserCollection>> list(UserCollectionParam param) {
|
||||
// 使用关联查询
|
||||
return success(userCollectionService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:list')")
|
||||
@ApiOperation("根据id查询我的收藏")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserCollection> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(userCollectionService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加和取消收藏")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserCollection userCollection) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
userCollection.setUserId(loginUser.getUserId());
|
||||
userCollection.setTid(userCollection.getTid());
|
||||
final UserCollection one = userCollectionService.getOne(new LambdaQueryWrapper<UserCollection>().eq(UserCollection::getUserId, loginUser.getUserId()).eq(UserCollection::getTid, userCollection.getTid()).last("limit 1"));
|
||||
if (one != null) {
|
||||
userCollectionService.removeById(one.getId());
|
||||
return success("已取消收藏");
|
||||
}
|
||||
if (userCollectionService.save(userCollection)) {
|
||||
return success("已添加收藏");
|
||||
}
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改我的收藏")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserCollection userCollection) {
|
||||
if (userCollectionService.updateById(userCollection)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除我的收藏")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userCollectionService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加我的收藏")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserCollection> list) {
|
||||
if (userCollectionService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改我的收藏")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserCollection> batchParam) {
|
||||
if (batchParam.update(userCollectionService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userCollection:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除我的收藏")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userCollectionService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.UserImportParam;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.DictionaryDataService;
|
||||
import com.gxwebsoft.common.system.service.OrganizationService;
|
||||
import com.gxwebsoft.common.system.service.RoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:41
|
||||
*/
|
||||
@Api(tags = "用户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user")
|
||||
public class UserController extends BaseController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@ApiOperation("分页查询用户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<User>> page(UserParam param) {
|
||||
return success(userService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@ApiOperation("查询全部用户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<User>> list(UserParam param) {
|
||||
return success(userService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@ApiOperation("根据id查询用户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<User> get(@PathVariable("id") Integer id) {
|
||||
return success(userService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@ApiOperation("根据手机号码查询用户")
|
||||
@GetMapping("/getByPhone/{phone}")
|
||||
public ApiResult<User> getByPhone(@PathVariable("phone") String phone) {
|
||||
return success(userService.getByPhone(phone));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:save')")
|
||||
@ApiOperation("添加用户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody User user) {
|
||||
user.setStatus(0);
|
||||
user.setPassword(userService.encodePassword(user.getPassword()));
|
||||
if (userService.saveUser(user)) {
|
||||
return success("添加成功",user.getUserId());
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:save')")
|
||||
@ApiOperation("批量添加用户")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<User> userList) {
|
||||
userList.forEach(d -> {
|
||||
d.setStatus(0);
|
||||
if (d.getPassword() != null) {
|
||||
d.setPassword(userService.encodePassword(d.getPassword()));
|
||||
}
|
||||
});
|
||||
if (userService.saveBatch(userList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:save')")
|
||||
@ApiOperation("批量添加用户并返回userId")
|
||||
@PostMapping("/batchBackUserId")
|
||||
public ApiResult<?> saveBatchBackUserId(@RequestBody List<User> userList) {
|
||||
userList.forEach(d -> {
|
||||
d.setStatus(0);
|
||||
d.setPassword(userService.encodePassword(d.getPassword()));
|
||||
});
|
||||
final Set<String> phones = userList.stream().map(User::getPhone).collect(Collectors.toSet());
|
||||
if (userService.saveBatch(userList)) {
|
||||
final UserParam userParam = new UserParam();
|
||||
userParam.setPhones(phones);
|
||||
userParam.setLimit(500L);
|
||||
final PageResult<User> result = userService.pageRel(userParam);
|
||||
final Set<Integer> collect = result.getList().stream().map(User::getUserId).collect(Collectors.toSet());
|
||||
return success("添加成功",collect);
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody User user) {
|
||||
user.setStatus(null);
|
||||
user.setUsername(null);
|
||||
user.setPassword(null);
|
||||
if (userService.updateUser(user)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<User> batchParam) {
|
||||
if (batchParam.update(userService, User::getUserId)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id数组", required = true, dataType = "string", dataTypeClass = String.class)
|
||||
})
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> deleteBatch(@RequestBody List<Integer> ids) {
|
||||
if (userService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户状态")
|
||||
@PutMapping("/status")
|
||||
public ApiResult<?> updateStatus(@RequestBody User user) {
|
||||
if (user.getUserId() == null || user.getStatus() == null || !Arrays.asList(0, 1).contains(user.getStatus())) {
|
||||
return fail("参数不正确");
|
||||
}
|
||||
User u = new User();
|
||||
u.setUserId(user.getUserId());
|
||||
u.setStatus(user.getStatus());
|
||||
if (userService.updateById(u)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改推荐状态")
|
||||
@PutMapping("/recommend")
|
||||
public ApiResult<?> updateRecommend(@RequestBody User user) {
|
||||
if (user.getUserId() == null || user.getRecommend() == null || !Arrays.asList(0, 1).contains(user.getRecommend())) {
|
||||
return fail("参数不正确");
|
||||
}
|
||||
User u = new User();
|
||||
u.setUserId(user.getUserId());
|
||||
u.setRecommend(user.getRecommend());
|
||||
if (userService.updateById(u)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户状态")
|
||||
@PutMapping("/status/batch")
|
||||
public ApiResult<?> updateStatusBatch(@RequestBody BatchParam<Integer> batchParam) {
|
||||
if (!Arrays.asList(0, 1).contains(batchParam.getData())) {
|
||||
return fail("状态值不正确");
|
||||
}
|
||||
if (userService.update(new LambdaUpdateWrapper<User>()
|
||||
.in(User::getUserId, batchParam.getIds())
|
||||
.set(User::getStatus, batchParam.getData()))) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("重置密码")
|
||||
@PutMapping("/password")
|
||||
public ApiResult<?> resetPassword(@RequestBody User user) {
|
||||
if (user.getUserId() == null || StrUtil.isBlank(user.getPassword())) {
|
||||
return fail("参数不正确");
|
||||
}
|
||||
User u = new User();
|
||||
u.setUserId(user.getUserId());
|
||||
u.setPassword(userService.encodePassword(user.getPassword()));
|
||||
if (userService.updateById(u)) {
|
||||
return success("重置成功");
|
||||
} else {
|
||||
return fail("重置失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量重置密码")
|
||||
@PutMapping("/password/batch")
|
||||
public ApiResult<?> resetPasswordBatch(@RequestBody BatchParam<String> batchParam) {
|
||||
if (batchParam.getIds() == null || batchParam.getIds().size() == 0) {
|
||||
return fail("请选择用户");
|
||||
}
|
||||
if (batchParam.getData() == null) {
|
||||
return fail("请输入密码");
|
||||
}
|
||||
if (userService.update(new LambdaUpdateWrapper<User>()
|
||||
.in(User::getUserId, batchParam.getIds())
|
||||
.set(User::getPassword, userService.encodePassword(batchParam.getData())))) {
|
||||
return success("重置成功");
|
||||
} else {
|
||||
return fail("重置失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("检查用户是否存在")
|
||||
@GetMapping("/existence")
|
||||
public ApiResult<?> existence(ExistenceParam<User> param) {
|
||||
if (param.isExistence(userService, User::getUserId)) {
|
||||
return success(param.getValue() + "已存在");
|
||||
}
|
||||
return fail(param.getValue() + "不存在");
|
||||
}
|
||||
|
||||
/**
|
||||
* excel导入用户
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('sys:user:save')")
|
||||
@ApiOperation("导入用户")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/import")
|
||||
public ApiResult<List<String>> importBatch(MultipartFile file) {
|
||||
ImportParams importParams = new ImportParams();
|
||||
try {
|
||||
List<UserImportParam> list = ExcelImportUtil.importExcel(file.getInputStream(),
|
||||
UserImportParam.class, importParams);
|
||||
// 校验是否重复
|
||||
if (CommonUtil.checkRepeat(list, UserImportParam::getUsername)) {
|
||||
return fail("账号存在重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, UserImportParam::getPhone)) {
|
||||
return fail("手机号存在重复", null);
|
||||
}
|
||||
// 校验是否存在
|
||||
List<User> usernameExists = userService.list(new LambdaQueryWrapper<User>().in(User::getUsername,
|
||||
list.stream().map(UserImportParam::getUsername).collect(Collectors.toList())));
|
||||
if (usernameExists.size() > 0) {
|
||||
return fail("账号已经存在",
|
||||
usernameExists.stream().map(User::getUsername).collect(Collectors.toList()));
|
||||
}
|
||||
List<User> phoneExists = userService.list(new LambdaQueryWrapper<User>().in(User::getPhone,
|
||||
list.stream().map(UserImportParam::getPhone).collect(Collectors.toList())));
|
||||
if (phoneExists.size() > 0) {
|
||||
return fail("手机号已经存在",
|
||||
phoneExists.stream().map(User::getPhone).collect(Collectors.toList()));
|
||||
}
|
||||
// 添加
|
||||
List<User> users = new ArrayList<>();
|
||||
for (UserImportParam one : list) {
|
||||
User u = new User();
|
||||
u.setStatus(0);
|
||||
u.setUsername(one.getUsername());
|
||||
u.setPassword(userService.encodePassword(one.getPassword()));
|
||||
u.setNickname(one.getNickname());
|
||||
u.setPhone(one.getPhone());
|
||||
Role role = roleService.getOne(new QueryWrapper<Role>()
|
||||
.eq("role_name", one.getRoleName()), false);
|
||||
if (role == null) {
|
||||
return fail("角色不存在", Collections.singletonList(one.getRoleName()));
|
||||
} else {
|
||||
u.setRoles(Collections.singletonList(role));
|
||||
}
|
||||
Organization organization = organizationService.getOne(new QueryWrapper<Organization>()
|
||||
.eq("organization_full_name", one.getOrganizationName()), false);
|
||||
if (organization == null) {
|
||||
return fail("机构不存在", Collections.singletonList(one.getOrganizationName()));
|
||||
} else {
|
||||
u.setOrganizationId(organization.getOrganizationId());
|
||||
}
|
||||
DictionaryData sex = dictionaryDataService.getByDictCodeAndName("sex", one.getSexName());
|
||||
if (sex == null) {
|
||||
return fail("性别不存在", Collections.singletonList(one.getSexName()));
|
||||
} else {
|
||||
u.setSex(sex.getDictDataCode());
|
||||
}
|
||||
}
|
||||
if (userService.saveBatch(users)) {
|
||||
return success("导入成功", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fail("导入失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@PostMapping("/getAvatarByMpWx")
|
||||
@ApiOperation("更新微信头像")
|
||||
public ApiResult<?> getAvatarByMpWx(@RequestBody User user){
|
||||
user.setAvatar("https://oa.gxwebsoft.com/assets/logo.7ccfefb9.svg");
|
||||
if (userService.updateUser(user)) {
|
||||
return success("更新成功");
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
@PostMapping("/updatePointsBySign")
|
||||
@ApiOperation("签到成功累加积分")
|
||||
public ApiResult<?> updatePointsBySign(){
|
||||
final User loginUser = getLoginUser();
|
||||
loginUser.setPoints(loginUser.getPoints() + 1);
|
||||
if (userService.updateUser(loginUser)) {
|
||||
return success("签到成功");
|
||||
}
|
||||
return fail("签到失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@PutMapping("/updateUserBalance")
|
||||
@ApiOperation("更新用户余额")
|
||||
public ApiResult<?> updateUserBalance(@RequestBody User user){
|
||||
if (getLoginUser() == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
if (userService.updateUser(user)) {
|
||||
return success("操作成功");
|
||||
}
|
||||
return fail("操作失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("统计用户余额")
|
||||
@GetMapping("/countUserBalance")
|
||||
public ApiResult<?> countUserBalance(User param) {
|
||||
final LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.gt(User::getBalance, 0);
|
||||
if (!param.getOrganizationId().equals(0)) {
|
||||
wrapper.eq(User::getOrganizationId,param.getOrganizationId());
|
||||
}
|
||||
final List<User> list = userService.list(wrapper);
|
||||
final BigDecimal totalBalance = list.stream().map(User::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// System.out.println("统计用户余额 = " + totalBalance);
|
||||
return success("统计成功",totalBalance);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.utils.FileServerUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.service.UserFileService;
|
||||
import com.gxwebsoft.common.system.entity.UserFile;
|
||||
import com.gxwebsoft.common.system.param.UserFileParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户文件控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-07-21 14:34:40
|
||||
*/
|
||||
@Api(tags = "用户文件管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-file")
|
||||
public class UserFileController extends BaseController {
|
||||
@Resource
|
||||
private UserFileService userFileService;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户文件")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserFile>> page(UserFileParam param, HttpServletRequest request) {
|
||||
param.setUserId(getLoginUserId());
|
||||
PageParam<UserFile, UserFileParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("is_directory desc");
|
||||
PageParam<UserFile, UserFileParam> result = userFileService.page(page, page.getWrapper());
|
||||
List<UserFile> records = result.getRecords();
|
||||
String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/system/user-file") + "/file";
|
||||
for (UserFile record : records) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setUrl(requestURL + "/" + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail/" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download/" + record.getPath());
|
||||
}
|
||||
}
|
||||
return success(records, result.getTotal());
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户文件")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserFile>> list(UserFileParam param, HttpServletRequest request) {
|
||||
param.setUserId(getLoginUserId());
|
||||
PageParam<UserFile, UserFileParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("is_directory desc");
|
||||
List<UserFile> records = userFileService.list(page.getOrderWrapper());
|
||||
String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/system/user-file") + "/file";
|
||||
for (UserFile record : records) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setUrl(requestURL + "/" + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail/" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download/" + record.getPath());
|
||||
}
|
||||
}
|
||||
return success(records);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户文件")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserFile userFile) {
|
||||
userFile.setUserId(getLoginUserId());
|
||||
if (userFile.getParentId() == null) {
|
||||
userFile.setParentId(0);
|
||||
}
|
||||
if (userFile.getIsDirectory() != null && userFile.getIsDirectory().equals(1)) {
|
||||
if (userFileService.count(new LambdaQueryWrapper<UserFile>()
|
||||
.eq(UserFile::getName, userFile.getName())
|
||||
.eq(UserFile::getParentId, userFile.getParentId())
|
||||
.eq(UserFile::getUserId, userFile.getUserId())) > 0) {
|
||||
return fail("文件夹名称已存在");
|
||||
}
|
||||
}
|
||||
if (userFileService.save(userFile)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户文件")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserFile userFile) {
|
||||
Integer loginUserId = getLoginUserId();
|
||||
UserFile old = userFileService.getById(userFile.getId());
|
||||
UserFile entity = new UserFile();
|
||||
if (StrUtil.isNotBlank(userFile.getName())) {
|
||||
entity.setName(userFile.getName());
|
||||
}
|
||||
if (userFile.getParentId() != null) {
|
||||
entity.setParentId(userFile.getParentId());
|
||||
}
|
||||
if (!old.getUserId().equals(loginUserId) ||
|
||||
(entity.getName() == null && entity.getParentId() == null)) {
|
||||
return fail("修改失败");
|
||||
}
|
||||
if (old.getIsDirectory() != null && old.getIsDirectory().equals(1)) {
|
||||
if (userFileService.count(new LambdaQueryWrapper<UserFile>()
|
||||
.eq(UserFile::getName, entity.getName() == null ? old.getName() : entity.getName())
|
||||
.eq(UserFile::getParentId, entity.getParentId() == null ? old.getParentId() : entity.getParentId())
|
||||
.eq(UserFile::getUserId, loginUserId)
|
||||
.ne(UserFile::getId, old.getId())) > 0) {
|
||||
return fail("文件夹名称已存在");
|
||||
}
|
||||
}
|
||||
if (userFileService.update(entity, new LambdaUpdateWrapper<UserFile>()
|
||||
.eq(UserFile::getId, userFile.getId())
|
||||
.eq(UserFile::getUserId, loginUserId))) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户文件")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userFileService.remove(new LambdaUpdateWrapper<UserFile>()
|
||||
.eq(UserFile::getId, id)
|
||||
.eq(UserFile::getUserId, getLoginUserId()))) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户文件")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userFileService.remove(new LambdaUpdateWrapper<UserFile>()
|
||||
.in(UserFile::getId, ids)
|
||||
.eq(UserFile::getUserId, getLoginUserId()))) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserGradeService;
|
||||
import com.gxwebsoft.common.system.entity.UserGrade;
|
||||
import com.gxwebsoft.common.system.param.UserGradeParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户会员等级表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-07 22:51:17
|
||||
*/
|
||||
@Api(tags = "用户会员等级表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-grade")
|
||||
public class UserGradeController extends BaseController {
|
||||
@Resource
|
||||
private UserGradeService userGradeService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户会员等级表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserGrade>> page(UserGradeParam param) {
|
||||
// 使用关联查询
|
||||
return success(userGradeService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户会员等级表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserGrade>> list(UserGradeParam param) {
|
||||
// 使用关联查询
|
||||
return success(userGradeService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询用户会员等级表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserGrade> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(userGradeService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户会员等级表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserGrade userGrade) {
|
||||
if (userGradeService.save(userGrade)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户会员等级表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserGrade userGrade) {
|
||||
if (userGradeService.updateById(userGrade)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户会员等级表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userGradeService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加用户会员等级表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserGrade> list) {
|
||||
if (userGradeService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户会员等级表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserGrade> batchParam) {
|
||||
if (batchParam.update(userGradeService, "grade_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGrade:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户会员等级表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userGradeService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.service.UserGroupService;
|
||||
import com.gxwebsoft.common.system.entity.UserGroup;
|
||||
import com.gxwebsoft.common.system.param.UserGroupParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户分组管理表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-28 15:16:39
|
||||
*/
|
||||
@Api(tags = "用户分组管理表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-group")
|
||||
public class UserGroupController extends BaseController {
|
||||
@Resource
|
||||
private UserGroupService userGroupService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户分组管理表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserGroup>> page(UserGroupParam param) {
|
||||
PageParam<UserGroup, UserGroupParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(userGroupService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(userGroupService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户分组管理表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserGroup>> list(UserGroupParam param) {
|
||||
PageParam<UserGroup, UserGroupParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(userGroupService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(userGroupService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询用户分组管理表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserGroup> get(@PathVariable("id") Integer id) {
|
||||
return success(userGroupService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(userGroupService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户分组管理表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserGroup userGroup) {
|
||||
if (userGroupService.save(userGroup)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户分组管理表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserGroup userGroup) {
|
||||
if (userGroupService.updateById(userGroup)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户分组管理表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userGroupService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加用户分组管理表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserGroup> list) {
|
||||
if (userGroupService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户分组管理表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserGroup> batchParam) {
|
||||
if (batchParam.update(userGroupService, "group_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userGroup:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户分组管理表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userGroupService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserOauthService;
|
||||
import com.gxwebsoft.common.system.entity.UserOauth;
|
||||
import com.gxwebsoft.common.system.param.UserOauthParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方用户信息表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-07 22:39:46
|
||||
*/
|
||||
@Api(tags = "第三方用户信息表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-oauth")
|
||||
public class UserOauthController extends BaseController {
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询第三方用户信息表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserOauth>> page(UserOauthParam param) {
|
||||
// 使用关联查询
|
||||
return success(userOauthService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部第三方用户信息表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserOauth>> list(UserOauthParam param) {
|
||||
// 使用关联查询
|
||||
return success(userOauthService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询第三方用户信息表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserOauth> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(userOauthService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加第三方用户信息表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserOauth userOauth) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
userOauth.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (userOauthService.save(userOauth)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改第三方用户信息表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserOauth userOauth) {
|
||||
if (userOauthService.updateById(userOauth)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除第三方用户信息表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userOauthService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加第三方用户信息表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserOauth> list) {
|
||||
if (userOauthService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改第三方用户信息表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserOauth> batchParam) {
|
||||
if (batchParam.update(userOauthService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userOauth:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除第三方用户信息表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userOauthService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserRefereeService;
|
||||
import com.gxwebsoft.common.system.entity.UserReferee;
|
||||
import com.gxwebsoft.common.system.param.UserRefereeParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户推荐关系表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-10-07 22:56:36
|
||||
*/
|
||||
@Api(tags = "用户推荐关系表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/user-referee")
|
||||
public class UserRefereeController extends BaseController {
|
||||
@Resource
|
||||
private UserRefereeService userRefereeService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户推荐关系表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserReferee>> page(UserRefereeParam param) {
|
||||
// 使用关联查询
|
||||
return success(userRefereeService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户推荐关系表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<UserReferee>> list(UserRefereeParam param) {
|
||||
// 使用关联查询
|
||||
return success(userRefereeService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询用户推荐关系表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserReferee> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(userRefereeService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户推荐关系表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody UserReferee userReferee) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
userReferee.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (userRefereeService.save(userReferee)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改用户推荐关系表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody UserReferee userReferee) {
|
||||
if (userRefereeService.updateById(userReferee)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除用户推荐关系表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (userRefereeService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加用户推荐关系表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<UserReferee> list) {
|
||||
if (userRefereeService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改用户推荐关系表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserReferee> batchParam) {
|
||||
if (batchParam.update(userRefereeService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:userReferee:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除用户推荐关系表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (userRefereeService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Api(tags = "域名所有权验证")
|
||||
@RestController
|
||||
@RequestMapping("/lvQ4EoivKJ.txt")
|
||||
public class VerifyTxt {
|
||||
|
||||
@ApiOperation("域名所有权验证")
|
||||
@GetMapping()
|
||||
public String verify(){
|
||||
return "cbfbfe827744f1ebfaf03bfe2a0def6a";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.VersionService;
|
||||
import com.gxwebsoft.common.system.entity.Version;
|
||||
import com.gxwebsoft.common.system.param.VersionParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 版本更新控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-01-15 18:52:24
|
||||
*/
|
||||
@Api(tags = "版本更新管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/version")
|
||||
public class VersionController extends BaseController {
|
||||
@Resource
|
||||
private VersionService versionService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询版本更新")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Version>> page(VersionParam param) {
|
||||
PageParam<Version, VersionParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(versionService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(versionService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部版本更新")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Version>> list(VersionParam param) {
|
||||
PageParam<Version, VersionParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(versionService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(versionService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询版本更新")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Version> get(@PathVariable("id") Integer id) {
|
||||
return success(versionService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(versionService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加版本更新")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Version version) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
version.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (versionService.save(version)) {
|
||||
return success("发布成功");
|
||||
}
|
||||
return fail("发布失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改版本更新")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Version version) {
|
||||
if (versionService.updateById(version)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除版本更新")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (versionService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加版本更新")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Version> list) {
|
||||
if (versionService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改版本更新")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Version> batchParam) {
|
||||
if (batchParam.update(versionService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:version:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除版本更新")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (versionService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.WhiteDomainService;
|
||||
import com.gxwebsoft.common.system.entity.WhiteDomain;
|
||||
import com.gxwebsoft.common.system.param.WhiteDomainParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务器白名单控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-03-26 00:22:21
|
||||
*/
|
||||
@Api(tags = "服务器白名单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/white-domain")
|
||||
public class WhiteDomainController extends BaseController {
|
||||
@Resource
|
||||
private WhiteDomainService whiteDomainService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@ApiOperation("分页查询服务器白名单")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<WhiteDomain>> page(WhiteDomainParam param) {
|
||||
// 使用关联查询
|
||||
return success(whiteDomainService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@ApiOperation("查询全部服务器白名单")
|
||||
@GetMapping()
|
||||
public ApiResult<List<WhiteDomain>> list(WhiteDomainParam param) {
|
||||
// 使用关联查询
|
||||
return success(whiteDomainService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@ApiOperation("根据id查询服务器白名单")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<WhiteDomain> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(whiteDomainService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加服务器白名单")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody WhiteDomain whiteDomain) {
|
||||
String key = "WhiteDomain:";
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
key = key + loginUser.getTenantId();
|
||||
whiteDomain.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (whiteDomainService.save(whiteDomain)) {
|
||||
// 重写缓存
|
||||
final List<WhiteDomain> list = whiteDomainService.list();
|
||||
final List<String> collect = list.stream().map(WhiteDomain::getDomain).collect(Collectors.toList());
|
||||
redisUtil.set(key,collect);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改服务器白名单")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody WhiteDomain whiteDomain) {
|
||||
if (whiteDomainService.updateById(whiteDomain)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除服务器白名单")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (whiteDomainService.removeById(id)) {
|
||||
// 重写缓存
|
||||
String key = "WhiteDomain:";
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
key = key + loginUser.getTenantId();
|
||||
}
|
||||
final List<WhiteDomain> list = whiteDomainService.list();
|
||||
final List<String> collect = list.stream().map(WhiteDomain::getDomain).collect(Collectors.toList());
|
||||
redisUtil.set(key,collect);
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加服务器白名单")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<WhiteDomain> list) {
|
||||
if (whiteDomainService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改服务器白名单")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<WhiteDomain> batchParam) {
|
||||
if (batchParam.update(whiteDomainService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:whiteDomain:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除服务器白名单")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (whiteDomainService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_OFFICIAL;
|
||||
import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_WEIXIN;
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.ACCESS_TOKEN_KEY;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/wx-login")
|
||||
@Api(tags = "微信小程序登录API")
|
||||
public class WxLoginController extends BaseController {
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
|
||||
public WxLoginController(StringRedisTemplate redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信openId")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/getOpenId")
|
||||
public ApiResult<LoginResult> getOpenId(@RequestBody UserParam userParam, HttpServletRequest request) {
|
||||
// 1.获取openid
|
||||
JSONObject result = getOpenIdByCode(userParam);
|
||||
String openid = result.getString("openid");
|
||||
String unionid = result.getString("unionid");
|
||||
if (openid == null) {
|
||||
return fail("获取openid失败", null);
|
||||
}
|
||||
// 2.通过openid查询用户是否已存在
|
||||
User user = userService.getByOauthId(userParam);
|
||||
// 3.存在则签发token并返回登录成功,不存在则注册新用户
|
||||
if (user == null) {
|
||||
user = addUser(userParam);
|
||||
}
|
||||
// 4.签发token
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@ApiOperation("微信授权手机号码并登录")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/loginByMpWxPhone")
|
||||
public ApiResult<LoginResult> loginByMpWxPhone(@RequestBody UserParam userParam, HttpServletRequest request) {
|
||||
// 获取手机号码
|
||||
String phone = getPhoneByCode(userParam);
|
||||
if(phone == null){
|
||||
String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString());
|
||||
redisTemplate.delete(key);
|
||||
throw new BusinessException("授权失败,请重试");
|
||||
}
|
||||
// 查询是否存在
|
||||
User user = userService.getByPhone(phone);
|
||||
// 不存在则注册
|
||||
if (user == null) {
|
||||
userParam.setPhone(phone);
|
||||
user = addUser(userParam);
|
||||
user.setRecommend(1);
|
||||
}
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_REGISTER, null, user.getTenantId(), request);
|
||||
// 附加体育中心项目用户信息
|
||||
// user.setBookingUser();
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@ApiOperation("微信授权手机号码并更新")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/updatePhoneByMpWx")
|
||||
public ApiResult<?> updatePhoneByMpWx(@RequestBody UserParam userParam) {
|
||||
// 获取微信授权手机号
|
||||
String phone = getPhoneByCode(userParam);
|
||||
// 查询当前用户
|
||||
User user = userService.getById(userParam.getUserId());
|
||||
if (user != null && phone != null) {
|
||||
user.setPhone(phone);
|
||||
userService.updateUser(user);
|
||||
return success("更新成功",phone);
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新用户注册
|
||||
*/
|
||||
private User addUser(UserParam userParam) {
|
||||
User addUser = new User();
|
||||
// 注册用户
|
||||
addUser.setStatus(0);
|
||||
addUser.setUsername(createUsername("wx_"));
|
||||
addUser.setNickname("微信用户");
|
||||
addUser.setPlatform(MP_WEIXIN);
|
||||
addUser.setGradeId(2);
|
||||
if(userParam.getPhone() != null){
|
||||
addUser.setPhone(userParam.getPhone());
|
||||
}
|
||||
addUser.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
addUser.setTenantId(getTenantId());
|
||||
addUser.setRecommend(1);
|
||||
Role role = roleService.getOne(new QueryWrapper<Role>().eq("role_code", "user"), false);
|
||||
addUser.setRoleId(role.getRoleId());
|
||||
if (userService.saveUser(addUser)) {
|
||||
// 添加用户角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(addUser.getUserId());
|
||||
userRole.setTenantId(addUser.getTenantId());
|
||||
userRole.setRoleId(addUser.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
}
|
||||
return addUser;
|
||||
}
|
||||
|
||||
// 获取openid
|
||||
private JSONObject getOpenIdByCode(UserParam userParam) {
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
// 获取openId
|
||||
String apiUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + setting.getString("appId") + "&secret=" + setting.getString("appSecret") + "&js_code=" + userParam.getCode() + "&grant_type=authorization_code";
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(apiUrl);
|
||||
// 解析access_token
|
||||
return JSON.parseObject(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信手机号码
|
||||
*
|
||||
* @param userParam 需要传微信凭证code
|
||||
*/
|
||||
private String getPhoneByCode(UserParam userParam) {
|
||||
// 获取手机号码
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken();
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
if (StrUtil.isBlank(userParam.getCode())) {
|
||||
throw new BusinessException("code不能为空");
|
||||
}
|
||||
paramMap.put("code", userParam.getCode());
|
||||
// 执行post请求
|
||||
String post = HttpUtil.post(apiUrl, JSON.toJSONString(paramMap));
|
||||
JSONObject json = JSON.parseObject(post);
|
||||
if (json.get("errcode").equals(0)) {
|
||||
JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info"));
|
||||
// 微信用户的手机号码
|
||||
final String phoneNumber = phoneInfo.getString("phoneNumber");
|
||||
// 验证手机号码
|
||||
if(!Validator.isMobile(phoneNumber)){
|
||||
String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString());
|
||||
redisTemplate.delete(key);
|
||||
throw new BusinessException("手机号码格式不正确");
|
||||
}
|
||||
return phoneNumber;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机账号
|
||||
*
|
||||
* @return username
|
||||
*/
|
||||
private String createUsername(String type) {
|
||||
return type.concat(RandomUtil.randomString(12));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口调用凭据AccessToken
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html
|
||||
*/
|
||||
private String getAccessToken() {
|
||||
String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString());
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
if(setting == null){
|
||||
throw new BusinessException("请先配置小程序");
|
||||
}
|
||||
// 从缓存获取access_token
|
||||
String value = redisTemplate.opsForValue().get(key);
|
||||
if (value != null) {
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(value);
|
||||
// return response.getString("access_token");
|
||||
}
|
||||
// 微信获取凭证接口
|
||||
String apiUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// 组装url参数
|
||||
String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(setting.getString("appId")).concat("&secret=").concat(setting.getString("appSecret"));
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(url);
|
||||
System.out.println("result = " + result);
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(result);
|
||||
if (response.getString("access_token") != null) {
|
||||
// 存入缓存
|
||||
redisTemplate.opsForValue().set(key, result,7000L, TimeUnit.SECONDS);
|
||||
return response.getString("access_token");
|
||||
}
|
||||
throw new BusinessException("小程序配置不正确");
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信openId")
|
||||
@PostMapping("/getWxOpenId")
|
||||
public ApiResult<?> getWxOpenId(@RequestBody UserParam userParam) {
|
||||
final User loginUser = getLoginUser();
|
||||
if(loginUser == null){
|
||||
return fail("请先登录");
|
||||
}
|
||||
// 已存在直接返回
|
||||
if(StrUtil.isNotBlank(loginUser.getOpenid())){
|
||||
return success(loginUser);
|
||||
}
|
||||
// 请求微信接口获取openid
|
||||
String apiUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
final JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
final String appId = setting.getString("appId");
|
||||
final String appSecret = setting.getString("appSecret");
|
||||
map.put("appid",appId);
|
||||
map.put("secret",appSecret);
|
||||
map.put("js_code",userParam.getCode());
|
||||
map.put("grant_type","authorization_code");
|
||||
final String response = HttpUtil.get(apiUrl,map);
|
||||
final JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
String openid = jsonObject.getString("openid");
|
||||
String sessionKey = jsonObject.getString("session_key");
|
||||
String unionid = jsonObject.getString("unionid");
|
||||
// 保存openID
|
||||
if(loginUser.getOpenid() == null || StrUtil.isBlank(loginUser.getOpenid())){
|
||||
loginUser.setOpenid(openid);
|
||||
loginUser.setUnionid(unionid);
|
||||
userService.updateById(loginUser);
|
||||
}
|
||||
return success("获取成功",jsonObject);
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信小程序码-用户ID")
|
||||
@GetMapping("/getUserQRCode")
|
||||
public ApiResult<?> getQRCode() {
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken();
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("path","/package/user/qrcode?user_id="+getLoginUserId());
|
||||
// map.put("env_version","trial");
|
||||
// 获取图片 Buffer
|
||||
byte[] qrCode = HttpRequest.post(apiUrl)
|
||||
.body(JSON.toJSONString(map))
|
||||
.execute().bodyBytes();
|
||||
|
||||
// 保存的文件名称
|
||||
final String fileName = CommonUtil.randomUUID8().concat(".png");
|
||||
// 保存路径
|
||||
String filePath = getUploadDir().concat("qrcode/") + fileName;
|
||||
File file = FileUtil.writeBytes(qrCode, filePath);
|
||||
if(file != null){
|
||||
return success(config.getFileServer().concat("/qrcode/").concat(fileName));
|
||||
}
|
||||
return fail("获取失败",null);
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信小程序码-订单核销码")
|
||||
@GetMapping("/getOrderQRCode/{orderNo}")
|
||||
public ApiResult<?> getOrderQRCode(@PathVariable("orderNo") String orderNo) {
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken();
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("path","/package/admin/order-scan?orderNo=".concat(orderNo));
|
||||
map.put("env_version","trial");
|
||||
// 获取图片 Buffer
|
||||
byte[] qrCode = HttpRequest.post(apiUrl)
|
||||
.body(JSON.toJSONString(map))
|
||||
.execute().bodyBytes();
|
||||
|
||||
// 保存的文件名称
|
||||
final String fileName = CommonUtil.randomUUID8().concat(".png");
|
||||
// 保存路径
|
||||
String filePath = getUploadDir().concat("qrcode/") + fileName;
|
||||
File file = FileUtil.writeBytes(qrCode, filePath);
|
||||
if(file != null){
|
||||
return success(config.getFileServer().concat("/qrcode/").concat(fileName));
|
||||
}
|
||||
return fail("获取失败",null);
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信小程序码-订单核销码-数量极多的业务场景")
|
||||
@GetMapping("/getOrderQRCodeUnlimited/{orderNo}")
|
||||
public ApiResult<?> getOrderQRCodeUnlimited(@PathVariable("orderNo") String orderNo) {
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + getAccessToken();
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("scene","orderNo=".concat(orderNo));
|
||||
map.put("page","package/admin/order-scan");
|
||||
map.put("env_version","trial");
|
||||
// 获取图片 Buffer
|
||||
byte[] qrCode = HttpRequest.post(apiUrl)
|
||||
.body(JSON.toJSONString(map))
|
||||
.execute().bodyBytes();
|
||||
System.out.println("qrCode = " + qrCode);
|
||||
|
||||
// 保存的文件名称
|
||||
final String fileName = CommonUtil.randomUUID8().concat(".png");
|
||||
// 保存路径
|
||||
String filePath = getUploadDir().concat("qrcode/") + fileName;
|
||||
File file = FileUtil.writeBytes(qrCode, filePath);
|
||||
if(file != null){
|
||||
return success(config.getFileServer().concat("/qrcode/").concat(fileName));
|
||||
}
|
||||
return fail("获取失败",null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(服务器)
|
||||
*/
|
||||
private String getUploadDir() {
|
||||
return config.getUploadPath() + "file/";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.utils.WxNativeUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.param.SettingParam;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
|
||||
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Api(tags = "微信Native支付接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/wx-native-pay")
|
||||
public class WxNativePayController extends BaseController {
|
||||
@Value("${spring.profiles.active}")
|
||||
String active;
|
||||
public static String merchantId = "1246610101";
|
||||
public static String privateKeyPath = "/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/resources/cert/apiclient_key.pem";
|
||||
public static String merchantSerialNumber = "48749613B40AA8F1D768583FC352358E13EB5AF0";
|
||||
public static String apiV3Key = "zGufUcqa7ovgxRL0kF5OlPr482EZwtn9";
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
private Config wxPayConfig;
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private RequestUtil requestUtil;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
|
||||
@ApiOperation("生成付款码")
|
||||
@PostMapping("/codeUrl")
|
||||
public ApiResult<?> getCodeUrl(@RequestBody Order order) {
|
||||
String key = "Payment:wxPay:".concat(getTenantId().toString());
|
||||
final Payment payment = redisUtil.get(key, Payment.class);
|
||||
if (payment == null) {
|
||||
return fail("微信支付未配置");
|
||||
}
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
final String appId = setting.getString("appId");
|
||||
final String appSecret = setting.getString("appSecret");
|
||||
|
||||
// 使用自动更新平台证书的RSA配置
|
||||
// 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
|
||||
|
||||
// 构建service
|
||||
NativePayService service = new NativePayService.Builder().config(this.getWxPayConfig()).build();
|
||||
// request.setXxx(val)设置所需参数,具体参数可见Request定义
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
// 计算金额
|
||||
order.setMoney(new BigDecimal(order.getPayPrice().toString()));
|
||||
order.setOrderNo(CommonUtil.createOrderNo());
|
||||
BigDecimal decimal = order.getMoney();
|
||||
final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
|
||||
// 将 BigDecimal 转换为 Integer
|
||||
Integer money = multiply.intValue();
|
||||
Amount amount = new Amount();
|
||||
amount.setTotal(money);
|
||||
request.setAmount(amount);
|
||||
request.setAppid(appId);
|
||||
request.setMchid(payment.getMchId());
|
||||
request.setDescription(order.getComments());
|
||||
request.setNotifyUrl("https://server.gxwebsoft.com/api/system/wx-native-pay/notify/" + getTenantId());
|
||||
request.setOutTradeNo(order.getOrderNo());
|
||||
// 调用下单方法,得到应答
|
||||
PrepayResponse response = service.prepay(request);
|
||||
// 使用微信扫描 code_url 对应的二维码,即可体验Native支付
|
||||
// System.out.println(response.getCodeUrl());
|
||||
// 生成指定url对应的二维码到文件,宽和高都是300像素
|
||||
// QrCodeUtil.generate(response.getCodeUrl(), 300, 300, FileUtil.file("/Users/gxwebsoft/Documents/uploads/wx-native-qrcode.jpg"));
|
||||
return success("生成付款码", response.getCodeUrl());
|
||||
}
|
||||
|
||||
|
||||
private Config getWxPayConfig() {
|
||||
// 获取租户ID
|
||||
final Integer tenantId = getTenantId();
|
||||
Config build = WxNativeUtil.getConfig(tenantId);
|
||||
if (build != null) {
|
||||
return build;
|
||||
}
|
||||
String key = "Payment:wxPay:".concat(tenantId.toString());
|
||||
final Payment payment = redisUtil.get(key, Payment.class);
|
||||
System.out.println("payment = " + payment);
|
||||
String apiclientKey = config.getUploadPath().concat("/file").concat(payment.getApiclientKey());
|
||||
// 开发环境配置
|
||||
if(active.equals("dev")){
|
||||
apiclientKey = privateKeyPath;
|
||||
}
|
||||
Config config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(payment.getMchId())
|
||||
.privateKeyFromPath(apiclientKey)
|
||||
.merchantSerialNumber(payment.getMerchantSerialNumber())
|
||||
.apiV3Key(payment.getApiKey())
|
||||
.build();
|
||||
System.out.println("config = " + config);
|
||||
WxNativeUtil.addConfig(tenantId, config);
|
||||
return config;
|
||||
}
|
||||
|
||||
@ApiModelProperty("异步通知")
|
||||
@PostMapping("/notify/{tenantId}")
|
||||
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
|
||||
System.out.println("异步通知*************** = ");
|
||||
System.out.println("request header = " + header);
|
||||
System.out.println("request body = " + body);
|
||||
System.out.println("tenantId = " + tenantId);
|
||||
|
||||
// 推送微信官方支付结果(携带租户ID的POST请求)
|
||||
// final String string = requestUtil.pushWxPayNotify(transaction, payment);
|
||||
|
||||
// 获取支付配置信息用于解密
|
||||
final SettingParam param = new SettingParam();
|
||||
param.setSettingKey("payment");
|
||||
param.setTenantId(tenantId);
|
||||
final String uploadPath = config.getUploadPath(); // 服务器本地路径
|
||||
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.internal.util.file.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.RoleParam;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.RoleService;
|
||||
import com.gxwebsoft.common.system.service.UserOauthService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_OFFICIAL;
|
||||
|
||||
@Api(tags = "微信公众号接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/wx-official")
|
||||
public class WxOfficialController extends BaseController {
|
||||
// 公众号AppID
|
||||
private static final String appid = "wxa67c676fc445590e";
|
||||
// 秘钥
|
||||
private static final String secret = "a450297b5ca8e081080148799d4e6b25";
|
||||
// 订阅消息模板ID
|
||||
private static final String templateId = "LBoByn-TLb2qJS7yR838lGRU-BA-RZE6jm-adb7AWPA";
|
||||
// 小程序APPID
|
||||
private static final String miniAppid = "wx541db955e7a62709";
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@ApiOperation("验证微信服务器")
|
||||
@GetMapping("/{id}")
|
||||
public String validate(@PathVariable("id") Integer tenantId,@RequestParam String nonce,@RequestParam String timestamp,@RequestParam String signature,@RequestParam String echostr){
|
||||
System.out.println("nonce = " + nonce);
|
||||
System.out.println("tenantId = " + tenantId);
|
||||
if(tenantId == null){
|
||||
return null;
|
||||
}
|
||||
String token = "gxwebsoft";
|
||||
String[] array = new String[]{token, timestamp, nonce};
|
||||
// 将token、timestamp、nonce三个参数进行字典序排序
|
||||
Arrays.sort(array);
|
||||
// 将三个参数字符串拼接成一个字符串进行sha1加密
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str: array){
|
||||
sb.append(str);
|
||||
}
|
||||
final String strSha1 = DigestUtil.sha1Hex(sb.toString());
|
||||
if (strSha1.equals(signature)) {
|
||||
return echostr;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation("接收微信的xml消息")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@RequestMapping("/{id}")
|
||||
@ResponseBody
|
||||
public String receiveMessages(HttpServletRequest request,@PathVariable("id") Integer tenantId) throws IOException {
|
||||
System.out.println("tenantId = " + tenantId);
|
||||
Integer userId = 0; // 用户ID
|
||||
// 从请求中获取XML数据
|
||||
String xmlData = IOUtils.toString(request.getInputStream(), "UTF-8");
|
||||
System.out.println("xmlData = " + xmlData);
|
||||
// 解析XML数据
|
||||
Document document = XmlUtil.parseXml(xmlData);
|
||||
Element rootElement = XmlUtil.getRootElement(document);
|
||||
Element FromUserName = XmlUtil.getElement(rootElement, "FromUserName");
|
||||
String openId = FromUserName.getTextContent();
|
||||
System.out.println("openId = " + openId);
|
||||
if(StrUtil.isNotBlank(openId)){
|
||||
// 获取用户基本信息(UnionID机制)
|
||||
final String userStr = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + getAccessToken() + "&openid="+ openId +"&lang=zh_CN");
|
||||
// 保存第三方用户信息表shop_user_oauth
|
||||
final JSONObject jsonObject = JSONObject.parseObject(userStr);
|
||||
final String unionid = jsonObject.getString("unionid");
|
||||
final String subscribe = jsonObject.getString("subscribe");
|
||||
System.out.println("unionid = " + unionid);
|
||||
sendTemplateMessage(openId);
|
||||
// 关注操作
|
||||
if (subscribe != null &&subscribe.equals("1")) {
|
||||
final int count = userOauthService.count(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getOauthType, MP_OFFICIAL).eq(UserOauth::getUnionid, unionid).eq(UserOauth::getTenantId,tenantId));
|
||||
System.out.println("count = " + count);
|
||||
if (count == 0) {
|
||||
// 其他平台是否有注册过
|
||||
final List<UserOauth> list = userOauthService.list(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getUnionid, unionid).eq(UserOauth::getDeleted, 0));
|
||||
final int size = list.size();
|
||||
// 新用户注册
|
||||
if (size== 0) {
|
||||
User user = new User();
|
||||
user.setStatus(0);
|
||||
user.setUsername("wxoff_".concat(RandomUtil.randomString(12)));
|
||||
user.setStatus(0);
|
||||
user.setNickname("微信公众号用户");
|
||||
user.setPlatform(MP_OFFICIAL);
|
||||
user.setGradeId(1);
|
||||
user.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
user.setTenantId(tenantId);
|
||||
user.setRecommend(0);
|
||||
final RoleParam roleParam = new RoleParam();
|
||||
roleParam.setTenantId(tenantId);
|
||||
roleParam.setRoleCode("guest");
|
||||
Role role = roleService.getByRoleCode(roleParam);
|
||||
user.setRoleId(role.getRoleId());
|
||||
if (userService.saveUser(user)) {
|
||||
userId = user.getUserId();
|
||||
// 添加用户角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setTenantId(user.getTenantId());
|
||||
userRole.setRoleId(user.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
}
|
||||
System.out.println("新微信公众号用户 = " + userId);
|
||||
}
|
||||
// 更新
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
for (UserOauth item: list){
|
||||
if(item.getUserId() != null){
|
||||
userId = item.getUserId();
|
||||
}
|
||||
}
|
||||
System.out.println("其他平台有注册过 = " + userId);
|
||||
}
|
||||
// 保存第三方用户记录
|
||||
final UserOauth userOauth = new UserOauth();
|
||||
userOauth.setOauthType(MP_OFFICIAL);
|
||||
userOauth.setUnionid(unionid);
|
||||
userOauth.setOauthId(openId);
|
||||
userOauth.setUserId(userId);
|
||||
userOauth.setTenantId(tenantId);
|
||||
boolean save = userOauthService.save(userOauth);
|
||||
System.out.println("关注微信公众号 = " + save);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendTemplateMessage(String openId){
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getAccessToken();
|
||||
TemplateMessage templateMessage = new TemplateMessage();
|
||||
templateMessage.setToUser(openId);
|
||||
templateMessage.setTemplateId("dVSbX2NRzAG7IuN4kkCQhgV-LjzxvApN3PgrGlon9JU");
|
||||
|
||||
/*
|
||||
您好,您已成功消费。
|
||||
|
||||
商品名:微信影城影票
|
||||
消费时间:2013年8月20日 20:38
|
||||
备注:您可以回复文字或语音对该商品及商家进行评价哦~
|
||||
{{productType.DATA}}:{{name.DATA}} 消费时间:{{time.DATA}} {{remark.DATA}}
|
||||
*/
|
||||
HashMap<String, TemplateMessageDTO> data = new HashMap<>();
|
||||
data.put("first",new TemplateMessageDTO("您收到了一条新的订单。"));
|
||||
data.put("tradeDateTime",new TemplateMessageDTO("02月18日 01时05分"));
|
||||
data.put("customerInfo",new TemplateMessageDTO("广州 王俊"));
|
||||
data.put("orderItemName",new TemplateMessageDTO("兴趣车型"));
|
||||
data.put("orderItemData",new TemplateMessageDTO("骐达 2011款 1.6 CVT 舒适版"));
|
||||
data.put("remark",new TemplateMessageDTO("截止24日09:39分,您尚有10个订单未处理。"));
|
||||
System.out.println("data = " + data);
|
||||
// 链式构建请求
|
||||
String result = HttpRequest.post(url)
|
||||
.body(JSONObject.toJSONString(data))//表单内容
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute().body();
|
||||
System.out.println("result = " + result);
|
||||
System.out.println("getAccessToken() = " + getAccessToken());
|
||||
}
|
||||
|
||||
@ApiOperation("send发送订阅通知")
|
||||
@PostMapping("/send")
|
||||
public ApiResult<?> send(UserParam param) {
|
||||
// send发送订阅通知
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=" + getAccessToken();
|
||||
final UserOauth userOauth = userOauthService.getOne(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getUserId, param.getUserId()).eq(UserOauth::getOauthType,"MP-OFFICIAL").eq(UserOauth::getDeleted, 0));
|
||||
if(userOauth != null){
|
||||
param.setOpenId(userOauth.getOauthId());
|
||||
final String oauthId = userOauth.getOauthId();
|
||||
// 跳转小程序链接
|
||||
HashMap<String, String> miniprogram = new HashMap<>();
|
||||
miniprogram.put("appid",miniAppid);
|
||||
miniprogram.put("pagepath","pages/chat/chat?friendId=" + param.getUserId());
|
||||
// 参数
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
final HashMap<String, String> thing1 = new HashMap<>();
|
||||
final HashMap<String, String> thing2 = new HashMap<>();
|
||||
thing1.put("value","有新访客需要接待");
|
||||
thing2.put("value","吉媒小红娘");
|
||||
data.put("thing1",thing1);
|
||||
data.put("thing2",thing2);
|
||||
|
||||
// 请求主服务器获取用户信息
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("access_token", getAccessToken());
|
||||
map.put("touser",oauthId); // "opEVj6e1YIlMyovkOQFCLJ7llmuI"
|
||||
// 红娘来信通知
|
||||
map.put("template_id", templateId);
|
||||
map.put("miniprogram",JSONObject.toJSONString(miniprogram));
|
||||
map.put("data",data);
|
||||
// 新访客通知
|
||||
// map.put("tid","XMpEsDHmZZqpiaAzmPqO0Gk_h39WCRkaNZ9VoSI9F34");
|
||||
// map.put("page","https://admin.jimeigroup.cn");
|
||||
// map.put("sceneDesc","消息提醒");
|
||||
System.out.println("map = " + map);
|
||||
|
||||
// 链式构建请求
|
||||
String result = HttpRequest.post(url)
|
||||
.body(JSONObject.toJSONString(map))//表单内容
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute().body();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
System.out.println("jsonObject = " + jsonObject);
|
||||
if(jsonObject != null){
|
||||
return success(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
return fail("请求失败",getAccessToken());
|
||||
}
|
||||
|
||||
// 调用接口凭证
|
||||
private String getAccessToken() {
|
||||
String key = MP_OFFICIAL.concat(":access_token:5");
|
||||
// 从缓存获取access_token
|
||||
String value = redisUtil.get(key);
|
||||
if (value != null) {
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(value);
|
||||
return response.getString("access_token");
|
||||
}
|
||||
// 微信获取凭证接口https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
|
||||
String apiUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// 组装url参数
|
||||
String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(appid).concat("&secret=").concat(secret);
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(url);
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(result);
|
||||
if (response.getString("access_token") != null) {
|
||||
// 存入缓存
|
||||
redisUtil.set(key, result,7000L, TimeUnit.SECONDS);
|
||||
return response.getString("access_token");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation("test")
|
||||
@PostMapping("/test")
|
||||
public ApiResult<?> count(){
|
||||
final int count = userOauthService.count(new LambdaQueryWrapper<UserOauth>().eq(UserOauth::getOauthType, MP_OFFICIAL).eq(UserOauth::getUnionid, "o0FaIuKa2UsVp6FCbvmZlrcaBRCM"));
|
||||
System.out.println("count = " + count);
|
||||
return success(getAccessToken());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RSANotificationConfig;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会员特权购买记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-20 18:07:50
|
||||
*/
|
||||
@Api(tags = "微信支付结果通知")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/wx-pay")
|
||||
public class WxPayNotifyController extends BaseController {
|
||||
@Value("${spring.profiles.active}")
|
||||
String active;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private RequestUtil requestUtil;
|
||||
@Resource
|
||||
private ConfigProperties conf;
|
||||
|
||||
@ApiModelProperty("异步通知")
|
||||
@PostMapping("/notify/{tenantId}")
|
||||
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
|
||||
System.out.println("异步通知*************** = ");
|
||||
|
||||
// 获取支付配置信息用于解密
|
||||
String key = "Payment:1:".concat(tenantId.toString());
|
||||
final Payment payment = redisUtil.get(key, Payment.class);
|
||||
String privateKey = payment.getApiKey();
|
||||
String apiclientCert = conf.getUploadPath().concat("/file").concat(payment.getApiclientCert());
|
||||
|
||||
com.wechat.pay.java.core.notification.RequestParam requestParam = new com.wechat.pay.java.core.notification.RequestParam.Builder()
|
||||
.serialNumber(header.get("wechatpay-serial"))
|
||||
.nonce(header.get("wechatpay-nonce"))
|
||||
.signature(header.get("wechatpay-signature"))
|
||||
.timestamp(header.get("wechatpay-timestamp"))
|
||||
.body(body)
|
||||
.build();
|
||||
|
||||
// 如果已经初始化了 RSAAutoCertificateConfig,可直接使用
|
||||
// 没有的话,则构造一个
|
||||
NotificationConfig config = new RSANotificationConfig.Builder()
|
||||
.apiV3Key(privateKey)
|
||||
.certificatesFromPath(apiclientCert)
|
||||
.build();
|
||||
|
||||
// 初始化 NotificationParser
|
||||
NotificationParser parser = new NotificationParser(config);
|
||||
|
||||
// 以支付通知回调为例,验签、解密并转换成 Transaction
|
||||
try {
|
||||
Transaction transaction = parser.parse(requestParam, Transaction.class);
|
||||
|
||||
if (StrUtil.equals("支付成功", transaction.getTradeStateDesc())) {
|
||||
|
||||
// 推送微信官方支付结果(携带租户ID的POST请求)
|
||||
requestUtil.pushWxPayNotify(transaction, payment);
|
||||
|
||||
return "SUCCESS";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
System.out.println($e.getMessage());
|
||||
}
|
||||
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user