This commit is contained in:
andy 2026-04-01 13:37:07 +08:00
parent 967ea6020b
commit fb3c3b44f1
9 changed files with 117 additions and 6 deletions

View File

@ -666,8 +666,12 @@ public class RzAttendanceServiceImpl extends ServiceImpl<RzAttendanceMapper, RzA
attendance.setWorkSum(BigDecimal.valueOf(dingsShift.getWorkHour()));
}else{
//早退需要计算工时
Long hours = (attendance.getWorkEndTime().getTime() - attendance.getWorkStartTime().getTime())/1000/60/60;
attendance.setWorkSum(BigDecimal.valueOf(hours));
if(attendance.getWorkStartTime() != null){
Long hours = (attendance.getWorkEndTime().getTime() - attendance.getWorkStartTime().getTime())/1000/60/60;
attendance.setWorkSum(BigDecimal.valueOf(hours));
}else {
attendance.setWorkSum(DataUtils.DEFAULT_VALUE);
}
attendance.setYcxFlag("1");
}
}else{

View File

@ -57,6 +57,8 @@ public class SysDept extends BaseEntity
/** 是否加班 */
private String isOverTime;
private String dingId;
/** 子部门 */
@TableField(exist = false)
private List<SysDept> children = new ArrayList<SysDept>();

View File

@ -3,6 +3,8 @@ package com.evo.common.utils;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@ -18,6 +20,7 @@ import com.evo.common.exception.ServiceException;
*
* @author evo
*/
@Slf4j
public class SecurityUtils
{
@ -62,7 +65,9 @@ public class SecurityUtils
}
catch (Exception e)
{
throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
log.error("获取用户账户异常", HttpStatus.UNAUTHORIZED);
return "system";
// throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
}
}

View File

@ -10,6 +10,7 @@ import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.evo.common.core.redis.RedisCache;
import com.evo.common.utils.StringUtils;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -243,4 +244,18 @@ public class DingUtils {
}
return "";
}
public static String getDeptInfo(Long deptId){
try {
DingTalkClient client = new DefaultDingTalkClient(DingGlobalParams.getUrl()+"v2/department/get");
OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
req.setDeptId(deptId);
OapiV2DepartmentGetResponse rsp = client.execute(req, getAccessToken());
return rsp.getBody();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}

View File

@ -34,7 +34,7 @@ public class DingCallBackUserAddOrgExchangeProcessor implements DingCallBackExch
@Override
public void exchange(JSONObject json) {
log.info("钉钉 新增员工========================>>>{}", json.toString());
JSONArray dataList = json.getJSONArray("userId");
JSONArray dataList = json.getJSONArray("UserId");
if(dataList!= null && dataList.size() > 0){
dataList.forEach(data->{
sysStaffService.insertSysStaffByDingDing(DingUtils.getUserInfoByUserId(String.valueOf(data)));

View File

@ -129,4 +129,9 @@ public interface SysDeptMapper extends BaseMapper<SysDept>
* @return 结果
*/
public int updateDeptForLeader(SysDept dept);
public SysDept selectByDingDeptId(String dingId);
public SysDept selectByName(String name);
}

View File

@ -3,6 +3,8 @@ package com.evo.system.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -19,6 +21,7 @@ import com.evo.common.utils.*;
import com.evo.common.utils.Collections;
import com.evo.common.utils.bean.BeanUtils;
import com.evo.common.utils.poi.ExcelUtil1;
import com.evo.ding.DingUtils;
import com.evo.equipment.service.IEqSnDetailService;
import com.evo.finance.domain.RzSalaryDetail;
import com.evo.finance.processor.SalaryCalculationStrategyExchangeProcessor;
@ -38,6 +41,7 @@ import com.evo.system.mapper.SysStaffMapper;
import com.evo.system.service.ISysStaffService;
import com.evo.system.service.RzUploadService;
import com.evo.system.utils.SubsidyCalculationUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
@ -209,19 +213,39 @@ public class SysStaffServiceImpl extends ServiceImpl<SysStaffMapper, SysStaff> i
log.info("当前员工信息已经存在, 无法再次入库, 钉钉返回员工信息为{}", dingUserInfo);
return;
}
//解析部门信息
JSONArray deptIds = result.getJSONArray("leader_in_dept");
Long deptId = 1l;
if(deptIds.size() > 0){
String dingDeptId= deptIds.getJSONObject(0).getString("dept_id");
String deptIdAncestors = findDeptId(dingDeptId);
deptId = Long.valueOf(deptIdAncestors.split("_")[0]);
}
//创建新的用户
sysStaff = new SysStaff();
sysStaff.setName(name);
sysStaff.setPhone(mobile);
sysStaff.setDingUserId(dingResult.getString("userid"));
sysStaff.setDeptId(deptId);
//员工编码
sysStaff.setCode(getCodeByCompanyName());
sysStaff.setEmploymentDate(new Date());
sysStaff.setWorkerTerm(1l);
sysStaff.setSeniority(0l);
sysStaff.setCompanyName("YT");
sysStaff.setIsLeader("");
sysStaff.setSex("0");
sysStaff.setLevel("10");
sysStaff.setRegularDate(DateUtils.addMonths(sysStaff.getEmploymentDate(),1));
sysStaff.setContractStart(sysStaff.getEmploymentDate());
sysStaff.setContractEnd(DateUtils.addYears(sysStaff.getEmploymentDate(), 1));
sysStaff.setDingUserId(result.getString("userid"));
sysStaff.setStatus(Constants.JOB_STATIS_0);
sysStaff.setCreateTime(DateUtils.getNowDate());
sysStaff.setCreateBy(SecurityUtils.getUsername());
sysStaff.setCreateBy("admin-钉钉推送");
sysStaff.setDelFlag(Constants.DELETE_FLAG_0);
sysStaff.setSource(Constants.SOURCE_DING);
@ -267,6 +291,39 @@ public class SysStaffServiceImpl extends ServiceImpl<SysStaffMapper, SysStaff> i
}
}
public String findDeptId(String dingDeptId){
SysDept dept = deptMapper.selectByDingDeptId(dingDeptId);
if(dept == null){
String deptResult = DingUtils.getDeptInfo(Long.valueOf(dingDeptId));
JSONObject deptObject = JSONObject.parseObject(deptResult).getJSONObject("result");
String deptName = deptObject.getString("name");
dept = deptMapper.selectByName(deptName);
if(dept != null){
return dept.getDeptId()+"_"+dept.getAncestors();
}else{
Long parentId = deptObject.getLong("parent_id");
String parentIdStr = "1_";
if(parentId != 1){
parentIdStr = findDeptId(String.valueOf(parentId));
}
String[] idArrays = parentIdStr.split("_");
dept = new SysDept();
dept.setParentId(Long.valueOf(idArrays[0]));
dept.setAncestors(idArrays[1]+","+idArrays[0]);
dept.setDeptName(deptName);
dept.setStatus("0");
dept.setDelFlag("0");
dept.setIsOverTime("0");
dept.setDingId(dingDeptId);
deptMapper.insert(dept);
return dept.getDeptId()+"_"+dept.getAncestors();
}
}else {
return dept.getDeptId()+"_"+dept.getAncestors();
}
}
/**
* 创建员工详情信息
* @param sysStaff

View File

@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.leader, d.phone,d.status, d.del_flag,d.is_over_time, d.create_by, d.create_time
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.leader, d.phone,d.status, d.del_flag,d.is_over_time, d.create_by, d.create_time, d.ding_id
from sys_dept d
</sql>
@ -100,6 +100,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null">status,</if>
<if test="isOverTime != null">is_over_time,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="dingId != null ">ding_id,</if>
create_time
)values(
<if test="deptId != null and deptId != 0">#{deptId},</if>
@ -111,6 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null">#{status},</if>
<if test="isOverTime != null">#{isOverTime},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="dingId != null ">#{dingId},</if>
sysdate()
)
</insert>
@ -126,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">status = #{status},</if>
<if test="isOverTime != null">is_over_time = #{isOverTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="dingId != null ">ding_id = #{dingId},</if>
update_time = sysdate()
</set>
where dept_id = #{deptId}
@ -164,6 +168,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeptVo"/>
where dept_id not in (select parent_id from sys_dept) and del_flag = '0'
</select>
<select id="selectByDingDeptId" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where ding_id =#{dingId}
</select>
<select id="selectByName" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where dept_name =#{name} and del_flag = '0'
</select>
<!-- 根据部门ID递归查询其所有的子集 -->
<select id="queryDeptsByDeptId" parameterType="Long" resultMap="SysDeptResult">
WITH recursive dept AS (

View File

@ -52,6 +52,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="extended" column="extended" />
<result property="dingUserId" column="ding_user_id" />
<result property="source" column="source" />
<result property="dingUserId" column="ding_user_id" />
</resultMap>
<sql id="selectSysStaffVo">
@ -151,6 +153,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="extended != null and extended != ''">extended,</if>
<if test="openid != null">openid,</if>
<if test="source != null">source,</if>
<if test="dingUserId != null">ding_user_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -202,6 +205,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="extended != null and extended != ''">#{extended},</if>
<if test="openid != null">#{openid},</if>
<if test="source != null">#{source},</if>
<if test="dingUserId != null">#{dingUserId},</if>
</trim>
</insert>
@ -255,6 +259,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="jobCode != null">job_Code=#{jobCode},</if>
<if test="extended != null and extended != ''">extended=#{extended},</if>
<if test="openid != null">openid=#{openid},</if>
<if test="dingUserId != null">ding_user_id= #{dingUserId},</if>
</trim>
where user_id = #{userId}
</update>