初始版本
This commit is contained in:
274
src/main/java/com/vverp/controller/api/AdminController.java
Normal file
274
src/main/java/com/vverp/controller/api/AdminController.java
Normal file
@@ -0,0 +1,274 @@
|
||||
package com.vverp.controller.api;
|
||||
|
||||
import com.vverp.dto.SimpleEntity;
|
||||
import com.vverp.entity.Company;
|
||||
import com.vverp.entity.Department;
|
||||
import com.vverp.entity.Role;
|
||||
import com.vverp.enums.NationalityType;
|
||||
import com.vverp.enums.Reservoir;
|
||||
import com.vverp.moli.util.Filter;
|
||||
import com.vverp.moli.util.Page;
|
||||
import com.vverp.moli.util.Pageable;
|
||||
import com.vverp.moli.util.RespData;
|
||||
import com.vverp.service.CompanyService;
|
||||
import com.vverp.service.DepartmentService;
|
||||
import com.vverp.service.RoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.vverp.entity.Admin;
|
||||
import com.vverp.service.AdminService;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@RestController("adminRestController")
|
||||
@RequestMapping("/api/admin")
|
||||
@Api(value = "管理员", description = "管理员接口")
|
||||
public class AdminController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private AdminService adminService;
|
||||
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@Resource
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
|
||||
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
||||
public RespData info() {
|
||||
Admin admin = adminService.getApp();
|
||||
if (admin == null) {
|
||||
return RespData.error("用户不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", admin.getId());
|
||||
map.put("name", admin.getName());
|
||||
map.put("phone", admin.getPhone() != null ? admin.getPhone() : "");
|
||||
map.put("avatar", "https://vverp1.oss-cn-shanghai.aliyuncs.com//upload/image/202001/aaf06b1f-7620-424b-9c6c-67785f064373.png");
|
||||
map.put("department", admin.getDepartment() != null ? admin.getDepartment().getName() : "");
|
||||
map.put("company", admin.getCompany() != null ? admin.getCompany().getName() : "");
|
||||
map.put("mpOpenId", admin.getMpOpenid());
|
||||
|
||||
return RespData.success(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
public RespData list(Pageable pageable) {
|
||||
Page<Admin> page = adminService.findPage(pageable);
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Admin admin : page.getContent()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", admin.getId());
|
||||
map.put("name", admin.getName());
|
||||
map.put("username", admin.getUsername());
|
||||
map.put("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(admin.getCreateDate()));
|
||||
list.add(map);
|
||||
}
|
||||
return RespData.success(new Page<>(list, page.getTotal(), page.getPageable()));
|
||||
}
|
||||
|
||||
@RequestMapping("/role")
|
||||
public RespData role() {
|
||||
List<Role> roles = roleService.findAll();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Role role : roles) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", role.getId());
|
||||
map.put("name", role.getChineseName());
|
||||
list.add(map);
|
||||
}
|
||||
|
||||
return RespData.success(list);
|
||||
}
|
||||
|
||||
@RequestMapping("/companyList")
|
||||
public RespData companyList() {
|
||||
List<Company> companies = companyService.findAll();
|
||||
|
||||
List<Map<String, Object>> companyList = new ArrayList<>();
|
||||
for (Company company : companies) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", company.getId());
|
||||
map.put("name", company.getName());
|
||||
companyList.add(map);
|
||||
}
|
||||
|
||||
return RespData.success(companyList);
|
||||
}
|
||||
|
||||
@RequestMapping("/departmentList")
|
||||
public RespData departmentList() {
|
||||
List<Department> departments = departmentService.findAll();
|
||||
|
||||
List<Map<String, Object>> departmentList = new ArrayList<>();
|
||||
for (Department department : departments) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", department.getId());
|
||||
map.put("name", department.getName());
|
||||
departmentList.add(map);
|
||||
}
|
||||
return RespData.success(departmentList);
|
||||
}
|
||||
|
||||
@RequestMapping("/nationalityType")
|
||||
public RespData nationalityType() {
|
||||
List<Map<String, Object>> nationalityTypeList = new ArrayList<>();
|
||||
for (NationalityType nationalityType : NationalityType.values()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", nationalityType);
|
||||
map.put("name", nationalityType.getName());
|
||||
nationalityTypeList.add(map);
|
||||
}
|
||||
return RespData.success(nationalityTypeList);
|
||||
}
|
||||
|
||||
@RequestMapping("/reservoir")
|
||||
public RespData reservoir() {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Reservoir reservoir : Reservoir.values()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", reservoir);
|
||||
map.put("name", reservoir.getName());
|
||||
list.add(map);
|
||||
}
|
||||
return RespData.success(list);
|
||||
}
|
||||
|
||||
@RequestMapping("/view")
|
||||
public RespData view(Long id) {
|
||||
Admin admin = adminService.find(id);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", admin.getId());
|
||||
map.put("username", admin.getUsername());
|
||||
map.put("name", admin.getName());
|
||||
map.put("phone", admin.getPhone());
|
||||
map.put("isEnabled", admin.getIsEnabled());
|
||||
|
||||
List<SimpleEntity> roles = new ArrayList<>();
|
||||
for (Role role : admin.getRoles()) {
|
||||
roles.add(new SimpleEntity(role.getId(), role.getChineseName()));
|
||||
}
|
||||
map.put("roleList", roles);
|
||||
|
||||
if (admin.getDepartment() != null) {
|
||||
map.put("departmentId", admin.getDepartment().getId());
|
||||
map.put("departmentName", admin.getDepartment().getName());
|
||||
}
|
||||
|
||||
if (admin.getCompany() != null) {
|
||||
map.put("companyId", admin.getCompany().getId());
|
||||
map.put("companyName", admin.getCompany().getName());
|
||||
}
|
||||
|
||||
map.put("reservoir", admin.getReservoir());
|
||||
map.put("reservoirName", admin.getReservoir() != null ? admin.getReservoir().getName() : "");
|
||||
|
||||
List<SimpleEntity> visibleCompanyList = new ArrayList<>();
|
||||
if (!admin.getVisibleCompanyIdsStr().equals("-1")) {
|
||||
for (String item : admin.getVisibleCompanyIdsStr().split(",")) {
|
||||
Company company = companyService.find(Long.valueOf(item));
|
||||
visibleCompanyList.add(new SimpleEntity(company.getId(), company.getName()));
|
||||
}
|
||||
}
|
||||
map.put("visibleCompanyList", visibleCompanyList);
|
||||
|
||||
List<SimpleEntity> visibleDepartmentList = new ArrayList<>();
|
||||
if (!admin.getVisibleDepartmentIdsStr().equals("-1")) {
|
||||
for (String item : admin.getVisibleDepartmentIdsStr().split(",")) {
|
||||
Department department = departmentService.find(Long.valueOf(item));
|
||||
visibleDepartmentList.add(new SimpleEntity(department.getId(), department.getName()));
|
||||
}
|
||||
}
|
||||
map.put("visibleDepartmentList", visibleDepartmentList);
|
||||
|
||||
map.put("onlySeeSelfFlag", admin.getOnlySeeSelfFlag());
|
||||
return RespData.success(map);
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
public RespData save(Admin admin, Long departmentId, Long companyId, String roleIds) {
|
||||
Long[] roles = new Long[]{};
|
||||
if (StringUtils.isNotEmpty(roleIds)) {
|
||||
String[] ids = roleIds.split(",");
|
||||
roles = new Long[ids.length];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
roles[i] = Long.valueOf(ids[i]);
|
||||
}
|
||||
}
|
||||
Department department = departmentService.find(departmentId);
|
||||
Company company = companyService.find(companyId);
|
||||
admin.setDepartment(department);
|
||||
admin.setCompany(company);
|
||||
adminService.saveAdmin(admin, roles);
|
||||
return RespData.success();
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
public RespData update(Admin admin, Long departmentId, Long companyId, String roleIds) {
|
||||
Long[] roles = new Long[]{};
|
||||
if (StringUtils.isNotEmpty(roleIds)) {
|
||||
String[] ids = roleIds.split(",");
|
||||
roles = new Long[ids.length];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
roles[i] = Long.valueOf(ids[i]);
|
||||
}
|
||||
}
|
||||
Department department = departmentService.find(departmentId);
|
||||
Company company = companyService.find(companyId);
|
||||
admin.setDepartment(department);
|
||||
admin.setCompany(company);
|
||||
adminService.updateAdmin(admin, roles);
|
||||
return RespData.success();
|
||||
}
|
||||
|
||||
@RequestMapping("/simple")
|
||||
public RespData simple() {
|
||||
return RespData.success(adminService.findSimpleList());
|
||||
}
|
||||
|
||||
@RequestMapping("/permissions")
|
||||
public RespData permissions() {
|
||||
Admin admin = adminService.getApp();
|
||||
Set<String> permissions = new HashSet<>();
|
||||
for (Role role : admin.getRoles()) {
|
||||
permissions.addAll(role.getAuthorities());
|
||||
}
|
||||
return RespData.success(permissions);
|
||||
}
|
||||
|
||||
@RequestMapping("/listByDepartment")
|
||||
public RespData listByDepartment(Long departmentId) {
|
||||
List<Admin> list = adminService.findListByAttribute("department.id", departmentId);
|
||||
return RespData.success(list);
|
||||
}
|
||||
|
||||
@RequestMapping("/setCid")
|
||||
public RespData setCid(String cid) {
|
||||
Admin admin = adminService.getCurrent();
|
||||
// todo 解除注释
|
||||
// for (Admin item : adminService.findList(
|
||||
// Filter.eq("cid", cid),
|
||||
// Filter.ne("id", admin.getId())
|
||||
// )) {
|
||||
// item.setCid(null);
|
||||
// adminService.update(item);
|
||||
// }
|
||||
admin.setCid(cid);
|
||||
adminService.update(admin);
|
||||
return RespData.success();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user