Initial commit
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AccessKeyService;
|
||||
import com.gxwebsoft.common.system.entity.AccessKey;
|
||||
import com.gxwebsoft.common.system.param.AccessKeyParam;
|
||||
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-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())) {
|
||||
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,114 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
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.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 StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:list')")
|
||||
@ApiOperation("查询全部缓存")
|
||||
@GetMapping()
|
||||
public ApiResult<HashMap<String, Object>> list() {
|
||||
System.out.println("查询全部缓存 = ");
|
||||
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("读取缓存")
|
||||
@GetMapping("/{key}")
|
||||
public ApiResult<?> get(@PathVariable("key") String key) {
|
||||
System.out.println("读取缓存 = " + key);
|
||||
final String cache = cacheClient.get(key);
|
||||
System.out.println("cache = " + cache);
|
||||
return success("读取成功", JSONObject.parseObject(cache));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:save')")
|
||||
@ApiOperation("添加缓存")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Cache cache) {
|
||||
if (cache.getExpireTime() != null) {
|
||||
cacheClient.set(cache.getKey(),cache.getContent(),cache.getExpireTime(), TimeUnit.MINUTES);
|
||||
return success("缓存成功");
|
||||
}
|
||||
cacheClient.set(cache.getKey(),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("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:cache:save')")
|
||||
@ApiOperation("缓存皮肤")
|
||||
@PostMapping("/theme")
|
||||
public ApiResult<?> saveTheme(@RequestBody Cache cache) {
|
||||
final User loginUser = getLoginUser();
|
||||
final String username = loginUser.getUsername();
|
||||
if (username.equals("admin")) {
|
||||
cacheClient.set(cache.getKey(),cache.getContent());
|
||||
return success("缓存成功");
|
||||
}
|
||||
return success("缓存失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
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.Company;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.CompanyParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* 企业信息控制器
|
||||
*
|
||||
* @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 UserService userService;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询企业信息")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Company>> page(CompanyParam param) {
|
||||
// 普通租户访问
|
||||
if(!getTenantId().equals(5)){
|
||||
param.setAuthoritative(false);
|
||||
PageParam<Company, CompanyParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(companyService.page(page, page.getWrapper()));
|
||||
}
|
||||
// 使用关联查询
|
||||
param.setAuthoritative(true);
|
||||
return success(companyService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部企业信息")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Company>> list(CompanyParam param) {
|
||||
// PageParam<Company, CompanyParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(companyService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
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.getById(id));
|
||||
// 使用关联查询
|
||||
return success(companyService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加企业信息")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Company company) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
company.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (companyService.save(company)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改企业信息")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Company company) {
|
||||
final int count = companyService.count();
|
||||
if (companyService.updateById(company)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败",count);
|
||||
}
|
||||
|
||||
@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:profile')")
|
||||
@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')")
|
||||
@ApiOperation("根据id查询企业信息")
|
||||
@GetMapping("/profile")
|
||||
public ApiResult<Company> profile() {
|
||||
// 使用关联查询
|
||||
// final Company company = companyService.getByTenantIdRel(getTenantId());
|
||||
// try {
|
||||
// company.setUsers(userService.count(new LambdaQueryWrapper<User>().gt(User::getOrganizationId, 0)));
|
||||
// companyService.updateById(company);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
return success(companyService.getByTenantIdRel(getTenantId()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.Dict;
|
||||
import com.gxwebsoft.common.system.param.DictParam;
|
||||
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;
|
||||
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;
|
||||
|
||||
@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("根据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,133 @@
|
||||
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.DictData;
|
||||
import com.gxwebsoft.common.system.param.DictDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
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;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictData>> page(DictDataParam param) {
|
||||
return success(dictDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictData>> list(DictDataParam param) {
|
||||
return success(dictDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@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("字典数据标识已存在");
|
||||
}
|
||||
if (dictDataService.save(dictData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@OperationLog
|
||||
@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,153 @@
|
||||
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.*;
|
||||
import com.gxwebsoft.common.system.entity.Dictionary;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
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,131 @@
|
||||
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')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictionaryData>> page(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictionaryData>> list(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@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')")
|
||||
@OperationLog
|
||||
@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,334 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.entity.Role;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.FileRecordParam;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
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 FileRecordService fileRecordService;
|
||||
|
||||
@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);
|
||||
result.setMerchantCode(getMerchantCode());
|
||||
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);
|
||||
result.setMerchantCode(getMerchantCode());
|
||||
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(config.getFileServer() + path);
|
||||
String contentType = FileServerUtil.getContentType(upload);
|
||||
result.setContentType(contentType);
|
||||
if (FileServerUtil.isImage(contentType)) {
|
||||
result.setThumbnail(requestURL + "/thumbnail" + path);
|
||||
}
|
||||
result.setDownloadUrl(requestURL + "/download" + path);
|
||||
result.setMerchantCode(getMerchantCode());
|
||||
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);
|
||||
if (fileRecordService.removeById(id)) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
fileRecordService.deleteFileAsync(Arrays.asList(
|
||||
new File(getUploadDir(), record.getPath()),
|
||||
new File(getUploadSmDir(), record.getPath())
|
||||
));
|
||||
}
|
||||
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);
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询文件")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<FileRecord>> page(FileRecordParam param, HttpServletRequest request) {
|
||||
// 搜索条件
|
||||
if (getMerchantCode() != null) {
|
||||
param.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
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.setUrl(requestURL + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download" + record.getPath());
|
||||
}
|
||||
}
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:file:list')")
|
||||
@OperationLog
|
||||
@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.setUrl(requestURL + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download" + record.getPath());
|
||||
}
|
||||
}
|
||||
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,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.IndustryService;
|
||||
import com.gxwebsoft.common.system.entity.Industry;
|
||||
import com.gxwebsoft.common.system.param.IndustryParam;
|
||||
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-05-17 11:26:43
|
||||
*/
|
||||
@Api(tags = "企业行业记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/industry")
|
||||
public class IndustryController extends BaseController {
|
||||
@Resource
|
||||
private IndustryService industryService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询企业行业记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Industry>> page(IndustryParam param) {
|
||||
PageParam<Industry, IndustryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(industryService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(industryService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部企业行业记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Industry>> list(IndustryParam param) {
|
||||
PageParam<Industry, IndustryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(industryService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(industryService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业行业记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Industry> get(@PathVariable("id") Integer id) {
|
||||
return success(industryService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(industryService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加企业行业记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Industry industry) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
industry.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (industryService.save(industry)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改企业行业记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Industry industry) {
|
||||
if (industryService.updateById(industry)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除企业行业记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (industryService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加企业行业记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Industry> list) {
|
||||
if (industryService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改企业行业记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Industry> batchParam) {
|
||||
if (batchParam.update(industryService, "industry_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:industry:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除企业行业记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (industryService.removeByIds(ids)) {
|
||||
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,261 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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.google.gson.Gson;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
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.JSONUtil;
|
||||
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.LoginRecord;
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.mapper.UserMapper;
|
||||
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.result.CaptchaResult;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.*;
|
||||
import com.gxwebsoft.oa.service.CustomerService;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
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 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 StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
public ApiResult<LoginResult> login(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
String username = param.getUsername();
|
||||
Integer tenantId = param.getTenantId();
|
||||
|
||||
// 登录账号|手机号码|邮箱登录
|
||||
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 message = "密码错误";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(username, tenantId),
|
||||
tokenExpireTime, configProperties.getTokenKey());
|
||||
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/user")
|
||||
public ApiResult<User> userInfo() {
|
||||
return success(userService.getByIdRel(getLoginUserId()));
|
||||
}
|
||||
|
||||
@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.setUsername(null);
|
||||
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("修改失败");
|
||||
}
|
||||
|
||||
@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("短信验证码")
|
||||
@PostMapping("/sendSmsCaptcha")
|
||||
public ApiResult<?> sendSmsCaptcha(@RequestBody SmsCaptchaParam param) {
|
||||
DefaultProfile profile = DefaultProfile.getProfile("regionld", "LTAI5tBWM9dSmEAoQFhNqxqJ", "Dr0BqiKl7eaL1NNKoCd12qKsbgjnum");
|
||||
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", "南宁网宿科技");
|
||||
request.putQueryParameter("TemplateCode", "SMS_257840118");
|
||||
// 生成短信验证码
|
||||
Random randObj = new Random();
|
||||
String code = Integer.toString(100000 + randObj.nextInt(900000));
|
||||
request.putQueryParameter("TemplateParam", "{\"code\":" + code + "}");
|
||||
try {
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
String json = response.getData();
|
||||
Gson g = new Gson();
|
||||
HashMap result = g.fromJson(json, HashMap.class);
|
||||
if("OK".equals(result.get("Message"))) {
|
||||
cacheClient.set(param.getPhone(),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("密码修改失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
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.Menu;
|
||||
import com.gxwebsoft.common.system.entity.Plug;
|
||||
import com.gxwebsoft.common.system.param.MenuParam;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.PlugService;
|
||||
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:23
|
||||
*/
|
||||
@Api(tags = "菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/menu")
|
||||
public class MenuController extends BaseController {
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private PlugService plugService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:menu:list')")
|
||||
@OperationLog
|
||||
@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')")
|
||||
@OperationLog
|
||||
@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')")
|
||||
@OperationLog
|
||||
@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)){
|
||||
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,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,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,171 @@
|
||||
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.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.Plug;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.PlugParam;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.PlugService;
|
||||
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-18 11:57:37
|
||||
*/
|
||||
@Api(tags = "插件扩展管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/plug")
|
||||
public class PlugController extends BaseController {
|
||||
@Resource
|
||||
private PlugService plugService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询插件扩展")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Plug>> page(PlugParam param) {
|
||||
// 如果不传userId,只显示审核通过的插件
|
||||
if (param.getUserId() == null) {
|
||||
param.setStatus(20);
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(plugService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部插件扩展")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Plug>> list(PlugParam param) {
|
||||
// 使用关联查询
|
||||
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.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, "menu_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("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:plug:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("发布插件")
|
||||
@PostMapping("/plug")
|
||||
public ApiResult<?> plug(@RequestBody Plug plug){
|
||||
final Integer menuId = plug.getParentId();
|
||||
// 查重
|
||||
final int count = plugService.count(new LambdaQueryWrapper<Plug>().eq(Plug::getMenuId, menuId));
|
||||
if(count > 0){
|
||||
return fail("请勿重复发布");
|
||||
}
|
||||
// 准备数据
|
||||
final Menu menu = menuService.getById(menuId);
|
||||
plug.setUserId(getLoginUserId());
|
||||
plug.setMenuId(menuId);
|
||||
plug.setTenantId(getTenantId());
|
||||
plug.setIcon(menu.getIcon());
|
||||
plug.setPath(menu.getPath());
|
||||
plug.setComponent(menu.getComponent());
|
||||
plug.setAuthority(menu.getAuthority());
|
||||
plug.setTitle(menu.getTitle());
|
||||
plug.setMenuType(menu.getMenuType());
|
||||
plug.setMeta(menu.getMeta());
|
||||
plug.setParentId(menu.getParentId());
|
||||
plug.setHide(menu.getHide());
|
||||
plug.setSortNumber(menu.getSortNumber());
|
||||
if(plugService.save(plug)){
|
||||
return success("发布成功");
|
||||
}
|
||||
return fail("发布失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
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);
|
||||
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);
|
||||
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 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.CacheClient;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.param.SettingParam;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.oa.entity.Tenant;
|
||||
import com.gxwebsoft.oa.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;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.TEN_ANT_SETTING_KEY;
|
||||
|
||||
/**
|
||||
* 系统设置控制器
|
||||
*
|
||||
* @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 CacheClient cacheClient;
|
||||
|
||||
@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)) {
|
||||
// 更新系统设置信息到缓存
|
||||
cacheClient.set(TEN_ANT_SETTING_KEY.concat(":").concat(setting.getSettingKey()), JSON.parseObject(setting.getContent()));
|
||||
// 更新租户信息
|
||||
if (setting.getSettingKey().equals("setting")) {
|
||||
System.out.println("修改系统设置 = " + setting.getContent());
|
||||
final String content = setting.getContent();
|
||||
final JSONObject jsonObject = JSONObject.parseObject(content);
|
||||
final String siteName = jsonObject.getString("siteName");
|
||||
final String logo = jsonObject.getString("logo");
|
||||
System.out.println("siteName = " + siteName);
|
||||
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) {
|
||||
// 新增
|
||||
final Setting one = settingService.getOne(new LambdaQueryWrapper<Setting>().eq(Setting::getSettingKey, setting.getSettingKey()));
|
||||
if(one == null){
|
||||
settingService.save(setting);
|
||||
cacheClient.set("theme",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)) {
|
||||
cacheClient.set("theme",setting.getContent());
|
||||
return success("更新成功");
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
@ApiOperation("更新主题皮肤")
|
||||
@GetMapping("/getTheme")
|
||||
public ApiResult<?> getTheme() {
|
||||
return success("获取成功",cacheClient.get("theme"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
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.apps.service.BcExportService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.DictionaryData;
|
||||
import com.gxwebsoft.common.system.entity.Organization;
|
||||
import com.gxwebsoft.common.system.entity.Role;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
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 com.gxwebsoft.shop.entity.UserOauth;
|
||||
import com.gxwebsoft.shop.service.RechargeOrderService;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private BcExportService bcExportService;
|
||||
@Resource
|
||||
private RechargeOrderService rechargeOrderService;
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<User>> page(UserParam param) {
|
||||
final PageResult<User> result = userService.pageRel(param);
|
||||
// 修复部门数据
|
||||
// result.getList().forEach(d -> {
|
||||
// System.out.println("d.getOrganizationName() = " + d.getOrganizationName());
|
||||
// final BcExport one = bcExportService.getOne(new LambdaQueryWrapper<BcExport>().eq(BcExport::getUserId, d.getUserId()));
|
||||
// one.setOrganizationName(d.getOrganizationName());
|
||||
// bcExportService.updateById(one);
|
||||
// });
|
||||
return success(userService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部用户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<User>> list(UserParam param) {
|
||||
return success(userService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询用户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<User> get(@PathVariable("id") Integer id) {
|
||||
return success(userService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加用户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody User user) {
|
||||
user.setStatus(0);
|
||||
user.setPassword(userService.encodePassword(user.getPassword()));
|
||||
if (userService.saveUser(user)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
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)) {
|
||||
QueryWrapper<UserOauth> userOauthQueryWrapper = new QueryWrapper<>();
|
||||
userOauthService.remove(userOauthQueryWrapper.eq("user_id",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) {
|
||||
ids.forEach(userId -> {
|
||||
QueryWrapper<UserOauth> userOauthQueryWrapper = new QueryWrapper<>();
|
||||
userOauthService.remove(userOauthQueryWrapper.eq("user_id",userId));
|
||||
});
|
||||
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("/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("重置失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:list')")
|
||||
@OperationLog
|
||||
@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')")
|
||||
@OperationLog
|
||||
@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("更新失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user