|
@@ -1,15 +1,26 @@
|
|
|
package edu.travel.commodity.web;
|
|
|
|
|
|
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.ShopSpec;
|
|
|
import edu.travel.commodity.service.ShopSpecService;
|
|
|
import edu.travel.remote.commodity.ShopSpecRemoteController;
|
|
|
import edu.travel.remote.dto.SpecDto;
|
|
|
import edu.travel.remote.vo.SpecVo;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
+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.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
import static edu.travel.rpc.RPCBaseResponse.success;
|
|
|
|
|
|
/**
|
|
@@ -19,13 +30,14 @@ import static edu.travel.rpc.RPCBaseResponse.success;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/shopSpec")
|
|
|
-public class ShopSpecController implements ShopSpecRemoteController {
|
|
|
+public class ShopSpecController extends BaseController<ShopSpec> implements ShopSpecRemoteController {
|
|
|
/**
|
|
|
* 服务对象
|
|
|
*/
|
|
|
@Autowired
|
|
|
private ShopSpecService shopSpecService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private CountryAdapter countryAdapter;
|
|
|
|
|
|
/**
|
|
|
* 分页查询规格
|
|
@@ -49,4 +61,97 @@ public class ShopSpecController implements ShopSpecRemoteController {
|
|
|
shopSpecService.insertOrUpdate(specDto);
|
|
|
return success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查找规格
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @GetMapping("/getFormId")
|
|
|
+ public RPCBaseResponse<SpecVo> getFormId(String id) {
|
|
|
+ RPCBaseResponse<ShopSpec> shopSpecRPCBaseResponse = super.getId(id);
|
|
|
+ if (!Objects.equals(shopSpecRPCBaseResponse.getCode(), BaseConstant.SUCCESS_CODE)){
|
|
|
+ return RPCBaseResponse.error(shopSpecRPCBaseResponse.getMsg());
|
|
|
+ }
|
|
|
+ //获取规格信息
|
|
|
+ ShopSpec shopSpec = shopSpecRPCBaseResponse.getData();
|
|
|
+ //提取countryId
|
|
|
+ Long countryId = shopSpec.getCountryId();
|
|
|
+ //获取国家信息countryAdapter
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> countryInfoResponse = countryAdapter.getFormId(countryId.toString());
|
|
|
+ //检查国家信息的响应
|
|
|
+ if (!Objects.equals(countryInfoResponse.getCode(), BaseConstant.SUCCESS_CODE)){
|
|
|
+ return RPCBaseResponse.error(countryInfoResponse.getMsg());
|
|
|
+ }
|
|
|
+ //获取国家信息
|
|
|
+ BaseCountryServeVo countryInfo = countryInfoResponse.getData();
|
|
|
+ //创建vo对象
|
|
|
+ SpecVo specVo = new SpecVo();
|
|
|
+ BeanUtils.copyProperties(shopSpec, specVo);
|
|
|
+ //存入map
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("countryInfo", countryInfo);
|
|
|
+ specVo.setMap(map);
|
|
|
+ return RPCBaseResponse.success(specVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新规格
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/updateTargetFormId")
|
|
|
+ public RPCBaseResponse<SpecVo> updateTargetFormId(@RequestBody SpecDto entity) {
|
|
|
+ ShopSpec shopSpec = new ShopSpec();
|
|
|
+ BeanUtils.copyProperties(entity, shopSpec);
|
|
|
+ RPCBaseResponse<ShopSpec> shopSpecRPCBaseResponse = super.updateTargetById(shopSpec);
|
|
|
+ RPCBaseResponse<SpecVo> shopSpecVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(shopSpecRPCBaseResponse, shopSpecVoRPCBaseResponse);
|
|
|
+ return shopSpecVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增规格
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/saveFormTarget")
|
|
|
+ public RPCBaseResponse<SpecVo> saveFormTarget(@RequestBody SpecDto entity) {
|
|
|
+ ShopSpec shopSpec = new ShopSpec();
|
|
|
+ BeanUtils.copyProperties(entity, shopSpec);
|
|
|
+ RPCBaseResponse<ShopSpec> shopSpecRPCBaseResponse = super.saveTarget(shopSpec);
|
|
|
+ RPCBaseResponse<SpecVo> shopSpecVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(shopSpecRPCBaseResponse, shopSpecVoRPCBaseResponse);
|
|
|
+ return shopSpecVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *删除规格
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @PostMapping("/deleteTargetFormId")
|
|
|
+ public RPCBaseResponse<SpecVo> deleteTargetFormId(@RequestBody List<String> ids) {
|
|
|
+ RPCBaseResponse<ShopSpec> shopSpecRPCBaseResponse = super.deleteTargetById(ids);
|
|
|
+ RPCBaseResponse<SpecVo> shopSpecVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(shopSpecRPCBaseResponse, shopSpecVoRPCBaseResponse);
|
|
|
+ return shopSpecVoRPCBaseResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有规格
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @GetMapping("/getAllForm")
|
|
|
+ public RPCBaseResponse<List<SpecVo>> getAllForm() {
|
|
|
+ RPCBaseResponse<List<ShopSpec>> shopSpecRPCBaseResponse = super.listAll();
|
|
|
+ RPCBaseResponse<List<SpecVo>> shopSpecVoRPCBaseResponse = new RPCBaseResponse<>();
|
|
|
+ BeanUtils.copyProperties(shopSpecRPCBaseResponse, shopSpecVoRPCBaseResponse);
|
|
|
+ return shopSpecVoRPCBaseResponse;
|
|
|
+ }
|
|
|
}
|