| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | public class SysOrganizationServiceImpl extends SuperServiceImpl<SysOrganizationMapper, SysOrganization> implements ISysOrganizationService { |
| | | @Autowired |
| | | RedisUtils redisUtils; |
| | | |
| | | @Autowired |
| | | SysUserOrgMapper sysUserOrgMapper; |
| | | /** |
| | | * 列表 |
| | | * |
| | |
| | | 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 (递归方式) |
| | | * |
| | |
| | | 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()); |
| | |
| | | } 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); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 获取自己组织的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; |
| | | } |
| | | |
| | | } |