|
@@ -1,20 +1,32 @@
|
|
|
package com.dragoninfo.dcuc.app.facade.sub;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.dragoninfo.dcuc.app.entity.sub.AppColumnRelation;
|
|
|
+import com.dragoninfo.dcuc.app.entity.sub.FieldCla;
|
|
|
import com.dragoninfo.dcuc.app.service.sub.IAppColumnRelationService;
|
|
|
+import com.dragoninfo.dcuc.app.service.sub.IFieldClaService;
|
|
|
+import com.dragoninfo.dcuc.app.vo.AppColumnDetailVo;
|
|
|
+import com.dragoninfo.dcuc.app.vo.AppColumnRelationPageVO;
|
|
|
import com.dragoninfo.dcuc.app.vo.AppColumnRelationVO;
|
|
|
+import com.dragoninfo.dcuc.app.vo.AppColumnSaveVo;
|
|
|
+import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
|
import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -28,22 +40,119 @@ public class AppColumnRelationFacade implements IAppColumnRelationFacaed {
|
|
|
@Autowired
|
|
|
private IAppColumnRelationService appColumnRelationService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFieldClaService fieldClaService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<AppColumnRelationVO> pageSearch(SearchDTO searchDTO) {
|
|
|
+ public Page<AppColumnRelationPageVO> pageSearch(SearchDTO searchDTO) {
|
|
|
Searchable searchable = Searchable.toSearchable(searchDTO);
|
|
|
Pageable pageable = searchable.getPage();
|
|
|
+ searchable.addSort(Sort.Direction.DESC, "createTime");
|
|
|
Page<AppColumnRelation> page = appColumnRelationService.pageSearch(searchable);
|
|
|
if (page.isEmpty()) {
|
|
|
return new PageImpl<>(Collections.emptyList(), pageable, 0L);
|
|
|
}
|
|
|
List<AppColumnRelation> content = page.getContent();
|
|
|
- List<AppColumnRelationVO> collect = content.stream().map(e -> {
|
|
|
- AppColumnRelationVO vo = new AppColumnRelationVO();
|
|
|
- BeanUtils.copyProperties(e, vo);
|
|
|
+ List<AppColumnRelationPageVO> collect = content.stream().map(e -> {
|
|
|
+ AppColumnRelationPageVO vo = new AppColumnRelationPageVO();
|
|
|
+ vo.setId(e.getId());
|
|
|
+ vo.setCodeValue(e.getCodeValue());
|
|
|
+ String codeName = e.getCodeName();
|
|
|
+ String[] split = codeName.split("->");
|
|
|
+ String relationName = split[0].split(StrUtil.UNDERLINE)[1] + split[1].split(StrUtil.UNDERLINE)[1];
|
|
|
+ vo.setColumnRelation(relationName);
|
|
|
return vo;
|
|
|
}).collect(Collectors.toList());
|
|
|
return new PageImpl<>(collect, pageable, page.getTotalElements());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AppColumnDetailVo detail(String id) {
|
|
|
+ AppColumnRelation relation = appColumnRelationService.getById(id);
|
|
|
+ if (null != relation) {
|
|
|
+ AppColumnDetailVo vo = new AppColumnDetailVo();
|
|
|
+ vo.setId(relation.getId());
|
|
|
+ String codeName = relation.getCodeName();
|
|
|
+ String[] split = codeName.split("->");
|
|
|
+ String oneName = split[0].split(StrUtil.UNDERLINE)[1];
|
|
|
+ String twoName = split[1].split(StrUtil.UNDERLINE)[1];
|
|
|
+ vo.setColumnClaNameOne(oneName);
|
|
|
+ vo.setColumnClaNameTwo(twoName);
|
|
|
+ String oneCode = relation.getColumnOneClassValue();
|
|
|
+ List<FieldCla> oneList = fieldClaService.getByNameLike(oneCode, "2");
|
|
|
+ if (CollectionUtils.isNotEmpty(oneList)) {
|
|
|
+ vo.setColumnClaIdOne(oneList.get(0).getId());
|
|
|
+ }
|
|
|
+ String twoCode = relation.getColumnTwoClassValue();
|
|
|
+ List<FieldCla> twoList = fieldClaService.getByNameLike(twoCode, "2");
|
|
|
+ if (CollectionUtils.isNotEmpty(twoList)) {
|
|
|
+ vo.setColumnClaIdTwo(twoList.get(0).getId());
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteById(String id) {
|
|
|
+ appColumnRelationService.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseStatus relationAdd(AppColumnSaveVo saveVo) {
|
|
|
+ AppColumnRelation relation = getNewRelation(saveVo);
|
|
|
+ AppColumnRelation exist = appColumnRelationService.getByCode(relation.getCodeValue());
|
|
|
+ if (null != exist) {
|
|
|
+ return ResponseStatus.fail("字段关系已存在");
|
|
|
+ }
|
|
|
+ appColumnRelationService.save(relation);
|
|
|
+ return ResponseStatus.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseStatus relationUpdate(AppColumnSaveVo saveVo) {
|
|
|
+ AppColumnRelation relation = getNewRelation(saveVo);
|
|
|
+ String codeValue = relation.getCodeValue();
|
|
|
+ AppColumnRelation oldRelation = appColumnRelationService.getById(saveVo.getId());
|
|
|
+ if (codeValue.equals(oldRelation.getCodeValue())) {
|
|
|
+ return ResponseStatus.fail("字段关系未修改");
|
|
|
+ }
|
|
|
+ AppColumnRelation exist = appColumnRelationService.getByCode(codeValue);
|
|
|
+ if (null != exist) {
|
|
|
+ return ResponseStatus.fail("字段关系已存在");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(relation, oldRelation, "createTime", "createUser");
|
|
|
+ appColumnRelationService.update(oldRelation);
|
|
|
+ return ResponseStatus.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private AppColumnRelation getNewRelation(AppColumnSaveVo saveVo) {
|
|
|
+ String columnIdOne = saveVo.getColumnClaIdOne();
|
|
|
+ String columnIdTwo = saveVo.getColumnClaIdTwo();
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ list.add(columnIdOne);
|
|
|
+ list.add(columnIdTwo);
|
|
|
+ List<FieldCla> secColumnClas = fieldClaService.getByIds(list);
|
|
|
+ List<String> firIds = secColumnClas.stream().map(FieldCla::getFirId).distinct().collect(Collectors.toList());
|
|
|
+ List<FieldCla> firColumnClas = fieldClaService.getByIds(firIds);
|
|
|
+ firColumnClas.addAll(secColumnClas);
|
|
|
+ Map<String, FieldCla> claMap = firColumnClas.stream().collect(Collectors.toMap(FieldCla::getId, e -> e));
|
|
|
+ AppColumnRelation relation = new AppColumnRelation();
|
|
|
+
|
|
|
+ FieldCla oneFieldCla = claMap.get(columnIdOne);
|
|
|
+ FieldCla twoFieldCla = claMap.get(columnIdTwo);
|
|
|
+ String oneName = oneFieldCla.getName();
|
|
|
+ String twoName = twoFieldCla.getName();
|
|
|
+ relation.setColumnOneClassValue(oneName);
|
|
|
+ relation.setColumnTwoClassValue(twoName);
|
|
|
+ FieldCla firOneFieldCla = claMap.get(oneFieldCla.getFirId());
|
|
|
+ FieldCla firTwoFieldCla = claMap.get(twoFieldCla.getFirId());
|
|
|
+ String code = firOneFieldCla.getName() + StrUtil.UNDERLINE + oneName + "->" + firTwoFieldCla + twoName;
|
|
|
+ relation.setCodeName(code);
|
|
|
+ relation.setCodeValue(code);
|
|
|
+ relation.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|