账号管理列表查询接口优化,新增账号新增编辑接口
This commit is contained in:
parent
e2f9b2356f
commit
742a2e6ec8
@ -1,10 +1,16 @@
|
||||
package com.cdzy.ebikeoperate.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.common.model.StaffDto;
|
||||
import com.cdzy.ebikeoperate.model.dto.response.EbikeOrgZoneDto;
|
||||
import com.cdzy.ebikeoperate.model.pojo.EbikeOrgZone;
|
||||
import com.cdzy.ebikeoperate.service.EbikeOrgZoneService;
|
||||
import com.ebike.feign.clients.StaffFeignClient;
|
||||
import com.ebike.feign.model.rsp.StaffFeign;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -22,6 +28,8 @@ public class EbikeOrgZoneController {
|
||||
|
||||
@Autowired
|
||||
private EbikeOrgZoneService ebikeOrgZoneService;
|
||||
@Resource
|
||||
private StaffFeignClient staffFeignClient;
|
||||
|
||||
/**
|
||||
* 添加行政区划授权信息。
|
||||
@ -87,4 +95,18 @@ public class EbikeOrgZoneController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有行政区划授权信息。
|
||||
*
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("listZoneByLogin")
|
||||
public JsonResult<?> listZoneByLogin() {
|
||||
|
||||
String token = StpUtil.getTokenValue();
|
||||
JsonResult<StaffFeign> jsonResult = staffFeignClient.getInfoByToken(token);
|
||||
List<EbikeOrgZoneDto> list = ebikeOrgZoneService.list(String.valueOf(jsonResult.getData().getOrgId()), null);
|
||||
return list == null ? JsonResult.failed("查询行政区划授权信息失败") : JsonResult.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@ -124,6 +124,11 @@
|
||||
<version>1.10.8</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.50</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<!--开发环境-->
|
||||
|
||||
@ -150,6 +150,7 @@ public class RolesController {
|
||||
@PostMapping("pageQueryRoles")
|
||||
public JsonResult<?> pageQueryRoles(@RequestBody @Validated RoleListQueryDto roleListQueryDto) {
|
||||
|
||||
try {
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
Object loginId = StpUtil.getLoginIdByToken(tokenValue);
|
||||
QueryWrapper queryStaff = QueryWrapper.create().where(STAFF.STAFF_ID.eq(loginId));
|
||||
@ -176,13 +177,25 @@ public class RolesController {
|
||||
List<ResRolesDto> records = resRolesDtoPage.getRecords();
|
||||
//统计pc权限数量和小程序权限数量
|
||||
for (ResRolesDto record : records) {
|
||||
QueryWrapper caseQuery = QueryWrapper.create().select(QueryMethods.sum(QueryMethods.case_().when(PERMISSIONS.PERM_TYPE.eq(1)).then(1).else_(0).end()).as("web_count"), QueryMethods.sum(QueryMethods.case_().when(PERMISSIONS.PERM_TYPE.eq(2)).then(1).else_(0).end()).as("applet_count")).innerJoin(ROLE_PERMISSIONS).on(PERMISSIONS.PERM_ID.eq(ROLE_PERMISSIONS.PERM_ID)).where(ROLE_PERMISSIONS.ROLE_ID.eq(record.getRoleId())).where(PERMISSIONS.PERM_TYPE.ne("0"));
|
||||
QueryWrapper caseQuery = QueryWrapper.create()
|
||||
.select(QueryMethods.sum(QueryMethods.case_()
|
||||
.when(PERMISSIONS.PERM_TYPE.eq(1)).then(1)
|
||||
.else_(0).end()).as("web_count"),
|
||||
QueryMethods.sum(QueryMethods.case_().when(PERMISSIONS.PERM_TYPE
|
||||
.eq(2)).then(1).else_(0)
|
||||
.end()).as("applet_count"))
|
||||
.innerJoin(ROLE_PERMISSIONS).on(PERMISSIONS.PERM_ID.eq(ROLE_PERMISSIONS.PERM_ID))
|
||||
.where(ROLE_PERMISSIONS.ROLE_ID.eq(record.getRoleId()))
|
||||
.and(PERMISSIONS.PERM_TYPE.ne("0"));
|
||||
ResRolesDto oneAs = permissionsService.getOneAs(caseQuery, ResRolesDto.class);
|
||||
if (oneAs == null) continue;
|
||||
record.setWebCount(oneAs.getWebCount());
|
||||
record.setAppletCount(oneAs.getAppletCount());
|
||||
}
|
||||
return JsonResult.success(resRolesDtoPage);
|
||||
} catch (Exception e) {
|
||||
return JsonResult.failed("出错了!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -260,7 +273,7 @@ public class RolesController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色信息更新
|
||||
* 角色信息删除
|
||||
*
|
||||
* @param roleId
|
||||
* @return
|
||||
@ -280,4 +293,24 @@ public class RolesController {
|
||||
return JsonResult.failed("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登陆用户所属组织下的所有角色信息。
|
||||
*
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("listByOrgId")
|
||||
public JsonResult<?> listByOrgId() {
|
||||
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
Object loginId = StpUtil.getLoginIdByToken(tokenValue);
|
||||
QueryWrapper queryStaff = QueryWrapper.create().where(STAFF.STAFF_ID.eq(loginId));
|
||||
StaffDto staff = staffService.getOneAs(queryStaff, StaffDto.class);
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(ROLES.ROLE_ID, ROLES.ROLE_NAME)
|
||||
.where(ROLES.ORG_ID.eq(staff.getOrgId()));
|
||||
List<ResRolesDto> list = rolesService.listAs(queryWrapper, ResRolesDto.class);
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,43 @@
|
||||
package com.cdzy.user.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cdzy.common.enums.Message;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.common.model.PageParam;
|
||||
import com.cdzy.common.model.StaffDto;
|
||||
import com.cdzy.user.model.dto.AccountListQueryDto;
|
||||
import com.cdzy.user.model.dto.RoleListQueryDto;
|
||||
import com.cdzy.user.model.dto.ReqStaffDto;
|
||||
import com.cdzy.user.model.dto.ResStaffDto;
|
||||
import com.cdzy.user.model.entity.Staff;
|
||||
import com.cdzy.user.model.entity.StaffRoles;
|
||||
import com.cdzy.user.model.entity.StaffZone;
|
||||
import com.cdzy.user.model.vo.StaffIds;
|
||||
import com.cdzy.user.service.StaffRolesService;
|
||||
import com.cdzy.user.service.StaffService;
|
||||
import com.cdzy.user.service.StaffZoneService;
|
||||
import com.cdzy.user.utils.AESUtils;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static com.cdzy.user.model.entity.table.RolesTableDef.ROLES;
|
||||
import static com.cdzy.user.model.entity.table.StaffRolesTableDef.STAFF_ROLES;
|
||||
import static com.cdzy.user.model.entity.table.StaffTableDef.STAFF;
|
||||
import static com.cdzy.user.model.entity.table.StaffZoneTableDef.STAFF_ZONE;
|
||||
|
||||
/**
|
||||
* 员工控制层。
|
||||
@ -32,6 +51,10 @@ public class StaffController {
|
||||
|
||||
@Resource
|
||||
private StaffService staffService;
|
||||
@Autowired
|
||||
private StaffZoneService staffZoneService;
|
||||
@Autowired
|
||||
private StaffRolesService staffRolesService;
|
||||
|
||||
/**
|
||||
* 添加。
|
||||
@ -165,6 +188,148 @@ public class StaffController {
|
||||
@PostMapping("pageQueryStaffs")
|
||||
public JsonResult<?> pageQueryStaffs(@RequestBody @Validated AccountListQueryDto accountListQueryDto) {
|
||||
|
||||
return JsonResult.success("");
|
||||
try {
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
Object loginId = StpUtil.getLoginIdByToken(tokenValue);
|
||||
QueryWrapper queryStaff = QueryWrapper.create().where(STAFF.STAFF_ID.eq(loginId));
|
||||
StaffDto staff = staffService.getOneAs(queryStaff, StaffDto.class);
|
||||
|
||||
QueryWrapper queryZone = QueryWrapper.create()
|
||||
.select(QueryMethods.groupConcat(STAFF_ZONE.ZONE_NAME).as("zone_name"),
|
||||
QueryMethods.groupConcat(STAFF_ZONE.ZONE_ID).as("zone_id"),
|
||||
STAFF_ZONE.STAFF_ID)
|
||||
.from(STAFF_ZONE)
|
||||
.groupBy(STAFF_ZONE.STAFF_ID);
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(STAFF.STAFF_ID, STAFF.ORG_ID, STAFF.USERNAME, STAFF.PHONE, STAFF.STATE,
|
||||
QueryMethods.groupConcat(ROLES.ROLE_NAME).as("role_name"),
|
||||
QueryMethods.groupConcat(ROLES.ROLE_ID).as("role_id"),
|
||||
STAFF.CREATED_AT)
|
||||
.select(STAFF_ZONE.ZONE_NAME.getName(), STAFF_ZONE.ZONE_ID.getName())
|
||||
.leftJoin(STAFF_ROLES).on(STAFF.STAFF_ID.eq(STAFF_ROLES.STAFF_ID))
|
||||
.leftJoin(ROLES).on(STAFF_ROLES.ROLE_ID.eq(ROLES.ROLE_ID))
|
||||
.leftJoin(queryZone).as("STAFF_ZONE").on(STAFF.STAFF_ID
|
||||
.eq(new QueryColumn("STAFF_ZONE", "staff_id")))
|
||||
.where(STAFF.ORG_ID.eq(staff.getOrgId()))
|
||||
.and(STAFF.USERNAME.eq(accountListQueryDto.getAccountName(),
|
||||
StringUtils.hasText(accountListQueryDto.getAccountName())))
|
||||
.and(STAFF.PHONE.eq(accountListQueryDto.getAccount(),
|
||||
StringUtils.hasText(accountListQueryDto.getAccount())))
|
||||
.groupBy(STAFF.STAFF_ID).orderBy(STAFF.CREATED_AT.desc());
|
||||
Page<ResStaffDto> page = Page.of(accountListQueryDto.getPageNum(), accountListQueryDto.getPageSize());
|
||||
Page<ResStaffDto> resRolesDtoPage = staffService.pageAs(page, queryWrapper, ResStaffDto.class);
|
||||
return JsonResult.success(resRolesDtoPage);
|
||||
} catch (Exception e) {
|
||||
return JsonResult.failed("出错了!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号信息新增
|
||||
*
|
||||
* @param staffDto
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("staffInfoAdd")
|
||||
public JsonResult<?> staffInfoAdd(@RequestBody ReqStaffDto staffDto) {
|
||||
|
||||
try {
|
||||
Staff staff = new Staff();
|
||||
BeanUtils.copyProperties(staffDto, staff);
|
||||
String encrypt = AESUtils.encrypt("123456");
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
Object loginId = StpUtil.getLoginIdByToken(tokenValue);
|
||||
QueryWrapper queryStaff = QueryWrapper.create().where(STAFF.STAFF_ID.eq(loginId));
|
||||
StaffDto staffLogin = staffService.getOneAs(queryStaff, StaffDto.class);
|
||||
staff.setOrgId(staffLogin.getOrgId());
|
||||
staff.setPassword(encrypt);
|
||||
staffService.save(staff);
|
||||
JSONArray roleId = staffDto.getRoleId();
|
||||
List<StaffRoles> roleList = IntStream.range(0, roleId.size())
|
||||
.mapToObj(i -> {
|
||||
StaffRoles staffRoles = new StaffRoles();
|
||||
staffRoles.setRoleId(Long.parseLong(roleId.get(i).toString()));
|
||||
staffRoles.setStaffId(staff.getStaffId());
|
||||
return staffRoles;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
if (!roleList.isEmpty()) {
|
||||
staffRolesService.saveBatch(roleList);
|
||||
}
|
||||
JSONArray zoneId = staffDto.getZoneId();
|
||||
List<StaffZone> zoneList = IntStream.range(0, zoneId.size())
|
||||
.mapToObj(i -> {
|
||||
StaffZone staffRoles = new StaffZone();
|
||||
JSONObject jsonObject = zoneId.getJSONObject(i);
|
||||
staffRoles.setZoneId(jsonObject.getLong("zoneId"));
|
||||
staffRoles.setZoneName(jsonObject.getString("zoneName"));
|
||||
staffRoles.setStaffId(staff.getStaffId());
|
||||
return staffRoles;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
if (!zoneList.isEmpty()) {
|
||||
staffZoneService.saveBatch(zoneList);
|
||||
}
|
||||
return JsonResult.success("保存成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return JsonResult.failed("保存失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号信息更新
|
||||
*
|
||||
* @param staffDto
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
@PostMapping("staffInfoUpdate")
|
||||
public JsonResult<?> staffInfoUpdate(@RequestBody ReqStaffDto staffDto) {
|
||||
|
||||
try {
|
||||
Staff staff = new Staff();
|
||||
BeanUtils.copyProperties(staffDto, staff);
|
||||
staffService.updateById(staff);
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.eq(STAFF_ROLES.STAFF_ID.getName(), staff.getStaffId());
|
||||
staffRolesService.remove(queryWrapper);
|
||||
queryWrapper.clear();
|
||||
queryWrapper.eq(STAFF_ZONE.STAFF_ID.getName(), staff.getStaffId());
|
||||
staffZoneService.remove(queryWrapper);
|
||||
JSONArray roleId = staffDto.getRoleId();
|
||||
List<StaffRoles> roleList = IntStream.range(0, roleId.size())
|
||||
.mapToObj(i -> {
|
||||
StaffRoles staffRoles = new StaffRoles();
|
||||
staffRoles.setRoleId(Long.parseLong(roleId.get(i).toString()));
|
||||
staffRoles.setStaffId(staff.getStaffId());
|
||||
return staffRoles;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
if (!roleList.isEmpty()) {
|
||||
staffRolesService.saveBatch(roleList);
|
||||
}
|
||||
JSONArray zoneId = staffDto.getZoneId();
|
||||
List<StaffZone> zoneList = IntStream.range(0, zoneId.size())
|
||||
.mapToObj(i -> {
|
||||
StaffZone staffRoles = new StaffZone();
|
||||
JSONObject jsonObject = zoneId.getJSONObject(i);
|
||||
staffRoles.setZoneId(jsonObject.getLong("zoneId"));
|
||||
staffRoles.setZoneName(jsonObject.getString("zoneName"));
|
||||
staffRoles.setStaffId(staff.getStaffId());
|
||||
return staffRoles;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
if (!zoneList.isEmpty()) {
|
||||
staffZoneService.saveBatch(zoneList);
|
||||
}
|
||||
return JsonResult.success("保存成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return JsonResult.failed("保存失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.cdzy.user.mapper;
|
||||
|
||||
import com.cdzy.user.model.entity.StaffZone;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
public interface StaffZoneMapper extends BaseMapper<StaffZone> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.cdzy.user.model.dto;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
@Data
|
||||
public class ReqStaffDto implements Serializable {
|
||||
|
||||
private Long staffId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String phone;
|
||||
|
||||
private Long orgId;
|
||||
|
||||
private String state;
|
||||
|
||||
private JSONArray zoneId;
|
||||
|
||||
private JSONArray roleId;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.cdzy.user.model.dto;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
@Data
|
||||
public class ResStaffDto implements Serializable {
|
||||
|
||||
private Long staffId;
|
||||
|
||||
private String zoneId;
|
||||
|
||||
private String zoneName;
|
||||
|
||||
private String username;
|
||||
|
||||
private String phone;
|
||||
|
||||
private Long orgId;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
private String state;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleId;
|
||||
|
||||
}
|
||||
@ -39,9 +39,13 @@ public class Staff implements Serializable {
|
||||
|
||||
private Long orgId;
|
||||
|
||||
@Column(onInsertValue = "0")
|
||||
private Boolean isSuperadmin;
|
||||
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(onInsertValue = "1")
|
||||
private String state;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.cdzy.user.model.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-04-01
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("ebike_staff_zone")
|
||||
public class StaffZone implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 绑定id
|
||||
*/
|
||||
@Id
|
||||
private Long bindId;
|
||||
|
||||
/**
|
||||
* 行政区划id
|
||||
*/
|
||||
private Long zoneId;
|
||||
|
||||
/**
|
||||
* 员工id
|
||||
*/
|
||||
private Long staffId;
|
||||
|
||||
/**
|
||||
* 行政区划名称
|
||||
*/
|
||||
private String zoneName;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.cdzy.user.service;
|
||||
|
||||
import com.cdzy.user.model.entity.Staff;
|
||||
import com.cdzy.user.model.entity.StaffZone;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-14
|
||||
*/
|
||||
public interface StaffZoneService extends IService<StaffZone> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.cdzy.user.service.impl;
|
||||
|
||||
import com.cdzy.user.mapper.StaffZoneMapper;
|
||||
import com.cdzy.user.model.entity.StaffZone;
|
||||
import com.cdzy.user.service.StaffZoneService;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author:Ding
|
||||
* @ClassName:StaffZoneServiceImpl
|
||||
* @Package:com.cdzy.user.service.impl.StaffZoneServiceImpl
|
||||
* @Description:
|
||||
* @CreateDate:2025年05月13日
|
||||
* @Version:
|
||||
**/
|
||||
@Service
|
||||
public class StaffZoneServiceImpl extends ServiceImpl<StaffZoneMapper, StaffZone> implements StaffZoneService {
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user