feat: 产品中心

This commit is contained in:
曹鹏飞 2025-06-16 09:19:57 +08:00
parent 3064174bbf
commit 9ef1194fdf
7 changed files with 90 additions and 12 deletions

View File

@ -0,0 +1,21 @@
package com.nflg.mobilebroken.product.config;
import com.nflg.mobilebroken.product.interceptor.LanguageInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Resource
private LanguageInterceptor languageInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 注册拦截器并指定拦截路径
registry.addInterceptor(languageInterceptor).addPathPatterns("/**");
}
}

View File

@ -60,10 +60,21 @@ public class MobilebrokenController extends BaseController{
*/
@GetMapping("/getType")
public ApiResult<List<ProductTypeVO>> getType(@Valid @RequestParam @NotNull Integer moduleId
,@Valid @RequestParam @NotNull String seriesName){
,@RequestParam(required = false) String seriesName){
return ApiResult.success(productTypeService.get(moduleId,seriesName,MultilingualUtil.getLanguage()));
}
/**
* 获取产品类型文件列表
* @param moduleId 产品模块id
* @param seriesName 产品系列名称
*/
@GetMapping
public ApiResult<List<ProductFileVO>> getFiles(@Valid @RequestParam @NotNull Integer moduleId
,@RequestParam(required = false) String seriesName){
return ApiResult.success(productTypeService.getFilesByLanguage(moduleId,seriesName,MultilingualUtil.getLanguage()));
}
/**
* 获取产品机型列表
* @param moduleId 产品模块id
@ -88,7 +99,7 @@ public class MobilebrokenController extends BaseController{
* 机型比较
* @param request 请求参数
*/
@GetMapping("/getModelCompareInfo")
@PostMapping("/getModelCompareInfo")
public ApiResult<List<ProductModelCompareInfoVO>> getModelCompareInfo(@Valid @RequestBody BatchDeleteRequest request){
return ApiResult.success(productModelService.getModelCompareInfo(request,MultilingualUtil.getLanguage()));
}

View File

@ -0,0 +1,28 @@
package com.nflg.mobilebroken.product.interceptor;
import cn.hutool.core.util.StrUtil;
import com.nflg.mobilebroken.common.util.MultilingualUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LanguageInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 从请求头中获取 language 参数
String language = request.getHeader("language");
if(StrUtil.isNotBlank(language)){
MultilingualUtil.setLanguage(language);
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// 请求完成后清理 ThreadLocal防止内存泄漏
MultilingualUtil.clear();
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nflg.mobilebroken.common.pojo.request.ProductTypeSearchRequest;
import com.nflg.mobilebroken.common.pojo.vo.FrontendProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductFileVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeVO;
import com.nflg.mobilebroken.repository.entity.ProductType;
@ -28,4 +29,6 @@ public interface ProductTypeMapper extends BaseMapper<ProductType> {
void copyItems(@NotNull Integer oldId, Integer newId);
Page<FrontendProductTypeSearchVO> search(String name, String language, Page<?> page);
List<ProductFileVO> getFilesByLanguage(Integer moduleId, String seriesNo, String language);
}

View File

@ -3,10 +3,7 @@ package com.nflg.mobilebroken.repository.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.nflg.mobilebroken.common.pojo.request.*;
import com.nflg.mobilebroken.common.pojo.vo.FrontendProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeInfoVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeVO;
import com.nflg.mobilebroken.common.pojo.vo.*;
import com.nflg.mobilebroken.repository.entity.ProductType;
import javax.validation.Valid;
@ -49,4 +46,6 @@ public interface IProductTypeService extends IService<ProductType> {
void saveSort(SortSaveRequest request);
Page<FrontendProductTypeSearchVO> search(@Valid ProductSeriesSearchRequest request, String language);
List<ProductFileVO> getFilesByLanguage(@Valid @NotNull Integer moduleId, String seriesName, String language);
}

View File

@ -11,10 +11,7 @@ import com.nflg.mobilebroken.common.constant.PublishState;
import com.nflg.mobilebroken.common.constant.STATE;
import com.nflg.mobilebroken.common.exception.NflgException;
import com.nflg.mobilebroken.common.pojo.request.*;
import com.nflg.mobilebroken.common.pojo.vo.FrontendProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeInfoVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeSearchVO;
import com.nflg.mobilebroken.common.pojo.vo.ProductTypeVO;
import com.nflg.mobilebroken.common.pojo.vo.*;
import com.nflg.mobilebroken.common.util.AdminUserUtil;
import com.nflg.mobilebroken.common.util.VUtils;
import com.nflg.mobilebroken.repository.entity.ProductType;
@ -277,6 +274,11 @@ public class ProductTypeServiceImpl extends ServiceImpl<ProductTypeMapper, Produ
return datas;
}
@Override
public List<ProductFileVO> getFilesByLanguage(Integer moduleId, String seriesName, String language) {
return baseMapper.getFilesByLanguage(moduleId, seriesName, language);
}
private void delete(Integer typeId){
ProductType info=getById(typeId);
removeById(typeId);

View File

@ -36,7 +36,10 @@
SELECT pt.id,pt.series_name,pt.name as 'typeNo',pti.*
FROM product_type pt
LEFT JOIN product_type_info pti ON pti.type_id=pt.id AND pti.language_code=#{language}
WHERE pt.state=1 AND pt.enable=1 AND pt.module_id=#{moduleId} AND pt.series_name=#{seriesNo}
WHERE pt.state=1 AND pt.enable=1 AND pt.module_id=#{moduleId}
<if test="seriesNo != null and seriesNo!=''">
AND pt.series_name=#{seriesNo}
</if>
ORDER BY pt.sort
</select>
@ -61,4 +64,15 @@
AND pti.`name` LIKE CONCAT('%', #{name}, '%')
ORDER BY pt.sort,pt.id DESC
</select>
<select id="getFilesByLanguage" resultType="com.nflg.mobilebroken.common.pojo.vo.ProductFileVO">
SELECT ptf.*
FROM product_type pt
LEFT JOIN product_type_file ptf ON ptf.type_id=pt.id AND ptf.language_code=#{language}
WHERE pt.state=1 AND pt.enable=1 AND pt.module_id=#{moduleId}
<if test="seriesNo != null and seriesNo!=''">
AND pt.series_name=#{seriesNo}
</if>
ORDER BY pt.sort
</select>
</mapper>