| | |
| | | package com.ruoyi.web.controller.product; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | 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.domain.R; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.im.comm.Result; |
| | | import com.ruoyi.im.service.MedicalInsuranceAccountService; |
| | | import com.ruoyi.system.domain.InsuranceProduct; |
| | | import com.ruoyi.system.domain.MedicalInsuranceAccount; |
| | | import com.ruoyi.system.domain.UserAccount; |
| | | import com.ruoyi.system.domain.UserPolicy; |
| | | import com.ruoyi.system.domain.dto.UserPolicyDto; |
| | | import com.ruoyi.im.service.UserPolicyService; |
| | | import com.ruoyi.system.service.UserAccountService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | |
| | | |
| | | @RestController |
| | | @RequestMapping("/userPolicy") |
| | | public class UserPolicyController { |
| | | public class UserPolicyController extends BaseController { |
| | | |
| | | @Autowired |
| | | UserPolicyService userPolicyService; |
| | |
| | | @Autowired |
| | | MedicalInsuranceAccountService medicalInsuranceAccountService; |
| | | |
| | | @Autowired |
| | | UserAccountService userAccountService; |
| | | |
| | | /** |
| | | * 保险购买申请 |
| | | */ |
| | | @PostMapping("/purchaseApplication") |
| | | public Result purchaseApplication(@Valid @RequestBody UserPolicyDto dto) { |
| | | public Result purchaseApplication(UserPolicyDto dto) { |
| | | try { |
| | | return userPolicyService.purchaseApplication(dto); |
| | | }catch (Exception e){ |
| | | e.getMessage(); |
| | | e.printStackTrace(); |
| | | return Result.error("购买失败"); |
| | | } |
| | | } |
| | |
| | | * 根据用户id查询保单 |
| | | */ |
| | | @GetMapping("/getPolicyById") |
| | | public Result getPolicyById(@RequestParam(value = "id") Integer id) { |
| | | public Result getPolicyById(@RequestParam(value = "account") String account) { |
| | | try { |
| | | List<UserPolicy> list = userPolicyService.list(new LambdaQueryWrapper<UserPolicy>().eq(UserPolicy::getUserId, id)); |
| | | UserAccount userAccount = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>() |
| | | .eq(UserAccount::getAccount,account)); |
| | | List<UserPolicy> list = userPolicyService.list(new LambdaQueryWrapper<UserPolicy>().eq(UserPolicy::getUserId, userAccount.getId())); |
| | | return Result.success(list); |
| | | }catch (Exception e){ |
| | | e.getMessage(); |
| | | return Result.error("购买失败"); |
| | | e.printStackTrace(); |
| | | return Result.error("查询失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保单列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(@RequestParam(value = "account",required = false) String account, |
| | | @RequestParam(value = "approvalStatus",required = false) Integer approvalStatus, |
| | | @RequestParam(value = "productName",required = false) String productName) { |
| | | startPage(); |
| | | |
| | | LambdaQueryWrapper<UserPolicy> wrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 产品名称模糊查询 |
| | | if (org.apache.commons.lang3.StringUtils.isNotBlank(account)) { |
| | | wrapper.like(UserPolicy::getUserId, account); |
| | | } |
| | | |
| | | // 产品代码模糊查询 |
| | | if (org.apache.commons.lang3.StringUtils.isNotBlank(productName)) { |
| | | wrapper.like(UserPolicy::getProductName, productName); |
| | | } |
| | | |
| | | // 产品状态精确查询 |
| | | if (approvalStatus != null) { |
| | | wrapper.eq(UserPolicy::getApprovalStatus, approvalStatus); |
| | | } |
| | | |
| | | // 按创建时间倒序排列 |
| | | wrapper.orderByDesc(UserPolicy::getCreatedAt); |
| | | |
| | | List<UserPolicy> list = userPolicyService.list(wrapper); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保单审批 |
| | | */ |
| | | @PostMapping("/examine") |
| | | @GetMapping("/examine") |
| | | @Transactional |
| | | public AjaxResult examine(@RequestParam(value = "id") Integer id, @RequestParam(value = "approvalStatus") Integer approvalStatus, @RequestParam(value = "message",required = false) String message) { |
| | | public AjaxResult examine(@RequestParam(value = "id") Integer id, |
| | | @RequestParam(value = "approvalStatus") Integer approvalStatus, |
| | | @RequestParam(value = "message",required = false) String message) { |
| | | try { |
| | | UserPolicy userPolicy = userPolicyService.getById(id); |
| | | if(ObjectUtil.isEmpty(userPolicy)){ |
| | |
| | | medicalInsuranceAccountService.save(medicalInsuranceAccount); |
| | | return AjaxResult.success("审批成功"); |
| | | }catch (Exception e){ |
| | | e.getMessage(); |
| | | e.printStackTrace(); |
| | | // 手动设置回滚 |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.error("审批失败!"); |
| | | } |
| | | } |