package org.jeecg.modules.base.controller;
|
|
import java.text.ParseException;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.stream.Collectors;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.system.vo.SelectTreeModel;
|
import org.jeecg.modules.base.entity.Enterprise;
|
import org.jeecg.modules.base.service.IEnterpriseService;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.modules.quartz.entity.QuartzJob;
|
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
import org.jeecg.modules.system.entity.Administrator;
|
import org.jeecg.common.system.base.entity.DataVersion;
|
import org.jeecg.modules.system.service.IAdministratorService;
|
import org.jeecg.modules.system.service.IDataVersionService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
/**
|
* @Description: 企业架构
|
* @Author: jeecg-boot
|
* @Date: 2022-11-21
|
* @Version: V1.0
|
*/
|
@Api(tags="企业架构")
|
@RestController
|
@RequestMapping("/base/enterprise")
|
@Slf4j
|
public class EnterpriseController extends JeecgController<Enterprise, IEnterpriseService> {
|
@Autowired
|
private IEnterpriseService enterpriseService;
|
@Autowired
|
private IDataVersionService dataVersionService;
|
@Autowired
|
private IQuartzJobService quartzJobService;
|
@Autowired
|
private IAdministratorService administratorService;
|
/**
|
*
|
* 获取集团架构树
|
*
|
*/
|
@GetMapping("/enterpriseTree")
|
public Result<?> getEnterpriseTree(@RequestParam(value = "version", required = false) Integer version){
|
SelectTreeModel selectTreeModel = new SelectTreeModel();
|
selectTreeModel.setKey("0");
|
selectTreeModel.setTitle("集团架构");
|
List<SelectTreeModel> finallyList = new ArrayList<>();
|
selectTreeModel.setChildren(enterpriseService.getEnterpriseVersionTree("0",version));
|
finallyList.add(selectTreeModel);
|
return Result.OK(finallyList);
|
}
|
/**
|
* 分页列表查询
|
*
|
* @param map
|
* @param pageNo
|
* @param pageSize
|
* @param parentId
|
* @return
|
*/
|
//@AutoLog(value = "企业架构-分页列表查询")
|
@ApiOperation(value="企业架构-分页列表查询", notes="企业架构-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<IPage<Map<String,Object>>> queryPageList(Map map,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
@RequestParam(name = "parentId",required = false) String parentId,
|
@RequestParam(name="version",required = false) Integer version
|
) {
|
Page<Map<String,Object>> page = new Page(pageNo, pageSize);
|
IPage<Map<String,Object>> pageList = enterpriseService.getEnterpriseListByPid(page,version,parentId);
|
return Result.OK(pageList);
|
}
|
/**
|
*
|
* 查询当前生效版本列表
|
*
|
*/
|
@GetMapping("getUsableList")
|
public Result<?> getUsableList(){
|
return Result.OK(enterpriseService.getUsableList());
|
}
|
|
/**
|
*
|
* 查所有企业列表
|
*
|
*/
|
@GetMapping("/mapList")
|
public Result<?> getEnterpriseList(){
|
return Result.OK(enterpriseService.getEnterprise());
|
}
|
|
/**
|
* 添加需要一次性完成
|
*
|
* @param map
|
* @return
|
*/
|
@AutoLog(value = "企业架构-添加")
|
@ApiOperation(value="企业架构-添加", notes="企业架构-添加")
|
@PostMapping(value = "/add")
|
@Transactional
|
public Result<String> add(@RequestBody Map<String,Object> map) {
|
Enterprise enterprise = new Enterprise();
|
//(设置保存的工作中心数据)
|
enterprise.setCode(String.valueOf(map.get("code")))
|
.setName(String.valueOf(map.get("name")))
|
.setRemark(String.valueOf(map.get("remark")))
|
.setVersion(Integer.parseInt(String.valueOf(map.get("version"))))
|
.setStatus(String.valueOf(map.get("status")))
|
.setParentId(String.valueOf(map.get("parentId")))
|
.setDelFlag(0);
|
enterpriseService.save(enterprise);
|
QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<Enterprise>()
|
.eq("code",enterprise.getCode()).eq("version",enterprise.getVersion()).eq("del_flag",0);
|
Enterprise selectEnterprise = enterpriseService.getOne(queryWrapper,true);
|
DataVersion dataVersion = new DataVersion();
|
dataVersion.setBusinessId(selectEnterprise.getId())
|
.setBusinessType("集团架构")
|
.setVersion(selectEnterprise.getVersion())
|
.setVersionStatus(String.valueOf(map.get("versionStatus")))
|
.setDelFlag(0)
|
.setEffectiveType("0")
|
.setIsLastUsable("0");
|
dataVersionService.save(dataVersion);
|
QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
|
.eq("business_id",selectEnterprise.getId()).eq("del_flag",0);
|
DataVersion selectDataVersion = dataVersionService.getOne(queryWrapper1,true);
|
selectEnterprise.setDataVersionId(selectDataVersion.getId());
|
enterpriseService.saveOrUpdate(selectEnterprise);
|
return Result.OK("添加成功!");
|
}
|
/**
|
* 升版
|
* 需要一次完成
|
* @param map
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersion")
|
@Transactional
|
public Result<?> updateVersion(@RequestBody Map<String,Object> map){
|
Integer version = Integer.parseInt((String)map.get("version"));
|
Integer newVersion = enterpriseService.getAllVersion().stream().findFirst().get()+1;
|
//该方法在api区
|
recurrenceUpdata("0","0",version,newVersion);
|
return Result.OK("升版成功",newVersion);
|
}
|
/**
|
* 立即生效
|
* 需要一次完成
|
* @param map
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersionStatusToUsable")
|
@Transactional
|
public Result<?> updateVersionStatusToUsable(@RequestBody Map<String,Object> map){
|
//如果有定时生生效,则将定时生效任务关闭
|
QuartzJob quartzJob = quartzJobService.getOne(new QueryWrapper<QuartzJob>()
|
.eq("job_class_name","org.jeecg.modules.quartz.job.EnterpriseSetUsableJob"),true);
|
if(ObjectUtils.isNotNull(quartzJob)){
|
quartzJobService.deleteAndStopJob(quartzJob);
|
}
|
//获取版本号
|
Integer version = Integer.parseInt((String)map.get("version"));
|
//获取上次生效版本并将其是否上次生效位置置为否
|
List<Enterprise> lastUsableList = enterpriseService.getLastUsableList();
|
if(CollectionUtils.isNotEmpty(lastUsableList)){
|
List<DataVersion> lastUsableVersionList = dataVersionService.list( new QueryWrapper<DataVersion>()
|
.in("business_id",lastUsableList.stream()
|
.map(Enterprise::getId)
|
.collect(Collectors.toList())).eq("del_flag",0));
|
lastUsableVersionList.stream().forEach(dataVersion -> {
|
dataVersion.setIsLastUsable("0");
|
});
|
dataVersionService.updateBatchById(lastUsableVersionList);
|
}
|
//获取生效版本及版本信息并将其置为失效
|
List<Enterprise> usableList = enterpriseService.getUsableList();
|
if(CollectionUtils.isNotEmpty(usableList)){
|
List<DataVersion> usableDataVersionList = dataVersionService.list(new QueryWrapper<DataVersion>()
|
.in("business_id",usableList.stream()
|
.map(Enterprise::getId)
|
.collect(Collectors.toList())));
|
usableDataVersionList.stream().forEach(dataVersion -> {
|
dataVersion
|
.setVersionStatus("3")
|
.setIsLastUsable("1")
|
.setExpiredTime(new Date(System.currentTimeMillis()));
|
});
|
dataVersionService.updateBatchById(usableDataVersionList);
|
}
|
//获取待生效版本及版本信息并将其置为生效
|
List<DataVersion> dataVersionList = dataVersionService.list(new QueryWrapper<DataVersion>()
|
.in("business_id",enterpriseService
|
.list(
|
new QueryWrapper<Enterprise>()
|
.eq("version",version)
|
.eq("del_flag",0)
|
)
|
.stream().map(Enterprise::getId)
|
.collect(Collectors.toList())));
|
dataVersionList.stream().forEach(dataVersion -> {
|
dataVersion.setVersionStatus("2")
|
.setEffectiveType("2")
|
.setEffectiveTime(new Date(System.currentTimeMillis()))
|
.setIsLastUsable("0");
|
});
|
//存入数据库
|
dataVersionService.updateBatchById(dataVersionList);
|
return Result.OK("生效成功");
|
}
|
/**
|
* 定时生效
|
* 需要一次性完成
|
* @param quartzJob
|
* @param
|
* @return
|
*/
|
@PostMapping("/updateVersionStatusToUsableBySetTime")
|
@Transactional
|
public Result<?> updateVersionStatusToUsableBySetTime(@RequestBody QuartzJob quartzJob) throws ParseException {
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
|
String jobClassName = quartzJob.getJobClassName();
|
String time = quartzJob.getCronExpression();
|
System.out.println(time);
|
LocalDateTime localDateTime = LocalDateTime.parse(time,dateTimeFormatter);
|
String cronStr=dateTimeFormatter1.format(localDateTime);
|
quartzJob.setCronExpression(cronStr);
|
QueryWrapper<QuartzJob> queryWrapper = new QueryWrapper();
|
queryWrapper.eq("JOB_CLASS_NAME",jobClassName);
|
List<QuartzJob> quartzJobs = quartzJobService.list(queryWrapper);
|
if(CollectionUtils.isEmpty(quartzJobs)){
|
quartzJobService.saveAndScheduleJob(quartzJob);
|
quartzJobs = quartzJobService.list(queryWrapper);
|
quartzJob.setId(quartzJobs.get(0).getId());
|
quartzJobService.resumeJob(quartzJob);
|
return Result.OK(quartzJob);
|
}else{
|
quartzJob.setId(quartzJobs.get(0).getId());
|
quartzJobService.resumeJob(quartzJob);
|
return Result.OK(quartzJob);
|
}
|
}
|
/**
|
* 编辑
|
*
|
* @param enterprise
|
* @return
|
*/
|
@AutoLog(value = "企业架构-编辑")
|
@ApiOperation(value="企业架构-编辑", notes="企业架构-编辑")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> edit(@RequestBody Enterprise enterprise) {
|
enterpriseService.updateById(enterprise);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "企业架构-通过id删除")
|
@ApiOperation(value="企业架构-通过id删除", notes="企业架构-通过id删除")
|
@DeleteMapping(value = "/delete")
|
@Transactional
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.eq("business_id",id));
|
enterpriseService.update(new UpdateWrapper<Enterprise>().
|
set("del_flag",1)
|
.eq("id",id));
|
return Result.OK("删除成功!");
|
}
|
|
|
/**
|
* 批量删除
|
*
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "企业架构-批量删除")
|
@ApiOperation(value="企业架构-批量删除", notes="企业架构-批量删除")
|
@DeleteMapping(value = "/deleteBatch")
|
@Transactional
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
dataVersionService.update(new UpdateWrapper<DataVersion>()
|
.set("del_flag",1)
|
.in("business_id",Arrays.asList(ids.split(","))));
|
enterpriseService.
|
update(new UpdateWrapper<Enterprise>()
|
.set("del_flag",1)
|
.in("id",Arrays.asList(ids.split(","))));
|
return Result.OK("删除成功");
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
@ApiOperation(value="企业架构-通过id查询", notes="企业架构-通过id查询")
|
@GetMapping(value = "/queryById")
|
public Result<Enterprise> queryById(@RequestParam(name="id",required=true) String id) {
|
Enterprise enterprise = enterpriseService.getById(id);
|
if(enterprise==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(enterprise);
|
}
|
|
/**
|
* 导出excel
|
*
|
* @param request
|
* @param enterprise
|
*/
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, Enterprise enterprise) {
|
return super.exportXls(request, enterprise, Enterprise.class, "企业架构");
|
}
|
|
/**
|
* 通过excel导入数据
|
*
|
* @param request
|
* @param response
|
* @return
|
*/
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, Enterprise.class);
|
}
|
/**
|
* 表单验证
|
*
|
*
|
*/
|
@GetMapping("/check")
|
public Result<?> check(@RequestParam(name="name",required = false) String name,
|
@RequestParam(name="version",required = false) Integer version,
|
@RequestParam(name="parentId",required = true) String parentId
|
){
|
QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<>();
|
if(!StringUtils.isBlank(name)){
|
queryWrapper.eq("name",name);
|
}
|
if(version!=null){
|
queryWrapper.eq("version",version);
|
}
|
if(!StringUtils.isBlank(parentId)){
|
queryWrapper.eq("parent_id",parentId);
|
}
|
queryWrapper.eq("del_flag","0");
|
return Result.OK(enterpriseService.list(queryWrapper));
|
}
|
/**
|
* 获取初始版本号
|
*
|
*
|
*/
|
@GetMapping("/getInitVersion")
|
public Result<?> getUsableVersion(){
|
return Result.OK(enterpriseService.getInitVersion());
|
}
|
/**
|
* 获取所有版本号
|
*
|
*
|
*/
|
@GetMapping("/getVersionList")
|
public Result<?> getAllVersion(){
|
return Result.OK(enterpriseService.getAllVersion());
|
}
|
/**
|
* 获取当前生效版本和上一次生效版本的版本号
|
*
|
* @return
|
*/
|
@GetMapping("/getNowAndLastUsableVersion")
|
public Result<?> getNowAndLastUsableVersion(){
|
return Result.OK(enterpriseService.getNowAndLastUsableVersion());
|
}
|
/**
|
* 删除消息提醒
|
*
|
* @param delIndexList
|
* @return
|
*/
|
@PostMapping("/checkDel")
|
@Transactional
|
public Result<?> checkDel(@RequestBody List<String> delIndexList){
|
List<Administrator> administrators = administratorService
|
.list(new QueryWrapper<Administrator>()
|
.in("enterprise_id",delIndexList)
|
.eq("del_flag",0)
|
);
|
List<String> list1 = administrators.stream().map(Administrator::getEnterpriseId).collect(Collectors.toList());
|
Set<String> set = new TreeSet<>();
|
set.addAll(list1);
|
if(CollectionUtils.isNotEmpty(set)){
|
List<Enterprise> enterpriseList = enterpriseService.listByIds(set);
|
final String[] listMessage = {""};
|
if(CollectionUtils.isNotEmpty(enterpriseList)){
|
enterpriseList.stream().forEach(enterprise -> {
|
listMessage[0] = listMessage[0] +enterprise.getCode()+",";
|
});
|
String trueMessage = "编号为"+listMessage[0]
|
.substring(0, listMessage[0].length()-1)+"的数据被引用,确认删除吗?";
|
return Result.OK(trueMessage);
|
}
|
}
|
return Result.OK("选中数据没有被引用,可以安全删除,确认删除吗?");
|
}
|
/**
|
* 拖拽节点
|
*
|
* @param map
|
* @return
|
*/
|
@PostMapping("/dropAndChangeNode")
|
@Transactional
|
public Result<?> dropAndChangeNode(@RequestBody Map<String,String> map){
|
String dropedKey=map.get("dropedKey");
|
String changeKey=map.get("changeKey");
|
String dropedParentId = map.get("dropedParentId");
|
String changeParentId = map.get("changeParentId");
|
Enterprise dropedEnterprise = enterpriseService.getById(dropedKey);
|
Enterprise changeEnterprise = enterpriseService.getById(changeKey);
|
String dropedCode = dropedEnterprise.getCode();
|
String changeCode = changeEnterprise.getCode();
|
String status = map.get("status");
|
if("1".equals(status)||"3".equals(status)){
|
dropedEnterprise.setId(changeKey).setParentId(changeParentId).setCode(changeCode);
|
changeEnterprise.setId(dropedKey).setParentId(dropedParentId).setCode(dropedCode);
|
List<Enterprise> list = new ArrayList<>();
|
list.add(dropedEnterprise);
|
list.add(changeEnterprise);
|
enterpriseService.updateBatchById(list);
|
}else if("4".equals(status)){
|
//互换位置
|
String finalCode="";
|
List<Enterprise> changeChildList = enterpriseService
|
.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",changeKey)
|
.eq("del_flag",0));
|
if(CollectionUtils.isNotEmpty(changeChildList)){
|
TreeSet<Integer> childIntCodeSet = new TreeSet<>(Comparator.reverseOrder());
|
changeChildList.stream().forEach(sysDepart -> {
|
String orgCode = sysDepart.getCode();
|
Integer subCode = Integer.parseInt(orgCode.substring(orgCode.lastIndexOf(".")+1));
|
childIntCodeSet.add(subCode);
|
});
|
Integer finalIntSubfix=childIntCodeSet.first()+1;
|
finalCode = changeCode+".0"+finalIntSubfix;
|
}
|
else {
|
finalCode = changeCode+".01";
|
}
|
dropedEnterprise.setParentId(changeKey).setCode(finalCode);
|
enterpriseService.updateById(dropedEnterprise);
|
//重新计算调整位置后各孩子的code
|
changeEveryChildCode(dropedKey,finalCode);
|
}else if("2".equals(status)){
|
String prefix = changeCode.substring(0,changeCode.lastIndexOf("."));
|
Integer changeSubfix = Integer.parseInt(changeCode.substring(changeCode.lastIndexOf(".")+1));
|
List<Enterprise> changeChildList = enterpriseService.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",changeParentId)
|
.eq("del_flag",0));
|
changeChildList.stream().forEach(enterprise -> {
|
String code = enterprise.getCode();
|
String id = enterprise.getId();
|
Integer numSubfix = Integer.parseInt(code.substring(code.lastIndexOf(".")+1));
|
if(numSubfix>changeSubfix){
|
numSubfix = numSubfix+1;
|
String finalCode = prefix+".0"+numSubfix;
|
enterprise.setCode(finalCode);
|
changeEveryChildCode(id,finalCode);
|
}
|
});
|
enterpriseService.saveOrUpdateBatch(changeChildList);
|
Integer numDropedSubfix = changeSubfix+1;
|
String finalDropedCode = prefix+".0"+numDropedSubfix;
|
dropedEnterprise.setCode(finalDropedCode).setParentId(changeParentId);
|
changeEveryChildCode(dropedKey,finalDropedCode);
|
enterpriseService.saveOrUpdate(dropedEnterprise);
|
}else if("5".equals(status)){
|
String prefix = changeCode.substring(0,changeCode.lastIndexOf("."));
|
Integer changeSubfix = Integer.parseInt(changeCode.substring(changeCode.lastIndexOf(".")+1));
|
List<Enterprise> changeChildList = enterpriseService.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",changeParentId)
|
.eq("del_flag",0));
|
changeChildList.stream().forEach(enterprise -> {
|
String code = enterprise.getCode();
|
String id = enterprise.getId();
|
Integer numSubfix = Integer.parseInt(code.substring(code.lastIndexOf(".")+1));
|
if(numSubfix>=changeSubfix){
|
numSubfix = numSubfix+1;
|
String finalCode = prefix+".0"+numSubfix;
|
enterprise.setCode(finalCode);
|
changeEveryChildCode(id,finalCode);
|
}
|
});
|
enterpriseService.saveOrUpdateBatch(changeChildList);
|
Integer numDropedSubfix = changeSubfix;
|
String finalDropedCode = prefix+".0"+numDropedSubfix;
|
dropedEnterprise.setCode(finalDropedCode).setParentId(changeParentId);
|
changeEveryChildCode(dropedKey,finalDropedCode);
|
enterpriseService.saveOrUpdate(dropedEnterprise);
|
}
|
|
return Result.OK("树结构调整成功");
|
|
}
|
/**
|
* 判断是否有亲子关系
|
*
|
* @param map
|
* @return
|
*/
|
@PostMapping("/checkPositionInfo")
|
public Result<?> checkPositionInfo(@RequestBody Map<String,String> map){
|
String dropedKey=map.get("dropedKey");
|
String changeKey=map.get("changeKey");
|
return Result.OK(isChildren(changeKey,dropedKey)||isChildren(dropedKey,changeKey));
|
}
|
|
/*-----------------------------------------------以下为提供方便的api-------------------------------*/
|
/**
|
* 升版单个树节点并返回升版后新节点Id
|
* @param sourceEnterprise
|
* @param newParentId
|
* @param newVersion
|
* @return newEnterPriseId
|
*
|
*/
|
public String updataOneNode
|
(
|
Enterprise sourceEnterprise,
|
String newParentId,
|
Integer newVersion
|
){
|
//1.取出旧版本信息;2.创建将新版本集团架构及其版本号并存入数据库
|
// 1.
|
DataVersion oldDataVersion = dataVersionService
|
.getOne(new QueryWrapper<DataVersion>()
|
.eq("business_id",sourceEnterprise.getId())
|
.eq("del_flag",0),true);
|
sourceEnterprise.setId(null)
|
.setParentId(newParentId)
|
.setVersion(newVersion);
|
//2.
|
enterpriseService.save(sourceEnterprise);
|
Enterprise newEnterprise = enterpriseService
|
.getOne(new QueryWrapper<Enterprise>()
|
.eq("code",sourceEnterprise.getCode())
|
.eq("version",newVersion)
|
.eq("del_flag",0),true);
|
DataVersion newDataVersion = new DataVersion();
|
newDataVersion
|
.setVersion(newVersion)
|
.setBusinessType("集团架构")
|
.setBusinessId(newEnterprise.getId())
|
.setIsLastUsable("0")
|
.setVersionStatus("1")
|
.setDelFlag(0)
|
.setSourceVersionId(oldDataVersion.getId());
|
dataVersionService.save(newDataVersion);
|
//将版本号存入关联的集团架构
|
String newDataVersionId = dataVersionService
|
.getOne(new QueryWrapper<DataVersion>()
|
.eq("business_id",newDataVersion.getBusinessId())
|
.eq("del_flag",0)).getId();
|
enterpriseService.update(new UpdateWrapper<Enterprise>()
|
.set("data_version_id",newDataVersionId)
|
.eq("id",newEnterprise.getId()));
|
return newEnterprise.getId();
|
}
|
/**
|
* 递归升版多个节点
|
* @param parentId
|
* @param newParentId
|
* @param version
|
* @param newVersion
|
* @return
|
*/
|
public void recurrenceUpdata(String parentId,String newParentId,Integer version,Integer newVersion){
|
CopyOnWriteArrayList<Enterprise> childList = new CopyOnWriteArrayList<>();
|
childList.addAll(enterpriseService.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",parentId)
|
.eq("version",version)
|
.eq("del_flag",0)));
|
if(CollectionUtils.isNotEmpty(childList)){
|
childList.stream().forEach(childEnterprise ->{
|
//把child的Id存下来,因为在流里边操作对象容易扯着蛋
|
String childNewId= childEnterprise.getId();
|
//将数据存入数据库
|
String childNewParentId=updataOneNode(childEnterprise,newParentId,newVersion);
|
//递归
|
recurrenceUpdata(childNewId,childNewParentId,version,newVersion);
|
} );
|
}
|
|
}
|
/**
|
* 拖拽交换两个树的位置
|
* @param dropedEnterprise
|
* @param changeEnterprise
|
* @return
|
*/
|
public void changePosition(Enterprise dropedEnterprise,Enterprise changeEnterprise){
|
String dropedId = dropedEnterprise.getId();
|
String changeId = changeEnterprise.getId();
|
String dropedParentId = dropedEnterprise.getParentId();
|
String changeParentId = changeEnterprise.getParentId();
|
String dropedCode = dropedEnterprise.getCode();
|
String changeCode = changeEnterprise.getCode();
|
//存在父换子
|
if(dropedId.equals(changeParentId)){
|
dropedEnterprise.setParentId(changeId);
|
changeEnterprise.setParentId(dropedParentId).setCode(dropedCode);
|
enterpriseService.saveOrUpdate(changeEnterprise);
|
enterpriseService.saveOrUpdate(dropedEnterprise);
|
changeEveryChildCode(changeId,dropedCode);
|
}
|
//存在子换父
|
else if(changeId.equals(dropedParentId)){
|
dropedEnterprise.setParentId(changeParentId).setCode(changeCode);
|
changeEnterprise.setParentId(dropedId);
|
enterpriseService.saveOrUpdate(dropedEnterprise);
|
enterpriseService.saveOrUpdate(changeEnterprise);
|
changeEveryChildCode(dropedId,changeCode);
|
}
|
else {
|
dropedEnterprise.setParentId(changeParentId).setCode(changeCode);
|
changeEnterprise.setParentId(dropedParentId).setCode(dropedCode);
|
enterpriseService.saveOrUpdate(dropedEnterprise);
|
enterpriseService.saveOrUpdate(changeEnterprise);
|
changeEveryChildCode(changeId,dropedCode);
|
changeEveryChildCode(dropedId,changeCode);
|
}
|
}
|
/**
|
* 递归调整树节点的code
|
* @param parentId
|
* @param prefix
|
* @return
|
*/
|
public void changeEveryChildCode(String parentId,String prefix){
|
List<Enterprise> children = enterpriseService.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",parentId)
|
.eq("del_flag",0));
|
if(CollectionUtils.isNotEmpty(children)){
|
for(Enterprise enterprise:children){
|
String id = enterprise.getId();
|
String oldCode = enterprise.getCode();
|
String subfix = oldCode.substring(oldCode.lastIndexOf(".")+1);
|
String realCode = prefix+"."+subfix;
|
enterpriseService.update(new UpdateWrapper<Enterprise>().set("code",realCode).eq("id",id));
|
changeEveryChildCode(id,realCode);
|
}
|
}
|
}
|
/**
|
* 递归判断是否为后辈公司
|
* @param parentId
|
* @param id
|
* @return
|
*/
|
public boolean isChildren(String parentId,String id){
|
boolean tag = false;
|
List<String> idList = enterpriseService.list(new QueryWrapper<Enterprise>()
|
.eq("parent_id",parentId)
|
.eq("del_flag",0))
|
.stream()
|
.map(Enterprise::getId)
|
.collect(Collectors.toList());
|
if(CollectionUtils.isNotEmpty(idList)){
|
for(String strId:idList){
|
if(strId.equals(id)){
|
return true;
|
}
|
else if(!tag){
|
tag = isChildren(strId,id);
|
}
|
}
|
}
|
return tag;
|
}
|
|
}
|