|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|