From 8190823a593d3123384d3a75774ad19ecea07204 Mon Sep 17 00:00:00 2001 From: houruijun <411269194@kidgrow.com> Date: Mon, 15 Jun 2020 11:20:12 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 51 insertions(+), 3 deletions(-) diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java index d815af8..09a1b2d 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysOrganizationServiceImpl.java @@ -13,7 +13,6 @@ import com.kidgrow.usercenter.vo.SysOrganizationVo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cglib.beans.BeanCopier; import org.springframework.stereotype.Service; @@ -24,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> @@ -158,9 +156,10 @@ 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()); List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList()); if (childs.size() > 0) { List<Map<String, Object>> treeData = getTreeData(id, sysOrganizations); @@ -180,15 +179,64 @@ @Override @Transactional public boolean saveOrUpdateSer(SysOrganization sysOrganization) { + //获取code + if (sysOrganization.getId() == null) { //保存 + String code = this.getCode(sysOrganization); + sysOrganization.setOrgCode(code); baseMapper.insert(sysOrganization); } else { //更新 + SysOrganization sysOrg = baseMapper.selectById(sysOrganization.getId()); + if(sysOrg.getOrgParentId()!=sysOrganization.getOrgParentId()){ + String code = this.getCode(sysOrganization); + sysOrganization.setOrgCode(code); + } int i = baseMapper.updateById(sysOrganization); } redisUtils.hdel(RedisConstant.ORGANIZATION, sysOrganization.getId().toString()); redisUtils.hset(RedisConstant.ORGANIZATION, sysOrganization.getId().toString(), sysOrganization); return true; } + + + /** + * 获取自己组织的code + * @param sysOrganization + * @return + */ + public String getCode(SysOrganization sysOrganization){ + //获取父级 + Long orgParentId = sysOrganization.getOrgParentId(); + if (orgParentId == null) { + return null; + } + SysOrganization sysOrg = baseMapper.selectById(orgParentId); + if(sysOrg!=null){ + String orgCode = sysOrg.getOrgCode(); + //查询 + QueryWrapper queryWrapper=new QueryWrapper(); + queryWrapper.eq("org_parent_id",sysOrg.getId()); + queryWrapper.orderByAsc("id"); + List<SysOrganization> list = baseMapper.selectList(queryWrapper); + if (list.size()>0) { + SysOrganization sysOrganizationLast = list.get(list.size() - 1); + String orgCodeLast = sysOrganizationLast.getOrgCode(); + String orgCodeLastQianZhui=orgCodeLast.substring(0,orgCodeLast.length() - 4); + Integer codenum = Integer.valueOf(orgCodeLast.substring(orgCodeLast.length() - 4)); + String str="0000"; + str+=(codenum+1); + String substring = str.substring(str.length() - 4); + return orgCodeLastQianZhui+substring; + }else { + String fucode = sysOrg.getOrgCode(); + String str="0001"; + return fucode+str; + } + + } + return null; + } + } -- Gitblit v1.8.0