| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package platform.modules.company.service;
- import java.io.File;
- import java.util.List;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.ui.ModelMap;
- import platform.common.Constant;
- import platform.common.base.model.Template;
- import platform.common.base.service.BaseService;
- import platform.common.base.service.DictionaryItemService;
- import platform.common.base.service.TemplateService;
- import platform.modules.company.dao.ProjectMaterialDao;
- import platform.modules.company.entity.*;
- import platform.modules.government.dao.AttachmentDao;
- import platform.modules.government.entity.Attachment;
- import platform.modules.government.entity.FileDown;
- import platform.modules.government.entity.Project;
- import platform.modules.government.service.AttachmentService;
- import platform.modules.government.service.ProjectService;
- import tk.mybatis.mapper.entity.Example;
- /**
- * 项目申报材料
- *
- * @author yl
- */
- @Service
- @Transactional
- public class ProjectMaterialService extends BaseService<ProjectMaterial> {
- @Autowired
- private ProjectMaterialDao projectMaterialDao;
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- 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;
- }
- //仅查询字典表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);
- }
- 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);
- }
- 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());
- }
- 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());
- }
- }
- return true;
- }
- return false;
- }
- public List<ProjectMaterial> gfindProvincesMaterials(ProjectProvinces projectApply) {
- return null;
- }
- /**
- * 删除原有附件
- *
- * @param id
- */
- public void deleteByApplyId(Integer id) {
- projectMaterialDao.deleteByApplyId(id);
- }
- }
|