|
@@ -2,6 +2,8 @@ package edu.travel.country.service.impl;
|
|
|
|
|
|
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.country.entity.BaseCountry;
|
|
|
import edu.travel.country.entity.BaseCountryServe;
|
|
|
import edu.travel.country.mapper.BaseCountryMapper;
|
|
@@ -9,8 +11,10 @@ import edu.travel.country.mapper.BaseCountryServeMapper;
|
|
|
import edu.travel.country.mapper.ShopCurrencyMapper;
|
|
|
import edu.travel.country.service.BaseCountryServeService;
|
|
|
import edu.travel.dto.BaseCountryServeDto;
|
|
|
+import edu.travel.dto.BaseCountryServeStatusDto;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.BaseCountryServeStatusVo;
|
|
|
import edu.travel.vo.BaseCountryServeVo;
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -18,23 +22,65 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class BaseCountryServeServiceImpl extends SysServiceImpl<BaseCountryServeMapper, BaseCountryServe> implements BaseCountryServeService {
|
|
|
@Autowired
|
|
|
private BaseCountryMapper baseCountryMapper;
|
|
|
+ @Autowired
|
|
|
+ private BaseCountryServeMapper baseCountryServeMapper;
|
|
|
|
|
|
//分页连表
|
|
|
@Override
|
|
|
-public RPCBaseResponse<List<BaseCountryServe>> getCountryServeCurrencyPageForm(BaseCountryServeDto dto) {
|
|
|
- // 查询所有国家服务数据
|
|
|
+public RPCBaseResponse<IPage<BaseCountryServe>> getCountryServeCurrencyPageForm(BaseCountryServeDto dto) {
|
|
|
+ // 检查参数
|
|
|
+ if (dto.getCurrentPage() == null || dto.getPageSize() == null) {
|
|
|
+ return new RPCBaseResponse<>(400, "Current page and page size must not be null", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建分页查询
|
|
|
+ Page<BaseCountryServe> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
+
|
|
|
+ // 创建查询条件
|
|
|
LambdaQueryWrapper<BaseCountryServe> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- // 查询所有的数据
|
|
|
- List<BaseCountryServe> baseCountryServeList = super.getListLink(queryWrapper);
|
|
|
- return new RPCBaseResponse <>(200, "SUCCESS", baseCountryServeList);
|
|
|
+ if (dto.getCountryId() != null) {
|
|
|
+ queryWrapper.eq(BaseCountryServe::getCountryId, dto.getCountryId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行分页查询
|
|
|
+ IPage<BaseCountryServe> countryServePage = super.getBaseMapper().selectPage(page, queryWrapper);
|
|
|
+
|
|
|
+ // 返回成功的响应
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", countryServePage);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<BaseCountryServeStatusVo> updateServeStatus(BaseCountryServeStatusDto entity) {
|
|
|
+ //检查参数是否合法
|
|
|
+ if (entity.getId() == null) {
|
|
|
+ return new RPCBaseResponse<>(400, "Currency id is not null", null);
|
|
|
+ }
|
|
|
+ //创建对象,用于更新
|
|
|
+ BaseCountryServe baseCountryServe = new BaseCountryServe();
|
|
|
+ baseCountryServe.setId(entity.getId());
|
|
|
+ baseCountryServe.setServeEnable(entity.getServeEnable());
|
|
|
+ //执行更新操作
|
|
|
+ boolean success = super.updateById(baseCountryServe);
|
|
|
+ //检查是否更新成功
|
|
|
+ if (!success) {
|
|
|
+ return new RPCBaseResponse<>(500, "FAIL", null);
|
|
|
+ }
|
|
|
+ //创建返回的结果对象
|
|
|
+ BaseCountryServeStatusVo baseCountryServeStatusVo = new BaseCountryServeStatusVo();
|
|
|
+ BeanUtils.copyProperties(baseCountryServe, baseCountryServeStatusVo);
|
|
|
+ //返回成功的响应
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", baseCountryServeStatusVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 服务国家树
|
|
|
* @return
|
|
@@ -71,12 +117,12 @@ public RPCBaseResponse<List<BaseCountryServe>> getCountryServeCurrencyPageForm(B
|
|
|
serveVo.setAreaCode(String.valueOf(country.getAreaCode()));
|
|
|
}
|
|
|
|
|
|
- serveMap.put(serve.getId(), serveVo);
|
|
|
+ serveMap.put(Long.valueOf(serve.getId()), serveVo);
|
|
|
}
|
|
|
|
|
|
// 构建树形结构
|
|
|
for (BaseCountryServe serve : baseCountryServeList) {
|
|
|
- Long parentId = serve.getParentId();
|
|
|
+ Long parentId = Long.valueOf(serve.getParentId());
|
|
|
BaseCountryServeVo serveVo = serveMap.get(serve.getId());
|
|
|
|
|
|
if (serveVo == null) {
|