163 lines
5.5 KiB
Java
163 lines
5.5 KiB
Java
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()));
|
|
}
|
|
|
|
}
|