forked from kidgrow-microservices-platform

zhaoxiaohao
2020-06-24 6ff7f64dc78dd5af4c180fe13a24aeef7581a6ab
kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java
@@ -9,6 +9,7 @@
import com.kidgrow.redis.util.RedisConstant;
import com.kidgrow.redis.util.RedisUtils;
import com.kidgrow.usercenter.mapper.SysOrganizationMapper;
import com.kidgrow.usercenter.mapper.SysUserOrgMapper;
import com.kidgrow.usercenter.service.ISysOrganizationService;
import com.kidgrow.usercenter.vo.SysOrganizationVo;
import lombok.extern.slf4j.Slf4j;
@@ -18,10 +19,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -38,7 +36,8 @@
public class SysOrganizationServiceImpl extends SuperServiceImpl<SysOrganizationMapper, SysOrganization> implements ISysOrganizationService {
    @Autowired
    RedisUtils redisUtils;
    @Autowired
    SysUserOrgMapper sysUserOrgMapper;
    /**
     * 列表
     *
@@ -142,6 +141,13 @@
        return ResultBody.ok().data(treeData);
    }
    @Override
    public int deleteByUserId(Long userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        return sysUserOrgMapper.deleteByMap(params);
    }
    /**
     * 将数据  封装成  tree   (递归方式)
     *
@@ -156,7 +162,7 @@
        for (Long id : idList
        ) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", ""+id);
            map.put("id", "" + id);
            map.put("name", collect.get(id).getOrgName());
            map.put("level", collect.get(id).getOrgLevel());
            map.put("parentId", collect.get(id).getOrgParentId());
@@ -177,7 +183,7 @@
     * @return
     */
    @Override
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateSer(SysOrganization sysOrganization) {
        //获取code
@@ -189,7 +195,7 @@
        } else {
            //更新
            SysOrganization sysOrg = baseMapper.selectById(sysOrganization.getId());
            if(sysOrg.getOrgParentId()!=sysOrganization.getOrgParentId()){
            if (sysOrg.getOrgParentId() != sysOrganization.getOrgParentId()) {
                String code = this.getCode(sysOrganization);
                sysOrganization.setOrgCode(code);
            }
@@ -203,36 +209,37 @@
    /**
     * 获取自己组织的code
     *
     * @param sysOrganization
     * @return
     */
    public String getCode(SysOrganization sysOrganization){
    public String getCode(SysOrganization sysOrganization) {
        //获取父级
        Long orgParentId = sysOrganization.getOrgParentId();
        if (orgParentId == null) {
            return null;
        }
        SysOrganization sysOrg = baseMapper.selectById(orgParentId);
        if(sysOrg!=null){
        if (sysOrg != null) {
            String orgCode = sysOrg.getOrgCode();
            //查询
            QueryWrapper queryWrapper=new QueryWrapper();
            queryWrapper.eq("org_parent_id",sysOrg.getId());
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("org_parent_id", sysOrg.getId());
            queryWrapper.orderByAsc("id");
            List<SysOrganization> list = baseMapper.selectList(queryWrapper);
            if (list.size()>0) {
            if (list.size() > 0) {
                SysOrganization sysOrganizationLast = list.get(list.size() - 1);
                String orgCodeLast = sysOrganizationLast.getOrgCode();
                String orgCodeLastQianZhui=orgCodeLast.substring(0,orgCodeLast.length() - 4);
                String orgCodeLastQianZhui = orgCodeLast.substring(0, orgCodeLast.length() - 4);
                Integer codenum = Integer.valueOf(orgCodeLast.substring(orgCodeLast.length() - 4));
                String str="0000";
                str+=(codenum+1);
                String str = "0000";
                str += (codenum + 1);
                String substring = str.substring(str.length() - 4);
                return orgCodeLastQianZhui+substring;
            }else {
                return orgCodeLastQianZhui + substring;
            } else {
                String fucode = sysOrg.getOrgCode();
                String str="0001";
                return fucode+str;
                String str = "0001";
                return fucode + str;
            }
        }