|
|
@ -1,8 +1,10 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dto.CustomerStaffAgencyDTO; |
|
|
|
import com.epmet.dto.CustomerStaffDTO; |
|
|
|
import com.epmet.dto.form.StaffInfoFromDTO; |
|
|
|
import com.epmet.dto.form.StaffSubmitFromDTO; |
|
|
|
import com.epmet.dto.form.StaffsInAgencyFromDTO; |
|
|
@ -11,6 +13,7 @@ import com.epmet.dto.result.StaffInfoResultDTO; |
|
|
|
import com.epmet.dto.result.StaffInitResultDTO; |
|
|
|
import com.epmet.dto.result.StaffsInAgencyResultDTO; |
|
|
|
import com.epmet.entity.CustomerAgencyEntity; |
|
|
|
import com.epmet.entity.CustomerStaffAgencyEntity; |
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
|
import com.epmet.feign.OperCrmFeignClient; |
|
|
|
import com.epmet.service.CustomerAgencyService; |
|
|
@ -18,7 +21,9 @@ import com.epmet.service.CustomerStaffAgencyService; |
|
|
|
import com.epmet.service.StaffService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -43,11 +48,17 @@ public class StaffServiceImpl implements StaffService { |
|
|
|
StaffsInAgencyResultDTO resultDTO = new StaffsInAgencyResultDTO(); |
|
|
|
//获取机关所在客户ID和人员总数
|
|
|
|
CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); |
|
|
|
if (null == customerAgencyEntity) { |
|
|
|
resultDTO.setStaffList(new ArrayList<>()); |
|
|
|
resultDTO.setStaffCount(0); |
|
|
|
return new Result<StaffsInAgencyResultDTO>().ok(resultDTO); |
|
|
|
} |
|
|
|
resultDTO.setStaffCount(customerAgencyEntity.getTotalUser()); |
|
|
|
fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); |
|
|
|
List<CustomerStaffAgencyDTO> customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); |
|
|
|
if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { |
|
|
|
return new Result<StaffsInAgencyResultDTO>().ok(null); |
|
|
|
resultDTO.setStaffList(new ArrayList<>()); |
|
|
|
return new Result<StaffsInAgencyResultDTO>().ok(resultDTO); |
|
|
|
} |
|
|
|
//提取所有userID
|
|
|
|
List<String> staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); |
|
|
@ -62,6 +73,9 @@ public class StaffServiceImpl implements StaffService { |
|
|
|
public Result<List<StaffInfoResultDTO>> getStaffList(StaffsInAgencyFromDTO fromDTO) { |
|
|
|
//获取机关所在客户ID
|
|
|
|
CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); |
|
|
|
if (null == customerAgencyEntity) { |
|
|
|
return new Result<List<StaffInfoResultDTO>>().ok(new ArrayList<>()); |
|
|
|
} |
|
|
|
fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); |
|
|
|
List<CustomerStaffAgencyDTO> customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); |
|
|
|
if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { |
|
|
@ -71,8 +85,7 @@ public class StaffServiceImpl implements StaffService { |
|
|
|
List<String> staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); |
|
|
|
fromDTO.setStaffList(staffIds); |
|
|
|
//获取用户列表
|
|
|
|
Result<List<StaffInfoResultDTO>> staffInfoListResult = epmetUserFeignClient.getStaffInfoForHome(fromDTO); |
|
|
|
return null; |
|
|
|
return epmetUserFeignClient.getStaffList(fromDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -90,24 +103,47 @@ public class StaffServiceImpl implements StaffService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result addStaff(TokenDto tokenDto, StaffSubmitFromDTO fromDTO) { |
|
|
|
CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); |
|
|
|
fromDTO.setApp(tokenDto.getApp()); |
|
|
|
fromDTO.setClient(tokenDto.getClient()); |
|
|
|
Result result = epmetUserFeignClient.addStaff(fromDTO); |
|
|
|
//机关总人数加一
|
|
|
|
if (result.success()) { |
|
|
|
CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); |
|
|
|
customerAgencyEntity.setTotalUser(customerAgencyEntity.getTotalUser() + 1); |
|
|
|
customerAgencyService.updateById(customerAgencyEntity); |
|
|
|
fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); |
|
|
|
Result<CustomerStaffDTO> result = epmetUserFeignClient.addStaff(fromDTO); |
|
|
|
|
|
|
|
if (!result.success()) { |
|
|
|
if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { |
|
|
|
return new Result().error(result.getCode(), result.getMsg()); |
|
|
|
} |
|
|
|
return new Result().error(EpmetErrorCode.STAFF_ADD_FAILED.getCode(), EpmetErrorCode.STAFF_ADD_FAILED.getMsg()); |
|
|
|
} |
|
|
|
//人员机关关系表
|
|
|
|
CustomerStaffAgencyEntity customerStaffAgencyEntity = new CustomerStaffAgencyEntity(); |
|
|
|
customerStaffAgencyEntity.setCustomerId(customerAgencyEntity.getCustomerId()); |
|
|
|
customerStaffAgencyEntity.setUserId(result.getData().getUserId()); |
|
|
|
customerStaffAgencyEntity.setAgencyId(customerAgencyEntity.getId()); |
|
|
|
customerStaffAgencyService.insert(customerStaffAgencyEntity); |
|
|
|
//机关总人数加一
|
|
|
|
customerAgencyEntity.setTotalUser(customerAgencyEntity.getTotalUser() + 1); |
|
|
|
customerAgencyService.updateById(customerAgencyEntity); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result editStaff(TokenDto tokenDto, StaffSubmitFromDTO fromDTO) { |
|
|
|
CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); |
|
|
|
fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); |
|
|
|
|
|
|
|
fromDTO.setApp(tokenDto.getApp()); |
|
|
|
fromDTO.setClient(tokenDto.getClient()); |
|
|
|
return epmetUserFeignClient.editStaff(fromDTO); |
|
|
|
Result result = epmetUserFeignClient.editStaff(fromDTO); |
|
|
|
if (!result.success()) { |
|
|
|
if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { |
|
|
|
return new Result().error(result.getCode(), result.getMsg()); |
|
|
|
} |
|
|
|
return new Result().error(EpmetErrorCode.STAFF_EDIT_FAILED.getCode(), EpmetErrorCode.STAFF_EDIT_FAILED.getMsg()); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|