Browse Source

查询登陆用户客户列表(工作端)、获取pc工作端登陆用户信息 接口开发

dev
zhangyongzhangyong 5 years ago
parent
commit
0db16b793c
  1. 26
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerListFormDTO.java
  2. 23
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CustomerListResultDTO.java
  3. 48
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/StaffBasicInfoResultDTO.java
  4. 29
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java
  5. 20
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java
  6. 24
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java
  7. 46
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java
  8. 14
      epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml

26
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerListFormDTO.java

@ -0,0 +1,26 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 查询登陆用户客户列表工作端
* @CreateTime 2020/8/25
*/
@Data
public class CustomerListFormDTO implements Serializable {
private static final long serialVersionUID = 1L;
public interface UserIdGroup extends CustomerClientShowGroup{}
/**
* 手机号
*/
@NotBlank(message = "手机号不能为空",groups = UserIdGroup.class)
private String phone;
}

23
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/CustomerListResultDTO.java

@ -0,0 +1,23 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* 查询登陆用户客户列表工作端
* @CreateTime 2020/8/25
*/
@Data
public class CustomerListResultDTO implements Serializable {
/**
* 客户Id
*/
private String customerId;
/**
* 客户名称
*/
private String customerName;
}

48
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/StaffBasicInfoResultDTO.java

@ -0,0 +1,48 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* 获取pc工作端登陆用户信息
* @CreateTime 2020/8/25
*/
@Data
public class StaffBasicInfoResultDTO implements Serializable {
/**
* 客户Id
*/
private String customerId;
/**
* 用户Id
*/
private String userId;
/**
* 真实姓名
*/
private String realName;
/**
* 性别0.未知1男2.
*/
private String gender;
/**
* 邮箱
*/
private String email;
/**
* 手机号
*/
private String mobile;
/**
* 地址
*/
private String address;
}

29
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java

@ -17,7 +17,9 @@
package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
@ -359,4 +361,31 @@ public class CustomerStaffController {
customerStaffService.updateRootManage(formDTO);
return new Result();
}
/**
* 查询登陆用户客户列表工作端
* 根据手机号查询customer_staff表数据在根据查询到的数据的userId判断是不是根管理员最后将同一手机号对应的客户列表且该手机都是根管理员的客户列表返给前端
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.util.List<com.epmet.dto.result.CustomerListResultDTO>>
* @Author zhangyong
* @Date 10:03 2020-08-25
**/
@PostMapping(value = "customerlist")
public Result<List<CustomerListResultDTO>> customerList(@RequestBody CustomerListFormDTO formDTO){
return customerStaffService.selectCustomerList(formDTO);
}
/**
* 获取pc工作端登陆用户信息
* 根据token中userId去查询登陆用户基本信息
* @param tokenDTO
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.StaffBasicInfoResultDTO>
* @Author zhangyong
* @Date 11:09 2020-08-25
**/
@PostMapping(value = "staffbasicinfo")
public Result<StaffBasicInfoResultDTO> staffBasicInfo(@LoginUser TokenDto tokenDTO){
return customerStaffService.selectStaffBasicInfo(tokenDTO.getUserId());
}
}

20
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java

@ -17,17 +17,18 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.annotation.DataFilter;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.commons.mybatis.entity.DataScope;
import com.epmet.dto.StaffRoleDTO;
import com.epmet.dto.form.CommonUserFormDTO;
import com.epmet.dto.form.CustomerStaffRoleListFormDTO;
import com.epmet.dto.result.*;
import com.epmet.dto.result.CustomerStaffRoleListResultDTO;
import com.epmet.dto.result.CustomerStaffRoleResultDTO;
import com.epmet.dto.result.GovStaffRoleResultDTO;
import com.epmet.dto.result.StaffRolesResultDTO;
import com.epmet.entity.StaffRoleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.context.annotation.Scope;
import java.util.List;
@ -100,4 +101,15 @@ public interface StaffRoleDao extends BaseDao<StaffRoleEntity> {
List<CustomerStaffRoleResultDTO> selectStaffRoles(@Param("staffId") String staffId);
List<StaffRoleEntity> listStaffRoleEntytiesByStaffIdAndOrgId(@Param("agencyId") String agencyId, @Param("staffId") String staffId);
}
/**
* 根据用户id角色id查询 工作人员-角色关系表
*
* @param staffId
* @param roleId
* @return com.epmet.dto.StaffRoleDTO
* @Author zhangyong
* @Date 10:45 2020-08-25
**/
StaffRoleDTO selectStaffRoleByStaffIdAndRoleId(@Param("staffId") String staffId, @Param("roleId") String roleId);
}

24
epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java

@ -284,4 +284,26 @@ public interface CustomerStaffService extends BaseService<CustomerStaffEntity> {
* @return com.epmet.dto.CustomerStaffDTO
*/
void updateRootManage(UpdateRootManageFormDTO formDTO);
}
/**
* 查询登陆用户客户列表工作端
* 根据手机号查询customer_staff表数据在根据查询到的数据的userId判断是不是根管理员最后将同一手机号对应的客户列表且该手机都是根管理员的客户列表返给前端
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.util.List<com.epmet.dto.result.CustomerListResultDTO>>
* @Author zhangyong
* @Date 10:03 2020-08-25
**/
Result<List<CustomerListResultDTO>> selectCustomerList(CustomerListFormDTO formDTO);
/**
* 获取pc工作端登陆用户信息
* 根据token中userId去查询登陆用户基本信息
*
* @param userId
* @return com.epmet.commons.tools.utils.Result<com.epmet.dto.result.StaffBasicInfoResultDTO>
* @Author zhangyong
* @Date 11:10 2020-08-25
**/
Result<StaffBasicInfoResultDTO> selectStaffBasicInfo(String userId);
}

46
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java

@ -17,12 +17,14 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.entity.DataScope;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
@ -47,6 +49,7 @@ import com.epmet.entity.StaffRoleEntity;
import com.epmet.entity.UserEntity;
import com.epmet.feign.AuthFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.redis.CustomerStaffRedis;
import com.epmet.service.CustomerStaffService;
import com.epmet.service.GovStaffRoleService;
@ -99,6 +102,8 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
private CustomerStaffDao customerStaffDao;
@Autowired
private GovStaffRoleDao govStaffRoleDao;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
@Override
public PageData<CustomerStaffDTO> page(Map<String, Object> params) {
@ -611,4 +616,43 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
update(dto);
}
}
@Override
public Result<List<CustomerListResultDTO>> selectCustomerList(CustomerListFormDTO formDTO) {
List<CustomerListResultDTO> listResultDTO = new ArrayList<>();
CustomerListResultDTO resultDTO = new CustomerListResultDTO();
CustomerDTO customerDTO = new CustomerDTO();
// 1.根据手机号,去 customer_staff表,进行查询; 查询结果 多条:字段 customer_id,user_id
List<CustomerStaffDTO> customerStaffList = baseDao.selectListCustomerStaffDTO(formDTO.getPhone());
for (CustomerStaffDTO staffDTO : customerStaffList){
// 2.根据 customer_id 去 gov_staff_role表,查询 customer_id + role_key = root_manager ,确定 根管理员的id,即roleId
GovStaffRoleDTO roleKey = govStaffRoleDao.getRoleByCustomerIdAndRoleKey(staffDTO.getCustomerId(), RoleKeyConstants.ROLE_KEY_ROOT_MANAGER);
// 3.根据roleId + staff_id(即 userId) 查 staff_role表的主键id, 如果查到了,那这个userId就是 根管理员
StaffRoleDTO staffRoleDTO = staffRoleDao.selectStaffRoleByStaffIdAndRoleId(staffDTO.getUserId(), roleKey.getId());
if (null != staffRoleDTO){
// 4.如果userID是根管理员的话,则根据customerId 去 customer表 查询 id、customer_name
customerDTO.setId(staffDTO.getCustomerId());
Result<CustomerDTO> customerInfo = operCrmOpenFeignClient.getCustomerInfo(customerDTO);
if (!customerInfo.success()) {
logger.error(String.format("获取根管理员信息失败,调用%s服务查询客户名称失败,入参%s", ServiceConstant.OPER_CRM_SERVER, JSON.toJSONString(staffDTO.getCustomerId())));
} else {
if (null != customerInfo.getData()){
resultDTO.setCustomerId(customerInfo.getData().getId());
resultDTO.setCustomerName(customerInfo.getData().getCustomerName());
listResultDTO.add(resultDTO);
}
}
}
}
return new Result<List<CustomerListResultDTO>>().ok(listResultDTO);
}
@Override
public Result<StaffBasicInfoResultDTO> selectStaffBasicInfo(String userId) {
CustomerStaffEntity staffEntity = baseDao.selectByUserId(userId);
StaffBasicInfoResultDTO resultDTO = ConvertUtils.sourceToTarget(staffEntity, StaffBasicInfoResultDTO.class);
resultDTO.setGender(String.valueOf(staffEntity.getGender()));
return new Result<StaffBasicInfoResultDTO>().ok(resultDTO);
}
}

14
epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml

@ -164,4 +164,16 @@
and sr.ORG_ID = #{agencyId}
and sr.DEL_FLAG='0'
</select>
</mapper>
<select id="selectStaffRoleByStaffIdAndRoleId" resultType="com.epmet.dto.StaffRoleDTO">
select
ID id,
STAFF_ID staffId,
ROLE_ID roleId,
ORG_ID orgId
from staff_role sr
where sr.STAFF_ID = #{staffId}
and sr.ROLE_ID = #{roleId}
and sr.DEL_FLAG='0'
</select>
</mapper>

Loading…
Cancel
Save