|
|
@@ -0,0 +1,109 @@
|
|
|
+package com.jzg.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.core.base.BaseController;
|
|
|
+import com.jzg.commons.entity.agreement.po.PtlAgreementAttributionDept;
|
|
|
+import com.jzg.commons.entity.agreement.vo.PtlAgreementAttributionDeptListVo;
|
|
|
+import com.jzg.commons.entity.agreement.vo.PtlAgreementAttributionDeptVo;
|
|
|
+import com.jzg.commons.entity.dto.AgreementAuthParam;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementDept;
|
|
|
+import com.jzg.commons.entity.po.SysDept;
|
|
|
+import com.jzg.commons.entity.vo.SysDeptVo;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
+import com.jzg.mapper.PtlAgreementAttributionDeptMapper;
|
|
|
+import com.jzg.mapper.SysDeptMapper;
|
|
|
+import com.jzg.service.PtlAgreementAttributionDeptService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author quchen
|
|
|
+ * @date 2025/3/17 10:30
|
|
|
+ */
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PtlAgreementAttributionDeptServiceImpl extends ServiceImpl<PtlAgreementAttributionDeptMapper, PtlAgreementAttributionDept> implements PtlAgreementAttributionDeptService {
|
|
|
+ @Autowired
|
|
|
+ private BaseController baseController;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptMapper deptMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PtlAgreementAttributionDeptListVo deptTree(String id, String deptName) {
|
|
|
+ // 获取所有协议选中的机构id
|
|
|
+ LambdaQueryWrapper<PtlAgreementAttributionDept> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PtlAgreementAttributionDept::getAgreementAttributionId, id);
|
|
|
+ List<PtlAgreementAttributionDept> agreementDepts = list(wrapper);
|
|
|
+ Map<String, PtlAgreementAttributionDept> deptMap = agreementDepts.stream().collect(Collectors.toMap(PtlAgreementAttributionDept::getDeptId, dept -> dept));
|
|
|
+ String deptId = baseController.getUserDeptId();
|
|
|
+ List<SysDeptVo> sysDepts = new ArrayList<>();
|
|
|
+ SysDept sysDept = deptMapper.selectById(deptId);
|
|
|
+ SysDeptVo sysDeptVo = new SysDeptVo(sysDept);
|
|
|
+ SysDept nameDept = null;
|
|
|
+ if(StringUtils.isNotEmpty(deptName)){
|
|
|
+ LambdaQueryWrapper<SysDept> deptWrapper = new LambdaQueryWrapper<>();
|
|
|
+ deptWrapper.eq(SysDept :: getName, deptName);
|
|
|
+ nameDept = deptMapper.selectOne(deptWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysDept> allWrapper = new LambdaQueryWrapper<>();
|
|
|
+ allWrapper.like(SysDept :: getRoute, deptId)
|
|
|
+ .eq(SysDept :: getIsDelete, 0);
|
|
|
+ if (Objects.nonNull(nameDept)){
|
|
|
+ allWrapper.like(Objects.isNull(nameDept), SysDept :: getRoute, nameDept.getId());
|
|
|
+ }
|
|
|
+ List<SysDept> depts = deptMapper.selectList(allWrapper);
|
|
|
+ List<String> deptIds = new ArrayList<>();
|
|
|
+ List<SysDeptVo> voDept = new ArrayList<>();
|
|
|
+ depts.forEach(item->{
|
|
|
+ SysDeptVo sysDeptv = new SysDeptVo(item);
|
|
|
+ if(deptMap.containsKey(sysDeptv.getId())){
|
|
|
+ sysDeptv.setIsCheck(1);
|
|
|
+ deptIds.add(sysDeptv.getId());
|
|
|
+ }else{
|
|
|
+ sysDeptv.setIsCheck(0);
|
|
|
+ }
|
|
|
+ voDept.add(sysDeptv);
|
|
|
+ });
|
|
|
+ Map<String, List<SysDeptVo>> map = voDept.stream().collect(Collectors.groupingBy(SysDeptVo::getParentId));
|
|
|
+ voDept.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
|
|
|
+ if (!Objects.isNull(nameDept)){
|
|
|
+ sysDepts = map.get(nameDept.getParentId());
|
|
|
+ } else if(!Objects.isNull(sysDept)) {
|
|
|
+ sysDepts = map.get(sysDeptVo.getParentId());
|
|
|
+ }
|
|
|
+ List<SysDeptVo> newResultDept = new ArrayList<>();
|
|
|
+ newResultDept.addAll(sysDepts);
|
|
|
+ PtlAgreementAttributionDeptListVo resultDept = new PtlAgreementAttributionDeptListVo();
|
|
|
+ resultDept.setDeptList(newResultDept);
|
|
|
+ resultDept.setDeptIds(deptIds);
|
|
|
+ return resultDept;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void authorization(PtlAgreementAttributionDeptVo ptlAgreementAttributionDeptVo) {
|
|
|
+ // 删除之前所有的授权id
|
|
|
+ LambdaQueryWrapper<PtlAgreementAttributionDept> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(PtlAgreementAttributionDept::getAgreementAttributionId, ptlAgreementAttributionDeptVo.getId());
|
|
|
+ this.remove(wrapper);
|
|
|
+
|
|
|
+ // 新增保存授权数据
|
|
|
+ List<String> deptIds = ptlAgreementAttributionDeptVo.getDeptIds();
|
|
|
+ List<PtlAgreementAttributionDept> agreementDepts = new ArrayList<>();
|
|
|
+ deptIds.forEach(deptId->{
|
|
|
+ PtlAgreementAttributionDept dept = new PtlAgreementAttributionDept(ptlAgreementAttributionDeptVo.getId(),deptId);
|
|
|
+ agreementDepts.add(dept);
|
|
|
+ });
|
|
|
+ this.saveBatch(agreementDepts);
|
|
|
+ }
|
|
|
+}
|