Commit 545beac6 authored by mlchun's avatar mlchun

1.注册、登录

parent 6de52e01
package io.hmit.controller;
import ch.qos.logback.core.pattern.ConverterUtil;
import com.alibaba.fastjson.JSON;
import io.hmit.annotation.Login;
import io.hmit.annotation.LoginUser;
import io.hmit.common.utils.ConvertUtils;
......@@ -8,21 +9,23 @@ import io.hmit.common.utils.Result;
import io.hmit.dto.OrgUserInfoDTO;
import io.hmit.dto.ServiceUserInfoDTO;
import io.hmit.dto.UserInfoDTO;
import io.hmit.dto.UserRegisterDTO;
import io.hmit.entity.UserEntity;
import io.hmit.modules.serviceOrder.dto.PensionOldFamilyDTO;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
import io.hmit.modules.serviceOrder.dto.PensionOrderEvaluationDTO;
import io.hmit.modules.serviceOrder.service.PensionOldFamilyService;
import io.hmit.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
/**
......@@ -75,4 +78,25 @@ public class UserController {
return new Result<ServiceUserInfoDTO>().ok(serviceUser);
}
@GetMapping("checkIdCardNo")
@ApiOperation("注册身份证ID查询")
public Result<UserRegisterDTO> checkIdCardNo(@RequestParam("idCardNo") Long idCardNo){
UserRegisterDTO userRegisterDTO = userService.getUserInfoByIdCardNo(idCardNo);
return new Result<UserRegisterDTO>().ok(userRegisterDTO);
}
@PostMapping("registerUser")
@ApiOperation("注册用户")
public Result registerUser(@RequestBody String dto){
UserRegisterDTO userRegisterDTO = null;
try {
userRegisterDTO = JSON.parseObject(URLDecoder.decode(dto,"UTF-8"), UserRegisterDTO.class);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
userService.registerUser(userRegisterDTO);
return new Result();
}
}
......@@ -3,6 +3,7 @@ package io.hmit.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.dto.OrgUserInfoDTO;
import io.hmit.dto.ServiceUserInfoDTO;
import io.hmit.dto.UserRegisterDTO;
import io.hmit.entity.UserEntity;
import io.hmit.modules.serviceOrder.dto.UserRoleInfoDTO;
import org.apache.ibatis.annotations.Mapper;
......@@ -31,4 +32,6 @@ public interface UserDao extends BaseDao<UserEntity> {
List<UserRoleInfoDTO> getUserRoleInfo(Long userId);
UserRegisterDTO getUserInfoByIdCardNo(Long idCardNo);
}
package io.hmit.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.hmit.modules.serviceOrder.dto.PensionOldFamilyDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @author Eve
* @email mengmengeve@gmail.com
* @create 2021/1/27
*/
@Data
@ApiModel(value = "用户注册信息")
public class UserRegisterDTO {
@JsonIgnore
private Long id;
/**
* 用户名
*/
@ApiModelProperty(value = "姓名")
private String username;
/**
* 手机号
*/
@ApiModelProperty(value = "手机号")
private String mobile;
/**
* 身份证号码
*/
@ApiModelProperty(value = "身份证号码")
private Long idCardNo;
/**
* 性别
*/
@ApiModelProperty(value = "性别")
private String gender;
/**
* 地址_地区
*/
@ApiModelProperty(value = "地址_地区")
private String addressArea;
/**
* 详细地址
*/
@ApiModelProperty(value = "详细地址")
private String address;
/**
* 所属社区Id
*/
@ApiModelProperty(value = "所属社区ID")
private Long communityId;
/**
* 所属社区名称
*/
@ApiModelProperty(value = "所属社区名称")
private String communityName;
/**
* 微信openid
*/
@ApiModelProperty(value = "微信openid")
private String openid;
/**
* 注册角色
*/
@ApiModelProperty(value = "注册角色")
private Long userRole;
}
......@@ -90,5 +90,9 @@ public class UserEntity implements Serializable {
* 所属社区Id
*/
private Long communityId;
/**
* 身份证号码
*/
private Long idCardNo;
}
......@@ -12,5 +12,5 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface RoleUserDao extends BaseDao<RoleUserEntity> {
}
\ No newline at end of file
......@@ -37,10 +37,19 @@ public class PensionOldFamilyDTO implements Serializable {
@ApiModelProperty(value = "家属与老人的关系")
private String familyMemberRole;
@ApiModelProperty(value = "性别")
private String gender;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "身份证号")
private String idCardNo;
@ApiModelProperty(value = "地址_地区")
private String addressArea;
@ApiModelProperty(value = "详细地址")
private String address;
}
\ No newline at end of file
......@@ -12,4 +12,6 @@ import io.hmit.modules.serviceOrder.entity.RoleUserEntity;
*/
public interface RoleUserService extends CrudService<RoleUserEntity, RoleUserDTO> {
void addRelation(Long roleId, Long userId);
}
\ No newline at end of file
......@@ -33,4 +33,11 @@ public class RoleUserServiceImpl extends CrudServiceImpl<RoleUserDao, RoleUserEn
}
@Override
public void addRelation(Long roleId, Long userId) {
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setRoleId(roleId);
roleUserEntity.setUserId(userId);
insert(roleUserEntity);
}
}
......@@ -2,10 +2,7 @@ package io.hmit.service;
import io.hmit.common.page.PageData;
import io.hmit.common.service.BaseService;
import io.hmit.dto.LoginDTO;
import io.hmit.dto.OrgUserInfoDTO;
import io.hmit.dto.ServiceUserInfoDTO;
import io.hmit.dto.UserInfoDTO;
import io.hmit.dto.*;
import io.hmit.entity.UserEntity;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
......@@ -48,4 +45,8 @@ public interface UserService extends BaseService<UserEntity> {
ServiceUserInfoDTO getServiceUserByUserId(Long userId);
UserRegisterDTO getUserInfoByIdCardNo(Long idCardNo);
void registerUser(UserRegisterDTO dto);
}
......@@ -9,24 +9,19 @@ import io.hmit.common.service.impl.BaseServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.validator.AssertUtils;
import io.hmit.dao.UserDao;
import io.hmit.dto.LoginDTO;
import io.hmit.dto.OrgUserInfoDTO;
import io.hmit.dto.ServiceUserInfoDTO;
import io.hmit.dto.UserInfoDTO;
import io.hmit.dto.*;
import io.hmit.entity.TokenEntity;
import io.hmit.entity.UserEntity;
import io.hmit.modules.serviceOrder.dto.UserRoleInfoDTO;
import io.hmit.modules.serviceOrder.service.PensionOldFamilyService;
import io.hmit.modules.serviceOrder.service.RoleUserService;
import io.hmit.service.TokenService;
import io.hmit.service.UserService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implements UserService {
......@@ -40,6 +35,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
@Autowired
private PensionOldFamilyService pensionOldFamilyService;
@Autowired
private RoleUserService roleUserService;
@Override
public UserEntity getByMobile(String mobile) {
return baseDao.getUserByMobile(mobile);
......@@ -129,4 +127,37 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
return userDao.getServiceUserByUserId(userId);
}
@Override
public UserRegisterDTO getUserInfoByIdCardNo(Long idCardNo) {
return userDao.getUserInfoByIdCardNo(idCardNo);
}
@Override
public void registerUser(UserRegisterDTO dto) {
UserRegisterDTO userRegisterDTO = getUserInfoByIdCardNo(dto.getIdCardNo());
UserEntity userEntity;
if (null != userRegisterDTO) {
userEntity = getUserByUserId(userRegisterDTO.getId());
userEntity.setOpenid(dto.getOpenid());
updateById(userEntity);
roleUserService.addRelation(dto.getUserRole(), userRegisterDTO.getId());
}else {
userEntity = new UserEntity();
userEntity.setUsername(dto.getUsername());
userEntity.setMobile(dto.getMobile());
userEntity.setPassword(DigestUtils.sha256Hex(dto.getIdCardNo().toString()));
userEntity.setAddress(dto.getAddress());
userEntity.setAddressArea(dto.getAddressArea());
userEntity.setCommunityId(dto.getCommunityId());
userEntity.setCreateDate(new Date());
userEntity.setIdCardNo(dto.getIdCardNo());
userEntity.setCommunityName(dto.getCommunityName());
userEntity.setGender(Integer.parseInt(dto.getIdCardNo().toString().substring(16, 17)) % 2 == 1 ? "男" : "女");
userEntity.setOpenid(dto.getOpenid());
insert(userEntity);
UserEntity byOpenId = getByOpenId(dto.getOpenid());
roleUserService.addRelation(dto.getUserRole(), byOpenId.getId());
}
}
}
\ No newline at end of file
......@@ -39,4 +39,9 @@
WHERE tru.role_id = tr.id AND tru.user_id = #{userId};
</select>
<select id="getUserInfoByIdCardNo" resultType="io.hmit.dto.UserRegisterDTO">
SELECT * FROM tb_user
WHERE tb_user.id_card_no = #{idCardNo};
</select>
</mapper>
\ No newline at end of file
......@@ -18,7 +18,7 @@
<select id="findByOldId" resultType="io.hmit.modules.serviceOrder.dto.PensionOldFamilyDTO">
SELECT tu.id, pof.old_id, pof.parent_role, pof.family_member_id, tu.username AS familyMemberName,
pof.family_member_role, tu.mobile, tu.id_card_no
pof.family_member_role, tu.mobile, tu.id_card_no, tu.address_area, tu.address, tu.gender
FROM pension_old_family pof, tb_user tu
WHERE pof.family_member_id = tu.id and pof.old_id = #{oldId}
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment