| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill 庄骞 (smallchill@163.com) |
| | | */ |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.flowable.idm.engine.impl.persistence.entity.UserEntity; |
| | | import org.springblade.common.cache.DictCache; |
| | | import org.springblade.common.cache.ParamCache; |
| | | import org.springblade.common.cache.SysCache; |
| | |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springblade.modules.auth.enums.UserEnum; |
| | | import org.springblade.modules.community.entity.CommunityEntity; |
| | | import org.springblade.modules.community.service.ICommunityService; |
| | | import org.springblade.modules.grid.service.IGridmanService; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.police.entity.PoliceAffairsGridEntity; |
| | | import org.springblade.modules.police.service.IPoliceAffairsGridService; |
| | | import org.springblade.modules.property.entity.PropertyCompanyEntity; |
| | | import org.springblade.modules.property.service.IPropertyCompanyService; |
| | | import org.springblade.modules.system.entity.*; |
| | | import org.springblade.modules.system.excel.PoliceUserExcel; |
| | | import org.springblade.modules.system.excel.UserExcel; |
| | |
| | | import org.springblade.modules.system.wrapper.UserWrapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | | import static org.springblade.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD; |
| | | |
| | | /** |
| | |
| | | private final IUserOauthService userOauthService; |
| | | private final IRoleService roleService; |
| | | private final BladeTenantProperties tenantProperties; |
| | | private final IPoliceAffairsGridService policeAffairsGridService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | * @param user |
| | | */ |
| | | public void updateGridBind(User user) { |
| | | // 先删除原有区域的绑定 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0).like("police_user_id", user.getId()); |
| | | // 删除掉之前已绑定的 |
| | | List<PoliceAffairsGridEntity> list = SpringUtil.getBean(IPoliceAffairsGridService.class).list(queryWrapper); |
| | | // 遍历 |
| | | for (PoliceAffairsGridEntity policeAffairsGridEntity : list) { |
| | | List<String> arrayList = new ArrayList<>(Arrays.asList(policeAffairsGridEntity.getPoliceUserId().split(","))); |
| | | arrayList.remove(user.getId().toString()); |
| | | // 更新 |
| | | policeAffairsGridEntity.setPoliceUserId(String.join(",", arrayList)); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | // 判断机构类型 |
| | | List<String> deptIds = new ArrayList<>(Arrays.asList(user.getDeptId().split(","))); |
| | | for (String deptId : deptIds) { |
| | | // 查询对应的机构 |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getById(deptId); |
| | | if (null != dept.getDeptNature() |
| | | && !Strings.isBlank(dept.getRegionCode()) |
| | | && dept.getDeptNature() == 1 |
| | | ) { |
| | | QueryWrapper<PoliceAffairsGridEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted", 0).eq("jw_grid_code", dept.getRegionCode()); |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridService.getOne(wrapper); |
| | | // 更新 |
| | | if (null != policeAffairsGridEntity) { |
| | | if (!Strings.isBlank(policeAffairsGridEntity.getPoliceUserId())) { |
| | | if (!policeAffairsGridEntity.getPoliceUserId().contains(user.getId().toString())) { |
| | | policeAffairsGridEntity.setPoliceUserId(policeAffairsGridEntity.getPoliceUserId() + "," + user.getId()); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | // 更新 |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | } else { |
| | | policeAffairsGridEntity.setPoliceUserId(user.getId().toString()); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | // 更新 |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean submitUserDept(User user) { |
| | |
| | | @Override |
| | | public User userByAccount(String tenantId, String account) { |
| | | return baseMapper.selectOne(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, account).eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED)); |
| | | } |
| | | |
| | | @Override |
| | | public UserInfo userInfo(String tenantId, String account) { |
| | | User user = baseMapper.selectOne(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, account).eq(User::getIsDeleted, BladeConstant.DB_NOT_DELETED)); |
| | | return buildUserInfo(user); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * @param userIds |
| | | */ |
| | | public void removePoliceGridBind(String userIds) { |
| | | List<String> userIdList = new ArrayList<>(Arrays.asList(userIds.split(","))); |
| | | for (String userId : userIdList) { |
| | | // 先删除原有区域的绑定 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0).like("police_user_id", userId); |
| | | // 删除掉之前已绑定的 |
| | | List<PoliceAffairsGridEntity> list = SpringUtil.getBean(IPoliceAffairsGridService.class).list(queryWrapper); |
| | | if (list.size() > 0) { |
| | | // 遍历 |
| | | for (PoliceAffairsGridEntity policeAffairsGridEntity : list) { |
| | | List<String> arrayList = new ArrayList<>(Arrays.asList(policeAffairsGridEntity.getPoliceUserId().split(","))); |
| | | arrayList.remove(userId); |
| | | // 更新 |
| | | policeAffairsGridEntity.setPoliceUserId(String.join(",", arrayList)); |
| | | // 解决更新报错 |
| | | policeAffairsGridEntity.setGeom(null); |
| | | SpringUtil.getBean(IPoliceAffairsGridService.class).updateById(policeAffairsGridEntity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<UserExcel> exportUser(Wrapper<User> queryWrapper) { |
| | | List<UserExcel> userList = baseMapper.exportUser(queryWrapper); |
| | | public List<UserExcel> exportUser(Wrapper<User> queryWrapper, String deptId) { |
| | | if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) { |
| | | deptId = AuthUtil.getDeptId(); |
| | | } |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | List<UserExcel> userList = baseMapper.exportUser(queryWrapper, deptIdList); |
| | | userList.forEach(user -> { |
| | | user.setUserTypeName(DictCache.getValue(DictEnum.USER_TYPE, user.getUserType())); |
| | | user.setRoleName(StringUtil.join(SysCache.getRoleNames(user.getRoleId()))); |
| | |
| | | return baseMapper.searchUserById(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserEntity> getUserInfoByCode(String houseCode, String type) { |
| | | if (type.equals("0")) { |
| | | IGridmanService bean = SpringUtil.getBean(IGridmanService.class); |
| | | return bean.getGridManByCode(houseCode); |
| | | } else { |
| | | // IPropertyCompanyDistrictService bean1 = SpringUtil.getBean(IPropertyCompanyDistrictService.class); |
| | | // return bean1.getDistictUserByCode(houseCode); |
| | | String deptId = AuthUtil.getDeptId(); |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | return baseMapper.selectUserByDept(deptIdList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<UserEntity> getUserInfoByDistrictId(String districtId, String building) { |
| | | return baseMapper.getUserInfoByDistrictId(districtId, building); |
| | | } |
| | | |
| | | @Override |
| | | public List<User> getUserInfoByDistrictIds(String districtIds) { |
| | | List<String> list = JSON.parseArray(districtIds).toJavaList(String.class); |
| | | return baseMapper.getUserInfoByDistrictIds(list); |
| | | } |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | |
| | | |
| | | @Override |
| | | public List<User> getUserInfoByPropertyId(String propertyCompanyId, String roleId) { |
| | | // 查询物业公司,获取物业公司的机构 |
| | | if (StringUtils.isBlank(propertyCompanyId)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | IPropertyCompanyService bean = SpringUtil.getBean(IPropertyCompanyService.class); |
| | | PropertyCompanyEntity one = bean.getOne(Wrappers.<PropertyCompanyEntity>lambdaQuery().eq(PropertyCompanyEntity::getId, propertyCompanyId)); |
| | | return baseMapper.getUserInfoByPropertyId(one.getDeptId().toString(), roleId); |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Object handleUser() { |
| | | List<User> list = list(Wrappers.<User>lambdaQuery() |
| | | .eq(User::getDeptId, "1727979636479037441") |
| | | .eq(User::getRoleId, "1717429059648606209")); |
| | | IHouseholdService bean = SpringUtil.getBean(IHouseholdService.class); |
| | | int a = 0; |
| | | for (User user : list) { |
| | | System.out.println("查詢處理啊的人:" + user.getId()); |
| | | HouseholdEntity one = bean.getOne(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | .eq(HouseholdEntity::getAssociatedUserId, user.getId()) |
| | | .eq(HouseholdEntity::getIsDeleted, 0)); |
| | | if (one != null) { |
| | | a++; |
| | | } |
| | | System.out.println("查詢處理啊的人:" + a); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | |
| | | * 设置机构 |
| | | */ |
| | | public void setDeptId(User user, PoliceUserExcel userExcel) { |
| | | // 查询机构 |
| | | QueryWrapper<PoliceAffairsGridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0) |
| | | .eq("community_code", userExcel.getCommunityCode()) |
| | | .eq("pcs_name", userExcel.getPoliceStationName()); |
| | | PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridService.getOne(queryWrapper); |
| | | if (null != policeAffairsGridEntity) { |
| | | // 查询对应绑定的机构 |
| | | QueryWrapper<Dept> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted", 0) |
| | | .eq("dept_nature", 1) |
| | | .eq("region_code", policeAffairsGridEntity.getJwGridCode()); |
| | | Dept dept = SpringUtil.getBean(IDeptService.class).getOne(wrapper); |
| | | if (null != dept) { |
| | | if (null != user.getId()) { |
| | | DeptNotHandle(user, dept); |
| | | } else { |
| | | user.setDeptId(dept.getId().toString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param user |
| | | */ |
| | | public void updateCommunityInfo(PoliceUserExcel userExcel, User user) { |
| | | QueryWrapper<CommunityEntity> wrapper = new QueryWrapper<>(); |
| | | System.out.println("wrapper = " + userExcel.getCommunityCode()); |
| | | wrapper.eq("is_deleted", 0).eq("code", userExcel.getCommunityCode()); |
| | | CommunityEntity one = SpringUtil.getBean(ICommunityService.class).getOne(wrapper); |
| | | if (null != one) { |
| | | String userId = user.getId().toString(); |
| | | if (!Strings.isBlank(one.getResPoliceUserId())) { |
| | | if (!one.getResPoliceUserId().contains(userId)) { |
| | | one.setResPoliceUserId(one.getResPoliceUserId() + "," + userId); |
| | | // 更新 |
| | | SpringUtil.getBean(ICommunityService.class).updateById(one); |
| | | } |
| | | } else { |
| | | one.setResPoliceUserId(userId); |
| | | // 更新 |
| | | SpringUtil.getBean(ICommunityService.class).updateById(one); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |