|
|
|
@ -24,6 +24,8 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.enums.DelFlagEnum; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.enums.EpdcDelFlagEnum; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
@ -70,6 +72,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.validation.constraints.NotBlank; |
|
|
|
import java.io.File; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
@ -99,6 +102,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
@Autowired |
|
|
|
private UserInvitationRecordService userInvitationRecordService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PartyMembersService partyMembersService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminFeignClient adminFeignClient; |
|
|
|
@Autowired |
|
|
|
@ -446,46 +452,71 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
@Override |
|
|
|
public Result<EpdcUserRegisterInfoResultDTO> checkUserRegisterState(EpdcCheckUserRegisterFromDTO fromDto) { |
|
|
|
|
|
|
|
UserDTO userDto = this.selectUserByWxInfo(fromDto.getOpenId(), fromDto.getWxUnionId()); |
|
|
|
|
|
|
|
// QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
|
|
|
|
// wrapper.eq(UserFieldConsant.WX_OPEN_ID, fromDto.getOpenId())
|
|
|
|
// .select(FieldConstant.ID, UserFieldConsant.NICKNAME, UserFieldConsant.FACE_IMG,
|
|
|
|
// FieldConstant.MOBILE, UserFieldConsant.REAL_NAME,
|
|
|
|
// FieldConstant.STATE, UserFieldConsant.PARTY_FLAG, UserFieldConsant.REMARK)
|
|
|
|
// .orderByDesc(FieldConstant.CREATED_TIME);
|
|
|
|
// List<UserEntity> userEntityList = this.baseDao.selectList(wrapper);
|
|
|
|
|
|
|
|
// 当前网格id
|
|
|
|
Long gridId = fromDto.getGridId(); |
|
|
|
// 当前用户
|
|
|
|
UserDTO userDto = null; |
|
|
|
// 当前用户id
|
|
|
|
String userId = null; |
|
|
|
// 当前用户扫码过的所有网格id
|
|
|
|
List<Long> gridIdList = Lists.newArrayList(); |
|
|
|
|
|
|
|
// 查询当前用户信息
|
|
|
|
List<UserDTO> userList = baseDao.selectListUserByWxForLogin(fromDto.getOpenId(), fromDto.getWxUnionId()); |
|
|
|
if (CollUtil.isNotEmpty(userList)) { |
|
|
|
userDto = userList.get(NumConstant.ZERO); |
|
|
|
userId = userDto.getId(); |
|
|
|
// 循环集合,确保集合中都是同一个用户的信息
|
|
|
|
for (UserDTO oneUserDto : userList) { |
|
|
|
if (!userId.equals(oneUserDto.getId())) { |
|
|
|
throw new RenException("用户信息异常,无法匹配唯一用户"); |
|
|
|
} |
|
|
|
gridIdList.add(oneUserDto.getGridId()); |
|
|
|
} |
|
|
|
} |
|
|
|
// 组装接口返回结果
|
|
|
|
EpdcUserRegisterInfoResultDTO resultDto = new EpdcUserRegisterInfoResultDTO(); |
|
|
|
resultDto.setGridId(fromDto.getGridId()); |
|
|
|
// 已注册
|
|
|
|
resultDto.setGridId(gridId); |
|
|
|
// 用户已注册
|
|
|
|
if (null != userDto) { |
|
|
|
resultDto.setUserDTO(userDto); |
|
|
|
// 获取用户关联当前网格信息
|
|
|
|
UserGridRelationDTO relationInfo = userGridRelationService.getUserRelationInfo(userDto.getId(), fromDto.getGridId()); |
|
|
|
// 未绑定当前网格
|
|
|
|
if (null == relationInfo) { |
|
|
|
resultDto.setRegisterState(NumConstant.ONE); |
|
|
|
} |
|
|
|
// 已绑定当前网格
|
|
|
|
else { |
|
|
|
if (gridIdList.contains(gridId)) { |
|
|
|
resultDto.setRegisterState(NumConstant.TWO); |
|
|
|
resultDto.setGrid(relationInfo.getGrid()); |
|
|
|
resultDto.setGrid(userDto.getGrid()); |
|
|
|
// 更新最后一次切换网格时间
|
|
|
|
UserGridRelationEntity userGridRelationEntity = new UserGridRelationEntity(); |
|
|
|
userGridRelationEntity.setId(relationInfo.getId()); |
|
|
|
userGridRelationEntity.setSwitchedTime(new Date()); |
|
|
|
userGridRelationService.updateById(userGridRelationEntity); |
|
|
|
updateGridSwitchedTime(userId, gridId); |
|
|
|
} else { |
|
|
|
resultDto.setRegisterState(NumConstant.ONE); |
|
|
|
} |
|
|
|
} |
|
|
|
// 未注册
|
|
|
|
else { |
|
|
|
resultDto.setRegisterState(NumConstant.ZERO); |
|
|
|
} |
|
|
|
|
|
|
|
return new Result<EpdcUserRegisterInfoResultDTO>().ok(resultDto); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户网格关系表,更新最后访问网格的时间 |
|
|
|
* |
|
|
|
* @param userId 用户id |
|
|
|
* @param gridId 网格id |
|
|
|
* @return void |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/2/26 14:59 |
|
|
|
*/ |
|
|
|
private void updateGridSwitchedTime(String userId, Long gridId) { |
|
|
|
UpdateWrapper<UserGridRelationEntity> wrapper = new UpdateWrapper<>(); |
|
|
|
wrapper.eq(FieldConstant.GRID_ID, gridId) |
|
|
|
.eq(UserFieldConsant.USER_ID, userId); |
|
|
|
|
|
|
|
UserGridRelationEntity entity = new UserGridRelationEntity(); |
|
|
|
entity.setSwitchedTime(new Date()); |
|
|
|
|
|
|
|
userGridRelationService.update(entity, wrapper); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result<EpdcUserRegisterInfoResultDTO> saveUserOrBindGrid(EpdcUserRegisterBindGridFormDTO fromDto) { |
|
|
|
@ -544,28 +575,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
String userId = userDto.getId(); |
|
|
|
String mobile = userDto.getMobile(); |
|
|
|
|
|
|
|
UserEntity userEntity = this.selectById(userId); |
|
|
|
if (null == userEntity) { |
|
|
|
return new Result().error("匹配用户失败"); |
|
|
|
} |
|
|
|
|
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>(); |
|
|
|
userWrapper.eq(FieldConstant.MOBILE, mobile) |
|
|
|
.ne(FieldConstant.ID, userId); |
|
|
|
Integer selectCount = this.baseDao.selectCount(userWrapper); |
|
|
|
if (selectCount > NumConstant.ZERO) { |
|
|
|
return new Result().error("手机号已被注册"); |
|
|
|
} |
|
|
|
//党员都需要查重
|
|
|
|
if (YesOrNoEnum.YES.value().equals(userDto.getPartyFlag())) { |
|
|
|
userWrapper = new QueryWrapper<>(); |
|
|
|
userWrapper.eq(UserFieldConsant.IDENTITY_NO, userDto.getIdentityNo()) |
|
|
|
.ne(FieldConstant.ID, userId); |
|
|
|
selectCount = this.baseDao.selectCount(userWrapper); |
|
|
|
if (selectCount > NumConstant.ZERO) { |
|
|
|
return new Result().error("身份证号已被注册"); |
|
|
|
} |
|
|
|
} |
|
|
|
UserEntity userEntity = selectUserForCheck(userId, |
|
|
|
YesOrNoEnum.YES.value().equals(userDto.getPartyFlag()) ? userDto.getIdentityNo() : null, |
|
|
|
mobile); |
|
|
|
|
|
|
|
return new Result<String>().ok(userEntity.getState()); |
|
|
|
} |
|
|
|
@ -823,29 +835,19 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @param formDto |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.UserDTO> |
|
|
|
* @Author yinzuomei |
|
|
|
* @Description 获取用户信息 合并上面的getByUnionId、getForLogin方法 |
|
|
|
* @Date 2019/12/7 13:58 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public Result<UserDTO> queryUserDto(EpdcAppQueryUserInfoFormDTO formDTO) { |
|
|
|
UserDTO userDto = this.selectUserByWxInfo(formDTO.getOpenId(), formDTO.getUnionId()); |
|
|
|
if (null != userDto) { |
|
|
|
QueryWrapper<UserGridRelationEntity> ugWrapper = new QueryWrapper<>(); |
|
|
|
ugWrapper.eq(UserFieldConsant.USER_ID, userDto.getId()) |
|
|
|
.orderByDesc(UserFieldConsant.SWITCHED_TIME); |
|
|
|
List<UserGridRelationDTO> gridRelations = userGridRelationService.listUserGrid(userDto.getId()); |
|
|
|
if (CollUtil.isNotEmpty(gridRelations)) { |
|
|
|
userDto.setGridId(gridRelations.get(NumConstant.ZERO).getGridId()); |
|
|
|
userDto.setGrid(gridRelations.get(NumConstant.ZERO).getGrid()); |
|
|
|
return new Result<UserDTO>().ok(userDto); |
|
|
|
} |
|
|
|
} |
|
|
|
return new Result(); |
|
|
|
public Result<UserDTO> queryUserDto(EpdcAppQueryUserInfoFormDTO formDto) { |
|
|
|
UserDTO user = selectUserByWxInfo(formDto.getOpenId(), formDto.getUnionId()); |
|
|
|
return new Result().ok(user); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param gridIdList |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.util.List < com.elink.esua.epdc.dto.epdc.result.EpdcGridUserResultDTO>> |
|
|
|
@ -872,56 +874,79 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
if (StringUtils.isBlank(openId)) { |
|
|
|
throw new RenException("openId不能为空"); |
|
|
|
} |
|
|
|
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>(); |
|
|
|
UserEntity userEntity = null; |
|
|
|
if (StringUtils.isNotBlank(unionId)) { |
|
|
|
wrapper.eq(UserFieldConsant.WX_UNION_ID, unionId); |
|
|
|
userEntity = this.baseDao.selectOne(wrapper); |
|
|
|
List<UserDTO> userList = baseDao.selectListUserByWxForLogin(openId, unionId); |
|
|
|
if (CollUtil.isEmpty(userList)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (null == userEntity) { |
|
|
|
wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(UserFieldConsant.WX_OPEN_ID, openId) |
|
|
|
.orderByDesc(FieldConstant.CREATED_TIME); |
|
|
|
userEntity = this.baseDao.selectOne(wrapper); |
|
|
|
UserDTO user = userList.get(NumConstant.ZERO); |
|
|
|
if (userList.size() > NumConstant.ONE) { |
|
|
|
String userId = user.getId(); |
|
|
|
// 循环集合,确保集合中都是同一个用户的信息
|
|
|
|
for (UserDTO oneUserDto : userList) { |
|
|
|
if (!userId.equals(oneUserDto.getId())) { |
|
|
|
throw new RenException("用户信息异常,无法匹配唯一用户"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return ConvertUtils.sourceToTarget(userEntity, UserDTO.class); |
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int countOthersByMobile(String mobile, String userId, boolean isVaild) { |
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>(); |
|
|
|
userWrapper.eq(FieldConstant.MOBILE, mobile).ne(FieldConstant.ID, userId); |
|
|
|
Integer count = this.baseDao.selectCount(userWrapper); |
|
|
|
if (isVaild && count > NumConstant.ZERO) { |
|
|
|
throw new RenException("手机号已被注册"); |
|
|
|
/** |
|
|
|
* 通过用户id,身份证号,手机号匹配用户,并校验手机号或身份证号是否被占用 |
|
|
|
* |
|
|
|
* @param userId 用户id,不能为空 |
|
|
|
* @param identityNo 身份证号,可为空 |
|
|
|
* @param mobile 手机号码,可为空 |
|
|
|
* @return com.elink.esua.epdc.entity.UserEntity |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/2/25 15:05 |
|
|
|
*/ |
|
|
|
private UserEntity selectUserForCheck(String userId, String identityNo, String mobile) { |
|
|
|
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
// del_flag = '0' and (id = ? or identity_no = ? or mobile = ?)
|
|
|
|
queryWrapper.eq(FieldConstant.DEL_FLAG, EpdcDelFlagEnum.NORMAL.value()) |
|
|
|
.and(i -> i.eq(FieldConstant.ID, userId) |
|
|
|
.or() |
|
|
|
.eq(StringUtils.isNotBlank(identityNo), UserFieldConsant.IDENTITY_NO, identityNo) |
|
|
|
.or() |
|
|
|
.eq(StringUtils.isNotBlank(mobile), FieldConstant.MOBILE, mobile)); |
|
|
|
List<UserEntity> userEntityList = baseDao.selectList(queryWrapper); |
|
|
|
if (CollUtil.isEmpty(userEntityList)) { |
|
|
|
throw new RenException("查询用户信息失败"); |
|
|
|
} |
|
|
|
return count; |
|
|
|
} |
|
|
|
|
|
|
|
private int countOthersByIdentityNo(String identityNo, String userId, boolean isVaild) { |
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>(); |
|
|
|
userWrapper.eq(UserFieldConsant.IDENTITY_NO, identityNo).ne(FieldConstant.ID, userId); |
|
|
|
Integer count = this.baseDao.selectCount(userWrapper); |
|
|
|
if (isVaild && count > NumConstant.ZERO) { |
|
|
|
throw new RenException("身份证号已被注册"); |
|
|
|
if (userEntityList.size() > NumConstant.ONE) { |
|
|
|
if (StringUtils.isNotBlank(mobile)) { |
|
|
|
for (UserEntity entity : userEntityList) { |
|
|
|
if (!userId.equals(entity.getId())) { |
|
|
|
if (StringUtils.isNotBlank(entity.getMobile()) && mobile.equals(entity.getMobile())) { |
|
|
|
throw new RenException("手机号码已被注册"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
throw new RenException("身份证号码已被注册"); |
|
|
|
} |
|
|
|
return count; |
|
|
|
return userEntityList.get(NumConstant.ZERO); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Result createPidemicInfo(EpdcAppPidemicCompleteInfoFromDTO completeInfoFromDto) { |
|
|
|
|
|
|
|
String userId = completeInfoFromDto.getUserId(); |
|
|
|
|
|
|
|
// 更新用户信息
|
|
|
|
UserEntity userEntity = selectById(userId); |
|
|
|
if (null == userEntity) { |
|
|
|
return new Result().error("查询用户信息失败"); |
|
|
|
String identityNo = ModuleUtils.replaceIllegalCharacter(completeInfoFromDto.getIdcard()).toUpperCase(); |
|
|
|
// 身份证号不合法,置空
|
|
|
|
if (StringUtils.isNotBlank(IdentityNoUtils.IdentityNoVerification(identityNo))) { |
|
|
|
identityNo = null; |
|
|
|
} |
|
|
|
|
|
|
|
String identityNo = completeInfoFromDto.getIdcard().trim().toUpperCase(); |
|
|
|
String realName = completeInfoFromDto.getName().trim(); |
|
|
|
String realName = ModuleUtils.replaceIllegalCharacter(completeInfoFromDto.getName()); |
|
|
|
|
|
|
|
// 更新用户信息
|
|
|
|
UserEntity userEntity = selectUserForCheck(userId, identityNo, completeInfoFromDto.getPhone()); |
|
|
|
|
|
|
|
if (userEntity.getPartyFlag().equals(YesOrNoEnum.YES.value())) { |
|
|
|
if (!(userEntity.getIdentityNo().equals(identityNo) && userEntity.getRealName().equals(realName))) { |
|
|
|
@ -929,15 +954,15 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
countOthersByIdentityNo(identityNo, userId, true); |
|
|
|
countOthersByMobile(completeInfoFromDto.getPhone(), userId, true); |
|
|
|
|
|
|
|
UserEntity updateUser = new UserEntity(); |
|
|
|
updateUser.setId(userId); |
|
|
|
updateUser.setRealName(realName); |
|
|
|
updateUser.setIdentityNo(identityNo); |
|
|
|
updateUser.setSex(IdentityNoUtils.getSex(identityNo)); |
|
|
|
updateUser.setBirthday(DateUtils.parse(IdentityNoUtils.getBirthday(identityNo), DateUtils.DATE_PATTERN)); |
|
|
|
// 有效的身份证号码
|
|
|
|
if (StringUtils.isNotBlank(identityNo)) { |
|
|
|
updateUser.setIdentityNo(identityNo); |
|
|
|
updateUser.setSex(IdentityNoUtils.getSex(identityNo)); |
|
|
|
updateUser.setBirthday(DateUtils.parse(IdentityNoUtils.getBirthday(identityNo), DateUtils.DATE_PATTERN)); |
|
|
|
} |
|
|
|
updateUser.setMobile(completeInfoFromDto.getPhone()); |
|
|
|
updateUser.setAddress(completeInfoFromDto.getHabitationDetail()); |
|
|
|
updateUser.setRentFlag(completeInfoFromDto.getIsRent()); |
|
|
|
@ -953,7 +978,10 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
updateUser.setState(AppUserStatesEnum.STATE_INFORMATION_PASSED.value()); |
|
|
|
String lastName = updateUser.getRealName().substring(NumConstant.ZERO, NumConstant.ONE); |
|
|
|
updateUser.setLastName(lastName); |
|
|
|
updateUser.setNickname(deptInfo.getGrid().concat("-").concat(lastName).concat(UserSexEnum.FEMALE.sex().equals(updateUser.getSex()) ? "女士" : "先生")); |
|
|
|
// 有身份证号码,能判断出性别,进行修改昵称
|
|
|
|
if (StringUtils.isNotBlank(identityNo)) { |
|
|
|
updateUser.setNickname(deptInfo.getGrid().concat("-").concat(lastName).concat(UserSexEnum.FEMALE.sex().equals(updateUser.getSex()) ? "女士" : "先生")); |
|
|
|
} |
|
|
|
updateUser.setDeptId(gridId); |
|
|
|
updateUser.setAllDeptIds(deptInfo.getAllDeptIds()); |
|
|
|
updateUser.setAllDeptNames(deptInfo.getAllDeptNames()); |
|
|
|
@ -963,7 +991,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
|
|
|
|
this.updateById(updateUser); |
|
|
|
|
|
|
|
String carNum = completeInfoFromDto.getCarNum(); |
|
|
|
String carNum = ModuleUtils.replaceIllegalCharacter(completeInfoFromDto.getCarNum()).toUpperCase(); |
|
|
|
|
|
|
|
if (YesOrNoEnum.YES.value().equals(completeInfoFromDto.getIsDriver()) |
|
|
|
&& StringUtils.isNotBlank(carNum)) { |
|
|
|
@ -985,9 +1013,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PartyMembersService partyMembersService; |
|
|
|
|
|
|
|
/*** |
|
|
|
* 临时生成注册党员 |
|
|
|
* @param file |
|
|
|
|