添加一键催办

This commit is contained in:
wulin 2020-12-16 17:54:38 +08:00
parent 3091d3516c
commit 6d717e067f
8 changed files with 177 additions and 35 deletions

View File

@ -66,4 +66,6 @@ public interface DepartmentsStaffRelateDao extends BaseMapper<DepartmentsStaffRe
List<String> selectStaffIdsByDepartments(@Param("deparmentIds")List<String> deparmentIds);
List<StaffEntity> selectLeadersByDepartmentId(@Param("depId") String depId);
List<Long> selectLongStaffIdsByDepartments(@Param("departmentIds") List<String> departmentIds);
}

View File

@ -44,5 +44,7 @@ public interface DepartmentsStaffRelateService extends IService<DepartmentsStaff
List<String> selectStaffIdsByDepartments(List<String> deparmentIds);
List<StaffEntity> selectLeadersByDepartmentId(String depId);
List<Long> selectLongStaffIdsByDepartments(List<String> departmentIds);
}

View File

@ -106,4 +106,12 @@ public class DepartmentsStaffRelateServiceImpl extends ServiceImpl<DepartmentsSt
public List<StaffEntity> selectLeadersByDepartmentId(String depId){
return departmentsStaffRelateDao.selectLeadersByDepartmentId(depId);
}
@Override
public List<Long> selectLongStaffIdsByDepartments(List<String> departmentIds){
if(CollectionUtils.isEmpty(departmentIds)){
return Collections.EMPTY_LIST;
}
return departmentsStaffRelateDao.selectLongStaffIdsByDepartments(departmentIds);
}
}

View File

@ -659,36 +659,7 @@ public class DingtalkBusiness {
return "error";
}
//一键催办
public String urging(Long startId, Long flowProcess, Long userId) {
StaffRole staffRole = staffRoleService.selectStaffRoleById(userId);
if(staffRole == null){
//不存在那么看是否为部门领导
}else{
//查询管理的部门信息
if(staffRole.getDepartmentId().intValue() != 0){
}
}
/*ResultRecord lzResultRecord = resultRecordService.selectResultRecordById(recordId);
//获取当前节点谁在处理
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordsByRecordIdAndStatus(recordId, 2);
if(flowRecords.size() > 0){
List<Long> ids = flowRecords.stream().map(new Function<FlowRecord, Long>() {
@Override
public Long apply(FlowRecord flowRecord) {
return flowRecord.getApprovalStaffId();
}
}).collect(Collectors.toList());
List<StaffEntity> staffs = staffService.selectNamesByIds(ids);
sendNoticeMsg(lzResultRecord, staffs);
return "OK";
}*/
return "error";
}
public String sendTaskInputMsg(List<StaffEntity> staffs){
int m = 0;
@ -805,11 +776,6 @@ public class DingtalkBusiness {
}
m++;
}
/*for (StaffEntity info:staffEntities
) {
dingTalkUtil.sendSingleActionCardMSG(appid, info, WorkMsgTypeEnum.TASK_REPLY_COMMENT.getTitle(),
content, WorkMsgTypeEnum.TASK_REPLY_COMMENT.getBtnText(), url, token);
}*/
}
return "OK";
@ -1018,6 +984,47 @@ public class DingtalkBusiness {
return R.error("未授权登录");
}
public void urging(List<StaffEntity> staffEntities, Map<Long, ResultRecord> mapReords) {
logger.info("批量催办");
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
String token = dingTalkUtil.getAccessTokenWitchEntity(thirdAppConfig);
if(token != null && token.length() > 0){
for (StaffEntity info:staffEntities
) {
ResultRecord record = mapReords.get(info.getId());
if(record != null){
String url = homeUrl;
if(url.contains("?")){
url += "&halokit=" + System.currentTimeMillis();
}else{
url += "?halokit=" + System.currentTimeMillis();
}
url += ("&detail=1&id=" + record.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("发送消息给{}url:{}", info, url);
String content = null;
if(!record.getStaffName().equals(info.getName())){
content = WorkMsgTypeEnum.URGING.getContent().replace("@", record.getStaffName());
}else{
content = WorkMsgTypeEnum.URGING.getContent().replace("@", "");
}
dingTalkUtil.sendSingleActionCardMSG(appid, info, WorkMsgTypeEnum.URGING.getTitle(),
content, WorkMsgTypeEnum.URGING.getBtnText(), url, token);
}else{
logger.info("无对应的record");
}
}
}else{
logger.info("token无效"); ;
}
}
public class ThreadSendMessage implements Runnable{

View File

@ -4,10 +4,18 @@ import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.app.dto.StaffSimpleDto;
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.StaffService;
import com.lz.modules.flow.dao.FlowStartMapper;
import com.lz.modules.flow.entity.FlowStart;
import com.lz.modules.flow.entity.StaffRole;
import com.lz.modules.flow.entity.StaffRoleDepartment;
import com.lz.modules.flow.service.EvaluationStartStaffService;
import com.lz.modules.flow.service.StaffRoleDepartmentService;
import com.lz.modules.flow.service.StaffRoleService;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.performance.req.AssessChangeReq;
@ -22,13 +30,18 @@ import com.lz.modules.performance.service.AssessManagerService;
import com.lz.modules.performance.service.ChartResultService;
import com.lz.modules.sys.controller.AbstractController;
import com.lz.modules.sys.dao.app.ResultRecordMapper;
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.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author: djc
@ -55,6 +68,19 @@ public class AssessManagerController extends AbstractController{
@Autowired
private DingtalkBusiness dingtalkBusiness;
@Autowired
private DepartmentsStaffRelateService departmentsStaffRelateService;
@Autowired
private StaffRoleDepartmentService staffRoleDepartmentService;
@Autowired
private DepartmentsService departmentsService;
@Autowired
private StaffService staffService;
@PostMapping("assess/manager/list")
@ -169,11 +195,93 @@ public class AssessManagerController extends AbstractController{
try {
Long userId = getUserId();
log.info("一键催办" + userId);
dingtalkBusiness.urging(startId, flowProcess, userId);
StaffRole staffRole = staffRoleService.selectStaffRoleById(userId);
boolean isManagementDepartment = false;
List<String> departmentIds = new ArrayList<>();
if(staffRole != null){
//查询管理的部门信息
if(staffRole.getDepartmentId().intValue() == 2){//管理特定部门
List<StaffRoleDepartment> staffRoleDepartments =
staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
if(staffRoleDepartments.size() > 0){
departmentIds.addAll(staffRoleDepartments.stream().map(new Function<StaffRoleDepartment, String>() {
@Override
public String apply(StaffRoleDepartment staffRoleDepartment) {
return staffRoleDepartment.getDepartmentId();
}
}).collect(Collectors.toList()));
}
}else if(staffRole.getDepartmentId().intValue() == 1){
//管理所在部门及子部门
isManagementDepartment = true;
}
}
//看下是否为部门领导
DepartmentsStaffRelateEntity departmentsStaffRelateEntity
= departmentsStaffRelateService.selectByStaffId(userId);
if (departmentsStaffRelateEntity != null && (isManagementDepartment ||
departmentsStaffRelateEntity.getIsLeader().intValue() == 1)) {//特定部门的
//获取所在部门下面的所有人员id
departmentIds.add(departmentsStaffRelateEntity.getDepartmentId());
}
if(departmentIds.size() > 0){
//去重
log.info("去重前数据{}", departmentIds.size());
departmentIds = departmentIds.stream().distinct().collect(Collectors.toList());
log.info("去重后数据{}", departmentIds.size());
List<String> childIds = new ArrayList<>();
//获取子部门信息
for (String pareId:departmentIds
) {
childIds.addAll(getChildsId(pareId));
}
if(childIds.size() > 0){
departmentIds.addAll(childIds);
}
}
//根据部门获取所有员工的id
List<Long> staffIds = departmentsStaffRelateService.selectLongStaffIdsByDepartments(departmentIds);
log.info("查询到有权限可以推送的人员数量为{}", staffIds.size());
//下面查询当前startId当前flowProcess下面有多少人员id
List<ResultRecord> resultRecords = resultRecordMapper.selectStaffIdsByStartIdAndFlowProcess(startId, flowProcess);
Map<Long, ResultRecord> mapReords =
resultRecords.stream().collect(Collectors.toMap(ResultRecord::getStaffId, Function.identity(), (e, r) -> e));
List<Long> staffIds1 = mapReords.keySet().stream().collect(Collectors.toList());
log.info("查询到在当前节点下的人数为{}", staffIds1.size());
if(staffIds1.size() > 0 && staffIds.size() > 0){
staffIds.retainAll(staffIds1);//求交集
log.info("最终能推送人员个数{}", staffIds.size());
if(staffIds.size() > 0){
List<StaffEntity> staffEntities = staffService.selectByIds(staffIds);
dingtalkBusiness.urging(staffEntities, mapReords);
}
}
} catch (Exception e) {
log.error("开始评分异常" ,e);
return R.error(e.getMessage());
}
return R.ok();
}
//获取部门下面的所有子部门信息
private List<String> getChildsId(String pareId){
log.info("查询{}的子部门", pareId);
List<String> ids = new ArrayList<>();
List<DepartmentsEntity> entitys = departmentsService.selectEntityByParentDepartmentId(pareId);
if(entitys.size() > 0){
for (DepartmentsEntity entity:entitys
) {
List<String> childsId = getChildsId(entity.getDepartmentId());
if(childsId.size() > 0){
ids.addAll(childsId);
}
}
}
log.info("子部门个数{}", ids.size());
return ids;
}
}

View File

@ -114,4 +114,5 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
List<Long> selectStaffIdsByFlowProcess(@Param("flowProcess") List<Integer> flowProcess);
List<ResultRecord> selectStaffIdsByStartIdAndFlowProcess(@Param("startId") Long startId, @Param("flowProcess") Long flowProcess);
}

View File

@ -653,5 +653,10 @@
)
</select>
<select id="selectStaffIdsByStartIdAndFlowProcess" resultType="ResultRecord">
select * from lz_result_record where is_delete = 0 and start_id = #{startId}
<if test="flowProcess != null"> and flow_process = #{flowProcess}</if>
</select>
</mapper>

View File

@ -109,4 +109,13 @@
select staff.* from lz_staff as staff join lz_departments_staff_relate as relate on staff.id = relate.staff_id
where relate.is_delete=0 and relate.department_id = #{depId} and relate.is_leader = 1
</select>
<select id="selectLongStaffIdsByDepartments" resultType="Long">
SELECT staff_id from lz_departments_staff_relate where is_delete = 0 and
department_id in
<foreach collection="departmentIds" item="department_id" open="(" close=")"
separator=",">
#{department_id}
</foreach>
</select>
</mapper>