Bladeren bron

健康小屋-登录逻辑修改

huangzhiyong 6 jaren geleden
bovenliggende
commit
b879e9b9df

+ 5 - 4
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/LoginController.java

@ -37,7 +37,6 @@ public class LoginController extends EnvelopRestEndpoint {
    private LoginService loginService;
    @Autowired
    private RestTemplate restTemplate;
    private String clientId;
    @Autowired
    private WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService;
@ -86,10 +85,11 @@ public class LoginController extends EnvelopRestEndpoint {
    @GetMapping("/mobile/login")
    @ApiOperation(value = "手机登录注册")
    public ObjEnvelop register(
    public ObjEnvelop mobileLogin(
            HttpServletRequest request,
            @ApiParam(name = "clientId", value = "应用id", required = true)@RequestParam(required = true, name = "clientId") String clientId,
            @ApiParam(name = "username", value = "账号", required = true)@RequestParam(required = true, name = "username") String username,
            @ApiParam(name = "username", value = "短信验证码", required = true)@RequestParam(required = true, name = "captcha") String captcha) throws ManageException, ParseException {
            @ApiParam(name = "captcha", value = "短信验证码", required = true)@RequestParam(required = true, name = "captcha") String captcha) throws ManageException, ParseException {
        if (wlyyRedisVerifyCodeService.verification(clientId, username, captcha)) {
            User user = loginService.phoneLogin(request,username);
            ObjEnvelop envelop = new ObjEnvelop();
@ -107,9 +107,10 @@ public class LoginController extends EnvelopRestEndpoint {
    @ApiOperation(value = "i健康用户登陆")
    public ObjEnvelop ijkLogin(
            HttpServletRequest request,
            @ApiParam(name = "clientId", value = "应用id", required = true)@RequestParam(required = true, name = "clientId") String clientId,
            @ApiParam(name = "username", value = "账号", required = true)@RequestParam(required = true, name = "username") String username,
            @ApiParam(name = "password", value = "密码", required = true)@RequestParam(required = true, name = "password") String password) throws ManageException {
        User user = loginService.iJklogin(request,username, password);
        User user = loginService.iJklogin(request,clientId,username, password);
        if (user !=null) {
            ObjEnvelop envelop = new ObjEnvelop();
            envelop.setStatus(200);

+ 92 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/UserController.java

@ -0,0 +1,92 @@
package com.yihu.jw.healthyhouse.controller.user;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.constant.LoginInfo;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.healthyhouse.service.user.UserService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.wlyy.HouseUserContant;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
 *  用户相关 接口
 * @author HZY
 * @created 2018/9/19 17:29
 */
@RequestMapping("/user")
@RestController
public class UserController  extends EnvelopRestEndpoint {
    @Autowired
    private UserService userService;
    //用户列表
    @GetMapping("/userList")
    @ApiOperation(value = "i健康用户登陆")
    public PageEnvelop userList(
            @ApiParam(name = "page", value = "页数", required = true)@RequestParam(required = true, name = "page") Integer page,
            @ApiParam(name = "pageSize", value = "每页数量", required = true)@RequestParam(required = true, name = "pageSize") Integer pageSize,
            @ApiParam(name = "city", value = "所在市区", required = false)@RequestParam(required = false, name = "city") String city,
            @ApiParam(name = "activated", value = "用户状态", required = false)@RequestParam(required = false, name = "activated") String activated ,
            @ApiParam(name = "name", value = "姓名/手机号", required = false)@RequestParam(required = false, name = "name") String name ,
            @ApiParam(name = "order", value = "使用次数排序", required = false)@RequestParam(required = false, name = "order") String order  ) throws ManageException {
        Map<String, String> map = new HashMap<>();
        map.put("cityCode",city);
        map.put("activated",activated);
        map.put("name",name);
        map.put("telephone",name);
        Page<User> users = userService.userList(page, pageSize, map, order);
        return PageEnvelop.getSuccessListWithPage("列表获取成功",users.getContent(),page,pageSize,users.getTotalElements());
    }
    /**
     *  获取用户详情
     * @param userId
     * @return
     */
    @GetMapping("/userDetail")
    public ObjEnvelop userDetail(
            @ApiParam(name = "userId", value = "用户id", required = true)@RequestParam(required = true, name = "userId") String userId ) {
        User user = userService.findById(userId);
        return ObjEnvelop.getSuccess("获取成功",user);
    }
    /**
     *  用户激活
     * @param userId
     * @return
     */
    @GetMapping("/activateUser")
    public Envelop activeUser(
            @ApiParam(name = "userId", value = "用户id", required = true)@RequestParam(required = true, name = "userId") String userId ,
            @ApiParam(name = "operator", value = "操作者", required = true)@RequestParam(required = true, name = "operator") String operator ) {
         userService.updateStatus(userId,operator, HouseUserContant.activated_active);
        return ObjEnvelop.getSuccess("激活成功");
    }
    /**
     *  用户冻结
     * @param userId
     * @return
     */
    @GetMapping("/freezeUser")
    public Envelop freezeUser(
            @ApiParam(name = "userId", value = "用户id", required = true)@RequestParam(required = true, name = "userId") String userId ,
            @ApiParam(name = "operator", value = "操作者", required = true)@RequestParam(required = true, name = "operator") String operator ) {
        userService.updateStatus(userId,operator, HouseUserContant.activated_lock);
        return ObjEnvelop.getSuccess("冻结成功");
    }
}

+ 3 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/UserDao.java

@ -13,6 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
 */
public interface UserDao extends PagingAndSortingRepository<User, String>, JpaSpecificationExecutor<User> {
    @Query("from User u where u.id=?1 and u.activated<>0 ")
    User findById(String id);
    @Query("from User u where u.loginCode=?1 and u.activated<>0 ")
    User findByLoginCode(String loginCode);

+ 209 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/facility/Facility.java

@ -0,0 +1,209 @@
package com.yihu.jw.healthyhouse.model.facility;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 *  设施服务
 * @author HZY
 * @created 2018/9/20 8:48
 */
@Entity
@Table(name = "facility")
public class Facility extends UuidIdentityEntity{
    @Column(name = "code", nullable = false)
    private String code;
    @Column(name = "code", nullable = false)
    private String name;
    @Column(name = "category", nullable = false)
    private String category;
    @Column(name = "org_code", nullable = false)
    private String orgCode;
    @Column(name = "org_name")
    private String orgName;
    @Column(name = "user_id", nullable = false)
    private String userId;
    @Column(name = "user_telephone", nullable = false)
    private String userTelephone;
    @Column(name = "province_id", nullable = false)
    private String provinceId;
    @Column(name = "city_code", nullable = false)
    private String cityCode;
    @Column(name = "county_code", nullable = false)
    private String countyCode;
    @Column(name = "street", nullable = false)
    private String street;
    @Column(name = "service_day", nullable = false)
    private String serviceDay;
    @Column(name = "service_start_time", nullable = false)
    private String serviceStartTime;
    @Column(name = "service_end_time", nullable = false)
    private String serviceEndTime;
    @Column(name = "status", nullable = false)
    private String status;
    @Column(name = "longitude", nullable = false)
    private String longitude;
    @Column(name = "latitude", nullable = false)
    private String latitude;
    @Column(name = "img_path")
    private String imgPath;
    @Column(name = "remarks")
    private String remarks;
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCategory() {
        return category;
    }
    public void setCategory(String category) {
        this.category = category;
    }
    public String getOrgCode() {
        return orgCode;
    }
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getUserTelephone() {
        return userTelephone;
    }
    public void setUserTelephone(String userTelephone) {
        this.userTelephone = userTelephone;
    }
    public String getProvinceId() {
        return provinceId;
    }
    public void setProvinceId(String provinceId) {
        this.provinceId = provinceId;
    }
    public String getCityCode() {
        return cityCode;
    }
    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }
    public String getCountyCode() {
        return countyCode;
    }
    public void setCountyCode(String countyCode) {
        this.countyCode = countyCode;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getServiceDay() {
        return serviceDay;
    }
    public void setServiceDay(String serviceDay) {
        this.serviceDay = serviceDay;
    }
    public String getServiceStartTime() {
        return serviceStartTime;
    }
    public void setServiceStartTime(String serviceStartTime) {
        this.serviceStartTime = serviceStartTime;
    }
    public String getServiceEndTime() {
        return serviceEndTime;
    }
    public void setServiceEndTime(String serviceEndTime) {
        this.serviceEndTime = serviceEndTime;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getLongitude() {
        return longitude;
    }
    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }
    public String getLatitude() {
        return latitude;
    }
    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }
    public String getImgPath() {
        return imgPath;
    }
    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }
    public String getRemarks() {
        return remarks;
    }
    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
}

+ 39 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/facility/FacilityServices.java

@ -0,0 +1,39 @@
package com.yihu.jw.healthyhouse.model.facility;
import com.yihu.jw.entity.UuidIdentityEntity;
/**
 *  设施服务
 * @author HZY
 * @created 2018/9/20 8:48
 */
public class FacilityServices extends UuidIdentityEntity{
    private String code;
    private String name;
    private String type;//所属设施类型:系统字典设施类型
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

+ 11 - 4
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/user/User.java

@ -6,7 +6,6 @@ import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
@ -32,7 +31,7 @@ public class User extends UuidIdentityEntityWithOperator {
    @Column(name = "telephone", nullable = false)
    private String telephone;
    @Column(name = "last_login_time", length = 0)
    private String lastLoginTime;
    private Date lastLoginTime;
    @Column(name = "img_remote_path")
    private String imgRemotePath;   //头像地址
    @Column(name = "user_type", nullable = false)
@ -46,6 +45,8 @@ public class User extends UuidIdentityEntityWithOperator {
    @Column(name = "salt")
    private String salt; //加密种子
    @Column(name = "facility_used_count")
    private String facilityUsedCount;//设施使用次数
    public String getLoginCode() {
@ -104,11 +105,11 @@ public class User extends UuidIdentityEntityWithOperator {
        this.telephone = telephone;
    }
    public String getLastLoginTime() {
    public Date getLastLoginTime() {
        return lastLoginTime;
    }
    public void setLastLoginTime(String lastLoginTime) {
    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }
@ -160,5 +161,11 @@ public class User extends UuidIdentityEntityWithOperator {
        this.salt = salt;
    }
    public String getFacilityUsedCount() {
        return facilityUsedCount;
    }
    public void setFacilityUsedCount(String facilityUsedCount) {
        this.facilityUsedCount = facilityUsedCount;
    }
}

+ 11 - 14
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java

@ -31,7 +31,6 @@ public class LoginService {
    private UserService userService;
    @Autowired
    private RestTemplate restTemplate;
    private String clientId;
    /**
     *  手机验证码方式登录并自动注册
     * @param loginCode
@ -49,18 +48,17 @@ public class LoginService {
            user.setName(loginCode);
            user.setTelephone(loginCode);
            user.setPassword(LoginInfo.DEFAULT_PASSWORD);
            userService.saveOrUpdate(user,LoginInfo.SAVE_TYPE_PHONE);//设置默认密码123456
        }else {
            //已注册用户更改用户状态
            user.setActivated(HouseUserContant.activated_active);
            userService.saveOrUpdate(user,LoginInfo.SAVE_TYPE_PHONE);
        }
        request.getSession().setAttribute(LoginInfo.IS_LOGIN, true);
        request.getSession().setAttribute(LoginInfo.TOKEN, ""); //TODO token是否添加
        request.getSession().setAttribute(LoginInfo.LOGIN_NAME, user.getName());
        request.getSession().setAttribute(LoginInfo.LOGIN_CODE, user.getLoginCode());
        request.getSession().setAttribute(LoginInfo.USER_ID, user.getId());
        user.setLastLoginTime(new Date());
        userService.saveOrUpdate(user,LoginInfo.SAVE_TYPE_PHONE);
        return user;
    }
@ -73,12 +71,12 @@ public class LoginService {
     * @throws Exception
     */
    @Transactional(noRollbackForClassName = "ManageException")
    public User iJklogin(HttpServletRequest request, String loginCode, String password) throws ManageException {
    public User iJklogin(HttpServletRequest request,String clientId, String loginCode, String password) throws ManageException {
        //判断登陆信息是否正确
        User user = userService.findByCode(loginCode);
        if (user == null) {
            //i健康登录认证
            Map<String, Object> data = oauthIjkLogin(loginCode, password);
            Map<String, Object> data = oauthIjkLogin(clientId,loginCode, password);
            if (data!=null ) {
                user = new User();
                user.setPassword(password);
@ -87,7 +85,6 @@ public class LoginService {
                user.setGender((String) data.get("gender"));
                user.setIdCardNo((String) data.get("idcard"));
                user.setTelephone((String) data.get("mobile"));
                userService.saveOrUpdate(user,LoginInfo.SAVE_TYPE_IJK);
            }else {
                String message = "账号不存在";
@ -104,7 +101,8 @@ public class LoginService {
        request.getSession().setAttribute(LoginInfo.LOGIN_NAME, user.getName());
        request.getSession().setAttribute(LoginInfo.USER_ID, user.getId());
        user.setActivated(HouseUserContant.activated_active);
        userService.saveOrUpdate(user,"systemLogin");
        user.setLastLoginTime(new Date());
        userService.saveOrUpdate(user,LoginInfo.SAVE_TYPE_IJK);
        return user;
    }
@ -116,7 +114,7 @@ public class LoginService {
     * @return
     * @throws ManageException
     */
    public Map<String, Object> oauthIjkLogin(String username, String password) throws ManageException{
    public Map<String, Object> oauthIjkLogin(String clientId,String username, String password) throws ManageException{
        HashMap<String, Object> userDetail = null;
        HttpHeaders reqHeaders = new HttpHeaders();
        reqHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
@ -138,16 +136,15 @@ public class LoginService {
    /**
     *  登出
     * @param username
     * @param loginCode
     * @param password
     * @return
     * @throws Exception
     */
    @Transactional(noRollbackForClassName = "ManageException")
    public User logout(HttpServletRequest request, String username, String password) throws ManageException {
        Map<String, List> data = new HashMap<>();
    public User logout(HttpServletRequest request, String loginCode, String password) throws ManageException {
        //判断登陆信息是否正确
        User user = userService.findByCode(username);
        User user = userService.findByCode(loginCode);
        if (user == null) {
            //保存登陆信息
            String message = "账号不存在";
@ -159,7 +156,7 @@ public class LoginService {
            throw new ManageException(message);
        }
        request.getSession().removeAttribute(LoginInfo.IS_LOGIN);
        request.getSession().removeAttribute(LoginInfo.TOKEN); //TODO token是否添加
        request.getSession().removeAttribute(LoginInfo.TOKEN);
        request.getSession().removeAttribute(LoginInfo.LOGIN_NAME);
        request.getSession().removeAttribute(LoginInfo.USER_ID);
        user.setActivated(HouseUserContant.activated_offline);

+ 26 - 16
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/UserService.java

@ -32,6 +32,10 @@ public class UserService {
    @Autowired
    private UserDao userDao;
    public User findById(String id){
        return userDao.findById(id);
    }
    public User findByCode(String code){
        return userDao.findByLoginCode(code);
    }
@ -49,13 +53,24 @@ public class UserService {
     * @return
     * @throws ManageException
     */
    public Page<User> userList(Integer page, Integer pageSize, Map<String,String> map)throws ManageException {
    public Page<User> userList(Integer page, Integer pageSize, Map<String,String> map,String order)throws ManageException {
         order = order == null ? "ASC" :order;
        // 排序
        Sort sort = new Sort(Sort.Direction.DESC, "modifyDate");
        Sort sort = new Sort(Sort.Direction.DESC, "facilityUsedCount");
        // 分页信息
        PageRequest pageRequest = new PageRequest(page, pageSize, sort);
        PageRequest pageRequest = new PageRequest(page - 1, pageSize, sort);
        // 设置查询条件
        Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
        // 所在市区
        String cityCode = map.get("cityCode");
        if (!StringUtils.isEmpty(cityCode)) {
            filters.put("cityCode", new SearchFilter("cityCode", SearchFilter.Operator.EQ, cityCode));
        }
        // 激活状态
        String activated = map.get("activated");
        if (!StringUtils.isEmpty(activated)) {
            filters.put("activated", new SearchFilter("activated", SearchFilter.Operator.EQ, activated));
        }
        // 用户名称
        String name = map.get("name");
        if (!StringUtils.isEmpty(name)) {
@ -66,8 +81,7 @@ public class UserService {
        if (!StringUtils.isEmpty(mobile)) {
            filters.put("telephone", new SearchFilter("telephone", SearchFilter.Operator.LIKE, mobile));
        }
        // 激活状态
        filters.put("activated", new SearchFilter("activated", SearchFilter.Operator.EQ, HouseUserContant.activated_active));
        Specification<User> spec = DynamicSpecifications.bySearchFilter(filters.values(), User.class);
        return userDao.findAll(spec, pageRequest);
    }
@ -79,16 +93,15 @@ public class UserService {
     * @param userCode     修改者code
     */
    @Transactional
    public void updateStatus(String codes, String userCode,Integer status) {
    public void updateStatus(String id, String userCode,Integer status) {
        User user = userDao.findByLoginCode(userCode);
        String userName = user.getName();
        for(String code:codes.split(",")){
            User user1 = findByCode(code);
            User user1 = findById(id);
            user1.setActivated(status);
            user1.setUpdateUserName(userName);
            user1.setUpdateUser(userCode);
            userDao.save(user1);
        }
    }
    /**
@ -100,7 +113,6 @@ public class UserService {
     */
    public Envelop saveOrUpdate(User user, String userCode) throws ManageException {
        User loginUser = userDao.findByLoginCode(userCode);
        String userName = loginUser.getName();
        if(user.getId()==null){//保存
            //判断登陆账号是否存在
            User user1 = userDao.findByLoginCode(userCode);
@ -117,13 +129,11 @@ public class UserService {
            userDao.save(user);
            return Envelop.getSuccess("保存成功");
        }else{//修改
            User user1 = findByCode(user.getLoginCode());
//            String psd = MD5.GetMD5Code(oldPsd + user1.getSalt());
//            if(!user1.getPassword().equals(psd)){//判断密码是否相同
//                throw new ManageException("原密码错误");
//            }
            if (loginUser!=null) {
                String userName = loginUser.getName();
                user.setUpdateUserName(userName);
            }
            user.setUpdateUser(userCode);
            user.setUpdateUserName(userName);
            userDao.save(user);
            return Envelop.getSuccess("修改成功");
        }

+ 1 - 2
svr/svr-healthy-house/src/main/resources/application.yml

@ -70,8 +70,7 @@ fast-dfs:
---
spring:
  profiles: dev
  profiles: jwdev
  datasource:
    url: jdbc:mysql://172.19.103.77:3306/healthy_house?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
    username: root

+ 1 - 1
svr/svr-healthy-house/src/main/resources/bootstrap.yml

@ -12,7 +12,7 @@ spring:
---
spring:
  profiles: dev
  profiles: jwdev
##发现服务的地址
eureka: