Commit 40a438e2 authored by 鲁鸿波's avatar 鲁鸿波

查询没有部门的租赁库数据并且添加默认部门以及默认岗位

parent 7ee5b626
package com.testor.common.scheduler;
import com.testor.module.notice.service.TSysOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import oshi.SystemInfo;
......@@ -19,6 +21,10 @@ import java.util.List;
@Component
@Slf4j
public class DiskCheckScheduler {
@Autowired
private TSysOrgService tSysOrgService;
// 每5分钟更新一次
@Scheduled(cron = "0 0/5 * * * ?")
public void refreshSwitch() {
......@@ -41,4 +47,14 @@ public class DiskCheckScheduler {
NumberFormat num = NumberFormat.getPercentInstance();
log.info("磁盘使用情况:" + num.format(usage));
}
/**
* 每天1点同步
* 查询没有部门的租赁库数据并且添加默认部门以及默认岗位
*/
@Scheduled(cron = "0 0 1 * * ?")
public void addIsRentDept(){
tSysOrgService.addIsRentDept();
}
}
......@@ -7,7 +7,9 @@ import java.util.function.Consumer;
import com.testor.biz.sys.org.model.domain.SysOrg;
import com.testor.biz.sys.org.service.SysOrgService;
import com.testor.common.core.domain.R;
import com.testor.module.lease.model.dto.*;
import com.testor.module.notice.service.TSysOrgService;
import com.testor.module.safe.model.domain.TSafeHazardOrg;
import com.testor.module.safe.service.TSafeHazardOrgService;
import com.testor.module.sys.model.domian.NewSysOrg;
......@@ -66,6 +68,9 @@ public class TLeaseBankController extends SuperController {
@Autowired
private TSafeHazardOrgService tSafeHazardOrgService;
@Autowired
private TSysOrgService tSysOrgService;
@ApiOperation(value = "获取首页地图 经纬度 ", notes = "Get TLeaseBank By Id")
@GetMapping(value = "/getHomeMapCoordinate")
public BaseResponse<List<SysOrg>> getHomeMapCoordinate(String orgId) {
......@@ -413,4 +418,10 @@ public class TLeaseBankController extends SuperController {
}
return queryWrapper;
}
@ApiOperation(value = "查询没有部门的租赁库数据并且添加默认部门以及默认岗位", notes = "get org by SysOrg")
@GetMapping("/addIsRentDept")
public R addIsRentDept() {
return R.ok(tSysOrgService.addIsRentDept());
}
}
package com.testor.module.notice.controller;
import com.testor.common.core.domain.R;
import com.testor.module.notice.service.TSysOrgService;
import com.tongtech.tfw.backend.common.biz.models.BaseResponse;
import com.tongtech.tfw.backend.common.models.supers.SuperController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
......@@ -25,4 +27,5 @@ public class TSysOrgController {
return tSysOrgService.getOrg();
}
}
......@@ -25,4 +25,16 @@ public interface TSysOrgDao extends SuperDao<TSysOrg> {
List<String> selectOrgIdAllSubId(@Param("orgId") String orgId);
/**
* 查询租赁库数据
* @return
*/
List<TSysOrg> selectIsRent();
/**
* 查询租赁库下有部门的数据
* @return
*/
List<TSysOrg> selectIsRentDept();
}
......@@ -60,7 +60,29 @@ public class TSysOrg extends SuperModel
@TableField("tree_sort")
private String treeSort;
/**
/**
* 级别
*/
@ApiModelProperty(value = "级别")
@TableField("tree_level")
private String treeLevel;
/**
* 是否部门 1部门 0 机构
*/
@ApiModelProperty(value = "是否部门 1部门 0 机构")
@TableField("is_dept")
private String isDept;
/**
* 是否为租赁库 0否 1是
*/
@ApiModelProperty(value = "是否为租赁库 0否 1是")
@TableField("is_rent")
private String isRent;
/**
* 机构名称
*/
@ApiModelProperty(value = "机构名称")
......
......@@ -12,4 +12,11 @@ import com.tongtech.tfw.backend.common.models.supers.SuperService;
*/
public interface TSysOrgService extends SuperService<TSysOrg> {
public BaseResponse getOrg();
/**
* 查询没有部门的租赁库数据并且添加默认部门以及默认岗位
* @return
*/
public int addIsRentDept();
}
package com.testor.module.notice.service.impl;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.testor.biz.sys.org.model.domain.SysOrg;
import com.testor.biz.sys.org.service.SysOrgService;
import com.testor.biz.sys.post.model.domain.TSysPost;
import com.testor.biz.sys.post.service.TSysPostService;
import com.testor.biz.sys.user.model.domain.SysUser;
import com.testor.biz.sys.user.service.SysUserService;
import com.testor.module.notice.dao.TSysOrgDao;
......@@ -15,9 +20,12 @@ import com.tongtech.tfw.backend.common.context.ContextUtils;
import com.tongtech.tfw.backend.common.models.supers.SuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
......@@ -34,6 +42,8 @@ public class TSysOrgServiceImpl extends SuperServiceImpl<TSysOrgDao, TSysOrg> im
private SysUserService sysUserService;
@Autowired
private SysOrgService sysOrgService;
@Autowired
private TSysPostService postService;
@Override
public BaseResponse getOrg() {
......@@ -53,6 +63,77 @@ public class TSysOrgServiceImpl extends SuperServiceImpl<TSysOrgDao, TSysOrg> im
return response;
}
@Transactional(rollbackFor = Exception.class)
@Override
public int addIsRentDept() {
// 1. 查询租赁库数据
List<TSysOrg> tSysOrgs = tSysOrgDao.selectIsRent();
if (CollectionUtils.isEmpty(tSysOrgs)) {
return 0;
}
// 2. 查询已有部门的租赁库数据
List<TSysOrg> tSysOrgDept = tSysOrgDao.selectIsRentDept();
// 3. 筛选出没有子部门的租赁库
Set<String> parentIdsWithDept = tSysOrgDept.stream()
.map(TSysOrg::getParentId)
.collect(Collectors.toSet());
List<TSysOrg> tSysOrgWithoutDept = tSysOrgs.stream()
.filter(org -> !parentIdsWithDept.contains(org.getOrgId()))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(tSysOrgWithoutDept)) {
return 0;
}
// 4. 为无部门的租赁库添加默认部门
List<TSysOrg> addSysOrg = new ArrayList<>();
for (TSysOrg temp : tSysOrgWithoutDept) {
if (StringUtils.isEmpty(temp.getOrgId()) || StringUtils.isEmpty(temp.getParentId())) {
log.warn("orgId 或 parentId 为空,跳过");
continue;
}
TSysOrg tSysOrg = new TSysOrg();
String orgId = IdWorker.getIdStr(); // 使用雪花算法生成唯一 ID
tSysOrg.setOrgId(orgId);
tSysOrg.setParentId(temp.getOrgId());
tSysOrg.setParentIds(temp.getParentId() + "," + orgId);
tSysOrg.setTreeSort("1");
tSysOrg.setTreeLevel("4");
tSysOrg.setOrgName("安全环保部");
tSysOrg.setStatus("0");
tSysOrg.setIsDept("1");
tSysOrg.setIsRent("1");
addSysOrg.add(tSysOrg);
}
// 5. 为这些部门添加默认岗位
List<TSysPost> addSysPost = new ArrayList<>();
for (TSysOrg temp : addSysOrg) {
TSysPost sysPost = new TSysPost();
String id = IdWorker.getIdStr(); // 使用雪花算法生成唯一 ID
sysPost.setId(id);
sysPost.setDeptId(temp.getOrgId());
sysPost.setOrgId(temp.getParentId());
sysPost.setPostName("综合部");
sysPost.setStatus("0");
addSysPost.add(sysPost);
}
// 6. 批量插入(如果某条记录失败,整个事务回滚)
if (!addSysOrg.isEmpty()) {
this.saveBatch(addSysOrg);
}
if (!addSysPost.isEmpty()) {
postService.saveBatch(addSysPost);
}
return 1;
}
// @Override
// public BaseResponse getOrg() {
// BaseResponse<Object> response = new BaseResponse<>();
......
......@@ -48,4 +48,17 @@
WHERE status = '0' and is_dept = '0' and org_id=#{orgId}
</select>
<select id="selectIsRent" resultType="com.testor.module.notice.model.domain.TSysOrg">
select * from t_sys_org
where is_rent = '1' and status = '0' AND org_name LIKE '%租赁库%'
</select>
<select id="selectIsRentDept" resultType="com.testor.module.notice.model.domain.TSysOrg">
select * from t_sys_org
where parent_id in(
select org_id from t_sys_org
where is_rent = '1' and status = '0' AND org_name LIKE '%租赁库%'
)
</select>
</mapper>
\ No newline at end of file
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