Commit bae1ccc6 by Lizh

修改远程调用问题

parent ba2bae90
......@@ -2,13 +2,14 @@ package com.jomalls.custom.app.service.system.impl;
import com.jomalls.custom.app.service.system.CountryCodeService;
import com.jomalls.custom.app.vo.system.CountryCodeVO;
import com.jomalls.custom.integrate.model.BaseCountryCodeModel;
import com.jomalls.custom.integrate.model.CountryCodeModel;
import com.jomalls.custom.integrate.service.SaasAdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -27,20 +28,23 @@ public class CountryCodeServiceImpl implements CountryCodeService {
@Override
public Map<String, String> getMap() {
List<BaseCountryCodeModel> list = saasAdminService.getAllCountryCode();
List<CountryCodeModel> list = saasAdminService.getAllCountryCode();
if (list == null || list.isEmpty()) {
return Collections.emptyMap();
}
return list.stream()
.collect(Collectors.toMap(
BaseCountryCodeModel::getCountryCode,
BaseCountryCodeModel::getNameCn,
(a, b) -> a));
Map<String, String> result = new LinkedHashMap<>();
for (CountryCodeModel model : list) {
if (model.getCountryCode() != null) {
result.put(String.valueOf(model.getCountryCode()),
model.getNameCn() != null ? model.getNameCn() : "");
}
}
return result;
}
@Override
public List<CountryCodeVO> getAll() {
List<BaseCountryCodeModel> list = saasAdminService.getAllCountryCode();
List<CountryCodeModel> list = saasAdminService.getAllCountryCode();
if (list == null || list.isEmpty()) {
return Collections.emptyList();
}
......@@ -52,7 +56,7 @@ public class CountryCodeServiceImpl implements CountryCodeService {
/**
* 将 Model 转换为 VO
*/
private CountryCodeVO toVO(BaseCountryCodeModel model) {
private CountryCodeVO toVO(CountryCodeModel model) {
CountryCodeVO vo = new CountryCodeVO();
vo.setCountryCode(model.getCountryCode());
vo.setNameCn(model.getNameCn());
......
......@@ -38,10 +38,9 @@ public class SysLogininforServiceImpl implements SysLogininforService {
entity.setMsg(message);
entity.setLoginTime(new Date());
// 采集客户端信息(与 custom-back AsyncFactory 对齐)
// 采集客户端信息
try {
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
entity.setIpaddr(getIpAddr(request));
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoSnakeVO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoVO;
import java.util.List;
import java.util.Map;
......@@ -23,7 +24,7 @@ public interface CustomWarehouseInfoService {
* @param page 分页参数
* @return 分页结果
*/
IPage<CustomWarehouseInfoSnakeVO> pageList(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page);
IPage<CustomWarehouseInfoVO> pageList(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page);
/**
* 获取仓库状态列表
......
......@@ -8,6 +8,7 @@ import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO;
import com.jomalls.custom.app.service.warehouse.CustomWarehouseInfoService;
import com.jomalls.custom.app.utils.BeanMapper;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoSnakeVO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoVO;
import com.jomalls.custom.dal.entity.CustomWarehouseInfoEntity;
import com.jomalls.custom.domain.service.warehouse.CustomWarehouseInfoDomainService;
import lombok.RequiredArgsConstructor;
......@@ -35,7 +36,7 @@ public class CustomWarehouseInfoServiceImpl implements CustomWarehouseInfoServic
private final CustomWarehouseInfoDomainService customWarehouseInfoDomainService;
@Override
public IPage<CustomWarehouseInfoSnakeVO> pageList(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page) {
public IPage<CustomWarehouseInfoVO> pageList(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page) {
LambdaQueryWrapper<CustomWarehouseInfoEntity> wrapper = new LambdaQueryWrapper<>();
// 按仓库名称模糊搜索
if (StringUtils.hasText(entity.getWarehouse_name())) {
......@@ -53,9 +54,9 @@ public class CustomWarehouseInfoServiceImpl implements CustomWarehouseInfoServic
wrapper.orderByDesc(CustomWarehouseInfoEntity::getCreateTime);
IPage<CustomWarehouseInfoEntity> entityPage = customWarehouseInfoDomainService.page(
new Page<>(page.getCurrent(), page.getSize()), wrapper);
// Entity → VO 转换(使用 snakeCase mapper 处理蛇形字段)
IPage<CustomWarehouseInfoSnakeVO> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
voPage.setRecords(BeanMapper.snakeCase().convertList(entityPage.getRecords(), CustomWarehouseInfoSnakeVO.class));
// Entity → VO 转换
IPage<CustomWarehouseInfoVO> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
voPage.setRecords(BeanMapper.snakeCase().convertList(entityPage.getRecords(), CustomWarehouseInfoVO.class));
return voPage;
}
......
package com.jomalls.custom.app.vo.warehouse;
import com.jomalls.custom.app.vo.product.CustomProductWarehouseRelSnakeVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* Model
*
* @author Lizh
* @date 2026-06-03 14:47:24
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "VO")
public class CustomWarehouseInfoVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
*
*/
@Schema(description = "")
private Long id;
/**
* 仓库名称
*/
@Schema(description = "仓库名称")
private String warehouseName;
/**
* 仓库编码
*/
@Schema(description = "仓库编码")
private String warehouseCode;
/**
* 统筹物流
*/
@Schema(description = "统筹物流")
private Boolean overallLogistics;
/**
* 超级工厂
*/
@Schema(description = "超级工厂")
private Integer superFactory;
/**
* 系统物流
*/
@Schema(description = "系统物流")
private Boolean systemLogistics;
/**
* 统筹物流覆盖范围
*/
@Schema(description = "统筹物流覆盖范围")
private String overallLogisticsScope;
/**
* 联系人姓名
*/
@Schema(description = "联系人姓名")
private String contactName;
/**
* 联系人电话
*/
@Schema(description = "联系人电话")
private String contactPhone;
/**
* 联系人邮箱
*/
@Schema(description = "联系人邮箱")
private String contactEmail;
/**
* 国家代码
*/
@Schema(description = "国家代码")
private String countryCode;
/**
* 国家名称
*/
@Schema(description = "国家名称")
private String countryName;
/**
* 州省
*/
@Schema(description = "州省")
private String province;
/**
* 州省 code
*/
@Schema(description = "州省 code")
private String provinceCode;
/**
* 州省简称
*/
@Schema(description = "州省简称")
private String provinceAbb;
/**
* 城市
*/
@Schema(description = "城市")
private String city;
/**
* 城市编码
*/
@Schema(description = "城市编码")
private String cityCode;
/**
* 区县
*/
@Schema(description = "区县")
private String district;
/**
* 街道
*/
@Schema(description = "街道")
private String street;
/**
* 邮编
*/
@Schema(description = "邮编")
private String postcode;
/**
* 公司名称
*/
@Schema(description = "公司名称")
private String companyName;
/**
* 社会信用代码
*/
@Schema(description = "社会信用代码")
private String socialCreditCode;
/**
* 备注
*/
@Schema(description = "备注")
private String remarks;
/**
*
*/
@Schema(description = "")
private Date updateTime;
/**
*
*/
@Schema(description = "")
private Date createTime;
/**
* 1已上线,10待上线,20已下线,30待下线
*/
@Schema(description = "1已上线,10待上线,20已下线,30待下线")
private Integer status;
/**
* 联系人姓名(中文)
*/
@Schema(description = "联系人姓名(中文)")
private String contactNameCn;
/**
* 国家名称(中文)
*/
@Schema(description = "国家名称(中文)")
private String countryNameCn;
/**
* 洲省(中文)
*/
@Schema(description = "洲省(中文)")
private String provinceCn;
/**
* 城市(中文)
*/
@Schema(description = "城市(中文)")
private String cityCn;
/**
* 区县(中文)
*/
@Schema(description = "区县(中文)")
private String districtCn;
/**
* 街道(中文)
*/
@Schema(description = "街道(中文)")
private String streetCn;
/**
* 是否为正式仓库
*/
@Schema(description = "是否为正式仓库")
private Boolean formal;
/**
* 币种
*/
@Schema(description = "币种")
private String settlementCurrency;
/**
* 公司名称(中文)
*/
@Schema(description = "公司名称(中文)")
private String companyNameCn;
}
package com.jomalls.custom.integrate.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import lombok.Data;
/**
* 国家代码模型(对接 admin 管理端 API)
* <p>
* 外部 API 返回的字段类型不统一,部分为 Integer(如 id, needProviceAbbr),
* 使用 @JsonSetter(Object) + toString() 统一转为 String。
*
* @author Lizh
*/
@Data
public class BaseCountryCodeModel {
public class CountryCodeModel {
@JsonProperty("countryCode")
/** ID */
private String id;
/** 国家编码 */
private String countryCode;
@JsonProperty("nameCn")
/** AE 国家编码 */
private String aeCountryCode;
/** 洲编码 */
private String continentCode;
/** 国家中文名 */
private String nameCn;
@JsonProperty("nameEn")
/** 国家英文名 */
private String nameEn;
@JsonProperty("continentCode")
private String continentCode;
/** 是否需要省缩写 */
private String needProviceAbbr;
@JsonProperty("telephoneAreaCode")
/** 电话区号 */
private String telephoneAreaCode;
/** 创建时间 */
private String createTime;
/** 更新时间 */
private String updateTime;
}
package com.jomalls.custom.integrate.service;
import com.jomalls.custom.integrate.model.BaseCountryCodeModel;
import com.jomalls.custom.integrate.model.CountryCodeModel;
import com.jomalls.custom.integrate.model.CategoryInfoModel;
import com.jomalls.custom.integrate.model.PropertyModel;
......@@ -40,5 +40,5 @@ public interface SaasAdminService {
* <p>
* 调用 admin 管理端 API 查询所有国家代码。
*/
List<BaseCountryCodeModel> getAllCountryCode();
List<CountryCodeModel> getAllCountryCode();
}
package com.jomalls.custom.integrate.service.impl;
import com.alibaba.fastjson2.JSON;
import com.jomalls.custom.enums.CodeEnum;
import com.jomalls.custom.integrate.client.RemoteApiClient;
import com.jomalls.custom.integrate.model.BaseCountryCodeModel;
import com.jomalls.custom.integrate.model.CategoryInfoModel;
import com.jomalls.custom.integrate.model.PropertyModel;
import com.jomalls.custom.integrate.model.SaasAdminApiResponseModel;
import com.jomalls.custom.integrate.model.*;
import com.jomalls.custom.integrate.service.SaasAdminService;
import com.jomalls.custom.security.LoginUser;
import com.jomalls.custom.security.SecurityUtils;
......@@ -39,7 +37,7 @@ public class SaasAdminServiceImpl implements SaasAdminService {
private static final String GET_ALL_LIST_URL = "/api/manage/rest/baseCategoryInfo/all_list";
private static final String GET_PROPERTY_BY_IDS_URL = "/api/manage/rest/baseProperty/getByIds";
private static final String GET_ALL_COUNTRY_CODE_URL = "/api/manage/rest/baseCountryCode/all";
private static final String GET_ALL_COUNTRY_CODE_URL = "/api/manage/rest/getAllCountry";
private static final int DEFAULT_MAP_SIZE = 2;
......@@ -55,7 +53,7 @@ public class SaasAdminServiceImpl implements SaasAdminService {
private final AtomicReference<CacheEntry<List<CategoryInfoModel>>> categoryCache = new AtomicReference<>();
/** 国家代码本地缓存 */
private final AtomicReference<CacheEntry<List<BaseCountryCodeModel>>> countryCodeCache = new AtomicReference<>();
private final AtomicReference<CacheEntry<List<CountryCodeModel>>> countryCodeCache = new AtomicReference<>();
@Value("${server.admin.base-url:https://admin.jomalls.com}")
private String adminBaseUrl;
......@@ -149,26 +147,25 @@ public class SaasAdminServiceImpl implements SaasAdminService {
*
* @return 国家代码列表,失败时返回空列表
*/
public List<BaseCountryCodeModel> getAllCountryCode() {
public List<CountryCodeModel> getAllCountryCode() {
// 命中缓存且未过期 → 直接返回
CacheEntry<List<BaseCountryCodeModel>> entry = countryCodeCache.get();
CacheEntry<List<CountryCodeModel>> entry = countryCodeCache.get();
if (entry != null && !entry.isExpired()) {
return entry.data;
}
// 未命中或已过期 → 远程调用刷新
String url = adminBaseUrl + GET_ALL_COUNTRY_CODE_URL;
try {
ResponseEntity<SaasAdminApiResponseModel<List<BaseCountryCodeModel>>> response = remoteApiClient.get(
url,
new ParameterizedTypeReference<>() {},
getHeader());
// 该接口返回裸数组 [...], 不是 SaasAdminApiResponseModel 包装
ResponseEntity<String> response = remoteApiClient.get(
url, new ParameterizedTypeReference<>() {}, getHeader());
if (response != null && response.getBody() != null) {
SaasAdminApiResponseModel<List<BaseCountryCodeModel>> responseBody = response.getBody();
if (responseBody.getCode() == CodeEnum.SUCCESS.getCode()) {
List<BaseCountryCodeModel> data = responseBody.getData();
String body = response.getBody();
List<CountryCodeModel> data = JSON.parseArray(body, CountryCodeModel.class);
if (!data.isEmpty()) {
countryCodeCache.set(new CacheEntry<>(data, COUNTRY_CODE_CACHE_TTL_MS));
return data;
}
return data;
}
} catch (Exception e) {
log.error("[ SaasAdminService ] {} 调用失败", url, e);
......
......@@ -2,6 +2,7 @@ package com.jomalls.custom.webapp.controller.system;
import com.jomalls.custom.app.service.system.CountryCodeService;
import com.jomalls.custom.app.vo.system.CountryCodeVO;
import com.jomalls.custom.utils.AjaxResult;
import com.jomalls.custom.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
......@@ -30,15 +31,13 @@ public class CountryCodeController {
@Operation(summary = "获取国家代码映射(code → nameCn)")
@GetMapping("/map")
public R<Map<String, String>> getMap() {
Map<String, String> map = countryCodeService.getMap();
return R.ok(map);
public AjaxResult getMap() {
return AjaxResult.success(countryCodeService.getMap());
}
@Operation(summary = "获取全部国家代码列表")
@GetMapping("/all")
public R<List<CountryCodeVO>> getAll() {
List<CountryCodeVO> list = countryCodeService.getAll();
return R.ok(list);
public List<CountryCodeVO> getAll() {
return countryCodeService.getAll();
}
}
......@@ -7,6 +7,8 @@ import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoSaveDTO;
import com.jomalls.custom.app.dto.warehouse.CustomWarehouseInfoUpdateDTO;
import com.jomalls.custom.app.service.warehouse.CustomWarehouseInfoService;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoSnakeVO;
import com.jomalls.custom.app.vo.warehouse.CustomWarehouseInfoVO;
import com.jomalls.custom.utils.AjaxResult;
import com.jomalls.custom.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
......@@ -33,38 +35,35 @@ public class CustomWarehouseInfoController {
@Operation(summary = "获取仓库状态列表")
@GetMapping("/statusList")
public R<List<Map<String, Object>>> statusList() {
return R.ok(customWarehouseInfoService.statusList());
public List<Map<String, Object>> statusList() {
return customWarehouseInfoService.statusList();
}
@Operation(summary = "分页查询仓库列表")
@RequiresPermissions("business:customWarehouse:list")
@GetMapping("/list")
public R<IPage<CustomWarehouseInfoSnakeVO>> list(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page) {
return R.ok(customWarehouseInfoService.pageList(entity, page));
public IPage<CustomWarehouseInfoVO> list(CustomWarehouseInfoSnakeVO entity, Page<CustomWarehouseInfoSnakeVO> page) {
return customWarehouseInfoService.pageList(entity, page);
}
@Operation(summary = "新增仓库")
@RequiresPermissions("business:customWarehouse:add")
@PostMapping
public R<Void> add(@RequestBody CustomWarehouseInfoSaveDTO dto) {
public void add(@RequestBody CustomWarehouseInfoSaveDTO dto) {
customWarehouseInfoService.add(dto);
return R.ok();
}
@Operation(summary = "修改仓库")
@RequiresPermissions("business:customWarehouse:edit")
@PutMapping
public R<Void> edit(@RequestBody CustomWarehouseInfoUpdateDTO dto) {
public void edit(@RequestBody CustomWarehouseInfoUpdateDTO dto) {
customWarehouseInfoService.edit(dto);
return R.ok();
}
@Operation(summary = "删除仓库")
@RequiresPermissions("business:customWarehouse:remove")
@DeleteMapping("/{ids}")
public R<Void> remove(@PathVariable String ids) {
public void remove(@PathVariable String ids) {
customWarehouseInfoService.remove(ids);
return R.ok();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment