| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- package com.ydtech.modules.protocol.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.esm.model.EsmInsCompany;
- import com.ydtech.modules.esm.service.EsmInsCompanyService;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.modules.protocol.dao.PtlInsAttributionTemplateMapper;
- import com.ydtech.modules.protocol.entity.constants.PtlApiType;
- import com.ydtech.modules.protocol.entity.dto.PtlInsAttributionTemplateQueryDto;
- import com.ydtech.modules.protocol.entity.po.PtlAgreementAttribution;
- import com.ydtech.modules.protocol.entity.po.PtlCrawlerApi;
- import com.ydtech.modules.protocol.entity.po.PtlInsAttributionTemplate;
- import com.ydtech.modules.protocol.entity.vo.PtlCrawlerApiSaveVo;
- import com.ydtech.modules.protocol.entity.vo.PtlInsAttributionTemplateQueryVo;
- import com.ydtech.modules.protocol.entity.vo.PtlInsAttributionTemplateSaveVo;
- import com.ydtech.modules.protocol.entity.vo.PtlInsAttributionTemplateVo;
- import com.ydtech.modules.protocol.service.PtlAgreementAttributionService;
- import com.ydtech.modules.protocol.service.PtlCrawlerApiService;
- import com.ydtech.modules.protocol.service.PtlInsAttributionTemplateService;
- import com.ydtech.modules.protocol.utils.AssertionUtils;
- import com.ydtech.utils.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.ObjectUtils;
- import java.util.List;
- import java.util.Objects;
- /**
- * @author wenks
- * @description 针对表【ptl_ins_attribution_template(保险公司归属信息模板配置)】的数据库操作Service实现
- * @createDate 2023-07-03 09:31:16
- */
- @Service
- public class PtlInsAttributionTemplateServiceImpl extends ServiceImpl<PtlInsAttributionTemplateMapper, PtlInsAttributionTemplate>
- implements PtlInsAttributionTemplateService {
- private final EsmInsCompanyService esmInsCompanyService;
- private final PtlCrawlerApiService ptlCrawlerApiService;
- private final PtlInsAttributionTemplateService proxyService;
- private final PtlAgreementAttributionService ptlAgreementAttributionService;
- public PtlInsAttributionTemplateServiceImpl(EsmInsCompanyService esmInsCompanyService, PtlCrawlerApiService ptlCrawlerApiService,
- @Lazy PtlInsAttributionTemplateService proxyService,PtlAgreementAttributionService ptlAgreementAttributionService) {
- this.esmInsCompanyService = esmInsCompanyService;
- this.ptlCrawlerApiService = ptlCrawlerApiService;
- this.proxyService = proxyService;
- this.ptlAgreementAttributionService = ptlAgreementAttributionService;
- }
- @Override
- public PtlInsAttributionTemplate getByApiTypeAndInsCompanyId(PtlInsAttributionTemplateSaveVo ptlInsAttributionTemplateSaveVo) {
- // 判断保险公司是否存在
- EsmInsCompany esmInsCompany = esmInsCompanyService.isExists(ptlInsAttributionTemplateSaveVo.getInsCompanyId());
- // 查询一个保险公司,一种api方式是否只有一种配置
- LambdaQueryWrapper<PtlInsAttributionTemplate> wrapper = byInsCompanyIdAndApiType(ptlInsAttributionTemplateSaveVo.getInsCompanyId(), ptlInsAttributionTemplateSaveVo.getApiType());
- List<PtlInsAttributionTemplate> list = list(wrapper);
- if (!list.isEmpty()) {
- throw new SystemException("一个保险公司,一种api方式只能配置一种");
- }
- return new PtlInsAttributionTemplate(ptlInsAttributionTemplateSaveVo, esmInsCompany.getNamesimple());
- }
- @Override
- @Transactional
- public HttpResult<Object> submit(PtlInsAttributionTemplateSaveVo ptlInsAttributionTemplateSaveVo) {
- // 一个保险公司,一种api方式只能配置一种
- PtlInsAttributionTemplate ptlInsAttributionTemplate = proxyService.getByApiTypeAndInsCompanyId(ptlInsAttributionTemplateSaveVo);
- boolean save = save(ptlInsAttributionTemplate);
- AssertionUtils.isSucceed(save, "保险公司归属信息模板添加失败");
- // 保存请求链接
- if (PtlApiType.PTL_API_2.getCode() == ptlInsAttributionTemplateSaveVo.getApiType()) {
- List<PtlCrawlerApi> ptlCrawlerApiList = PtlCrawlerApi.toPtlCrawlerApiList(ptlInsAttributionTemplate.getId(), ptlInsAttributionTemplateSaveVo.getApi());
- boolean b = ptlCrawlerApiService.saveBatch(ptlCrawlerApiList);
- AssertionUtils.isSucceed(b, "保险公司api请求插入失败");
- }
- return HttpResult.ok("添加成功");
- }
- @Override
- public HttpResult<PtlInsAttributionTemplateQueryDto> getByIdObtain(String id) {
- PtlInsAttributionTemplate ptlInsAttributionTemplate = getById(id);
- PtlInsAttributionTemplateQueryDto ptlInsAttributionTemplateQueryDto = new PtlInsAttributionTemplateQueryDto();
- BeanUtils.copyProperties(ptlInsAttributionTemplate, ptlInsAttributionTemplateQueryDto);
- if (PtlApiType.PTL_API_2.getCode() == ptlInsAttributionTemplate.getApiType()) {
- List<PtlCrawlerApi> ptlCrawlerApiList = ptlCrawlerApiService.getByTemplateIdList(id);
- ptlInsAttributionTemplateQueryDto.setApi(ptlCrawlerApiList);
- }
- return HttpResult.ok(ptlInsAttributionTemplateQueryDto);
- }
- @Override
- public HttpResult<BasePageResult<PtlInsAttributionTemplate>> getAll(PtlInsAttributionTemplateQueryVo queryVo) {
- Page<PtlInsAttributionTemplate> pageQuery = new Page<>(queryVo.getPageNum(), queryVo.getPageSize());
- LambdaQueryWrapper<PtlInsAttributionTemplate> queryWrapper = new LambdaQueryWrapper<PtlInsAttributionTemplate>()
- .eq(!StringUtils.isNullOrEmpty(queryVo.getInsCompanyId()), PtlInsAttributionTemplate::getInsCompanyId, queryVo.getInsCompanyId())
- .eq(!StringUtils.isNullOrEmpty(queryVo.getApiType()), PtlInsAttributionTemplate::getApiType, queryVo.getApiType());
- Page<PtlInsAttributionTemplate> page = page(pageQuery, queryWrapper);
- BasePageResult<PtlInsAttributionTemplate> pageResult = new BasePageResult<>(queryVo.getPageNum(), page.getSize(), page.getTotal(), page.getPages(), page.getRecords());
- return HttpResult.ok("succeed", pageResult);
- }
- @Override
- public HttpResult<Object> deleteById(String id) {
- boolean b = removeById(id);
- LambdaQueryWrapper<PtlCrawlerApi> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(PtlCrawlerApi::getTemplateId, id);
- ptlCrawlerApiService.remove(wrapper);
- AssertionUtils.isSucceed(b, "保险公司归属信息模板删除失败");
- return HttpResult.ok("删除成功");
- }
- @Override
- public HttpResult<Object> revise(String id, PtlInsAttributionTemplateSaveVo ptlInsAttributionTemplateSaveVo) {
- // 判断保险公司是否存在
- EsmInsCompany esmInsCompany = esmInsCompanyService.isExists(ptlInsAttributionTemplateSaveVo.getInsCompanyId());
- PtlInsAttributionTemplate ptlInsAttributionTemplate = new PtlInsAttributionTemplate(ptlInsAttributionTemplateSaveVo, esmInsCompany.getNamesimple());
- ptlInsAttributionTemplate.setId(id);
- LambdaQueryWrapper<PtlInsAttributionTemplate> wrapper = byInsCompanyIdAndApiType(ptlInsAttributionTemplateSaveVo.getInsCompanyId(), ptlInsAttributionTemplateSaveVo.getApiType());
- PtlInsAttributionTemplate ptlInsAttributionTemplateOne = getOne(wrapper);
- if (!ObjectUtils.isEmpty(ptlInsAttributionTemplateOne) && !Objects.equals(ptlInsAttributionTemplateOne.getId(), id)) {
- throw new SystemException("一个保险公司,一种api方式只能配置一种");
- }
- if (PtlApiType.PTL_API_2.getCode() == ptlInsAttributionTemplateSaveVo.getApiType()) {
- LambdaQueryWrapper<PtlCrawlerApi> crawlerApiWrapper = new LambdaQueryWrapper<>();
- crawlerApiWrapper.eq(PtlCrawlerApi::getTemplateId, ptlInsAttributionTemplate.getId());
- ptlCrawlerApiService.remove(crawlerApiWrapper);
- // 保存请求链接
- List<PtlCrawlerApi> ptlCrawlerApiList = PtlCrawlerApi.toPtlCrawlerApiList(ptlInsAttributionTemplate.getId(), ptlInsAttributionTemplateSaveVo.getApi());
- boolean b = ptlCrawlerApiService.saveBatch(ptlCrawlerApiList);
- AssertionUtils.isSucceed(b, "保险公司api请求插入失败");
- }
- boolean b = updateById(ptlInsAttributionTemplate);
- AssertionUtils.isSucceed(b, "保险公司归属信息模板修改失败");
- return HttpResult.ok("修改成功");
- }
- @Override
- public HttpResult<PtlAgreementAttribution> getPtlInsAttributionTemplate(PtlInsAttributionTemplateVo ptlInsAttributionTemplateVo) {
- String code = "000000";
- String substring = ptlInsAttributionTemplateVo.getInsCompanyId().substring(0, 5);
- String companyId = substring + code;
- LambdaQueryWrapper<PtlAgreementAttribution> wrapper = byInsCompanyIdAndApiTypeAndAgreementId(ptlInsAttributionTemplateVo.getAgreementId(),companyId, ptlInsAttributionTemplateVo.getApiType());
- PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getOne(wrapper);
- if(ObjectUtils.isEmpty(ptlAgreementAttribution)) {
- PtlInsAttributionTemplate ptlInsAttributionTemplate = lambdaQuery().eq(PtlInsAttributionTemplate::getInsCompanyId, companyId)
- .eq(PtlInsAttributionTemplate::getApiType, ptlInsAttributionTemplateVo.getApiType())
- .one();
- AssertionUtils.isEmpty(ptlInsAttributionTemplate, "保险公司归属信息模板查询失败");
- ptlAgreementAttribution = new PtlAgreementAttribution( ptlInsAttributionTemplate);
- }
- return HttpResult.ok(ptlAgreementAttribution);
- }
- private LambdaQueryWrapper<PtlInsAttributionTemplate> byInsCompanyIdAndApiType(String insCompanyId, Integer apiType) {
- LambdaQueryWrapper<PtlInsAttributionTemplate> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(PtlInsAttributionTemplate::getInsCompanyId, insCompanyId)
- .eq(PtlInsAttributionTemplate::getApiType, apiType);
- return wrapper;
- }
- private LambdaQueryWrapper<PtlAgreementAttribution> byInsCompanyIdAndApiTypeAndAgreementId(String agreementId, String insCompanyId, Integer apiType) {
- LambdaQueryWrapper<PtlAgreementAttribution> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(PtlAgreementAttribution::getId, agreementId)
- .eq(PtlAgreementAttribution::getInsCompanyId, insCompanyId)
- .eq(PtlAgreementAttribution::getApiType, apiType);
- return wrapper;
- }
- }
|