From a5a30794eac3cec902f5253704c2269ba763a063 Mon Sep 17 00:00:00 2001 From: HAHA Date: Tue, 17 May 2022 09:31:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E5=BD=95=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/utils/NodeTree.java | 45 +++++ .../commons/tools/utils/NodeTreeUtils.java | 31 +++ .../AgencyAddressBookTreeResultDTO.java | 39 ++++ .../epmet/controller/AgencyController.java | 92 +++++---- .../java/com/epmet/dao/CustomerAgencyDao.java | 18 +- .../java/com/epmet/service/AgencyService.java | 25 ++- .../epmet/service/impl/AgencyServiceImpl.java | 180 ++++++++++-------- .../resources/mapper/CustomerAgencyDao.xml | 55 ++++++ 8 files changed, 361 insertions(+), 124 deletions(-) create mode 100644 epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTree.java create mode 100644 epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTreeUtils.java create mode 100644 epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencyAddressBookTreeResultDTO.java diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTree.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTree.java new file mode 100644 index 0000000000..8f28cef145 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTree.java @@ -0,0 +1,45 @@ +package com.epmet.commons.tools.utils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class NodeTree implements Serializable { + private static final long serialVersionUID = 8020505121785861117L; + /** + * 主键 + */ + private String id; + /** + * 上级ID + */ + private String pid; + /** + * 子节点列表 + */ + private List children = new ArrayList<>(); + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTreeUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTreeUtils.java new file mode 100644 index 0000000000..1c3df168ee --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/NodeTreeUtils.java @@ -0,0 +1,31 @@ +package com.epmet.commons.tools.utils; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class NodeTreeUtils { + + public static List build(List treeNodes) { + List result = new ArrayList<>(); + + //list转map + Map nodeMap = new LinkedHashMap<>(treeNodes.size()); + for(T treeNode : treeNodes){ + nodeMap.put(treeNode.getId(), treeNode); + } + + for(T node : nodeMap.values()) { + T parent = nodeMap.get(node.getPid()); + if(parent != null && !(node.getId().equals(parent.getId()))){ + parent.getChildren().add(node); + continue; + } + + result.add(node); + } + + return result; + } +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencyAddressBookTreeResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencyAddressBookTreeResultDTO.java new file mode 100644 index 0000000000..33e3fd3737 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencyAddressBookTreeResultDTO.java @@ -0,0 +1,39 @@ +package com.epmet.dto.result; + + +import com.epmet.commons.tools.utils.NodeTree; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AgencyAddressBookTreeResultDTO extends NodeTree implements Serializable { + + private static final long serialVersionUID = -1993037593855768962L; + + /** + * 父id + */ + private String pid; + + /** + * 名字 + */ + private String name; + + /** + * 级别 + */ + private String level; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java index 659b411519..e917eacf59 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/AgencyController.java @@ -94,15 +94,15 @@ public class AgencyController { public Result addAgency(@LoginUser TokenDto tokenDTO, @RequestBody AddAgencyFormDTO formDTO) { ValidatorUtils.validateEntity(formDTO); //机构级别是市级以上则市、区县名称可不传值,是区县级以上则区县名称可不传值 - if(!CustomerAgencyConstant.PROVINCE_LEVEL.equals(formDTO.getLevel())&&!CustomerAgencyConstant.CITY_LEVEL.equals(formDTO.getLevel())){ - if(StringUtils.isBlank(formDTO.getCity())){ + if (!CustomerAgencyConstant.PROVINCE_LEVEL.equals(formDTO.getLevel()) && !CustomerAgencyConstant.CITY_LEVEL.equals(formDTO.getLevel())) { + if (StringUtils.isBlank(formDTO.getCity())) { throw new RenException(CustomerAgencyConstant.CITY_EXCEPTION); } - if(StringUtils.isBlank(formDTO.getDistrict())){ + if (StringUtils.isBlank(formDTO.getDistrict())) { throw new RenException(CustomerAgencyConstant.DISTRICT_EXCEPTION); } - }else if(!CustomerAgencyConstant.PROVINCE_LEVEL.equals(formDTO.getLevel())){ - if(StringUtils.isBlank(formDTO.getCity())){ + } else if (!CustomerAgencyConstant.PROVINCE_LEVEL.equals(formDTO.getLevel())) { + if (StringUtils.isBlank(formDTO.getCity())) { throw new RenException(CustomerAgencyConstant.CITY_EXCEPTION); } } @@ -118,13 +118,13 @@ public class AgencyController { **/ @PostMapping("addagency-v2") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_SUBAGENCY_CREATE) - public Result addAgencyV2(@LoginUser TokenDto tokenDTO,@RequestBody AddAgencyV2FormDTO formDTO) { + public Result addAgencyV2(@LoginUser TokenDto tokenDTO, @RequestBody AddAgencyV2FormDTO formDTO) { ValidatorUtils.validateEntity(formDTO, AddAgencyV2FormDTO.DefaultUserShowGroup.class, AddAgencyV2FormDTO.AddUserInternalGroup.class); if (formDTO.getAreaCodeSwitch().equals(CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN)) { ValidatorUtils.validateEntity(formDTO, AddAgencyV2FormDTO.AreaCodeGroup.class); } //当前客户下,同级组织中,组织名称不允许重复 - customerAgencyService.checkAgencyName(formDTO.getAgencyName(),tokenDTO.getCustomerId(),null,formDTO.getParentAgencyId()); + customerAgencyService.checkAgencyName(formDTO.getAgencyName(), tokenDTO.getCustomerId(), null, formDTO.getParentAgencyId()); AddAgencyResultDTO resultDTO = agencyService.addAgencyV2(formDTO); //2021-11-30 推送mq,数据同步到中介库 start @@ -141,6 +141,7 @@ public class AgencyController { /** * 添加根级组织 + * * @param form * @return */ @@ -175,7 +176,7 @@ public class AgencyController { formDTO.setUserId(tokenDTO.getUserId()); formDTO.setCustomerId(tokenDTO.getCustomerId()); ValidatorUtils.validateEntity(formDTO, EditAgencyFormDTO.DefaultUserShowGroup.class, EditAgencyFormDTO.AddUserInternalGroup.class); - Result result = agencyService.editAgency(formDTO); + Result result = agencyService.editAgency(formDTO); //2021-10-18 推送mq,数据同步到中介库 start【中介库只放了组织的名称、级别,所以涉及批量修改pname的操作不涉及同步中间库】 OrgOrStaffMQMsg mq = new OrgOrStaffMQMsg(); @@ -245,6 +246,7 @@ public class AgencyController { /** * 根据Id查询agency + * * @param agencyId * @return */ @@ -259,6 +261,7 @@ public class AgencyController { /** * 根据staffId查询 + * * @param staffId * @return */ @@ -275,6 +278,7 @@ public class AgencyController { /** * 查询客户根级组织 + * * @param customerId * @return */ @@ -286,6 +290,7 @@ public class AgencyController { /** * 批量查询客户根级组织 + * * @param customerIds * @return */ @@ -324,100 +329,101 @@ public class AgencyController { } /** - * @Description 【地图配置】删除 * @param formDTO + * @Description 【地图配置】删除 * @author zxc * @date 2021/10/25 9:30 上午 */ @PostMapping("mapdelarea") - public Result mapDelArea(@RequestBody MapDelAreaFormDTO formDTO){ + public Result mapDelArea(@RequestBody MapDelAreaFormDTO formDTO) { ValidatorUtils.validateEntity(formDTO, MapDelAreaFormDTO.MapDelAreaForm.class); agencyService.mapDelArea(formDTO); return new Result(); } /** - * @Description 【地图配置】新增 * @param formDTO + * @Description 【地图配置】新增 * @author zxc * @date 2021/10/25 9:58 上午 */ @PostMapping("mapaddarea") - public Result mapAddArea(@RequestBody MapAddAreaFormDTO formDTO){ + public Result mapAddArea(@RequestBody MapAddAreaFormDTO formDTO) { ValidatorUtils.validateEntity(formDTO, MapAddAreaFormDTO.MapAddAreaForm.class); agencyService.mapAddArea(formDTO); return new Result(); } /** - * @Description 【地图配置】组织查询 * @param formDTO * @param tokenDto + * @Description 【地图配置】组织查询 * @author zxc * @date 2021/10/25 10:50 上午 */ @PostMapping("maporg") - public Result mapOrg(@RequestBody MapOrgFormDTO formDTO, @LoginUser TokenDto tokenDto){ - return new Result().ok(agencyService.mapOrg(formDTO,tokenDto)); + public Result mapOrg(@RequestBody MapOrgFormDTO formDTO, @LoginUser TokenDto tokenDto) { + return new Result().ok(agencyService.mapOrg(formDTO, tokenDto)); } /** - * @Description 查询楼栋信息 * @param formDTO + * @Description 查询楼栋信息 * @author zxc * @date 2021/11/2 9:18 上午 */ @PostMapping("baseinfofamilybuilding") - public Result> baseInfoFamilyBuilding(@RequestBody BaseInfoFamilyBuildingFormDTO formDTO){ + public Result> baseInfoFamilyBuilding(@RequestBody BaseInfoFamilyBuildingFormDTO formDTO) { ValidatorUtils.validateEntity(formDTO, BaseInfoFamilyBuildingFormDTO.BaseInfoFamilyBuildingForm.class); return new Result>().ok(agencyService.baseInfoFamilyBuilding(formDTO)); } /** - * @Description 查询下级agencyId * @param orgId + * @Description 查询下级agencyId * @author zxc * @date 2021/12/9 4:42 下午 */ @PostMapping("getsonagencyid") - public Result> getSonAgencyId(@RequestParam("orgId")String orgId,@RequestParam("type")String type){ - return new Result>().ok(agencyService.getSonAgencyId(orgId,type)); + public Result> getSonAgencyId(@RequestParam("orgId") String orgId, @RequestParam("type") String type) { + return new Result>().ok(agencyService.getSonAgencyId(orgId, type)); } /** * Desc: 生成某类型下的二维码 + * * @param formDTO * @author zxc * @date 2022/3/2 10:32 上午 */ @PostMapping("create-qrcode") - public void createQrCode(@LoginUser TokenDto tokenDto, @RequestBody CreateQrCodeFormDTO formDTO, HttpServletResponse response){ + public void createQrCode(@LoginUser TokenDto tokenDto, @RequestBody CreateQrCodeFormDTO formDTO, HttpServletResponse response) { ValidatorUtils.validateEntity(formDTO, CreateQrCodeFormDTO.CreateQrCodeForm.class); String id = formDTO.getId(); String type = formDTO.getType(); String name = ""; try { - if (type.equals(OrgInfoConstant.COMMUNITY)){ + if (type.equals(OrgInfoConstant.COMMUNITY)) { CustomerAgencyDTO customerAgencyDTO = customerAgencyService.get(id); - if (customerAgencyDTO == null){ - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"组织信息不存在"); + if (customerAgencyDTO == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "组织信息不存在"); } name = customerAgencyDTO.getOrganizationName(); - }else if (type.equals(OrgInfoConstant.NEIGHBOR_HOOD)){ + } else if (type.equals(OrgInfoConstant.NEIGHBOR_HOOD)) { IcNeighborHoodDTO icNeighborHoodDTO = neighborHoodService.get(id); - if (icNeighborHoodDTO == null){ - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"小区信息不存在"); + if (icNeighborHoodDTO == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "小区信息不存在"); } name = icNeighborHoodDTO.getNeighborHoodName(); } //url组成:数字社区地址?小区id&用户id //String url = "https://demo.tduckapp.com/s/7314b64b3a26455ab793fb8c640856b6?id="+id; String url = EnvEnum.getCurrentEnv().getUrl() - .replace("cloud","open") + .replace("cloud", "open") .replace("api/", StrConstant.EPMETY_STR) .concat("epmet-oper-gov/#/caiji/") .concat(id).concat("?") - .concat("name=").concat(URLEncoder.encode(name,StrConstant.UTF_8)).concat(StrConstant.AND_MARK) + .concat("name=").concat(URLEncoder.encode(name, StrConstant.UTF_8)).concat(StrConstant.AND_MARK) .concat("customerId=").concat(tokenDto.getCustomerId()).concat(StrConstant.AND_MARK) .concat("type=").concat(type).concat(StrConstant.AND_MARK) .concat("userId=").concat(tokenDto.getUserId()) @@ -429,18 +435,18 @@ public class AgencyController { ImageIO.write(image, "png", imageOutput); InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); long length = imageOutput.length(); - String fileName = name+".png"; + String fileName = name + ".png"; response.setContentType("application/octet-stream"); - response.setContentLength((int)length); - response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode(fileName, StrConstant.UTF_8)); + response.setContentLength((int) length); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StrConstant.UTF_8)); //输出流 byte[] bytes = new byte[1024]; OutputStream outputStream = response.getOutputStream(); long count = 0; - while(count < length){ + while (count < length) { int len = inputStream.read(bytes, 0, 1024); - count +=len; + count += len; outputStream.write(bytes, 0, len); } outputStream.flush(); @@ -451,12 +457,28 @@ public class AgencyController { /** * Desc: 查询工作人员所属组织下的所有社区 + * * @param tokenDto * @author zxc * @date 2022/3/21 15:13 */ @PostMapping("community-list") - public Result> getCommunityList(@LoginUser TokenDto tokenDto){ + public Result> getCommunityList(@LoginUser TokenDto tokenDto) { return new Result>().ok(agencyService.getCommunityList(tokenDto)); } + + /** + * 通讯录树状结构 + * + * @param name + * @param tokenDto + * @return com.epmet.commons.tools.utils.Result> + * @author LZN + * @date 2022/5/16 10:42 + */ + @GetMapping("/orgtree/{name}/{customerId}") + public Result> getAddressTree(@PathVariable String name, @PathVariable String customerId) { + List dto = agencyService.getAddressTree(name, customerId); + return new Result>().ok(dto); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java index 5e7cd8713a..8eb7a45da1 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerAgencyDao.java @@ -295,26 +295,40 @@ public interface CustomerAgencyDao extends BaseDao { /** * desc:获取组织和网格的数据 树形sql + * * @param agencyId * @return */ ExtStaffPermissionResultDTO selectAgencyAndGridById(@Param("agencyId") String agencyId); + /** * @Description 【事件】社区服务热线 * @author sun **/ OrgMobileResultDTO getAgencyMobile(@Param("gridId") String gridId); - int updateSubAgencyAreaCodeById(@Param("customerId")String customerId, @Param("agencyId")String agencyId, @Param("operateUserId") String operateUserId); + int updateSubAgencyAreaCodeById(@Param("customerId") String customerId, @Param("agencyId") String agencyId, @Param("operateUserId") String operateUserId); /** * Desc: 查询组织下的社区 + * * @param customerId * @param agencyId * @author zxc * @date 2022/3/21 15:23 */ - List getCommunityList(@Param("customerId")String customerId, @Param("agencyId")String agencyId); + List getCommunityList(@Param("customerId") String customerId, @Param("agencyId") String agencyId); + /** + * 通讯录树 + * + * @param name + * @param customerId + * @return java.util.List + * @author LZN + * @date 2022/5/16 10:44 + */ + List getAddressTree(@Param("name") String name, + @Param("customerId") String customerId); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java index 629adcc17a..ea43abd53e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/AgencyService.java @@ -66,6 +66,7 @@ public interface AgencyService { /** * 根据Id查询 + * * @param agencyId * @return */ @@ -75,6 +76,7 @@ public interface AgencyService { /** * 查询客户根级组织 + * * @param customerId */ CustomerAgencyDTO getCustomerRootAgency(String customerId); @@ -99,52 +101,63 @@ public interface AgencyService { AddAgencyResultDTO addAgencyV2(AddAgencyV2FormDTO formDTO); /** - * @Description 【地图配置】删除 * @param formDTO + * @Description 【地图配置】删除 * @author zxc * @date 2021/10/25 9:30 上午 */ void mapDelArea(MapDelAreaFormDTO formDTO); /** - * @Description 【地图配置】新增 * @param formDTO + * @Description 【地图配置】新增 * @author zxc * @date 2021/10/25 9:58 上午 */ void mapAddArea(MapAddAreaFormDTO formDTO); /** - * @Description 【地图配置】组织查询 * @param formDTO * @param tokenDto + * @Description 【地图配置】组织查询 * @author zxc * @date 2021/10/25 10:50 上午 */ MapOrgResultDTO mapOrg(MapOrgFormDTO formDTO, TokenDto tokenDto); /** - * @Description 查询楼栋信息 * @param formDTO + * @Description 查询楼栋信息 * @author zxc * @date 2021/11/2 9:18 上午 */ List baseInfoFamilyBuilding(BaseInfoFamilyBuildingFormDTO formDTO); /** - * @Description 查询下级agencyId * @param orgId + * @Description 查询下级agencyId * @author zxc * @date 2021/12/9 4:42 下午 */ - List getSonAgencyId(String orgId,String type); + List getSonAgencyId(String orgId, String type); /** * Desc: 查询工作人员所属组织下的所有社区 + * * @param tokenDto * @author zxc * @date 2022/3/21 15:13 */ List getCommunityList(TokenDto tokenDto); + /** + * 通讯录树状结构 + * + * @param name + * @param customerId + * @return java.util.List + * @author LZN + * @date 2022/5/16 10:43 + */ + List getAddressTree(String name, String customerId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index c07985347c..dd9e8009eb 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -33,6 +33,7 @@ import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.NodeTreeUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.CustomerAgencyConstant; import com.epmet.constant.OrgInfoConstant; @@ -156,15 +157,15 @@ public class AgencyServiceImpl implements AgencyService { Result result = new Result(); CustomerAgencyEntity originalEntity = customerAgencyDao.selectById(formDTO.getAgencyId()); //当前客户下,同级组织中,组织名称不允许重复 - customerAgencyService.checkAgencyName(formDTO.getAgencyName(),originalEntity.getCustomerId(),originalEntity.getId(),originalEntity.getPid()); + customerAgencyService.checkAgencyName(formDTO.getAgencyName(), originalEntity.getCustomerId(), originalEntity.getId(), originalEntity.getPid()); originalEntity.setOrganizationName(formDTO.getAgencyName()); originalEntity.setCode(formDTO.getCode()); originalEntity.setContacts(formDTO.getContacts()); originalEntity.setMobile(formDTO.getMobile()); - if(StringUtils.isNotBlank(formDTO.getLatitude())){ + if (StringUtils.isNotBlank(formDTO.getLatitude())) { originalEntity.setLatitude(formDTO.getLatitude()); } - if(StringUtils.isNotBlank(formDTO.getLongitude())){ + if (StringUtils.isNotBlank(formDTO.getLongitude())) { originalEntity.setLongitude(formDTO.getLongitude()); } originalEntity.setCenterAddress(formDTO.getCenterAddress()); @@ -207,20 +208,20 @@ public class AgencyServiceImpl implements AgencyService { } //3:循环组织列表,查询每一个组织的所有上级组织重新拼接所有上级名称(allParentName)字段值 List editList = new ArrayList<>(); - agencyList.forEach(agency->{ + agencyList.forEach(agency -> { //3-1:查询当前组织的所有上级组织 List listStr = Arrays.asList(agency.getPids().split(":")); List parentList = customerAgencyDao.selectPAgencyById(listStr); //3-2:重新拼接当前组织的所有上级名称字段值,将组织Id和拼好的值存入集合 StringBuffer allParentName = new StringBuffer(); - parentList.forEach(parents->{ - if(StringUtils.isBlank(allParentName)){ + parentList.forEach(parents -> { + if (StringUtils.isBlank(allParentName)) { allParentName.append(parents.getName()); - }else { + } else { allParentName.append("-").append(parents.getName()); } }); - CustomerAgencyEntity customerAgencyEntity = ConvertUtils.sourceToTarget(agency,CustomerAgencyEntity.class); + CustomerAgencyEntity customerAgencyEntity = ConvertUtils.sourceToTarget(agency, CustomerAgencyEntity.class); customerAgencyEntity.setAllParentName(allParentName.toString()); customerAgencyEntity.setUpdatedBy(formDTO.getUserId()); editList.add(customerAgencyEntity); @@ -240,11 +241,12 @@ public class AgencyServiceImpl implements AgencyService { /** * 所有下家组织、网格、部门的area_code,parent_area_code置为空 * 直属组织parent_area_code、直属网格+直属部门的area_code更新为最新值 + * * @param customerId * @param formDTO * @param originalAreaCode */ - private void updateSubOrg(String customerId, EditAgencyFormDTO formDTO,String originalAreaCode) { + private void updateSubOrg(String customerId, EditAgencyFormDTO formDTO, String originalAreaCode) { //如果原来这个组织有area_code再去更新,没有其实应该按照pids去更新。 customerAgencyDao.updateSubAgencyAreaCodeById(customerId, formDTO.getAgencyId(), formDTO.getUserId()); //网格的 @@ -254,40 +256,39 @@ public class AgencyServiceImpl implements AgencyService { //1、更新直属网格的areaCode LambdaUpdateWrapper updateGridWrapper = new LambdaUpdateWrapper<>(); - updateGridWrapper.eq(CustomerGridEntity::getPid,formDTO.getAgencyId()) + updateGridWrapper.eq(CustomerGridEntity::getPid, formDTO.getAgencyId()) .set(CustomerGridEntity::getAreaCode, formDTO.getAreaCode()) - .set(CustomerGridEntity::getUpdatedBy,formDTO.getUserId()) - .set(CustomerGridEntity::getUpdatedTime,new Date()); - int subGridRows=customerGridDao.update(null,updateGridWrapper); - log.info(String.format("更新了%s个直属网格的area_code",subGridRows)); + .set(CustomerGridEntity::getUpdatedBy, formDTO.getUserId()) + .set(CustomerGridEntity::getUpdatedTime, new Date()); + int subGridRows = customerGridDao.update(null, updateGridWrapper); + log.info(String.format("更新了%s个直属网格的area_code", subGridRows)); // 2、更新直属部门的area_code LambdaUpdateWrapper updateDeptWrapper = new LambdaUpdateWrapper<>(); - updateDeptWrapper.eq(CustomerDepartmentEntity::getAgencyId,formDTO.getAgencyId()) + updateDeptWrapper.eq(CustomerDepartmentEntity::getAgencyId, formDTO.getAgencyId()) .set(CustomerDepartmentEntity::getAreaCode, formDTO.getAreaCode()) - .set(CustomerDepartmentEntity::getUpdatedBy,formDTO.getUserId()) - .set(CustomerDepartmentEntity::getUpdatedTime,new Date()); - int gridRows=customerDepartmentDao.update(null,updateDeptWrapper); - log.info(String.format("更新了%s个直属部门的area_code",gridRows)); + .set(CustomerDepartmentEntity::getUpdatedBy, formDTO.getUserId()) + .set(CustomerDepartmentEntity::getUpdatedTime, new Date()); + int gridRows = customerDepartmentDao.update(null, updateDeptWrapper); + log.info(String.format("更新了%s个直属部门的area_code", gridRows)); // 3、更新下级组织的parent_area_code LambdaUpdateWrapper updateAgencyWrapper = new LambdaUpdateWrapper<>(); - updateAgencyWrapper.eq(CustomerAgencyEntity::getPid,formDTO.getAgencyId()) + updateAgencyWrapper.eq(CustomerAgencyEntity::getPid, formDTO.getAgencyId()) .set(CustomerAgencyEntity::getParentAreaCode, formDTO.getAreaCode()) - .set(CustomerAgencyEntity::getUpdatedBy,formDTO.getUserId()) - .set(CustomerAgencyEntity::getUpdatedTime,new Date()); + .set(CustomerAgencyEntity::getUpdatedBy, formDTO.getUserId()) + .set(CustomerAgencyEntity::getUpdatedTime, new Date()); Integer rows = customerAgencyDao.update(null, updateAgencyWrapper); - log.info(String.format("更新了%s个下级组织的parent_area_code",rows)); + log.info(String.format("更新了%s个下级组织的parent_area_code", rows)); } /** - * * @param formDTO 编辑组织入参 - * @param parent 当前编辑组织的上级组织 + * @param parent 当前编辑组织的上级组织 * @return 返回组织区划编码 */ private String getAgencyNewAreaCode(EditAgencyFormDTO formDTO, CustomerAgencyEntity parent) { - String newAreaCode=""; + String newAreaCode = ""; if (!"other".equals(formDTO.getAreaCode())) { //校验除了当前组织外,areaCode是否被使用过 List agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(formDTO.getAreaCode(), formDTO.getAgencyId()); @@ -295,7 +296,7 @@ public class AgencyServiceImpl implements AgencyService { //已经被占用,提示 throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); } - newAreaCode=formDTO.getAreaCode(); + newAreaCode = formDTO.getAreaCode(); } else { //如果选择的是other,需要自定义一个编码 AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); @@ -310,16 +311,17 @@ public class AgencyServiceImpl implements AgencyService { throw new RenException("自定义area_code异常" + addAreaCodeResult.getInternalMsg()); } } - newAreaCode=addAreaCodeResult.getData(); + newAreaCode = addAreaCodeResult.getData(); } return newAreaCode; } /** * 如果当前客户开启了areaCode,校验参数逼单 + * * @param formDTO */ - private void checkEditAgencyFormDTO(EditAgencyFormDTO formDTO,CustomerAgencyEntity originalEntity) { + private void checkEditAgencyFormDTO(EditAgencyFormDTO formDTO, CustomerAgencyEntity originalEntity) { //根组织不允许修改 if (StringUtils.isNotBlank(originalEntity.getPid()) && !NumConstant.ZERO_STR.equals(originalEntity.getPid())) { //03.23:平阴线上版本与产品主线版本差距太大,平阴的修改组织只能修改组织名称。 @@ -364,14 +366,14 @@ public class AgencyServiceImpl implements AgencyService { return result; } //3:组织下有网格,不允许删除 - int gridCount = customerGridDao.selectGridCountByAgencyId(formDTO.getAgencyId()); + int gridCount = customerGridDao.selectGridCountByAgencyId(formDTO.getAgencyId()); if (gridCount > NumConstant.ZERO) { result.setCode(EpmetErrorCode.NOT_DEL_AGENCY_GRID.getCode()); result.setMsg(EpmetErrorCode.NOT_DEL_AGENCY_GRID.getMsg()); return result; } //4:删除当前机关组织(逻辑删) - if (customerAgencyDao.delByAgencyId(formDTO.getAgencyId(),loginUserUtil.getLoginUserId()) < NumConstant.ONE) { + if (customerAgencyDao.delByAgencyId(formDTO.getAgencyId(), loginUserUtil.getLoginUserId()) < NumConstant.ONE) { log.error(CustomerAgencyConstant.DEL_EXCEPTION); throw new RenException(CustomerAgencyConstant.DEL_EXCEPTION); } @@ -403,24 +405,24 @@ public class AgencyServiceImpl implements AgencyService { agencysResultDTO.setMobile(entity.getMobile()); agencysResultDTO.setAreaCodeSwitch(customerOrgParameterService.getAreaCodeSwitch(entity.getCustomerId())); agencysResultDTO.setAreaName(StrConstant.EPMETY_STR); - agencysResultDTO.setAreaCode(StringUtils.isNotBlank(entity.getAreaCode())?entity.getAreaCode():StrConstant.EPMETY_STR); + agencysResultDTO.setAreaCode(StringUtils.isNotBlank(entity.getAreaCode()) ? entity.getAreaCode() : StrConstant.EPMETY_STR); //查询组织区划的名称 if (null != entity && StringUtils.isNotBlank(entity.getAreaCode())) { switch (entity.getLevel()) { case CustomerAgencyConstant.PROVINCE_LEVEL: - agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getProvince()) ? entity.getProvince():entity.getOrganizationName()); + agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getProvince()) ? entity.getProvince() : entity.getOrganizationName()); break; case CustomerAgencyConstant.CITY_LEVEL: - agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getCity()) ? entity.getCity():entity.getOrganizationName()); + agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getCity()) ? entity.getCity() : entity.getOrganizationName()); break; case CustomerAgencyConstant.DISTRICT: - agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getDistrict()) ? entity.getDistrict():entity.getOrganizationName()); + agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getDistrict()) ? entity.getDistrict() : entity.getOrganizationName()); break; case CustomerAgencyConstant.STREET_LEVEL: - agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getStreet()) ? entity.getStreet():entity.getOrganizationName()); + agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getStreet()) ? entity.getStreet() : entity.getOrganizationName()); break; case CustomerAgencyConstant.COMMUNITY_LEVEL: - agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getCommunity()) ? entity.getCommunity():entity.getOrganizationName()); + agencysResultDTO.setAreaName(StringUtils.isNotBlank(entity.getCommunity()) ? entity.getCommunity() : entity.getOrganizationName()); break; default: agencysResultDTO.setAreaName(StrConstant.EPMETY_STR); @@ -504,7 +506,7 @@ public class AgencyServiceImpl implements AgencyService { } customerAgencyRedis.set(agencyId, agencyInfoCache); } - CustomerAgencyDTO customerAgencyDTO=ConvertUtils.sourceToTarget(agencyInfoCache,CustomerAgencyDTO.class); + CustomerAgencyDTO customerAgencyDTO = ConvertUtils.sourceToTarget(agencyInfoCache, CustomerAgencyDTO.class); return customerAgencyDTO; } @@ -547,7 +549,7 @@ public class AgencyServiceImpl implements AgencyService { @Override public CustomerAgencyDTO getCustomerRootAgency(String customerId) { - CustomerAgencyDTO root=customerAgencyDao.getCustomerRootAgency(customerId); + CustomerAgencyDTO root = customerAgencyDao.getCustomerRootAgency(customerId); if (null != root) { root.setAreaCodeSwitch(customerOrgParameterService.getAreaCodeSwitch(customerId)); } @@ -652,17 +654,17 @@ public class AgencyServiceImpl implements AgencyService { } AddAgencyResultDTO resultDTO = new AddAgencyResultDTO(); resultDTO.setAreaCodeSwitch(formDTO.getAreaCodeSwitch()); - CustomerAgencyEntity insertEntity=this.constructInsertEntity(formDTO,parent); + CustomerAgencyEntity insertEntity = this.constructInsertEntity(formDTO, parent); //判断areaCodeSwitch:open: 选择地区编码必填;closed: 无需选择地区编码 if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { //校验areaCode是否被使用过 if (!"other".equals(formDTO.getAreaCode())) { - List agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(insertEntity.getAreaCode(),null); + List agencyIds = customerAgencyDao.selectAgencyIdsByAreaCode(insertEntity.getAreaCode(), null); if (CollectionUtils.isNotEmpty(agencyIds)) { //已经被占用,提示 throw new RenException(EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getCode(), EpmetErrorCode.AREA_CODE_ALREADY_EXISTS.getMsg()); } - }else{ + } else { //如果选择的是other,需要自定义一个编码 AddAreaCodeFormDTO addAreaCodeFormDTO = new AddAreaCodeFormDTO(); addAreaCodeFormDTO.setCurrentAreaLevel(formDTO.getLevel()); @@ -688,19 +690,19 @@ public class AgencyServiceImpl implements AgencyService { } /** - * @Description 【地图配置】删除 * @param formDTO + * @Description 【地图配置】删除 * @author zxc * @date 2021/10/25 9:30 上午 */ @Override public void mapDelArea(MapDelAreaFormDTO formDTO) { - customerAgencyDao.delMapArea(formDTO.getOrgId(),formDTO.getLevel()); + customerAgencyDao.delMapArea(formDTO.getOrgId(), formDTO.getLevel()); } /** - * @Description 【地图配置】新增 * @param formDTO + * @Description 【地图配置】新增 * @author zxc * @date 2021/10/25 9:58 上午 */ @@ -710,14 +712,14 @@ public class AgencyServiceImpl implements AgencyService { } /** + * @param formDTO + * @param tokenDto * @Description 【地图配置】组织查询 * 根据level查询去查询不同的表,类型,组织:agency,网格:grid,小区:neighborHood * 组织类型去查 customer_agency,看本级是不是 community,是,下级组织就是网格,查询customer_grid,不是,继续查customer_agency * 网格类型去查 查询customer_grid,下级去查 ic_neighbor_hood, * 当前组织没有经纬度的话,直接赋值根组织的经纬度, * 下级组织经纬度为空的话,直接赋值上级的经纬度 - * @param formDTO - * @param tokenDto * @author zxc * @date 2021/10/25 10:50 上午 */ @@ -725,38 +727,38 @@ public class AgencyServiceImpl implements AgencyService { public MapOrgResultDTO mapOrg(MapOrgFormDTO formDTO, TokenDto tokenDto) { MapOrgResultDTO result = new MapOrgResultDTO(); LambdaQueryWrapper qw = new LambdaQueryWrapper(); - qw.eq(CustomerAgencyEntity::getPid, NumConstant.ZERO_STR).eq(CustomerAgencyEntity::getDelFlag, NumConstant.ZERO_STR).eq(CustomerAgencyEntity::getCustomerId,tokenDto.getCustomerId()); + qw.eq(CustomerAgencyEntity::getPid, NumConstant.ZERO_STR).eq(CustomerAgencyEntity::getDelFlag, NumConstant.ZERO_STR).eq(CustomerAgencyEntity::getCustomerId, tokenDto.getCustomerId()); CustomerAgencyEntity customerAgencyEntity = customerAgencyDao.selectOne(qw); - if (StringUtils.isBlank(formDTO.getOrgId())){ + if (StringUtils.isBlank(formDTO.getOrgId())) { CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); - if (null == staffInfo){ + if (null == staffInfo) { return result; } formDTO.setOrgId(staffInfo.getAgencyId()); formDTO.setLevel(OrgInfoConstant.AGENCY); } - if (StringUtils.isNotBlank(customerAgencyEntity.getLatitude())){ + if (StringUtils.isNotBlank(customerAgencyEntity.getLatitude())) { result.setLatitude(new BigDecimal(customerAgencyEntity.getLatitude())); } - if (StringUtils.isNotBlank(customerAgencyEntity.getLongitude())){ + if (StringUtils.isNotBlank(customerAgencyEntity.getLongitude())) { result.setLongitude(new BigDecimal(customerAgencyEntity.getLongitude())); } - if (formDTO.getLevel().equals(OrgInfoConstant.AGENCY)){ + if (formDTO.getLevel().equals(OrgInfoConstant.AGENCY)) { CustomerAgencyEntity entity = customerAgencyDao.selectById(formDTO.getOrgId()); - result = ConvertUtils.sourceToTarget(entity,MapOrgResultDTO.class); + result = ConvertUtils.sourceToTarget(entity, MapOrgResultDTO.class); result.setName(entity.getOrganizationName()); result.setLevel(formDTO.getLevel()); result.setAgencyLevel(entity.getLevel()); //经纬度 如果本级没有则取根级组织的 根级没有就空着 - if (StringUtils.isNotBlank(entity.getLatitude())){ + if (StringUtils.isNotBlank(entity.getLatitude())) { result.setLatitude(new BigDecimal(entity.getLatitude())); } - if (StringUtils.isNotBlank(entity.getLongitude())){ + if (StringUtils.isNotBlank(entity.getLongitude())) { result.setLongitude(new BigDecimal(entity.getLongitude())); } - if (entity.getLevel().equals(OrgInfoConstant.COMMUNITY)){ + if (entity.getLevel().equals(OrgInfoConstant.COMMUNITY)) { List son = customerAgencyDao.selectSonOrg(formDTO.getOrgId(), OrgInfoConstant.GRID); - if (CollectionUtils.isNotEmpty(son)){ + if (CollectionUtils.isNotEmpty(son)) { MapOrgResultDTO finalResult = result; son.forEach(s -> { s.setLatitude(StringUtils.isBlank(s.getLatitudeOrigin()) ? finalResult.getLatitude() : new BigDecimal(s.getLatitudeOrigin())); @@ -764,15 +766,15 @@ public class AgencyServiceImpl implements AgencyService { }); } result.setChildren(CollectionUtils.isEmpty(son) ? new ArrayList<>() : son); - }else { + } else { List dtoList = new ArrayList<>(); List son = customerAgencyDao.selectSonOrg(formDTO.getOrgId(), OrgInfoConstant.AGENCY); - if (CollectionUtils.isNotEmpty(son)){ + if (CollectionUtils.isNotEmpty(son)) { dtoList.addAll(son); } // 直属网格 List directlySub = customerAgencyDao.selectSonOrg(formDTO.getOrgId(), OrgInfoConstant.GRID); - if (CollectionUtils.isNotEmpty(directlySub)){ + if (CollectionUtils.isNotEmpty(directlySub)) { dtoList.addAll(directlySub); } for (MapSonOrgResultDTO d : dtoList) { @@ -781,21 +783,21 @@ public class AgencyServiceImpl implements AgencyService { } result.setChildren(dtoList); } - }else if (formDTO.getLevel().equals(OrgInfoConstant.GRID)){ + } else if (formDTO.getLevel().equals(OrgInfoConstant.GRID)) { CustomerGridEntity entity = customerGridDao.selectById(formDTO.getOrgId()); - result = ConvertUtils.sourceToTarget(entity,MapOrgResultDTO.class); + result = ConvertUtils.sourceToTarget(entity, MapOrgResultDTO.class); result.setName(entity.getGridName()); result.setLevel(formDTO.getLevel()); result.setAgencyLevel(OrgInfoConstant.GRID); //经纬度 如果本级没有则取根级组织的 根级没有就空着 - if (StringUtils.isNotBlank(entity.getLatitude())){ + if (StringUtils.isNotBlank(entity.getLatitude())) { result.setLatitude(new BigDecimal(entity.getLatitude())); } - if (StringUtils.isNotBlank(entity.getLongitude())){ + if (StringUtils.isNotBlank(entity.getLongitude())) { result.setLongitude(new BigDecimal(entity.getLongitude())); } List son = customerAgencyDao.selectSonOrg(formDTO.getOrgId(), OrgInfoConstant.NEIGHBOR_HOOD); - if (CollectionUtils.isNotEmpty(son)){ + if (CollectionUtils.isNotEmpty(son)) { for (MapSonOrgResultDTO s : son) { s.setLatitude(StringUtils.isBlank(s.getLatitudeOrigin()) ? result.getLatitude() : new BigDecimal(s.getLatitudeOrigin())); s.setLongitude(StringUtils.isBlank(s.getLongitudeOrigin()) ? result.getLongitude() : new BigDecimal(s.getLongitudeOrigin())); @@ -807,35 +809,35 @@ public class AgencyServiceImpl implements AgencyService { } /** - * @Description 查询楼栋信息 * @param formDTO + * @Description 查询楼栋信息 * @author zxc * @date 2021/11/2 9:18 上午 */ @Override public List baseInfoFamilyBuilding(BaseInfoFamilyBuildingFormDTO formDTO) { List result = icBuildingDao.baseInfoFamilyBuilding(formDTO.getNeighborHoodId()); - if (CollectionUtils.isEmpty(result)){ + if (CollectionUtils.isEmpty(result)) { return new ArrayList<>(); } return result; } /** - * @Description 查询下级agencyId * @param orgId + * @Description 查询下级agencyId * @author zxc * @date 2021/12/9 4:42 下午 */ @Override - public List getSonAgencyId(String orgId,String type) { + public List getSonAgencyId(String orgId, String type) { List result = new ArrayList<>(); - if (type.equals("community")){ + if (type.equals("community")) { result = customerAgencyDao.getSonGridId(orgId); - }else { + } else { result = customerAgencyDao.getSonAgencyId(orgId); } - if (CollectionUtils.isNotEmpty(result)){ + if (CollectionUtils.isNotEmpty(result)) { return result; } return new ArrayList<>(); @@ -843,6 +845,7 @@ public class AgencyServiceImpl implements AgencyService { /** * Desc: 查询工作人员所属组织下的所有社区 + * * @param tokenDto * @author zxc * @date 2022/3/21 15:13 @@ -850,20 +853,36 @@ public class AgencyServiceImpl implements AgencyService { @Override public List getCommunityList(TokenDto tokenDto) { CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); - if (null == staffInfo){ - throw new EpmetException("未查询到工作人员信息"+staffInfo.getStaffId()); + if (null == staffInfo) { + throw new EpmetException("未查询到工作人员信息" + staffInfo.getStaffId()); } String agencyId = staffInfo.getAgencyId(); AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(agencyId); - if (null == agencyInfo){ - throw new EpmetException("查询组织信息失败"+agencyInfo); + if (null == agencyInfo) { + throw new EpmetException("查询组织信息失败" + agencyInfo); } - if (agencyInfo.getLevel().equals(CustomerAgencyConstant.COMMUNITY_LEVEL)){ + if (agencyInfo.getLevel().equals(CustomerAgencyConstant.COMMUNITY_LEVEL)) { return new ArrayList<>(); } return customerAgencyDao.getCommunityList(tokenDto.getCustomerId(), agencyId); } + /** + * 通讯录树 + * + * @param name + * @param customerId + * @return java.util.List + * @author LZN + * @date 2022/5/16 10:45 + */ + @Override + public List getAddressTree(String name, String customerId) { + List list = customerAgencyDao.getAddressTree(name, customerId); + System.out.println(list); + return NodeTreeUtils.build(list); + } + private CustomerAgencyEntity constructInsertEntity(AddAgencyV2FormDTO formDTO, CustomerAgencyDTO parent) { CustomerAgencyEntity insertEntity = ConvertUtils.sourceToTarget(formDTO, CustomerAgencyEntity.class); insertEntity.setOrganizationName(formDTO.getAgencyName()); @@ -879,8 +898,7 @@ public class AgencyServiceImpl implements AgencyService { insertEntity.setPids(parent.getPids().concat(StrConstant.COLON).concat(parent.getId())); insertEntity.setAllParentName(parent.getAllParentName().concat(StrConstant.HYPHEN).concat(parent.getOrganizationName())); } - switch(parent.getLevel()) - { + switch (parent.getLevel()) { case CustomerAgencyConstant.PROVINCE_LEVEL: insertEntity.setLevel(CustomerAgencyConstant.CITY_LEVEL); insertEntity.setProvince(parent.getProvince()); @@ -908,7 +926,7 @@ public class AgencyServiceImpl implements AgencyService { insertEntity.setCommunity(formDTO.getAreaName()); break; default: - log.info("parent.getLevel()="+parent.getLevel()); + log.info("parent.getLevel()=" + parent.getLevel()); break; } return insertEntity; diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml index d8314ee8b5..fc0cd6aaa9 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerAgencyDao.xml @@ -744,6 +744,61 @@ AND CUSTOMER_ID = #{customerId} AND CONCAT(PIDS,':',ID) LIKE CONCAT('%',#{agencyId},'%') + UPDATE customer_agency From b2b62e09258143c01d34e67308d0f3ac7862839c Mon Sep 17 00:00:00 2001 From: HAHA Date: Tue, 17 May 2022 10:02:00 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/service/impl/AgencyServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index dd9e8009eb..e108376cbe 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -879,7 +879,6 @@ public class AgencyServiceImpl implements AgencyService { @Override public List getAddressTree(String name, String customerId) { List list = customerAgencyDao.getAddressTree(name, customerId); - System.out.println(list); return NodeTreeUtils.build(list); } From 305f1c8a1f510e41945ab6616dfac21b53435f53 Mon Sep 17 00:00:00 2001 From: YUJT Date: Thu, 2 Jun 2022 10:55:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/CustomerStaffServiceImpl.java | 1392 +++++++++-------- 1 file changed, 697 insertions(+), 695 deletions(-) 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 01283f45c4..af84965ac4 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 @@ -82,550 +82,550 @@ import java.util.stream.Collectors; @Slf4j @Service public class CustomerStaffServiceImpl extends BaseServiceImpl implements CustomerStaffService { - private final Logger logger = LogManager.getLogger(getClass()); - @Autowired - private GovStaffRoleService govStaffRoleService; - @Autowired - private UserService userService; - @Autowired - private StaffRoleService staffRoleService; - @Autowired - private StaffRoleDao staffRoleDao; - @Autowired - private CpUserDetailRedis cpUserDetailRedis; - @Autowired - private AuthFeignClient authFeignClient; - @Autowired - private GovOrgOpenFeignClient govOrgOpenFeignClient; - @Autowired - private CustomerStaffDao customerStaffDao; - @Autowired - private GovStaffRoleDao govStaffRoleDao; + private final Logger logger = LogManager.getLogger(getClass()); + @Autowired + private GovStaffRoleService govStaffRoleService; + @Autowired + private UserService userService; + @Autowired + private StaffRoleService staffRoleService; + @Autowired + private StaffRoleDao staffRoleDao; + @Autowired + private CpUserDetailRedis cpUserDetailRedis; + @Autowired + private AuthFeignClient authFeignClient; + @Autowired + private GovOrgOpenFeignClient govOrgOpenFeignClient; + @Autowired + private CustomerStaffDao customerStaffDao; + @Autowired + private GovStaffRoleDao govStaffRoleDao; @Autowired private OperCrmOpenFeignClient operCrmOpenFeignClient; @Autowired private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; - @Override - public PageData page(Map params) { - IPage page = baseDao.selectPage( - getPage(params, FieldConstant.CREATED_TIME, false), - getWrapper(params) - ); - return getPageData(page, CustomerStaffDTO.class); - } - - @Override - public List list(Map params) { - List entityList = baseDao.selectList(getWrapper(params)); - - return ConvertUtils.sourceToTarget(entityList, CustomerStaffDTO.class); - } - - private QueryWrapper getWrapper(Map params) { - String id = (String) params.get(FieldConstant.ID_HUMP); - - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); - - return wrapper; - } - - @Override - public CustomerStaffDTO get(String id) { - CustomerStaffEntity entity = baseDao.selectById(id); - return ConvertUtils.sourceToTarget(entity, CustomerStaffDTO.class); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void save(CustomerStaffDTO dto) { - CustomerStaffEntity entity = ConvertUtils.sourceToTarget(dto, CustomerStaffEntity.class); - insert(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(CustomerStaffDTO dto) { - CustomerStaffEntity entity = ConvertUtils.sourceToTarget(dto, CustomerStaffEntity.class); - updateById(entity); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(String[] ids) { - // 逻辑删除(@TableLogic 注解) - baseDao.deleteBatchIds(Arrays.asList(ids)); - } - - @Override - public Result> getCustsomerStaffByPhone(String mobile) { - //判断用户是否存在 - List customerStaffDTOList = baseDao.selectListCustomerStaffDTO(mobile); - if (null == customerStaffDTOList || customerStaffDTOList.size() == 0) { - logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],code[%s],msg[%s]", mobile, EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); - return new Result().error(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); - } - return new Result>().ok(customerStaffDTOList); - } + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, CustomerStaffDTO.class); + } + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); - @Override - public Result getCustomerStaffInfo(CustomerStaffFormDTO formDTO) { - CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(formDTO); - if (null == customerStaffDTO) { - logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],code[%s],msg[%s]", formDTO.getMobile(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); - return new Result().error(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); - } - //判断用户是否已被禁用 - if (null != customerStaffDTO && UserConstant.DISABLED.equals(customerStaffDTO.getEnableFlag())) { - logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getMobile(), formDTO.getCustomerId(), EpmetErrorCode.GOV_STAFF_DISABLED.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg())); - return new Result().error(EpmetErrorCode.GOV_STAFF_DISABLED.getCode()); - } - return new Result().ok(customerStaffDTO); - } - - @Override - public Result getCustomerStaffInfoByUserId(CustomerStaffDTO formDTO) { - CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfoByUserId(formDTO); - return new Result().ok(customerStaffDTO); - } - - @Override - public Result> selectStaffGridListByUserId(List customerStaffGridDTOS) { - if (CollectionUtils.isEmpty(customerStaffGridDTOS)){ - return new Result>().ok(new ArrayList<>()); - } - List gridManager = staffRoleService.listStaffsInRole(UserRoleConstant.GRID_MANAGER, customerStaffGridDTOS.get(0).getPid(), DataScope.getDefault()); - List staffGridListDTOS = baseDao.selectStaffGridListByUserId(customerStaffGridDTOS); - for (GovStaffRoleResultDTO govStaffRoleResultDTO : gridManager) { - if (govStaffRoleResultDTO.getRoleKey().equals(UserRoleConstant.GRID_MANAGER)){ - for (StaffGridListDTO staffGridListDTO : staffGridListDTOS) { - if (staffGridListDTO.getStaffId().equals(govStaffRoleResultDTO.getStaffId())){ - staffGridListDTO.setRoleName(govStaffRoleResultDTO.getRoleName()); - } - } - } - } - return new Result>().ok(staffGridListDTOS); - } - - @Override - public Result> 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<>(); - } - if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) { - Map> map = govStaffRoleService.getStaffRoles(fromDTO.getStaffList(), fromDTO.getAgencyId()); - list.forEach(item -> { - item.setRoles(map.get(item.getStaffId())); - }); - } - return new Result>().ok(list); - } + return ConvertUtils.sourceToTarget(entityList, CustomerStaffDTO.class); + } - @Override - public Result> addStaffInit(StaffInfoFromDTO fromDTO) { - GovStaffRoleDTO govStaffRoleDTO = new GovStaffRoleDTO(); - govStaffRoleDTO.setCustomerId(fromDTO.getCustomerId()); - List roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); - if (null == roleList || roleList.size() == 0) { - return new Result>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); - } - List staffRoleList = roleList.stream() - .filter(p -> !RoleKeyConstants.ROLE_KEY_ROOT_MANAGER.equals(p.getRoleKey())) - .map(p -> { - RoleInfoResultDTO staffRoleResultDTO = new RoleInfoResultDTO(); - staffRoleResultDTO.setRoleId(p.getId()); - staffRoleResultDTO.setRoleName(p.getRoleName()); - staffRoleResultDTO.setFullTimeOnly(p.getFullTimeOnly()); - staffRoleResultDTO.setDescription(p.getDescription()); - return staffRoleResultDTO; - }).collect(Collectors.toList()); - return new Result>().ok(staffRoleList); - } - - @Override - public Result editStaffInit(StaffInfoFromDTO fromDTO) { - StaffInitResultDTO resultDTO = new StaffInitResultDTO(); - //获取工作人员信息 - CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfo(fromDTO); - if (null == customerStaffDTO) { - log.warn("工作人员不存在"); - } - resultDTO.setStaffId(customerStaffDTO.getUserId()); - resultDTO.setName(customerStaffDTO.getRealName()); - resultDTO.setGender(customerStaffDTO.getGender()); - resultDTO.setMobile(customerStaffDTO.getMobile()); - resultDTO.setWorkType(customerStaffDTO.getWorkType()); - //获取角色列表 - GovStaffRoleDTO govStaffRoleDTO = new GovStaffRoleDTO(); - govStaffRoleDTO.setCustomerId(fromDTO.getCustomerId()); - List roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); - //获取工作人员角色 - List staffRoles = govStaffRoleService.listRolesByStaffId(fromDTO.getStaffId(), fromDTO.getAgencyId()); - List staffRoleList = roleList - .stream() - .filter(p -> !RoleKeyConstants.ROLE_KEY_ROOT_MANAGER.equals(p.getRoleKey())) - .map(p -> { - StaffRoleResultDTO staffRoleResultDTO = new StaffRoleResultDTO(); - staffRoleResultDTO.setRoleId(p.getId()); - staffRoleResultDTO.setRoleName(p.getRoleName()); - staffRoleResultDTO.setFullTimeOnly(p.getFullTimeOnly()); - staffRoleResultDTO.setDescription(p.getDescription()); - staffRoleResultDTO.setSelected(false); - return staffRoleResultDTO; - }).collect(Collectors.toList()); - - staffRoleList.forEach(role -> staffRoles.forEach(staffRole -> { - if (role.getRoleId().equals(staffRole.getId())) { - role.setSelected(true); - } - })); - resultDTO.setRoleList(staffRoleList); - - return new Result().ok(resultDTO); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Result 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()); - userEntity.setFromClient(fromDTO.getClient()); - userEntity.setCustomerId(fromDTO.getCustomerId()); - userService.insert(userEntity); - //Customer_Staff表插入数据 - CustomerStaffEntity staffEntity = new CustomerStaffEntity(); - staffEntity.setCustomerId(fromDTO.getCustomerId()); - staffEntity.setUserId(userEntity.getId()); - staffEntity.setRealName(fromDTO.getName()); - staffEntity.setMobile(fromDTO.getMobile()); - staffEntity.setActiveFlag(CustomerStaffConstant.INACTIVE); - staffEntity.setGender(fromDTO.getGender()); - staffEntity.setWorkType(fromDTO.getWorkType()); - staffEntity.setEnableFlag(CustomerStaffConstant.ENABLE); - baseDao.insert(staffEntity); - - //工作人员角色关联表 - fromDTO.getRoles().forEach(role -> { - StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); - staffRoleEntity.setStaffId(userEntity.getId()); - staffRoleEntity.setRoleId(role); - staffRoleEntity.setOrgId(fromDTO.getAgencyId()); - staffRoleEntity.setCustomerId(fromDTO.getCustomerId()); - staffRoleService.insert(staffRoleEntity); - }); - - // 角色放缓存 - CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); - List roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); - dto.setCustomerId(fromDTO.getCustomerId()); - dto.setStaffId(userEntity.getId()); - dto.setAgencyId(fromDTO.getAgencyId()); - Map m = new HashMap(16); - roleKeyValue.forEach(r -> { - m.put(r.getRoleKey(),r.getRoleName()); - }); - dto.setRoles(m); - CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); - - return new Result().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 (null != customerStaffDTO && !fromDTO.getStaffId().equals(customerStaffDTO.getUserId())){ - return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); - } + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); - CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); - //Customer_Staff表插入数据 - CustomerStaffEntity staffEntity = new CustomerStaffEntity(); - staffEntity.setId(customerStaffEntity.getId()); - staffEntity.setRealName(fromDTO.getName()); - staffEntity.setMobile(fromDTO.getMobile()); - staffEntity.setGender(fromDTO.getGender()); - staffEntity.setWorkType(fromDTO.getWorkType()); - baseDao.updateById(staffEntity); - - //清空权限关联 - StaffRoleDTO staffRoleDTO = new StaffRoleDTO(); - staffRoleDTO.setStaffId(fromDTO.getStaffId()); - staffRoleDTO.setOrgId(fromDTO.getAgencyId()); - staffRoleService.clearStaffRoles(staffRoleDTO); - //重新添加角色关联 - fromDTO.getRoles().forEach(role -> { - StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); - staffRoleEntity.setStaffId(fromDTO.getStaffId()); - staffRoleEntity.setRoleId(role); - staffRoleEntity.setOrgId(fromDTO.getAgencyId()); - staffRoleService.insert(staffRoleEntity); - }); - - // 重新查询用户的角色列表(可以取到前端没有传过来的角色,例如根管理员) - List staffRoleEntytiesByStaffIdAndOrgId = staffRoleService.getStaffRoleEntytiesByStaffIdAndOrgId(fromDTO.getAgencyId(), fromDTO.getStaffId()); - List roleIds = new ArrayList<>(); - if (!CollectionUtils.isEmpty(staffRoleEntytiesByStaffIdAndOrgId)) { - roleIds = staffRoleEntytiesByStaffIdAndOrgId.stream().map(sr -> sr.getRoleId()).collect(Collectors.toList()); - } + return wrapper; + } - // redis缓存角色修改 - UpdateCachedRolesFormDTO updateRolesForm = new UpdateCachedRolesFormDTO(); - updateRolesForm.setOrgId(fromDTO.getAgencyId()); - updateRolesForm.setStaffId(fromDTO.getStaffId()); - updateRolesForm.setRoleIds(roleIds); - try { - Result result = authFeignClient.updateCachedRoles(updateRolesForm); - if (!result.success()) { - logger.error("修改用户信息:修改用户已缓存的角色列表失败:{}", result.getInternalMsg()); - } - logger.info("修改用户信息:修改用户已缓存的角色列表成功"); - } catch (Exception e) { - log.error("method exception", e); - logger.error("修改用户信息:修改用户已缓存的角色列表异常:{}", ExceptionUtils.getErrorStackTrace(e)); - } + @Override + public CustomerStaffDTO get(String id) { + CustomerStaffEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, CustomerStaffDTO.class); + } - // 角色放缓存 - CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); - List roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); - dto.setCustomerId(fromDTO.getCustomerId()); - dto.setStaffId(fromDTO.getStaffId()); - dto.setAgencyId(fromDTO.getAgencyId()); - Map m = new HashMap(16); - roleKeyValue.forEach(r -> { - m.put(r.getRoleKey(),r.getRoleName()); - }); - dto.setRoles(m); - CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); - - return new Result(); - } - - @Override - public Result getStaffDetail(StaffInfoFromDTO fromDTO) { - StaffDetailResultDTO resultDTO = new StaffDetailResultDTO(); - //获取工作人员信息 - CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfo(fromDTO); - resultDTO.setStaffId(customerStaffDTO.getUserId()); - resultDTO.setName(customerStaffDTO.getRealName()); - resultDTO.setMobile(customerStaffDTO.getMobile()); - resultDTO.setHeadPhoto(customerStaffDTO.getHeadPhoto()); - resultDTO.setGender(customerStaffDTO.getGender()); - resultDTO.setActiveFlag(customerStaffDTO.getActiveFlag()); - resultDTO.setActiveTime(customerStaffDTO.getActiveTime()); - resultDTO.setEnableFlag(customerStaffDTO.getEnableFlag()); - - //获取工作人员角色 - List staffRoles = govStaffRoleService.listRolesByStaffId(fromDTO.getStaffId(), fromDTO.getAgencyId()); - List roles = staffRoles.stream().map(GovStaffRoleEntity::getRoleName).collect(Collectors.toList()); - resultDTO.setRoles(roles); - return new Result().ok(resultDTO); - } - - @Override - public Result disabledStaff(StaffInfoFromDTO fromDTO) { - CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); - CustomerStaffEntity staffEntity = new CustomerStaffEntity(); - staffEntity.setId(customerStaffEntity.getId()); - staffEntity.setEnableFlag(CustomerStaffConstant.DISABLED); - baseDao.updateById(staffEntity); - //2021.8.24 sun 人员禁用时删除工作人员的缓存信息 - CustomerStaffRedis.delStaffInfoFormCache(fromDTO.getCustomerId(), fromDTO.getStaffId()); - return new Result(); - } - - /** - * 根据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) { - //1:根据userId集合查询人员基本信息 - List staffList = baseDao.selectDepartmentStaffList(formDTO); - //2:根据组织Id查询部门下是领导角色的用户 - List staffRoleDTOS = staffRoleService.listStaffsInRole(UserRoleConstant.DEPT_LEADER, formDTO.getAgencyId(), DataScope.getDefault()); - staffRoleDTOS.forEach(roleDto -> { - staffList.stream().filter(staffDto -> - roleDto.getStaffId().equals(staffDto.getStaffId())).findAny().ifPresent(result -> - result.setRoleName(roleDto.getRoleName())); - }); - return new Result>().ok(staffList); - } - - /** - * @return Result> - * @Description 通过userId列表查询未被禁用的用户信息 - * @Param CommonUserIdListFormDTO :: getUserIdList - * @Author wangc - * @Date 2020.04.24 15:44 - **/ - @Override - public Result> getEnableStaffMsgList(CommonUserIdListFormDTO userIdList) { - if (userIdList.getUserIdList().size() <= NumConstant.ZERO) { - return new Result>().ok(new ArrayList<>()); - } + @Override + @Transactional(rollbackFor = Exception.class) + public void save(CustomerStaffDTO dto) { + CustomerStaffEntity entity = ConvertUtils.sourceToTarget(dto, CustomerStaffEntity.class); + insert(entity); + } - return new Result>().ok(baseDao.selectEnableStaffMsg(userIdList.getUserIdList(), userIdList.getCustomerId())); - } - - /** - * @param staffIdList - * @return - * @Author sun - * @Description 根据staffId集合查询工作人员基础信息 - **/ - @Override - public CustomerStaffListResultDTO getCustomerStaffList(List staffIdList) { - //1:批量查询人员基本信息 - List staffList = baseDao.selectStaffByIds(staffIdList); - //2:批量查询人员拥有的所有角色信息 - List roleList = staffRoleDao.selectStaffRoleList(staffIdList); - CustomerStaffListResultDTO list = new CustomerStaffListResultDTO(); - list.setStaffList(staffList); - list.setRoleList(roleList); - return list; - } - - /** - * @param staffId - * @return - * @Author sun - * @Description 根据staffId查询工作人员基本信息 - **/ - @Override - public CustomerStaffDTO getCustomerStaff(String staffId) { - return baseDao.selectByStaffId(staffId); - } - - /** - * @param staffResetPwFormDTO - * @return void - * @author yinzuomei - * @description 工作端,修改工作人员密码 - * @Date 2020/7/1 10:41 - **/ - @Override - public void resetStaffPassword(StaffResetPwFormDTO staffResetPwFormDTO) { - CustomerStaffDTO customerStaffDTO=this.getCustomerStaff(staffResetPwFormDTO.getStaffId()); - if(null==customerStaffDTO){ - return; - } - //密码加密 - String password = PasswordUtils.encode(staffResetPwFormDTO.getNewPassword()); - logger.info(String.format("密码%s加密后为%s",staffResetPwFormDTO.getNewPassword(),password)); - customerStaffDTO.setPassword(password); - this.update(customerStaffDTO); - } - - /** - * @Description 得到工组人员的头像、名称、所属机关名称 - * @param userId - * @return - * @author wangc - * @date 2020.07.27 14:45 - **/ - @Override - public StaffEtAgencyResultDTO getStaffMsg(IssueInitiatorFormDTO userId) { - StaffEtAgencyResultDTO result = new StaffEtAgencyResultDTO(); - CustomerStaffDTO staff = baseDao.selectByStaffId(userId.getUserId()); - if(null != staff){ - Result agencyResult = govOrgOpenFeignClient.getAgencyByStaff(userId.getUserId()); - if(agencyResult.success() && null != agencyResult.getData()){ - result = ConvertUtils.sourceToTarget(agencyResult.getData(),StaffEtAgencyResultDTO.class); - result.setAgencyId(agencyResult.getData().getId()); - result.setNickname(new StringBuilder(agencyResult.getData().getOrganizationName()).append(ModuleConstant.DASH).append(staff.getRealName()).toString()); - } - } - return result; - } - - /** - * @param formDTO - * @return - * @Author sun - * @Description 根据客户ID、手机号查询政府端工作人员基本信息,校验用户是否存在 - **/ - @Override - public List getCustsomerStaffByIdAndPhone(ThirdCustomerStaffFormDTO formDTO) { - //根据客户Id和手机号查询工作人员信息 - List customerStaffDTOList = baseDao.selectStaff(formDTO); - if (null == customerStaffDTOList || customerStaffDTOList.size() < NumConstant.ONE) { - logger.warn(String.format("根据客户Id和手机号查询用户异常,客户Id:[%s],手机号:[%s],code[%s],msg[%s]", - formDTO.getCustomerId(), formDTO.getMobile(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), - EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); - throw new RenException(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); - } - return customerStaffDTOList; - } - - /** - * @Description 查询工作人员的信息 - * @param formDTO - * @author zxc - * @date 2020/8/13 1:45 下午 - */ - @Override - public List getStaffInfoList(UserIdsFormDTO formDTO) { - List userIds = formDTO.getUserIds(); - // 1. 根据userId查询人员基本信息 - List staffInfoList = new ArrayList<>(); - userIds.forEach(staffId->{ - CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), staffId); - if (staffInfo ==null){ - log.error("getStaffInfoList fail customerId:{}, staffId:{} not exist in db",formDTO.getCustomerId(), staffId); - return; - } - StaffSinGridResultDTO resultDTO = new StaffSinGridResultDTO(); - resultDTO.setStaffId(staffId); - resultDTO.setStaffName(staffInfo.getRealName()); - resultDTO.setHeadPhoto(staffInfo.getHeadPhoto()); - resultDTO.setGender(staffInfo.getGender()); - - List roleInfoList = new ArrayList<>(); - staffInfo.getRoleMap().forEach((key,value) ->{ - RoleResultDTO dto = new RoleResultDTO(); - dto.setRoleKey(key); - dto.setRoleName(value); - roleInfoList.add(dto); - }); - resultDTO.setRoleList(roleInfoList); - staffInfoList.add(resultDTO); - }); + @Override + @Transactional(rollbackFor = Exception.class) + public void update(CustomerStaffDTO dto) { + CustomerStaffEntity entity = ConvertUtils.sourceToTarget(dto, CustomerStaffEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result> getCustsomerStaffByPhone(String mobile) { + //判断用户是否存在 + List customerStaffDTOList = baseDao.selectListCustomerStaffDTO(mobile); + if (null == customerStaffDTOList || customerStaffDTOList.size() == 0) { + logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],code[%s],msg[%s]", mobile, EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); + return new Result().error(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); + } + return new Result>().ok(customerStaffDTOList); + } + + + @Override + public Result getCustomerStaffInfo(CustomerStaffFormDTO formDTO) { + CustomerStaffDTO customerStaffDTO = baseDao.selectListCustomerStaffInfo(formDTO); + if (null == customerStaffDTO) { + logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],code[%s],msg[%s]", formDTO.getMobile(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); + return new Result().error(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); + } + //判断用户是否已被禁用 + if (null != customerStaffDTO && UserConstant.DISABLED.equals(customerStaffDTO.getEnableFlag())) { + logger.warn(String.format("根据手机号查询用户异常,手机号:[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getMobile(), formDTO.getCustomerId(), EpmetErrorCode.GOV_STAFF_DISABLED.getCode(), EpmetErrorCode.GOV_STAFF_DISABLED.getMsg())); + return new Result().error(EpmetErrorCode.GOV_STAFF_DISABLED.getCode()); + } + return new Result().ok(customerStaffDTO); + } + + @Override + public Result getCustomerStaffInfoByUserId(CustomerStaffDTO formDTO) { + CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfoByUserId(formDTO); + return new Result().ok(customerStaffDTO); + } + + @Override + public Result> selectStaffGridListByUserId(List customerStaffGridDTOS) { + if (CollectionUtils.isEmpty(customerStaffGridDTOS)) { + return new Result>().ok(new ArrayList<>()); + } + List gridManager = staffRoleService.listStaffsInRole(UserRoleConstant.GRID_MANAGER, customerStaffGridDTOS.get(0).getPid(), DataScope.getDefault()); + List staffGridListDTOS = baseDao.selectStaffGridListByUserId(customerStaffGridDTOS); + for (GovStaffRoleResultDTO govStaffRoleResultDTO : gridManager) { + if (govStaffRoleResultDTO.getRoleKey().equals(UserRoleConstant.GRID_MANAGER)) { + for (StaffGridListDTO staffGridListDTO : staffGridListDTOS) { + if (staffGridListDTO.getStaffId().equals(govStaffRoleResultDTO.getStaffId())) { + staffGridListDTO.setRoleName(govStaffRoleResultDTO.getRoleName()); + } + } + } + } + return new Result>().ok(staffGridListDTOS); + } + + @Override + public Result> 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<>(); + } + if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) { + Map> map = govStaffRoleService.getStaffRoles(fromDTO.getStaffList(), fromDTO.getAgencyId()); + list.forEach(item -> { + item.setRoles(map.get(item.getStaffId())); + }); + } + return new Result>().ok(list); + } + + @Override + public Result> addStaffInit(StaffInfoFromDTO fromDTO) { + GovStaffRoleDTO govStaffRoleDTO = new GovStaffRoleDTO(); + govStaffRoleDTO.setCustomerId(fromDTO.getCustomerId()); + List roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); + + if (null == roleList || roleList.size() == 0) { + return new Result>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); + } + List staffRoleList = roleList.stream() + .filter(p -> !RoleKeyConstants.ROLE_KEY_ROOT_MANAGER.equals(p.getRoleKey())) + .map(p -> { + RoleInfoResultDTO staffRoleResultDTO = new RoleInfoResultDTO(); + staffRoleResultDTO.setRoleId(p.getId()); + staffRoleResultDTO.setRoleName(p.getRoleName()); + staffRoleResultDTO.setFullTimeOnly(p.getFullTimeOnly()); + staffRoleResultDTO.setDescription(p.getDescription()); + return staffRoleResultDTO; + }).collect(Collectors.toList()); + return new Result>().ok(staffRoleList); + } + + @Override + public Result editStaffInit(StaffInfoFromDTO fromDTO) { + StaffInitResultDTO resultDTO = new StaffInitResultDTO(); + //获取工作人员信息 + CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfo(fromDTO); + if (null == customerStaffDTO) { + log.warn("工作人员不存在"); + } + resultDTO.setStaffId(customerStaffDTO.getUserId()); + resultDTO.setName(customerStaffDTO.getRealName()); + resultDTO.setGender(customerStaffDTO.getGender()); + resultDTO.setMobile(customerStaffDTO.getMobile()); + resultDTO.setWorkType(customerStaffDTO.getWorkType()); + //获取角色列表 + GovStaffRoleDTO govStaffRoleDTO = new GovStaffRoleDTO(); + govStaffRoleDTO.setCustomerId(fromDTO.getCustomerId()); + List roleList = govStaffRoleService.getGovStaffRoleList(govStaffRoleDTO); + //获取工作人员角色 + List staffRoles = govStaffRoleService.listRolesByStaffId(fromDTO.getStaffId(), fromDTO.getAgencyId()); + List staffRoleList = roleList + .stream() + .filter(p -> !RoleKeyConstants.ROLE_KEY_ROOT_MANAGER.equals(p.getRoleKey())) + .map(p -> { + StaffRoleResultDTO staffRoleResultDTO = new StaffRoleResultDTO(); + staffRoleResultDTO.setRoleId(p.getId()); + staffRoleResultDTO.setRoleName(p.getRoleName()); + staffRoleResultDTO.setFullTimeOnly(p.getFullTimeOnly()); + staffRoleResultDTO.setDescription(p.getDescription()); + staffRoleResultDTO.setSelected(false); + return staffRoleResultDTO; + }).collect(Collectors.toList()); + + staffRoleList.forEach(role -> staffRoles.forEach(staffRole -> { + if (role.getRoleId().equals(staffRole.getId())) { + role.setSelected(true); + } + })); + resultDTO.setRoleList(staffRoleList); + + return new Result().ok(resultDTO); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result 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()); + userEntity.setFromClient(fromDTO.getClient()); + userEntity.setCustomerId(fromDTO.getCustomerId()); + userService.insert(userEntity); + //Customer_Staff表插入数据 + CustomerStaffEntity staffEntity = new CustomerStaffEntity(); + staffEntity.setCustomerId(fromDTO.getCustomerId()); + staffEntity.setUserId(userEntity.getId()); + staffEntity.setRealName(fromDTO.getName()); + staffEntity.setMobile(fromDTO.getMobile()); + staffEntity.setActiveFlag(CustomerStaffConstant.INACTIVE); + staffEntity.setGender(fromDTO.getGender()); + staffEntity.setWorkType(fromDTO.getWorkType()); + staffEntity.setEnableFlag(CustomerStaffConstant.ENABLE); + baseDao.insert(staffEntity); + + //工作人员角色关联表 + fromDTO.getRoles().forEach(role -> { + StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); + staffRoleEntity.setStaffId(userEntity.getId()); + staffRoleEntity.setRoleId(role); + staffRoleEntity.setOrgId(fromDTO.getAgencyId()); + staffRoleEntity.setCustomerId(fromDTO.getCustomerId()); + staffRoleService.insert(staffRoleEntity); + }); + + // 角色放缓存 + CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); + List roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); + dto.setCustomerId(fromDTO.getCustomerId()); + dto.setStaffId(userEntity.getId()); + dto.setAgencyId(fromDTO.getAgencyId()); + Map m = new HashMap(16); + roleKeyValue.forEach(r -> { + m.put(r.getRoleKey(), r.getRoleName()); + }); + dto.setRoles(m); + CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); + + return new Result().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 (null != customerStaffDTO && !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(); + staffEntity.setId(customerStaffEntity.getId()); + staffEntity.setRealName(fromDTO.getName()); + staffEntity.setMobile(fromDTO.getMobile()); + staffEntity.setGender(fromDTO.getGender()); + staffEntity.setWorkType(fromDTO.getWorkType()); + baseDao.updateById(staffEntity); + + //清空权限关联 + StaffRoleDTO staffRoleDTO = new StaffRoleDTO(); + staffRoleDTO.setStaffId(fromDTO.getStaffId()); + staffRoleDTO.setOrgId(fromDTO.getAgencyId()); + staffRoleService.clearStaffRoles(staffRoleDTO); + //重新添加角色关联 + fromDTO.getRoles().forEach(role -> { + StaffRoleEntity staffRoleEntity = new StaffRoleEntity(); + staffRoleEntity.setStaffId(fromDTO.getStaffId()); + staffRoleEntity.setRoleId(role); + staffRoleEntity.setOrgId(fromDTO.getAgencyId()); + staffRoleService.insert(staffRoleEntity); + }); + + // 重新查询用户的角色列表(可以取到前端没有传过来的角色,例如根管理员) + List staffRoleEntytiesByStaffIdAndOrgId = staffRoleService.getStaffRoleEntytiesByStaffIdAndOrgId(fromDTO.getAgencyId(), fromDTO.getStaffId()); + List roleIds = new ArrayList<>(); + if (!CollectionUtils.isEmpty(staffRoleEntytiesByStaffIdAndOrgId)) { + roleIds = staffRoleEntytiesByStaffIdAndOrgId.stream().map(sr -> sr.getRoleId()).collect(Collectors.toList()); + } + + // redis缓存角色修改 + UpdateCachedRolesFormDTO updateRolesForm = new UpdateCachedRolesFormDTO(); + updateRolesForm.setOrgId(fromDTO.getAgencyId()); + updateRolesForm.setStaffId(fromDTO.getStaffId()); + updateRolesForm.setRoleIds(roleIds); + try { + Result result = authFeignClient.updateCachedRoles(updateRolesForm); + if (!result.success()) { + logger.error("修改用户信息:修改用户已缓存的角色列表失败:{}", result.getInternalMsg()); + } + logger.info("修改用户信息:修改用户已缓存的角色列表成功"); + } catch (Exception e) { + log.error("method exception", e); + logger.error("修改用户信息:修改用户已缓存的角色列表异常:{}", ExceptionUtils.getErrorStackTrace(e)); + } + + // 角色放缓存 + CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); + List roleKeyValue = govStaffRoleDao.selectRoleKeyName(fromDTO.getRoles()); + dto.setCustomerId(fromDTO.getCustomerId()); + dto.setStaffId(fromDTO.getStaffId()); + dto.setAgencyId(fromDTO.getAgencyId()); + Map m = new HashMap(16); + roleKeyValue.forEach(r -> { + m.put(r.getRoleKey(), r.getRoleName()); + }); + dto.setRoles(m); + CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId()); + + return new Result(); + } + + @Override + public Result getStaffDetail(StaffInfoFromDTO fromDTO) { + StaffDetailResultDTO resultDTO = new StaffDetailResultDTO(); + //获取工作人员信息 + CustomerStaffDTO customerStaffDTO = baseDao.selectStaffInfo(fromDTO); + resultDTO.setStaffId(customerStaffDTO.getUserId()); + resultDTO.setName(customerStaffDTO.getRealName()); + resultDTO.setMobile(customerStaffDTO.getMobile()); + resultDTO.setHeadPhoto(customerStaffDTO.getHeadPhoto()); + resultDTO.setGender(customerStaffDTO.getGender()); + resultDTO.setActiveFlag(customerStaffDTO.getActiveFlag()); + resultDTO.setActiveTime(customerStaffDTO.getActiveTime()); + resultDTO.setEnableFlag(customerStaffDTO.getEnableFlag()); + + //获取工作人员角色 + List staffRoles = govStaffRoleService.listRolesByStaffId(fromDTO.getStaffId(), fromDTO.getAgencyId()); + List roles = staffRoles.stream().map(GovStaffRoleEntity::getRoleName).collect(Collectors.toList()); + resultDTO.setRoles(roles); + return new Result().ok(resultDTO); + } + + @Override + public Result disabledStaff(StaffInfoFromDTO fromDTO) { + CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); + CustomerStaffEntity staffEntity = new CustomerStaffEntity(); + staffEntity.setId(customerStaffEntity.getId()); + staffEntity.setEnableFlag(CustomerStaffConstant.DISABLED); + baseDao.updateById(staffEntity); + //2021.8.24 sun 人员禁用时删除工作人员的缓存信息 + CustomerStaffRedis.delStaffInfoFormCache(fromDTO.getCustomerId(), fromDTO.getStaffId()); + return new Result(); + } + + /** + * 根据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) { + //1:根据userId集合查询人员基本信息 + List staffList = baseDao.selectDepartmentStaffList(formDTO); + //2:根据组织Id查询部门下是领导角色的用户 + List staffRoleDTOS = staffRoleService.listStaffsInRole(UserRoleConstant.DEPT_LEADER, formDTO.getAgencyId(), DataScope.getDefault()); + staffRoleDTOS.forEach(roleDto -> { + staffList.stream().filter(staffDto -> + roleDto.getStaffId().equals(staffDto.getStaffId())).findAny().ifPresent(result -> + result.setRoleName(roleDto.getRoleName())); + }); + return new Result>().ok(staffList); + } + + /** + * @return Result> + * @Description 通过userId列表查询未被禁用的用户信息 + * @Param CommonUserIdListFormDTO :: getUserIdList + * @Author wangc + * @Date 2020.04.24 15:44 + **/ + @Override + public Result> getEnableStaffMsgList(CommonUserIdListFormDTO userIdList) { + if (userIdList.getUserIdList().size() <= NumConstant.ZERO) { + return new Result>().ok(new ArrayList<>()); + } + + return new Result>().ok(baseDao.selectEnableStaffMsg(userIdList.getUserIdList(), userIdList.getCustomerId())); + } + + /** + * @param staffIdList + * @return + * @Author sun + * @Description 根据staffId集合查询工作人员基础信息 + **/ + @Override + public CustomerStaffListResultDTO getCustomerStaffList(List staffIdList) { + //1:批量查询人员基本信息 + List staffList = baseDao.selectStaffByIds(staffIdList); + //2:批量查询人员拥有的所有角色信息 + List roleList = staffRoleDao.selectStaffRoleList(staffIdList); + CustomerStaffListResultDTO list = new CustomerStaffListResultDTO(); + list.setStaffList(staffList); + list.setRoleList(roleList); + return list; + } + + /** + * @param staffId + * @return + * @Author sun + * @Description 根据staffId查询工作人员基本信息 + **/ + @Override + public CustomerStaffDTO getCustomerStaff(String staffId) { + return baseDao.selectByStaffId(staffId); + } + + /** + * @param staffResetPwFormDTO + * @return void + * @author yinzuomei + * @description 工作端,修改工作人员密码 + * @Date 2020/7/1 10:41 + **/ + @Override + public void resetStaffPassword(StaffResetPwFormDTO staffResetPwFormDTO) { + CustomerStaffDTO customerStaffDTO = this.getCustomerStaff(staffResetPwFormDTO.getStaffId()); + if (null == customerStaffDTO) { + return; + } + //密码加密 + String password = PasswordUtils.encode(staffResetPwFormDTO.getNewPassword()); + logger.info(String.format("密码%s加密后为%s", staffResetPwFormDTO.getNewPassword(), password)); + customerStaffDTO.setPassword(password); + this.update(customerStaffDTO); + } + + /** + * @param userId + * @return + * @Description 得到工组人员的头像、名称、所属机关名称 + * @author wangc + * @date 2020.07.27 14:45 + **/ + @Override + public StaffEtAgencyResultDTO getStaffMsg(IssueInitiatorFormDTO userId) { + StaffEtAgencyResultDTO result = new StaffEtAgencyResultDTO(); + CustomerStaffDTO staff = baseDao.selectByStaffId(userId.getUserId()); + if (null != staff) { + Result agencyResult = govOrgOpenFeignClient.getAgencyByStaff(userId.getUserId()); + if (agencyResult.success() && null != agencyResult.getData()) { + result = ConvertUtils.sourceToTarget(agencyResult.getData(), StaffEtAgencyResultDTO.class); + result.setAgencyId(agencyResult.getData().getId()); + result.setNickname(new StringBuilder(agencyResult.getData().getOrganizationName()).append(ModuleConstant.DASH).append(staff.getRealName()).toString()); + } + } + return result; + } + + /** + * @param formDTO + * @return + * @Author sun + * @Description 根据客户ID、手机号查询政府端工作人员基本信息,校验用户是否存在 + **/ + @Override + public List getCustsomerStaffByIdAndPhone(ThirdCustomerStaffFormDTO formDTO) { + //根据客户Id和手机号查询工作人员信息 + List customerStaffDTOList = baseDao.selectStaff(formDTO); + if (null == customerStaffDTOList || customerStaffDTOList.size() < NumConstant.ONE) { + logger.warn(String.format("根据客户Id和手机号查询用户异常,客户Id:[%s],手机号:[%s],code[%s],msg[%s]", + formDTO.getCustomerId(), formDTO.getMobile(), EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(), + EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg())); + throw new RenException(EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode()); + } + return customerStaffDTOList; + } + + /** + * @param formDTO + * @Description 查询工作人员的信息 + * @author zxc + * @date 2020/8/13 1:45 下午 + */ + @Override + public List getStaffInfoList(UserIdsFormDTO formDTO) { + List userIds = formDTO.getUserIds(); + // 1. 根据userId查询人员基本信息 + List staffInfoList = new ArrayList<>(); + userIds.forEach(staffId -> { + CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), staffId); + if (staffInfo == null) { + log.error("getStaffInfoList fail customerId:{}, staffId:{} not exist in db", formDTO.getCustomerId(), staffId); + return; + } + StaffSinGridResultDTO resultDTO = new StaffSinGridResultDTO(); + resultDTO.setStaffId(staffId); + resultDTO.setStaffName(staffInfo.getRealName()); + resultDTO.setHeadPhoto(staffInfo.getHeadPhoto()); + resultDTO.setGender(staffInfo.getGender()); + + List roleInfoList = new ArrayList<>(); + staffInfo.getRoleMap().forEach((key, value) -> { + RoleResultDTO dto = new RoleResultDTO(); + dto.setRoleKey(key); + dto.setRoleName(value); + roleInfoList.add(dto); + }); + resultDTO.setRoleList(roleInfoList); + staffInfoList.add(resultDTO); + }); /*List staffInfoList = customerStaffDao.getStaffInfoList(userIds); if (staffInfoList.size() == NumConstant.ZERO){ @@ -644,14 +644,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl govOrgResult = - govOrgOpenFeignClient.staffInfoExt(result); - if(govOrgResult.success() && null != govOrgResult.getData()){ + govOrgOpenFeignClient.staffInfoExt(result); + if (govOrgResult.success() && null != govOrgResult.getData()) { return govOrgResult.getData(); } } - log.warn("com.epmet.service.impl.CustomerStaffServiceImpl.extStaffInfo,根据传入的用户Id未找到对应的工作人员,传参:{}",JSON.toJSONString(staffParam)); + log.warn("com.epmet.service.impl.CustomerStaffServiceImpl.extStaffInfo,根据传入的用户Id未找到对应的工作人员,传参:{}", JSON.toJSONString(staffParam)); return null; } - @Override - public void updateRootManage(UpdateRootManageFormDTO formDTO) { - CustomerStaffDTO dto = baseDao.selectRootManage(formDTO.getOrgId(), formDTO.getRoleKey()); - if (null == dto) { - throw new RenException("查询客户管理员失败"); - } - dto.setRealName(formDTO.getRootManageName()); - dto.setMobile(formDTO.getRootManagePhone()); - update(dto); - } + @Override + public void updateRootManage(UpdateRootManageFormDTO formDTO) { + CustomerStaffDTO dto = baseDao.selectRootManage(formDTO.getOrgId(), formDTO.getRoleKey()); + if (null == dto) { + throw new RenException("查询客户管理员失败"); + } + dto.setRealName(formDTO.getRootManageName()); + dto.setMobile(formDTO.getRootManagePhone()); + update(dto); + } - @Override - public Result> selectCustomerList(CustomerListFormDTO formDTO) { + @Override + public Result> selectCustomerList(CustomerListFormDTO formDTO) { List listResultDTO = new ArrayList<>(); CustomerDTO customerDTO = new CustomerDTO(); - // 1.根据手机号,去 customer_staff表,进行查询; 查询结果 多条:字段 customer_id,user_id + // 1.根据手机号,去 customer_staff表,进行查询; 查询结果 多条:字段 customer_id,user_id List customerStaffList = baseDao.selectListCustomerStaffDTO(formDTO.getPhone()); //sun 2020.11.12 需求变更-之前pc工作端只能是工作端小程序的超级管理员能登陆 现调整为工作端小程序的工作人员均可登陆(使用账号密码登陆) start @@ -714,150 +714,152 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl customerInfo = operCrmOpenFeignClient.getCustomerInfo(customerDTO); - if (!customerInfo.success()) { - logger.warn(String.format("获取客户信息失败,调用%s服务查询客户名称失败,入参%s", ServiceConstant.OPER_CRM_SERVER, JSON.toJSONString(staffDTO.getCustomerId()))); - } else { - if (null != customerInfo.getData()){ - CustomerListResultDTO resultDTO = new CustomerListResultDTO(); - resultDTO.setCustomerId(customerInfo.getData().getId()); - resultDTO.setCustomerName(customerInfo.getData().getCustomerName()); - listResultDTO.add(resultDTO); - } - } - } - //2020.11.12 sun end - return new Result>().ok(listResultDTO); - } - - @Override - public Result selectStaffBasicInfo(String userId, String customerId) { - StaffBasicInfoResultDTO resultDTO = baseDao.selectStaffBasicInfo(userId); - if (null != resultDTO) { - resultDTO.setRoleList(baseDao.selectStaffRoles(userId, resultDTO.getCustomerId())); - CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); - if (null != staffInfo) { - resultDTO.setAgencyId(staffInfo.getAgencyId()); - resultDTO.setAgencyName(staffInfo.getAgencyName()); - resultDTO.setLevel(staffInfo.getLevel()); - resultDTO.setLongitude(staffInfo.getLongitude()); - resultDTO.setLatitude(staffInfo.getLatitude()); - AgencyInfoCache agency = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId()); - resultDTO.setAreaCodePath(null != agency && !CollectionUtils.isEmpty(agency.getAreaCodePath()) ? agency.getAreaCodePath() : new ArrayList<>()); - resultDTO.setAreaCode(null != agency && StringUtils.isNotBlank(agency.getAreaCode()) ? agency.getAreaCode() : StrConstant.EPMETY_STR); - } - //获取工作人员所属客户名 - CustomerDTO dto = new CustomerDTO(); - dto.setId(customerId); - Result customerResult = operCrmOpenFeignClient.getCustomerInfo(dto); - if (!customerResult.success()) { - throw new RenException(customerResult.getCode(), customerResult.getMsg()); - } - if (null != customerResult.getData()) { - resultDTO.setCustomerName(customerResult.getData().getCustomerName()); - } - } - return new Result().ok(resultDTO); - } - - /** - * @param formDTO - * @return - * @Author sun - * @Description PC工作端登陆-根据客户Id和手机号查询登陆用户信息 - **/ - @Override - public GovWebOperLoginResultDTO getStaffIdAndPwd(GovWebOperLoginFormDTO formDTO) { - //1.根据客户Id和手机号查询用户信息 - return baseDao.selectByCustomerIdAndPhone(formDTO); - } - - /** - * 根据staffId查询用户基本信息 - * @author sun - * @return - */ - @Override - public BasicInfoResultDTO getStaffBasicInfo(StaffBasicInfoFromDTO fromDTO) { - return baseDao.getStaffBasicInfo(fromDTO); - } - - @Override - public List list(String customerId, String realName, String mobile, List userIds) { - return baseDao.listDTOS(customerId, realName, mobile, userIds); - } - - /** - * 【通讯录】工作人员解禁 - * @author sun - */ - @Override - public void enableStaff(EnableStaffFormDTO fromDTO) { - CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); - if (null == customerStaffEntity) { - logger.error(String.format("工作人员解禁,未查询到被解禁人信息,被解禁人Id->%s", fromDTO.getStaffId())); - throw new RenException("未查询到被解禁人信息,请核对后操作"); - } - CustomerStaffEntity staffEntity = new CustomerStaffEntity(); - staffEntity.setId(customerStaffEntity.getId()); - staffEntity.setEnableFlag(CustomerStaffConstant.ENABLE); - baseDao.updateById(staffEntity); - } - - /** - * @Author sun - * @Description 根据工作人员姓名批量查询基础信息数据 - **/ - @Override - public List getByRealNames(GetByRealNamesFormDTO formDTO) { - return baseDao.getByRealNames(formDTO); - } - - /** - * @Author sun - * @Description 【事件】网格员服务电话 - **/ - @Override - public List gridMobileList(String gridId, String userId) { - List resultList = new ArrayList<>(); - //1.查询网格下工作人员列表 - CommonGridIdFormDTO dto = new CommonGridIdFormDTO(); - dto.setGridId(gridId); - dto.setUserId(userId); - Result> gridStaffs = govOrgOpenFeignClient.getGridStaffs(dto); - if (!gridStaffs.success()) { - throw new RenException("获取网格下工作人员列表失败!"); - } - if (gridStaffs.getData().size() < NumConstant.ONE) { - return resultList; - } + for (CustomerStaffDTO staffDTO : customerStaffList) { + customerDTO.setId(staffDTO.getCustomerId()); + Result customerInfo = operCrmOpenFeignClient.getCustomerInfo(customerDTO); + if (!customerInfo.success()) { + logger.warn(String.format("获取客户信息失败,调用%s服务查询客户名称失败,入参%s", ServiceConstant.OPER_CRM_SERVER, JSON.toJSONString(staffDTO.getCustomerId()))); + } else { + if (null != customerInfo.getData()) { + CustomerListResultDTO resultDTO = new CustomerListResultDTO(); + resultDTO.setCustomerId(customerInfo.getData().getId()); + resultDTO.setCustomerName(customerInfo.getData().getCustomerName()); + listResultDTO.add(resultDTO); + } + } + } + //2020.11.12 sun end + return new Result>().ok(listResultDTO); + } - //2.查询工作人员中拥有网格长网格员角色的人员列表 - List staffRoleList = staffRoleDao.staffRoleList(gridStaffs.getData()); - - //3.查询工作人员基础信息 - List staffIdList = staffRoleList.stream().map(GridMobileListResultDTO.Role::getStaffId).collect(Collectors.toList()); - staffIdList = staffIdList.stream().distinct().collect(Collectors.toList()); - List list = baseDao.selectStaffByIds(staffIdList); - - //4.封装数据并返回 - resultList = ConvertUtils.sourceToTarget(list, GridMobileListResultDTO.class); - List roleList = null; - for (GridMobileListResultDTO re : resultList) { - roleList = new ArrayList<>(); - for (GridMobileListResultDTO.Role r : staffRoleList) { - if (re.getStaffId().equals(r.getStaffId())) { - GridMobileListResultDTO.Role role = ConvertUtils.sourceToTarget(r, GridMobileListResultDTO.Role.class); - roleList.add(role); - } - } - re.setGridId(gridId); - re.setRoleList(roleList); - } + @Override + public Result selectStaffBasicInfo(String userId, String customerId) { + StaffBasicInfoResultDTO resultDTO = baseDao.selectStaffBasicInfo(userId); + if (null != resultDTO) { + resultDTO.setRoleList(baseDao.selectStaffRoles(userId, resultDTO.getCustomerId())); + CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); + if (null != staffInfo) { + resultDTO.setAgencyId(staffInfo.getAgencyId()); + resultDTO.setAgencyName(staffInfo.getAgencyName()); + resultDTO.setLevel(staffInfo.getLevel()); + resultDTO.setLongitude(staffInfo.getLongitude()); + resultDTO.setLatitude(staffInfo.getLatitude()); + AgencyInfoCache agency = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId()); + resultDTO.setAreaCodePath(null != agency && !CollectionUtils.isEmpty(agency.getAreaCodePath()) ? agency.getAreaCodePath() : new ArrayList<>()); + resultDTO.setAreaCode(null != agency && StringUtils.isNotBlank(agency.getAreaCode()) ? agency.getAreaCode() : StrConstant.EPMETY_STR); + } + //获取工作人员所属客户名 + CustomerDTO dto = new CustomerDTO(); + dto.setId(customerId); + Result customerResult = operCrmOpenFeignClient.getCustomerInfo(dto); + if (!customerResult.success()) { + throw new RenException(customerResult.getCode(), customerResult.getMsg()); + } + if (null != customerResult.getData()) { + resultDTO.setCustomerName(customerResult.getData().getCustomerName()); + } + } + return new Result().ok(resultDTO); + } + + /** + * @param formDTO + * @return + * @Author sun + * @Description PC工作端登陆-根据客户Id和手机号查询登陆用户信息 + **/ + @Override + public GovWebOperLoginResultDTO getStaffIdAndPwd(GovWebOperLoginFormDTO formDTO) { + //1.根据客户Id和手机号查询用户信息 + return baseDao.selectByCustomerIdAndPhone(formDTO); + } - return resultList; - } + /** + * 根据staffId查询用户基本信息 + * + * @return + * @author sun + */ + @Override + public BasicInfoResultDTO getStaffBasicInfo(StaffBasicInfoFromDTO fromDTO) { + return baseDao.getStaffBasicInfo(fromDTO); + } + + @Override + public List list(String customerId, String realName, String mobile, List userIds) { + return baseDao.listDTOS(customerId, realName, mobile, userIds); + } + + /** + * 【通讯录】工作人员解禁 + * + * @author sun + */ + @Override + public void enableStaff(EnableStaffFormDTO fromDTO) { + CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); + if (null == customerStaffEntity) { + logger.error(String.format("工作人员解禁,未查询到被解禁人信息,被解禁人Id->%s", fromDTO.getStaffId())); + throw new RenException("未查询到被解禁人信息,请核对后操作"); + } + CustomerStaffEntity staffEntity = new CustomerStaffEntity(); + staffEntity.setId(customerStaffEntity.getId()); + staffEntity.setEnableFlag(CustomerStaffConstant.ENABLE); + baseDao.updateById(staffEntity); + } + + /** + * @Author sun + * @Description 根据工作人员姓名批量查询基础信息数据 + **/ + @Override + public List getByRealNames(GetByRealNamesFormDTO formDTO) { + return baseDao.getByRealNames(formDTO); + } + + /** + * @Author sun + * @Description 【事件】网格员服务电话 + **/ + @Override + public List gridMobileList(String gridId, String userId) { + List resultList = new ArrayList<>(); + //1.查询网格下工作人员列表 + CommonGridIdFormDTO dto = new CommonGridIdFormDTO(); + dto.setGridId(gridId); + dto.setUserId(userId); + Result> gridStaffs = govOrgOpenFeignClient.getGridStaffs(dto); + if (!gridStaffs.success()) { + throw new RenException("获取网格下工作人员列表失败!"); + } + if (gridStaffs.getData().size() < NumConstant.ONE) { + return resultList; + } + + //2.查询工作人员中拥有网格长网格员角色的人员列表 + List staffRoleList = staffRoleDao.staffRoleList(gridStaffs.getData()); + + //3.查询工作人员基础信息 + List staffIdList = staffRoleList.stream().map(GridMobileListResultDTO.Role::getStaffId).collect(Collectors.toList()); + staffIdList = staffIdList.stream().distinct().collect(Collectors.toList()); + List list = baseDao.selectStaffByIds(staffIdList); + + //4.封装数据并返回 + resultList = ConvertUtils.sourceToTarget(list, GridMobileListResultDTO.class); + List roleList = null; + for (GridMobileListResultDTO re : resultList) { + roleList = new ArrayList<>(); + for (GridMobileListResultDTO.Role r : staffRoleList) { + if (re.getStaffId().equals(r.getStaffId())) { + GridMobileListResultDTO.Role role = ConvertUtils.sourceToTarget(r, GridMobileListResultDTO.Role.class); + roleList.add(role); + } + } + re.setGridId(gridId); + re.setRoleList(roleList); + } + + return resultList; + } } From 29825586e603bf89165cb91efc335137510f7c78 Mon Sep 17 00:00:00 2001 From: YUJT Date: Thu, 2 Jun 2022 11:20:20 +0800 Subject: [PATCH 4/4] append --- .../java/com/epmet/service/impl/CustomerStaffServiceImpl.java | 1 + 1 file changed, 1 insertion(+) 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 af84965ac4..4c8ce4ec92 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 @@ -324,6 +324,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl