| | |
| | | package com.panzhihua.westcommittee.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.beust.jcommander.internal.Lists; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.west.SystemUserVo; |
| | | import com.panzhihua.common.utlis.PayUtil; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.westcommittee.dao.SystemUserLevelMapper; |
| | | import com.panzhihua.westcommittee.dao.SystemUserMapper; |
| | | import com.panzhihua.westcommittee.model.entity.ComAct; |
| | | import com.panzhihua.westcommittee.model.entity.ComStreet; |
| | | import com.panzhihua.westcommittee.model.entity.SystemUser; |
| | | import com.panzhihua.westcommittee.model.entity.*; |
| | | import com.panzhihua.westcommittee.model.vo.RegionVO; |
| | | import com.panzhihua.westcommittee.service.IComActService; |
| | | import com.panzhihua.westcommittee.service.IComStreetService; |
| | | import com.panzhihua.westcommittee.service.ISystemUserService; |
| | | import com.panzhihua.westcommittee.service.*; |
| | | import com.panzhihua.westcommittee.utils.ExcelUtil; |
| | | import com.panzhihua.westcommittee.warpper.SystemUserList; |
| | | import com.panzhihua.westcommittee.warpper.SystemUserListVo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import sun.security.util.Password; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | @Service |
| | | @RequiredArgsConstructor(onConstructor_ = {@Lazy}) |
| | | public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService { |
| | | private final IComActService comActService; |
| | | private final SystemUserLevelMapper systemUserLevelMapper; |
| | | private final IComStreetService comStreetService; |
| | | /** |
| | | * 获取列表数据 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<SystemUserListVo> list(SystemUser user, SystemUserList query) { |
| | | Page page = new Page<>(); |
| | | page.setCurrent(query.getPageNum()); |
| | | page.setSize(query.getPageSize()); |
| | | IPage<SystemUserListVo> list = this.baseMapper.list(page, user, query); |
| | | return list; |
| | | } |
| | | private final IComActService comActService; |
| | | private final SystemUserLevelMapper systemUserLevelMapper; |
| | | private final IComStreetService comStreetService; |
| | | private final ExcelUtil excelUtil; |
| | | private final IDepartmentService departmentService; |
| | | private final ISystemPostService systemPostService; |
| | | |
| | | /** |
| | | * 根据手机号码查询小程序用户在西区纪委的上级角色用户 |
| | | * @param phone |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Optional<SystemUser> getSystemUserAdminByPhone(String phone) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | return Optional.empty(); |
| | | } |
| | | return this.lambdaQuery() |
| | | .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3) |
| | | .eq(SystemUser::getIsAdmin, 1).last("LIMIT 1").oneOpt(); |
| | | } |
| | | /** |
| | | * 获取列表数据 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<SystemUserListVo> list(SystemUser user, SystemUserList query) { |
| | | Page page = new Page<>(); |
| | | page.setCurrent(query.getPageNum()); |
| | | page.setSize(query.getPageSize()); |
| | | if(query.getDeptId()!=null || user.getAccountLevel()==2){ |
| | | IPage<SystemUserListVo> list = this.baseMapper.list(page, user, query); |
| | | return list; |
| | | }else { |
| | | List<Integer> deptIds=new ArrayList<>(); |
| | | if(user.getAccountLevel()==3){ |
| | | List<Long> ids = comActService.list(new LambdaQueryWrapper<ComAct>().eq(ComAct::getStreetId, user.getStreetId())).stream().map(ComAct::getCommunityId).collect(Collectors.toList()); |
| | | List<Department> list = departmentService.list(new LambdaQueryWrapper<Department>().eq(Department::getTier, 3).eq(Department::getStreetId, user.getStreetId()) |
| | | .or(department -> department.and(department1 -> department1.eq(Department::getTier, 4).in(Department::getCommunityId, ids)))); |
| | | if(list.isEmpty()){ |
| | | return new Page<>(); |
| | | } |
| | | deptIds= list.stream().map(Department::getId).collect(Collectors.toList()); |
| | | }else if(user.getAccountLevel()==4){ |
| | | List<Department> list = departmentService.list(new LambdaQueryWrapper<Department>().eq(Department::getTier, 4).eq(Department::getCommunityId, user.getCommunityId())); |
| | | if(list.isEmpty()){ |
| | | return new Page<>(); |
| | | } |
| | | deptIds= list.stream().map(Department::getId).collect(Collectors.toList()); |
| | | } |
| | | IPage<SystemUserListVo> list = this.baseMapper.list1(page, user, query,deptIds); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Optional<SystemUser> getSystemUserByPhone(String phone) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | return Optional.empty(); |
| | | } |
| | | return this.lambdaQuery() |
| | | .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3).last("LIMIT 1").oneOpt(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取行政区划数据 |
| | | * |
| | | * @param pcode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getRegion(String pcode) { |
| | | return this.baseMapper.getRegion(pcode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取街道数据 |
| | | * |
| | | * @param areaCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getStreet(String areaCode) { |
| | | return this.baseMapper.getStreet(areaCode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取社区数据 |
| | | * |
| | | * @param streetId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getCommunity(String streetId) { |
| | | return this.baseMapper.getCommunity(streetId); |
| | | } |
| | | /** |
| | | * 根据手机号码查询小程序用户在西区纪委的上级角色用户 |
| | | * @param phone |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Optional<SystemUser> getSystemUserAdminByPhone(String phone) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | return Optional.empty(); |
| | | } |
| | | return this.lambdaQuery() |
| | | .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3) |
| | | .eq(SystemUser::getIsAdmin, 1).last("LIMIT 1").oneOpt(); |
| | | } |
| | | |
| | | /** |
| | | * 获取区县-街道-社区树 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getRegionTree(SystemUserVo loginUserInfo) { |
| | | log.info("getRegionTree入参:{}",JSONObject.toJSONString(loginUserInfo)); |
| | | SystemUser systemUser = getById(loginUserInfo.getId()); |
| | | Integer accountLevel = systemUser.getAccountLevel(); |
| | | List<RegionVO> regionTree = new ArrayList<>(); |
| | | switch (accountLevel) { |
| | | case 1: |
| | | regionTree = baseMapper.getRegion("510400"); |
| | | baseMapper.getStreet("510400"); |
| | | regionTree.forEach(district -> { |
| | | district.setTier(2); |
| | | List<RegionVO> streets = baseMapper.getStreet(district.getId()); |
| | | district.setChildren(streets); |
| | | streets.forEach(street -> { |
| | | street.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(street.getId()); |
| | | communities.forEach(e->e.setTier(4)); |
| | | street.setChildren(communities); |
| | | }); |
| | | }); |
| | | break; |
| | | case 2: |
| | | regionTree = baseMapper.getStreet(systemUser.getDistrictsCode()); |
| | | regionTree.forEach(regionVO->{ |
| | | regionVO.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(regionVO.getId()); |
| | | communities.forEach(e->e.setTier(4)); |
| | | regionVO.setChildren(communities); |
| | | }); |
| | | break; |
| | | case 3: |
| | | ComStreet street = comStreetService.getById(systemUser.getStreetId()); |
| | | RegionVO streetVO = new RegionVO(); |
| | | streetVO.setId(street.getStreetId()); |
| | | streetVO.setName(street.getName()); |
| | | streetVO.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(systemUser.getStreetId()); |
| | | communities.forEach(e->e.setTier(4)); |
| | | streetVO.setChildren(communities); |
| | | regionTree = Lists.newArrayList(streetVO); |
| | | break; |
| | | case 4: |
| | | ComAct byId = comActService.getById(systemUser.getCommunityId()); |
| | | RegionVO regionVO = new RegionVO(); |
| | | regionVO.setTier(4); |
| | | regionVO.setId(byId.getCommunityId().toString()); |
| | | regionVO.setName(byId.getName()); |
| | | regionTree = Lists.newArrayList(regionVO); |
| | | break; |
| | | } |
| | | @Override |
| | | public Optional<SystemUser> getSystemUserByPhone(String phone) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | return Optional.empty(); |
| | | } |
| | | return this.lambdaQuery() |
| | | .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3).last("LIMIT 1").oneOpt(); |
| | | } |
| | | |
| | | return regionTree; |
| | | } |
| | | /** |
| | | * 获取行政区划数据 |
| | | * |
| | | * @param pcode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getRegion(String pcode) { |
| | | return this.baseMapper.getRegion(pcode); |
| | | } |
| | | |
| | | @Override |
| | | public String getCreateByIdPhone(Long createBy) { |
| | | return this.baseMapper.getCreateByIdPhone(createBy); |
| | | } |
| | | |
| | | /** |
| | | * 获取街道数据 |
| | | * |
| | | * @param areaCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getStreet(String areaCode) { |
| | | return this.baseMapper.getStreet(areaCode); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取社区数据 |
| | | * |
| | | * @param streetId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getCommunity(String streetId) { |
| | | return this.baseMapper.getCommunity(streetId); |
| | | } |
| | | |
| | | /** |
| | | * 获取区县-街道-社区树 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<RegionVO> getRegionTree(SystemUserVo loginUserInfo) { |
| | | log.info("getRegionTree入参:{}", JSONObject.toJSONString(loginUserInfo)); |
| | | SystemUser systemUser = getById(loginUserInfo.getId()); |
| | | Integer accountLevel = systemUser.getAccountLevel(); |
| | | List<RegionVO> regionTree = new ArrayList<>(); |
| | | switch (accountLevel) { |
| | | case 1: |
| | | regionTree = baseMapper.getRegion("510400"); |
| | | baseMapper.getStreet("510400"); |
| | | regionTree.forEach(district -> { |
| | | district.setTier(2); |
| | | List<RegionVO> streets = baseMapper.getStreet(district.getId()); |
| | | district.setChildren(streets); |
| | | streets.forEach(street -> { |
| | | street.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(street.getId()); |
| | | communities.forEach(e -> e.setTier(4)); |
| | | street.setChildren(communities); |
| | | }); |
| | | }); |
| | | break; |
| | | case 2: |
| | | regionTree = baseMapper.getStreet(systemUser.getDistrictsCode()); |
| | | regionTree.forEach(regionVO -> { |
| | | regionVO.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(regionVO.getId()); |
| | | communities.forEach(e -> e.setTier(4)); |
| | | regionVO.setChildren(communities); |
| | | }); |
| | | break; |
| | | case 3: |
| | | ComStreet street = comStreetService.getById(systemUser.getStreetId()); |
| | | RegionVO streetVO = new RegionVO(); |
| | | streetVO.setId(street.getStreetId()); |
| | | streetVO.setName(street.getName()); |
| | | streetVO.setTier(3); |
| | | List<RegionVO> communities = baseMapper.getCommunity(systemUser.getStreetId()); |
| | | communities.forEach(e -> e.setTier(4)); |
| | | streetVO.setChildren(communities); |
| | | regionTree = Lists.newArrayList(streetVO); |
| | | break; |
| | | case 4: |
| | | ComAct byId = comActService.getById(systemUser.getCommunityId()); |
| | | RegionVO regionVO = new RegionVO(); |
| | | regionVO.setTier(4); |
| | | regionVO.setId(byId.getCommunityId().toString()); |
| | | regionVO.setName(byId.getName()); |
| | | regionTree = Lists.newArrayList(regionVO); |
| | | break; |
| | | } |
| | | |
| | | return regionTree; |
| | | } |
| | | |
| | | @Override |
| | | public String getCreateByIdPhone(Long createBy) { |
| | | return this.baseMapper.getCreateByIdPhone(createBy); |
| | | } |
| | | |
| | | @SneakyThrows |
| | | @Override |
| | | public R<?> importUser(String s, MultipartFile file) { |
| | | List<List<List<String>>> upload = excelUtil.upload(s, file); |
| | | List<List<String>> lists = upload.get(0); |
| | | for (List<String> list : lists) { |
| | | String name = list.get(0); |
| | | String postName = list.get(1); |
| | | String deptName = list.get(2); |
| | | String roleId = list.get(3); |
| | | String phone = list.get(4); |
| | | String pwd = list.get(5); |
| | | |
| | | long count = this.count(new LambdaQueryWrapper<SystemUser>().eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3)); |
| | | if (0 == count) { |
| | | SystemUser systemUser = new SystemUser(); |
| | | systemUser.setName(name); |
| | | systemUser.setPhone(phone); |
| | | systemUser.setPassword(PayUtil.MD5(pwd).toLowerCase()); |
| | | |
| | | try { |
| | | Department name1 = departmentService.getOne(new QueryWrapper<Department>().eq("name", deptName)); |
| | | systemUser.setOneDepartmentId(name1.getId()); |
| | | systemUser.setDistricts(name1.getDistricts()); |
| | | systemUser.setDistrictsCode(name1.getDistrictsCode()); |
| | | systemUser.setStreet(name1.getStreet()); |
| | | systemUser.setStreetId(name1.getStreetId()); |
| | | systemUser.setCommunity(name1.getCommunity()); |
| | | systemUser.setCommunityId(name1.getCommunityId()); |
| | | systemUser.setAccountLevel(name1.getTier()); |
| | | systemUser.setStatus(1); |
| | | systemUser.setSystemRoleId(Integer.valueOf(roleId)); |
| | | systemUser.setCreateTime(LocalDateTime.now()); |
| | | |
| | | SystemPost name2 = systemPostService.getOne(new QueryWrapper<SystemPost>().eq("name", postName)); |
| | | systemUser.setSystemPostId(name2.getId()); |
| | | save(systemUser); |
| | | |
| | | } catch (Exception e) { |
| | | System.out.println(deptName); |
| | | System.out.println(postName); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | System.out.println(PayUtil.MD5("111111").toLowerCase()); |
| | | } |
| | | |
| | | } |