<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      科技政策查詢系統網頁版

      項目結構
      PolicyController
      package com.example.policyquerysystem.controller;

      import com.example.policyquerysystem.dto.PolicyQueryDto;
      import com.example.policyquerysystem.dto.PolicyTypeTreeDTO;
      import com.example.policyquerysystem.dto.TypeNodeDTO;
      import com.example.policyquerysystem.entity.Policy;
      import com.example.policyquerysystem.entity.PolicyType;
      import com.example.policyquerysystem.service.PolicyService;
      import com.example.policyquerysystem.service.PolicyTypeService;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.*;

      import java.util.List;
      import java.util.Map;
      import java.util.stream.Collectors;

      @Controller
      @RequestMapping("/policy")
      public class PolicyController {

      @Autowired
      private PolicyService policyService;
      
      @Autowired
      private PolicyTypeService policyTypeService;
      
      @GetMapping("/")
      public String index(Model model) {
          // 獲取分類樹數據
          List<PolicyTypeTreeDTO> typeTree = policyTypeService.getFullTypeTree();
          model.addAttribute("typeTree", typeTree);
      
          // 添加空白查詢DTO
          model.addAttribute("queryDto", new PolicyQueryDto());
      
          return "index";
      }
      
      
      @GetMapping("/detail/{id}")
      public String detail(@PathVariable Long id, Model model) {
          Policy policy = policyService.getPolicyById(id);
          if (policy != null) {
              String typeName = policyTypeService.getTypeNameById(policy.getType());
              model.addAttribute("policy", policy);
              model.addAttribute("typeName", typeName);
          }
          return "policy-detail";
      }
      
      @GetMapping("/search")
      public String searchForm(Model model) {
          List<TypeNodeDTO> typeTree = policyTypeService.getTypeTreeAsDTO();
          model.addAttribute("typeTree", typeTree);
          model.addAttribute("queryDto", new PolicyQueryDto());
          return "search-form";
      }
      
      @PostMapping("/search")
      public String search(PolicyQueryDto queryDto, Model model) {
          List<Policy> policies = policyService.advancedSearchWithSpecification(queryDto);
          String typeName = queryDto.getType() != null && !queryDto.getType().isEmpty()
                  ? policyTypeService.getTypeNameById(queryDto.getType())
                  : "";
      
          model.addAttribute("policies", policies);
          model.addAttribute("queryDto", queryDto);
          model.addAttribute("typeName", typeName);
          return "policy-list";
      }
      
      @GetMapping("/types")
      public String showTypeTree(Model model) {
          model.addAttribute("typeTree", policyTypeService.getFullTypeTree());
          return "policy-type-tree";
      }
      
      @GetMapping("/type/{typeId}")
      public String listByType(@PathVariable String typeId, Model model) {
          // 先獲取分類名稱
          String typeName = policyTypeService.getTypeNameById(typeId);
      
          // 使用分類名稱查詢政策
          List<Policy> policies = policyService.findByTypeName(typeName);
      
          model.addAttribute("policies", policies);
          model.addAttribute("typeName", typeName);
          return "policy-list";
      }
      
      @GetMapping("/advanced-search")
      public String advancedSearchForm(Model model) {
          model.addAttribute("typeTree", policyTypeService.getSelectableTypeTree());
          model.addAttribute("queryDto", new PolicyQueryDto());
          return "advanced-search";
      }
      

      }
      package com.example.policyquerysystem.repository;

      import com.example.policyquerysystem.entity.Policy;
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
      import org.springframework.data.jpa.repository.Query;
      import org.springframework.data.repository.query.Param;
      import org.springframework.stereotype.Repository;

      import java.util.Collections;
      import java.util.List;

      @Repository
      public interface PolicyRepository extends JpaRepository<Policy, Long>, JpaSpecificationExecutor {

      List<Policy> findByType(String type);
      // 如果需要查詢該分類及其所有子分類的政策
      
      @Query("SELECT p FROM Policy p WHERE p.type LIKE :typeId%")
      List<Policy> findByTypeAndSubTypes(@Param("typeId") String typeId);
      
      @Query("SELECT p FROM Policy p WHERE " +
              "(:name IS NULL OR p.name LIKE %:name%) AND " +
              "(:type IS NULL OR p.type = :type) AND " +
              "(:organ IS NULL OR p.organ LIKE %:organ%) AND " +
              "(:document IS NULL OR p.document LIKE %:document%) AND " +
              "(:text IS NULL OR p.text LIKE %:text%)")
      List<Policy> advancedSearch(String name, String type, String organ, String document, String text);
      
      // 通過分類名稱查詢
      @Query("SELECT p FROM Policy p WHERE p.type = :typeName")
      List<Policy> findByTypeName(@Param("typeName") String typeName);
      
      // 通過分類ID查詢(先獲取名稱再查詢)
      default List<Policy> findByTypeId(PolicyTypeRepository typeRepo, String typeId) {
          return typeRepo.findById(typeId)
                  .map(type -> findByTypeName(type.getTypeName()))
                  .orElse(Collections.emptyList());
      }
      

      }
      package com.example.policyquerysystem.repository;

      import com.example.policyquerysystem.entity.PolicyType;
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.data.jpa.repository.Query;
      import org.springframework.stereotype.Repository;

      import java.util.List;

      @Repository
      public interface PolicyTypeRepository extends JpaRepository<PolicyType, String> {

      List<PolicyType> findByParentIdIsNull();
      
      List<PolicyType> findByParentId(String parentId);
      
      @Query("SELECT t FROM PolicyType t WHERE t.typeName LIKE %:keyword%")
      List<PolicyType> searchByKeyword(String keyword);
      

      }
      package com.example.policyquerysystem.service;

      import com.example.policyquerysystem.dto.PolicyQueryDto;
      import com.example.policyquerysystem.entity.Policy;
      import com.example.policyquerysystem.repository.PolicyRepository;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.data.jpa.domain.Specification;
      import org.springframework.stereotype.Service;

      import javax.persistence.criteria.Predicate;
      import java.util.ArrayList;
      import java.util.List;

      @Service
      public class PolicyService {

      @Autowired
      private PolicyRepository policyRepository;
      
      @Autowired
      private PolicyTypeService policyTypeService;
      
      public List<Policy> findByType(String typeId) {
          return policyRepository.findByType(typeId);
      }
      public List<Policy> advancedSearch(PolicyQueryDto queryDto) {
          return policyRepository.advancedSearch(
                  queryDto.getName(),
                  queryDto.getType(),
                  queryDto.getOrgan(),
                  queryDto.getDocument(),
                  queryDto.getText()
          );
      }
      
      public List<Policy> advancedSearchWithSpecification(PolicyQueryDto queryDto) {
          return policyRepository.findAll((Specification<Policy>) (root, query, criteriaBuilder) -> {
              List<Predicate> predicates = new ArrayList<>();
      
              if (queryDto.getName() != null && !queryDto.getName().isEmpty()) {
                  predicates.add(criteriaBuilder.like(root.get("name"), "%" + queryDto.getName() + "%"));
              }
      
              if (queryDto.getType() != null && !queryDto.getType().isEmpty()) {
                  predicates.add(criteriaBuilder.equal(root.get("type"), queryDto.getType()));
              }
      
              if (queryDto.getOrgan() != null && !queryDto.getOrgan().isEmpty()) {
                  predicates.add(criteriaBuilder.like(root.get("organ"), "%" + queryDto.getOrgan() + "%"));
              }
      
              if (queryDto.getDocument() != null && !queryDto.getDocument().isEmpty()) {
                  predicates.add(criteriaBuilder.like(root.get("document"), "%" + queryDto.getDocument() + "%"));
              }
      
              if (queryDto.getText() != null && !queryDto.getText().isEmpty()) {
                  predicates.add(criteriaBuilder.like(root.get("text"), "%" + queryDto.getText() + "%"));
              }
      
              return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
          });
      }
      
      public Policy getPolicyById(Long id) {
          return policyRepository.findById(id).orElse(null);
      }
      
      
      public List<Policy> findByTypeName(String typeName) {
          return policyRepository.findByTypeName(typeName);
      }
      

      }
      package com.example.policyquerysystem.service;

      import com.example.policyquerysystem.dto.PolicyTypeTreeDTO;
      import com.example.policyquerysystem.dto.TypeNodeDTO;
      import com.example.policyquerysystem.entity.PolicyType;
      import com.example.policyquerysystem.repository.PolicyTypeRepository;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Service;

      import java.util.*;
      import java.util.stream.Collectors;

      @Service
      public class PolicyTypeService {

      @Autowired
      private PolicyTypeRepository policyTypeRepository;
      
      public List<PolicyType> getRootTypes() {
          return policyTypeRepository.findByParentIdIsNull();
      }
      
      public List<PolicyType> getChildrenTypes(String parentId) {
          return policyTypeRepository.findByParentId(parentId);
      }
      
      public Map<String, List<PolicyType>> getTypeTree() {
          List<PolicyType> rootTypes = getRootTypes();
          Map<String, List<PolicyType>> typeTree = new HashMap<>();
      
          for (PolicyType rootType : rootTypes) {
              List<PolicyType> children = getChildrenTypes(rootType.getTypeId());
              typeTree.put(rootType.getTypeId(), children);
          }
      
          return typeTree;
      }
      
      public String getTypeNameById(String typeId) {
          return policyTypeRepository.findById(typeId)
                  .map(PolicyType::getTypeName)
                  .orElse("未知分類");
      }
      
      public List<PolicyType> searchTypes(String keyword) {
          return policyTypeRepository.searchByKeyword(keyword);
      }
      public Map<String, String> getAllTypeNames() {
          return policyTypeRepository.findAll()
                  .stream()
                  .collect(Collectors.toMap(PolicyType::getTypeId, PolicyType::getTypeName));
      }
      
      public Map<String, Object> getTypeTreeWithNames() {
          List<PolicyType> rootTypes = getRootTypes();
          Map<String, Object> typeTree = new LinkedHashMap<>();
      
          for (PolicyType rootType : rootTypes) {
              Map<String, Object> node = new HashMap<>();
              node.put("name", rootType.getTypeName());
      
              List<Map<String, String>> children = getChildrenTypes(rootType.getTypeId()).stream()
                      .map(child -> {
                          Map<String, String> childMap = new HashMap<>();
                          childMap.put("id", child.getTypeId());
                          childMap.put("name", child.getTypeName());
                          return childMap;
                      })
                      .collect(Collectors.toList());
      
              node.put("children", children);
              typeTree.put(rootType.getTypeId(), node);
          }
      
          return typeTree;
      }
      public List<TypeNodeDTO> getTypeTreeAsDTO() {
          // 獲取所有根節點
          List<PolicyType> rootTypes = policyTypeRepository.findByParentIdIsNull();
      
          return rootTypes.stream()
                  .map(root -> {
                      TypeNodeDTO rootNode = new TypeNodeDTO(root);
                      // 獲取子節點
                      List<PolicyType> children = policyTypeRepository.findByParentId(root.getTypeId());
                      rootNode.setChildren(
                              children.stream()
                                      .map(TypeNodeDTO::new)
                                      .collect(Collectors.toList())
                      );
                      return rootNode;
                  })
                  .collect(Collectors.toList());
      }
      
      private TypeNodeDTO convertToDTO(PolicyType policyType) {
          TypeNodeDTO dto = new TypeNodeDTO(policyType);
          List<PolicyType> children = getChildrenTypes(policyType.getTypeId());
          dto.setChildren(children.stream()
                  .map(this::convertToDTO)
                  .collect(Collectors.toList()));
          return dto;
      }
      
      
          public List<PolicyTypeTreeDTO> getFullTypeTree() {
              // 獲取所有分類數據
              List<PolicyType> allTypes = policyTypeRepository.findAll();
      
              // 構建ID到DTO的映射
              Map<String, PolicyTypeTreeDTO> dtoMap = new HashMap<>();
              allTypes.forEach(type -> dtoMap.put(type.getTypeId(), new PolicyTypeTreeDTO(type)));
      
              // 構建樹形結構
              List<PolicyTypeTreeDTO> result = new ArrayList<>();
              for (PolicyType type : allTypes) {
                  PolicyTypeTreeDTO dto = dtoMap.get(type.getTypeId());
                  if (type.getParentId() == null || type.getParentId().isEmpty()) {
                      result.add(dto);
                  } else {
                      PolicyTypeTreeDTO parentDto = dtoMap.get(type.getParentId());
                      if (parentDto != null) {
                          parentDto.getChildren().add(dto);
                      }
                  }
              }
      
              return result;
          }
      public List<PolicyTypeTreeDTO> getSelectableTypeTree() {
          List<PolicyTypeTreeDTO> fullTree = this.getFullTypeTree();
      
          // 確保所有節點都可選(包括一級分類)
          fullTree.forEach(root -> {
              root.setSelectable(true);
              root.getChildren().forEach(child -> child.setSelectable(true));
          });
      
          return fullTree;
      }
      

      }
      package com.example.policyquerysystem;

      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;

      @SpringBootApplication
      public class PolicyQuerySystemApplication {

      public static void main(String[] args) {
          SpringApplication.run(PolicyQuerySystemApplication.class, args);
      }
      

      }

      科技政策查詢系統
      posted @ 2025-04-12 23:19  霸王雞  閱讀(7)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 午夜精品福利一区二区三| 亚洲国产精品第一二三区| 九九热免费精品视频在线| 国产精品美女一区二三区| 亚洲国产欧美一区二区好看电影| 日韩欧美在线综合网另类| 免费人成网站免费看视频| 浮妇高潮喷白浆视频| 老色鬼永久精品网站| 四虎成人精品永久免费av| 成全高清在线播放电视剧| 偷拍美女厕所尿尿嘘嘘小便| 亚洲国产另类久久久精品黑人 | 精品国产乱码久久久久久口爆网站| 99精品国产精品一区二区| 国产午夜影视大全免费观看| 99er热精品视频| 亚洲 欧美 中文 日韩aⅴ| 又爽又黄又无遮挡的激情视频 | 国产午精品午夜福利757视频播放| 亚洲中文字幕无码av在线| 中文字幕国产精品一二区| 国产精品多p对白交换绿帽| 日本少妇xxx做受| 亚洲一线二线三线品牌精华液久久久| 国产精品中文字幕第一页| 91久久偷偷做嫩草影院免费看 | 久久这里只有精品首页| 国内自拍偷拍福利视频看看| 男人的天堂av社区在线| 国产成人精品电影在线观看| 最新国产精品好看的精品| 无码熟妇人妻av影音先锋| 国产女人高潮视频在线观看| 美女一区二区三区亚洲麻豆| 亚洲一区成人在线视频| 海晏县| 成人免费无码不卡毛片| 日日噜噜夜夜狠狠视频| 浪卡子县| 亚洲乱色一区二区三区丝袜|