改造核心框架
This commit is contained in:
@@ -12,6 +12,7 @@ import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.TenantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -36,6 +37,15 @@ public class CompanyController extends BaseController {
|
||||
@Resource
|
||||
private CompanyMapper companyMapper;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询企业信息不限租户")
|
||||
@GetMapping("/pageAll")
|
||||
public ApiResult<PageResult<Company>> pageAll(CompanyParam param) {
|
||||
// 使用关联查询
|
||||
return success(companyService.pageRelAll(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询企业信息")
|
||||
@@ -136,6 +146,7 @@ public class CompanyController extends BaseController {
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业信息")
|
||||
@GetMapping("/profile")
|
||||
public ApiResult<Company> profile() {
|
||||
@@ -149,6 +160,14 @@ public class CompanyController extends BaseController {
|
||||
return fail("企业不存在",null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询企业信息不限租户")
|
||||
@GetMapping("/profileAll/{companyId}")
|
||||
public ApiResult<Company> profileAll(@PathVariable("companyId") Integer companyId) {
|
||||
return success(companyMapper.getCompanyAll(companyId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:company:profile')")
|
||||
@OperationLog
|
||||
@ApiOperation("销毁租户")
|
||||
|
||||
@@ -35,6 +35,8 @@ import com.wf.captcha.SpecCaptcha;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -404,8 +406,7 @@ public class MainController extends BaseController {
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
|
||||
// @Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@ApiOperation("账号注册")
|
||||
@PostMapping("/register")
|
||||
public ApiResult<?> register(@RequestBody User user) {
|
||||
@@ -536,12 +537,24 @@ public class MainController extends BaseController {
|
||||
/// 添加系统菜单
|
||||
if (resultUserRole) {
|
||||
Menu menu = new Menu();
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(0);
|
||||
menu.setHide(1);
|
||||
menu.setTitle("扩展插件");
|
||||
menu.setPath("/system/plug");
|
||||
menu.setComponent("/system/plug");
|
||||
menu.setIcon("AppstoreAddOutlined");
|
||||
menu.setAuthority("sys:plug:list");
|
||||
menu.setSortNumber(0);
|
||||
menu.setTenantId(tenant.getTenantId());
|
||||
menuService.save(menu);
|
||||
// 10.系统管理
|
||||
menu.setTitle("系统管理");
|
||||
menu.setParentId(0);
|
||||
menu.setPath("/system");
|
||||
menu.setIcon("setting-outlined");
|
||||
menu.setSortNumber(999);
|
||||
menu.setHide(1);
|
||||
menu.setTenantId(tenant.getTenantId());
|
||||
menuService.save(menu);
|
||||
Integer parentId = menu.getMenuId();
|
||||
@@ -552,6 +565,7 @@ public class MainController extends BaseController {
|
||||
menu.setIcon("AuditOutlined");
|
||||
menu.setAuthority("sys:company:profile");
|
||||
menu.setSortNumber(1);
|
||||
menu.setHide(0);
|
||||
menuService.save(menu);
|
||||
menu.setTitle("用户管理");
|
||||
menu.setPath("/system/user");
|
||||
@@ -811,16 +825,16 @@ public class MainController extends BaseController {
|
||||
menu.setAuthority("sys:auth:user");
|
||||
menuService.save(menu);
|
||||
// 1.控制台
|
||||
menu.setParentId(0);
|
||||
menu.setTitle("管理首页");
|
||||
menu.setPath("/dashboard");
|
||||
menu.setIcon("home-outlined");
|
||||
menu.setComponent("/dashboard/workplace");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(1);
|
||||
menu.setHide(0);
|
||||
menu.setMenuType(0);
|
||||
menuService.save(menu);
|
||||
// menu.setParentId(0);
|
||||
// menu.setTitle("管理首页");
|
||||
// menu.setPath("/dashboard");
|
||||
// menu.setIcon("home-outlined");
|
||||
// menu.setComponent("/dashboard/workplace");
|
||||
// menu.setAuthority("");
|
||||
// menu.setSortNumber(1);
|
||||
// menu.setHide(0);
|
||||
// menu.setMenuType(0);
|
||||
// menuService.save(menu);
|
||||
|
||||
// 个人中心
|
||||
menu.setParentId(0);
|
||||
|
||||
@@ -4,13 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.RoleMenu;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.param.PlugParam;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.MenuService;
|
||||
import com.gxwebsoft.common.system.service.RoleMenuService;
|
||||
import com.gxwebsoft.common.system.service.TenantService;
|
||||
import com.gxwebsoft.common.system.entity.Tenant;
|
||||
import com.gxwebsoft.common.system.param.TenantParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
@@ -20,6 +19,7 @@ import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -37,106 +37,110 @@ import java.util.stream.Collectors;
|
||||
@RestController
|
||||
@RequestMapping("/api/system/tenant")
|
||||
public class TenantController extends BaseController {
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("分页查询租户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||
return success(tenantService.pageRel(param));
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询租户")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||
// 使用关联查询
|
||||
return success(tenantService.pageRel(param));
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("查询全部租户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Tenant>> list(TenantParam param) {
|
||||
// 使用关联查询
|
||||
return success(tenantService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@ApiOperation("根据id查询租户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Tenant> get(@PathVariable("id") Integer id) {
|
||||
Tenant tenant = tenantService.getById(id);
|
||||
// 附加企业信息
|
||||
List<Company> list = companyService.list(new LambdaQueryWrapper<Company>().eq(Company::getTenantId, tenant.getTenantId()).eq(Company::getAuthoritative, true));
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
final Company company = list.get(0);
|
||||
tenant.setCompany(company);
|
||||
}
|
||||
return success(tenant);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部租户")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Tenant>> list(TenantParam param) {
|
||||
// 使用关联查询
|
||||
return success(tenantService.listRel(param));
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加租户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Tenant tenant) {
|
||||
System.out.println("tenant = " + tenant);
|
||||
if (tenantService.save(tenant)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询租户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Tenant> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(tenantService.getByIdRel(id));
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改租户")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Tenant tenant) {
|
||||
if (tenantService.updateById(tenant)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加租户")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Tenant tenant) {
|
||||
System.out.println("tenant = " + tenant);
|
||||
if (tenantService.save(tenant)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (tenantService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改租户")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Tenant tenant) {
|
||||
if (tenantService.updateById(tenant)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加租户")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Tenant> list) {
|
||||
if (tenantService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (tenantService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改租户")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Tenant> batchParam) {
|
||||
if (batchParam.update(tenantService, "tenant_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加租户")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Tenant> list) {
|
||||
if (tenantService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改租户")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Tenant> batchParam) {
|
||||
if (batchParam.update(tenantService, "tenant_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除租户")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (tenantService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
@PreAuthorize("hasAuthority('sys:tenant:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除租户")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (tenantService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("租户角色权限初始化")
|
||||
@GetMapping("/role-menu/{id}")
|
||||
|
||||
@@ -143,6 +143,9 @@ public class Company implements Serializable {
|
||||
@ApiModelProperty(value = "是否默认企业主体")
|
||||
private Boolean authoritative;
|
||||
|
||||
@ApiModelProperty("是否推荐")
|
||||
private Boolean recommend;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
|
||||
@@ -52,10 +52,6 @@ public class Tenant implements Serializable {
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty(value = "logo")
|
||||
@TableField(exist = false)
|
||||
private String logo;
|
||||
|
||||
@ApiModelProperty(value = "游客")
|
||||
@TableField(exist = false)
|
||||
private String username;
|
||||
@@ -76,4 +72,12 @@ public class Tenant implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Company company;
|
||||
|
||||
@ApiModelProperty(value = "企业名称")
|
||||
@TableField(exist = false)
|
||||
private String companyName;
|
||||
|
||||
@ApiModelProperty(value = "logo")
|
||||
@TableField(exist = false)
|
||||
private String logo;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.core.web.ExistenceParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.system.entity.Company;
|
||||
import com.gxwebsoft.common.system.param.CompanyParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -39,4 +40,9 @@ public interface CompanyMapper extends BaseMapper<Company> {
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Company> getCount(@Param("param") CompanyParam param);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Company> selectPageRelAll(PageParam<Company, CompanyParam> page, CompanyParam param);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
Company getCompanyAll(@Param("companyId") Integer companyId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.Tenant;
|
||||
import com.gxwebsoft.common.system.param.TenantParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -101,6 +101,9 @@
|
||||
<if test="param.authoritative != null">
|
||||
AND a.authoritative = #{param.authoritative}
|
||||
</if>
|
||||
<if test="param.recommend != null">
|
||||
AND a.recommend = #{param.recommend}
|
||||
</if>
|
||||
<if test="param.appName != null">
|
||||
AND a.short_name = #{param.appName}
|
||||
</if>
|
||||
@@ -122,6 +125,23 @@
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 分页查询不限租户 -->
|
||||
<select id="selectPageRelAll" resultType="com.gxwebsoft.common.system.entity.Company">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 企业查询不限租户 -->
|
||||
<select id="getCompanyAll" resultType="com.gxwebsoft.common.system.entity.Company">
|
||||
SELECT a.*,b.tenant_id,b.tenant_name,b.tenant_code
|
||||
FROM sys_company a
|
||||
LEFT JOIN sys_tenant b ON a.tenant_id = b.tenant_id
|
||||
<where>
|
||||
<if test="companyId != null">
|
||||
AND a.company_id = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Company">
|
||||
<include refid="selectSql"></include>
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
SELECT a.*,b.company_name,b.company_logo
|
||||
FROM sys_tenant a
|
||||
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
|
||||
<where>
|
||||
<if test="param.tenantId != null">
|
||||
AND a.tenant_id = #{param.tenantId}
|
||||
|
||||
@@ -113,6 +113,9 @@ public class CompanyParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer authentication;
|
||||
|
||||
@ApiModelProperty(value = "是否推荐")
|
||||
private Boolean recommend;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer status;
|
||||
|
||||
@@ -41,4 +41,6 @@ public interface CompanyService extends IService<Company> {
|
||||
Company getByIdRel(Integer companyId);
|
||||
|
||||
Company getByTenantIdRel(Integer tenantId);
|
||||
|
||||
PageResult<Company> pageRelAll(CompanyParam param);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,12 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Company> pageRelAll(CompanyParam param) {
|
||||
PageParam<Company, CompanyParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<Company> list = baseMapper.selectPageRelAll(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
@Override
|
||||
public PageResult<Tenant> pageRel(TenantParam param) {
|
||||
PageParam<Tenant, TenantParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc");
|
||||
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||
List<Tenant> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user