Commit 77592261 by fudahua

离职继承fix

parent 948c4a1f
......@@ -81,4 +81,8 @@ public interface HandoverExternalMapper {
* @return
*/
TabHandoverExternal getByExternalUserIdAndStaffId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("staffId") String staffId, @Param("externalUserId") String externalUserId);
/**
*/
int delNoTransferExternal(@Param("userIds") List<String> userIds, @Param("wxEnterpriseId") String wxEnterpriseId);
}
\ No newline at end of file
......@@ -45,4 +45,18 @@ public interface HandoverStaffMapper {
* @return
*/
List<TabHandoverStaff> listByStoreId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("storeId") String storeId);
/**
* 获取待分配列表
*
* @param wxEnterpriseId
* @return
*/
List<TabHandoverStaff> listByWxEnterpriseId(@Param("wxEnterpriseId") String wxEnterpriseId);
/**
* 删除用户
*/
int delByUserIds(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("userIds") List<String> userIds);
}
\ No newline at end of file
package com.gic.haoban.manage.service.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.ToolUtil;
import com.gic.haoban.base.api.common.BasePageInfo;
......@@ -15,14 +16,13 @@ import com.gic.wechat.api.dto.qywx.QywxUnassignedInfoDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -70,22 +70,19 @@ public class HandoverServiceImpl implements HandoverService {
@Override
public boolean saveHandover(String wxEnterpriseId, List<QywxUnassignedInfoDTO> infoList) {
logger.info("saveHandover-保存离职基础数据:{}", wxEnterpriseId);
TabHaobanWxEnterprise wxEnterprise = wxEnterpriseMapper.selectByPrimaryKey(wxEnterpriseId);
if (CollectionUtils.isEmpty(infoList)) {
logger.info("保存失败");
logger.info("没有要保存的数据,删除所有需要删除逇");
delHandoverStaff(wxEnterpriseId, null);
return false;
}
Map<String, List<QywxUnassignedInfoDTO>> handoverUserMap = infoList.stream().collect(Collectors.groupingBy(dto -> dto.getHandoverUserid()));
handoverUserMap.forEach((userId, list) -> {
TabHandoverStaff handoverStaff = getHandoverStaff(wxEnterpriseId, userId);
if (null == handoverStaff) {
logger.info("staff已经存在不许重复");
return;
}
// List<String> staffIds = new ArrayList<>();
// staffIds.add(handoverStaff.getStaffId());
// List<String> handoverExternalIds = handoverExternalMapper.listIdByStaffIds(wxEnterpriseId, staffIds);
List<TabHandoverExternal> externalList = list.stream().map(dto -> {
TabHandoverExternal mid = getHandExternal(dto, wxEnterprise, handoverStaff);
mid.setStaffId(handoverStaff.getStaffId());
......@@ -104,9 +101,33 @@ public class HandoverServiceImpl implements HandoverService {
handoverExternalMapper.insertBatch(needAdd);
});
//删除不需要的staff数据
List<TabHandoverStaff> handoverStaffList = handoverStaffMapper.listByWxEnterpriseId(wxEnterpriseId);
if (CollectionUtils.isEmpty(handoverStaffList)) {
logger.info("没有新数据,无需删除");
return true;
}
Set<String> hasWxUserIds = handoverStaffList.stream().map(dto -> dto.getHandoverUserId()).collect(Collectors.toSet());
Sets.SetView<String> needDelUserIds = Sets.difference(hasWxUserIds, handoverUserMap.keySet());
if (CollectionUtils.isEmpty(needDelUserIds)) {
logger.info("没有新数据,无需删除2");
return true;
}
logger.info("删除数据");
delHandoverStaff(wxEnterpriseId, new ArrayList<>(needDelUserIds));
return false;
}
/**
* 删除企业下的数据
*
* @param wxEnterpriseId
* @param wxUserIds
*/
private void delHandoverStaff(String wxEnterpriseId, List<String> wxUserIds) {
handoverStaffMapper.delByUserIds(wxEnterpriseId, wxUserIds);
handoverExternalMapper.delNoTransferExternal(wxUserIds, wxEnterpriseId);
}
private void saveHandoverStaff(TabHandoverStaff handoverStaff) {
if (handoverStaff.getHandoverStaffId() != null) {
......@@ -255,14 +276,23 @@ public class HandoverServiceImpl implements HandoverService {
}
list.forEach(dto -> {
TabHandoverExternal handoverExternal = handoverExternalMapper.getByTransferId(wxEnterpriseId, transferId, dto.getExternalUserid());
if (dto.getTakeoverTime() > 0) {
Date date = new Date(dto.getTakeoverTime() * 1000);
handoverExternal.setTakeoverTime(date);
try {
TabHandoverExternal handoverExternal = handoverExternalMapper.getByTransferId(wxEnterpriseId, transferId, dto.getExternalUserid());
if (handoverExternal == null) {
logger.info("不存在该人员,有问题:{}", dto.getExternalUserid());
return;
}
if (dto.getTakeoverTime() != null && dto.getTakeoverTime() > 0) {
Date date = new Date(dto.getTakeoverTime() * 1000);
handoverExternal.setTakeoverTime(date);
}
handoverExternal.setTransferStatus(dto.getStatus());
handoverExternal.setUpdateTime(new Date());
handoverExternalMapper.updateByPrimaryKeySelective(handoverExternal);
} catch (Exception e) {
logger.info("exception:{},{}", JSONObject.toJSONString(dto), e);
e.printStackTrace();
}
handoverExternal.setTransferStatus(dto.getStatus());
handoverExternal.setUpdateTime(new Date());
handoverExternalMapper.updateByPrimaryKeySelective(handoverExternal);
});
return true;
}
......
......@@ -141,6 +141,7 @@ public class HandoverOperationApiServiceImpl implements HandoverOperationApiServ
handoverService.dealResult(wxEnterpriseId, dto.getHandoverTransferId(), customerResults);
} catch (Exception e) {
e.printStackTrace();
logger.info("处理异常:{},{}", JSONObject.toJSONString(dto), e);
}
});
......
......@@ -323,4 +323,20 @@
and external_user_id=#{externalUserId}
and status_flag!=0
</select>
<update id="delNoTransferExternal">
update tab_haoban_handover_external
set
status_flag = 0,
update_time = now()
where
wx_enterprise_id=#{wxEnterpriseId}
<if test="userIds!=null and userIds.size>0">
and user_id in
<foreach collection="userIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
and status_flag=1
</update>
</mapper>
\ No newline at end of file
......@@ -178,4 +178,28 @@
and store_id=#{storeId}
and status_flag=1
</select>
<select id="listByWxEnterpriseId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_handover_staff
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and status_flag=1
</select>
<update id="delByUserIds">
update tab_haoban_handover_staff
set
status_flag = 0,
update_time = now()
where
wx_enterprise_id=#{wxEnterpriseId}
and status_flag=1
<if test="userIds!=null and userIds.size>0">
and handover_user_id in
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</update>
</mapper>
\ No newline at end of file
......@@ -189,8 +189,7 @@
select
<include refid="Base_Column_List"/>
from tab_haoban_clerk_main_store_related
where 1=1
and wx_enterprise_id = #{wxEnterpriseId}
where wx_enterprise_id = #{wxEnterpriseId}
and staff_id = #{staffId}
order by create_time desc limit 1
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment