优化机构
This commit is contained in:
@@ -66,5 +66,11 @@ public class DataSyncController {
|
||||
return iDataSyncService.orgDataSync();
|
||||
}
|
||||
|
||||
@ApiOperation("同步组织机构,添加参数")
|
||||
@PostMapping("/updateByOrgs")
|
||||
public String updateByOrgs() throws Exception {
|
||||
return iDataSyncService.updateByOrgs();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,4 +8,6 @@ public interface IDataSyncService {
|
||||
public String dataSync();
|
||||
|
||||
public String orgDataSync();
|
||||
|
||||
public String updateByOrgs();
|
||||
}
|
||||
|
||||
+48
@@ -6,6 +6,7 @@ import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao;
|
||||
import com.adc.da.slrs.sarBussStandAttrInfo.service.ISarBussStandAttrInfoService;
|
||||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
||||
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
|
||||
import com.adc.da.slrs.sarInstitution.dao.TsInstitutionDao;
|
||||
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
||||
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
||||
import com.adc.da.slrs.sarPosition.entity.TsPosition;
|
||||
@@ -51,6 +52,8 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
@Autowired
|
||||
ITsInstitutionService tsInstitutionService;
|
||||
@Autowired
|
||||
TsInstitutionDao tsInstitutionDao;
|
||||
@Autowired
|
||||
private ISarStandardsInfoService iSarStandardsInfoService;
|
||||
@Autowired
|
||||
private ISarBussionessStandService iSarBussionessStandService;
|
||||
@@ -354,6 +357,7 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
|
||||
public String orgDataSync(){
|
||||
try{
|
||||
@@ -423,6 +427,15 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
}
|
||||
tsInstitutionService.removeByIds(delIdList);
|
||||
}
|
||||
//全部部门
|
||||
List<TsInstitution> allTsInstitutionListForPids = new ArrayList<>(addTsInstitutionList);
|
||||
allTsInstitutionListForPids.addAll(updateTsInstitutionList);
|
||||
for (TsInstitution tsInstitution : allTsInstitutionListForPids){
|
||||
List<String> parentIds = new ArrayList<>();
|
||||
getParentTaxCompanyIds(allTsInstitutionListForPids, tsInstitution.getId(), parentIds);
|
||||
tsInstitution.setParentIds(String.join(",",parentIds));
|
||||
}
|
||||
tsInstitutionService.updateBatchById(allTsInstitutionListForPids);
|
||||
}else{
|
||||
logger.info("本次获取组织机构的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
|
||||
}
|
||||
@@ -432,4 +445,39 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
|
||||
public String updateByOrgs(){
|
||||
QueryWrapper<TsInstitution> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.ne("id","");
|
||||
List<TsInstitution> tsInstitutions = tsInstitutionDao.selectList(queryWrapper);
|
||||
//全部部门
|
||||
List<TsInstitution> allTsInstitutionListForPids = new ArrayList<>(tsInstitutions);
|
||||
// allTsInstitutionListForPids.addAll(updateTsInstitutionList);
|
||||
for (TsInstitution tsInstitution : allTsInstitutionListForPids){
|
||||
List<String> parentIds = new ArrayList<>();
|
||||
getParentTaxCompanyIds(allTsInstitutionListForPids, tsInstitution.getId(), parentIds);
|
||||
tsInstitution.setParentIds(String.join(",",parentIds));
|
||||
logger.info(String.valueOf(tsInstitution));
|
||||
}
|
||||
tsInstitutionService.updateBatchById(allTsInstitutionListForPids);
|
||||
return allTsInstitutionListForPids.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取父级ids
|
||||
* @param taxCompanyList
|
||||
* @param id
|
||||
*/
|
||||
private void getParentTaxCompanyIds(List<TsInstitution> taxCompanyList, String id, List<String> parentIds) {
|
||||
for (TsInstitution taxCompany : taxCompanyList) {
|
||||
if (StringUtils.isEmpty(taxCompany.getParentId())) {
|
||||
continue;
|
||||
}
|
||||
//判断是否有父节点
|
||||
if (id.equals(taxCompany.getId())) {
|
||||
parentIds.add(taxCompany.getParentId());
|
||||
getParentTaxCompanyIds(taxCompanyList, taxCompany.getParentId(), parentIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public class TsInstitution extends BaseEntity {
|
||||
@ApiModelProperty(value = "上级机构")
|
||||
private String parentId;
|
||||
|
||||
private String parentIds;
|
||||
|
||||
@ApiModelProperty(value = "机构层级")
|
||||
private Integer level;
|
||||
|
||||
|
||||
+23
-23
@@ -460,29 +460,29 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
||||
public IPage<TsUser> getAllUsers(TsUser tsUser) {
|
||||
List<String> ids=new ArrayList<>();
|
||||
ids.add(tsUser.getInstitutionId());
|
||||
List<String> middle=new ArrayList<>();
|
||||
middle.addAll(ids);
|
||||
boolean flag=true;
|
||||
while (flag){
|
||||
QueryWrapper<TsInstitution> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.in("parent_id",middle);
|
||||
List<TsInstitution> tsmiddle=tsInstitutionService.list(queryWrapper);
|
||||
if (tsmiddle.size()>0){
|
||||
tsmiddle.forEach(tsInstitution -> {
|
||||
middle.add(tsInstitution.getId());
|
||||
});
|
||||
middle.removeAll(ids);
|
||||
ids.addAll(middle);
|
||||
}else {
|
||||
tsmiddle.forEach(tsInstitution -> {
|
||||
middle.add(tsInstitution.getId());
|
||||
});
|
||||
middle.removeAll(ids);
|
||||
ids.addAll(middle);
|
||||
flag=false;
|
||||
}
|
||||
}
|
||||
ids.removeIf(s -> null==s);
|
||||
// List<String> middle=new ArrayList<>();
|
||||
// middle.addAll(ids);
|
||||
// boolean flag=true;
|
||||
// while (flag){
|
||||
// QueryWrapper<TsInstitution> queryWrapper=new QueryWrapper<>();
|
||||
// queryWrapper.in("parent_id",middle);
|
||||
// List<TsInstitution> tsmiddle=tsInstitutionService.list(queryWrapper);
|
||||
// if (tsmiddle.size()>0){
|
||||
// tsmiddle.forEach(tsInstitution -> {
|
||||
// middle.add(tsInstitution.getId());
|
||||
// });
|
||||
// middle.removeAll(ids);
|
||||
// ids.addAll(middle);
|
||||
// }else {
|
||||
// tsmiddle.forEach(tsInstitution -> {
|
||||
// middle.add(tsInstitution.getId());
|
||||
// });
|
||||
// middle.removeAll(ids);
|
||||
// ids.addAll(middle);
|
||||
// flag=false;
|
||||
// }
|
||||
// }
|
||||
// ids.removeIf(s -> null==s);
|
||||
Page<TsUser> tsUserPage = new Page<>();
|
||||
tsUserPage.setCurrent(tsUser.getCurrent());
|
||||
tsUserPage.setSize(tsUser.getSize());
|
||||
|
||||
@@ -82,6 +82,8 @@
|
||||
on u.usid=up.user_id
|
||||
left join ts_position p
|
||||
on up.position_id=p.id
|
||||
left join ts_institution ti
|
||||
on ti.id = u.INSTITUTION_ID
|
||||
where 1=1
|
||||
<if test="TsUser.uname != null and TsUser.uname != '' ">
|
||||
and (u.uname like concat('%',#{TsUser.uname},'%') or u.ACCOUNT like concat(#{TsUser.uname},'%'))
|
||||
@@ -90,9 +92,9 @@
|
||||
and u.email like concat('%',#{TsUser.email},'%')
|
||||
</if>
|
||||
<if test=" null != ids and ids.size()> 0">
|
||||
and INSTITUTION_ID in
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")" index="index">
|
||||
#{id}
|
||||
and
|
||||
<foreach item="id" collection="ids" open="(" separator="or" close=")" index="index">
|
||||
ti.parent_ids like concat('%',#{id},'%')
|
||||
</foreach>
|
||||
</if>
|
||||
ORDER BY p.id is null,p.create_time
|
||||
@@ -105,6 +107,8 @@
|
||||
on u.usid=up.user_id
|
||||
left join ts_position p
|
||||
on up.position_id=p.id
|
||||
left join ts_institution ti
|
||||
on ti.id = u.INSTITUTION_ID
|
||||
where 1=1
|
||||
<if test="TsUser.uname != null and TsUser.uname != '' ">
|
||||
and u.uname like concat('%',#{TsUser.uname},'%')
|
||||
@@ -113,9 +117,9 @@
|
||||
and u.email like concat('%',#{TsUser.email},'%')
|
||||
</if>
|
||||
<if test=" null != ids and ids.size()> 0">
|
||||
and INSTITUTION_ID in
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")" index="index">
|
||||
#{id}
|
||||
and
|
||||
<foreach item="id" collection="ids" open="(" separator="or" close=")" index="index">
|
||||
ti.parent_ids like concat('%',#{id},'%')
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user