From 63e16b80d9fa0e958d1c85b929b855bafcc45c52 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Sun, 26 Apr 2020 16:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87-=E5=B7=A5=E4=BD=9C=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=20bug=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/exception/EpmetErrorCode.java | 6 +- .../epmet/dto/form/StaffSubmitFromDTO.java | 4 ++ .../com/epmet/feign/EpmetUserFeignClient.java | 2 +- .../EpmetUserFeignClientFallBack.java | 2 +- .../epmet/service/impl/StaffServiceImpl.java | 56 ++++++++++++--- .../controller/CustomerStaffController.java | 70 ++++++++++++++++++- .../epmet/service/CustomerStaffService.java | 2 +- .../impl/CustomerStaffServiceImpl.java | 64 +++++++++++------ .../resources/mapper/CustomerStaffDao.xml | 38 ++++++---- 9 files changed, 193 insertions(+), 51 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index f84dfde45f..5dbc9f0cf2 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -34,8 +34,10 @@ public enum EpmetErrorCode { REQUIRE_PERMISSION(8301, "没有足够的操作权限"), - NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"); - + NOT_ADD_GRID(8401,"您当前的网格名称已存在,请重新修改"), + MOBILE_USED(8402,"该手机号已注册"), + STAFF_ADD_FAILED(8403,"人员添加失败"), + STAFF_EDIT_FAILED(8404,"人员编辑失败"); private int code; private String msg; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java index 87ffa6f26b..0f368af813 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffSubmitFromDTO.java @@ -16,6 +16,10 @@ import java.util.List; @Data public class StaffSubmitFromDTO implements Serializable { private static final long serialVersionUID = 1L; + /** + * 客户ID + */ + private String customerId; /** * 机关ID */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java index 1d52e9072d..d8a404d782 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java @@ -96,7 +96,7 @@ public interface EpmetUserFeignClient { * @return Result */ @PostMapping("/epmetuser/customerstaff/addstaff") - Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO); + Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO); /** * 人员编辑 diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java index 29986d388f..20255d3962 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallBack.java @@ -68,7 +68,7 @@ public class EpmetUserFeignClientFallBack implements EpmetUserFeignClient { } @Override - public Result addStaff(StaffSubmitFromDTO fromDTO) { + public Result addStaff(StaffSubmitFromDTO fromDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "addStaff", fromDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java index db4e263508..dcdb8087f7 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java @@ -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().ok(resultDTO); + } resultDTO.setStaffCount(customerAgencyEntity.getTotalUser()); fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); List customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { - return new Result().ok(null); + resultDTO.setStaffList(new ArrayList<>()); + return new Result().ok(resultDTO); } //提取所有userID List staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); @@ -62,6 +73,9 @@ public class StaffServiceImpl implements StaffService { public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { //获取机关所在客户ID CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); + if (null == customerAgencyEntity) { + return new Result>().ok(new ArrayList<>()); + } fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); List customerStaffAgencyList = customerStaffAgencyService.getCustomerStaffAgencyList(fromDTO).getData(); if (null == customerStaffAgencyList || customerStaffAgencyList.size() == 0) { @@ -71,8 +85,7 @@ public class StaffServiceImpl implements StaffService { List staffIds = customerStaffAgencyList.stream().map(CustomerStaffAgencyDTO::getUserId).collect(Collectors.toList()); fromDTO.setStaffList(staffIds); //获取用户列表 - Result> 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 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 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index 1ae28a3d14..cdc627dcc8 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -155,7 +155,7 @@ public class CustomerStaffController { * @return */ @PostMapping("staffsinagency") - public Result> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffInfoForHome(@RequestBody StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffInfoForHome(fromDTO); } @@ -165,7 +165,7 @@ public class CustomerStaffController { * @return */ @PostMapping("stafflist") - public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { + public Result> getStaffList(@RequestBody StaffsInAgencyFromDTO fromDTO) { return customerStaffService.getStaffList(fromDTO); } @@ -194,4 +194,70 @@ public class CustomerStaffController { public Result> selectCustomerIdByUserId(@RequestBody AddDepartmentStaffFormDTO addDepartmentStaffFormDTO){ return customerStaffService.selectCustomerIdByUserId(addDepartmentStaffFormDTO); } + + /** + * 人员添加页面初始化 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("rolelist") + public Result addStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.addStaffInit(fromDTO); + } + + /** + * 人员编辑页面初始化 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaffinit") + public Result editStaffInit(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.editStaffInit(fromDTO); + } + + /** + * 人员添加 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("addstaff") + public Result addStaff(@RequestBody StaffSubmitFromDTO fromDTO){ + return customerStaffService.addStaff(fromDTO); + } + + /** + * 人员编辑 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("editstaff") + public Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO){ + return customerStaffService.editStaff(fromDTO); + } + + /** + * 人员详情 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("staffdetail") + public Result getStaffDetail(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.getStaffDetail(fromDTO); + } + + /** + * 人员禁用 + * + * @param fromDTO 参数 + * @return Result + */ + @PostMapping("disabledstaff") + public Result disabledStaff(@RequestBody StaffInfoFromDTO fromDTO){ + return customerStaffService.disabledStaff(fromDTO); + } } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index 92f6779396..924c85d2f2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -173,7 +173,7 @@ public interface CustomerStaffService extends BaseService { * @param fromDTO 参数 * @return Result */ - Result addStaff(StaffSubmitFromDTO fromDTO); + Result addStaff(StaffSubmitFromDTO fromDTO); /** * 人员编辑 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index d6a76ac6f9..799ab62d71 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -61,6 +61,7 @@ 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.Arrays; import java.util.List; import java.util.Map; @@ -84,6 +85,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( @@ -178,12 +180,18 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl> getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { List list = baseDao.selectCustomerStaffList(fromDTO); + if (null == list) { + list = new ArrayList<>(); + } return new Result>().ok(list); } @Override public Result> getStaffList(StaffsInAgencyFromDTO fromDTO) { List list = baseDao.selectStaffList(fromDTO); + if (null == list) { + list = new ArrayList<>(); + } return new Result>().ok(list); } @@ -194,7 +202,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); if (null == roleList || roleList.size() == 0) { - return new Result().ok(null); + return new Result().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); } List staffRoleList = roleList.stream().map(p -> { StaffRoleResultDTO staffRoleResultDTO = new StaffRoleResultDTO(); @@ -245,7 +253,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl addStaff(StaffSubmitFromDTO fromDTO) { + CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); + customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); + customerStaffFormDTO.setMobile(fromDTO.getMobile()); + CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); + if (null != customerStaffDTO) { + return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + } //USER表插入数据 UserEntity userEntity = new UserEntity(); userEntity.setFromApp(fromDTO.getApp()); @@ -253,6 +268,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class)); } @Override @Transactional(rollbackFor = Exception.class) public Result editStaff(StaffSubmitFromDTO fromDTO) { + CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); + customerStaffFormDTO.setCustomerId(fromDTO.getCustomerId()); + customerStaffFormDTO.setMobile(fromDTO.getMobile()); + CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(customerStaffFormDTO); + if (!fromDTO.getStaffId().equals(customerStaffDTO.getUserId())) { + return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + } + CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); //Customer_Staff表插入数据 CustomerStaffEntity staffEntity = new CustomerStaffEntity(); @@ -334,18 +358,19 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl selectGridStaffCountByUserId(List userIdDTO) { - Result gridStaffCountDTOResult = new Result(); - GridStaffCountDTO gridStaffCountDTO = baseDao.selectGridStaffCountByUserId(userIdDTO); - gridStaffCountDTOResult.setData(gridStaffCountDTO); - return gridStaffCountDTOResult; - } + /** + * 根据userId查询网格下未被禁用的人员数量 + * + * @param userIdDTO + * @return + */ + @Override + public Result selectGridStaffCountByUserId(List userIdDTO) { + Result gridStaffCountDTOResult = new Result(); + GridStaffCountDTO gridStaffCountDTO = baseDao.selectGridStaffCountByUserId(userIdDTO); + gridStaffCountDTOResult.setData(gridStaffCountDTO); + return gridStaffCountDTOResult; + } @Override public Result> getDepartmentStaffList(DepartmentInStaffFormDTO formDTO) { @@ -364,11 +389,10 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl>().ok(staffList); } - /** - * - * @param: addDepartmentStaffFormDTO - * @auther: zxc - */ + /** + * @param: addDepartmentStaffFormDTO + * @auther: zxc + */ @Override public Result> selectCustomerIdByUserId(AddDepartmentStaffFormDTO addDepartmentStaffFormDTO) { return new Result>().ok(baseDao.selectCustomerIdByUserId(addDepartmentStaffFormDTO)); diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index 9335d663bd..828aa05c1d 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -59,29 +59,39 @@ @@ -111,7 +121,7 @@ #{userId} - ORDER BY convert(cs.REAL_NAME using gbk) asc ASC + ORDER BY convert(cs.REAL_NAME using gbk) ASC