Forráskód Böngészése

增加转换接口v7

xiewenjie 3 éve
szülő
commit
25fde7d77a

+ 0 - 36
sxz-core/src/main/java/com/fdkk/sxz/system/controller/SysLoginController.java

@@ -1,8 +1,6 @@
 package com.fdkk.sxz.system.controller;
 
 import cn.hutool.captcha.GifCaptcha;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -12,7 +10,6 @@ import com.fdkk.sxz.base.BaseController;
 import com.fdkk.sxz.base.Result;
 import com.fdkk.sxz.constant.Constant;
 import com.fdkk.sxz.constant.ResponseConstant;
-import com.fdkk.sxz.entity.LoginCheckEntity;
 import com.fdkk.sxz.entity.system.Resource;
 import com.fdkk.sxz.entity.system.Role;
 import com.fdkk.sxz.entity.system.User;
@@ -23,7 +20,6 @@ import com.fdkk.sxz.system.service.IResourceService;
 import com.fdkk.sxz.system.service.IUserRoleService;
 import com.fdkk.sxz.system.service.IUserService;
 import com.fdkk.sxz.util.RedisUtil;
-import com.fdkk.sxz.webApi.service.ILoginCheckService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
@@ -62,8 +58,6 @@ public class SysLoginController extends BaseController {
 
     @Autowired
     private IUserService userService;
-    @Autowired
-    private ILoginCheckService loginCheckService;
 
     @Autowired
     private IUserRoleService userRoleService;
@@ -103,36 +97,6 @@ public class SysLoginController extends BaseController {
         }
     }
 
-    @PostMapping("/applogin")
-    @NoAuthentication
-    @ApiOperation(value = "执行登录先验证是否在时间范围内", notes = "返回token")
-    public Result<String> applogin(@RequestBody LoginUser loginUser, HttpServletRequest request) throws Exception {
-        String userAccount = loginUser.getUserAccount();
-        String userPassword = loginUser.getUserPassword();
-        if (StringUtils.isEmpty(userAccount) || StringUtils.isEmpty(userPassword)) {
-            return error(ResponseConstant.PARAM_ERROR);
-        }
-
-        LoginCheckEntity checkEntity = loginCheckService.findByUserAccount(userAccount);
-        if (ObjectUtil.isNotNull(checkEntity)) {
-            if (!DateUtil.isIn(DateUtil.parse(DateUtil.now()), checkEntity.getStartExpirationTime(),
-                    checkEntity.getEndExpirationTime()
-            )) {
-                return error(ResponseConstant.ACCOUNT_EXPIRED);
-            }
-        }
-        // 查询用户是否存在
-        QueryWrapper<User> ew = new QueryWrapper<>();
-        ew.eq("user_account", userAccount).or().eq("user_mobile", userAccount).or().eq("user_email", userAccount);
-        User user = userService.getOne(ew);
-        if (StringUtils.isEmpty(user) || !BCrypt.checkpw(user.getUserAccount() + userPassword, user.getUserPassword())) {
-            return error(ResponseConstant.INVALID_USERNAME_PASSWORD);
-        }
-        String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
-        long expTime = expireTime.get(Constant.ExpTimeType.WEB);
-        redisUtil.setEx("userLoginToken:" + token, JSON.toJSONString(user), expTime, TimeUnit.MILLISECONDS);
-        return successPut(token);
-    }
 
     @PostMapping("/login")
     @NoAuthentication

+ 84 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/LoginController.java

@@ -1,5 +1,6 @@
 package com.fdkk.sxz.webApi.controller;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -10,6 +11,8 @@ import com.fdkk.sxz.annotation.log.AroundLog;
 import com.fdkk.sxz.base.BaseController;
 import com.fdkk.sxz.base.Result;
 import com.fdkk.sxz.constant.CodeConstant;
+import com.fdkk.sxz.constant.ResponseConstant;
+import com.fdkk.sxz.entity.LoginCheckEntity;
 import com.fdkk.sxz.entity.StatisticsEntity;
 import com.fdkk.sxz.system.dto.CreateUser;
 import com.fdkk.sxz.system.service.IUserService;
@@ -17,6 +20,7 @@ import com.fdkk.sxz.util.DateUtil;
 import com.fdkk.sxz.util.OkHttpUtils;
 import com.fdkk.sxz.util.RedisUtil;
 import com.fdkk.sxz.vo.request.RequestUser;
+import com.fdkk.sxz.webApi.service.ILoginCheckService;
 import com.fdkk.sxz.webApi.service.IStatisticsService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -54,6 +58,86 @@ public class LoginController extends BaseController {
 
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private ILoginCheckService loginCheckService;
+
+    /**
+     * 登陆
+     *
+     * @param user
+     * @return
+     */
+    @ApiOperation("登陆")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "phoneNum", value = "用户名", dataType = "String"),
+            @ApiImplicitParam(name = "password", value = "密码", dataType = "String")})
+    @RequestMapping(value = "/applogin", method = RequestMethod.POST)
+    @NoAuthentication
+    @AroundLog(name = "登陆")
+    @ResponseBody
+    public JSONObject applogin(@RequestBody RequestUser user) {
+        JSONObject resData = new JSONObject();
+        if (StrUtil.isEmpty(user.getPhoneNum())) {
+            resData.put("code", -1);
+            resData.put("msg", "账户不能为空");
+            return resData;
+        }
+        if (StrUtil.isEmpty(user.getPassword())) {
+            resData.put("code", -1);
+            resData.put("msg", "密码不能为空");
+            return resData;
+        }
+        LoginCheckEntity checkEntity = loginCheckService.findByUserAccount(user.getPhoneNum());
+        if (ObjectUtil.isNotNull(checkEntity)) {
+            if (!cn.hutool.core.date.DateUtil.isIn(cn.hutool.core.date.DateUtil.parse(cn.hutool.core.date.DateUtil.now()), checkEntity.getStartExpirationTime(),
+                    checkEntity.getEndExpirationTime()
+            )) {
+                resData.put("code", -1);
+                resData.put("msg", ResponseConstant.ACCOUNT_EXPIRED.getMsg());
+                return resData;
+            }
+        }
+
+        JSONObject data = new JSONObject();
+        data.put("phoneNum", user.getPhoneNum());
+//        data.put("password", Base64Converter.addText(Base64Converter.encode(user.getPassword())));
+        data.put("password", user.getPassword());
+        data.put("cameraType", 4);
+
+        JSONObject object = OkHttpUtils.httpPostJson(mainUrl + "api/sso/user/login", data.toJSONString(), null);
+        if ("88888888888".equals(user.getPhoneNum())) {
+            object.put("isAdmin", 1);
+        } else {
+            object.put("isAdmin", 0);
+        }
+        int code = object.getInteger("code").intValue();
+        if (code != 0) {
+            return object;
+        }
+        CreateUser createUser = new CreateUser();
+        createUser.setUserName(object.getJSONObject("data").getJSONObject("user").getString("nickName"));
+        createUser.setUserAccount(user.getPhoneNum());
+        createUser.setUserMobile(user.getPhoneNum());
+        createUser.setFdkkId(object.getJSONObject("data").getJSONObject("user").getLong("id"));
+        boolean usersExists = userService.getUsersExists(createUser);
+        if (!usersExists) {
+            userService.createUser(createUser);
+        }
+        LambdaQueryWrapper<StatisticsEntity> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(StatisticsEntity::getStatisticsDate, DateUtil.date2String(new Date(), DateUtil.YYYY_MM_DD_DATE_FORMAT));
+        List<StatisticsEntity> statisticsEntityList = statisticsService.list(wrapper);
+        if (statisticsEntityList.size() > 0) {
+            StatisticsEntity statisticsEntity = statisticsEntityList.get(0);
+            statisticsEntity.setLoginNum(statisticsEntity.getLoginNum() + 1);
+            statisticsService.updateById(statisticsEntity);
+        } else {
+            StatisticsEntity statisticsEntity = new StatisticsEntity();
+            statisticsEntity.setLoginNum(1);
+            statisticsEntity.setStatisticsDate(DateUtil.date2String(new Date(), DateUtil.YYYY_MM_DD_DATE_FORMAT));
+            statisticsService.save(statisticsEntity);
+        }
+        return object;
+    }
 
     /**
      * 登陆