Przeglądaj źródła

国家功能部分

一条糖醋鱼 1 miesiąc temu
rodzic
commit
af20c1a1e1

+ 55 - 0
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/dto/BaseCountryDto.java

@@ -0,0 +1,55 @@
+package edu.travel.commodity.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import edu.travel.entity.BaseEntity;
+import edu.travel.po.PagePO;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 国家表
+ */
+@Data
+public class BaseCountryDto extends PagePO {
+    /**
+     * ID
+     */
+    private Long id;
+
+    /**
+     * 所属洲
+     */
+    private Long parentId;
+    /**
+     * 图片
+     */
+    private String imageUrl;
+
+    /**
+     * 国家/洲中文名称
+     */
+    private String countryNameZh;
+
+    /**
+     * 国家/洲英文名称
+     */
+    private String countryNameEn;
+
+    /**
+     * 当地国家/洲名称
+     */
+    private String countryNameLocal;
+    /**
+     * 国家图片
+     */
+    private Integer countryImg;
+    /**
+     * 国家区号
+     */
+    private Integer areaCode;
+
+}

+ 11 - 1
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/service/BaseCountryService.java

@@ -1,8 +1,18 @@
 package edu.travel.commodity.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import edu.travel.commodity.dto.BaseCountryDto;
 import edu.travel.commodity.entity.BaseCountry;
 import com.baomidou.mybatisplus.extension.service.IService;
-public interface BaseCountryService extends IService<BaseCountry>{
+import edu.travel.commodity.vo.BaseCountryVo;
+import edu.travel.rpc.RPCBaseResponse;
+
+import java.util.List;
 
+public interface BaseCountryService extends IService<BaseCountry>{
 
+//分页
+    RPCBaseResponse<IPage<BaseCountryVo>> getCountryPage(BaseCountryDto baseCountryDTO);
+//国家树
+    RPCBaseResponse<List<BaseCountryVo>> getCountryTree();
 }

+ 47 - 2
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/service/impl/BaseCountryServiceImpl.java

@@ -1,12 +1,57 @@
 package edu.travel.commodity.service.impl;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import edu.travel.commodity.dto.BaseCountryDto;
 import edu.travel.commodity.entity.BaseCountry;
 import edu.travel.commodity.mapper.BaseCountryMapper;
 import edu.travel.commodity.service.BaseCountryService;
+import edu.travel.commodity.vo.BaseCountryVo;
+import edu.travel.rpc.RPCBaseResponse;
+import edu.travel.service.SysServiceImpl;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Service
-public class BaseCountryServiceImpl extends ServiceImpl<BaseCountryMapper, BaseCountry> implements BaseCountryService {
+public class BaseCountryServiceImpl extends SysServiceImpl<BaseCountryMapper, BaseCountry> implements BaseCountryService {
+
+    @Override
+    public RPCBaseResponse<IPage<BaseCountryVo>> getCountryPage(BaseCountryDto baseCountryDto) {
+        Page<BaseCountry> baseCountryPage = new Page<>(baseCountryDto.getCurrentPage(), baseCountryDto.getPageSize());
+        IPage<BaseCountry> pageLink = super.getPageLink(new LambdaQueryWrapper<BaseCountry>(), baseCountryPage);
+        IPage<BaseCountryVo> pageVoLink = new Page<>();
+        BeanUtils.copyProperties(pageLink,pageVoLink);
+        RPCBaseResponse<IPage<BaseCountryVo>> pageRPCPageResponse = new RPCBaseResponse<>(200,"SUCCESS",pageVoLink);
+        return pageRPCPageResponse;
+    }
+
+    //国家树
+    @Override
+    public RPCBaseResponse<List<BaseCountryVo>> getCountryTree() {
+        //查询所有国家数据
+        LambdaQueryWrapper<BaseCountry> queryWrapper =  new LambdaQueryWrapper<>();
+        //获取所有国际家数据
+        List<BaseCountry> baseCountryList = super.getListLink(queryWrapper);
+
+        //构建树形结构
+        List<BaseCountryVo>  BaseCountryTree = buildCountryTree(baseCountryList);
+
+        //返回结果
+        return new RPCBaseResponse<>(200,"SUCCESS",BaseCountryTree);
+    }
+
+    //树构建方法
+    private List<BaseCountryVo> buildCountryTree(List<BaseCountry> baseCountryList) {
+        //map,快速查找国家VO对象
+        Map<Long,BaseCountryVo> countryMap = new HashMap<>();
+        List<BaseCountryVo> rootCountries = new ArrayList<>();
+        return null;
+    }
 
 }

+ 55 - 0
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/vo/BaseCountryVo.java

@@ -0,0 +1,55 @@
+package edu.travel.commodity.vo;
+
+import edu.travel.entity.BaseEntity;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 国家表
+ */
+@Data
+
+public class BaseCountryVo extends BaseEntity {
+    /**
+     * ID
+     */
+    private Long id;
+
+    /**
+     * 所属洲
+     */
+    private Long parentId;
+    /**
+     * 图片
+     */
+    private String imageUrl;
+
+    /**
+     * 国家/洲中文名称
+     */
+    private String countryNameZh;
+
+    /**
+     * 国家/洲英文名称
+     */
+    private String countryNameEn;
+
+    /**
+     * 当地国家/洲名称
+     */
+    private String countryNameLocal;
+    /**
+     * 国家图片
+     */
+    private Integer countryImg;
+    /**
+     * 国家区号
+     */
+    private Integer areaCode;
+    /**
+     * 子类
+     */
+    private List<BaseCountryVo> children = new ArrayList<>();
+}

+ 29 - 9
edu-travel-service/edu-travel-service-commodity/src/main/java/edu/travel/commodity/web/BaseCountryController.java

@@ -1,23 +1,43 @@
 package edu.travel.commodity.web;
-import edu.travel.commodity.service.BaseCountryService;
-import org.springframework.web.bind.annotation.*;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import edu.travel.commodity.dto.BaseCountryDto;
+import edu.travel.commodity.service.BaseCountryService;
+import edu.travel.commodity.vo.BaseCountryVo;
+import edu.travel.rpc.RPCBaseResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
 
 /**
-* 国家表(base_country)表控制层
-*
-* @author xxxxx
-*/
+ * 国家表(base_country)表控制层
+ *
+ * @author xxxxx
+ */
 @RestController
 @RequestMapping("/base_country")
 public class BaseCountryController {
-/**
-* 服务对象
-*/
+
+    /**
+     * 服务对象
+     */
     @Autowired
     private BaseCountryService baseCountryService;
 
 
+    //国家树
+    @GetMapping("/getCountryTree")
+    public RPCBaseResponse<List<BaseCountryVo>> getCountryTree() {
+        return baseCountryService.getCountryTree();
+    }
+
+    //国家分页
+    @GetMapping("/getCountryPage")
+    public RPCBaseResponse<IPage<BaseCountryVo>> getCountryPage(BaseCountryDto baseCountryDTO) {
+        return baseCountryService.getCountryPage(baseCountryDTO);
+    }
 
 }