|
@@ -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;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 登陆
|