package platform.modules.company.service; import java.io.File; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.exceptions.ClientException; import com.xiaoleilu.hutool.util.StrUtil; import org.apache.commons.lang3.StringUtils; import org.apache.xmlbeans.impl.xb.xsdschema.Public; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import platform.common.Constant; import platform.common.base.model.DictionaryItem; 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.common.exception.BaseException; import platform.common.util.*; import platform.modules.build.entity.Company; import platform.modules.build.service.CompanyService; import platform.modules.company.dao.ProjectApplicationDao; import platform.modules.company.dto.ProjectApplicationSearchCondition; import platform.modules.company.entity.*; import platform.modules.government.dao.ProjectDao; import platform.modules.government.dto.*; import platform.modules.government.entity.*; import platform.modules.government.service.*; import platform.modules.government.service.ProjectService; import platform.modules.sys.entity.Approval; import platform.modules.sys.entity.Group; import platform.modules.sys.entity.Message; import platform.modules.sys.entity.UserGroup; import platform.modules.sys.service.*; import tk.mybatis.mapper.entity.Example; import javax.annotation.Resource; /** * 项目申报Service * * @author yl */ @Service @Transactional public class ProjectApplicationService extends BaseService { @Value("${repositoryPath}") public String repositoryPath; final private String attachmentType = "annex_template"; final private Integer annexTwoId = 18655; final private String annexTwoType = "annex_template_2"; final private String annexTwoUrl = "/docs/annex_template/苏州高新区工业经济发展专项扶持资金申报材料目录.docx"; final private String annexTwoName = "苏州高新区工业经济发展专项扶持资金申报材料目录"; @Autowired private DictionaryItemService dictionaryItemService; @Autowired private CompanyOprationsInfoService companyOprationsInfoService; @Autowired private ProjectApplicationCompanyInfoService projectApplicationCompanyInfoService; @Autowired private ProjectApplicationOperationsInfoService projectApplicationOperationsInfoService; @Autowired private ProjectMaterialService projectMaterialService; @Autowired private ApprovalService approvalService; @Autowired private CompanyService companyService; @Autowired private ProjectService projectService; @Autowired private ProjectApplicationDao projectApplicationDao; @Autowired private ProjectApplicationService projectApplicationService; @Autowired private ProjectTypeService projectTypeService; @Autowired private ProjectDeclarationService projectDeclarationService; @Autowired private MessageService messageService; @Autowired private StreetService streetService; @Autowired private UserService userService; @Autowired private WaitToDoService waitToDoService; @Resource private ProjectDao projectDao; @Autowired private GroupService groupService; @Autowired private UserGroupService userGroupService; @Autowired private AttachmentService attachmentService; @Autowired private TemplateService templateService; public PageInfo findPage(Integer pageNum, Integer pageSize, String keyword, ProjectApplicationSearchCondition searchCondition) { Example example = new Example(ProjectApplication.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); if (StringUtils.isNotBlank(searchCondition.getProject_name())) { criteria.andLike("project_name", "%" + searchCondition.getProject_name() + "%"); } if (StringUtils.isNotBlank(searchCondition.getProject_type())) { criteria.andEqualTo("project_type", searchCondition.getProject_type()); } if (ShiroUtils.getUserType().equals(Constant.UserType.COMPANY)) { Integer companyId = ShiroUtils.getCompanyId(); if (null != companyId) { criteria.andEqualTo("company_id", companyId); } } if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { Integer streetId = ShiroUtils.getStreetId(); if (null != streetId) { criteria.andEqualTo("street_id", streetId); } } if (StringUtils.isNotBlank(searchCondition.getStartTime())) { criteria.andCondition("apply_date >= ", searchCondition.getStartTime().substring(0, 10)); } if (StringUtils.isNotBlank(searchCondition.getEndTime())) { criteria.andCondition("apply_date <= ", searchCondition.getEndTime().substring(0, 10)); } if (searchCondition.getProject_year() != null && !searchCondition.getProject_year().equals("")) criteria.andCondition("apply_date like", searchCondition.getProject_year() + "-%"); //倒序 example.setOrderByClause("create_time desc"); PageHelper.startPage(pageNum, pageSize); List applys = this.selectByExample(example); for (ProjectApplication projectApply : applys) { getFullInfo(projectApply); } return new PageInfo(applys); } public ProjectApplication getFullInfo(ProjectApplication projectApply) { if (null != projectApply.getCompany_id()) { Company company = companyService.findById(projectApply.getCompany_id()); projectApply.setCompany_name(company.getCompany_name()); } if (null != projectApply.getProject_type()) { ProjectType type = projectTypeService.findById(projectApply.getProject_type()); if (null != type) { String typeName = type.getType_name(); projectApply.setProject_type_name(typeName); String super_type_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE, type.getSuper_type()); projectApply.setProject_super_type_name(super_type_name); } } if (null != projectApply.getApply_status()) { String status_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPLY_STATUS, projectApply.getApply_status()); projectApply.setApply_status_name(status_name); if (projectApply.getApply_status().equals(Constant.ProjectApplyStatus.PENDING_SUBMIT) || projectApply.getApply_status().equals(Constant.ProjectApplyStatus.REJECT)) { projectApply.setCanEdit(true); projectApply.setCanDelete(true); } } if (null != projectApply.getDeclaration_id()) { ProjectDeclaration dec = projectDeclarationService.findById(projectApply.getDeclaration_id()); if (null != dec) { //项目大类 String superType = dec.getProject_super_type(); if (StringUtils.isNotBlank(superType)) { DictionaryItem superTypeItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE, superType); if (null != superTypeItem) { projectApply.setProject_super_type_name(superTypeItem.getName()); } } //项目来源 String source = dec.getProject_source(); if (StringUtils.isNotBlank(source)) { DictionaryItem sourceItem = dictionaryItemService.findByTypeAndValue(Constant.DictionaryType.PROJECT_SOURCE, source); if (null != sourceItem) { projectApply.setProject_source_name(sourceItem.getName()); } } } } return projectApply; } public ModelMap getDictInfo(ModelMap modelMap) { //查询币种单位数据 List currencyList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.CURRENCY_UNIT); modelMap.put("currencyList", currencyList); /*//项目类型 List projectTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_APPLICATION_TYPE); modelMap.put("projectTypeList", projectTypeList);*/ //项目申报时,项目类别 if (null == modelMap.get("projectTypeList")) { if (null != modelMap.get("declaration_id")) { //项目类型 Integer declarationId = Integer.valueOf(String.valueOf(modelMap.get("declaration_id"))); if (declarationId > 0) { ProjectDeclaration dec = projectDeclarationService.findById(declarationId); if (null != dec) { String superType = dec.getProject_super_type(); if (StringUtils.isNotBlank(superType)) { // List projectTypeList = projectTypeService.findBySuperType(superType); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); int year = LocalDateTime.parse(dec.getApply_startdate(), formatter).getYear(); List projectTypeList = projectTypeService.findByYear(year); modelMap.put("projectTypeList", projectTypeList); } } } } else { if (modelMap.get("project_year") != null && !modelMap.get("project_year").equals("")) { List projectTypeList = projectTypeService.findByYear(Integer.parseInt(modelMap.get("project_year").toString())); modelMap.put("projectTypeList", projectTypeList); } else { List projectTypeList = projectTypeService.selectAllProjectType(); modelMap.put("projectTypeList", projectTypeList); } } } //项目名称 return modelMap; } /** * 已经申请的取项目申报的新数据,新增申请时根据Companyid查询 * * @param companyId * @param apply * @return */ public List getOperationsInfo(Integer companyId, ProjectApplication apply) { if (null != apply) { //已经申请的取新数据 List infos = projectApplicationOperationsInfoService.findOperationsInfoByApply(apply, Constant.DictionaryType.PROJECT_APPLICATION); return infos; } else { List operationsInfo = new ArrayList(); int year = com.feilong.core.date.DateUtil.getYear(new Date()); for (int i = 1; i <= 3; i++) { int dataYear = year - i; ProjectApplicationOperationsInfo info = new ProjectApplicationOperationsInfo(); info.setCid(companyId); info.setYear(String.valueOf(dataYear)); //企业在数据填报处已经填报的经营信息,带出来 CompanyOprationsInfo beforeInfo = companyOprationsInfoService.findCompanyOprationsByCidAndYear(companyId, String.valueOf(dataYear), Constant.DictionaryType.PROJECT_APPLICATION); if (null != beforeInfo) { info.setCurrOperationInfoId(beforeInfo.getId()); if (beforeInfo.getOperation_income() != null) { info.setOperation_income(beforeInfo.getOperation_income().toString()); } } operationsInfo.add(info); } return operationsInfo; } } private void saveMessage(ProjectApplication apply) { try { Message messages = new Message(); messages.setApply_id(apply.getId()); messages.setTitle("企业提交项目申报"); ProjectDeclaration projectDeclaration = projectDeclarationService.findById(apply.getDeclaration_id()); String projectName = projectDeclaration.getProject_name(); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); String now = sdf2.format(new Date()); String message = ShiroUtils.getUserName() + ",您好。您于“" + now + "”提交的“" + projectName + "项目”的申请已提交,进入审核流程。"; messages.setContent(message); messages.setBusiness_type(Constant.Message_Business_type.PROJECT_APPLY); String[] streetArr = ShiroUtils.getCompanyId().toString().split(","); Set set = new HashSet<>(Arrays.asList(streetArr)); String[] streetArrs = set.toArray(new String[set.size()]); int[] streetArrInt = new int[streetArrs.length]; for (int i = 0; i < streetArrs.length; i++) { streetArrInt[i] = Integer.parseInt(streetArrs[i]); } messageService.saveMessageAndPush(messages, streetArrInt, Constant.UserType.COMPANY); //发送短信 Map params = new HashMap<>(); params.put("project_no", apply.getApply_no()); params.put("apply_name", Constant.ProjectType.PROJECT_APPLICATION); String templatePatram = JSONObject.toJSONString(params); String templateCode = Constant.SMS_TemplateCode.RPOJECT_APPLY_SUBMIT; User companyAdmin = userService.findById(ShiroUtils.getUserId()); AlibabaSMSUtil.sendSMS( companyAdmin.getPhone(), templateCode, Constant.SINGNAMW, templatePatram); Message messages1 = new Message(); messages1.setApply_id(apply.getId()); messages1.setTitle("提醒街道审核"); Company company = companyService.findById(ShiroUtils.getCompanyId()); Street street = streetService.findById(ShiroUtils.getStreetId()); String message1 = street.getName() + ",您好。“" + company.getCompany_name() + "企业”的“" + projectName + "项目”申请需要您审核。谢谢。"; messages1.setContent(message1); messages1.setBusiness_type(Constant.Message_Business_type.PROJECT_APPLY); int[] streetArrInt1 = new int[1]; streetArrInt1[0] = ShiroUtils.getStreetId(); messageService.saveMessageAndPush(messages1, streetArrInt1, Constant.UserType.STREET); List users = userService.findUsersByStreetId(ShiroUtils.getStreetId()); waitToDoService.completeAllTODO(apply.getId(), Constant.DictionaryType.PROJECT_APPLICATION); List pusers = userService.findUsersByPermission("S_PROJECT_APPROVE"); for (User user : users) { for (User puser : pusers) { if (Objects.equals(user.getId(), puser.getId())) { waitToDoService.newTODO("项目申报审核", "/projectApprove/approve/" + apply.getId(), Constant.WaitToDo_OperType.AUDIT, apply.getId(), Constant.DictionaryType.PROJECT_APPLICATION, apply.getApply_no(), user.getId().toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false); //给街道发送短信 // String tempCode = Constant.SMS_TemplateCode.RPOJECT_APPROVAL_REMIND; // AlibabaSMSUtil.sendSMS( // puser.getPhone(), tempCode, Constant.SINGNAMW, templatePatram); } } } } catch (Exception e) { e.printStackTrace(); } } public Boolean saveProjectApply(ProjectApplication apply) { User user = userService.findById(ShiroUtils.getUserId()); apply.setCompany_id(user.getCompany_id()); apply.setBuild_id(user.getBuild_id()); apply.setStreet_id(user.getStreet_id()); String no = GenerateNoUtil.generateProjectApplyNo(Constant.ProjectNoHeader.PROJECT_APPLICATION); apply.setApply_no(no); if (apply.getIsDraft().equals(Constant.IsDraft.DRAFT)) { //保存草稿 apply.setApply_status(Constant.ProjectApplyStatus.PENDING_SUBMIT); } else if (apply.getIsDraft().equals(Constant.IsDraft.NOT_DRAFT)) { //提交申请 apply.setApply_status(Constant.ProjectApplyStatus.IN_AUDIT); apply.setApprove_status(Constant.ProjectApplicationStatus.LOCAL_AUDIT); //申请日期 apply.setApply_date(DateUtil.getTimeStringShort(new Date())); //提交申请,同步数据至企业信息表和企业经营数据表 copyCompanyData(apply); } if (this.insertAndGetId(apply) > 0) { //保存企业基本信息 if (null != apply.getCompanyInfo()) { ProjectApplicationCompanyInfo companyInfo = apply.getCompanyInfo(); companyInfo.setApply_id(apply.getId()); companyInfo.setApply_type(Constant.DictionaryType.PROJECT_APPLICATION); projectApplicationCompanyInfoService.saveSelective(companyInfo); } //保存经营信息 if (null != apply.getOperationsInfo() && apply.getOperationsInfo().size() > 0) { List operationsInfoList = apply.getOperationsInfo(); for (ProjectApplicationOperationsInfo info : operationsInfoList) { info.setApply_id(apply.getId()); info.setApply_type(Constant.DictionaryType.PROJECT_APPLICATION); projectApplicationOperationsInfoService.saveSelective(info); } } //保存材料 if (null != apply.getApplyMaterials() && apply.getApplyMaterials().size() > 0) { for (ProjectMaterial material : apply.getApplyMaterials()) { material.setApply_id(apply.getId()); projectMaterialService.saveMaterial(material); } } if (apply.getIsDraft().equals(Constant.IsDraft.NOT_DRAFT)) { //直接提交申请,添加流程信息 Approval approval = new Approval(); approval.setApply_id(apply.getId()); approval.setApproval_round(1); approval.setAfter_approvalstatus(Constant.ProjectApplicationStatus.LOCAL_AUDIT); String streetChecker = getLocalChecker(apply.getStreet_id()); if (StringUtils.isNotBlank(streetChecker)) { approval.setNextchecker(streetChecker); } else { throw new BaseException("街道没有项目申报审核人员,请联系街道管理员配置。"); } approval.setChecker(ShiroUtils.getUserId()); approval.setType(Constant.DictionaryType.PROJECT_APPLICATION); approval.setOper_type(Constant.OperType.SUBMIT); approval.setDepartment(ShiroUtils.getUserEntity().getCompany_name()); approvalService.insertAndGetId(approval); //发送消息 new Thread(() -> saveMessage(apply), "sndMessage").start(); } } return true; } //街道项目申报审核人 public String getLocalChecker(Integer street_id) { String nextChecker = ""; if (null != street_id) { List users = userService.findUsersByStreetId(street_id); //List pusers = userService.findUsersByPermission("S_PROJECT_APPROVE"); //Group group = groupService.findByName(Constant.XMSBJDSLZ, null); Group group = groupService.findByNameAndUserType(Constant.XMSBJDSLZ, null, Constant.UserType.STREET, ShiroUtils.getStreetId()); if (null == group) { throw new BaseException("操作失败,项目申报街道受理组没有该项目责任单位的审核人员,请联系管理员配置"); } List userGroups = userGroupService.findByGroupId(group.getId()); for (User user : users) { //for (User puser : pusers) { //if (Objects.equals(user.getId(), puser.getId())) { for (UserGroup userGroup : userGroups) { if (Objects.equals(userGroup.getUser_id(), user.getId())) { nextChecker += user.getId() + ","; } } //} //} } } return nextChecker; } public Boolean updateProjectApply(ProjectApplication apply) { ProjectApplication oldApply = findById(apply.getId()); apply.setApply_no(oldApply.getApply_no()); if (apply.getIsDraft().equals(Constant.IsDraft.NOT_DRAFT)) { User user = userService.findById(ShiroUtils.getUserId()); apply.setCompany_id(user.getCompany_id()); apply.setBuild_id(user.getBuild_id()); apply.setStreet_id(user.getStreet_id()); //提交申请 apply.setApply_status(Constant.ProjectApplyStatus.IN_AUDIT); apply.setApprove_status(Constant.ProjectApplicationStatus.LOCAL_AUDIT); //申请日期 if (StringUtils.isBlank(apply.getApply_date())) { apply.setApply_date(DateUtil.getTimeStringShort(new Date())); } //提交申请,同步数据至企业信息表和企业经营数据表 copyCompanyData(apply); saveMessage(apply); } if (this.updateSelective(apply) > 0) { //保存企业基本信息 if (null != apply.getCompanyInfo()) { projectApplicationCompanyInfoService.updateSelective(apply.getCompanyInfo()); } //保存经营信息 if (null != apply.getOperationsInfo() && apply.getOperationsInfo().size() > 0) { List operationsInfoList = apply.getOperationsInfo(); for (ProjectApplicationOperationsInfo info : operationsInfoList) { projectApplicationOperationsInfoService.updateSelective(info); } } //删除原有材料 projectMaterialService.deleteByApplyId(apply.getId()); //保存材料 if (null != apply.getApplyMaterials() && apply.getApplyMaterials().size() > 0) { for (ProjectMaterial material : apply.getApplyMaterials()) { material.setApply_id(apply.getId()); Template template = templateService.findById(material.getTemplate_id()); if (template == null) { material.setContent("annex_template"); } projectMaterialService.saveMaterial(material); } } if (apply.getIsDraft().equals(Constant.IsDraft.NOT_DRAFT)) { //直接提交申请,添加流程信息 Approval latestApproval = approvalService.getLatestApproval(apply.getId(), Constant.DictionaryType.PROJECT_APPLICATION); Approval approval = new Approval(); approval.setApply_id(apply.getId()); if (null != latestApproval) { //是编辑 approval.setOper_type(Constant.OperType.EDIT); approval.setBefore_approvalstatus(latestApproval.getAfter_approvalstatus()); approval.setApproval_round(latestApproval.getApproval_round() == null ? 1 : latestApproval.getApproval_round() + 1); } else { approval.setOper_type(Constant.OperType.SUBMIT); approval.setApproval_round(1); } approval.setAfter_approvalstatus(Constant.ProjectApplicationStatus.LOCAL_AUDIT); approval.setChecker(ShiroUtils.getUserId()); User user = userService.findById(ShiroUtils.getUserId()); Integer street_id = apply.getStreet_id() == null ? user.getStreet_id() : apply.getStreet_id(); //approval.setNextchecker(getLocalChecker(street_id)); String streetChecker = getLocalChecker(street_id); if (StringUtils.isNotBlank(streetChecker)) { approval.setNextchecker(streetChecker); } else { throw new BaseException("街道没有项目申报审核人员,请联系街道管理员配置。"); } approval.setType(Constant.DictionaryType.PROJECT_APPLICATION); approval.setDepartment(ShiroUtils.getUserEntity().getCompany_name()); approvalService.insertAndGetId(approval); //发送短信 ExecutorService threadpool = Executors.newFixedThreadPool(1); threadpool.execute(() -> saveMessage(apply)); } } return true; } private void copyCompanyData(ProjectApplication apply) { //同步企业基本信息 ProjectApplicationCompanyInfo companyInfo = apply.getCompanyInfo(); Company preCompanyInfo = companyService.findById(companyInfo.getCompany_id()); if (StringUtils.isNotBlank(companyInfo.getCompany_name())) { preCompanyInfo.setCompany_name(companyInfo.getCompany_name()); } if (StringUtils.isNotBlank(companyInfo.getRegistration_address())) { preCompanyInfo.setRegistration_address(companyInfo.getRegistration_address()); } if (null != companyInfo.getCurrency_unit()) { preCompanyInfo.setCurrency_unit(companyInfo.getCurrency_unit()); } if (null != companyInfo.getRegistration_capital()) { preCompanyInfo.setRegistration_capital(companyInfo.getRegistration_capital()); } if (StringUtils.isNotBlank(companyInfo.getLegal_representative())) { preCompanyInfo.setLegal_representative(companyInfo.getLegal_representative()); } if (StringUtils.isNotBlank(companyInfo.getLr_position())) { preCompanyInfo.setLr_position(companyInfo.getLr_position()); } companyService.updateSelective(preCompanyInfo); //同步企业营业收入 List operationsInfo = apply.getOperationsInfo(); for (ProjectApplicationOperationsInfo info : operationsInfo) { if (null != info.getOperation_income()) { CompanyOprationsInfo preInfo = companyOprationsInfoService.findCompanyOprationsByCidAndYear(companyInfo.getCompany_id(), String.valueOf(com.feilong.core.date.DateUtil.getYear(new Date())), Constant.DictionaryType.PROJECT_APPLICATION); if (null != preInfo) { preInfo.setOperation_income(Double.parseDouble(info.getOperation_income())); companyOprationsInfoService.updateSelective(preInfo); } } } } public ModelMap getApplyInfo(Integer apply_id, ModelMap modelMap) { //申报详情 ProjectApplication projectApply = this.findById(apply_id); Project project = new Project(); project.setId(projectApply.getProject_id()); project = projectDao.selectOne(project); modelMap.put("isTechnical", project.getIs_technical()); modelMap.put("projectApply", projectApply); if (projectApply.getProject_type() != null) { List projects = projectService.findByType(projectApply.getProject_type().toString()); modelMap.put("projectNameList", projects); } //项目类别 if (projectApply.getDeclaration_id() != null) { //项目类型 Integer declarationId = projectApply.getDeclaration_id(); if (declarationId > 0) { ProjectDeclaration dec = projectDeclarationService.findById(declarationId); if (null != dec) modelMap.put("projectTypeList", projectTypeList(dec.getApply_startdate())); } } //企业信息 ProjectApplicationCompanyInfo companyInfo = projectApplicationCompanyInfoService.findByApplyIdAndType(apply_id, Constant.DictionaryType.PROJECT_APPLICATION); //modelMap.put("companyInfo", companyInfo == null ? new ProjectApplicationCompanyInfo():companyInfo); if (companyInfo == null) { ProjectApplicationCompanyInfo company = new ProjectApplicationCompanyInfo(); company.setIndustry_code(company.getIndustry_code()); company.setIndustry_code(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, company.getIndustry_code())); modelMap.put("companyInfo", company); } else { if (!Objects.equals(companyInfo.getIndustry_code(), "Empty")) { companyInfo.setIndustry_code(companyInfo.getIndustry_code()); companyInfo.setIndustry_name(dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.INDUSTRY_TYPE, companyInfo.getIndustry_code())); } else { companyInfo.setIndustry_name("其他"); } modelMap.put("companyInfo", companyInfo); } //申报材料(模版) List materials = projectMaterialService.getAnnexMaterial(projectApply.getId()); //附件 materials.addAll(projectMaterialService.getApplyMaterials(projectApply)); modelMap.put("applyMaterials", materials); //经营数据 modelMap.put("operationsInfo", getOperationsInfo(null, projectApply)); //申报流程 List approvalList = approvalService.getProjectApprovalList(apply_id); modelMap.put("approvalList", approvalList); //流程信息 return modelMap; } /** * 获取年份申报大类 * * @param apply_startdate * @return */ private List projectTypeList(String apply_startdate) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); int year = LocalDateTime.parse(apply_startdate, formatter).getYear(); return projectTypeService.findByYear(year); } //绑定数据codeName public ProjectApplication getFullApplicationInfo(ProjectApplication projectApply) { if (null != projectApply.getProject_type()) { /*String type_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPLICATION_TYPE, String.valueOf(projectApply.getProject_type())); projectApply.setProject_type_name(type_name);*/ ProjectType type = projectTypeService.findById(projectApply.getProject_type()); if (null != type) { String typeName = type.getType_name(); projectApply.setProject_type_name(typeName); String super_type_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE, type.getSuper_type()); projectApply.setProject_super_type_name(super_type_name); } } if (null != projectApply.getApply_status()) { String status_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPLY_STATUS, projectApply.getApply_status()); projectApply.setApply_status_name(status_name); } if (null != projectApply.getApprove_status()) { String status_name = dictionaryItemService.findNameByTypeAndValue(Constant.DictionaryType.PROJECT_APPROVE_STATUS, projectApply.getApprove_status()); projectApply.setApprove_status_name(status_name); } if (null != projectApply.getCompany_id() && StringUtils.isBlank(projectApply.getCompany_name())) { Company company = companyService.findById(projectApply.getCompany_id()); if (null != company) { projectApply.setCompany_name(company.getCompany_name()); } } return projectApply; } //是否可以申请项目,今年是否已经申请过互斥的项目,或这个项目已经申请过 public Boolean canApplyProject(ProjectApplication apply) { Boolean flag = true; Integer company_id = ShiroUtils.getCompanyId(); Integer project_id = apply.getProject_id(); if (null != project_id) { Project project = projectService.findById(project_id); if (StringUtils.isNotBlank(project.getMutex())) { //今年已经申请过互斥的项目,不能再申请 List mutexApplys = projectApplicationDao.selectMutexApplications(company_id, project); if (null != mutexApplys && mutexApplys.size() > 0) { flag = false; } } else { //查找是否申请过本项目 //20180816 临时去掉同一年同类型只能申请一次的限制 /*List applys = projectApplicationDao.selectApplicationsByCidAndPid(company_id, project_id); if (null != applys && applys.size() > 0) { flag = false; }*/ flag = true; } } return flag; } public List getStreetDeclaerNum(SearchCondition condition) { if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { condition.setUser_type(Constant.UserType.STREET); condition.setStreet_id(ShiroUtils.getStreetId()); } List list = projectApplicationDao.getStreetDeclaerNum(condition); return list; } public List getProjectCategoryRate(SearchCondition condition) { if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { condition.setUser_type(Constant.UserType.STREET); condition.setStreet_id(ShiroUtils.getStreetId()); } List list = projectApplicationDao.getProjectCategoryRate(condition); return list; } //项目申报总数 public int getProjectTotalNum() { int total = projectApplicationDao.getProjectTotalNum(new SearchCondition()); return total; } //通过的项目申报 public int getPassedProjectTotalNum() { SearchCondition condition = new SearchCondition(); condition.setApprove_status(Integer.valueOf(Constant.ProjectApplicationStatus.APPROVED)); int total = projectApplicationDao.getProjectTotalNum(condition); return total; } //发布的项目申报 //2020.04.14修改 改为统计申请通过的数量 由excel导入 public int getReleaseProjectTotalNum() { // Example example = new Example(ProjectDeclaration.class); // Example.Criteria criteria = example.createCriteria(); // criteria.andEqualTo("del_flag", false); // criteria.andEqualTo("status", "1"); // List list = projectDeclarationService.selectByExample(example); Example example = new Example(ProjectApplication.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", false); criteria.andNotEqualTo("apply_status", "0"); criteria.andIsNotNull("pass"); List list = projectApplicationService.selectByExample(example); if (list != null && list.size() > 0) { return list.size(); } return 0; } public ApplicationDto selectYearArray() { return projectApplicationDao.selectYearArray(); } public int selectStreetReportingByYear(Street street, int i) { return projectApplicationDao.selectReportingByYear(street, i); } public int selectProjectReportingByYear(ProjectType projectType, int i) { SearchCondition condition = new SearchCondition(); if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { condition.setUser_type(Constant.UserType.STREET); condition.setStreet_id(ShiroUtils.getStreetId()); } return projectApplicationDao.selectProjectReportingByYear(projectType, i, condition); } public ApplicationDto selectFilingSituation(Integer id, SearchCondition condition) { if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { condition.setUser_type(Constant.UserType.STREET); condition.setStreet_id(ShiroUtils.getStreetId()); } return projectApplicationDao.selectFilingSituation(id, condition); } public ApplicationDto getProjectByType(SearchCondition condition, Integer id) { if (ShiroUtils.getUserType().equals(Constant.UserType.STREET)) { condition.setUser_type(Constant.UserType.STREET); condition.setStreet_id(ShiroUtils.getStreetId()); } return projectApplicationDao.getProjectByType(condition, id); } public List canApplyProjectIntelligent(int companyId) { List applications = projectApplicationDao.canApplyProjectIntelligent(companyId); return applications; } @Transactional(readOnly = true) public Integer getProjectNum() { Example example = new Example(ProjectApplication.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andNotEqualTo("apply_status", 0); return this.selectByExample(example).size(); } @Transactional(readOnly = true) public List getProjectAcceptVolume(BusinessSearchDto businessSearchDto) { Example example = new Example(ProjectApplication.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andNotEqualTo("apply_status", 0); if (businessSearchDto.getWeek()) { criteria.andBetween("create_time", DateUtil.getTimesWeekmorning(), DateUtil.getTimesWeeknight()); } if (businessSearchDto.getMonth()) { criteria.andBetween("create_time", DateUtil.getTimesMonthmorning(), DateUtil.getTimesMonthnight()); } return this.selectByExample(example); } public Integer getprojectDecNum(Integer departmentId) { Example example = new Example(ProjectDeclaration.class); Example.Criteria criteria = example.createCriteria(); // criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("status", 1); criteria.andEqualTo("department_id", departmentId); return projectDeclarationService.selectByExample(example).size(); } public List getProjectTypeRate(SearchCondition searchCondition) { return projectApplicationDao.getProjectTypeRate(searchCondition); } public List getProjectResult(SearchCondition searchCondition) { return projectApplicationDao.getProjectResult(searchCondition); } public List getProjectHandleCompare(SearchCondition searchCondition) { return projectApplicationDao.getProjectHandleCompare(searchCondition); } public List findListByCondition(SearchCondition searchCondition) { return projectApplicationDao.findListByCondition(searchCondition); } public List importList() { return projectApplicationDao.importList(); } /** * 保存项目申报草稿 * * @param apply * @return */ public Integer saveProjectApplyDraft(ProjectApplication apply) { User user = userService.findById(ShiroUtils.getUserId()); apply.setCompany_id(user.getCompany_id()); apply.setBuild_id(user.getBuild_id()); apply.setStreet_id(user.getStreet_id()); String no = GenerateNoUtil.generateProjectApplyNo(Constant.ProjectNoHeader.PROJECT_APPLICATION); apply.setApply_no(no); apply.setApply_status(Constant.ProjectApplyStatus.PENDING_SUBMIT); apply.setApply_date(DateUtil.getTimeStringShort(new Date())); //提交申请,同步数据至企业信息表和企业经营数据表 copyCompanyData(apply); Integer applyId = this.insertAndGetId(apply); if (applyId > 0) { //保存企业基本信息 if (null != apply.getCompanyInfo()) { ProjectApplicationCompanyInfo companyInfo = apply.getCompanyInfo(); companyInfo.setApply_id(apply.getId()); companyInfo.setApply_type(Constant.DictionaryType.PROJECT_APPLICATION); projectApplicationCompanyInfoService.saveSelective(companyInfo); } //保存经营信息 if (null != apply.getOperationsInfo() && apply.getOperationsInfo().size() > 0) { List operationsInfoList = apply.getOperationsInfo(); for (ProjectApplicationOperationsInfo info : operationsInfoList) { info.setApply_id(apply.getId()); info.setApply_type(Constant.DictionaryType.PROJECT_APPLICATION); projectApplicationOperationsInfoService.saveSelective(info); } } } return applyId; } /** * 项目申报生成附件 * * @param apply */ public List createFile(ProjectApplication apply) { List fileDowns = new ArrayList<>(); //生成附件一 fileDowns.add(annexOne(apply)); //附件2 // fileDowns.add(attachmentService.findAnnex2("annex_template_2")); // fileDowns.add(new FileDown(annexTwoId, annexTwoName, annexTwoUrl, null)); fileDowns.add(attachmentService.findAnnex2(annexTwoType)); //附件3 fileDowns.add(annexThree(apply)); //附件4 fileDowns.add(annexFour(apply)); //模版文件 List materials = projectMaterialService.findProjectMaterialByType(apply.getProject_id()); for (ProjectMaterial material : materials) { Template template = new Template(); template.setId(material.getTemplate_id()); FileDown file = templateService.setFile(template); String fileUrl = CommonUtils.isNull(file) ? null : file.getFile_url(); fileDowns.add(new FileDown(material.getTemplate_id(), material.getContent(), fileUrl, material.getTemplate_id() + "")); } return fileDowns; } /** * 附件4 * * @param apply */ private FileDown annexFour(ProjectApplication apply) { final String annexName = "申报专项资金项目承诺书"; // String annexTempUrl = "/Users/xikaiwen/Downloads/annex4.docx"; String annexTempUrl = repositoryPath + "/docs/annex_template/annex4.docx"; //文件数据库存储路径 String annexOutputUrl = getFilePath(annexName, "docs") + ".docx"; // annexOutputUrl = "/Users/xikaiwen/Downloads/新附件4.docx"; Map dataMap = new HashMap<>(); dataMap.put("companyName", apply.getCompanyInfo().getCompany_name()); dataMap.put("customizeName", apply.getCustomize_name()); String type = Constant.DictionaryType.PROJECT_APPLICATION_TYPE; dataMap.put("projectType", projectType(apply.getProject_type()) + "-" + apply.getProject_name()); createAnnex(annexTempUrl, annexOutputUrl, dataMap); return getFileDown(annexName, annexOutputUrl); } /** * 附件3 * * @param apply */ private FileDown annexThree(ProjectApplication apply) { final String annexName = "苏州高新区工业经济发展专项扶持资金申请表"; // String annexTempUrl = "/Users/xikaiwen/Downloads/annex3.docx"; String annexTempUrl = repositoryPath + "/docs/annex_template/annex3.docx"; //文件数据库存储路径 String annexOutputUrl = getFilePath(annexName, "docs") + ".docx"; // annexOutputUrl = "/Users/xikaiwen/Downloads/新附件3.docx"; ProjectApplicationCompanyInfo companyInfo = apply.getCompanyInfo(); List operationsInfo = apply.getOperationsInfo(); Map dataMap = new HashMap<>(); dataMap.put("name", companyInfo.getCompany_name()); dataMap.put("business", dictionaryItemValue(Constant.DictionaryType.INDUSTRY_TYPE, companyInfo.getIndustry_code())); dataMap.put("regAddress", companyInfo.getRegistration_address()); dataMap.put("regCap", companyInfo.getRegistration_capital()); dataMap.put("lr", companyInfo.getLegal_representative()); dataMap.put("lrPosition", companyInfo.getLr_position()); dataMap.put("lrPhone", companyInfo.getLr_phone()); dataMap.put("contact", companyInfo.getContact()); dataMap.put("position", companyInfo.getContact_position()); dataMap.put("phone", companyInfo.getContact_phone()); dataMap.put("ta", companyInfo.getTotal_assets()); dataMap.put("fa", companyInfo.getFixed_assets()); //币种 dataMap.put("cn", currencyUnit(companyInfo.getCurrency_unit())); dataMap.put("faunit", currencyUnit(companyInfo.getFixed_assets_currency_unit())); dataMap.put("taunit", currencyUnit(companyInfo.getTotal_assets_currency_unit())); currencyUnit(companyInfo.getFixed_assets_currency_unit()); //近三年营收情况 for (int i = 0; i < 3; i++) { dataMap.put("oi" + i, operationsInfo.get(i).getOperation_income()); dataMap.put("si" + i, operationsInfo.get(i).getSales_income()); dataMap.put("pi" + i, operationsInfo.get(i).getProcessing_income()); dataMap.put("st" + i, operationsInfo.get(i).getStorage_tax()); dataMap.put("at" + i, operationsInfo.get(i).getAdded_value_tax()); dataMap.put("bt" + i, operationsInfo.get(i).getBusiness_tax()); dataMap.put("ct" + i, operationsInfo.get(i).getCorporate_income_tax()); } dataMap.put("projectType", projectType(apply.getProject_type()) + "-" + apply.getProject_name()); createAnnex(annexTempUrl, annexOutputUrl, dataMap); return getFileDown(annexName, annexOutputUrl); } private String currencyUnit(Integer currency_unit_id) { DictionaryItem item = dictionaryItemService.findById(currency_unit_id); if (item == null) { return "元"; } if (item.getName().equals("人命币")) { return "元"; } return item.getName(); } /** * 附件1 * * @param apply */ private FileDown annexOne(ProjectApplication apply) { // final String annexName = "2019年苏州高新区工业经济发展专项扶持资金申请资料"; final String annexName = "2020年苏州高新区工业经济发展专项扶持资金申报材料(封面)"; // String annexTempUrl = "/Users/xikaiwen/Downloads/annex1.docx"; String annexTempUrl = repositoryPath + "/docs/annex_template/annex1.docx"; //文件数据库存储路径 String annexOneOutputUrl = getFilePath(annexName, "docs") + ".docx"; // annexOneOutputUrl = "/Users/xikaiwen/Downloads/新附件1.docx"; ProjectApplicationCompanyInfo companyInfo = apply.getCompanyInfo(); Map dataMap = new HashMap<>(); dataMap.put("companyName", companyInfo.getCompany_name()); dataMap.put("address", companyInfo.getRegistration_address()); dataMap.put("customizeName", apply.getCustomize_name()); dataMap.put("projectType", projectType(apply.getProject_type()) + "-" + apply.getProject_name()); dataMap.put("phone", companyInfo.getContact_phone()); dataMap.put("contact", companyInfo.getContact()); dataMap.put("applyDate", DateUtil.getTimeStringShort(new Date())); createAnnex(annexTempUrl, annexOneOutputUrl, dataMap); return getFileDown(annexName, annexOneOutputUrl); } /** * 获取数据字典名字 * * @param type * @param value */ private String dictionaryItemValue(String type, String value) { DictionaryItem item = dictionaryItemService.findByTypeAndValue(type, value + ""); return item.getName(); } /** * 获取项目大类 * * @param id */ public String projectType(Integer id) { ProjectType type = projectTypeService.findById(id); return type.getType_name(); } private FileDown getFileDown(String annexName, String annexOneOutputUrl) { //文件数据库存储路径 String docUrl = StringUtils.replace(StrUtil.subSuf(annexOneOutputUrl, repositoryPath.length()), "\\", "/"); //保存文件 Attachment attachment = new Attachment(); attachment.setFile_url(docUrl); attachment.setBusiness_type(attachmentType); // attachment.setBusiness_id(applyDraftId); attachment.setFile_name(annexName); attachmentService.insertAndGetId(attachment); return new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), null); } /** * 生产附件 * * @param annexOneTempUrl * @param annexOneOutputUrl * @param dataMap */ private void createAnnex(String annexOneTempUrl, String annexOneOutputUrl, Map dataMap) { BokeWordUtils.changWord(annexOneTempUrl, annexOneOutputUrl, dataMap, null); } public String getFilePath(String sourceFileName, String typeFolder) { String baseFolder = repositoryPath + File.separator + typeFolder; Date nowDate = new Date(); // yyyy/MM/dd String fileFolder = baseFolder + File.separator + com.xiaoleilu.hutool.date.DateUtil.format(nowDate, "yyyy") + File.separator + com.xiaoleilu.hutool.date.DateUtil.format(nowDate, "MM") + File.separator + com.xiaoleilu.hutool.date.DateUtil.format(nowDate, "dd"); File file = new File(fileFolder); if (!file.isDirectory()) { // 如果目录不存在,则创建目录 file.mkdirs(); } // 生成新的文件名 String fileName = com.xiaoleilu.hutool.date.DateUtil.format(nowDate, "yyyyMMddHHmmss") + sourceFileName; return fileFolder + File.separator + fileName; } /** * 项目申报汇总 * * @param paramApplication * @return */ public List findProjectApplicationSynthesis(ParamApplication paramApplication) { return projectApplicationDao.findProjectApplicationSynthesis(paramApplication); } }