|
@@ -1,15 +1,33 @@
|
|
|
package edu.travel.commodity.web;
|
|
|
|
|
|
+import com.alibaba.nacos.shaded.com.google.common.base.Objects;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import edu.travel.adapter.service.country.CountryAdapter;
|
|
|
+import edu.travel.commodity.constant.BaseConstant;
|
|
|
+import edu.travel.commodity.entity.ShopParameters;
|
|
|
import edu.travel.commodity.service.ShopParametersService;
|
|
|
+import edu.travel.entity.BaseEntity;
|
|
|
+import edu.travel.remote.commodity.ShopParametersRemoteController;
|
|
|
+import edu.travel.remote.dto.ParametersDto;
|
|
|
import edu.travel.remote.dto.ProductSpecDto;
|
|
|
+import edu.travel.remote.dto.ShopParametersDto;
|
|
|
+import edu.travel.remote.vo.ParametersVo;
|
|
|
import edu.travel.resp.BaseResponse;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.remote.vo.ShopParametersVo;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
+import edu.travel.vo.BaseCountryVo;
|
|
|
+import edu.travel.web.BaseController;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
import static edu.travel.rpc.RPCBaseResponse.success;
|
|
|
|
|
|
/**
|
|
@@ -19,12 +37,14 @@ import static edu.travel.rpc.RPCBaseResponse.success;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/shopParameters")
|
|
|
-public class ShopParametersController {
|
|
|
+public class ShopParametersController extends BaseController<ShopParameters> implements ShopParametersRemoteController{
|
|
|
/**
|
|
|
* 服务对象
|
|
|
*/
|
|
|
@Autowired
|
|
|
private ShopParametersService shopParametersService;
|
|
|
+ @Autowired
|
|
|
+ private CountryAdapter countryAdapter;
|
|
|
|
|
|
/**
|
|
|
* 获取商品参数
|
|
@@ -35,4 +55,163 @@ public class ShopParametersController {
|
|
|
public RPCBaseResponse<Page<ShopParametersVo>> getShopParameters(ProductSpecDto param){
|
|
|
return success(shopParametersService.getShopParameters(param));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取参数
|
|
|
+ */
|
|
|
+ @GetMapping("getAllParameters")
|
|
|
+ public RPCBaseResponse<Page<ParametersVo>> getAllParameters(ParametersDto param){
|
|
|
+ return success(shopParametersService.getAllParameters(param));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id获取商品参数(连表-服务国家)
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @GetMapping("/getFormId")
|
|
|
+ public RPCBaseResponse<ShopParametersVo> getFormId(String id) {
|
|
|
+ RPCBaseResponse<ShopParameters> parametersRPCBaseResponse = super.getId(id);
|
|
|
+ if (!Objects.equal(parametersRPCBaseResponse.getCode(), BaseConstant.SUCCESS_CODE))
|
|
|
+ {
|
|
|
+ return RPCBaseResponse.error(parametersRPCBaseResponse.getMsg());
|
|
|
+ }
|
|
|
+ ShopParameters shopParameters = parametersRPCBaseResponse.getData();
|
|
|
+
|
|
|
+ //提取countryID
|
|
|
+ Long countryId = shopParameters.getCountryId();
|
|
|
+
|
|
|
+ //调用方法获取国家信息
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> countryInfoResponse = countryAdapter.getFormId(countryId.toString());
|
|
|
+ if (!Objects.equal(countryInfoResponse.getCode(), BaseConstant.SUCCESS_CODE))
|
|
|
+ {
|
|
|
+ return RPCBaseResponse.error(countryInfoResponse.getMsg());
|
|
|
+ }
|
|
|
+ BaseCountryServeVo countryInfo = countryInfoResponse.getData();
|
|
|
+ //创建返回对象
|
|
|
+ ShopParametersVo shopParametersVo = new ShopParametersVo();
|
|
|
+ BeanUtils.copyProperties(shopParameters, shopParametersVo);
|
|
|
+ //存入map
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("countryData", countryInfo);
|
|
|
+ shopParametersVo.setMap(map);
|
|
|
+
|
|
|
+ return RPCBaseResponse.success(shopParametersVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新参数信息
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/updateFormId")
|
|
|
+ public RPCBaseResponse<ShopParametersVo> updateTargetFormId(@RequestBody ShopParametersDto entity) {
|
|
|
+ ShopParameters shopParameters = new ShopParameters();
|
|
|
+ BeanUtils.copyProperties(entity, shopParameters);
|
|
|
+ RPCBaseResponse<ShopParameters> countryRPCBaseResponse = super.updateTargetById(shopParameters);
|
|
|
+ RPCBaseResponse<ShopParametersVo> shopParametersVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(countryRPCBaseResponse, shopParametersVoRPCBaseResponse);
|
|
|
+ return shopParametersVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增商品参数信息
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/saveFormTarget")
|
|
|
+ public RPCBaseResponse<ShopParametersVo> saveFormTarget(ShopParametersDto entity) {
|
|
|
+ ShopParameters shopParameters = new ShopParameters();
|
|
|
+ BeanUtils.copyProperties(entity, shopParameters);
|
|
|
+ RPCBaseResponse<ShopParameters> countryRPCBaseResponse = super.saveTarget(shopParameters);
|
|
|
+ RPCBaseResponse<ShopParametersVo> shopParametersVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(countryRPCBaseResponse, shopParametersVoRPCBaseResponse);
|
|
|
+ return shopParametersVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除商品参数信息
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/deleteTargetFormId")
|
|
|
+ public RPCBaseResponse<ShopParametersVo> deleteTargetFormId(List<String> ids) {
|
|
|
+ RPCBaseResponse<ShopParameters> countryRPCBaseResponse = super.deleteTargetById(ids);
|
|
|
+ RPCBaseResponse<ShopParametersVo> shopParametersVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(countryRPCBaseResponse, shopParametersVoRPCBaseResponse);
|
|
|
+ return shopParametersVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有商品参数信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @GetMapping("/getAllForm")
|
|
|
+ public RPCBaseResponse<List<ShopParametersVo>> getAllForm() {
|
|
|
+ // Step 1: 获取所有 ShopParameters 数据
|
|
|
+ RPCBaseResponse<List<ShopParameters>> countryRPCBaseResponse = super.listAll();
|
|
|
+
|
|
|
+ // Step 2: 创建一个用于存储每个 ShopParametersVo 的映射
|
|
|
+ Map<Long, ShopParametersVo> parametersMap = new HashMap<>();
|
|
|
+ List<ShopParametersVo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // Step 3: 创建一个 Map,用于存储 countryId 对应的数据
|
|
|
+ Map<Long, BaseCountryVo> countryDataMap = new HashMap<>();
|
|
|
+
|
|
|
+ // Step 4: 将所有 ShopParameters 转换为 ShopParametersVo,并存储在 map 中
|
|
|
+ if (countryRPCBaseResponse.getData() != null) {
|
|
|
+ for (ShopParameters parameters : countryRPCBaseResponse.getData()) {
|
|
|
+ ShopParametersVo parametersVo = new ShopParametersVo();
|
|
|
+ BeanUtils.copyProperties(parameters, parametersVo);
|
|
|
+ parametersMap.put(parameters.getId(), parametersVo);
|
|
|
+
|
|
|
+ // Step 5: 利用 countryId 查找相关数据并存储到 countryDataMap 中
|
|
|
+ if (parameters.getCountryId() != null) {
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> countryResponse = countryAdapter.getFormId(parameters.getCountryId().toString());
|
|
|
+
|
|
|
+ // 确保 countryResponse 不为 null,并提取数据
|
|
|
+ if (countryResponse != null && countryResponse.getData() != null) {
|
|
|
+ BaseCountryServeVo serveVo = countryResponse.getData();
|
|
|
+ BaseCountryVo countryData = convertToBaseCountryVo(serveVo); // 进行转换
|
|
|
+ countryDataMap.put(parameters.getCountryId(), countryData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step 6: 将国家数据添加到 ShopParametersVo 中
|
|
|
+ for (ShopParametersVo parametersVo : parametersMap.values()) {
|
|
|
+ if (countryDataMap.containsKey(parametersVo.getCountryId())) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("countryData", countryDataMap.get(parametersVo.getCountryId()));
|
|
|
+ parametersVo.setMap(map);
|
|
|
+ }
|
|
|
+ result.add(parametersVo); // Adding to result list
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step 7: 创建返回的 RPCBaseResponse
|
|
|
+ RPCBaseResponse<List<ShopParametersVo>> shopParametersVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(countryRPCBaseResponse, shopParametersVoRPCBaseResponse);
|
|
|
+ shopParametersVoRPCBaseResponse.setData(result); // 设置结果数据
|
|
|
+
|
|
|
+ return shopParametersVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 实现 BaseCountryServeVo 到 BaseCountryVo 的转换方法
|
|
|
+ private BaseCountryVo convertToBaseCountryVo(BaseCountryServeVo serveVo) {
|
|
|
+ BaseCountryVo countryVo = new BaseCountryVo();
|
|
|
+ countryVo.setId(serveVo.getId());
|
|
|
+ countryVo.setCountryNameZh(serveVo.getCountryNameZh());
|
|
|
+ countryVo.setCountryNameEn(serveVo.getCountryNameEn());
|
|
|
+ countryVo.setAreaCode(serveVo.getAreaCode());
|
|
|
+ return countryVo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|