| | |
| | | */ |
| | | @PostMapping("/update") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult update(InsuranceProductUpdateDTO dto) { |
| | | public AjaxResult update(@RequestBody InsuranceProductUpdateDTO dto) { |
| | | // 1. 查询产品是否存在 |
| | | InsuranceProduct insuranceProduct = insuranceProductService.getById(dto.getId()); |
| | | if (insuranceProduct == null) { |
| | |
| | | } |
| | | |
| | | // 4. 处理产品特色 |
| | | if (dto.getFeatureDtoList() != null && !dto.getFeatureDtoList().isEmpty()) { |
| | | if (dto.getProductFeature() != null && !dto.getProductFeature().isEmpty()) { |
| | | try { |
| | | // 先删除该产品原有的所有特色 |
| | | deleteByProductId(insuranceProduct.getId()); |
| | | |
| | | // 转换DTO为实体并设置产品ID |
| | | List<InsuranceFeature> features = dto.getFeatureDtoList().stream() |
| | | List<InsuranceFeature> features = dto.getProductFeature().stream() |
| | | .map(f -> { |
| | | InsuranceFeature insuranceFeature = new InsuranceFeature(); |
| | | insuranceFeature.setProductId(insuranceProduct.getId()); |
| | |
| | | @GetMapping("/get") |
| | | public AjaxResult get(@RequestParam(value = "id") Integer id) { |
| | | InsuranceProduct insuranceProduct = insuranceProductService.getById(id); |
| | | List<InsuranceFeature> features = insuranceFeatureService.list(new LambdaQueryWrapper<InsuranceFeature>() |
| | | .eq(InsuranceFeature::getProductId, insuranceProduct.getId())); |
| | | insuranceProduct.setProductFeature(features); |
| | | return AjaxResult.success(insuranceProduct); |
| | | } |
| | | |
| | |
| | | wrapper.orderByDesc(InsuranceProduct::getCreatedAt); |
| | | |
| | | List<InsuranceProduct> list = insuranceProductService.list(wrapper); |
| | | list.forEach(f->{ |
| | | List<InsuranceFeature> features = insuranceFeatureService.list(new LambdaQueryWrapper<InsuranceFeature>() |
| | | .eq(InsuranceFeature::getProductId, f.getId())); |
| | | f.setProductFeature(features); |
| | | }); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | |
| | | */ |
| | | @PostMapping("/create") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult create(InsuranceProductUpdateDTO dto) { |
| | | public AjaxResult create(@RequestBody InsuranceProductUpdateDTO dto) { |
| | | // 1. 检查产品代码是否已存在 |
| | | long count = insuranceProductService.count(new LambdaQueryWrapper<InsuranceProduct>().eq(InsuranceProduct::getProductCode, dto.getProductCode())); |
| | | if (count > 0) { |
| | |
| | | } |
| | | |
| | | // 4. 处理产品特色 |
| | | if (dto.getFeatureDtoList() != null && !dto.getFeatureDtoList().isEmpty()) { |
| | | if (dto.getProductFeature() != null && !dto.getProductFeature().isEmpty()) { |
| | | try { |
| | | // 转换DTO为实体并设置产品ID |
| | | List<InsuranceFeature> features = dto.getFeatureDtoList().stream() |
| | | List<InsuranceFeature> features = dto.getProductFeature().stream() |
| | | .map(f -> { |
| | | InsuranceFeature insuranceFeature = new InsuranceFeature(); |
| | | insuranceFeature.setProductId(product.getId()); |