|
@@ -0,0 +1,136 @@
|
|
|
+package com.jeeplus.modules.projectEngineering.service;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.jeeplus.common.service.TreeService;
|
|
|
+import com.jeeplus.common.utils.StringUtils;
|
|
|
+import com.jeeplus.modules.projectAccessory.dao.ProjectTemplateDao;
|
|
|
+import com.jeeplus.modules.projectAccessory.entity.ProjectAccessoryInfo;
|
|
|
+import com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo;
|
|
|
+import com.jeeplus.modules.projectEngineering.dao.ProjectEngineeringInfoDao;
|
|
|
+import com.jeeplus.modules.projectEngineering.entity.ProjectEngineeringInfo;
|
|
|
+import com.jeeplus.modules.sys.entity.Office;
|
|
|
+import com.jeeplus.modules.sys.utils.UserUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Transactional(readOnly = true)
|
|
|
+public class ProjectEngineeringService extends TreeService<ProjectEngineeringInfoDao, ProjectEngineeringInfo> {
|
|
|
+ @Autowired
|
|
|
+ private ProjectEngineeringInfoDao engineeringInfoDao;
|
|
|
+
|
|
|
+ public ProjectEngineeringInfo get(String id) {
|
|
|
+ return super.get(id);
|
|
|
+ }
|
|
|
+ private List<ProjectEngineeringInfo> fingIds(Set<String> parentIdSet, String companyId) {
|
|
|
+ return engineeringInfoDao.fingIds(parentIdSet,companyId);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询所有数据
|
|
|
+ * @param projectEngineeringInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ProjectEngineeringInfo> findList(ProjectEngineeringInfo projectEngineeringInfo) {
|
|
|
+ List<ProjectEngineeringInfo> projectEngineeringInfoList = new ArrayList<>();
|
|
|
+ List<ProjectEngineeringInfo> listReturn = Lists.newArrayList();
|
|
|
+ //根据条件查询数据集合
|
|
|
+ List<ProjectEngineeringInfo> listAll = super.findList(projectEngineeringInfo);
|
|
|
+ Office company = UserUtils.getSelectCompany();
|
|
|
+ projectEngineeringInfo.setCompanyId(company.getId());
|
|
|
+ //判断,数据不为空则添加到返回集合中
|
|
|
+ if (listAll!=null && listAll.size()!=0){
|
|
|
+ projectEngineeringInfoList.addAll(listAll);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(projectEngineeringInfoList!=null&&projectEngineeringInfoList.size()>0&&projectEngineeringInfo!=null&& (StringUtils.isNotBlank(projectEngineeringInfo.getEngineeringName())||StringUtils.isNotBlank(projectEngineeringInfo.getIndexNum()))){
|
|
|
+ //标准内容模糊查询,查询所有父节点
|
|
|
+ Set<String> parentIdSet = new HashSet<>();
|
|
|
+ for (ProjectEngineeringInfo engineeringInfo : projectEngineeringInfoList) {
|
|
|
+ String parentIds = engineeringInfo.getParentIds();
|
|
|
+ if (StringUtils.isNotBlank(parentIds)){
|
|
|
+ parentIdSet.addAll(Arrays.asList(parentIds.split(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ProjectEngineeringInfo engineeringInfo : projectEngineeringInfoList) {
|
|
|
+ parentIdSet.remove(engineeringInfo.getId());
|
|
|
+ }
|
|
|
+ projectEngineeringInfoList.addAll(0,this.fingIds(parentIdSet,"0"));
|
|
|
+ projectEngineeringInfoList.addAll(0,this.fingIds(parentIdSet,UserUtils.getSelectCompany().getId()));
|
|
|
+ }
|
|
|
+ sortList(listReturn,projectEngineeringInfoList,"0",true);
|
|
|
+ return listReturn;
|
|
|
+ }
|
|
|
+ public static void sortList(List<ProjectEngineeringInfo> list, List<ProjectEngineeringInfo> sourcelist, String parentId, boolean cascade){
|
|
|
+ for (int i=0; i<sourcelist.size(); i++){
|
|
|
+ ProjectEngineeringInfo e = sourcelist.get(i);
|
|
|
+ if (e.getParent()!=null && StringUtils.isNotBlank(e.getParent().getId()) && e.getParent().getId().equals(parentId)){
|
|
|
+ list.add(e);
|
|
|
+ if (cascade){
|
|
|
+ // 判断是否还有子节点, 有则继续获取子节点
|
|
|
+ for (int j=0; j<sourcelist.size(); j++){
|
|
|
+ ProjectEngineeringInfo child = sourcelist.get(j);
|
|
|
+ if (child.getParent()!=null && StringUtils.isNotBlank(child.getParent().getId()) && child.getParent().getId().equals(e.getId())){
|
|
|
+ sortList(list, sourcelist, e.getId(), true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @param projectEngineeringInfo
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void save(ProjectEngineeringInfo projectEngineeringInfo) {
|
|
|
+ //设置序号
|
|
|
+ if(projectEngineeringInfo.getIsNewRecord()) {
|
|
|
+ projectEngineeringInfo.setParent(this.get(projectEngineeringInfo.getParent().getId()));
|
|
|
+ String orderNum = null;
|
|
|
+ //判断是否选择了父级节点。没有选择则默认为第一级别
|
|
|
+ if(null != projectEngineeringInfo.getParent()){
|
|
|
+ //添加数据
|
|
|
+ String parentids=projectEngineeringInfo.getParent().getParentIds();
|
|
|
+ projectEngineeringInfo.setParentIds(parentids+projectEngineeringInfo.getParent().getId()+",");
|
|
|
+ projectEngineeringInfo.setParentId(projectEngineeringInfo.getParent().getId());
|
|
|
+ orderNum = this.selectOrderNum(projectEngineeringInfo.getParent().getId());
|
|
|
+ projectEngineeringInfo.setCompanyId(UserUtils.getSelectCompany().getId());
|
|
|
+ }else{
|
|
|
+ //添加数据
|
|
|
+ projectEngineeringInfo.setParentIds("0,");
|
|
|
+ projectEngineeringInfo.setParentId("0");
|
|
|
+ orderNum = this.selectOrderNum("0");
|
|
|
+ projectEngineeringInfo.setCompanyId("0");
|
|
|
+ }
|
|
|
+ //判断是否有数据,没有数据则默认给编号01,有则在最大数据上递增1
|
|
|
+ if (StringUtils.isBlank(orderNum)) {
|
|
|
+ projectEngineeringInfo.setIndexNum(projectEngineeringInfo.getParent().getIndexNum() + "01");
|
|
|
+ } else {
|
|
|
+ projectEngineeringInfo.setIndexNum(String.valueOf(Integer.valueOf(orderNum) + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据条件进行新增或修改处理
|
|
|
+ if (StringUtils.isNotBlank(projectEngineeringInfo.getId())){
|
|
|
+ projectEngineeringInfo.preUpdate();
|
|
|
+ dao.update(projectEngineeringInfo);
|
|
|
+ }else{
|
|
|
+ projectEngineeringInfo.preInsert();
|
|
|
+ dao.insert(projectEngineeringInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有父级信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ProjectEngineeringInfo> getParentInfo(){
|
|
|
+ return engineeringInfoDao.getParentAll();
|
|
|
+ }
|
|
|
+ public String selectOrderNum(String parentId) {
|
|
|
+ return engineeringInfoDao.selectOrderNum(parentId);
|
|
|
+ }
|
|
|
+}
|