| | |
| | | package com.ruoyi.web.controller.product; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.im.util.ConverterUtil; |
| | | import com.ruoyi.system.domain.GroupWelcomeConfig; |
| | | import com.ruoyi.system.domain.InsuranceFeature; |
| | | import com.ruoyi.system.domain.InsuranceProduct; |
| | | import com.ruoyi.system.domain.IpBlacklist; |
| | | import com.ruoyi.system.domain.dto.InsuranceProductUpdateDTO; |
| | | import com.ruoyi.system.service.InsuranceFeatureService; |
| | | import com.ruoyi.system.service.InsuranceProductService; |
| | | import com.ruoyi.im.service.InsuranceFeatureService; |
| | | import com.ruoyi.im.service.InsuranceProductService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | */ |
| | | @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()); |
| | | insuranceProduct.setTerm(dto.getTerm()); |
| | | |
| | | insuranceProduct.setNumberDays(dto.getNumberDays()); |
| | | // 处理枚举状态 |
| | | if (dto.getStatus() != null) { |
| | | try { |
| | |
| | | insuranceProduct.setGuaranteeExplanation(dto.getGuaranteeExplanation()); |
| | | insuranceProduct.setInsureAge(dto.getInsureAge()); |
| | | insuranceProduct.setObligationDisclose(dto.getObligationDisclose()); |
| | | insuranceProduct.setProductFeature(dto.getProductFeature()); |
| | | insuranceProduct.setLiabilityExemption(dto.getLiabilityExemption()); |
| | | insuranceProduct.setImg1(dto.getImg1()); |
| | | insuranceProduct.setImg2(dto.getImg2()); |
| | |
| | | } |
| | | |
| | | // 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()); |
| | | insuranceFeature.setTitle(f.getTitle()); |
| | | insuranceFeature.setDetail(f.getDetail()); |
| | | insuranceFeature.setCreatedAt(LocalDateTime.now()); |
| | | insuranceFeature.setUpdatedAt(LocalDateTime.now()); |
| | | insuranceFeature.setCreatedAt(new Date()); |
| | | insuranceFeature.setUpdatedAt(new Date()); |
| | | return insuranceFeature; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | |
| | | 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) { |
| | |
| | | product.setCoverageAmount(dto.getCoverageAmount()); |
| | | product.setPremium(dto.getPremium()); |
| | | product.setTerm(dto.getTerm()); |
| | | product.setNumberDays(dto.getNumberDays()); |
| | | |
| | | // 处理状态 |
| | | if (dto.getStatus() != null) { |
| | |
| | | product.setGuaranteeExplanation(dto.getGuaranteeExplanation()); |
| | | product.setInsureAge(dto.getInsureAge()); |
| | | product.setObligationDisclose(dto.getObligationDisclose()); |
| | | product.setProductFeature(dto.getProductFeature()); |
| | | product.setLiabilityExemption(dto.getLiabilityExemption()); |
| | | product.setImg1(dto.getImg1()); |
| | | product.setImg2(dto.getImg2()); |
| | | |
| | | // 设置创建时间和更新时间 |
| | | product.setCreatedAt(LocalDateTime.now()); |
| | | product.setUpdatedAt(LocalDateTime.now()); |
| | | product.setCreatedAt(new Date()); |
| | | product.setUpdatedAt(new Date()); |
| | | |
| | | // 3. 保存产品信息 |
| | | boolean productSuccess = insuranceProductService.save(product); |
| | |
| | | } |
| | | |
| | | // 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()); |
| | | insuranceFeature.setTitle(f.getTitle()); |
| | | insuranceFeature.setDetail(f.getDetail()); |
| | | insuranceFeature.setCreatedAt(LocalDateTime.now()); |
| | | insuranceFeature.setUpdatedAt(LocalDateTime.now()); |
| | | insuranceFeature.setCreatedAt(new Date()); |
| | | insuranceFeature.setUpdatedAt(new Date()); |
| | | return insuranceFeature; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | |
| | | /** |
| | | * 删除产品 |
| | | */ |
| | | @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("产品不存在"); |