|
|
@@ -0,0 +1,312 @@
|
|
|
+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.exception.SystemException;
|
|
|
+import com.ydtech.modules.base.controller.BaseController;
|
|
|
+import com.ydtech.modules.order.entity.BasePageResult;
|
|
|
+import com.ydtech.modules.protocol.dao.PtlAgreementGroupLinkAgreementMapper;
|
|
|
+import com.ydtech.modules.protocol.dao.PtlAgreementGroupMapper;
|
|
|
+import com.ydtech.modules.protocol.entity.dto.PtlAgreementGroupDto;
|
|
|
+import com.ydtech.modules.protocol.entity.dto.PtlAgreementGroupLinkAgreementDto;
|
|
|
+import com.ydtech.modules.protocol.entity.po.*;
|
|
|
+import com.ydtech.modules.protocol.entity.vo.*;
|
|
|
+import com.ydtech.modules.protocol.service.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Administrator
|
|
|
+ * @description 针对表【ptl_agreement_group(协议组)】的数据库操作Service实现
|
|
|
+ * @createDate 2024-10-24 09:54:37
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PtlAgreementGroupServiceImpl extends ServiceImpl<PtlAgreementGroupMapper, PtlAgreementGroups>
|
|
|
+ implements PtlAgreementGroupService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupMapper ptlAgreementGroupMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupLinkAgreementMapper ptlAgreementGroupLinkAgreementMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupLinkAgreementService ptlAgreementGroupLinkAgreementService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupLinkAgreementRecordService ptlAgreementGroupLinkAgreementRecordService;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupLinkDeptService ptlAgreementGroupLinkDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementGroupLinkDeptRecordService ptlAgreementGroupLinkDeptRecordService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 10:56
|
|
|
+ * @Description: 分页查询
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BasePageResult<PtlAgreementGroupDto> queryPage(PtlAgreementGroupVo ptlAgreementGroupVo) {
|
|
|
+ Page<PtlAgreementGroupDto> page = new Page<>(ptlAgreementGroupVo.getPageNum(),
|
|
|
+ ptlAgreementGroupVo.getPageSize());
|
|
|
+ Page<PtlAgreementGroupDto> pageResult = ptlAgreementGroupMapper.queryPage(page, ptlAgreementGroupVo);
|
|
|
+ return new BasePageResult<>(ptlAgreementGroupVo.getPageNum(), page.getSize(), pageResult.getTotal(), page.getPages(),
|
|
|
+ pageResult.getRecords());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 11:30
|
|
|
+ * @Description: 新增或者修改
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addOrUpdate(PtlAgreementGroupAddVo ptlAgreementGroupAddVo) {
|
|
|
+ //判断有没有默认的数据,没有必须先添加
|
|
|
+ PtlAgreementGroups defaultFlagGroup = this.findByDefaultFlag(ptlAgreementGroupAddVo.getId());
|
|
|
+ if(ptlAgreementGroupAddVo.getId()==null){
|
|
|
+ //如果非默认必须先添加默认
|
|
|
+ if(ptlAgreementGroupAddVo.getDefaultFlag()==0 && defaultFlagGroup ==null){
|
|
|
+ throw new SystemException("不存在默认协议组先添加默认协议组!!");
|
|
|
+ }else if(ptlAgreementGroupAddVo.getDefaultFlag()==1 && defaultFlagGroup!=null){
|
|
|
+ if(Objects.equals(defaultFlagGroup.getId(), ptlAgreementGroupAddVo.getId() == null ? 0L : ptlAgreementGroupAddVo.getId())){
|
|
|
+ throw new SystemException("默认协议组不允许修改!!");
|
|
|
+ }else{
|
|
|
+ throw new SystemException("已存在默认协议组不允许添加!!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(Objects.equals(defaultFlagGroup.getId(), ptlAgreementGroupAddVo.getId() == null ? 0L : ptlAgreementGroupAddVo.getId())){
|
|
|
+ throw new SystemException("默认协议组不允许修改!!");
|
|
|
+ }else{
|
|
|
+ if(ptlAgreementGroupAddVo.getDefaultFlag()==1){
|
|
|
+ throw new SystemException("非默认协议组不允许修改为默认!!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询协议组名称是否存在
|
|
|
+ PtlAgreementGroups groupNames = this.findByName(ptlAgreementGroupAddVo.getAgreementGroupName(),ptlAgreementGroupAddVo.getId());
|
|
|
+ if(groupNames!=null){
|
|
|
+ throw new SystemException("默认协议组名称已存在不允许添加!!");
|
|
|
+ }
|
|
|
+ PtlAgreementGroups groups = new PtlAgreementGroups();
|
|
|
+ if(ptlAgreementGroupAddVo.getId()==null){
|
|
|
+ BeanUtils.copyProperties(ptlAgreementGroupAddVo, groups);
|
|
|
+ groups.setCreateTime(new Date());
|
|
|
+ groups.setCreateUser(new BaseController().getUserId());
|
|
|
+ groups.setDelFlag(0);
|
|
|
+ //添加
|
|
|
+ this.save(groups);
|
|
|
+ }else{
|
|
|
+ PtlAgreementGroups updateData = this.getById(ptlAgreementGroupAddVo.getId());
|
|
|
+ BeanUtils.copyProperties(ptlAgreementGroupAddVo, updateData);
|
|
|
+ //修改
|
|
|
+ updateData.setUpdateTime(new Date());
|
|
|
+ updateData.setUpdateUser(new BaseController().getUserId());
|
|
|
+ updateData.setDelFlag(0);
|
|
|
+ this.updateById(updateData);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 11:30
|
|
|
+ * @Description: 逻辑删除
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateByIdDelete(Long id) {
|
|
|
+ PtlAgreementGroups defaultFlagGroup = this.getById(id);
|
|
|
+ //如果非默认必须先添加默认
|
|
|
+ if(defaultFlagGroup.getDefaultFlag()==1){
|
|
|
+ throw new SystemException("默认协议组不允许删除");
|
|
|
+ }
|
|
|
+ defaultFlagGroup.setDelFlag(1);
|
|
|
+ //逻辑删除
|
|
|
+ this.updateById(defaultFlagGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 11:39
|
|
|
+ * @Description: 查询默认协议
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PtlAgreementGroups findByDefaultFlag(Long id) {
|
|
|
+ LambdaQueryWrapper<PtlAgreementGroups> infoWapper = new LambdaQueryWrapper<>();
|
|
|
+ if(id!=null){
|
|
|
+ infoWapper.ne(PtlAgreementGroups::getId, id);
|
|
|
+ }
|
|
|
+ infoWapper.eq(PtlAgreementGroups::getDefaultFlag, 1);
|
|
|
+ infoWapper.eq(PtlAgreementGroups::getDelFlag, 0);
|
|
|
+ PtlAgreementGroups group = this.getOne(infoWapper);
|
|
|
+ return group;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 11:39
|
|
|
+ * @Description: 查询默认协议
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PtlAgreementGroups findByName(String name,Long id) {
|
|
|
+ LambdaQueryWrapper<PtlAgreementGroups> infoWapper = new LambdaQueryWrapper<>();
|
|
|
+ if(id!=null){
|
|
|
+ infoWapper.ne(PtlAgreementGroups::getId, id);
|
|
|
+ }
|
|
|
+ infoWapper.eq(PtlAgreementGroups::getAgreementGroupName, name);
|
|
|
+ infoWapper.eq(PtlAgreementGroups::getDelFlag, 0);
|
|
|
+ PtlAgreementGroups group = this.getOne(infoWapper);
|
|
|
+ return group;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 15:18
|
|
|
+ * @Description: 查询可以使用的协议
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BasePageResult<PtlAgreementGroupLinkAgreementDto> findAgreementList(PtlAgreementListVo ptlAgreementListVo) {
|
|
|
+ Page<PtlAgreementGroupLinkAgreementDto> page = new Page<>(ptlAgreementListVo.getPageNum(),
|
|
|
+ ptlAgreementListVo.getPageSize());
|
|
|
+ Page<PtlAgreementGroupLinkAgreementDto> pageResult = ptlAgreementGroupLinkAgreementMapper.queryPage(page, ptlAgreementListVo);
|
|
|
+ return new BasePageResult<>(ptlAgreementListVo.getPageNum(), page.getSize(), pageResult.getTotal(), page.getPages(),
|
|
|
+ pageResult.getRecords());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 15:23
|
|
|
+ * @Description: 保存集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void saveAgreementList(PtlAgreementGroupLinkAgreementAddVo ptlAgreementGroupLinkAgreementAddVo) {
|
|
|
+ //保存协议组关联协议
|
|
|
+ List<Long> oldIds= ptlAgreementGroupLinkAgreementMapper.findByGroupId(ptlAgreementGroupLinkAgreementAddVo.getAgreementGroupId());
|
|
|
+ ArrayList<Long> agreementList = ptlAgreementGroupLinkAgreementAddVo.getAgreementList();
|
|
|
+ if(oldIds!=null && !oldIds.isEmpty() && agreementList!=null && !agreementList.isEmpty()){
|
|
|
+ agreementList.removeAll(oldIds);
|
|
|
+ }
|
|
|
+ //添加
|
|
|
+ List<PtlAgreementGroupLinkAgreement> addList = new ArrayList<PtlAgreementGroupLinkAgreement>();
|
|
|
+ List<PtlAgreementGroupLinkAgreementRecord> addRecordList = new ArrayList<PtlAgreementGroupLinkAgreementRecord>();
|
|
|
+ agreementList.stream().forEach(agreeId -> {
|
|
|
+ PtlAgreementGroupLinkAgreement dto =new PtlAgreementGroupLinkAgreement(null,agreeId,ptlAgreementGroupLinkAgreementAddVo.getAgreementGroupId(),new Date(),new BaseController().getUserId());
|
|
|
+ PtlAgreementGroupLinkAgreementRecord recordDto =new PtlAgreementGroupLinkAgreementRecord(null,agreeId,ptlAgreementGroupLinkAgreementAddVo.getAgreementGroupId(),new Date(),new BaseController().getUserId(),"add");
|
|
|
+ addList.add(dto);
|
|
|
+ addRecordList.add(recordDto);
|
|
|
+ });
|
|
|
+ ptlAgreementGroupLinkAgreementService.saveBatch(addList);
|
|
|
+ ptlAgreementGroupLinkAgreementRecordService.saveBatch(addRecordList);
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 15:24
|
|
|
+ * @Description: 查询协议组关联的协议
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BasePageResult<PtlAgreementGroupLinkAgreementDto> findLinkAgreementList(PtlAgreementGroupLinkAgreementVo ptlAgreementGroupLinkAgreementVo) {
|
|
|
+ Page<PtlAgreementGroupLinkAgreementDto> page = new Page<>(ptlAgreementGroupLinkAgreementVo.getPageNum(),
|
|
|
+ ptlAgreementGroupLinkAgreementVo.getPageSize());
|
|
|
+ Page<PtlAgreementGroupLinkAgreementDto> pageResult = ptlAgreementGroupLinkAgreementMapper.findLinkAgreementList(page, ptlAgreementGroupLinkAgreementVo);
|
|
|
+ return new BasePageResult<>(ptlAgreementGroupLinkAgreementVo.getPageNum(), page.getSize(), pageResult.getTotal(), page.getPages(),
|
|
|
+ pageResult.getRecords());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 15:31
|
|
|
+ * @Description: 删除协议组关联的协议
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteLinkAgreementList(PtlAgreementGroupLinkAgreementDeleteVo ptlAgreementGroupLinkAgreementDeleteVo) {
|
|
|
+ List<PtlAgreementGroupLinkAgreement> deleteList = ptlAgreementGroupLinkAgreementService.findByIds(ptlAgreementGroupLinkAgreementDeleteVo.getIds());
|
|
|
+ List<PtlAgreementGroupLinkAgreementRecord> addRecordList = new ArrayList<PtlAgreementGroupLinkAgreementRecord>();
|
|
|
+ if(deleteList!=null && !deleteList.isEmpty()){
|
|
|
+ deleteList.stream().forEach(agree -> {
|
|
|
+ PtlAgreementGroupLinkAgreementRecord recordDto =new PtlAgreementGroupLinkAgreementRecord(null,agree.getPtlAgreementId(),agree.getPtlAgreementGroupId(),new Date(),new BaseController().getUserId(),"delete");
|
|
|
+ addRecordList.add(recordDto);
|
|
|
+ });
|
|
|
+ ptlAgreementGroupLinkAgreementService.removeByIds(deleteList);
|
|
|
+ ptlAgreementGroupLinkAgreementRecordService.saveBatch(addRecordList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/24 15:24
|
|
|
+ * @Description: 协议授权
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void authorizeDeptList(PtlAgreementGroupLinkDeptAddVo ptlAgreementGroupLinkDeptAddVo) {
|
|
|
+ //通过协议组id查詢到授权的部门删除重新添加
|
|
|
+ // 删除添加
|
|
|
+ ArrayList<PtlAgreementGroupLinkDeptRecord> addRecordList =new ArrayList<PtlAgreementGroupLinkDeptRecord>();
|
|
|
+ ArrayList<PtlAgreementGroupLinkDept> addList =new ArrayList<PtlAgreementGroupLinkDept>();
|
|
|
+ //查询
|
|
|
+ List<PtlAgreementGroupLinkDept> deleteList = ptlAgreementGroupLinkDeptService.findByGroupId(ptlAgreementGroupLinkDeptAddVo.getPtlAgreementGroupId());
|
|
|
+ if(deleteList!=null && !deleteList.isEmpty()){
|
|
|
+ deleteList.stream().forEach(dept -> {
|
|
|
+ PtlAgreementGroupLinkDeptRecord recordDto =new PtlAgreementGroupLinkDeptRecord(null,dept.getPtlAgreementGroupId(),dept.getDeptId(),new Date(),new BaseController().getUserId(),"delete");
|
|
|
+ addRecordList.add(recordDto);
|
|
|
+ });
|
|
|
+ ptlAgreementGroupLinkDeptService.removeByIds(deleteList);
|
|
|
+ }
|
|
|
+ //查询新增的list
|
|
|
+ ArrayList<String> ids = ptlAgreementGroupLinkDeptAddVo.getIds();
|
|
|
+ if(ids!=null && !ids.isEmpty()){
|
|
|
+ ids.stream().forEach(deptId -> {
|
|
|
+ PtlAgreementGroupLinkDept dto =new PtlAgreementGroupLinkDept(null,ptlAgreementGroupLinkDeptAddVo.getPtlAgreementGroupId(),deptId,new Date(),new BaseController().getUserId());
|
|
|
+ PtlAgreementGroupLinkDeptRecord recordDto =new PtlAgreementGroupLinkDeptRecord(null,ptlAgreementGroupLinkDeptAddVo.getPtlAgreementGroupId(),deptId,new Date(),new BaseController().getUserId(),"add");
|
|
|
+ addRecordList.add(recordDto);
|
|
|
+ addList.add(dto);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(addList!=null && !addList.isEmpty()){
|
|
|
+ ptlAgreementGroupLinkDeptService.saveBatch(addList);
|
|
|
+ }
|
|
|
+ if(addRecordList!=null && !addRecordList.isEmpty()){
|
|
|
+ ptlAgreementGroupLinkDeptRecordService.saveBatch(addRecordList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/25 9:59
|
|
|
+ * @Description: 通过协议id查询授权部门ids
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<String> findDeptIdsByPtlAgreementGroupId(Long ptlAgreementGroupId) {
|
|
|
+ ArrayList<String> deptIds =new ArrayList<String>();
|
|
|
+ //查询
|
|
|
+ List<PtlAgreementGroupLinkDept> deleteList = ptlAgreementGroupLinkDeptService.findByGroupId(ptlAgreementGroupId);
|
|
|
+ if(deleteList!=null && !deleteList.isEmpty()){
|
|
|
+ deleteList.stream().forEach(dept -> {
|
|
|
+ deptIds.add(dept.getDeptId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return deptIds;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|