10 changed files with 422 additions and 336 deletions
@ -0,0 +1,60 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.elink.esua.epdc.user.service; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
||||
|
import com.elink.esua.epdc.user.dto.CachingUserInfoDTO; |
||||
|
import com.elink.esua.epdc.user.dto.UserDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcAppQueryUserInfoFormDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcCheckUserRegisterFromDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcUserRegisterBindGridFormDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.result.EpdcUserRegisterInfoResultDTO; |
||||
|
import com.elink.esua.epdc.user.entity.UserDjylEntity; |
||||
|
|
||||
|
/** |
||||
|
* 用户信息表 |
||||
|
* |
||||
|
* @author qu qu@gmail.com |
||||
|
* @since v1.0.0 2019-09-02 |
||||
|
*/ |
||||
|
public interface UserDjylService extends BaseService<UserDjylEntity> { |
||||
|
|
||||
|
UserDTO get(String id); |
||||
|
|
||||
|
/** |
||||
|
* 党建小程序用户注册 |
||||
|
* @param userDto |
||||
|
* @return |
||||
|
*/ |
||||
|
Result npmUserRegister(UserDTO userDto); |
||||
|
|
||||
|
/** |
||||
|
* 党建小程序用户个人信息修改 |
||||
|
* @param userDto |
||||
|
* @return |
||||
|
*/ |
||||
|
Result<String> npmUserUpdate(UserDTO userDto); |
||||
|
|
||||
|
|
||||
|
Result<CachingUserInfoDTO> queryNpmCachingUserInfo(EpdcAppQueryUserInfoFormDTO formDTO); |
||||
|
|
||||
|
Result<EpdcUserRegisterInfoResultDTO> checkNamUserRegisterState(EpdcCheckUserRegisterFromDTO fromDto); |
||||
|
|
||||
|
Result<EpdcUserRegisterInfoResultDTO> namSaveUserOrBindGrid(EpdcUserRegisterBindGridFormDTO fromDto); |
||||
|
} |
@ -0,0 +1,266 @@ |
|||||
|
/** |
||||
|
* Copyright 2018 人人开源 https://www.renren.io
|
||||
|
* <p> |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* <p> |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* <p> |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.elink.esua.epdc.user.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
|
import com.elink.esua.epdc.commons.dynamic.datasource.annotation.DataSource; |
||||
|
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; |
||||
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
||||
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
||||
|
import com.elink.esua.epdc.dto.ParentAndAllDeptDTO; |
||||
|
import com.elink.esua.epdc.user.constant.UserFieldConsant; |
||||
|
import com.elink.esua.epdc.user.dao.UserAuthenticateHistoryDao; |
||||
|
import com.elink.esua.epdc.user.dao.UserDjylDao; |
||||
|
import com.elink.esua.epdc.user.datasources.DataSourceNames; |
||||
|
import com.elink.esua.epdc.user.dto.CachingUserInfoDTO; |
||||
|
import com.elink.esua.epdc.user.dto.UserDTO; |
||||
|
import com.elink.esua.epdc.user.dto.UserGridRelationDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcAppQueryUserInfoFormDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcCheckUserRegisterFromDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.form.EpdcUserRegisterBindGridFormDTO; |
||||
|
import com.elink.esua.epdc.user.dto.epdc.result.EpdcUserRegisterInfoResultDTO; |
||||
|
import com.elink.esua.epdc.user.entity.UserDjylEntity; |
||||
|
import com.elink.esua.epdc.user.entity.UserGridRelationEntity; |
||||
|
import com.elink.esua.epdc.user.entity.UserInvitationRecordEntity; |
||||
|
import com.elink.esua.epdc.user.feign.AdminFeignClient; |
||||
|
import com.elink.esua.epdc.user.service.UserDjylService; |
||||
|
import com.elink.esua.epdc.user.service.UserGridRelationService; |
||||
|
import com.elink.esua.epdc.user.service.UserInvitationRecordService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 用户信息表 |
||||
|
* |
||||
|
* @author qu qu@gmail.com |
||||
|
* @since v1.0.0 2019-09-02 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class UserDjylServiceImpl extends BaseServiceImpl<UserDjylDao, UserDjylEntity> implements UserDjylService { |
||||
|
|
||||
|
|
||||
|
@Resource |
||||
|
private AdminFeignClient adminFeignClient; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserGridRelationService userGridRelationService; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserInvitationRecordService userInvitationRecordService; |
||||
|
|
||||
|
@Resource |
||||
|
private UserAuthenticateHistoryDao userAuthenticateHistoryDao; |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public Result npmUserRegister(UserDTO userDto) { |
||||
|
//修改数据库结构
|
||||
|
Result<ParentAndAllDeptDTO> parentAndAllDeptDTOResult = adminFeignClient.getParentAndAllDept(userDto.getGridId().toString()); |
||||
|
if (!parentAndAllDeptDTOResult.success()) { |
||||
|
return new Result<EpdcUserRegisterInfoResultDTO>().error(parentAndAllDeptDTOResult.getMsg()); |
||||
|
} |
||||
|
|
||||
|
UserDjylEntity entity = ConvertUtils.sourceToTarget(userDto, UserDjylEntity.class); |
||||
|
insert(entity); |
||||
|
|
||||
|
UserGridRelationDTO dto = new UserGridRelationDTO(); |
||||
|
dto.setUserId(entity.getId()); |
||||
|
dto.setAllDeptNames(parentAndAllDeptDTOResult.getData().getAllDeptNames()); |
||||
|
dto.setAllDeptIds(parentAndAllDeptDTOResult.getData().getAllDeptIds()); |
||||
|
dto.setParentDeptNames(parentAndAllDeptDTOResult.getData().getParentDeptNames()); |
||||
|
dto.setParentDeptIds(parentAndAllDeptDTOResult.getData().getParentDeptIds()); |
||||
|
dto.setGridId(parentAndAllDeptDTOResult.getData().getGridId()); |
||||
|
dto.setGrid(parentAndAllDeptDTOResult.getData().getGrid()); |
||||
|
dto.setSwitchedTime(new Date()); |
||||
|
userGridRelationService.save(dto); |
||||
|
|
||||
|
userDto.setAllDeptIds(parentAndAllDeptDTOResult.getData().getAllDeptIds()); |
||||
|
return new Result().ok(userDto); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<String> npmUserUpdate(UserDTO userDto) { |
||||
|
//修改数据库结构
|
||||
|
Result<ParentAndAllDeptDTO> parentAndAllDeptDTOResult = adminFeignClient.getParentAndAllDept(userDto.getGridId().toString()); |
||||
|
if (!parentAndAllDeptDTOResult.success()) { |
||||
|
return new Result<String>().error(parentAndAllDeptDTOResult.getMsg()); |
||||
|
} |
||||
|
|
||||
|
UserDjylEntity entity = ConvertUtils.sourceToTarget(userDto, UserDjylEntity.class); |
||||
|
entity.setId(userDto.getUserId()); |
||||
|
baseDao.updateById(entity); |
||||
|
|
||||
|
UserGridRelationEntity entity1 = new UserGridRelationEntity(); |
||||
|
entity1.setAllDeptIds(parentAndAllDeptDTOResult.getData().getAllDeptIds()); |
||||
|
entity1.setAllDeptNames(parentAndAllDeptDTOResult.getData().getAllDeptNames()); |
||||
|
entity1.setParentDeptIds(parentAndAllDeptDTOResult.getData().getParentDeptIds()); |
||||
|
entity1.setParentDeptNames(parentAndAllDeptDTOResult.getData().getParentDeptNames()); |
||||
|
entity1.setGridId(parentAndAllDeptDTOResult.getData().getGridId()); |
||||
|
entity1.setGrid(parentAndAllDeptDTOResult.getData().getGrid()); |
||||
|
LambdaUpdateWrapper<UserGridRelationEntity> updateWrapper = Wrappers.lambdaUpdate(); |
||||
|
updateWrapper.eq(UserGridRelationEntity::getUserId, entity.getId()); |
||||
|
userGridRelationService.update(entity1, updateWrapper); |
||||
|
|
||||
|
return new Result<String>().ok("修改成功"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<CachingUserInfoDTO> queryNpmCachingUserInfo(EpdcAppQueryUserInfoFormDTO formDTO) { |
||||
|
if (StringUtils.isBlank(formDTO.getOpenId())) { |
||||
|
throw new RenException("openId不能为空"); |
||||
|
} |
||||
|
return new Result<CachingUserInfoDTO>().ok(baseDao.selectNpmCachingUserInfoDTO(formDTO.getOpenId(), formDTO.getUnionId())); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public Result<EpdcUserRegisterInfoResultDTO> namSaveUserOrBindGrid(EpdcUserRegisterBindGridFormDTO fromDto) { |
||||
|
UserDTO formUserDto = fromDto.getUserDTO(); |
||||
|
UserGridRelationDTO userGridRel = fromDto.getGridRelationDTO(); |
||||
|
// 用户注册
|
||||
|
if (NumConstant.ZERO == fromDto.getRegisterState()) { |
||||
|
UserDjylEntity userEntity = ConvertUtils.sourceToTarget(formUserDto, UserDjylEntity.class); |
||||
|
if (baseDao.insert(userEntity) > 0) { |
||||
|
formUserDto.setId(userEntity.getId()); |
||||
|
} else { |
||||
|
return new Result<EpdcUserRegisterInfoResultDTO>().error("用户注册失败"); |
||||
|
} |
||||
|
} |
||||
|
userGridRel.setUserId(formUserDto.getId()); |
||||
|
//修改数据库结构
|
||||
|
Result<ParentAndAllDeptDTO> parentAndAllDeptDTOResult = adminFeignClient.getParentAndAllDept(userGridRel.getGridId().toString()); |
||||
|
if (!parentAndAllDeptDTOResult.success()) { |
||||
|
return new Result<EpdcUserRegisterInfoResultDTO>().error(parentAndAllDeptDTOResult.getMsg()); |
||||
|
} |
||||
|
userGridRel.setAllDeptNames(parentAndAllDeptDTOResult.getData().getAllDeptNames()); |
||||
|
userGridRel.setAllDeptIds(parentAndAllDeptDTOResult.getData().getAllDeptIds()); |
||||
|
userGridRel.setParentDeptNames(parentAndAllDeptDTOResult.getData().getParentDeptNames()); |
||||
|
userGridRel.setParentDeptIds(parentAndAllDeptDTOResult.getData().getParentDeptIds()); |
||||
|
// 用户绑定网格
|
||||
|
userGridRelationService.save(userGridRel); |
||||
|
// 组装用户注册信息
|
||||
|
EpdcUserRegisterInfoResultDTO resultDto = new EpdcUserRegisterInfoResultDTO(); |
||||
|
resultDto.setRegisterState(NumConstant.TWO); |
||||
|
resultDto.setGrid(userGridRel.getGrid()); |
||||
|
resultDto.setGridId(userGridRel.getGridId()); |
||||
|
resultDto.setUserDTO(formUserDto); |
||||
|
|
||||
|
// 记录邀请记录
|
||||
|
if (StringUtils.isNotEmpty(fromDto.getInviteUserId())) { |
||||
|
UserInvitationRecordEntity entity = new UserInvitationRecordEntity(); |
||||
|
entity.setUserId(formUserDto.getId()); |
||||
|
entity.setInviteUserId(fromDto.getInviteUserId()); |
||||
|
// 获取用户信息
|
||||
|
UserDTO userDto = this.get(formUserDto.getId()); |
||||
|
entity.setRegisterTime(userDto.getRegisterTime()); |
||||
|
entity.setGrid(userGridRel.getGrid()); |
||||
|
entity.setGridId(userGridRel.getGridId()); |
||||
|
userInvitationRecordService.insert(entity); |
||||
|
} |
||||
|
|
||||
|
return new Result<EpdcUserRegisterInfoResultDTO>().ok(resultDto); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<EpdcUserRegisterInfoResultDTO> checkNamUserRegisterState(EpdcCheckUserRegisterFromDTO fromDto) { |
||||
|
Long gridId = fromDto.getGridId(); |
||||
|
UserDTO userDto = null; |
||||
|
String userId = null; |
||||
|
List<Long> gridIdList = null; |
||||
|
// 查询当前用户信息
|
||||
|
List<UserDTO> userList = baseDao.selectUserByWxForLogin(fromDto.getOpenId(), fromDto.getWxUnionId()); |
||||
|
if (null != userList.get(NumConstant.ZERO)) { |
||||
|
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(gridId); |
||||
|
// 用户已注册
|
||||
|
if (null != userDto) { |
||||
|
resultDto.setUserDTO(userDto); |
||||
|
// 已绑定当前网格
|
||||
|
if (gridIdList.contains(gridId)) { |
||||
|
resultDto.setRegisterState(NumConstant.TWO); |
||||
|
resultDto.setGrid(userDto.getGrid()); |
||||
|
// 更新最后一次切换网格时间
|
||||
|
updateGridSwitchedTime(userId, gridId); |
||||
|
} else { |
||||
|
resultDto.setRegisterState(NumConstant.ONE); |
||||
|
} |
||||
|
} |
||||
|
// 未注册
|
||||
|
else { |
||||
|
resultDto.setRegisterState(NumConstant.ZERO); |
||||
|
} |
||||
|
return new Result<EpdcUserRegisterInfoResultDTO>().ok(resultDto); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@DataSource(value = DataSourceNames.FIRST) |
||||
|
public UserDTO get(String id) { |
||||
|
UserDjylEntity entity = baseDao.selectById(id); |
||||
|
UserDTO resultDTO = ConvertUtils.sourceToTarget(entity, UserDTO.class); |
||||
|
Integer submitNum = userAuthenticateHistoryDao.countAuthenticateHistory(id, null); |
||||
|
resultDTO.setTotalSubmitNum(submitNum == null ? 0 : submitNum); |
||||
|
//0 未通过1通过
|
||||
|
Integer failNum = userAuthenticateHistoryDao.countAuthenticateHistory(id, NumConstant.ZERO_STR); |
||||
|
resultDTO.setTotalFailNum(failNum == null ? 0 : failNum); |
||||
|
Integer passSubmitNum = userAuthenticateHistoryDao.countAuthenticateHistory(id, NumConstant.ONE_STR); |
||||
|
resultDTO.setTotalPassSubmitNum(passSubmitNum == null ? 0 : passSubmitNum); |
||||
|
return 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); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue