|
@@ -0,0 +1,640 @@
|
|
|
+package org.springblade.meter.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.manager.entity.ContractInfo;
|
|
|
+import org.springblade.manager.entity.ProjectInfo;
|
|
|
+import org.springblade.meter.dto.MeterTreeContractDTO;
|
|
|
+import org.springblade.meter.dto.MeterTreeContractSaveBatchDTO;
|
|
|
+import org.springblade.meter.entity.MeterTreeContract;
|
|
|
+import org.springblade.meter.entity.MeterTreeProject;
|
|
|
+import org.springblade.meter.entity.MeterTreeSystem;
|
|
|
+import org.springblade.meter.entity.MeterTreeTemplateInfo;
|
|
|
+import org.springblade.meter.service.MeterTreeContractService;
|
|
|
+import org.springblade.meter.service.MeterTreeProjectService;
|
|
|
+import org.springblade.meter.service.MeterTreeSystemService;
|
|
|
+import org.springblade.meter.service.MeterTreeTemplateInfoService;
|
|
|
+import org.springblade.meter.vo.MeterTreeContractVO;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/tree")
|
|
|
+@Api(value = "计量单元(树)接口", tags = "计量单元(树)接口")
|
|
|
+public class MeterTreeController extends BladeController {
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+ private final BladeRedis bladeRedis;
|
|
|
+ private final MeterTreeTemplateInfoService meterTreeTemplateInfoService;
|
|
|
+ private final MeterTreeSystemService meterTreeSystemService;
|
|
|
+ private final MeterTreeProjectService meterTreeProjectService;
|
|
|
+ private final MeterTreeContractService meterTreeContractService;
|
|
|
+
|
|
|
+ @GetMapping("/template/detail")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "树模板详情", notes = "传入id")
|
|
|
+ public R<MeterTreeTemplateInfo> templateDetail(@RequestParam String id) {
|
|
|
+ return R.data(meterTreeTemplateInfoService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/template/submit")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "树模板新增、修改", notes = "传入MeterTreeTemplateInfo")
|
|
|
+ public R<Object> templateSubmit(@RequestBody MeterTreeTemplateInfo obj) {
|
|
|
+ if (ObjectUtil.isNotEmpty(obj.getId())) {
|
|
|
+ /*修改模板信息*/
|
|
|
+ if (meterTreeTemplateInfoService.updateById(obj)) {
|
|
|
+ /*修改详情根节点名称*/
|
|
|
+ return R.data(meterTreeSystemService.update(Wrappers.<MeterTreeSystem>lambdaUpdate()
|
|
|
+ .eq(MeterTreeSystem::getId, obj.getId())
|
|
|
+ .set(MeterTreeSystem::getNodeName, obj.getName())));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ /*创建模板信息*/
|
|
|
+ if (meterTreeTemplateInfoService.save(obj)) {
|
|
|
+ /*创建详情根节点*/
|
|
|
+ MeterTreeSystem systemTree = new MeterTreeSystem();
|
|
|
+ systemTree.setId(obj.getId());
|
|
|
+ systemTree.setTemplateId(obj.getId());
|
|
|
+ systemTree.setNodeName(obj.getName());
|
|
|
+ systemTree.setParentId(0L);
|
|
|
+ systemTree.setAncestor("0");
|
|
|
+ return R.data(meterTreeSystemService.save(systemTree));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/template/remove")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "树模板删除", notes = "传入ids")
|
|
|
+ public R<Object> templateRemove(@RequestParam String ids) {
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ for (String id : split) {
|
|
|
+ /*删除模板*/
|
|
|
+ if (meterTreeTemplateInfoService.removeById(id)) {
|
|
|
+
|
|
|
+ /*判断项目引用情况,项目引用中无法删除(项目节点sourceNodeId指向就是系统级节点的id*/
|
|
|
+ List<MeterTreeProject> meterTreeProjects = meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .select(MeterTreeProject::getProjectId)
|
|
|
+ .eq(MeterTreeProject::getTemplateId, id)
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .groupBy(MeterTreeProject::getProjectId)
|
|
|
+ );
|
|
|
+ if (meterTreeProjects.size() > 0) {
|
|
|
+ List<Long> projectIds = meterTreeProjects.stream().map(MeterTreeProject::getProjectId).collect(Collectors.toList());
|
|
|
+ List<ProjectInfo> projectInfoList = jdbcTemplate.query("SELECT project_name FROM m_project_info WHERE id in(" + org.apache.commons.lang.StringUtils.join(projectIds, ",") + ")", new BeanPropertyRowMapper<>(ProjectInfo.class));
|
|
|
+ List<String> names = projectInfoList.stream().map(ProjectInfo::getProjectName).collect(Collectors.toList());
|
|
|
+ throw new ServiceException("【" + org.apache.commons.lang.StringUtils.join(names, "、") + "】项目引用中,无法删除该节点");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*删除详情*/
|
|
|
+ meterTreeSystemService.remove(Wrappers.<MeterTreeSystem>lambdaQuery().eq(MeterTreeSystem::getTemplateId, id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/template/page")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "树模板分页", notes = "传入MeterTreeTemplateInfo、Query")
|
|
|
+ public R<IPage<MeterTreeTemplateInfo>> templatePage(@RequestBody MeterTreeTemplateInfo meterTreeTemplateInfo, @RequestBody Query query) {
|
|
|
+ IPage<MeterTreeTemplateInfo> pages = meterTreeTemplateInfoService.page(Condition.getPage(query), Condition.getQueryWrapper(meterTreeTemplateInfo));
|
|
|
+ List<MeterTreeTemplateInfo> sortResult = pages.getRecords().stream()
|
|
|
+ .sorted(Comparator.comparing(MeterTreeTemplateInfo::getCreateTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return R.data(pages.setRecords(sortResult));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/template/list")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "树模板列表", notes = "")
|
|
|
+ public R<List<MeterTreeTemplateInfo>> templateList() {
|
|
|
+ return R.data(meterTreeTemplateInfoService.getBaseMapper().selectList(Wrappers.<MeterTreeTemplateInfo>lambdaQuery().select(MeterTreeTemplateInfo::getName, MeterTreeTemplateInfo::getId)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/system/detail")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "系统树节点详情", notes = "传入id")
|
|
|
+ public R<MeterTreeSystem> systemDetail(@RequestParam String id) {
|
|
|
+ return R.data(meterTreeSystemService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/system/save")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "系统树节点新增", notes = "传入MeterTreeSystem(上级的id赋值到parentId字段上提交)")
|
|
|
+ public R<Object> systemSave(@RequestBody MeterTreeSystem obj) {
|
|
|
+ /*计算parentId、ancestor*/
|
|
|
+ if (ObjectUtil.isEmpty(obj.getParentId()) || ObjectUtil.isEmpty(obj.getAncestor())) {
|
|
|
+ throw new ServiceException("未获取到父节点id或祖级id");
|
|
|
+ }
|
|
|
+ MeterTreeSystem parentNode = meterTreeSystemService.getById(obj.getParentId());
|
|
|
+ if (ObjectUtil.isEmpty(parentNode)) {
|
|
|
+ throw new ServiceException("未获取到父节点信息");
|
|
|
+ }
|
|
|
+ obj.setAncestor(parentNode.getAncestor() + "," + parentNode.getId());
|
|
|
+
|
|
|
+ /*获取最大sort*/
|
|
|
+ Integer maxSort = meterTreeSystemService.selectMaxSort(obj.getParentId());
|
|
|
+ obj.setSort(ObjectUtils.defaultIfNull(maxSort, 0) + 1);
|
|
|
+
|
|
|
+ return R.data(meterTreeSystemService.save(obj));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/system/update")
|
|
|
+ @ApiOperationSupport(order = 7)
|
|
|
+ @ApiOperation(value = "系统树节点修改", notes = "传入MeterTreeSystem")
|
|
|
+ public R<Object> systemUpdate(@RequestBody MeterTreeSystem obj) {
|
|
|
+ return R.data(meterTreeSystemService.updateById(obj));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/system/remove")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "系统树节点删除", notes = "传入id")
|
|
|
+ public R<Object> systemRemove(@RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ MeterTreeSystem obj = meterTreeSystemService.getById(id);
|
|
|
+ if (obj != null) {
|
|
|
+ if (obj.getParentId().equals(0L) && obj.getAncestor().equals("0")) {
|
|
|
+ throw new ServiceException("根节点无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*子节点判断*/
|
|
|
+ Long countChild = meterTreeSystemService.getBaseMapper().selectCount(Wrappers.<MeterTreeSystem>lambdaQuery()
|
|
|
+ .eq(MeterTreeSystem::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeSystem::getStatus, 1)
|
|
|
+ .like(MeterTreeSystem::getAncestor, id)
|
|
|
+ );
|
|
|
+ if (countChild > 0) {
|
|
|
+ throw new ServiceException("该节点下存在子节点,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*判断项目引用情况,项目引用中无法删除(项目节点sourceNodeId指向就是系统级节点的id*/
|
|
|
+ List<MeterTreeProject> meterTreeProjects = meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .select(MeterTreeProject::getProjectId)
|
|
|
+ .eq(MeterTreeProject::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeProject::getSourceNodeId, obj.getId())
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .groupBy(MeterTreeProject::getProjectId)
|
|
|
+ );
|
|
|
+ if (meterTreeProjects.size() > 0) {
|
|
|
+ List<Long> projectIds = meterTreeProjects.stream().map(MeterTreeProject::getProjectId).collect(Collectors.toList());
|
|
|
+ List<ProjectInfo> projectInfoList = jdbcTemplate.query("SELECT project_name FROM m_project_info WHERE id in(" + org.apache.commons.lang.StringUtils.join(projectIds, ",") + ")", new BeanPropertyRowMapper<>(ProjectInfo.class));
|
|
|
+ List<String> names = projectInfoList.stream().map(ProjectInfo::getProjectName).collect(Collectors.toList());
|
|
|
+ throw new ServiceException("【" + org.apache.commons.lang.StringUtils.join(names, "、") + "】项目引用中,无法删除该节点");
|
|
|
+ }
|
|
|
+ return R.data(meterTreeSystemService.removeById(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/system/same-list")
|
|
|
+ @ApiOperationSupport(order = 9)
|
|
|
+ @ApiOperation(value = "系统树节点同级列表", notes = "传入parentId")
|
|
|
+ public R<List<MeterTreeSystem>> systemSameList(@RequestParam String parentId) {
|
|
|
+ if (StringUtils.isNotEmpty(parentId)) {
|
|
|
+ return R.data(meterTreeSystemService.getBaseMapper().selectList(Wrappers.<MeterTreeSystem>lambdaQuery()
|
|
|
+ .eq(MeterTreeSystem::getParentId, parentId)
|
|
|
+ .eq(MeterTreeSystem::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeSystem::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/system/sort")
|
|
|
+ @ApiOperationSupport(order = 10)
|
|
|
+ @ApiOperation(value = "系统树节点同级排序", notes = "传入节点ids逗号拼接字符串,按照顺序从上到下")
|
|
|
+ public R<Object> systemSort(@RequestBody String ids) {
|
|
|
+ if (StringUtils.isNotEmpty(ids)) {
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ int sort = 1;
|
|
|
+ for (String id : split) {
|
|
|
+ meterTreeSystemService.update(Wrappers.<MeterTreeSystem>lambdaUpdate()
|
|
|
+ .set(MeterTreeSystem::getSort, sort++)
|
|
|
+ .eq(MeterTreeSystem::getId, id)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/system/lazy")
|
|
|
+ @ApiOperationSupport(order = 11)
|
|
|
+ @ApiOperation(value = "系统树节点懒加载", notes = "传入templateId、节点id(根节点id=0)")
|
|
|
+ public R<List<MeterTreeSystem>> systemLazy(@RequestParam String templateId, @RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id) && StringUtils.isNotEmpty(templateId)) {
|
|
|
+ return R.data(meterTreeSystemService.getBaseMapper().selectList(Wrappers.<MeterTreeSystem>lambdaQuery()
|
|
|
+ .eq(MeterTreeSystem::getParentId, id)
|
|
|
+ .eq(MeterTreeSystem::getTemplateId, templateId)
|
|
|
+ .eq(MeterTreeSystem::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeSystem::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/system/child-list")
|
|
|
+ @ApiOperationSupport(order = 12)
|
|
|
+ @ApiOperation(value = "系统树节点下级节点列表", notes = "传入id")
|
|
|
+ public R<List<MeterTreeSystem>> systemChildList(@RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ return R.data(meterTreeSystemService.getBaseMapper().selectList(Wrappers.<MeterTreeSystem>lambdaQuery()
|
|
|
+ .like(MeterTreeSystem::getAncestor, id)
|
|
|
+ .eq(MeterTreeSystem::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeSystem::getCreateTime)
|
|
|
+ .orderByAsc(MeterTreeSystem::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/project/detail")
|
|
|
+ @ApiOperationSupport(order = 13)
|
|
|
+ @ApiOperation(value = "项目树节点详情", notes = "传入id")
|
|
|
+ public R<MeterTreeProject> projectDetail(@RequestParam String id) {
|
|
|
+ return R.data(meterTreeProjectService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/project/save")
|
|
|
+ @ApiOperationSupport(order = 14)
|
|
|
+ @ApiOperation(value = "项目树节点新增", notes = "传入MeterTreeProject(上级的id赋值到parentId字段上提交)")
|
|
|
+ public R<Object> projectSave(@RequestBody MeterTreeProject obj) {
|
|
|
+ /*计算parentId、ancestor*/
|
|
|
+ if (ObjectUtil.isEmpty(obj.getParentId()) || ObjectUtil.isEmpty(obj.getAncestor())) {
|
|
|
+ throw new ServiceException("未获取到父节点id或祖级id");
|
|
|
+ }
|
|
|
+ MeterTreeProject parentNode = meterTreeProjectService.getById(obj.getParentId());
|
|
|
+ if (ObjectUtil.isEmpty(parentNode)) {
|
|
|
+ throw new ServiceException("未获取到父节点信息");
|
|
|
+ }
|
|
|
+ obj.setAncestor(parentNode.getAncestor() + "," + parentNode.getId());
|
|
|
+
|
|
|
+ /*获取最大sort*/
|
|
|
+ Integer maxSort = meterTreeProjectService.selectMaxSort(obj.getParentId());
|
|
|
+ obj.setSort(ObjectUtils.defaultIfNull(maxSort, 0) + 1);
|
|
|
+
|
|
|
+ obj.setDataSourceType(2); //客户手动新增
|
|
|
+ obj.setSourceNodeId(null); //手动新增无源节点id
|
|
|
+ obj.setUpdateStatus(0); //非编辑
|
|
|
+
|
|
|
+ return R.data(meterTreeProjectService.save(obj));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/project/update")
|
|
|
+ @ApiOperationSupport(order = 15)
|
|
|
+ @ApiOperation(value = "项目树节点修改", notes = "传入MeterTreeProject")
|
|
|
+ public R<Object> projectUpdate(@RequestBody MeterTreeProject obj) {
|
|
|
+ obj.setUpdateStatus(1); //编辑
|
|
|
+ return R.data(meterTreeProjectService.updateById(obj));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/project/remove")
|
|
|
+ @ApiOperationSupport(order = 16)
|
|
|
+ @ApiOperation(value = "项目树节点删除", notes = "传入id")
|
|
|
+ public R<Object> projectRemove(@RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ MeterTreeProject obj = meterTreeProjectService.getById(id);
|
|
|
+ if (obj != null) {
|
|
|
+ if (obj.getParentId().equals(0L) && obj.getAncestor().equals("0")) {
|
|
|
+ throw new ServiceException("根节点无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*子节点判断*/
|
|
|
+ Long countChild = meterTreeProjectService.getBaseMapper().selectCount(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .eq(MeterTreeProject::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeProject::getProjectId, obj.getProjectId())
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .like(MeterTreeProject::getAncestor, id)
|
|
|
+ );
|
|
|
+ if (countChild > 0) {
|
|
|
+ throw new ServiceException("该节点下存在子节点,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*判断合同段引用情况,合同段引用中无法删除(合同段节点sourceNodeId指向就是项目节点的id*/
|
|
|
+ List<MeterTreeContract> meterTreeContracts = meterTreeContractService.getBaseMapper().selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .select(MeterTreeContract::getContractId)
|
|
|
+ .eq(MeterTreeContract::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeContract::getProjectId, obj.getProjectId())
|
|
|
+ .eq(MeterTreeContract::getSourceNodeId, obj.getId())
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .groupBy(MeterTreeContract::getContractId)
|
|
|
+ );
|
|
|
+ if (meterTreeContracts.size() > 0) {
|
|
|
+ List<Long> contractIds = meterTreeContracts.stream().map(MeterTreeContract::getContractId).collect(Collectors.toList());
|
|
|
+ List<ContractInfo> contractInfoList = jdbcTemplate.query("SELECT contract_name FROM m_contract_info WHERE id in(" + org.apache.commons.lang.StringUtils.join(contractIds, ",") + ")", new BeanPropertyRowMapper<>(ContractInfo.class));
|
|
|
+ List<String> names = contractInfoList.stream().map(ContractInfo::getContractName).collect(Collectors.toList());
|
|
|
+ throw new ServiceException("【" + org.apache.commons.lang.StringUtils.join(names, "、") + "】合同段引用中,无法删除该节点");
|
|
|
+ }
|
|
|
+ return R.data(meterTreeProjectService.removeById(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/project/same-list")
|
|
|
+ @ApiOperationSupport(order = 17)
|
|
|
+ @ApiOperation(value = "项目树节点同级列表", notes = "传入parentId")
|
|
|
+ public R<List<MeterTreeProject>> projectSameList(@RequestParam String parentId) {
|
|
|
+ if (StringUtils.isNotEmpty(parentId)) {
|
|
|
+ return R.data(meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .eq(MeterTreeProject::getParentId, parentId)
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeProject::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/project/sort")
|
|
|
+ @ApiOperationSupport(order = 18)
|
|
|
+ @ApiOperation(value = "项目树节点同级排序", notes = "传入节点ids逗号拼接字符串,按照顺序从上到下")
|
|
|
+ public R<Object> projectSort(@RequestBody String ids) {
|
|
|
+ if (StringUtils.isNotEmpty(ids)) {
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ int sort = 1;
|
|
|
+ for (String id : split) {
|
|
|
+ meterTreeProjectService.update(Wrappers.<MeterTreeProject>lambdaUpdate()
|
|
|
+ .set(MeterTreeProject::getSort, sort++)
|
|
|
+ .eq(MeterTreeProject::getId, id)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/project/lazy")
|
|
|
+ @ApiOperationSupport(order = 19)
|
|
|
+ @ApiOperation(value = "项目树节点懒加载", notes = "传入projectId、节点id(根节点id=0)")
|
|
|
+ public R<List<MeterTreeProject>> projectLazy(@RequestParam String projectId, @RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id) && StringUtils.isNotEmpty(projectId)) {
|
|
|
+ return R.data(meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .eq(MeterTreeProject::getParentId, id)
|
|
|
+ .eq(MeterTreeProject::getProjectId, projectId)
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeProject::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/refresh")
|
|
|
+ @ApiOperationSupport(order = 20)
|
|
|
+ @ApiOperation(value = "合同段树新增、同步(重加载树)", notes = "传入项目projectId、合同段contractId")
|
|
|
+ public R<Object> contractRefresh(@RequestParam String projectId, @RequestParam String contractId) {
|
|
|
+ boolean result = false;
|
|
|
+ if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(contractId)) {
|
|
|
+ String redisKey = "meter:contract:refresh-tree:" + projectId + "_" + contractId;
|
|
|
+ String redisValue = bladeRedis.get(redisKey);
|
|
|
+ if (StringUtils.isNotEmpty(redisValue) && redisValue.equals("1")) {
|
|
|
+ return R.fail(400, "请勿重复提交,60秒后再尝试");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*首先判断是否存在项目树*/
|
|
|
+ MeterTreeProject rootNode = meterTreeProjectService.getBaseMapper().selectOne(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .select(MeterTreeProject::getTemplateId)
|
|
|
+ .eq(MeterTreeProject::getProjectId, projectId)
|
|
|
+ .eq(MeterTreeProject::getParentId, 0L)
|
|
|
+ .eq(MeterTreeProject::getAncestor, "0")
|
|
|
+ .eq(MeterTreeProject::getStatus, 1));
|
|
|
+
|
|
|
+ if (rootNode != null) {
|
|
|
+ /*当前项目所有树*/
|
|
|
+ List<MeterTreeProject> meterTreeProjects = meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .eq(MeterTreeProject::getTemplateId, rootNode.getTemplateId())
|
|
|
+ .eq(MeterTreeProject::getProjectId, projectId)
|
|
|
+ .eq(MeterTreeProject::getStatus, 1));
|
|
|
+
|
|
|
+ /*判断合同段是否存在树,不存在为初始化,存在则为同步*/
|
|
|
+ Long count = meterTreeContractService.getBaseMapper().selectCount(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getTemplateId, rootNode.getTemplateId())
|
|
|
+ .eq(MeterTreeContract::getContractId, contractId)
|
|
|
+ .eq(MeterTreeContract::getParentId, 0L)
|
|
|
+ .eq(MeterTreeContract::getAncestor, "0")
|
|
|
+ .eq(MeterTreeContract::getStatus, 1));
|
|
|
+
|
|
|
+ if (count == 0) {
|
|
|
+ /*初始化新增到合同段*/
|
|
|
+ result = meterTreeContractService.contractTreeInit(meterTreeProjects, Long.parseLong(contractId));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ /*同步修改到合同段(增量)*/
|
|
|
+ result = meterTreeContractService.contractTreeSync(meterTreeProjects, rootNode.getTemplateId(), Long.parseLong(contractId), Long.parseLong(projectId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /*加锁*/
|
|
|
+ bladeRedis.set(redisKey, "1");
|
|
|
+ bladeRedis.expire(redisKey, 60);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未获取到项目计量单元信息!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (result) {
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/left-list")
|
|
|
+ @ApiOperationSupport(order = 21)
|
|
|
+ @ApiOperation(value = "合同段-新增/增补单元-左边节点列表", notes = "传入id")
|
|
|
+ public R<List<MeterTreeProject>> leftList(@RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ MeterTreeContract contractNode = meterTreeContractService.getById(id);
|
|
|
+ if (contractNode != null) {
|
|
|
+ /*根据数据源id获取到对应项目的节点*/
|
|
|
+ MeterTreeProject projectNode = meterTreeProjectService.getById(contractNode.getSourceNodeId());
|
|
|
+ if (projectNode != null) {
|
|
|
+ /*获取项目树子级(即左边节点列表)*/
|
|
|
+ return R.data(meterTreeProjectService.getBaseMapper().selectList(Wrappers.<MeterTreeProject>lambdaQuery()
|
|
|
+ .eq(MeterTreeProject::getParentId, projectNode.getId())
|
|
|
+ .eq(MeterTreeProject::getStatus, 1)
|
|
|
+ ));
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未获取到项目计量单元信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/contract/save")
|
|
|
+ @ApiOperationSupport(order = 22)
|
|
|
+ @ApiOperation(value = "合同段树节点新增", notes = "传入MeterTreeContractSaveBatchDTO")
|
|
|
+ public R<Object> contractSave(@RequestBody MeterTreeContractSaveBatchDTO dto) {
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getDataList()) && dto.getDataList().size() > 0 && (dto.getRequestType().equals(1) || dto.getRequestType().equals(2))) {
|
|
|
+ if (meterTreeContractService.contractSave(dto)) {
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/contract/update")
|
|
|
+ @ApiOperationSupport(order = 23)
|
|
|
+ @ApiOperation(value = "合同段树节点修改", notes = "传入MeterTreeContractDTO")
|
|
|
+ public R<Object> contractUpdate(@RequestBody MeterTreeContractDTO dto) {
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getDecompositionList()) && dto.getDecompositionList().size() > 0) {
|
|
|
+ /*最底层节点修改*/
|
|
|
+ dto.setUpdateStatus(1); //编辑
|
|
|
+ boolean b1 = meterTreeContractService.updateById(dto);
|
|
|
+ boolean b2 = true; //TODO 修改分解清单列表信息
|
|
|
+ if (b1 && b2) {
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ } else if (ObjectUtil.isEmpty(dto.getDecompositionList()) || dto.getDecompositionList().size() == 0) {
|
|
|
+ /*非最底层节点修改*/
|
|
|
+ dto.setUpdateStatus(1); //编辑
|
|
|
+ if (meterTreeContractService.updateById(dto)) {
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/detail")
|
|
|
+ @ApiOperationSupport(order = 24)
|
|
|
+ @ApiOperation(value = "合同段树节点详情", notes = "传入id")
|
|
|
+ public R<MeterTreeContractVO> contractDetail(@RequestParam String id) {
|
|
|
+ MeterTreeContract basicInfo = meterTreeContractService.getById(id);
|
|
|
+ if (basicInfo != null) {
|
|
|
+ MeterTreeContractVO vo = new MeterTreeContractVO();
|
|
|
+ BeanUtil.copyProperties(basicInfo, vo);
|
|
|
+
|
|
|
+ //TODO 此处为分解列表信息,查询赋值
|
|
|
+ vo.setDecompositionList(null);
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/lazy")
|
|
|
+ @ApiOperationSupport(order = 25)
|
|
|
+ @ApiOperation(value = "合同段树节点懒加载", notes = "传入contractId、节点id(根节点id=0)")
|
|
|
+ public R<List<MeterTreeContract>> contractLazy(@RequestParam String contractId, @RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id) && StringUtils.isNotEmpty(contractId)) {
|
|
|
+ return R.data(meterTreeContractService.getBaseMapper().selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getParentId, id)
|
|
|
+ .eq(MeterTreeContract::getContractId, contractId)
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeContract::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/same-list")
|
|
|
+ @ApiOperationSupport(order = 26)
|
|
|
+ @ApiOperation(value = "合同段树节点同级列表", notes = "传入parentId")
|
|
|
+ public R<List<MeterTreeContract>> contractSameList(@RequestParam String parentId) {
|
|
|
+ if (StringUtils.isNotEmpty(parentId)) {
|
|
|
+ return R.data(meterTreeContractService.getBaseMapper().selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getParentId, parentId)
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .orderByAsc(MeterTreeContract::getSort)));
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/contract/sort")
|
|
|
+ @ApiOperationSupport(order = 27)
|
|
|
+ @ApiOperation(value = "合同段树节点同级排序", notes = "传入节点ids逗号拼接字符串,按照顺序从上到下")
|
|
|
+ public R<Object> contractSort(@RequestBody String ids) {
|
|
|
+ if (StringUtils.isNotEmpty(ids)) {
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ int sort = 1;
|
|
|
+ for (String id : split) {
|
|
|
+ meterTreeContractService.update(Wrappers.<MeterTreeContract>lambdaUpdate()
|
|
|
+ .set(MeterTreeContract::getSort, sort++)
|
|
|
+ .eq(MeterTreeContract::getId, id)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/remove")
|
|
|
+ @ApiOperationSupport(order = 28)
|
|
|
+ @ApiOperation(value = "合同段树节点删除", notes = "传入id")
|
|
|
+ public R<Object> contractRemove(@RequestParam String id) {
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ MeterTreeContract obj = meterTreeContractService.getById(id);
|
|
|
+ if (obj != null) {
|
|
|
+ if (obj.getParentId().equals(0L) && obj.getAncestor().equals("0")) {
|
|
|
+ throw new ServiceException("根节点无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*子节点判断*/
|
|
|
+ Long countChild = meterTreeContractService.getBaseMapper().selectCount(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .eq(MeterTreeContract::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeContract::getProjectId, obj.getProjectId())
|
|
|
+ .eq(MeterTreeContract::getContractId, obj.getContractId())
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .like(MeterTreeContract::getAncestor, id)
|
|
|
+ );
|
|
|
+ if (countChild > 0) {
|
|
|
+ throw new ServiceException("该节点下存在子节点,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 判断分解清单列表引用情况,是否确认要删除
|
|
|
+
|
|
|
+ return R.data(meterTreeContractService.removeById(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/contract/lock")
|
|
|
+ @ApiOperationSupport(order = 29)
|
|
|
+ @ApiOperation(value = "合同段树节点锁定/解锁", notes = "传入id、lockStatus=1(锁定),lockStatus=0(解锁)")
|
|
|
+ public R<Object> contractLock(@RequestParam String id, @RequestParam Integer lockStatus) {
|
|
|
+ if (StringUtils.isNotEmpty(id) && (lockStatus.equals(0) || lockStatus.equals(1))) {
|
|
|
+ MeterTreeContract obj = meterTreeContractService.getById(id);
|
|
|
+ if (obj != null) {
|
|
|
+ /*获取所有子级信息*/
|
|
|
+ List<MeterTreeContract> meterTreeContracts = meterTreeContractService.getBaseMapper().selectList(Wrappers.<MeterTreeContract>lambdaQuery()
|
|
|
+ .select(MeterTreeContract::getId)
|
|
|
+ .eq(MeterTreeContract::getTemplateId, obj.getTemplateId())
|
|
|
+ .eq(MeterTreeContract::getProjectId, obj.getProjectId())
|
|
|
+ .eq(MeterTreeContract::getContractId, obj.getContractId())
|
|
|
+ .eq(MeterTreeContract::getStatus, 1)
|
|
|
+ .like(MeterTreeContract::getAncestor, id)
|
|
|
+ );
|
|
|
+ if (meterTreeContracts.size() > 0) {
|
|
|
+ /*添加选择的顶级节点*/
|
|
|
+ meterTreeContracts.add(obj);
|
|
|
+ /*批量修改*/
|
|
|
+ List<Long> contractNodeIds = meterTreeContracts.stream().map(MeterTreeContract::getId).collect(Collectors.toList());
|
|
|
+ UpdateWrapper<MeterTreeContract> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("id", contractNodeIds);
|
|
|
+ MeterTreeContract updateEntity = new MeterTreeContract();
|
|
|
+ updateEntity.setIsLock(lockStatus);
|
|
|
+ return R.data(meterTreeContractService.update(updateEntity, updateWrapper));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|