package com.ydtech.modules.protocol.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ydtech.core.page.HttpResult; import com.ydtech.core.page.PageResult; import com.ydtech.exception.SystemException; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.order.entity.po.InsUploadFiles; import com.ydtech.modules.order.service.InsUploadFilesService; import com.ydtech.modules.protocol.entity.po.PtlAgreement; import com.ydtech.modules.protocol.entity.po.PtlAgreementNonCarProductCosts; import com.ydtech.modules.protocol.entity.po.PtlAgreementProductCosts; import com.ydtech.modules.protocol.entity.po.PtlAgreementUndwrtRules; import com.ydtech.modules.protocol.entity.vo.*; import com.ydtech.modules.protocol.service.*; import com.ydtech.modules.protocol.utils.AssertionUtils; import com.ydtech.validation.annotation.CheckObjectNotNull; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Objects; /** * @author wenks * @description 协议管理内容 * @createDate 2023-06-05 17:59:52 */ @Api(tags = "协议") @RequestMapping("/plt/agreement") @RestController public class PtlAgreementController extends BaseController { @Value("${agreement.shutdown}") private boolean shutdown; private final PtlAgreementService ptlAgreementService; private final PtlAgreementUndwrtRulesService ptlAgreementUndwrtRulesService; private final PtlAgreementProductCostsService ptlAgreementProductCostsService; private final PtlAgreementNonCarProductCostsService ptlAgreementNonCarProductCostsService; private final PtlAgreementTrajectoryService ptlAgreementTrajectoryService; private final InsUploadFilesService insUploadFilesService; public PtlAgreementController(PtlAgreementService ptlAgreementService, PtlAgreementUndwrtRulesService ptlAgreementUndwrtRulesService, PtlAgreementProductCostsService ptlAgreementProductCostsService, PtlAgreementNonCarProductCostsService ptlAgreementNonCarProductCostsService, PtlAgreementTrajectoryService ptlAgreementTrajectoryService, InsUploadFilesService insUploadFilesService) { this.ptlAgreementService = ptlAgreementService; this.ptlAgreementProductCostsService = ptlAgreementProductCostsService; this.ptlAgreementUndwrtRulesService = ptlAgreementUndwrtRulesService; this.ptlAgreementNonCarProductCostsService = ptlAgreementNonCarProductCostsService; this.ptlAgreementTrajectoryService = ptlAgreementTrajectoryService; this.insUploadFilesService = insUploadFilesService; } @PostMapping("/page") @ApiOperation("分页查询协议") public HttpResult> page(@RequestBody PtlAgreementPageVo ptlAgreementPageVo) { Page page = buildPageRequest(ptlAgreementPageVo.getPageDto()); Page pageResultHttpResult = ptlAgreementService.pageAgreement(page, ptlAgreementPageVo); return HttpResult.ok(buildPageResponse(pageResultHttpResult)); } @GetMapping("/getAllAgreement") @ApiOperation("复制费用查询同保险公司协议") public HttpResult> getAllAgreement(@RequestParam String agreementId) { return HttpResult.ok(ptlAgreementService.getAllAgreement(agreementId)); } @PostMapping("/list") @ApiOperation("根据保险公司查询协议列表") public HttpResult> list(@RequestBody PtlAgreementPageVo ptlAgreementPageVo) { return ptlAgreementService.listAgreement(ptlAgreementPageVo); } @PostMapping("/listInternal") @ApiOperation("根据保险公司查询协议列表") public HttpResult> listInternal(@RequestBody PtlAgreementPageVo ptlAgreementPageVo) { ptlAgreementPageVo.setIsExternal(0); ptlAgreementPageVo.setAuditStatus(0); ptlAgreementPageVo.setValidStatus("1"); return ptlAgreementService.listAgreementInternal(ptlAgreementPageVo); } @PutMapping("/{agreementId}") @ApiOperation("修改协议") public HttpResult revise(@PathVariable String agreementId, @RequestBody PtlAgreementSaveVo agreement) { String userName = getUserName(); return ptlAgreementService.reviseAgreement(userName, agreementId, agreement); } @PostMapping("/batch") @ApiOperation("批量修改协议是否启用状态") public HttpResult batchRevise(@RequestBody PltAgreementBatchVo pltAgreementBatchVo) { List ptlAgreements = new ArrayList<>(); for (String agreementId : pltAgreementBatchVo.getAgreementIds()) { PtlAgreement ptlAgreement = new PtlAgreement(); ptlAgreement.setId(agreementId); ptlAgreement.setValidStatus(pltAgreementBatchVo.getValidStatus()); ptlAgreement.setAuditType(pltAgreementBatchVo.getAuditType()); ptlAgreements.add(ptlAgreement); } boolean b = ptlAgreementService.updateBatchById(ptlAgreements); AssertionUtils.isSucceed(b, "批量修改协议失败"); return HttpResult.ok("批量修改协议成功"); } @GetMapping("/{agreementId}") @ApiOperation("通过协议id查询所有信息") public HttpResult getByAgreementId(@PathVariable String agreementId) { return ptlAgreementService.getByAgreementId(agreementId); } @DeleteMapping("/{agreementId}") @ApiOperation("删除协议") public HttpResult delete(@PathVariable String agreementId) { return ptlAgreementService.deleteAgreement(agreementId, getUserName()); } @PostMapping @ApiOperation("添加协议") public HttpResult save(@RequestBody PtlAgreementSaveVo agreement) { String userName = getUserName(); return ptlAgreementService.saveAgreement(agreement, userName); } @PostMapping("/getProduct") @ApiOperation("查询协议产品费用") public PageResult getProductSav(@RequestBody PtlAgreementProductQueryVo ptlAgreementProductQueryVo) { Page page = buildPageRequest(ptlAgreementProductQueryVo.getPageDto()); Page schemeQueryDto = ptlAgreementProductCostsService.getByAgreementId(page, ptlAgreementProductQueryVo); return buildPageResponse(schemeQueryDto); } @PostMapping("productSave") @ApiOperation("添加协议产品费用") public HttpResult productSave(@RequestBody PtlAgreementProductCosts agreement) { String userName = getUserName(); return ptlAgreementService.saveAgreementProduct(agreement, userName); } @PostMapping("productUpdate") @ApiOperation("修改协议产品费用") public HttpResult productUpdate(@RequestBody PtlAgreementProductCosts agreement) { String userName = getUserName(); return ptlAgreementService.updateAgreementProduct(agreement, userName); } @GetMapping("productDelete") @ApiOperation("删除协议产品费用") public HttpResult productDelete(String id) { String userName = getUserName(); return ptlAgreementService.deleteAgreementProduct(id, userName); } @GetMapping("/getNonCarProduct") @ApiOperation("查询非车产品费用") public HttpResult getNonCarProduct(@RequestParam String agreementId) { List nonCarProductCosts = ptlAgreementNonCarProductCostsService.getByAgreementId(agreementId); return HttpResult.ok(nonCarProductCosts); } @PostMapping("nonCarProductSave") @ApiOperation("添加非车产品费用") public HttpResult nonCarProductSave(@RequestBody PtlAgreementNonVehicleProductCostsVo agreement) { String userName = getUserName(); return ptlAgreementService.saveAgreementNonCarProductCosts(agreement, userName); } @PostMapping("getUndwrtRules") @ApiOperation("查询承保规则") public PageResult getUndwrtRules(@RequestBody PtlAgreementUndwrtRulesQueryVo ptlAgreementUndwrtRulesQueryVo) { Page page = buildPageRequest(ptlAgreementUndwrtRulesQueryVo.getPageDto()); Page underwritingRules = ptlAgreementUndwrtRulesService.getByAgreementId(page, ptlAgreementUndwrtRulesQueryVo.getAgreementId()); return buildPageResponse(underwritingRules); } @PostMapping("undwrtRulesSave") @ApiOperation("添加承保规则") public HttpResult underwritingRulesSave(@RequestBody PtlAgreementUndwrtRules ptlAgreementUndwrtRules) { String userName = getUserName(); return ptlAgreementService.saveAgreementUndwrtRules(ptlAgreementUndwrtRules, userName); } @PostMapping("undwrtRulesUpdate") @ApiOperation("修改承保规则") public HttpResult underwritingRulesUpdate(@RequestBody PtlAgreementUndwrtRules ptlAgreementUndwrtRules) { String userName = getUserName(); return ptlAgreementService.updateAgreementUndwrtRules(ptlAgreementUndwrtRules, userName); } @GetMapping("undwrtRulesDelete") @ApiModelProperty("删除承保规则") public HttpResult underwritingRulesDelete(String id) { String userName = getUserName(); return ptlAgreementService.deleteAgreementUndwrtRules(id, userName); } @PostMapping("/audit/{agreementId}") @ApiOperation("审核协议") public HttpResult audit(@PathVariable String agreementId, @RequestBody PtlAgreementAuditVo ptlAgreementAuditVo) { return ptlAgreementService.auditAgreement(agreementId, ptlAgreementAuditVo); } @GetMapping("/shutdown") @ApiOperation("关闭") public HttpResult shutdown() { return HttpResult.ok("", shutdown); } @PostMapping("/noncarcost") @ApiOperation("获取非车险费用配置列表") public HttpResult> getAgreementNonCarCosts(@RequestBody PtlAgreement ptlAgreement) { return ptlAgreementService.getNonCarCostsInfo(ptlAgreement.getAgreementCode(), ptlAgreement.getAssociationCompaniesId()); } @PostMapping("/findrelationagree") @ApiOperation("获取可同步协议列表") public HttpResult> findRelationAgreement(@RequestBody PtlAgreement ptlAgreement) { return ptlAgreementService.findRelationAgreement(ptlAgreement.getAssociationCompaniesId()); } @GetMapping("getDockingPersonList") @ApiOperation("获取对接人列表") public HttpResult getDockingPersonList() { List> list = ptlAgreementService.getDockingPersonList(); return HttpResult.ok(list); } @PostMapping("/agreementCopy") @ApiOperation("协议复制") public HttpResult getAgreementCopy(@RequestBody PtlAgreementVo ptlAgreementVo) { return ptlAgreementService.getAgreementCopy(ptlAgreementVo); } @PostMapping("/agreementTrajectory") @ApiOperation("协议轨迹") public HttpResult getAgreementTrajectory(@RequestBody PtlAgreementVo ptlAgreementVo) { return ptlAgreementTrajectoryService.getAgreementTrajectory(ptlAgreementVo); } @PostMapping("/updateFeeFile") @ApiOperation("上传费用文件") public HttpResult updateFeeFile(@CheckObjectNotNull(message = "上传文件不能为空") MultipartFile multipartFile, String agreementId) throws IOException { agreementId = agreementId.replace(",",""); InsUploadFiles insUploadFiles = insUploadFilesService.uploadFile(multipartFile, getUserName(), "file"); PtlAgreement byId = ptlAgreementService.getById(agreementId); if(Objects.isNull(byId)){ throw new SystemException("找不到协议"); } byId.setFeeFileId(insUploadFiles.getId()); return ptlAgreementService.updateById(byId) ? HttpResult.ok("上传费用文件成功") : HttpResult.error("上传文件失败"); } }