企业修改

This commit is contained in:
GUO 2024-06-07 23:15:45 +08:00
parent 4da9fa295b
commit bca18576bf
3 changed files with 39 additions and 22 deletions

View File

@ -1,17 +1,18 @@
package com.zhgd.xmgl.modules.project.mapper; package com.zhgd.xmgl.modules.project.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.project.entity.ProjectEnterprise;
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.zhgd.xmgl.modules.project.entity.ProjectEnterprise;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/** /**
* @Description: 项目劳务公司关联 * @Description: 项目劳务公司关联
* @author pds * @author pds
@ -36,4 +37,5 @@ public interface ProjectEnterpriseMapper extends BaseMapper<ProjectEnterprise> {
void updateAncestors(@Param("oldAncestor") String oldAncestor, @Param("newAncestor") String newAncestor, @Param("projectSn") String projectSn, @Param("id") Long id); void updateAncestors(@Param("oldAncestor") String oldAncestor, @Param("newAncestor") String newAncestor, @Param("projectSn") String projectSn, @Param("id") Long id);
List<XzProjectOrg> getChildren(Long id);
} }

View File

@ -223,4 +223,9 @@
SET ancestors=REPLACE(ancestors, #{oldAncestor}, #{newAncestor}) SET ancestors=REPLACE(ancestors, #{oldAncestor}, #{newAncestor})
WHERE ancestors LIKE N'${oldAncestor},${id}%' and project_sn = #{projectSn} WHERE ancestors LIKE N'${oldAncestor},${id}%' and project_sn = #{projectSn}
</update> </update>
<select id="getChildren" resultType="com.zhgd.xmgl.modules.xz.entity.XzProjectOrg">
select * from project_enterprise
where find_in_set(#{id}, ancestors)
</select>
</mapper> </mapper>

View File

@ -16,6 +16,7 @@ import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
import com.zhgd.xmgl.modules.worker.entity.UserEnterprise; import com.zhgd.xmgl.modules.worker.entity.UserEnterprise;
import com.zhgd.xmgl.modules.worker.mapper.EnterpriseInfoMapper; import com.zhgd.xmgl.modules.worker.mapper.EnterpriseInfoMapper;
import com.zhgd.xmgl.modules.worker.mapper.UserEnterpriseMapper; import com.zhgd.xmgl.modules.worker.mapper.UserEnterpriseMapper;
import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg;
import com.zhgd.xmgl.security.entity.UserInfo; import com.zhgd.xmgl.security.entity.UserInfo;
import com.zhgd.xmgl.security.util.SecurityUtils; import com.zhgd.xmgl.security.util.SecurityUtils;
import com.zhgd.xmgl.util.MessageUtil; import com.zhgd.xmgl.util.MessageUtil;
@ -96,30 +97,39 @@ public class ProjectEnterpriseServiceImpl extends ServiceImpl<ProjectEnterpriseM
} }
@Override @Override
public void editProjectEnterprise(ProjectEnterprise projectEnterprise) { public void editProjectEnterprise(ProjectEnterprise pe) {
ProjectEnterprise oldPo = projectEnterpriseMapper.selectById(projectEnterprise.getId()); ProjectEnterprise old = projectEnterpriseMapper.selectById(pe.getId());
if (oldPo == null) { if (old == null) {
throw new OpenAlertException(MessageUtil.get("notFindErr")); throw new OpenAlertException(MessageUtil.get("notFindErr"));
} }
if (!Objects.equals(oldPo.getParentProjectEnterpriseId(), projectEnterprise.getParentProjectEnterpriseId())) { if (!Objects.equals(old.getParentProjectEnterpriseId(), pe.getParentProjectEnterpriseId())) {
ProjectEnterprise pOrg = projectEnterpriseMapper.selectById(projectEnterprise.getParentProjectEnterpriseId()); if (Objects.equals(pe.getId(), pe.getParentProjectEnterpriseId())) {
throw new OpenAlertException("不能将其移动到其自身");
}
List<XzProjectOrg> children = baseMapper.getChildren(pe.getId());
for (XzProjectOrg child : children) {
if (child.getId().equals(pe.getParentProjectEnterpriseId())) {
throw new OpenAlertException("不能将其移动到其自身下级");
}
}
ProjectEnterprise pOrg = projectEnterpriseMapper.selectById(pe.getParentProjectEnterpriseId());
// 修改子部门 // 修改子部门
boolean top = projectEnterprise.getParentProjectEnterpriseId() == null || projectEnterprise.getParentProjectEnterpriseId() == 0; boolean top = pe.getParentProjectEnterpriseId() == null || pe.getParentProjectEnterpriseId() == 0;
if (top) { if (top) {
projectEnterprise.setParentProjectEnterpriseId(0L); pe.setParentProjectEnterpriseId(0L);
projectEnterprise.setAncestors("0"); pe.setAncestors("0");
} else { } else {
if (pOrg == null) { if (pOrg == null) {
throw new OpenAlertException("上级部门不存在"); throw new OpenAlertException("上级部门不存在");
} }
projectEnterprise.setAncestors(pOrg.getAncestors() + "," + pOrg.getId()); pe.setAncestors(pOrg.getAncestors() + "," + pOrg.getId());
} }
baseMapper.updateAncestors(oldPo.getAncestors(), projectEnterprise.getAncestors(), projectEnterprise.getProjectSn(), projectEnterprise.getId()); baseMapper.updateAncestors(old.getAncestors(), pe.getAncestors(), pe.getProjectSn(), pe.getId());
baseMapper.updateById(projectEnterprise); baseMapper.updateById(pe);
} else { } else {
projectEnterprise.setAncestors(null); pe.setAncestors(null);
baseMapper.updateById(projectEnterprise); baseMapper.updateById(pe);
} }
} }