| | |
| | | */ |
| | | @PostMapping("/update") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult update(@Valid @RequestBody InsuranceProductUpdateDTO dto) { |
| | | public AjaxResult update(@RequestBody InsuranceProductUpdateDTO dto) { |
| | | // 1. 查询产品是否存在 |
| | | InsuranceProduct insuranceProduct = insuranceProductService.getById(dto.getId()); |
| | | if (insuranceProduct == null) { |
| | |
| | | |
| | | // 2. 更新产品基本信息 |
| | | insuranceProduct.setProductName(dto.getProductName()); |
| | | insuranceProduct.setProductCode(dto.getProductCode()); |
| | | insuranceProduct.setDescription(dto.getDescription()); |
| | | insuranceProduct.setCoverageAmount(dto.getCoverageAmount()); |
| | | insuranceProduct.setPremium(dto.getPremium()); |
| | |
| | | } |
| | | |
| | | // 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()); |
| | |
| | | deleteByProductId(insuranceProduct.getId()); |
| | | } |
| | | |
| | | return AjaxResult.success("保存成功!"); |
| | | return AjaxResult.success("修改成功!"); |
| | | } |
| | | |
| | | public void deleteByProductId(Integer productId) { |
| | |
| | | @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); |
| | | } |
| | | |
| | |
| | | * 产品信息列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(InsuranceProductUpdateDTO dto) { |
| | | public TableDataInfo list(@RequestParam(value = "productName",required = false) String productName, |
| | | @RequestParam(value = "productCode",required = false) String productCode, |
| | | @RequestParam(value = "status",required = false) String status) { |
| | | startPage(); |
| | | |
| | | LambdaQueryWrapper<InsuranceProduct> wrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 产品名称模糊查询 |
| | | if (StringUtils.isNotBlank(dto.getProductName())) { |
| | | wrapper.like(InsuranceProduct::getProductName, dto.getProductName()); |
| | | if (StringUtils.isNotBlank(productName)) { |
| | | wrapper.like(InsuranceProduct::getProductName, productName); |
| | | } |
| | | |
| | | // 产品代码模糊查询 |
| | | if (StringUtils.isNotBlank(dto.getProductCode())) { |
| | | wrapper.like(InsuranceProduct::getProductCode, dto.getProductCode()); |
| | | if (StringUtils.isNotBlank(productCode)) { |
| | | wrapper.like(InsuranceProduct::getProductCode, productCode); |
| | | } |
| | | |
| | | // 产品状态精确查询 |
| | | if (dto.getStatus() != null) { |
| | | wrapper.eq(InsuranceProduct::getStatus, dto.getStatus()); |
| | | if (StringUtils.isNotBlank(status)) { |
| | | wrapper.eq(InsuranceProduct::getStatus, status); |
| | | } |
| | | |
| | | // 按创建时间倒序排列 |
| | | 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(@Valid @RequestBody 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()); |
| | |
| | | /** |
| | | * 删除产品 |
| | | */ |
| | | @DeleteMapping("/{id}") |
| | | public AjaxResult delete(@PathVariable Integer id) { |
| | | @GetMapping("/delete") |
| | | public AjaxResult delete(@RequestParam(value = "id") Integer id) { |
| | | InsuranceProduct product = insuranceProductService.getById(id); |
| | | if (product == null) { |
| | | return AjaxResult.error("产品不存在"); |