|
|
@@ -0,0 +1,211 @@
|
|
|
+package com.jzg.organization.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.constants.Constants;
|
|
|
+import com.jzg.commons.constants.ReturnInformation;
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
+import com.jzg.commons.entity.dto.*;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementCostExternal;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementCostExternalType;
|
|
|
+import com.jzg.commons.entity.vo.CostExternalVo;
|
|
|
+import com.jzg.commons.exception.SystemException;
|
|
|
+import com.jzg.commons.util.DateTimeUtils;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementCostExternalMapper;
|
|
|
+import com.jzg.organization.service.PtlAgreementCostExternalService;
|
|
|
+import com.jzg.organization.service.PtlAgreementCostExternalTypeService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PtlAgreementCostExternalServiceImpl extends ServiceImpl<PtlAgreementCostExternalMapper, PtlAgreementCostExternal> implements PtlAgreementCostExternalService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PtlAgreementCostExternalTypeService ptlAgreementCostExternalTypeService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public HttpResult save(CostExternalAdd costExternalAdd) {
|
|
|
+ try {
|
|
|
+ if (verifyAgreementCostExternal(costExternalAdd.getContactPerson(), costExternalAdd.getContactMobile(),null)){
|
|
|
+ throw new SystemException("对接人姓名和对接人手机号已存在");
|
|
|
+ }
|
|
|
+ costExternalAdd.getPtlAgreementCostExternalAddList().forEach(ptlAgreementCostExternalAdd -> {
|
|
|
+ ptlAgreementCostExternalAdd.setPtlAgreementId(costExternalAdd.getPtlAgreementId());
|
|
|
+ ptlAgreementCostExternalAdd.setContactPerson(costExternalAdd.getContactPerson());
|
|
|
+ ptlAgreementCostExternalAdd.setContactMobile(costExternalAdd.getContactMobile());
|
|
|
+ PtlAgreementCostExternal ptlAgreementCostExternal = BeanUtil.copyProperties(ptlAgreementCostExternalAdd, PtlAgreementCostExternal.class);
|
|
|
+ if (baseMapper.insert(ptlAgreementCostExternal) <= 0) {
|
|
|
+ throw new SystemException(ReturnInformation.FAILURE_MESSAGE);
|
|
|
+ }
|
|
|
+ saveOrUpdate(ptlAgreementCostExternalAdd.getCostExternalTypeAdds(), ptlAgreementCostExternal.getId());
|
|
|
+
|
|
|
+ });
|
|
|
+ return HttpResult.ok(ReturnInformation.SUCCESS_MESSAGE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存失败: ", e);
|
|
|
+ return HttpResult.error(ReturnInformation.FAILURE_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean verifyAgreementCostExternal(String contactPerson, String contactMobile,List<String> ids) {
|
|
|
+ if (baseMapper.selectCount(new LambdaQueryWrapper<>(PtlAgreementCostExternal.class)
|
|
|
+ .eq(PtlAgreementCostExternal::getContactPerson, contactPerson)
|
|
|
+ .eq(PtlAgreementCostExternal::getContactMobile, contactMobile)
|
|
|
+ .eq(PtlAgreementCostExternal::getIsDelete, Constants.NOT_DELETED)
|
|
|
+ .notIn(CollectionUtils.isNotEmpty(ids),PtlAgreementCostExternal::getId, ids) ) > 0 ){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult getById(Long id) {
|
|
|
+ return HttpResult.ok(baseMapper.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult updateById(PtlAgreementCostExternalEnd costExternalEnd) {
|
|
|
+ try {
|
|
|
+// ArrayList<String> list = new ArrayList<>();
|
|
|
+// list.add(costExternalEnd.getId());
|
|
|
+// if (verifyAgreementCostExternal(costExternalEnd.getContactPerson(), costExternalEnd.getContactMobile(),list)){
|
|
|
+// return HttpResult.error("对接人姓名和对接人手机号已存在");
|
|
|
+// }
|
|
|
+ PtlAgreementCostExternal ptlAgreementCostExternal = BeanUtil.copyProperties(costExternalEnd, PtlAgreementCostExternal.class);
|
|
|
+ if (baseMapper.updateById(ptlAgreementCostExternal) <= 0) {
|
|
|
+ return HttpResult.error(ReturnInformation.UPDATE_FAILED);
|
|
|
+ }
|
|
|
+ saveOrUpdate(costExternalEnd.getCostExternalTypeAdds(), ptlAgreementCostExternal.getId());
|
|
|
+ return HttpResult.ok(ReturnInformation.UPDATE_SUCCESS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存失败: ", e);
|
|
|
+ return HttpResult.error(ReturnInformation.UPDATE_FAILED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void saveOrUpdate(List<?> list, Long id) {
|
|
|
+ try {
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ ptlAgreementCostExternalTypeService.deleteByPtlAgreementCostExternalId(id);
|
|
|
+ List<PtlAgreementCostExternalType> ptlAgreementCostExternalTypes = BeanUtil.copyToList(list, PtlAgreementCostExternalType.class);
|
|
|
+ ptlAgreementCostExternalTypes.forEach(ptlAgreementCostExternalTypeAdd -> {
|
|
|
+ ptlAgreementCostExternalTypeAdd.setPtlAgreementCostExternalId(id);
|
|
|
+ });
|
|
|
+ ptlAgreementCostExternalTypeService.saveBatch(ptlAgreementCostExternalTypes);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录日志
|
|
|
+ log.error("保存或更新失败: ", e);
|
|
|
+ throw new SystemException("保存或更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult costExternalList(CostExternalParam costExternalParam) {
|
|
|
+ List<CostExternalVo> costExternalVo = baseMapper.costExternalList(costExternalParam);
|
|
|
+ if (CollectionUtils.isNotEmpty(costExternalVo)) {
|
|
|
+ costExternalVo.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .flatMap(vo -> Optional.ofNullable(vo.getCostExternalListVo()).orElse(Collections.emptyList()).stream())
|
|
|
+ .forEach(costExternalListVo ->
|
|
|
+ costExternalListVo.setEffective(DateTimeUtils.isCurrentTimeAfter(costExternalListVo.getFailureTime()))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return HttpResult.ok(costExternalVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult enableDisableByIds(List<String> ids,Boolean isEnabled) {
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(ids)){
|
|
|
+ return HttpResult.error("参数不能为空");
|
|
|
+ }
|
|
|
+ PtlAgreementCostExternal ptlAgreementCostExternal = new PtlAgreementCostExternal();
|
|
|
+ ptlAgreementCostExternal.setIsEnabled(isEnabled ? 0 : 1);
|
|
|
+ return baseMapper.update(ptlAgreementCostExternal,new LambdaQueryWrapper<>(PtlAgreementCostExternal.class)
|
|
|
+ .in(PtlAgreementCostExternal::getId,ids)) > 0 ?
|
|
|
+ HttpResult.ok(isEnabled ? "启用成功" : "禁用成功") : HttpResult.error(isEnabled ? "启用失败" : "禁用失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult pageList(CostExternalPageParam pageParam) {
|
|
|
+ return HttpResult.ok(baseMapper.pageList(pageParam.getPage(),pageParam));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult updateList(CostExternalEnd costExternalEnd) {
|
|
|
+ try {
|
|
|
+ List<String> collect = costExternalEnd.getPtlAgreementCostExternalAddList().stream().map(PtlAgreementCostExternalEnd::getId).collect(Collectors.toList());
|
|
|
+ if (verifyAgreementCostExternal(costExternalEnd.getContactPerson(), costExternalEnd.getContactMobile(),collect)){
|
|
|
+ throw new SystemException("对接人姓名和对接人手机号已存在");
|
|
|
+ }
|
|
|
+ costExternalEnd.getPtlAgreementCostExternalAddList().forEach(agreementCostExternalEnd -> {
|
|
|
+ agreementCostExternalEnd.setPtlAgreementId(costExternalEnd.getPtlAgreementId());
|
|
|
+ agreementCostExternalEnd.setContactPerson(costExternalEnd.getContactPerson());
|
|
|
+ agreementCostExternalEnd.setContactMobile(costExternalEnd.getContactMobile());
|
|
|
+ PtlAgreementCostExternal ptlAgreementCostExternal = BeanUtil.copyProperties(agreementCostExternalEnd, PtlAgreementCostExternal.class);
|
|
|
+ if (!baseMapper.insertOrUpdate(ptlAgreementCostExternal)) {
|
|
|
+ throw new SystemException(ReturnInformation.FAILURE_MESSAGE);
|
|
|
+ }
|
|
|
+ saveOrUpdate(agreementCostExternalEnd.getCostExternalTypeAdds(), ptlAgreementCostExternal.getId());
|
|
|
+ });
|
|
|
+ return HttpResult.ok(ReturnInformation.SUCCESS_MESSAGE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存失败: ", e);
|
|
|
+ return HttpResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult selectByAgreementIdAll(CostExternalParam costExternalParam) {
|
|
|
+ if (costExternalParam.getPtlAgreementId() == null){
|
|
|
+ return HttpResult.error("协议ID不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(costExternalParam.getContactPerson())){
|
|
|
+ return HttpResult.error("对接人姓名不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(costExternalParam.getContactMobile())){
|
|
|
+ return HttpResult.error("对接人手机号不能为空");
|
|
|
+ }
|
|
|
+ return HttpResult.ok(baseMapper.selectByAgreementIdAll(costExternalParam));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult deleteByPtlAgreementIdAndMobile(CostExternalDeleteParam costExternalDeleteParam) {
|
|
|
+ return baseMapper.delete(new LambdaQueryWrapper<>(PtlAgreementCostExternal.class).eq(PtlAgreementCostExternal::getPtlAgreementId,costExternalDeleteParam.getPtlAgreementId() )
|
|
|
+ .eq(PtlAgreementCostExternal::getContactMobile,costExternalDeleteParam.getContactMobile())) > 0 ? HttpResult.ok(ReturnInformation.DELETE_SUCCESS) : HttpResult.error(ReturnInformation.DELETE_FAILED);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult approvalMethodAll(List<String> ids, int auditMethod) {
|
|
|
+ PtlAgreementCostExternal ptlAgreementCostExternal = new PtlAgreementCostExternal();
|
|
|
+ ptlAgreementCostExternal.setAuditMethod(auditMethod);
|
|
|
+ return baseMapper.update(ptlAgreementCostExternal,new LambdaQueryWrapper<>(PtlAgreementCostExternal.class)
|
|
|
+ .in(PtlAgreementCostExternal::getId,ids)) > 0 ?
|
|
|
+ HttpResult.ok(ReturnInformation.UPDATE_SUCCESS) : HttpResult.error(ReturnInformation.UPDATE_FAILED);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|