diff --git a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java index 2a320915e8..ea1763af18 100644 --- a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java +++ b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/govorg/form/StaffDetailV2FormDTO.java @@ -46,5 +46,6 @@ public class StaffDetailV2FormDTO implements Serializable { * 数字社区里的角色名称 */ private List szsqRoles; + private String customerId; } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java index e89800fa69..7f2fa0e263 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java @@ -7,6 +7,8 @@ import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.form.IdAndNameDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.enums.OrgTypeEnum; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.utils.ConvertUtils; @@ -720,7 +722,8 @@ public class EpmetUserServiceImpl implements EpmetUserService { //基本信息 CustomerStaffDTO dto = customerStaffDao.selectByStaffId(staffId); if (null == dto) { - return result; + // return result; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"customer_staff is null staffId:"+staffId,"未查询到工作人员基础信息"); } //角色信息 List list = staffRoleDao.selectByStaffId(staffId); diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java index 4261969097..6b81da281f 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/yantai/DataSyncUserAndOrgServiceImpl.java @@ -1,16 +1,22 @@ package com.epmet.controller.yantai; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.common.CustomerStaffRedis; +import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoDTOCache; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.api.yt.OrgData; +import com.epmet.commons.tools.utils.api.yt.UserData; import com.epmet.commons.tools.utils.api.yt.YantaiApi; import com.epmet.dao.yantai.DataSyncOrgDataDao; import com.epmet.dao.yantai.DataSyncUserDataDao; +import com.epmet.dto.CustomerStaffDTO; import com.epmet.dto.form.yantai.YtUserPageFormDTO; import com.epmet.dto.result.yantai.DataSyncOrgDataDTO; import com.epmet.dto.result.yantai.YtUserPageResDTO; import com.epmet.entity.yantai.DataSyncOrgDataEntity; +import com.epmet.entity.yantai.DataSyncUserDataEntity; import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.service.DataSyncOrgDataService; import com.epmet.service.DataSyncUserDataService; @@ -56,9 +62,46 @@ public class DataSyncUserAndOrgServiceImpl implements DataSyncUserAndOrgService */ @Override public Boolean yanTaiSyncUser(String organizationId) { - -// List data = YantaiApi.getUserByOuGuid(organizationId); - //todo 更新或插入数据 + String customerId = "45687aa479955f9d06204d415238f7cc"; + // 缓存初始化staffs + epmetUserOpenFeignClient.allCustomerStaffInCache(customerId); + Integer no = NumConstant.ONE; + Integer size; + do { + // 分批获取org + PageInfo pageInfo = PageHelper.startPage(no, NumConstant.ONE_HUNDRED).doSelectPageInfo(() -> dataSyncOrgDataDao.getAllList(customerId)); + size = pageInfo.getList().size(); + if (CollectionUtils.isNotEmpty(pageInfo.getList())){ + List needInsert = new ArrayList<>(); + pageInfo.getList().forEach(org -> { + // 根据org查用户 + List data = YantaiApi.getUserByOuGuid(org.getOrganizationId()); + if (CollectionUtils.isNotEmpty(data)){ + for (UserData u : data) { + CustomerStaffInfoDTOCache staffInfo = CustomerStaffRedis.getStaffInfoByMobile(customerId, u.getMobileTelephoneNumber()); + DataSyncUserDataEntity entity = ConvertUtils.sourceToTarget(u, DataSyncUserDataEntity.class); + entity.setCustomerId(customerId); + entity.setRemark(""); + if (null == staffInfo){ + entity.setStatus(NumConstant.ZERO_STR); + entity.setOrganizationId(""); + entity.setStaffId(""); + }else { + CustomerStaffInfoCacheResult staffInfo1 = CustomerStaffRedis.getStaffInfo(customerId, staffInfo.getUserId()); + entity.setStatus(NumConstant.ONE_STR); + entity.setOrganizationId(null == staffInfo1 ? "" : staffInfo1.getAgencyId()); + entity.setStaffId(staffInfo.getUserId()); + } + needInsert.add(entity); + } + } + }); + dataSyncUserDataService.insertBatch(needInsert,NumConstant.FIVE_HUNDRED); + } + no++; + }while (size == NumConstant.ONE_HUNDRED); + // 删除staffs缓存 + CustomerStaffRedis.delAllCustomerStaff(customerId); return false; } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java index edad699db9..b0b0529b62 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/yantai/DataSyncOrgDataDao.java @@ -22,4 +22,6 @@ public interface DataSyncOrgDataDao extends BaseDao { * @return */ List queryList(@Param("pid") String pid); + + List getAllList(@Param("customerId") String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml index 6f81c501f3..14931417d7 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/yantai/DataSyncOrgDataDao.xml @@ -46,4 +46,10 @@ order by d.ORDER_NUMBER asc + \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java index 47e3105b3d..e1b2602373 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/StaffOrgRelationDTO.java @@ -60,7 +60,7 @@ public class StaffOrgRelationDTO implements Serializable { private String orgId; /** - * 工作人员添加入口类型(组织:agency;部门:dept;网格:gridId) + * 工作人员的添加入口类型(组织:agency;部门:dept;网格:grid) */ private String orgType; diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java index ecdfba89f9..7bc3b93076 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddStaffV2FromDTO.java @@ -74,5 +74,8 @@ public class AddStaffV2FromDTO implements Serializable { private List newRoles; - private String currentStaffId; + /** + * 烟台用:当前登录用户 + */ + private String currentUserId; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java index 7c2a885f06..9bcd6dcb8c 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/StaffInfoFromDTO.java @@ -1,5 +1,6 @@ package com.epmet.dto.form; +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; import lombok.Data; import javax.validation.constraints.NotBlank; @@ -14,7 +15,7 @@ import java.io.Serializable; @Data public class StaffInfoFromDTO implements Serializable { private static final long serialVersionUID = 1L; - public interface EditStaffInitGroup {} + public interface EditStaffInitGroup extends CustomerClientShowGroup {} /** * 客户ID */ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java index 69f9e86294..87b641b564 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/StaffInitResultDTO.java @@ -13,6 +13,7 @@ import java.util.List; @Data public class StaffInitResultDTO implements Serializable { private static final long serialVersionUID = 1L; + private String customerId; /** * 人员ID */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java index d3f9b9dd28..bcc8e2f55e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/StaffController.java @@ -4,13 +4,17 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.RequirePermission; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.enums.RequirePermissionEnum; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.service.StaffService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -97,7 +101,7 @@ public class StaffController { */ @PostMapping("editstaff") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_UPDATE) - public Result editStaff(@LoginUser TokenDto tokenDto, @RequestBody StaffSubmitFromDTO fromDTO){ + public Result editStaff(@RequestBody StaffSubmitFromDTO fromDTO){ ValidatorUtils.validateEntity(fromDTO); return staffService.editStaff(fromDTO); } @@ -204,10 +208,20 @@ public class StaffController { @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_CREATE) public Result addStaffV2(@LoginUser TokenDto tokenDto, @RequestBody AddStaffV2FromDTO fromDTO){ ValidatorUtils.validateEntity(fromDTO, AddStaffV2FromDTO.AddStaff.class); - fromDTO.setCustomerId(tokenDto.getCustomerId()); - fromDTO.setApp(tokenDto.getApp()); - fromDTO.setClient(tokenDto.getClient()); - fromDTO.setCurrentStaffId(tokenDto.getUserId()); + if(AppClientConstant.APP_OPER.equals(tokenDto.getApp())){ + if(StringUtils.isBlank(fromDTO.getCustomerId())){ + // 该接口烟台运营端-统一认证也在用,所以客户id,运营端必传。 + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"运营端操作,customerId不能为空","运营端操作,customerId不能为空"); + } + }else{ + //小程序端或者数字社区从token里面取 + fromDTO.setCustomerId(tokenDto.getCustomerId()); + } + //因为添加的是工作人员,这里写死吧! + fromDTO.setApp("gov"); + fromDTO.setClient("wxmp"); + //当前登录用户 + fromDTO.setCurrentUserId(tokenDto.getUserId()); return staffService.addStaffV2(fromDTO); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java index 99c242b25d..04ef0c00d2 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/StaffOrgRelationEntity.java @@ -56,7 +56,7 @@ public class StaffOrgRelationEntity extends BaseEpmetEntity { private String orgId; /** - * 工作人员添加入口类型(组织:agency;部门:dept;网格:gridId) + * 工作人员的添加入口类型(组织:agency;部门:dept;网格:grid) */ private String orgType; diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java index 9f337196ca..a81f868ac5 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/StaffServiceImpl.java @@ -216,14 +216,12 @@ public class StaffServiceImpl implements StaffService { CustomerAgencyEntity customerAgencyEntity = customerAgencyService.selectById(fromDTO.getAgencyId()); fromDTO.setCustomerId(customerAgencyEntity.getCustomerId()); } + // epmetUserFeignClient.editStaff没有用到这俩参数,就注释了。 // fromDTO.setApp(tokenDto.getApp()); // fromDTO.setClient(tokenDto.getClient()); Result result = epmetUserFeignClient.editStaff(fromDTO); if (!result.success()) { - if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { - return new Result().error(result.getCode(), result.getMsg()); - } - return new Result().error(EpmetErrorCode.STAFF_EDIT_FAILED.getCode(), EpmetErrorCode.STAFF_EDIT_FAILED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),result.getInternalMsg(),result.getMsg()); } // if (tokenDto.getClient().equals("web")){ if(CollectionUtils.isNotEmpty(fromDTO.getNewRoles())){ @@ -575,8 +573,8 @@ public class StaffServiceImpl implements StaffService { //1.根据新增人员类型判断查询机关信息 OrgResultDTO orgDTO = customerAgencyDao.selectAgencyDetail(fromDTO.getOrgId(), fromDTO.getOrgType()); if (null == orgDTO) { - logger.error(String.format("工作人员新增,根据新增人员组织类型未查询到相关组织信息,orgId->%s,orgType->%s", fromDTO.getOrgId(), fromDTO.getOrgType())); - throw new RenException("根据新增人员组织类型未查询到相关组织信息"); + logger.warn(String.format("工作人员新增,根据新增人员组织类型未查询到相关组织信息,orgId->%s,orgType->%s", fromDTO.getOrgId(), fromDTO.getOrgType())); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"根据新增人员组织类型未查询到相关组织信息","组织不存在"); } //2.调用user服务,新增用户信息 @@ -584,10 +582,7 @@ public class StaffServiceImpl implements StaffService { submitDTO.setAgencyId(orgDTO.getAgencyId()); Result result = epmetUserFeignClient.addStaff(submitDTO); if (!result.success()) { - if (result.getCode() != EpmetErrorCode.SERVER_ERROR.getCode()) { - return new Result().error(result.getCode(), result.getMsg()); - } - return new Result().error(EpmetErrorCode.STAFF_ADD_FAILED.getCode(), EpmetErrorCode.STAFF_ADD_FAILED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),result.getInternalMsg(),result.getMsg()); } //3.人员机关表总人数加一、关系表新增关系数据 @@ -655,7 +650,7 @@ public class StaffServiceImpl implements StaffService { || "0c41b272ee9ee95ac6f184ad548a30eb".equals(fromDTO.getCustomerId())) { YtSyncStaffIdFormDTO ytSyncStaffIdFormDTO = ConvertUtils.sourceToTarget(fromDTO,YtSyncStaffIdFormDTO.class); ytSyncStaffIdFormDTO.setStaffId(result.getData().getUserId()); - ytSyncStaffIdFormDTO.setOperUserId(fromDTO.getCurrentStaffId()); + ytSyncStaffIdFormDTO.setOperUserId(fromDTO.getCurrentUserId()); epmetThirdOpenFeignClient.dataSyncUpdateStaff(ytSyncStaffIdFormDTO); } //2022.10.18加个返参,借用下StaffDetailResultDTO不再新建dto了 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 657e590d64..0bcb0b5eee 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -61,6 +61,8 @@ import com.epmet.service.GovStaffRoleService; import com.epmet.service.StaffRoleService; import com.epmet.service.UserService; import com.epmet.util.ModuleConstant; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -301,6 +303,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + // return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"手机号已存在","手机号已存在"); } //USER表插入数据 UserEntity userEntity = new UserEntity(); @@ -467,12 +471,14 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + // return new Result().error(EpmetErrorCode.MOBILE_USED.getCode(), EpmetErrorCode.MOBILE_USED.getMsg()); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"手机号已存在","手机号已存在"); } CustomerStaffEntity customerStaffEntity = baseDao.selectByUserId(fromDTO.getStaffId()); //Customer_Staff表插入数据 CustomerStaffEntity staffEntity = new CustomerStaffEntity(); + staffEntity.setCustomerId(customerStaffEntity.getCustomerId()); staffEntity.setId(customerStaffEntity.getId()); staffEntity.setRealName(fromDTO.getName()); staffEntity.setMobile(fromDTO.getMobile()); @@ -491,6 +497,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl customerStaffs = baseDao.getAllStaffByCustomerId(customerId); - size = customerStaffs.size(); - if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(customerStaffs)){ - customerStaffs.forEach(c -> { + PageInfo pageInfo = PageHelper.startPage(no, NumConstant.ONE_HUNDRED).doSelectPageInfo(() -> baseDao.getAllStaffByCustomerId(customerId)); + size = pageInfo.getList().size(); + if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(pageInfo.getList())){ + pageInfo.getList().forEach(c -> { String key = RedisKeys.getCustomerStaffInfoKeyByMobile(customerId, c.getMobile()); Map map = BeanUtil.beanToMap(c, false, true); redisUtils.hMSet(key,map);