From afe15fef3e4a4c76a54c55d94a1023814e0660c6 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Thu, 19 Aug 2021 11:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B7=A5=E4=BD=9C=E4=BA=BA?= =?UTF-8?q?=E5=91=98V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dto/form/AddStaffV2FromDTO.java | 32 ++++--- .../com/epmet/dto/result/OrgResultDTO.java | 91 +++++++++++++++++++ .../com/epmet/controller/StaffController.java | 9 +- .../java/com/epmet/dao/CustomerAgencyDao.java | 6 ++ .../epmet/service/impl/StaffServiceImpl.java | 69 +++++++++++++- .../resources/mapper/CustomerAgencyDao.xml | 63 +++++++++++++ 6 files changed, 251 insertions(+), 19 deletions(-) create mode 100644 epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrgResultDTO.java 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 4d77fa3114..5f369289e9 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 @@ -1,5 +1,6 @@ package com.epmet.dto.form; +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.Length; @@ -19,44 +20,49 @@ import java.util.List; public class AddStaffV2FromDTO implements Serializable { private static final long serialVersionUID = 1L; /** - * 客户ID + * 新增人员所属类型Id */ - private String customerId; + private String orgId; /** - * 机关ID + * 客户ID */ - private String agencyId; + private String customerId; /** - * 人员ID + * 新增人员所属类型【组织:agency;部门:dept;网格:grid】】 */ - private String staffId; + private String orgType; /** * 姓名 */ - @NotBlank(message = "姓名不能为空") - @Length(max = 15, message = "姓名仅允许输入15个字符") + @NotBlank(message = "姓名不能为空", groups = AddStaffV2FromDTO.AddStaff.class) + @Length(max = 15, message = "姓名仅允许输入15个字符", groups = AddStaffV2FromDTO.AddStaff.class) private String name; + /** + * 人员ID + */ + private String staffId; /** * 手机 */ - @NotBlank(message = "手机号不能为空") - @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "请输入正确的手机号") + @NotBlank(message = "手机号不能为空", groups = AddStaffV2FromDTO.AddStaff.class) + @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "请输入正确的手机号", groups = AddStaffV2FromDTO.AddStaff.class) private String mobile; /** * 性别 */ - @NotNull(message = "性别不能为空") + @NotNull(message = "性别不能为空", groups = AddStaffV2FromDTO.AddStaff.class) private Integer gender; /** * 专兼职 */ - @NotBlank(message = "专兼职不能为空") + @NotBlank(message = "专兼职不能为空", groups = AddStaffV2FromDTO.AddStaff.class) private String workType; /** * 角色id列表 */ - @NotNull(message = "角色不能为空") + @NotNull(message = "角色不能为空", groups = AddStaffV2FromDTO.AddStaff.class) private List roles; + public interface AddStaff extends CustomerClientShowGroup {} /** * 来源app(政府端:gov、居民端:resi、运营端:oper) */ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrgResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrgResultDTO.java new file mode 100644 index 0000000000..54cd3a5cc1 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/OrgResultDTO.java @@ -0,0 +1,91 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + + +/** + * 按类型查询对应机关信息 + */ +@Data +public class OrgResultDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 机关Id + */ + private String agencyId; + + /** + * 客户ID + */ + private String customerId; + + /** + * 上级组织机构ID + */ + private String pid; + + /** + * 所有上级组织机构ID(以英文:隔开) + */ + private String pids; + + /** + * 所有上级名称,以-连接 + */ + private String allParentName; + + /** + * 组织名称 + */ + private String organizationName; + + /** + * 机关级别(社区级:community, +乡(镇、街道)级:street, +区县级: district, +市级: city +省级:province) 机关级别(社区级:community,乡(镇、街道)级:street,区县级: district,市级: city省级:province) + */ + private String level; + + /** + * 地区编码 + */ + private String areaCode; + + /** + * 总人数 + */ + private Integer totalUser = 0; + + /** + * 部门总人数 + */ + private Integer DeptTotalUser = 0; + + /** + * 网格总人数 + */ + private Integer gridTotalUser = 0; +} \ No newline at end of file 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 ef125beb1a..2dafc1e158 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 @@ -172,10 +172,11 @@ public class StaffController { */ @PostMapping("addstaffv2") @RequirePermission(requirePermission = RequirePermissionEnum.ORG_STAFF_CREATE) - public Result addStaffV2(@RequestBody AddStaffV2FromDTO fromDTO){ - fromDTO.setApp("gov"); - fromDTO.setClient("wxmp"); - ValidatorUtils.validateEntity(fromDTO); + 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()); return staffService.addStaffV2(fromDTO); } 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 dc5518a35c..b0149c28d8 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 @@ -233,4 +233,10 @@ public interface CustomerAgencyDao extends BaseDao { @Param("customerId") String customerId, @Param("agencyId") String agencyId, @Param("parentAgencyId") String parentAgencyId); + + /** + * 根据新增人员类型判断查询机关信息 + * @author sun + */ + OrgResultDTO selectAgencyDetail(@Param("orgId") String orgId, @Param("orgType") String orgType); } \ No newline at end of file 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 402ca28f4f..2004327484 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 @@ -6,16 +6,20 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.constant.CustomerAgencyConstant; +import com.epmet.dao.CustomerAgencyDao; import com.epmet.dao.CustomerStaffAgencyDao; import com.epmet.dto.*; import com.epmet.dto.form.*; import com.epmet.dto.result.*; -import com.epmet.entity.CustomerAgencyEntity; -import com.epmet.entity.CustomerStaffAgencyEntity; +import com.epmet.entity.*; import com.epmet.feign.*; import com.epmet.service.*; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +35,7 @@ import java.util.stream.Collectors; */ @Service public class StaffServiceImpl implements StaffService { + private static final Logger logger = LoggerFactory.getLogger(StaffServiceImpl.class); @Autowired private EpmetUserFeignClient epmetUserFeignClient; @Autowired @@ -55,6 +60,12 @@ public class StaffServiceImpl implements StaffService { private RedisUtils redisUtils; @Autowired private CustomerStaffAgencyDao customerStaffAgencyDao; + @Autowired + private com.epmet.dao.CustomerAgencyDao customerAgencyDao; + @Autowired + private CustomerStaffDepartmentService customerStaffDepartmentService; + @Autowired + private CustomerStaffGridService customerStaffGridService; @Override public Result getStaffInfoForHome(StaffsInAgencyFromDTO fromDTO) { @@ -309,8 +320,62 @@ public class StaffServiceImpl implements StaffService { @Override @Transactional(rollbackFor = Exception.class) public Result addStaffV2(AddStaffV2FromDTO fromDTO) { + //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("根据新增人员组织类型未查询到相关组织信息"); + } + + //2.调用user服务,新增用户信息 + StaffSubmitFromDTO submitDTO = ConvertUtils.sourceToTarget(fromDTO, StaffSubmitFromDTO.class); + 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()); + } + + //3.人员机关表总人数加一、关系表新增关系数据 + //人员机关关系表 + CustomerStaffAgencyEntity customerStaffAgencyEntity = new CustomerStaffAgencyEntity(); + customerStaffAgencyEntity.setCustomerId(fromDTO.getCustomerId()); + customerStaffAgencyEntity.setUserId(result.getData().getUserId()); + customerStaffAgencyEntity.setAgencyId(orgDTO.getAgencyId()); + customerStaffAgencyService.insert(customerStaffAgencyEntity); + //机关总人数加一 + CustomerAgencyEntity agencyEntity = new CustomerAgencyEntity(); + agencyEntity.setId(orgDTO.getAgencyId()); + agencyEntity.setTotalUser(orgDTO.getTotalUser() + 1); + customerAgencyService.updateById(agencyEntity); + + //4.部门、网格主表、关系表修改、新增数据 + if ("dept".equals(fromDTO.getOrgType())) { + CustomerStaffDepartmentEntity dept = new CustomerStaffDepartmentEntity(); + dept.setCustomerId(fromDTO.getCustomerId()); + dept.setUserId(result.getData().getUserId()); + dept.setDepartmentId(fromDTO.getOrgId()); + customerStaffDepartmentService.insert(dept); + CustomerDepartmentEntity departmentEntity = new CustomerDepartmentEntity(); + departmentEntity.setId(fromDTO.getOrgId()); + departmentEntity.setTotalUser(orgDTO.getDeptTotalUser() + 1); + customerDepartmentService.updateById(departmentEntity); + } + if ("grid".equals(fromDTO.getOrgType())) { + CustomerStaffGridEntity grid = new CustomerStaffGridEntity(); + grid.setCustomerId(fromDTO.getCustomerId()); + grid.setUserId(result.getData().getUserId()); + grid.setGridId(fromDTO.getOrgId()); + customerStaffGridService.insert(grid); + CustomerGridEntity gridEntity = new CustomerGridEntity(); + gridEntity.setId(fromDTO.getOrgId()); + gridEntity.setTotalUser(orgDTO.getGridTotalUser() + 1); + customerGridService.updateById(gridEntity); + } return new Result(); } + } 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 58d2fd628e..ba8a00245d 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 @@ -441,4 +441,67 @@ AND ca.pid =#{parentAgencyId} + + + \ No newline at end of file