Browse Source

项目申报各种类附件相关的修改

huZhiHao 5 năm trước cách đây
mục cha
commit
ec4f0c376d

+ 3 - 3
src/main/java/platform/common/base/dao/DictionaryItemDao.java

@@ -5,10 +5,10 @@ import org.apache.ibatis.annotations.Param;
 import platform.common.base.mapper.BaseMapper;
 import platform.common.base.model.DictionaryItem;
 
-public interface DictionaryItemDao extends BaseMapper<DictionaryItem>{
+public interface DictionaryItemDao extends BaseMapper<DictionaryItem> {
 
-	DictionaryItem getDictionaryItem(@Param("name") String name,@Param("value") String value,@Param("typeId") Integer typeId);
+    DictionaryItem getDictionaryItem(@Param("name") String name, @Param("value") String value, @Param("typeId") Integer typeId);
 
-	DictionaryItem findByTypeAndCondition(@Param("typeName") String typeName, @Param("itemCondition")DictionaryItem condition);
+    DictionaryItem findByTypeAndCondition(@Param("typeName") String typeName, @Param("itemCondition") DictionaryItem condition);
 
 }

+ 62 - 6
src/main/java/platform/common/base/service/DictionaryItemService.java

@@ -1,7 +1,8 @@
 package platform.common.base.service;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,10 +12,13 @@ import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 
+import platform.common.Constant;
 import platform.common.base.dao.DictionaryItemDao;
 import platform.common.base.model.DictionaryItem;
 import platform.common.base.model.DictionaryType;
+import platform.common.util.DateUtil;
 import platform.common.util.WebUtil;
+import platform.modules.build.entity.ContractProperty;
 import tk.mybatis.mapper.entity.Example;
 
 @Service
@@ -116,20 +120,20 @@ public class DictionaryItemService extends BaseService<DictionaryItem> {
 
     //根据类型和值(value)查找名称(name)
     public String findNameByTypeAndValue(String typeName, String value) {
-    	if(StringUtils.isNotBlank(typeName) && StringUtils.isNotBlank(value)) {
-    		DictionaryItem condition = new DictionaryItem();
+        if (StringUtils.isNotBlank(typeName) && StringUtils.isNotBlank(value)) {
+            DictionaryItem condition = new DictionaryItem();
             condition.setValue(value);
             DictionaryItem item = dictionaryItemDao.findByTypeAndCondition(typeName, condition);
             if (null != item) {
                 return item.getName();
             }
-    	}
+        }
         return "";
     }
 
     //根据类型和值(value)查找名称(name)
     public String findValueByTypeAndName(String typeName, String name) {
-        if(StringUtils.isNotBlank(typeName) && StringUtils.isNotBlank(name)) {
+        if (StringUtils.isNotBlank(typeName) && StringUtils.isNotBlank(name)) {
             DictionaryItem condition = new DictionaryItem();
             condition.setName(name);
             DictionaryItem item = dictionaryItemDao.findByTypeAndCondition(typeName, condition);
@@ -151,6 +155,58 @@ public class DictionaryItemService extends BaseService<DictionaryItem> {
         return null;
     }
 
+    //根据类型和名称(name)查找Id 离自己申请时间最近
+    public Integer findIdByTypeAndNameRecent(String typeName, String name, String time) {
+
+        DictionaryType type = dictionaryTypeService.getDictionaryType(typeName);
+
+//        Example example = new Example(DictionaryItem.class);
+//        Example.Criteria criteria = example.createCriteria();
+//        criteria.andEqualTo("tid", type.getId());
+//        criteria.andEqualTo("name", name);
+        DictionaryItem condition = new DictionaryItem();
+        condition.setTid(type.getId());
+        condition.setName(name);
+        List<DictionaryItem> dictionaryItemList =this.findListByWhere(condition);
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+        try {
+            Date date1 = sdf.parse(time);
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(date1);
+            cal.add(Calendar.DATE, 1);
+            date1 = cal.getTime();
+
+            Iterator<DictionaryItem> it = dictionaryItemList.iterator();
+            while (it.hasNext()) {
+                DictionaryItem item = it.next();
+                Date date2 = sdf.parse(item.getCreate_time());
+                if (date1.before(date2)){
+                    it.remove();
+                }
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        DictionaryItem item = dictionaryItemList.get(dictionaryItemList.size() - 1);
+        if (null != item) {
+            return item.getId();
+        }
+        return 0;
+    }
+
+    //根据类型和名称(name)查找Id 仅激活
+    public Integer findIdByTypeAndNameActive(String typeName, String name) {
+        DictionaryItem condition = new DictionaryItem();
+        condition.setName(name);
+        condition.setIs_active(true);
+        DictionaryItem item = dictionaryItemDao.findByTypeAndCondition(typeName, condition);
+        if (null != item) {
+            return item.getId();
+        }
+        return null;
+    }
+
     //根据id查找item
     public DictionaryItem findByItemId(Integer id) {
         Example example = new Example(DictionaryItem.class);

+ 1 - 1
src/main/java/platform/modules/company/service/ProjectApplicationService.java

@@ -913,7 +913,7 @@ public class ProjectApplicationService extends BaseService<ProjectApplication> {
         fileDowns.add(annexFour(apply));
 
         //模版文件
-        List<ProjectMaterial> materials = projectMaterialService.findProjectMaterialByType(apply.getProject_id());
+        List<ProjectMaterial> materials = projectMaterialService.findProjectMaterialByTypeActive(apply.getProject_id());
         for (ProjectMaterial material : materials) {
 
             Template template = new Template();

+ 216 - 132
src/main/java/platform/modules/company/service/ProjectMaterialService.java

@@ -26,162 +26,246 @@ import tk.mybatis.mapper.entity.Example;
 
 /**
  * 项目申报材料
- * @author yl
  *
+ * @author yl
  */
 @Service
 @Transactional
-public class ProjectMaterialService extends BaseService<ProjectMaterial>{
+public class ProjectMaterialService extends BaseService<ProjectMaterial> {
+
+    @Autowired
+    private ProjectMaterialDao projectMaterialDao;
 
-	@Autowired
-	private ProjectMaterialDao projectMaterialDao;
-	
-	@Autowired
+    @Autowired
     private AttachmentService attachmentService;
-    
+
     @Autowired
-	private DictionaryItemService dictionaryItemService;
-    
+    private DictionaryItemService dictionaryItemService;
+
     @Autowired
     private AttachmentDao attachmentDao;
-    
-	@Autowired
-	private ProjectService projectService;
-
-	public List<ProjectMaterial> findProjectMaterialByType(Integer projectId) {
-		
-		Integer itemId = 0;
-		
-		Project project = projectService.findById(projectId);
-		if(null != project) {
-			itemId = dictionaryItemService.findIdByTypeAndName(Constant.DictionaryType.PROJECT_NAME, project.getProject_name());
-		}
-		
-    	List<ProjectMaterial> materials = projectMaterialDao.findMaterialTemplateByType(itemId); 
-    	
-		for(ProjectMaterial material : materials) {
-			//绑定模板文件
-			List<Attachment> templateFile = attachmentService.selectByIdAndBusinessId(Constant.Attachment.TEMPLATE,material.getTemplate_id(),null);
-			if(null != templateFile && templateFile.size()>0) {
-				FileDown fileDown = new FileDown(templateFile.get(0).getId(), templateFile.get(0).getFile_name(), templateFile.get(0).getFile_url(),templateFile.get(0).getDownload_uri());
-				material.setTemplateFile(fileDown);
-			}
-			else {
-				material.setTemplateFile(new FileDown(null, material.getContent(), null, null));
-			}
-		}
-    	
-		return materials;
-	}
-
-	public List<ProjectMaterial> getApplyMaterials(ProjectApplication projectApply) {
-		//申请材料
-		List<ProjectMaterial> materials = this.findProjectMaterialByApply(projectApply);
-		return materials;
-	}
-
-	/**
-	 * 2019 附件
-	 * @param applyId
-	 * @return
-	 */
-	public List<ProjectMaterial> getAnnexMaterial(Integer applyId){
-		List<ProjectMaterial> materials = projectMaterialDao.findByContentAndApplyId("annex_template", applyId);
-		for (ProjectMaterial material : materials) {
-			//模版文件
-			Attachment template = attachmentService.findById(material.getTemplate_id());
-			material.setTemplateFile(new FileDown(template.getId(), template.getFile_name(), template.getFile_url(), null));
-			//上传文件
-			List<Attachment> file = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROJECT, material.getId(),null);
-			if(null != file && file.size()>0) {
-				Attachment attachment = file.get(0);
-				FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(),
-						StringUtils.isNotBlank(attachment.getFile_url())?attachment.getFile_url():"", attachment.getDownload_uri());
-				material.setFileDown(fileDown);
-			}
-		}
-		return materials;
-	}
-	
-	/**
-	 * 查找申请文件模板和匹配的已经上传的材料
-	 * @param projectApply
-	 * @return
-	 */
-	public List<ProjectMaterial> findProjectMaterialByApply(ProjectApplication projectApply) {
-		//找出模板,再匹配上传材料
-		List<ProjectMaterial> materialTemplates = findProjectMaterialByType(projectApply.getProject_id());
-		for(ProjectMaterial material : materialTemplates) {
-			ProjectMaterial existMaterial = findMaterialByApplyIdAndTemplateId(projectApply.getId(),material.getTemplate_id());
-			if( null != existMaterial ) {
-				material.setId(existMaterial.getId());
-				material.setApply_id(existMaterial.getApply_id());
-				//绑定文件
-				List<Attachment> file = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROJECT, existMaterial.getId(),null);
-				if(null != file && file.size()>0) {
-					Attachment attachment = file.get(0);
-					FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(),
-							StringUtils.isNotBlank(attachment.getFile_url())?attachment.getFile_url():"", attachment.getDownload_uri());
-					material.setFileDown(fileDown);
-				}
-			}
-		}
-		return materialTemplates;
-	}
-
-	//查找申请的相应模板的上传材料
-	public ProjectMaterial findMaterialByApplyIdAndTemplateId(Integer id, Integer template_id) {
-		Example example = new Example(ProjectMaterial.class);
+
+    @Autowired
+    private ProjectService projectService;
+
+    //全部
+    public List<ProjectMaterial> findProjectMaterialByType(Integer projectId) {
+
+        Integer itemId = 0;
+
+        Project project = projectService.findById(projectId);
+        if (null != project) {
+            itemId = dictionaryItemService.findIdByTypeAndName(Constant.DictionaryType.PROJECT_NAME, project.getProject_name());
+        }
+
+        List<ProjectMaterial> materials = projectMaterialDao.findMaterialTemplateByType(itemId);
+
+        for (ProjectMaterial material : materials) {
+            //绑定模板文件
+            List<Attachment> templateFile = attachmentService.selectByIdAndBusinessId(Constant.Attachment.TEMPLATE, material.getTemplate_id(), null);
+            if (null != templateFile && templateFile.size() > 0) {
+                FileDown fileDown = new FileDown(templateFile.get(0).getId(), templateFile.get(0).getFile_name(), templateFile.get(0).getFile_url(), templateFile.get(0).getDownload_uri());
+                material.setTemplateFile(fileDown);
+            } else {
+                material.setTemplateFile(new FileDown(null, material.getContent(), null, null));
+            }
+        }
+
+        return materials;
+    }
+
+    //仅查询字典表item激活的
+    public List<ProjectMaterial> findProjectMaterialByTypeActive(Integer projectId) {
+
+        Integer itemId = 0;
+
+        Project project = projectService.findById(projectId);
+        if (null != project) {
+            itemId = dictionaryItemService.findIdByTypeAndNameActive(Constant.DictionaryType.PROJECT_NAME, project.getProject_name());
+        }
+
+        List<ProjectMaterial> materials = projectMaterialDao.findMaterialTemplateByType(itemId);
+
+        for (ProjectMaterial material : materials) {
+            //绑定模板文件
+            List<Attachment> templateFile = attachmentService.selectByIdAndBusinessId(Constant.Attachment.TEMPLATE, material.getTemplate_id(), null);
+            if (null != templateFile && templateFile.size() > 0) {
+                FileDown fileDown = new FileDown(templateFile.get(0).getId(), templateFile.get(0).getFile_name(), templateFile.get(0).getFile_url(), templateFile.get(0).getDownload_uri());
+                material.setTemplateFile(fileDown);
+            } else {
+                material.setTemplateFile(new FileDown(null, material.getContent(), null, null));
+            }
+        }
+
+        return materials;
+    }
+
+
+    //仅查询离创建时间最近且小于创建时间的
+    public List<ProjectMaterial> findProjectMaterialByTypeRecent(Integer projectId) {
+
+        Integer itemId = 0;
+
+        Project project = projectService.findById(projectId);
+        if (null != project) {
+            itemId = dictionaryItemService.findIdByTypeAndNameRecent(Constant.DictionaryType.PROJECT_NAME, project.getProject_name(), project.getCreate_time());
+        }
+
+        List<ProjectMaterial> materials = projectMaterialDao.findMaterialTemplateByType(itemId);
+
+        for (ProjectMaterial material : materials) {
+            //绑定模板文件
+            List<Attachment> templateFile = attachmentService.selectByIdAndBusinessId(Constant.Attachment.TEMPLATE, material.getTemplate_id(), null);
+            if (null != templateFile && templateFile.size() > 0) {
+                FileDown fileDown = new FileDown(templateFile.get(0).getId(), templateFile.get(0).getFile_name(), templateFile.get(0).getFile_url(), templateFile.get(0).getDownload_uri());
+                material.setTemplateFile(fileDown);
+            } else {
+                material.setTemplateFile(new FileDown(null, material.getContent(), null, null));
+            }
+        }
+
+        return materials;
+    }
+
+    public List<ProjectMaterial> getApplyMaterials(ProjectApplication projectApply) {
+        //申请材料
+//		List<ProjectMaterial> materials = this.findProjectMaterialByApply(projectApply);
+        //20200805修改逻辑获取最近的 因为可能存在第二年同名的
+        List<ProjectMaterial> materials = this.findProjectMaterialByApplyRecent(projectApply);
+        return materials;
+    }
+
+    /**
+     * 2019 附件
+     *
+     * @param applyId
+     * @return
+     */
+    public List<ProjectMaterial> getAnnexMaterial(Integer applyId) {
+        List<ProjectMaterial> materials = projectMaterialDao.findByContentAndApplyId("annex_template", applyId);
+        for (ProjectMaterial material : materials) {
+            //模版文件
+            Attachment template = attachmentService.findById(material.getTemplate_id());
+            material.setTemplateFile(new FileDown(template.getId(), template.getFile_name(), template.getFile_url(), null));
+            //上传文件
+            List<Attachment> file = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROJECT, material.getId(), null);
+            if (null != file && file.size() > 0) {
+                Attachment attachment = file.get(0);
+                FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(),
+                        StringUtils.isNotBlank(attachment.getFile_url()) ? attachment.getFile_url() : "", attachment.getDownload_uri());
+                material.setFileDown(fileDown);
+            }
+        }
+        return materials;
+    }
+
+    /**
+     * 查找申请文件模板和匹配的已经上传的材料
+     *
+     * @param projectApply
+     * @return
+     */
+    public List<ProjectMaterial> findProjectMaterialByApply(ProjectApplication projectApply) {
+        //找出模板,再匹配上传材料
+        List<ProjectMaterial> materialTemplates = findProjectMaterialByType(projectApply.getProject_id());
+        for (ProjectMaterial material : materialTemplates) {
+            ProjectMaterial existMaterial = findMaterialByApplyIdAndTemplateId(projectApply.getId(), material.getTemplate_id());
+            if (null != existMaterial) {
+                material.setId(existMaterial.getId());
+                material.setApply_id(existMaterial.getApply_id());
+                //绑定文件
+                List<Attachment> file = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROJECT, existMaterial.getId(), null);
+                if (null != file && file.size() > 0) {
+                    Attachment attachment = file.get(0);
+                    FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(),
+                            StringUtils.isNotBlank(attachment.getFile_url()) ? attachment.getFile_url() : "", attachment.getDownload_uri());
+                    material.setFileDown(fileDown);
+                }
+            }
+        }
+        return materialTemplates;
+    }
+
+    /**
+     * 查找申请文件模板和匹配的已经上传的材料 最近的
+     *
+     * @param projectApply
+     * @return
+     */
+    public List<ProjectMaterial> findProjectMaterialByApplyRecent(ProjectApplication projectApply) {
+        //找出模板,再匹配上传材料
+        List<ProjectMaterial> materialTemplates = findProjectMaterialByTypeRecent(projectApply.getProject_id());
+        for (ProjectMaterial material : materialTemplates) {
+            ProjectMaterial existMaterial = findMaterialByApplyIdAndTemplateId(projectApply.getId(), material.getTemplate_id());
+            if (null != existMaterial) {
+                material.setId(existMaterial.getId());
+                material.setApply_id(existMaterial.getApply_id());
+                //绑定文件
+                List<Attachment> file = attachmentService.selectByIdAndBusinessId(Constant.Attachment.PROJECT, existMaterial.getId(), null);
+                if (null != file && file.size() > 0) {
+                    Attachment attachment = file.get(0);
+                    FileDown fileDown = new FileDown(attachment.getId(), attachment.getFile_name(),
+                            StringUtils.isNotBlank(attachment.getFile_url()) ? attachment.getFile_url() : "", attachment.getDownload_uri());
+                    material.setFileDown(fileDown);
+                }
+            }
+        }
+        return materialTemplates;
+    }
+
+    //查找申请的相应模板的上传材料
+    public ProjectMaterial findMaterialByApplyIdAndTemplateId(Integer id, Integer template_id) {
+        Example example = new Example(ProjectMaterial.class);
         Example.Criteria criteria = example.createCriteria();
         criteria.andEqualTo("del_flag", false);
         if (null != id && id > 0) {
-				criteria.andEqualTo("apply_id", id);
+            criteria.andEqualTo("apply_id", id);
         }
         if (null != template_id && template_id > 0) {
             criteria.andEqualTo("template_id", template_id);
         }
         List<ProjectMaterial> materials = this.selectByExample(example);
-        if(null != materials && materials.size()>0) {
-        	return materials.get(0);
+        if (null != materials && materials.size() > 0) {
+            return materials.get(0);
         }
         return null;
-	}
+    }
 
-	public Boolean saveMaterial(ProjectMaterial material) {
-		if (this.saveSelective(material) > 0) {
-			if(null != material.getFileDown() && null != material.getFileDown().getFile_id()) {
-				attachmentDao.updateAttachment(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
-			}
+    public Boolean saveMaterial(ProjectMaterial material) {
+        if (this.saveSelective(material) > 0) {
+            if (null != material.getFileDown() && null != material.getFileDown().getFile_id()) {
+                attachmentDao.updateAttachment(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
+            }
             return true;
         }
         return false;
-	}
-	
-	public Boolean updateMaterial(ProjectMaterial material) {
-		if (this.updateSelective(material) > 0) {
-			if(null != material.getFileDown() && null != material.getFileDown().getFile_id()) {
-				List<Attachment> attachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
-				if (attachments.size() == 0) {
-	            	//size为0,则是重新上传的文件,更新附件
-	                attachmentDao.deleteByBusiness(Constant.Attachment.PROJECT, material.getId());
-	                attachmentDao.updateAttachment(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
-	            }
-			}
+    }
+
+    public Boolean updateMaterial(ProjectMaterial material) {
+        if (this.updateSelective(material) > 0) {
+            if (null != material.getFileDown() && null != material.getFileDown().getFile_id()) {
+                List<Attachment> attachments = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
+                if (attachments.size() == 0) {
+                    //size为0,则是重新上传的文件,更新附件
+                    attachmentDao.deleteByBusiness(Constant.Attachment.PROJECT, material.getId());
+                    attachmentDao.updateAttachment(Constant.Attachment.PROJECT, material.getId(), material.getFileDown().getFile_id());
+                }
+            }
             return true;
         }
         return false;
-	}
-
-	public List<ProjectMaterial> gfindProvincesMaterials(ProjectProvinces projectApply) {
-		return null;
-	}
-
-	/**
-	 * 删除原有附件
-	 *
-	 * @param id
-	 */
-	public void deleteByApplyId(Integer id) {
-		projectMaterialDao.deleteByApplyId(id);
-	}
+    }
+
+    public List<ProjectMaterial> gfindProvincesMaterials(ProjectProvinces projectApply) {
+        return null;
+    }
+
+    /**
+     * 删除原有附件
+     *
+     * @param id
+     */
+    public void deleteByApplyId(Integer id) {
+        projectMaterialDao.deleteByApplyId(id);
+    }
 }

+ 6 - 3
src/main/resources/mapper/common/dictionaryItemDao.xml

@@ -31,15 +31,18 @@
         	from dictionary_item item 
         		left join dictionary_type dtype on item.tid = dtype.id
         		where 
-        		dtype.name = #{typeName} and item.del_flag=0
-        	
+        		dtype.name = #{typeName}
+        		and item.del_flag=0
         	<if test="itemCondition.name!=null and itemCondition.name!=''">
             	and item.name=#{itemCondition.name}
         	</if>
+			<if test="itemCondition.is_active != null and itemCondition.is_active != '' ">
+				and item.is_active=#{itemCondition.is_active}
+			</if>
         	<if test="itemCondition.value!=null and itemCondition.value!=''">
             	and item.value=#{itemCondition.value}
         	</if>
-        	
+        	order by item.create_time desc
         	limit 0,1
     </select>
 </mapper>