From 719fd8086c8c0b3595f976dc016026c60d7dabb8 Mon Sep 17 00:00:00 2001 From: wulin Date: Thu, 26 Nov 2020 17:35:54 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=92=89=E9=92=89?= =?UTF-8?q?=E9=80=9A=E8=AE=AF=E5=BD=95=E5=90=8C=E6=AD=A5=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E9=92=89=E9=92=89V2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E5=85=B6?= =?UTF-8?q?=E4=BB=96bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/lz/common/utils/DingTalkUtil.java | 139 +++++- .../modules/app/dao/StaffOccupationDao.java | 2 + .../entity/DepartmentsStaffRelateEntity.java | 5 + .../app/entity/StaffOccupationEntity.java | 4 + .../app/service/StaffOccupationService.java | 2 + .../lz/modules/app/service/StaffService.java | 2 + .../impl/StaffOccupationServiceImpl.java | 5 + .../app/service/impl/StaffServiceImpl.java | 2 +- .../job/business/DingtalkBusiness.java | 446 ++++++++++++++++-- .../model/responseBo/DepartmentStaffBo.java | 4 + .../resources/mapper/generator/StaffDao.xml | 4 +- .../mapper/generator/StaffOccupationDao.xml | 4 + 13 files changed, 572 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index 336d33ee..1dce0895 100644 --- a/pom.xml +++ b/pom.xml @@ -251,7 +251,7 @@ com.aliyun alibaba-dingtalk-service-sdk - 1.0.0 + 2.0.0 suibian diff --git a/src/main/java/com/lz/common/utils/DingTalkUtil.java b/src/main/java/com/lz/common/utils/DingTalkUtil.java index 6a4d5187..298f089f 100644 --- a/src/main/java/com/lz/common/utils/DingTalkUtil.java +++ b/src/main/java/com/lz/common/utils/DingTalkUtil.java @@ -121,6 +121,7 @@ public class DingTalkUtil { try { //下面获取所有部门的i就按单信息 Map list = new HashMap<>(); + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list"); OapiDepartmentListRequest req = new OapiDepartmentListRequest(); req.setFetchChild(true); @@ -144,6 +145,7 @@ public class DingTalkUtil { deReq.setId(departmentInfosBo.getId()); deReq.setHttpMethod("GET"); OapiDepartmentGetResponse deRsp = client.execute(deReq, accessToken); + logger.info("钉钉部门信息返回{}", deRsp.getBody()); json = JSONObject.parseObject(deRsp.getBody()); departmentInfosBo.setChatId(json.getString("deptGroupChatId")); departmentInfosBo.setLeaderEmployeeId(json.getString("deptManagerUseridList"));//部门主管,多个主管以|隔开 @@ -162,6 +164,47 @@ public class DingTalkUtil { return null; } + public List getDepartmentDetailsV2(String accessToken, String departmentIds) { + List list = new ArrayList<>(); + + try { + //下面获取所有部门的i就按单信息 + getDepartment(list, 1L, accessToken); + return list; + } catch (Exception e) { + logger.info("获取部门详情异常{}", e); + } + return null; + } + + private void getDepartment(List list, Long depId, String accessToken) throws ApiException { + + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub"); + OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest(); + req.setDeptId(depId); + req.setLanguage("zh_CN"); + OapiV2DepartmentListsubResponse rsp = client.execute(req, accessToken); + + logger.info("钉钉请求返回{}", rsp.getBody()); + JSONObject json = JSONObject.parseObject(rsp.getBody()); + if(json.getInteger("errcode") == 0) { + JSONArray array = json.getJSONArray("result"); + logger.info("子部门数量{}", array.size()); + for (int i = 0; i < array.size(); i++) { + json = array.getJSONObject(i); + + DepartmentInfosBo departmentInfosBo = new DepartmentInfosBo(); + departmentInfosBo.setName(json.getString("name")); + departmentInfosBo.setId(json.getString("dept_id"));//自身ID + departmentInfosBo.setParentId(json.getString("parent_id"));//父级ID + list.add(departmentInfosBo); + logger.info("钉钉请求{}的子部门", departmentInfosBo.getName()); + getDepartment(list, json.getLong("dept_id"), accessToken); + } + } + + } + /** * 获取部门用户详情 * @@ -183,7 +226,7 @@ public class DingTalkUtil { for(long page = 0; isNext; page++){ req.setOffset(page); OapiUserListbypageResponse rsp = client.execute(req, accessToken); - logger.info("钉钉请求返回{}", rsp.getBody()); + logger.info("钉钉请求人员返回{}", rsp.getBody()); JSONObject json = JSONObject.parseObject(rsp.getBody()); if(json.getInteger("errcode") == 0){ JSONArray array = json.getJSONArray("userlist"); @@ -219,7 +262,99 @@ public class DingTalkUtil { }else{ - logger.info("获取部门详情异常{}", rsp.getBody()); + logger.info("获取人员详情异常{}", rsp.getBody()); + } + } + + return list; + } catch (Exception e) { + e.printStackTrace(); + logger.info("获取部门用户详情异常{}", e); + } + return null; + } + + /** + * 获取部门用户详情 + * + * @param accessToken + * @return + */ + public List getDepartmentStaffDetailsV2(String accessToken, String departmentId) { + try { + long page = 0L; + List list =new ArrayList<>(); + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list"); + OapiV2UserListRequest req = new OapiV2UserListRequest(); + req.setDeptId(Long.parseLong(departmentId)); + req.setCursor(page); + req.setSize(100L); + req.setOrderField("modify_desc"); + req.setContainAccessLimit(false); + req.setLanguage("zh_CN"); + /*OapiV2UserListResponse rsp = client.execute(req, accessToken); + + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage"); + + OapiUserListbypageRequest req = new OapiUserListbypageRequest(); + req.setDepartmentId(Long.parseLong(departmentId)); + + req.setSize(100L); + req.setHttpMethod("GET");*/ + + boolean isNext = false; + for(; true; page++){ + req.setCursor(page); + OapiV2UserListResponse rsp = client.execute(req, accessToken); + logger.info("钉钉请求人员返回{}", rsp.getBody()); + JSONObject json = JSONObject.parseObject(rsp.getBody()); + if(json.getInteger("errcode") == 0){ + json = json.getJSONObject("result"); + JSONArray array = json.getJSONArray("list"); + isNext = json.getBoolean("has_more");//获取是否由更多数据 + for (int i = 0; i < array.size(); i++) { + json = array.getJSONObject(i); + DepartmentStaffBo departmentStaffBo = new DepartmentStaffBo(); + departmentStaffBo.setEmployeeId(json.getString("userid"));//用户在企业内部的唯一编号,创建时可指定。可代表一定的含义 + departmentStaffBo.setName(json.getString("name")); + departmentStaffBo.setEmployeeNo(json.getString("job_number"));//工号 + departmentStaffBo.setUnionId(json.getString("unionid"));//企业内部id,唯一 + departmentStaffBo.setOpenId(departmentStaffBo.getUnionId());//和上面的值目前是一样的,未找到说明 + departmentStaffBo.setMobile(json.getString("mobile"));//手机,需要单独授权手机权限 + departmentStaffBo.setEmail(json.getString("email"));//邮箱,钉钉的企业邮箱才可以,需要单独授权手机权限 + departmentStaffBo.setAvatar(json.getString("avatar"));//头像 + departmentStaffBo.setPosition(json.getString("title")); + departmentStaffBo.setStatus(0); + /*if(json.getBoolean("active")){ + //在职已激活 + departmentStaffBo.setStatus(0); + }else{ + //在职未激活 + departmentStaffBo.setStatus(4); + }*/ + if(json.getBoolean("leader")){ + departmentStaffBo.setIsLeader(1); + + }else{ + departmentStaffBo.setIsLeader(0); + } + + if(json.getBoolean("boss")){ + departmentStaffBo.setIsBoss(1); + + }else{ + departmentStaffBo.setIsBoss(0); + } + list.add(departmentStaffBo); + } + if(!isNext){ + break; + } + + + }else{ + logger.info("获取人员详情异常{}", rsp.getBody()); + break; } } diff --git a/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java b/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java index f0ce615e..c13d106a 100644 --- a/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java +++ b/src/main/java/com/lz/modules/app/dao/StaffOccupationDao.java @@ -33,4 +33,6 @@ public interface StaffOccupationDao extends BaseMapper { void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo); List removeDimissionStaffByStaffIds(@Param("staffIds") List staffIds); + + List selectAll(); } diff --git a/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java b/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java index edc90a6d..de9c6f4b 100644 --- a/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java +++ b/src/main/java/com/lz/modules/app/entity/DepartmentsStaffRelateEntity.java @@ -39,6 +39,11 @@ public class DepartmentsStaffRelateEntity implements Serializable { * 是否为部门领导 */ private Integer isLeader; + //获取mapkey + public String getKey(){ + return departmentId + "_" + staffId; + } + /** * 自增主键 * @return diff --git a/src/main/java/com/lz/modules/app/entity/StaffOccupationEntity.java b/src/main/java/com/lz/modules/app/entity/StaffOccupationEntity.java index 1959c17a..26ed9a84 100644 --- a/src/main/java/com/lz/modules/app/entity/StaffOccupationEntity.java +++ b/src/main/java/com/lz/modules/app/entity/StaffOccupationEntity.java @@ -105,4 +105,8 @@ public class StaffOccupationEntity implements Serializable { */ private String resumeUrl; + public String getKey(){ + return staffId + "_" + position; + } + } diff --git a/src/main/java/com/lz/modules/app/service/StaffOccupationService.java b/src/main/java/com/lz/modules/app/service/StaffOccupationService.java index 61ab3b85..1ee2f43e 100644 --- a/src/main/java/com/lz/modules/app/service/StaffOccupationService.java +++ b/src/main/java/com/lz/modules/app/service/StaffOccupationService.java @@ -33,5 +33,7 @@ public interface StaffOccupationService extends IService void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo); List removeDimissionStaffByStaffIds(List staffIds); + + List selectAll(); } diff --git a/src/main/java/com/lz/modules/app/service/StaffService.java b/src/main/java/com/lz/modules/app/service/StaffService.java index 936f6f45..eddffc4d 100644 --- a/src/main/java/com/lz/modules/app/service/StaffService.java +++ b/src/main/java/com/lz/modules/app/service/StaffService.java @@ -105,5 +105,7 @@ public interface StaffService extends IService { List selectStaffsByGroupId(Long copyId); List findManger(Long recordId, int flowProcess); + + StaffEntity convertStaffEntity(DepartmentStaffBo staffBo); } diff --git a/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java b/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java index 214bde65..38a998e7 100644 --- a/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java +++ b/src/main/java/com/lz/modules/app/service/impl/StaffOccupationServiceImpl.java @@ -72,4 +72,9 @@ public class StaffOccupationServiceImpl extends ServiceImpl selectAll(){ + return staffOccupationDao.selectAll(); + } } diff --git a/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java b/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java index a15333aa..cd0f894a 100644 --- a/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java +++ b/src/main/java/com/lz/modules/app/service/impl/StaffServiceImpl.java @@ -374,7 +374,7 @@ public class StaffServiceImpl extends ServiceImpl impleme } } - private StaffEntity convertStaffEntity(DepartmentStaffBo staffBo) { + public StaffEntity convertStaffEntity(DepartmentStaffBo staffBo) { StaffEntity staffEntity = new StaffEntity(); staffEntity.setName(staffBo.getName());//员工姓名 staffEntity.setGender(staffBo.getGender()); diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java index 235da916..68851670 100644 --- a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java +++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java @@ -1,15 +1,20 @@ package com.lz.modules.job.business; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiRoleListRequest; +import com.dingtalk.api.request.OapiRoleSimplelistRequest; +import com.dingtalk.api.response.OapiRoleListResponse; +import com.dingtalk.api.response.OapiRoleSimplelistResponse; import com.google.common.collect.Lists; import com.lz.common.emun.WorkMsgTypeEnum; import com.lz.common.utils.DateUtils; import com.lz.common.utils.DingTalkUtil; import com.lz.common.utils.R; import com.lz.modules.app.dao.StaffDao; -import com.lz.modules.app.entity.DepartmentsEntity; -import com.lz.modules.app.entity.StaffEntity; -import com.lz.modules.app.entity.StaffOccupationEntity; -import com.lz.modules.app.entity.StaffSimpleInfo; +import com.lz.modules.app.entity.*; import com.lz.modules.app.service.DepartmentsService; import com.lz.modules.app.service.DepartmentsStaffRelateService; import com.lz.modules.app.service.StaffOccupationService; @@ -31,8 +36,11 @@ import com.lz.modules.third.entity.ThirdMsgSendRecord; import com.lz.modules.third.entity.WorkMsg; import com.lz.modules.third.service.ThirdAppConfigService; import com.lz.modules.third.service.ThirdMsgSendRecordService; +import com.taobao.api.ApiException; import org.apache.commons.collections.map.CompositeMap; +import org.apache.commons.collections.map.HashedMap; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -40,6 +48,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -131,69 +140,420 @@ public class DingtalkBusiness { //获取Token String token = dingTalkUtil.getAccessToken(appid); if(token != null && token.length() > 0){ + + /*DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list"); + OapiRoleListRequest request = new OapiRoleListRequest(); + request.setOffset(0L); + request.setSize(10L); + + OapiRoleListResponse response = null; + try { + response = client.execute(request, token); + logger.info("角色返回{}", response.getBody()); + JSONObject jsonObject = JSONObject.parseObject(response.getBody()); + JSONArray jsonArray = jsonObject.getJSONObject("result").getJSONArray("list"); + for (int i = 0; i < jsonArray.size(); i++ + ) { + JSONObject json = jsonArray.getJSONObject(i); + JSONArray array = json.getJSONArray("roles"); + logger.info("角色组{}", json.getString("name")); + for(int j = 0; j < array.size(); j++){ + json = array.getJSONObject(j); + client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/simplelist"); + OapiRoleSimplelistRequest request1 = new OapiRoleSimplelistRequest(); + request1.setRoleId(json.getLong("id")); + request1.setOffset(0L); + request1.setSize(200L); + + OapiRoleSimplelistResponse response1 = client.execute(request1, token); + logger.info("钉钉获取角色{},数据为{}", json.getString("name"), response1.getBody()); + } + } + } catch (ApiException e) { + e.printStackTrace(); + }*/ + + List addDeparts = new ArrayList<>();//需要新增的部门信息 + List updateDeparts = new ArrayList<>();//需要更新的部门信息 + + List addStaffs = new ArrayList<>();//需要新增的人员信息 + List updateStaffs = new ArrayList<>();//需要更新的人员 + + List addDepartStaff = new ArrayList<>();//需要新增的部门人员对应关系 + List updateDepartStaff = new ArrayList<>();//需要更新部门人员对应关系 + Map mapEmployeeIdDeparts = new HashedMap();//新员工对应的部门对应关系 + + List addStaffOcc = new ArrayList<>();//需要新增的职位信息 + List updateStaffOcc = new ArrayList<>();//需要更新的职位信息 + Map mapEmployeeIdStaffOccs = new HashedMap();//新员工对应的职位对应关系 + + List newDepartIds = new ArrayList<>();//新的部门或者新的人员对应信息 + List newPositions = new ArrayList<>();//新的职位或者新的人员对应信息 + //获取所有的部门详情 - Map departmentInfosBos = dingTalkUtil.getDepartmentDetails(token, "1"); + List departmentInfosBos = dingTalkUtil.getDepartmentDetailsV2(token, "1"); if(departmentInfosBos.size() > 0){ - //获取所有部门信息 + //获取原有部门信息 + Map mapDepartmentInfosBos + = departmentInfosBos.stream().collect(Collectors.toMap(DepartmentInfosBo::getId, Function.identity(), (e, r) -> e)); List departmentsEntities = departmentsService.selectAll(); - Map mapDeparts = - departmentsEntities.stream().collect(Collectors.toMap(DepartmentsEntity::getDepartmentId, Function.identity(), (e, r) -> e)); - //更新数据库中的部门相关信息 - //departmentsService.updateDepartmentInfos(departmentInfosBos); + Map mapDeparts = null; + if(departmentsEntities.size() > 0){ + mapDeparts = + departmentsEntities.stream().collect(Collectors.toMap(DepartmentsEntity::getDepartmentId, Function.identity(), (e, r) -> e)); + } + + //获取原有的部门人员对应关系 + List departmentsStaffRelateEntities = departmentsStaffRelateService.selectAll(); + + Map mapDepStaffs = null; + if(departmentsStaffRelateEntities.size() > 0){ + mapDepStaffs = + departmentsStaffRelateEntities.stream().collect( + Collectors.toMap(DepartmentsStaffRelateEntity::getKey, + Function.identity(), (e, r) -> e)); + } + + //获取所有人员信息 + List staffEntities = staffService.selectAll(); + Map mapStaffs = null; + if(staffEntities.size() > 0){ + mapStaffs = staffEntities.stream(). + collect(Collectors.toMap(StaffEntity::getEmployeeId, Function.identity(), (e, r)->e)); + } + Map mapMorDepartStaffs = new HashedMap();//跨部门人员 + List staffOccupationEntities = staffOccupationService.selectAll(); + Map mapStaffOccs = null; + if(staffOccupationEntities.size() > 0){ + mapStaffOccs = + staffOccupationEntities.stream().collect(Collectors.toMap(StaffOccupationEntity::getKey, Function.identity(), (e, r) -> e)); + } + Map mapHaveStaffOccs = new HashedMap(); + //删除原有的对应关系下面在更新 - departmentsStaffRelateService.deleteAllRelates(); //未在飞书组织架构里的成员,置为离职(全部置为离职,再把在职的恢复) - staffOccupationService.updateAllOccupation(); //获取飞书部门对应的用户详情 - for (String key : departmentInfosBos.keySet()) { - if(mapDeparts.containsKey(key)){ + for (DepartmentInfosBo departmentInfo : departmentInfosBos) { + //DepartmentInfosBo departmentInfo = departmentInfosBos.get(key); + String key = departmentInfo.getId(); + DepartmentsEntity departmentsEntity = null; + if(mapDeparts != null && mapDeparts.containsKey(key)){ //部门存在 + departmentsEntity = mapDeparts.get(key); + updateDeparts.add(departmentsEntity); mapDeparts.remove(key); + }else{//新增部门信息 + departmentsEntity = new DepartmentsEntity(); + departmentsEntity.setDepartmentId(departmentInfo.getId()); + addDeparts.add(departmentsEntity); } - DepartmentInfosBo departmentInfo = departmentInfosBos.get(key); + //获取部门用户详情 - List staffs = dingTalkUtil.getDepartmentStaffDetails(token, departmentInfo.getId()); + List staffs = dingTalkUtil.getDepartmentStaffDetailsV2(token, departmentInfo.getId()); logger.info("=============================" + departmentInfo.getName() + "================================"); - - //departmentInfo.setMemberCount(staffs.size());//设置部门人数,钉钉没有返回部门人数,只能这样设置 - //计算父类的 - DepartmentInfosBo integer = departmentInfo; - while(!integer.getParentId().equals("1")){ - integer = departmentInfosBos.get(integer.getParentId()); - if(integer.getMemberCount() == null){ - integer.setMemberCount(0); - } - integer.setMemberCount(integer.getMemberCount() + staffs.size()); - - } - //获取自己的 + //设置本部门人数 if(departmentInfo.getMemberCount() == null){ departmentInfo.setMemberCount(0); } departmentInfo.setMemberCount(departmentInfo.getMemberCount() + staffs.size()); + //计算父类的 + DepartmentInfosBo integer = departmentInfo; + while(!integer.getParentId().equals("1")){ + integer = mapDepartmentInfosBos.get(integer.getParentId()); + if(integer.getMemberCount() == null){ + integer.setMemberCount(0); + } + integer.setMemberCount(integer.getMemberCount() + staffs.size()); + } + + if(staffs.size() > 0){ - //循环录入到员工信息表中 - if(staffService.updateStaffsInfo(staffs)){ - //加入到部门和员工关系表,同时更新leader关系 - departmentsStaffRelateService.addRelateInfos(departmentInfo.getId(), staffs); - //录入员工职业信息表 - enterStaffOccupationInfos(staffs); + for (DepartmentStaffBo departmentStaffBo:staffs + ) { + StaffEntity staff = staffService.convertStaffEntity(departmentStaffBo); + if(mapStaffs != null && mapStaffs.containsKey(departmentStaffBo.getEmployeeId())){//老员工 + StaffEntity entity = mapStaffs.get(departmentStaffBo.getEmployeeId()); + staff.setId(entity.getId()); + staff.setCreateTime(entity.getCreateTime()); + staff.setUpdateTime(new Date()); + updateStaffs.add(staff); + if(!mapMorDepartStaffs.containsKey(departmentStaffBo.getEmployeeId())){ + mapMorDepartStaffs.put(departmentStaffBo.getEmployeeId(), staff); + } + mapStaffs.remove(departmentStaffBo.getEmployeeId()); + + StaffOccupationEntity staffOccupation = new StaffOccupationEntity(); + staffOccupation.setStaffId(staff.getId()); + staffOccupation.setPosition(departmentStaffBo.getPosition());//职位信息 + staffOccupation.setEmployeeNo(departmentStaffBo.getEmployeeNo()); + staffOccupation.setStaffNo(departmentStaffBo.getEmployeeNo());//钉钉的员工工号 + staffOccupation.setStaffType(departmentStaffBo.getEmployeeType()); + staffOccupation.setStaffStatus(departmentStaffBo.getStatus()); + String key1 = entity.getId() + "_" + staffOccupation.getPosition(); + if(mapStaffOccs != null && mapStaffOccs.containsKey(key1)){//职位信息已存在,更新 + StaffOccupationEntity staffOccupation1 = mapStaffOccs.get(key1); + staffOccupation.setId(staffOccupation1.getId()); + staffOccupation.setUpdateTime(new Date()); + updateStaffOcc.add(staffOccupation); + mapStaffOccs.remove(key1); + mapHaveStaffOccs.put(key1, staffOccupation); + }else if(!mapHaveStaffOccs.containsKey(key1)){//职位信息不存在,新建 + + addStaffOcc.add(staffOccupation); + mapHaveStaffOccs.put(key1, staffOccupation); + } + + DepartmentsStaffRelateEntity departmentsStaffRelateEntity = new DepartmentsStaffRelateEntity(); + departmentsStaffRelateEntity.setDepartmentId(departmentInfo.getId()); + departmentsStaffRelateEntity.setStaffId(staff.getId()); + departmentsStaffRelateEntity.setIsLeader(departmentStaffBo.getIsLeader()); + if(mapDepStaffs != null && mapDepStaffs.containsKey(departmentsStaffRelateEntity.getKey())){//对应关系已经存在 + DepartmentsStaffRelateEntity staffRelateEntityentity1 = mapDepStaffs.get(departmentsStaffRelateEntity.getKey()); + if(staffRelateEntityentity1.getIsLeader().intValue() != departmentsStaffRelateEntity.getIsLeader().intValue()){ + departmentsStaffRelateEntity.setId(staffRelateEntityentity1.getId()); + departmentsStaffRelateEntity.setUpdateTime(new Date()); + updateDepartStaff.add(departmentsStaffRelateEntity); + + } + mapDepStaffs.remove(departmentsStaffRelateEntity.getKey()); + + }else{//不存在对应关系 + addDepartStaff.add(departmentsStaffRelateEntity); + } + }else if(mapMorDepartStaffs.containsKey(departmentStaffBo.getEmployeeId())){ + //跨部门人员 + StaffEntity entity = mapMorDepartStaffs.get(departmentStaffBo.getEmployeeId()); + staff.setId(entity.getId()); + DepartmentsStaffRelateEntity departmentsStaffRelateEntity = new DepartmentsStaffRelateEntity(); + departmentsStaffRelateEntity.setDepartmentId(departmentInfo.getId()); + departmentsStaffRelateEntity.setIsLeader(departmentStaffBo.getIsLeader()); + departmentsStaffRelateEntity.setStaffId(staff.getId()); + + StaffOccupationEntity staffOccupation = new StaffOccupationEntity(); + staffOccupation.setStaffId(staff.getId()); + staffOccupation.setPosition(departmentStaffBo.getPosition());//职位信息 + staffOccupation.setEmployeeNo(departmentStaffBo.getEmployeeNo()); + staffOccupation.setStaffNo(departmentStaffBo.getEmployeeNo());//钉钉的员工工号 + staffOccupation.setStaffType(departmentStaffBo.getEmployeeType()); + staffOccupation.setStaffStatus(departmentStaffBo.getStatus()); + + + if(entity.getId() == null){//新用户 + key = staff.getEmployeeId() + "_" + departmentsStaffRelateEntity.getDepartmentId(); + if(!mapEmployeeIdDeparts.containsKey(key)){ + + departmentsStaffRelateEntity.setIsLeader(departmentStaffBo.getIsLeader()); + mapEmployeeIdDeparts.put(key + , departmentsStaffRelateEntity); + newDepartIds.add(departmentsStaffRelateEntity.getDepartmentId()); + } + + key = staff.getEmployeeId() + "_" + staffOccupation.getPosition(); + if(!mapEmployeeIdStaffOccs.containsKey(key)){ + + mapEmployeeIdStaffOccs.put(key + , staffOccupation); + newPositions.add(departmentStaffBo.getPosition()); + } + }else{ + String key1 = entity.getId() + "_" + staffOccupation.getPosition(); + if(mapStaffOccs != null && mapStaffOccs.containsKey(key1)){//职位信息已存在,更新 + StaffOccupationEntity staffOccupation1 = mapStaffOccs.get(key1); + staffOccupation.setId(staffOccupation1.getId());//职位信息 + staffOccupation.setUpdateTime(new Date()); + updateStaffOcc.add(staffOccupation); + mapStaffOccs.remove(key1); + mapHaveStaffOccs.put(key1, staffOccupation); + }else if(!mapHaveStaffOccs.containsKey(key1)){//职位信息不存在,新建 + addStaffOcc.add(staffOccupation); + mapHaveStaffOccs.put(key1, staffOccupation); + } + + if(mapDepStaffs != null && mapDepStaffs.containsKey(departmentsStaffRelateEntity.getKey())){//对应关系已经存在 + DepartmentsStaffRelateEntity staffRelateEntityentity1 = mapDepStaffs.get(departmentsStaffRelateEntity.getKey()); + if(staffRelateEntityentity1.getIsLeader().intValue() != departmentsStaffRelateEntity.getIsLeader().intValue()){ + departmentsStaffRelateEntity.setId(staffRelateEntityentity1.getId()); + departmentsStaffRelateEntity.setUpdateTime(new Date()); + updateDepartStaff.add(departmentsStaffRelateEntity); + + } + mapDepStaffs.remove(departmentsStaffRelateEntity.getKey()); + }else{//不存在对应关系 + addDepartStaff.add(departmentsStaffRelateEntity); + } + } + }else{//新的员工信息 + addStaffs.add(staff); + + if(!mapMorDepartStaffs.containsKey(departmentStaffBo.getEmployeeId())){ + mapMorDepartStaffs.put(departmentStaffBo.getEmployeeId(), staff); + } + + //新增部门人员对应关系,新增人员后插入数据库 + DepartmentsStaffRelateEntity departmentsStaffRelateEntity = new DepartmentsStaffRelateEntity(); + departmentsStaffRelateEntity.setDepartmentId(departmentInfo.getId()); + key = staff.getEmployeeId() + "_" + departmentsStaffRelateEntity.getDepartmentId(); + if(!mapEmployeeIdDeparts.containsKey(key)){ + + departmentsStaffRelateEntity.setIsLeader(departmentStaffBo.getIsLeader()); + mapEmployeeIdDeparts.put(key + , departmentsStaffRelateEntity); + newDepartIds.add(departmentsStaffRelateEntity.getDepartmentId()); + } + + //新增人员职位信息,新增人员后插入数据库 + StaffOccupationEntity staffOccupation = new StaffOccupationEntity(); + staffOccupation.setPosition(departmentStaffBo.getPosition());//职位信息 + key = staff.getEmployeeId() + "_" + staffOccupation.getPosition(); + if(!mapEmployeeIdStaffOccs.containsKey(key)){ + + staffOccupation.setEmployeeNo(departmentStaffBo.getEmployeeNo()); + staffOccupation.setStaffNo(departmentStaffBo.getEmployeeNo());//钉钉的员工工号 + staffOccupation.setStaffType(departmentStaffBo.getEmployeeType()); + staffOccupation.setStaffStatus(departmentStaffBo.getStatus()); + mapEmployeeIdStaffOccs.put(key + , staffOccupation); + newPositions.add(departmentStaffBo.getPosition()); + } + + } } - - } } - for (String key : departmentInfosBos.keySet()) { - DepartmentInfosBo departmentInfo = departmentInfosBos.get(key); - departmentsService.updateDepartmentInfo(departmentInfo); - } - if(mapDeparts.size() > 0){//有需要删除的部门信息 + if(mapDeparts != null && mapDeparts.size() > 0){//有需要删除的部门信息 + logger.info("删除部门信息个数{}", mapDeparts.size()); departmentsEntities = mapDeparts.values().stream().collect(Collectors.toList()); - departmentsService.delDepartments(departmentsEntities); + for(DepartmentsEntity entity:departmentsEntities) { + entity.setIsDelete(1); + entity.setUpdateTime(new Date()); + } + departmentsService.updateBatchById(departmentsEntities); + } + if(addDeparts.size() > 0){//有新增部门 + logger.info("新增部门信息个数{}", addDeparts.size()); + for (DepartmentsEntity entity:addDeparts + ) { + DepartmentInfosBo departmentInfo = mapDepartmentInfosBos.get(entity.getDepartmentId()); + entity.setDepartmentId(departmentInfo.getId()); + entity.setDepartmentName(departmentInfo.getName()); + entity.setDepartmentParentId(departmentInfo.getParentId()); + entity.setMemberCount(departmentInfo.getMemberCount()); + entity.setChatId(departmentInfo.getChatId()); + entity.setLeaderEmployeeId(departmentInfo.getLeaderEmployeeId()); + entity.setLeaderOpenId(departmentInfo.getLeaderOpenId()); + entity.setStatus(1); + } + departmentsService.saveBatch(addDeparts); } + if(updateDeparts.size() > 0){//有新增部门 + logger.info("更新部门信息个数{}", updateDeparts.size()); + for (DepartmentsEntity entity:updateDeparts + ) { + DepartmentInfosBo departmentInfo = mapDepartmentInfosBos.get(entity.getDepartmentId()); + entity.setDepartmentId(departmentInfo.getId()); + entity.setDepartmentName(departmentInfo.getName()); + entity.setDepartmentParentId(departmentInfo.getParentId()); + entity.setMemberCount(departmentInfo.getMemberCount()); + entity.setChatId(departmentInfo.getChatId()); + entity.setLeaderEmployeeId(departmentInfo.getLeaderEmployeeId()); + entity.setLeaderOpenId(departmentInfo.getLeaderOpenId()); + entity.setStatus(1); + } + departmentsService.updateBatchById(updateDeparts); + } + + if(addStaffs.size() > 0){//有新增部门 + logger.info("新增人员信息个数{}", addStaffs.size()); + staffService.saveBatch(addStaffs); + String key; + for (StaffEntity entity:addStaffs + ) { + for (String departId:newDepartIds + ) { + key = entity.getEmployeeId() + "_" + departId; + if(mapEmployeeIdDeparts.containsKey(key)){ + DepartmentsStaffRelateEntity departmentsStaffRelateEntity = + mapEmployeeIdDeparts.get(key); + departmentsStaffRelateEntity.setStaffId(entity.getId()); + addDepartStaff.add(departmentsStaffRelateEntity); + mapEmployeeIdDeparts.remove(key); + } + } + + for (String position:newPositions + ) { + key = entity.getEmployeeId() + "_" + position; + if(mapEmployeeIdStaffOccs.containsKey(key)){ + StaffOccupationEntity staffOccupation = mapEmployeeIdStaffOccs.get(key); + staffOccupation.setStaffId(entity.getId()); + addStaffOcc.add(staffOccupation); + mapEmployeeIdStaffOccs.remove(key); + } + } + } + } + + if(updateStaffs.size() > 0){//有新增部门 + logger.info("更新人员信息个数{}", updateStaffs.size()); + staffService.updateBatchById(updateStaffs); + } + + if(mapDepStaffs != null && mapDepStaffs.size() > 0){ + logger.info("删除人员部门个数{}", mapDepStaffs.size()); + departmentsStaffRelateEntities = mapDepStaffs.values().stream().collect(Collectors.toList()); + for (DepartmentsStaffRelateEntity entity:departmentsStaffRelateEntities + ) { + entity.setIsDelete(1); + } + departmentsStaffRelateService.updateBatchById(departmentsStaffRelateEntities); + } + + if(addDepartStaff.size() > 0){//有新增部门 + logger.info("新增部门人员对应关系个数{}", addDepartStaff.size()); + departmentsStaffRelateService.saveBatch(addDepartStaff); + + } + + if(updateDepartStaff.size() > 0){//有新增部门 + logger.info("更新部门人员对应关系个数{}", updateDepartStaff.size()); + departmentsStaffRelateService.updateBatchById(updateDepartStaff); + } + + if(addStaffOcc.size() > 0){//有新增部门 + logger.info("新增人员职位对应关系个数{}", addStaffOcc.size()); + staffOccupationService.saveBatch(addStaffOcc); + + } + + if(updateStaffOcc.size() > 0){//有新增部门 + logger.info("更新人员对职位应关系个数{}", updateStaffOcc.size()); + staffOccupationService.updateBatchById(updateStaffOcc); + } + + if(mapStaffs != null && mapStaffs.size() > 0){//离职人员 + logger.info("离职人员可能个数{}", mapStaffs.size()); + if(mapStaffOccs != null && mapStaffOccs.size() > 0){ + logger.info("离职人员对应的职位信息个数{}", mapStaffs.size()); + staffEntities = mapStaffs.values().stream().collect(Collectors.toList()); + staffOccupationEntities.clear(); + for (StaffEntity entity:staffEntities + ) { + if(mapStaffOccs.containsKey(entity.getId())){ + StaffOccupationEntity staffOccupationEntity = mapStaffOccs.get(entity.getId()); + if(staffOccupationEntity.getStaffStatus().intValue() == 0){ + staffOccupationEntity.setStaffStatus(1); + staffOccupationEntity.setUpdateTime(new Date()); + staffOccupationEntities.add(staffOccupationEntity); + } + } + } + logger.info("离职人员实际个数{}", staffOccupationEntities.size()); + staffOccupationService.updateBatchById(staffOccupationEntities); + } + } }else{ logger.info("部门信息为空"); } diff --git a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java index 990fe21b..4d55936d 100644 --- a/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java +++ b/src/main/java/com/lz/modules/job/model/responseBo/DepartmentStaffBo.java @@ -82,6 +82,10 @@ public class DepartmentStaffBo implements Serializable { */ private Integer isLeader; + /*** + * 是否为老板 + */ + private Integer isBoss; diff --git a/src/main/resources/mapper/generator/StaffDao.xml b/src/main/resources/mapper/generator/StaffDao.xml index 102b4ab8..0c17f05a 100644 --- a/src/main/resources/mapper/generator/StaffDao.xml +++ b/src/main/resources/mapper/generator/StaffDao.xml @@ -256,7 +256,7 @@ ),1,0) department_leader from lz_staff ls,lz_staff_occupation lso - where lso.staff_id=ls.id and ls.is_delete=0 + where lso.staff_id=ls.id and ls.is_delete=0 and lso.is_delete=0 and lso.staff_status=#{staffStatus} and ls.name like concat('%',#{name},'%') @@ -480,7 +480,7 @@ from (select staff.id as staff_id, staff.name as name, relate.is_leader as department_leader from lz_departments_staff_relate relate join lz_staff staff on staff.id = relate.staff_id where relate.department_id = #{departmentId} and relate.is_delete=0 and staff.is_delete=0 group by relate.staff_id) jj - join lz_staff_occupation occ on jj.staff_id=occ.staff_id where occ.staff_status=0 and occ.is_delete=0 + join lz_staff_occupation occ on jj.staff_id=occ.staff_id where occ.staff_status=0 and occ.is_delete=0 GROUP BY jj.staff_id diff --git a/src/main/resources/mapper/generator/StaffOccupationDao.xml b/src/main/resources/mapper/generator/StaffOccupationDao.xml index c5e70cfc..7b0240ae 100644 --- a/src/main/resources/mapper/generator/StaffOccupationDao.xml +++ b/src/main/resources/mapper/generator/StaffOccupationDao.xml @@ -68,4 +68,8 @@ + + From 90fd42b7f661afca19143ababb695c62fe37071f Mon Sep 17 00:00:00 2001 From: wulin Date: Thu, 26 Nov 2020 18:04:23 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/mapper/generator/StaffDao.xml | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/resources/mapper/generator/StaffDao.xml b/src/main/resources/mapper/generator/StaffDao.xml index 0c17f05a..546fa963 100644 --- a/src/main/resources/mapper/generator/StaffDao.xml +++ b/src/main/resources/mapper/generator/StaffDao.xml @@ -248,43 +248,43 @@ From 65753426df35e69a24d3f91e92e443c42deaa594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BB=BA=E8=B6=85?= <3182967682@qq.com> Date: Tue, 1 Dec 2020 13:56:39 +0800 Subject: [PATCH 07/19] fix --- pom.xml | 2 +- .../controller/AssessManagerController.java | 5 +- .../controller/ChartController.java | 15 +-- .../controller/ExportController.java | 107 ++++++++++++++++++ .../mapper/generator/StaffOccupationDao.xml | 2 +- 5 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/lz/modules/performance/controller/ExportController.java diff --git a/pom.xml b/pom.xml index 1dce0895..5fc6ee94 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 2.9.9 2.8.5 1.2.60 - 4.1.1 + 5.2.3 1.18.4 3.17 diff --git a/src/main/java/com/lz/modules/performance/controller/AssessManagerController.java b/src/main/java/com/lz/modules/performance/controller/AssessManagerController.java index ae350613..2dbee8f0 100644 --- a/src/main/java/com/lz/modules/performance/controller/AssessManagerController.java +++ b/src/main/java/com/lz/modules/performance/controller/AssessManagerController.java @@ -6,6 +6,7 @@ import com.lz.common.utils.StringUtil; import com.lz.modules.app.dto.StaffSimpleDto; import com.lz.modules.flow.dao.FlowStartMapper; import com.lz.modules.flow.entity.FlowStart; +import com.lz.modules.flow.service.EvaluationStartStaffService; import com.lz.modules.performance.req.AssessChangeReq; import com.lz.modules.performance.req.AssessListReq; import com.lz.modules.performance.req.AssessDetailReq; @@ -47,6 +48,7 @@ public class AssessManagerController extends AbstractController{ private ChartResultService chartResultService; + @PostMapping("assess/manager/list") @ApiOperation("获取考核列表") @ApiResponses({@ApiResponse(code = 200,message = "成功",response = AssessManagerListRes.class)}) @@ -115,9 +117,6 @@ public class AssessManagerController extends AbstractController{ } - - - @GetMapping("assess/manager/delete") @ApiOperation("删除考核任务") @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ChartStatisticalRes.class)}) diff --git a/src/main/java/com/lz/modules/performance/controller/ChartController.java b/src/main/java/com/lz/modules/performance/controller/ChartController.java index 6c2c1c33..344ca94f 100644 --- a/src/main/java/com/lz/modules/performance/controller/ChartController.java +++ b/src/main/java/com/lz/modules/performance/controller/ChartController.java @@ -1,16 +1,9 @@ package com.lz.modules.performance.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.google.common.collect.Lists; import com.lz.common.utils.PageUtils; import com.lz.common.utils.R; -import com.lz.common.utils.StringUtil; -import com.lz.modules.app.enums.ResultRecordStatusEnum; import com.lz.modules.app.resp.OwnResultResp; -import com.lz.modules.equipment.entity.model.BasePage; import com.lz.modules.flow.dao.FlowStartMapper; -import com.lz.modules.flow.entity.FlowStart; -import com.lz.modules.flow.service.FlowStartService; import com.lz.modules.performance.req.ChartResultReq; import com.lz.modules.performance.req.ChartStartsReq; import com.lz.modules.performance.req.OwnResultReq; @@ -19,17 +12,13 @@ import com.lz.modules.performance.res.ChartStatisticalRes; import com.lz.modules.performance.res.ResultRankListRes; import com.lz.modules.performance.service.ChartResultService; import com.lz.modules.sys.controller.AbstractController; -import com.lz.modules.sys.entity.app.ResultRecord; import com.lz.modules.sys.service.app.ResultRecordService; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.function.Function; -import java.util.function.Supplier; +import java.util.List; /** * @Author: djc @@ -110,6 +99,4 @@ public class ChartController extends AbstractController{ } - - } diff --git a/src/main/java/com/lz/modules/performance/controller/ExportController.java b/src/main/java/com/lz/modules/performance/controller/ExportController.java new file mode 100644 index 00000000..23262d09 --- /dev/null +++ b/src/main/java/com/lz/modules/performance/controller/ExportController.java @@ -0,0 +1,107 @@ +package com.lz.modules.performance.controller; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; +import com.lz.common.utils.PageUtils; +import com.lz.common.utils.R; +import com.lz.common.utils.StringUtil; +import com.lz.modules.performance.req.ChartResultReq; +import com.lz.modules.performance.service.ChartResultService; +import com.lz.modules.sys.entity.app.ResultRecord; +import io.swagger.annotations.ApiParam; +import io.swagger.models.auth.In; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: djc + * @Desc: + * @Date: 2020/12/1 10:26 + */ +@RestController +@RequestMapping("/performance") +@Slf4j +public class ExportController { + @Autowired + private ChartResultService chartResultService; + + + @GetMapping("/export/levelDetail") + public R levelDetail(@RequestBody @ApiParam(name = "body",value = "body请求体",required = true) ChartResultReq req,HttpServletResponse response){ + PageUtils pageUtils; + try { + //Long userId = getUserId(); + Long userId = 313L; + req.setLoginUserId(userId); + pageUtils = chartResultService.selectChartDetailList(req); + } catch (Exception e) { + log.error("获取报表等级详情数据异常" ,e); + return R.error(e.getMessage()); + } + List list = pageUtils.getList(); + ExcelWriter writer = ExcelUtil.getWriter(); + ResultRecord resultRecord = new ResultRecord(); + + writer.addHeaderAlias("name", "姓名"); + writer.addHeaderAlias("age", "年龄"); + writer.merge(1, "员工信息表"); + writer.write(list, true); + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + String name = null; + try { + //name = new String("XXX国际贸易公司".getBytes("UTF-8")); + name = new String("XXX国际贸易公司".getBytes("UTF-8"),"utf-8"); + System.out.println("-----" + name); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls"); + ServletOutputStream out = null; + try { + out = response.getOutputStream(); + writer.flush(out, true); + } catch (IOException e) { + e.printStackTrace(); + } finally { + writer.close(); + } + IoUtil.close(out); + return R.ok().put("data",pageUtils); + + + } + + + + private void buildData(Class data,List tags,ExcelWriter writer){ + if(data == null || CollectionUtils.isEmpty(tags)){ + log.info("导出excel-实体属性或数据为空!"); + return; + } + Field[] fields = data.getDeclaredFields(); + if(fields.length != tags.size()){ + log.info("导出excel-实体属性与数据大小不一致!"); + return; + } + System.out.println(fields.length); + for(int i=0; i + diff --git a/src/main/resources/mapper/generator/DepartmentsDao.xml b/src/main/resources/mapper/generator/DepartmentsDao.xml index ba3c028f..7928da60 100644 --- a/src/main/resources/mapper/generator/DepartmentsDao.xml +++ b/src/main/resources/mapper/generator/DepartmentsDao.xml @@ -188,4 +188,22 @@ + + + + + + diff --git a/src/main/resources/mapper/generator/StaffOccupationDao.xml b/src/main/resources/mapper/generator/StaffOccupationDao.xml index 9821cd63..d9015dff 100644 --- a/src/main/resources/mapper/generator/StaffOccupationDao.xml +++ b/src/main/resources/mapper/generator/StaffOccupationDao.xml @@ -72,4 +72,14 @@ select * from lz_staff_occupation where is_delete=0 + + From 9428491ab889c7fd8f161a1724707f10640c0bb1 Mon Sep 17 00:00:00 2001 From: wulin Date: Wed, 2 Dec 2020 10:03:37 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=8A=A0=E4=BA=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lz/modules/flow/service/impl/FlowStartServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java index 727a3f44..9a51685e 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java @@ -857,6 +857,7 @@ public class FlowStartServiceImpl extends ServiceImpl Date: Wed, 2 Dec 2020 10:11:09 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E7=BA=BF=E7=A8=8B=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FlowStartServiceImpl.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java index 9a51685e..e15a8364 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/FlowStartServiceImpl.java @@ -2,22 +2,13 @@ package com.lz.modules.flow.service.impl; import ch.qos.logback.classic.Logger; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.common.collect.Lists; import com.lz.common.emun.ChartOptType; import com.lz.common.emun.CheckStaffType; import com.lz.common.emun.WorkMsgTypeEnum; import com.lz.common.utils.R; -import com.lz.common.utils.StringUtil; -import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; import com.lz.modules.app.entity.StaffEntity; import com.lz.modules.app.entity.StaffSimpleInfo; -import com.lz.modules.app.enums.FlowApprovalRoleTypeEnums; -import com.lz.modules.app.enums.FlowRecordStatusEnums; -import com.lz.modules.app.enums.RoleEnums; -import com.lz.modules.app.service.DepartmentsService; -import com.lz.modules.app.service.DepartmentsStaffRelateService; import com.lz.modules.app.service.StaffService; -import com.lz.modules.flow.dao.EvaluationStartStaffMapper; import com.lz.modules.flow.dao.FlowStartMapper; import com.lz.modules.flow.entity.*; import com.lz.modules.flow.model.*; @@ -28,22 +19,15 @@ import com.lz.modules.sys.entity.app.ResultDetail; import com.lz.modules.sys.entity.app.ResultRecord; import com.lz.modules.sys.service.app.ResultDetailService; import com.lz.modules.sys.service.app.ResultRecordService; -import com.lz.modules.third.entity.ThirdAppConfig; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.map.HashedMap; -import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.interceptor.TransactionAspectSupport; -import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.function.Function; import java.util.stream.Collectors; @@ -839,12 +823,12 @@ public class FlowStartServiceImpl extends ServiceImpl resultRecords; + List resultStarts; List noticeStaff; public ThreadInitFlowRecord(List resultRecords, List noticeStaff){ - this.resultRecords = resultRecords; + this.resultStarts = resultRecords; this.noticeStaff = noticeStaff; } @@ -853,13 +837,14 @@ public class FlowStartServiceImpl extends ServiceImpl Date: Wed, 2 Dec 2020 11:41:20 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=BA=BF=E4=B8=8A?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=82=AC=E5=8A=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lz/common/emun/WorkMsgTypeEnum.java | 2 +- .../controller/ResultRecordController.java | 29 ++++++++++++++ .../lz/modules/flow/dao/FlowRecordMapper.java | 4 +- .../flow/service/FlowRecordService.java | 2 + .../service/impl/FlowRecordServiceImpl.java | 5 +++ .../job/business/DingtalkBusiness.java | 38 ++++++++++++++++++- .../mapper/flow/FlowRecordMapper.xml | 5 +++ 7 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java b/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java index 3d9806fa..806bdcdb 100644 --- a/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java +++ b/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java @@ -14,7 +14,7 @@ public enum WorkMsgTypeEnum { LEADER_PASS(2, "绩效已打分", "去提交给人事", "# 绩效已打分\n ## 你的绩效已经打分"), //绩效通过人事,老板审核的最终审核通知 PASS(3, "绩效通过", "去查看", "# 绩效通过\n ## 你的绩效已经通过"), - URGING(4, "绩效催办", "去审批", "# 绩效催办\n ## @提醒您审批"), + URGING(4, "绩效催办", "去审批", "# 绩效催办\n ## @的绩效需您处理"), END(5, "绩效终止", "去查看", "# 绩效终止\n ## @,你的绩效终止"), START_WORK(6, "绩效考评待办事项", "去查看", "# 绩效目标制定\n ## @,你的绩效需要制定目标"), START_SCORE(7, "绩效考评待办事项", "去查看", "# 绩效结果输入\n ## @,你的绩效需要输入结果"), diff --git a/src/main/java/com/lz/modules/app/controller/ResultRecordController.java b/src/main/java/com/lz/modules/app/controller/ResultRecordController.java index 01d8012a..ce6fc40a 100644 --- a/src/main/java/com/lz/modules/app/controller/ResultRecordController.java +++ b/src/main/java/com/lz/modules/app/controller/ResultRecordController.java @@ -20,6 +20,7 @@ import com.lz.modules.flow.entity.*; import com.lz.modules.flow.model.*; import com.lz.modules.flow.req.ResultDetailReq; import com.lz.modules.flow.service.*; +import com.lz.modules.job.business.DingtalkBusiness; import com.lz.modules.sys.controller.AbstractController; import com.lz.modules.sys.entity.SysUserEntity; import com.lz.modules.sys.entity.app.ResultComment; @@ -105,6 +106,9 @@ public class ResultRecordController extends AbstractController { @Autowired private FlowChartDetailRecordService flowChartDetailRecordService; + @Autowired + private DingtalkBusiness dingtalkBusiness; + /** * 列表 */ @@ -331,6 +335,31 @@ public class ResultRecordController extends AbstractController { return R.ok().put("lzResultRecord", lzResultRecord); } + /** + * 信息 + */ + @GetMapping("/urging") + @ApiOperation("绩效意见催办-吴林") + @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "绩效id")}) + @ApiResponses({@ApiResponse(code = 200, message = "成功", response = R.class)}) + public R getDetail(@RequestParam Long id) { + ResultRecord lzResultRecord = lzResultRecordService.selectResultRecordById(id); + //获取当前节点,谁在处理 + List flowRecords = flowRecordService.selectFlowRecordsByRecordIdAndStatus(id, 2); + if(flowRecords.size() > 0){ + List ids = flowRecords.stream().map(new Function() { + @Override + public Long apply(FlowRecord flowRecord) { + return flowRecord.getApprovalStaffId(); + } + }).collect(Collectors.toList()); + List staffs = staffService.selectNamesByIds(ids); + dingtalkBusiness.sendNoticeMsg(lzResultRecord, staffs); + return R.ok("催办成功"); + } + return R.error("无可催办人员"); + } + /** * 信息 */ diff --git a/src/main/java/com/lz/modules/flow/dao/FlowRecordMapper.java b/src/main/java/com/lz/modules/flow/dao/FlowRecordMapper.java index d417c7c5..fff7c877 100644 --- a/src/main/java/com/lz/modules/flow/dao/FlowRecordMapper.java +++ b/src/main/java/com/lz/modules/flow/dao/FlowRecordMapper.java @@ -90,5 +90,7 @@ public interface FlowRecordMapper extends BaseMapper { List selectSkipFlowRecordsById(@Param("recordId") Long recordId); - List selectFirstFlowRecordsByIdAndFlowIndex(Long recordId, int flowIndex, int status); + List selectFirstFlowRecordsByIdAndFlowIndex(@Param("recordId") Long recordId, @Param("flowIndex") int flowIndex, @Param("status") int status); + + List selectFlowRecordsByRecordIdAndStatus(@Param("recordId") Long recordId, @Param("status") int status); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/flow/service/FlowRecordService.java b/src/main/java/com/lz/modules/flow/service/FlowRecordService.java index 99c44187..4503002a 100644 --- a/src/main/java/com/lz/modules/flow/service/FlowRecordService.java +++ b/src/main/java/com/lz/modules/flow/service/FlowRecordService.java @@ -86,4 +86,6 @@ public interface FlowRecordService extends IService { List selectSkipFlowRecordsById(Long recordId); List selectFirstFlowRecordsByIdAndFlowIndex(Long recordId, int flowIndex, int status); + + List selectFlowRecordsByRecordIdAndStatus(Long recordId, int status); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowRecordServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowRecordServiceImpl.java index 412a65e5..5a19246b 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/FlowRecordServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/FlowRecordServiceImpl.java @@ -231,4 +231,9 @@ public class FlowRecordServiceImpl extends ServiceImpl selectFlowRecordsByRecordIdAndStatus(Long recordId, int status){ + return flowRecordMapper.selectFlowRecordsByRecordIdAndStatus(recordId, status); + } + } diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java index 5127f532..50127d1a 100644 --- a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java +++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java @@ -104,6 +104,7 @@ public class DingtalkBusiness { @Resource StaffDao staffDao; + static String homeUrl = "https://lzmanagement.ldxinyong.com/digitization"; @Value("${dingtalk.appid}") private String appid; @@ -585,6 +586,39 @@ public class DingtalkBusiness { } } + public String sendNoticeMsg(ResultRecord lzResultRecord, List staffs) { + + ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid); + String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig); + if(token != null && token.length() > 0){ + String url = homeUrl; + if(url.contains("?")){ + url += "&halokit=" + System.currentTimeMillis(); + }else{ + url += "?halokit=" + System.currentTimeMillis(); + } + url += ("&detail=1&id=" + lzResultRecord.getId()); + url = URLEncoder.encode(url); + + + url = "dingtalk://dingtalkclient/action/openapp?corpid=" + thirdAppConfig.getCorpId() + + "&container_type=work_platform&app_id=0_" + + appid + "&redirect_type=jump&redirect_url=" + url; + logger.info("推送消息个数{}", staffs.size()); + for (StaffEntity info: + staffs) { + logger.info("发送消息给{},url:{}", info, url); + String content = WorkMsgTypeEnum.URGING.getContent().replace("@", lzResultRecord.getStaffName()); + dingTalkUtil.sendSingleActionCardMSG(appid, info, WorkMsgTypeEnum.URGING.getTitle(), + content, WorkMsgTypeEnum.URGING.getBtnText(), url, token); + } + return "OK"; + + }else{ + return "token无效"; + } + } + public String sendWorkMSG(String appid, Long fromStaffid, long toStaffid, int type) { //获取Token StaffEntity toStaffEntity = staffService.selectStaffById(toStaffid); @@ -741,13 +775,15 @@ public class DingtalkBusiness { return R.error("未授权登录"); } + + public class ThreadSendMessage implements Runnable{ List toStaffids; StaffSimpleInfo fromStaff = null; List recordIds; WorkMsgTypeEnum workMsgTypeEnum; String appid; - String hostUrl = "https://lzmanagement.ldxinyong.com/digitization"; + String hostUrl = homeUrl; public ThreadSendMessage(StaffSimpleInfo fromStaff, List toStaffids, WorkMsgTypeEnum typeEnum, String appid){ this.fromStaff = fromStaff; this.toStaffids = toStaffids; diff --git a/src/main/resources/mapper/flow/FlowRecordMapper.xml b/src/main/resources/mapper/flow/FlowRecordMapper.xml index 22201063..7dca5bc4 100644 --- a/src/main/resources/mapper/flow/FlowRecordMapper.xml +++ b/src/main/resources/mapper/flow/FlowRecordMapper.xml @@ -322,5 +322,10 @@ select * from lz_flow_record where is_delete = 0 and flow_index =]]> #{flowIndex} and record_id = #{recordId} and status=#{status} order by flow_index asc + + From 2ff0b3fb92e705b6f4830a31406650d0a028de70 Mon Sep 17 00:00:00 2001 From: wulin Date: Wed, 2 Dec 2020 11:49:00 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E5=82=AC=E5=8A=9E=E6=96=87=E6=A1=88?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java | 2 +- .../lz/modules/app/controller/ResultRecordController.java | 2 +- .../com/lz/modules/job/business/DingtalkBusiness.java | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java b/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java index 806bdcdb..0f94627a 100644 --- a/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java +++ b/src/main/java/com/lz/common/emun/WorkMsgTypeEnum.java @@ -14,7 +14,7 @@ public enum WorkMsgTypeEnum { LEADER_PASS(2, "绩效已打分", "去提交给人事", "# 绩效已打分\n ## 你的绩效已经打分"), //绩效通过人事,老板审核的最终审核通知 PASS(3, "绩效通过", "去查看", "# 绩效通过\n ## 你的绩效已经通过"), - URGING(4, "绩效催办", "去审批", "# 绩效催办\n ## @的绩效需您处理"), + URGING(4, "绩效催办", "去处理", "# 绩效催办\n ## @的绩效需您处理"), END(5, "绩效终止", "去查看", "# 绩效终止\n ## @,你的绩效终止"), START_WORK(6, "绩效考评待办事项", "去查看", "# 绩效目标制定\n ## @,你的绩效需要制定目标"), START_SCORE(7, "绩效考评待办事项", "去查看", "# 绩效结果输入\n ## @,你的绩效需要输入结果"), diff --git a/src/main/java/com/lz/modules/app/controller/ResultRecordController.java b/src/main/java/com/lz/modules/app/controller/ResultRecordController.java index ce6fc40a..1471fcc5 100644 --- a/src/main/java/com/lz/modules/app/controller/ResultRecordController.java +++ b/src/main/java/com/lz/modules/app/controller/ResultRecordController.java @@ -339,7 +339,7 @@ public class ResultRecordController extends AbstractController { * 信息 */ @GetMapping("/urging") - @ApiOperation("绩效意见催办-吴林") + @ApiOperation("绩效催办-吴林") @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "绩效id")}) @ApiResponses({@ApiResponse(code = 200, message = "成功", response = R.class)}) public R getDetail(@RequestParam Long id) { diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java index 50127d1a..64a11be6 100644 --- a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java +++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java @@ -608,7 +608,13 @@ public class DingtalkBusiness { for (StaffEntity info: staffs) { logger.info("发送消息给{},url:{}", info, url); - String content = WorkMsgTypeEnum.URGING.getContent().replace("@", lzResultRecord.getStaffName()); + String content = null; + if(!lzResultRecord.getStaffName().equals(info.getName())){ + content = WorkMsgTypeEnum.URGING.getContent().replace("@", lzResultRecord.getStaffName()); + }else{ + content = WorkMsgTypeEnum.URGING.getContent().replace("@", "您"); + } + dingTalkUtil.sendSingleActionCardMSG(appid, info, WorkMsgTypeEnum.URGING.getTitle(), content, WorkMsgTypeEnum.URGING.getBtnText(), url, token); } From 36036f61f1e5ca1435fd5057753681e950ca9f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BB=BA=E8=B6=85?= <3182967682@qq.com> Date: Wed, 2 Dec 2020 15:56:19 +0800 Subject: [PATCH 15/19] fix --- .../controller/ExportController.java | 86 +++++++++++++------ .../performance/dto/LevelDetailExportDto.java | 37 ++++++++ .../modules/performance/dto/StaffTypeDto.java | 12 +++ .../performance/res/LevelDetailExportRes.java | 12 +-- .../service/impl/ChartResultServiceImpl.java | 62 +++++++++++-- .../sys/dao/app/ResultRecordMapper.java | 3 +- .../mapper/app/ResultRecordMapper.xml | 2 +- .../mapper/generator/StaffOccupationDao.xml | 4 +- 8 files changed, 170 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/lz/modules/performance/dto/LevelDetailExportDto.java diff --git a/src/main/java/com/lz/modules/performance/controller/ExportController.java b/src/main/java/com/lz/modules/performance/controller/ExportController.java index a29bee57..9545b7a2 100644 --- a/src/main/java/com/lz/modules/performance/controller/ExportController.java +++ b/src/main/java/com/lz/modules/performance/controller/ExportController.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; +import cn.hutool.poi.excel.StyleSet; import com.google.common.collect.Lists; import com.lz.common.utils.PageUtils; import com.lz.common.utils.R; @@ -21,6 +22,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -38,7 +41,7 @@ import java.util.List; * @Date: 2020/12/1 10:26 */ @RestController -@RequestMapping("/performance") +@RequestMapping("/file") @Slf4j @Api(value="导出excel接口", tags={"导出表格"}) public class ExportController { @@ -46,39 +49,21 @@ public class ExportController { private ChartResultService chartResultService; - @PostMapping("/export/levelDetail") + @GetMapping("/export/levelDetail") @ApiOperation("导出等级详情") - public void levelDetail(@RequestBody @ApiParam(name = "body",value = "body请求体",required = true) ChartResultReq req,HttpServletResponse response){ - List levelDetailExportRes = Lists.newArrayList(); + public void levelDetail(ChartResultReq req,HttpServletResponse response){ try { //Long userId = getUserId(); Long userId = 313L; req.setLoginUserId(userId); - levelDetailExportRes = chartResultService.selectLevelDetailList(req); + //获取数据 + List data = chartResultService.selectLevelDetailList(req); + //导出 + buildExcelExport(data,response); + } catch (Exception e) { - log.error("获取报表等级详情数据异常" ,e); + log.error("导出等级详情异常,e: ",e); } - List rowHead = CollUtil.newArrayList("序号", "工号", "员工姓名", "当月状态", "一级部门", "二级部门", "三级部门", "职位", "员工月度绩效考核评分","员工月度绩效考核结果等级"); - List data = Lists.newArrayList(); - - ExcelWriter writer = ExcelUtil.getWriter(); - buildData(LevelDetailExportRes.class,null,writer); - writer.merge(1, "员工信息表"); - writer.write(data, true); - - response.setContentType("application/vnd.ms-excel;charset=utf-8"); - String name = "test测试"; - response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls"); - ServletOutputStream out = null; - try { - out = response.getOutputStream(); - writer.flush(out, true); - } catch (IOException e) { - e.printStackTrace(); - } finally { - writer.close(); - } - IoUtil.close(out); } @@ -103,4 +88,51 @@ public class ExportController { writer.addHeaderAlias(field.getName(), tags.get(i)); } } + + private void buildExcelExport(List data, HttpServletResponse response){ + //设置表头表尾及数据 + List rowHead = CollUtil.newArrayList("序号", "工号", "员工姓名", "当月状态", "一级部门", "二级部门", "三级部门", "职位", "员工月度绩效考核评分","员工月度绩效考核结果等级"); + ExcelWriter writer = ExcelUtil.getWriter(); + writer.setColumnWidth(-1,15); + writer.passRows(4); + buildData(LevelDetailExportRes.class,rowHead,writer); + writer.merge(0,2,0,9,"绩效考核总表",false); + writer.merge(3,3,0,1,"考核月份",false); + writer.write(data, true); + writer.merge(7 + data.size(),8 + data.size(),0,0,"签字",false); + + //设置下拉框数据 + String[] values = { "当月入职", "当月离职", "当月跨部门调动", "当月转正", "已转正", "试用期"}; + Sheet sheet = writer.getSheet(); + int firstRow = 4; + int lastRow = 4; + int firstCol = 3; + int lastCol = 3; + CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); + StyleSet styleSet = writer.getStyleSet(); + CellStyle cellStyle = styleSet.getCellStyle(); + cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); + DataValidationHelper helper = sheet.getDataValidationHelper(); + DataValidationConstraint constraint = helper.createExplicitListConstraint(values); + DataValidation dataValidation = helper.createValidation(constraint, addressList); + writer.addValidationData(dataValidation); + + //响应 + String name = "test测试"; + response.setContentType("application/vnd.ms-excel;charset=utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls"); + ServletOutputStream out = null; + try { + out = response.getOutputStream(); + writer.flush(out, true); + } + catch (IOException e) { + log.error("生成excel文档异常,e: ",e); + } + finally { + writer.close(); + } + IoUtil.close(out); + } + } diff --git a/src/main/java/com/lz/modules/performance/dto/LevelDetailExportDto.java b/src/main/java/com/lz/modules/performance/dto/LevelDetailExportDto.java new file mode 100644 index 00000000..363cf9ec --- /dev/null +++ b/src/main/java/com/lz/modules/performance/dto/LevelDetailExportDto.java @@ -0,0 +1,37 @@ +package com.lz.modules.performance.dto; + +import lombok.Data; + +/** + * @Author: djc + * @Desc: + * @Date: 2020/12/2 10:15 + */ +@Data +public class LevelDetailExportDto { + //序号 + private Long id; + //工号 + private String staffNo; + //姓名 + private String staffName; + //员工id + private Long staffId; + //当月状态 + private int staffType; + //所属部门 + private Long departmentId; + //一级部门 + private String departmentOne; + //二级部门 + private String departmentTwo; + //三级部门 + private String departmentThree; + //职位 + private String position; + //员工月度绩效考核评分 + private String allScore; + //员工月度绩效考核结果等级 + private String scoreLevel; + +} diff --git a/src/main/java/com/lz/modules/performance/dto/StaffTypeDto.java b/src/main/java/com/lz/modules/performance/dto/StaffTypeDto.java index f833b1f6..5822caf5 100644 --- a/src/main/java/com/lz/modules/performance/dto/StaffTypeDto.java +++ b/src/main/java/com/lz/modules/performance/dto/StaffTypeDto.java @@ -2,6 +2,8 @@ package com.lz.modules.performance.dto; import lombok.Data; +import java.util.Date; + /** * @Author: djc * @Desc: @@ -13,4 +15,14 @@ public class StaffTypeDto { private int staffType; //员工id private Long staffId; + //职位 + private String position; + //人员状态 + private Long staffStatus; + //入职日期 + private Date entryTime; + //转正日期 + private Date officialTime; + //离职时间 + private Date resignationTime; } diff --git a/src/main/java/com/lz/modules/performance/res/LevelDetailExportRes.java b/src/main/java/com/lz/modules/performance/res/LevelDetailExportRes.java index e43acdc7..c418ea1c 100644 --- a/src/main/java/com/lz/modules/performance/res/LevelDetailExportRes.java +++ b/src/main/java/com/lz/modules/performance/res/LevelDetailExportRes.java @@ -15,20 +15,16 @@ public class LevelDetailExportRes { private String staffNo; //姓名 private String staffName; - //员工id - private Long staffId; //当月状态 private int staffType; - //所属部门 - private Long departmentId; //一级部门 - private int departmentOne; + private String departmentOne; //二级部门 - private int departmentTwo; + private String departmentTwo; //三级部门 - private int departmentThree; + private String departmentThree; //职位 - private String departmentName; + private String position; //员工月度绩效考核评分 private String allScore; //员工月度绩效考核结果等级 diff --git a/src/main/java/com/lz/modules/performance/service/impl/ChartResultServiceImpl.java b/src/main/java/com/lz/modules/performance/service/impl/ChartResultServiceImpl.java index 17ee857b..6629a595 100644 --- a/src/main/java/com/lz/modules/performance/service/impl/ChartResultServiceImpl.java +++ b/src/main/java/com/lz/modules/performance/service/impl/ChartResultServiceImpl.java @@ -12,10 +12,7 @@ import com.lz.common.utils.StringUtil; import com.lz.modules.app.entity.DepartmentsEntity; import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; import com.lz.modules.app.entity.StaffEntity; -import com.lz.modules.app.service.DepartmentsService; -import com.lz.modules.app.service.DepartmentsStaffRelateService; -import com.lz.modules.app.service.StaffOccupationService; -import com.lz.modules.app.service.StaffService; +import com.lz.modules.app.service.*; import com.lz.modules.flow.dao.EvaluationGroupMapper; import com.lz.modules.flow.dao.FlowChartMapper; import com.lz.modules.flow.dao.FlowStartMapper; @@ -24,6 +21,7 @@ import com.lz.modules.flow.entity.FlowStart; import com.lz.modules.flow.service.EvaluationGroupService; import com.lz.modules.flow.service.FlowChartService; import com.lz.modules.flow.service.FlowStartService; +import com.lz.modules.performance.dto.LevelDetailExportDto; import com.lz.modules.performance.dto.StaffTypeDto; import com.lz.modules.performance.enums.ResultFlowProcessEnum; import com.lz.modules.performance.req.AssessDetailReq; @@ -40,6 +38,8 @@ import com.lz.modules.sys.entity.app.ResultRecord; import com.lz.modules.sys.service.app.ResultRecordService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -80,6 +80,8 @@ public class ChartResultServiceImpl implements ChartResultService { private EvaluationGroupMapper evaluationGroupMapper; @Autowired private StaffOccupationService staffOccupationService; + @Autowired + private StaffWorkTransferRecordService staffWorkTransferRecordService; private static final Long processId = 1L; @@ -243,18 +245,60 @@ public class ChartResultServiceImpl implements ChartResultService { @Override public List selectLevelDetailList(ChartResultReq req) { List mandepartmentIds = getMandepartmentIds(req.getDepartmentIds(), req.getLoginUserId()); - List levelDetailExportRes = resultRecordMapper.selectLevelDetailList(mandepartmentIds, req.getStartId(), req.getScoreLevel()); + List levelDetailExportDtos = resultRecordMapper.selectLevelDetailList(mandepartmentIds, req.getStartId(), req.getScoreLevel()); - if(CollectionUtils.isEmpty(levelDetailExportRes)){ + if(CollectionUtils.isEmpty(levelDetailExportDtos)){ return Collections.EMPTY_LIST; } - List staffIds = levelDetailExportRes.stream().map(LevelDetailExportRes::getStaffId).collect(Collectors.toList()); - List depIds = levelDetailExportRes.stream().map(levelDetailExportRes1 -> levelDetailExportRes1.getDepartmentId().toString()).collect(Collectors.toList()); + List staffIds = levelDetailExportDtos.stream().map(LevelDetailExportDto::getStaffId).collect(Collectors.toList()); + List depIds = levelDetailExportDtos.stream().map(levelDetailExportDto -> levelDetailExportDto.getDepartmentId().toString()).collect(Collectors.toList()); List staffTypeDtos = staffOccupationService.selectStaffTypesByStaffIds(staffIds); + //状态 + Map types = Maps.newHashMap(); + //职位 + Map positions = Maps.newHashMap(); + + for(StaffTypeDto dto: staffTypeDtos){ + types.put(dto.getStaffId(),dto.getStaffType()); + positions.put(dto.getStaffId(),dto.getPosition()); + } Map> map = departmentsService.selectDepartmentTreeByDepIds(depIds); - //TODO 整合数据 + for(LevelDetailExportDto res: levelDetailExportDtos){ + Integer integer = types.get(res.getStaffId()); + String position = positions.get(res.getStaffId()); + if(integer !=null){ + res.setStaffType(integer); + } + if(StringUtil.isNotBlank(position)){ + res.setPosition(position); + } + List names = map.get(res.getDepartmentId()); + if(CollectionUtils.isNotEmpty(names)){ + Collections.reverse(names); + int size = names.size(); + if(size>0 && StringUtils.isNotBlank(names.get(0))){ + res.setDepartmentOne(names.get(0)); + } + if(size>1 && StringUtils.isNotBlank(names.get(1))){ + res.setDepartmentTwo(names.get(1)); + } + if(size>2 && StringUtils.isNotBlank(names.get(2))){ + res.setDepartmentThree(names.get(2)); + } + } + } + + //人员变动信息 TODO + //staffWorkTransferRecordService + + //拷贝为excel格式 + List levelDetailExportRes = levelDetailExportDtos.stream().map(levelDetailExportDto -> { + LevelDetailExportRes res = new LevelDetailExportRes(); + BeanUtils.copyProperties(levelDetailExportDto,res); + return res; + }).collect(Collectors.toList()); return levelDetailExportRes; diff --git a/src/main/java/com/lz/modules/sys/dao/app/ResultRecordMapper.java b/src/main/java/com/lz/modules/sys/dao/app/ResultRecordMapper.java index 5e0dc8e8..316791c8 100644 --- a/src/main/java/com/lz/modules/sys/dao/app/ResultRecordMapper.java +++ b/src/main/java/com/lz/modules/sys/dao/app/ResultRecordMapper.java @@ -16,6 +16,7 @@ import com.lz.modules.app.req.ReportListReq; import com.lz.modules.app.req.ResultRecordReq; import com.lz.modules.app.resp.OwnResultResp; import com.lz.modules.flow.model.ResultRecordDto; +import com.lz.modules.performance.dto.LevelDetailExportDto; import com.lz.modules.performance.dto.ToScoreDingTalkDto; import com.lz.modules.performance.req.AssessDetailReq; import com.lz.modules.performance.req.OwnResultReq; @@ -109,7 +110,7 @@ public interface ResultRecordMapper extends BaseMapper { List selectResultRecordsByStartId(Long startId); - List selectLevelDetailList(@Param("departmentIds") List departmentIds, @Param("startId")Long startId, @Param("scoreLevel")String scoreLevel); + List selectLevelDetailList(@Param("departmentIds") List departmentIds, @Param("startId")Long startId, @Param("scoreLevel")String scoreLevel); } \ No newline at end of file diff --git a/src/main/resources/mapper/app/ResultRecordMapper.xml b/src/main/resources/mapper/app/ResultRecordMapper.xml index a5508889..0f15ce89 100644 --- a/src/main/resources/mapper/app/ResultRecordMapper.xml +++ b/src/main/resources/mapper/app/ResultRecordMapper.xml @@ -619,7 +619,7 @@ and start_id = #{startId} - SELECT r.id,all_score,department_id,staff_name,staff_id,score_level,job_number staffNo from lz_result_record r LEFT JOIN lz_staff s on r.staff_id = s.id diff --git a/src/main/resources/mapper/generator/StaffOccupationDao.xml b/src/main/resources/mapper/generator/StaffOccupationDao.xml index d9015dff..8750018d 100644 --- a/src/main/resources/mapper/generator/StaffOccupationDao.xml +++ b/src/main/resources/mapper/generator/StaffOccupationDao.xml @@ -73,8 +73,8 @@ select staff_id,staff_type,position,staff_status,entry_time,official_time from lz_staff_occupation - where is_delete = 0 and + where is_delete = 0 and staff_status = 0 and staff_id in From 006bf3840730c3c19984114e3e017da916ea1459 Mon Sep 17 00:00:00 2001 From: wulin Date: Wed, 2 Dec 2020 17:46:21 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=A6=BB=E8=81=8C=E4=BA=BA=E5=91=98=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lz/common/utils/DingTalkUtil.java | 7 ++- .../job/business/DingtalkBusiness.java | 50 +++++++++++++++++-- src/test/java/com/lz/mysql/MysqlMain.java | 46 +---------------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/lz/common/utils/DingTalkUtil.java b/src/main/java/com/lz/common/utils/DingTalkUtil.java index 298f089f..67563ec6 100644 --- a/src/main/java/com/lz/common/utils/DingTalkUtil.java +++ b/src/main/java/com/lz/common/utils/DingTalkUtil.java @@ -280,7 +280,7 @@ public class DingTalkUtil { * @param accessToken * @return */ - public List getDepartmentStaffDetailsV2(String accessToken, String departmentId) { + public List getDepartmentStaffDetailsV2(String accessToken, String departmentId, Map mapProbation) { try { long page = 0L; List list =new ArrayList<>(); @@ -324,6 +324,11 @@ public class DingTalkUtil { departmentStaffBo.setEmail(json.getString("email"));//邮箱,钉钉的企业邮箱才可以,需要单独授权手机权限 departmentStaffBo.setAvatar(json.getString("avatar"));//头像 departmentStaffBo.setPosition(json.getString("title")); + if(mapProbation.containsKey(departmentStaffBo.getEmployeeId())){ + departmentStaffBo.setEmployeeType(2); + }else{ + departmentStaffBo.setEmployeeType(1); + } departmentStaffBo.setStatus(0); /*if(json.getBoolean("active")){ //在职已激活 diff --git a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java index 64a11be6..8f4b7857 100644 --- a/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java +++ b/src/main/java/com/lz/modules/job/business/DingtalkBusiness.java @@ -6,8 +6,10 @@ import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiRoleListRequest; import com.dingtalk.api.request.OapiRoleSimplelistRequest; +import com.dingtalk.api.request.OapiSmartworkHrmEmployeeQueryonjobRequest; import com.dingtalk.api.response.OapiRoleListResponse; import com.dingtalk.api.response.OapiRoleSimplelistResponse; +import com.dingtalk.api.response.OapiSmartworkHrmEmployeeQueryonjobResponse; import com.google.common.collect.Lists; import com.lz.common.emun.WorkMsgTypeEnum; import com.lz.common.utils.DateUtils; @@ -47,10 +49,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -195,6 +194,9 @@ public class DingtalkBusiness { List departmentInfosBos = dingTalkUtil.getDepartmentDetailsV2(token, "1"); if(departmentInfosBos.size() > 0){ + List probationUserIDS = getProbationStaff(token);//获取试用期人员信息 + Map mapProbation = + probationUserIDS.stream().collect(Collectors.toMap(String::toString, Function.identity(), (e, r) -> e)); //获取原有部门信息 Map mapDepartmentInfosBos = departmentInfosBos.stream().collect(Collectors.toMap(DepartmentInfosBo::getId, Function.identity(), (e, r) -> e)); @@ -251,7 +253,7 @@ public class DingtalkBusiness { } //获取部门用户详情 - List staffs = dingTalkUtil.getDepartmentStaffDetailsV2(token, departmentInfo.getId()); + List staffs = dingTalkUtil.getDepartmentStaffDetailsV2(token, departmentInfo.getId(), mapProbation); logger.info("=============================" + departmentInfo.getName() + "================================"); //设置本部门人数 if(departmentInfo.getMemberCount() == null){ @@ -466,6 +468,7 @@ public class DingtalkBusiness { if(addStaffs.size() > 0){//有新增部门 logger.info("新增人员信息个数{}", addStaffs.size()); + staffService.saveBatch(addStaffs); String key; for (StaffEntity entity:addStaffs @@ -495,6 +498,8 @@ public class DingtalkBusiness { } } + + if(updateStaffs.size() > 0){//有新增部门 logger.info("更新人员信息个数{}", updateStaffs.size()); staffService.updateBatchById(updateStaffs); @@ -559,6 +564,41 @@ public class DingtalkBusiness { } } + private List getProbationStaff(String token){ + //获取试用期员工信息 + + try { + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob"); + OapiSmartworkHrmEmployeeQueryonjobRequest req = new OapiSmartworkHrmEmployeeQueryonjobRequest(); + Long offSet = 0L; + req.setStatusList("2"); + req.setSize(50L); + boolean isNext = false; + List ids = new ArrayList<>(); + { + req.setOffset(offSet); + OapiSmartworkHrmEmployeeQueryonjobResponse rsp = client.execute(req, token); + logger.info("钉钉请求试用期员工返回信息{}", rsp.getBody()); + JSONObject jsonObject = JSONObject.parseObject(rsp.getBody()); + if(jsonObject.getIntValue("errcode") == 0){ + jsonObject = jsonObject.getJSONObject("result"); + offSet = jsonObject.getLong("next_cursor"); + if(offSet != null){ + isNext = true; + } + JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("data_list")); + ids.addAll(Arrays.stream(jsonArray.toArray(new String[jsonArray.size()])).collect(Collectors.toList())); + }else{ + logger.info("钉钉请求返回错误{}", jsonObject); + } + }while(isNext) + return ids; + + } catch (ApiException e) { + e.printStackTrace(); + } + return null; + } public void enterStaffOccupationInfos(List staffs) { diff --git a/src/test/java/com/lz/mysql/MysqlMain.java b/src/test/java/com/lz/mysql/MysqlMain.java index 09095683..9433eb0c 100644 --- a/src/test/java/com/lz/mysql/MysqlMain.java +++ b/src/test/java/com/lz/mysql/MysqlMain.java @@ -1,5 +1,7 @@ package com.lz.mysql; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.lz.common.utils.StringUtil; import com.lz.modules.flow.entity.FlowChartRole; import org.springframework.util.ResourceUtils; @@ -65,51 +67,7 @@ public class MysqlMain { */ public static void main(String[] args) throws Exception { - /*Long a = 2l; - Long b = 3l; - String value = "aaa"; - StopWatch stopWatch = new StopWatch(); - stopWatch.start("测试静态方法"); - for(int i = 0; i < 10000; i++){ - if(TestStaticAndHuo.isEmpt(value)){ - } - } - stopWatch.stop(); - - stopWatch.start("测试对象方法"); - for(int i = 0; i < 10000; i++){ - if(value == null || value.length() == 0){ - - } - } - stopWatch.stop(); - - System.out.println(stopWatch.prettyPrint());*/ - - /*List testMaps = new ArrayList<>(); - TestMap test = new TestMap(); - test.setName("123"); - test.setMobile("18969093321"); - testMaps.add(test); - - test = new TestMap(); - test.setName("123"); - test.setMobile("18969093321"); - testMaps.add(test); - - Map t = testMaps.stream().collect(Collectors.toMap(TestMap::getName, testMap -> testMap)); - List flowChartRoles = new ArrayList<>(); - flowChartRoles.add(1L); - flowChartRoles.add(2L); - flowChartRoles.add(3L); - flowChartRoles.add(4L); - String roles = flowChartRoles.stream().map(new Function() { - @Override - public String apply(Long flowChartRole) { - return flowChartRole.toString(); - } - }).collect(Collectors.joining(","));*/ String path = ResourceUtils.getURL("classpath:").getPath(); System.out.println(path);