Browse Source

项目类型、成果文件管理关联

user5 4 years atrás
parent
commit
2f6eb7e25a

+ 14 - 0
src/main/java/com/jeeplus/modules/projectType/dao/ProjectResultsFileTemplateDao.java

@@ -93,5 +93,19 @@ public interface ProjectResultsFileTemplateDao  extends CrudDao<ProjectTemplateT
      */
     List<ProjectContentTreeData> getTemplateForm(String typeId);
 
+    /**
+     * 根据parentId获取id
+     * @param parentId
+     * @return
+     */
+    List<String> idList(String parentId);
+
+    /**
+     * 根据parentId获取父节点的tier值
+     * @param parentId
+     * @return
+     */
+    Integer getTierByParentId(String parentId);
+
 
 }

+ 31 - 2
src/main/java/com/jeeplus/modules/projectType/service/ProjectTypeService.java

@@ -2,8 +2,11 @@ package com.jeeplus.modules.projectType.service;
 
 import com.jeeplus.common.persistence.Page;
 import com.jeeplus.common.service.CrudService;
+import com.jeeplus.common.utils.MyBeanUtils;
 import com.jeeplus.common.utils.StringUtils;
+import com.jeeplus.modules.projectType.dao.ProjectResultsFileTemplateDao;
 import com.jeeplus.modules.projectType.dao.ProjectTypeDao;
+import com.jeeplus.modules.projectType.entity.ProjectTemplateType;
 import com.jeeplus.modules.projectType.entity.ProjectType;
 import com.jeeplus.modules.projectcontentinfo.entity.ProjectBasedData;
 import com.jeeplus.modules.projectcontentinfo.entity.ProjectReportTreeData;
@@ -13,6 +16,7 @@ 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.Map;
 
@@ -26,6 +30,8 @@ import java.util.Map;
 public class ProjectTypeService extends CrudService<ProjectTypeDao, ProjectType> {
     @Autowired
     private ProjectTypeDao projectTypeDao;
+    @Autowired
+    private ProjectResultsFileTemplateDao templateDao;
 
     public ProjectType getProjectType(String id) {
         return projectTypeDao.get(id);
@@ -80,8 +86,31 @@ public class ProjectTypeService extends CrudService<ProjectTypeDao, ProjectType>
                /* //根据该父类的id获取该父类的类型,插入到该对像的父类parentId中
                 String parentTypeId=dao.getParentTypeId(projectType.getParentId());
                 projectType.setParentId(parentTypeId);*/
-
-                projectType.setTypeId(typeId);
+                if(StringUtils.isBlank(typeId)){
+                    projectType.setTypeId(projectType.getParentId()+"1");
+                }else{
+                    projectType.setTypeId(typeId);
+                }
+                if(StringUtils.isNotBlank(projectType.getTypeId())){
+                    projectType.setId(projectType.getTypeId());
+                    ProjectTemplateType templateProjectType = new ProjectTemplateType();
+                    try {
+                        MyBeanUtils.copyBeanNotNull2Bean(projectType, templateProjectType);//将编辑表单中的非NULL值覆盖数据库记录中的值
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    List<String> idList = templateDao.idList("0");
+                    if(idList.contains(templateProjectType.getParentId())){
+                        templateProjectType.setTier(2);
+                    }else{
+                        //根据parentId获取父节点tier的值并加1保存
+                        Integer parentTier = templateDao.getTierByParentId(templateProjectType.getParentId());
+                        templateProjectType.setTier(parentTier+1);
+                    }
+                    if(templateProjectType.getTier() <4){
+                        templateDao.insert(templateProjectType);
+                    }
+                }
                 dao.insert(projectType);
             }
 

+ 10 - 0
src/main/resources/mappings/modules/projectType/ProjectResultsFileTemplateDao.xml

@@ -241,4 +241,14 @@
 
 	</select>
 
+	<select id="idList" resultType="java.lang.String">
+		select id from project_template_type a
+		where a.parent_id = #{parentId}
+	</select>
+
+	<select id="getTierByParentId" resultType="java.lang.Integer">
+		select tier from project_template_type a
+		where id=#{parentId}
+	</select>
+
 </mapper>