|
@@ -0,0 +1,117 @@
|
|
|
|
|
+package com.jzg.organization.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
|
|
+import com.jzg.commons.entity.dto.SysOrganizationAdd;
|
|
|
|
|
+import com.jzg.commons.entity.dto.SysOrganizationParam;
|
|
|
|
|
+import com.jzg.commons.entity.dto.SysOrganizationSetPerson;
|
|
|
|
|
+import com.jzg.commons.entity.dto.SysOrganizationUserLinkAdd;
|
|
|
|
|
+import com.jzg.commons.entity.po.SysOrganization;
|
|
|
|
|
+import com.jzg.commons.entity.po.SysOrganizationUserLink;
|
|
|
|
|
+import com.jzg.commons.entity.vo.LeftSysOrganizationVo;
|
|
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
|
|
+import com.jzg.organization.mapper.SysOrganizationMapper;
|
|
|
|
|
+import com.jzg.organization.service.SysOrganizationService;
|
|
|
|
|
+import com.jzg.organization.service.SysOrganizationUserLinkService;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMapper, SysOrganization> implements SysOrganizationService {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysOrganizationMapper sysOrganizationMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SysOrganizationUserLinkService sysOrganizationUserLinkService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult queryPageList(SysOrganizationParam sysOrganizationParam) {
|
|
|
|
|
+ QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.select("id, system_code, name, dept_id, manager_id, describe_information, attribute, is_delete, create_by, create_time, update_by, update_time," +
|
|
|
|
|
+ "(SELECT COUNT(1) FROM sys_organization_user_link WHERE sys_organization_user_link.organization_id = sys_organization.id) memberNumber");
|
|
|
|
|
+ queryWrapper.like("name", sysOrganizationParam.getParam());
|
|
|
|
|
+ List<SysOrganization> list = null;
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(sysOrganizationParam.getPage())){
|
|
|
|
|
+ list = sysOrganizationMapper.selectList(sysOrganizationParam.getPage(), queryWrapper);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ sysOrganizationMapper.selectList( queryWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.ok(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public LambdaQueryWrapper getLambdaQueryWrapper(SysOrganizationParam sysOrganizationParam) {
|
|
|
|
|
+ LambdaQueryWrapper<SysOrganization> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ if (ObjectUtil.isEmpty(sysOrganizationParam)){
|
|
|
|
|
+ return lambdaQueryWrapper;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotEmpty(sysOrganizationParam.getParam())){
|
|
|
|
|
+ lambdaQueryWrapper.like(SysOrganization::getName, sysOrganizationParam.getParam());
|
|
|
|
|
+ }
|
|
|
|
|
+ lambdaQueryWrapper.orderByDesc(SysOrganization::getCreateTime);
|
|
|
|
|
+ return lambdaQueryWrapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult deleteById(Long id) {
|
|
|
|
|
+ boolean isExist = sysOrganizationUserLinkService.selectByOrgId(id);
|
|
|
|
|
+ if (isExist){
|
|
|
|
|
+ return HttpResult.error("该机构下还有用户,请先删除用户");
|
|
|
|
|
+ }
|
|
|
|
|
+ return sysOrganizationMapper.deleteById(id) > 1 ? HttpResult.ok("删除成功") : HttpResult.error("删除失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean nameExists(SysOrganizationAdd organizationAdd) {
|
|
|
|
|
+ LambdaQueryWrapper<SysOrganization> last = new LambdaQueryWrapper<SysOrganization>()
|
|
|
|
|
+ .eq(SysOrganization::getName, organizationAdd.getName())
|
|
|
|
|
+ .eq(SysOrganization::getSystemCode, organizationAdd.getSystemCode())
|
|
|
|
|
+ .eq(SysOrganization::getAttribute, organizationAdd.getAttribute())
|
|
|
|
|
+ .eq(SysOrganization::getIsDelete, 0)
|
|
|
|
|
+ .last("limit 1");
|
|
|
|
|
+ boolean exists = sysOrganizationMapper.exists(last);
|
|
|
|
|
+ return exists;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult leftList(SysOrganizationParam sysOrganizationParam) {
|
|
|
|
|
+ QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.select("name,id,system_code, (SELECT COUNT(1) FROM sys_organization_user_link WHERE sys_organization_user_link.organization_id = sys_organization.id) memberNumber");
|
|
|
|
|
+ queryWrapper.groupBy("name,id");
|
|
|
|
|
+ List<SysOrganization> sysOrganizations = sysOrganizationMapper.selectList(queryWrapper);
|
|
|
|
|
+ List<LeftSysOrganizationVo> list = JSONObject.parseObject(JSONObject.toJSONString(sysOrganizations), List.class);
|
|
|
|
|
+ return HttpResult.ok(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult addTeamUsers(SysOrganizationUserLinkAdd organizationUserLinkAdd) {
|
|
|
|
|
+ SysOrganizationUserLink organizationUserLink = new SysOrganizationUserLink();
|
|
|
|
|
+ BeanUtils.copyProperties(organizationUserLinkAdd, organizationUserLink);
|
|
|
|
|
+ return sysOrganizationUserLinkService.save(organizationUserLink) ? HttpResult.ok("添加成功") : HttpResult.error("添加失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult setResponsiblePerson(SysOrganizationSetPerson setPerson) {
|
|
|
|
|
+ SysOrganization sysOrganization = sysOrganizationMapper.selectById(setPerson.getId());
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(sysOrganization)){
|
|
|
|
|
+ sysOrganization.setManagerId(setPerson.getManagerId());
|
|
|
|
|
+ return sysOrganizationMapper.updateById(sysOrganization) > 1 ? HttpResult.ok("设置成功") : HttpResult.error("设置失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResult.error("所选团队、渠道、电销组不存在或以删除,请刷新");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|