|
|
@@ -0,0 +1,222 @@
|
|
|
+package com.jzg.organization.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+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.base.BaseController;
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
+import com.jzg.commons.entity.dto.AgreementAddParam;
|
|
|
+import com.jzg.commons.entity.dto.AgreementAuthParam;
|
|
|
+import com.jzg.commons.entity.dto.AgreementEditParam;
|
|
|
+import com.jzg.commons.entity.dto.AgreementParam;
|
|
|
+import com.jzg.commons.entity.enums.YesNoEnum;
|
|
|
+import com.jzg.commons.entity.po.EsmInsCompany;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementDept;
|
|
|
+import com.jzg.commons.entity.po.SysSystem;
|
|
|
+import com.jzg.commons.entity.vo.AgreementInfoVo;
|
|
|
+import com.jzg.commons.entity.vo.AgreementUserVo;
|
|
|
+import com.jzg.commons.entity.vo.AgreementVo;
|
|
|
+import com.jzg.commons.entity.vo.UpAndDownVo;
|
|
|
+import com.jzg.commons.exception.SystemException;
|
|
|
+import com.jzg.commons.util.MinioUtils;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
+import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
+import com.jzg.commons.util.idgen.IdWorker;
|
|
|
+import com.jzg.organization.client.EsmInsCompanyClient;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementMapper;
|
|
|
+import com.jzg.organization.mapper.SysUserMapper;
|
|
|
+import com.jzg.organization.service.PtlAgreementDeptService;
|
|
|
+import com.jzg.organization.service.PtlAgreementService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+* @author dongxin
|
|
|
+* @description 针对表【ptl_agreement(协议信息表)】的数据库操作Service实现
|
|
|
+* @createDate 2025-02-18 10:49:25
|
|
|
+*/
|
|
|
+@Service
|
|
|
+public class PtlAgreementServiceImpl extends ServiceImpl<PtlAgreementMapper, PtlAgreement>
|
|
|
+ implements PtlAgreementService {
|
|
|
+
|
|
|
+ @Value("${minio.bucket-name}")
|
|
|
+ private String bucketName;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementDeptService agreementDeptService;
|
|
|
+
|
|
|
+ @Qualifier("baseController")
|
|
|
+ @Autowired
|
|
|
+ private BaseController baseController;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EsmInsCompanyClient companyClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper userMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AgreementVo> queryPage(AgreementParam param) {
|
|
|
+ Page<AgreementVo> page = baseMapper.queryPage(param.getPage(), param);
|
|
|
+ List<AgreementVo> agreementVos = page.getRecords();
|
|
|
+ if(CollUtil.isNotEmpty(agreementVos)){
|
|
|
+ for (AgreementVo agreementVo : agreementVos) {
|
|
|
+ // 获取文件外链地址
|
|
|
+ String fileUrl = MinioUtils.getPresignedObjectUrl(bucketName,agreementVo.getFileName());
|
|
|
+ agreementVo.setFileUrl(fileUrl);
|
|
|
+ LocalDateTime startDate = agreementVo.getStartDate();
|
|
|
+ LocalDateTime endDate = agreementVo.getEndDate();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ PtlAgreement agreement = new PtlAgreement();
|
|
|
+ agreement.setId(agreementVo.getId());
|
|
|
+ //更新是否有效
|
|
|
+ if (now.isEqual(startDate) || (now.isAfter(startDate) && now.isBefore(endDate))) {
|
|
|
+ agreement.setValidStatus("0");
|
|
|
+ } else {
|
|
|
+ agreement.setValidStatus("1");
|
|
|
+ }
|
|
|
+ updateById(agreement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AgreementInfoVo queryById(String id) {
|
|
|
+ AgreementVo agreementVo = this.isExistById(id);
|
|
|
+
|
|
|
+ // 获取协议授权
|
|
|
+ List<PtlAgreementDept> deptList = agreementDeptService.getByAgreementId(id);
|
|
|
+ AgreementInfoVo agreementInfoVo = new AgreementInfoVo(agreementVo,deptList);
|
|
|
+ return agreementInfoVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AgreementVo isExistById(String id) {
|
|
|
+ AgreementVo agreementVo = baseMapper.queryById(id);
|
|
|
+ if (ObjectUtils.isEmpty(agreementVo)) {
|
|
|
+ throw new SystemException("协议id不存在!");
|
|
|
+ }
|
|
|
+ return agreementVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isExistsName(String agreementTitle, String id) {
|
|
|
+ long count = this.count(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
+ .eq(PtlAgreement::getAgreementTitle, agreementTitle)
|
|
|
+ .ne(StringUtils.isNotNull(id),PtlAgreement::getId, id)
|
|
|
+ );
|
|
|
+ return count > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void agreementAdd(AgreementAddParam param) {
|
|
|
+ PtlAgreement ptlAgreement = new PtlAgreement();
|
|
|
+ BeanUtils.copyProperties(param,ptlAgreement);
|
|
|
+ String sysCode = baseController.getUserSystemCode();
|
|
|
+
|
|
|
+ // 获取保险公司信息
|
|
|
+ HttpResult<EsmInsCompany> result = companyClient.findById(param.getCompanyId());
|
|
|
+ String companyCode = "";
|
|
|
+ if(result.getCode() == 200 && Objects.nonNull(result.getData())){
|
|
|
+ companyCode = result.getData().getCompanyCode();
|
|
|
+ }else{
|
|
|
+ throw new SystemException("无法获取到保险公司信息");
|
|
|
+ }
|
|
|
+ // code生成规则 系统code + 保险公司code + 时间戳
|
|
|
+ ptlAgreement.setAgreementCode(sysCode + companyCode + +System.currentTimeMillis());
|
|
|
+ ptlAgreement.setSerialNumber(0);
|
|
|
+ ptlAgreement.setIsExternal(0);
|
|
|
+ ptlAgreement.setIsEnable(YesNoEnum.NO.getCode()); // 启用
|
|
|
+
|
|
|
+ // 判断生效状态
|
|
|
+ LocalDateTime startDate = param.getStartDate();
|
|
|
+ LocalDateTime endDate = param.getEndDate();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //更新是否有效
|
|
|
+ if (now.isEqual(startDate) || (now.isAfter(startDate) && now.isBefore(endDate))) {
|
|
|
+ ptlAgreement.setValidStatus("0");
|
|
|
+ } else {
|
|
|
+ ptlAgreement.setValidStatus("1");
|
|
|
+ }
|
|
|
+ save(ptlAgreement);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void agreementEdit(AgreementEditParam param) {
|
|
|
+ PtlAgreement ptlAgreement = new PtlAgreement();
|
|
|
+ BeanUtils.copyProperties(param,ptlAgreement);
|
|
|
+ // 判断生效状态
|
|
|
+ LocalDateTime startDate = param.getStartDate();
|
|
|
+ LocalDateTime endDate = param.getEndDate();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //更新是否有效
|
|
|
+ if (now.isEqual(startDate) || (now.isAfter(startDate) && now.isBefore(endDate))) {
|
|
|
+ ptlAgreement.setValidStatus("0");
|
|
|
+ } else {
|
|
|
+ ptlAgreement.setValidStatus("1");
|
|
|
+ }
|
|
|
+ updateById(ptlAgreement);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AgreementUserVo> getUserByDeptId(String deptId) {
|
|
|
+ List<AgreementUserVo> userVoList = userMapper.getUserByDeptId(deptId);
|
|
|
+ return userVoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteByIds(List<String> ids) {
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upAndDown(UpAndDownVo upAndDownVo) {
|
|
|
+ if(YesNoEnum.YES.equals(upAndDownVo.getOpType())) {
|
|
|
+ upAndDownVo.getIds().forEach(id->{
|
|
|
+ reDeploy(Convert.toStr(id));
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ upAndDownVo.getIds().forEach(id->{
|
|
|
+ unDeploy(Convert.toStr(id));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unDeploy(String id) {
|
|
|
+ PtlAgreement agreement = new PtlAgreement();
|
|
|
+ agreement.setId(id);
|
|
|
+ agreement.setIsEnable(YesNoEnum.NO.getCode());
|
|
|
+ baseMapper.updateById(agreement);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reDeploy(String id) {
|
|
|
+ PtlAgreement agreement = new PtlAgreement();
|
|
|
+ agreement.setId(id);
|
|
|
+ agreement.setIsEnable(YesNoEnum.YES.getCode());
|
|
|
+ baseMapper.updateById(agreement);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|