commit
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package io.v.nutz.zhgh.welfare.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.dao.CndPlus;
|
||||
import io.v.nutz.base.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.models.User;
|
||||
import io.v.nutz.zhgh.welfare.mode.WelfareUnitMode;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareList;
|
||||
import io.v.nutz.zhgh.welfare.model.WelfareProject;
|
||||
@@ -24,6 +26,7 @@ import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -121,8 +124,8 @@ public class WelfareListServiceImpl extends ViServiceImpl<WelfareList> implement
|
||||
}
|
||||
|
||||
/**
|
||||
* 福利名单保存的是生成名单时的单位快照;人员调动后,通过用户ID关联用户主档案更新该快照。
|
||||
* 用户的福利单位或二级单位为空时不参与同步,避免将名单中已有的有效信息清空。
|
||||
* 福利名单保存的是生成名单时的单位快照;人员调动后,通过用户ID关联 user 视图更新该快照。
|
||||
* 视图中的工会或单位为空时不参与同步,避免将名单中已有的有效信息清空。
|
||||
*
|
||||
* @param projectId 福利项目ID
|
||||
* @return 实际更新的福利名单数量
|
||||
@@ -130,20 +133,33 @@ public class WelfareListServiceImpl extends ViServiceImpl<WelfareList> implement
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public int updateWelfareListUnitInfo(String projectId) {
|
||||
Sql sql = Sqls.create("""
|
||||
UPDATE welfare_list wl
|
||||
INNER JOIN sys_user u ON u.id = wl.userId
|
||||
SET wl.welfareUnitId = u.$welfareUnitField,
|
||||
wl.welfareSecondLevelUnitId = u.unitid
|
||||
WHERE wl.projectId = @projectId
|
||||
AND u.$welfareUnitField IS NOT NULL
|
||||
AND u.$welfareUnitField != ''
|
||||
AND u.unitid IS NOT NULL
|
||||
AND u.unitid != ''
|
||||
""");
|
||||
sql.setVar("welfareUnitField", WelfareUnitMode.getMode().getField());
|
||||
sql.setParam("projectId", projectId);
|
||||
return dao().execute(sql).getUpdateCount();
|
||||
List<WelfareList> welfareLists = query(Cnd.where("projectId", "=", projectId));
|
||||
if (welfareLists.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<String> userIds = welfareLists.stream()
|
||||
.map(WelfareList::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
List<User> users = dao().query(User.class, Cnd.where("id", "in", userIds));
|
||||
Map<String, User> userMap = users.stream()
|
||||
.collect(Collectors.toMap(User::getId, user -> user));
|
||||
|
||||
// 只同步视图中单位和工会信息完整的人员,避免用空值覆盖福利名单原有快照。
|
||||
List<WelfareList> updateLists = new ArrayList<>();
|
||||
for (WelfareList welfareList : welfareLists) {
|
||||
User user = userMap.get(welfareList.getUserId());
|
||||
if (user == null || StrUtil.isBlank(user.getUnionid()) || StrUtil.isBlank(user.getUnitid())) {
|
||||
continue;
|
||||
}
|
||||
welfareList.setWelfareUnitId(user.getUnionid());
|
||||
welfareList.setWelfareSecondLevelUnitId(user.getUnitid());
|
||||
updateLists.add(welfareList);
|
||||
}
|
||||
if (updateLists.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return dao().update(updateLists, "^(welfareUnitId|welfareSecondLevelUnitId)$");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user