|
|
@@ -0,0 +1,160 @@
|
|
|
+package com.jzg.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+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.jzg.commons.core.page.HttpResult;
|
|
|
+import com.jzg.commons.entity.agreement.po.PtlAgreementAttribution;
|
|
|
+import com.jzg.commons.entity.agreement.po.PtlAgreementUrl;
|
|
|
+import com.jzg.commons.entity.agreement.po.PtlInsAttributionTemplate;
|
|
|
+import com.jzg.commons.entity.agreement.vo.PtlAgreementAttributionQueryVo;
|
|
|
+import com.jzg.commons.entity.agreement.vo.PtlAgreementAttributionSaveVo;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
+import com.jzg.commons.entity.po.SysDept;
|
|
|
+import com.jzg.commons.exception.SystemException;
|
|
|
+import com.jzg.mapper.PtlAgreementAttributionMapper;
|
|
|
+import com.jzg.organization.service.PtlAgreementService;
|
|
|
+import com.jzg.service.PtlAgreementAttributionService;
|
|
|
+import com.jzg.service.PtlAgreementUrlService;
|
|
|
+import com.jzg.service.PtlInsAttributionTemplateService;
|
|
|
+import com.jzg.service.SysDeptService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author quchen
|
|
|
+ * @date 2025/2/18 17:07
|
|
|
+ */
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PtlAgreementAttributionImpl extends ServiceImpl<PtlAgreementAttributionMapper, PtlAgreementAttribution> implements PtlAgreementAttributionService {
|
|
|
+ @Resource
|
|
|
+ private PtlInsAttributionTemplateService ptlInsAttributionTemplateService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PtlAgreementAttributionService ptlAgreementAttributionService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PtlAgreementUrlService ptlAgreementUrlService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PtlAgreementService ptlAgreementService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptService sysDeptService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addAgreementAttribution(PtlAgreementAttributionSaveVo ptlAgreementAttributionSaveVo) {
|
|
|
+ PtlInsAttributionTemplate ptlInsAttributionTemplate = ptlInsAttributionTemplateService.getByCompanyId(ptlAgreementAttributionSaveVo.getInsCompanyId());
|
|
|
+ if (ptlInsAttributionTemplate == null) {
|
|
|
+ throw new RuntimeException("该保险公司模版不存在");
|
|
|
+ }
|
|
|
+ verifyAgreeAttribution(ptlAgreementAttributionSaveVo.getUserDept(),ptlAgreementAttributionSaveVo.getUsername());
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = new PtlAgreementAttribution(ptlAgreementAttributionSaveVo,ptlInsAttributionTemplate);
|
|
|
+ save(ptlAgreementAttribution);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult<Object> getAgreementAttribution(String id) {
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = baseMapper.getAgreementAttribution(id);
|
|
|
+ if (Objects.isNull(ptlAgreementAttribution)) {
|
|
|
+ throw new RuntimeException("该保险公司账号不存在");
|
|
|
+ }
|
|
|
+// PtlInsAttributionTemplate ptlInsAttributionTemplate = ptlInsAttributionTemplateService.lambdaQuery()
|
|
|
+// .eq(PtlInsAttributionTemplate::getInsCompanyId, ptlAgreementAttribution.getInsCompanyId())
|
|
|
+// .one();
|
|
|
+// PtlAgreementAttribution.filterTemplates(ptlAgreementAttribution,ptlInsAttributionTemplate);
|
|
|
+ return HttpResult.ok("",ptlAgreementAttribution);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PtlAgreementAttribution> getAgreementAttributionList(Page page, PtlAgreementAttributionQueryVo ptlAgreementAttributionQueryVo) {
|
|
|
+ return baseMapper.getAgreementAttributionList(page,ptlAgreementAttributionQueryVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateAgreementAttribution(PtlAgreementAttributionSaveVo ptlAgreementAttributionSaveVo) {
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(ptlAgreementAttributionSaveVo.getId());
|
|
|
+ if (Objects.isNull(ptlAgreementAttribution)) {
|
|
|
+ throw new RuntimeException("该保险公司账号不存在");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(ptlAgreementAttributionSaveVo,ptlAgreementAttribution);
|
|
|
+ ptlAgreementAttribution.setFields(JSONArray.parseArray(JSON.toJSONString(ptlAgreementAttributionSaveVo.getFields())));
|
|
|
+ updateById(ptlAgreementAttribution);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PtlAgreementUrl> getAgreementUrlList(String companyId) {
|
|
|
+ LambdaQueryWrapper<PtlAgreementUrl> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PtlAgreementUrl::getCompanyId, companyId);
|
|
|
+ return ptlAgreementUrlService.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean deleteAgreementAttribution(List<String> ids) {
|
|
|
+ for (String id : ids) {
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(id);
|
|
|
+ if (Objects.isNull(ptlAgreementAttribution)) {
|
|
|
+ throw new RuntimeException("该保险公司账号不存在");
|
|
|
+ }
|
|
|
+ List<PtlAgreement> ptlAgreements = ptlAgreementService.lambdaQuery()
|
|
|
+ .eq(PtlAgreement::getAttributionId, id)
|
|
|
+ .list();
|
|
|
+ if (!ptlAgreements.isEmpty()) {
|
|
|
+ throw new SystemException("当前账号有部分报价协议,请更换协议的账号后,再进行删除");
|
|
|
+ }
|
|
|
+ ptlAgreementAttribution.setIsDelete("1");
|
|
|
+ ptlAgreementAttributionService.updateById(ptlAgreementAttribution);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean enableAgreementAttribution(List<String> ids) {
|
|
|
+ return updateQuoteStatus(ids,"0");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean disableAgreementAttribution(List<String> ids) {
|
|
|
+ return updateQuoteStatus(ids,"1");
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean updateQuoteStatus(List<String> ids, String status) {
|
|
|
+ for (String id : ids) {
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.getById(id);
|
|
|
+ if (Objects.isNull(ptlAgreementAttribution)) {
|
|
|
+ throw new RuntimeException("该保险公司账号不存在");
|
|
|
+ }
|
|
|
+ ptlAgreementAttribution.setQuoteStatus(status);
|
|
|
+ ptlAgreementAttributionService.updateById(ptlAgreementAttribution);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void verifyAgreeAttribution(String userDept,String username) {
|
|
|
+ SysDept sysDept = sysDeptService.getById(userDept);
|
|
|
+ if (Objects.isNull(sysDept)) {
|
|
|
+ throw new SystemException("归属不存在,请重新选择");
|
|
|
+ }
|
|
|
+ PtlAgreementAttribution ptlAgreementAttribution = ptlAgreementAttributionService.lambdaQuery()
|
|
|
+ .eq(PtlAgreementAttribution::getUserDept, userDept)
|
|
|
+ .eq(PtlAgreementAttribution::getUsername, username)
|
|
|
+ .eq(PtlAgreementAttribution::getIsDelete, "0")
|
|
|
+ .one();
|
|
|
+ if (!Objects.isNull(ptlAgreementAttribution)) {
|
|
|
+ throw new SystemException("该归属下账号已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|