From 17c774c9c13febdcff654ffd6bbabd313c37a3ee Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Fri, 20 Oct 2023 09:24:09 +0800
Subject: [PATCH] chore:补充提交

---
 screen-api/pom.xml                                                              |    6 +
 screen-api/src/main/java/com/moral/api/pojo/query/AppUserCond.java              |   31 ++++++
 screen-api/src/main/java/com/moral/api/utils/WechatUtils.java                   |   19 +++
 screen-api/src/main/java/com/moral/api/service/UserService.java                 |    6 +
 screen-api/src/main/java/com/moral/api/controller/AppUserController.java        |   63 ++----------
 screen-api/src/main/java/com/moral/api/pojo/vo/allocation/AllocationFindVo.java |    3 
 screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java        |   82 ++++++++++++++++
 screen-api/src/main/java/com/moral/api/entity/User.java                         |    3 
 screen-api/src/main/java/com/moral/api/pojo/enums/AppAllocationStateEnum.java   |   59 +++++++++++
 screen-api/src/main/java/com/moral/api/service/impl/AllocationServiceImpl.java  |   20 +++
 10 files changed, 235 insertions(+), 57 deletions(-)

diff --git a/screen-api/pom.xml b/screen-api/pom.xml
index 2c3b9ac..76c0098 100644
--- a/screen-api/pom.xml
+++ b/screen-api/pom.xml
@@ -11,6 +11,12 @@
     <artifactId>screen-api</artifactId>
 
     <dependencies>
+        <!-- http��������������������� -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.2</version>
+        </dependency>
         <dependency>
             <groupId>org.moral</groupId>
             <artifactId>screen-common</artifactId>
diff --git a/screen-api/src/main/java/com/moral/api/controller/AppUserController.java b/screen-api/src/main/java/com/moral/api/controller/AppUserController.java
index 74d50c9..af15b1c 100644
--- a/screen-api/src/main/java/com/moral/api/controller/AppUserController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/AppUserController.java
@@ -6,6 +6,7 @@
 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.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -14,17 +15,11 @@
 
 import java.util.Map;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.moral.api.entity.AppUser;
-import com.moral.api.exception.BusinessException;
-import com.moral.api.mapper.AppUserMapper;
 import com.moral.api.service.UserService;
-import com.moral.api.utils.WechatUtils;
+
 import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
+
 
 @Slf4j
 @Api(tags = {"���������������������"})
@@ -35,11 +30,10 @@
     @Autowired
     private UserService userService;
 
-    @Autowired
-    private AppUserMapper appUserMapper;
 
-    @ApiOperation(value = "������������", notes = "������������")
-    @PostMapping("login")
+
+    @ApiOperation(value = "������������")
+    @PostMapping("logins")
     public ResultMessage login(@RequestBody Map<String, Object> parameters) {
         if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
@@ -53,45 +47,12 @@
     }
 
 
-    @PostMapping("/wx/login")
-    @ApiOperation(value = "���������������", notes = "���������������")
-    public ResultMessage userLogin(@RequestParam(value = "code", required = false) String code,
-                        @RequestParam(value = "rawData", required = false) String rawData,
-                        @RequestParam(value = "signature", required = false) String signature) {
-        // ������������������������rawData
-        // ���������signature
-        JSONObject rawDataJson = JSON.parseObject(rawData);
-        // 1.������������������������code
-        // 2.������������������ ������������������������ appi + appsecret + code
-        JSONObject SessionKeyOpenId = WechatUtils.getSessionKeyOrOpenId(code);
-        // 3.������������������������ ���������������������
-        String openid = SessionKeyOpenId.getString("openid");
-        String sessionKey = SessionKeyOpenId.getString("session_key");
-
-        // 4.������������ ������������������������signature������������������������������signature2 = sha1(rawData + sessionKey)
-        String signature2 = DigestUtils.sha1Hex(rawData + sessionKey);
-        if (!signature.equals(signature2)) {
-//            return ResultMessage.ok().message("������������������");
-//            return ResultMessage.ok("������������������");
-            throw new BusinessException("������������������");
-        }
-        // 5.���������������User������������������������������������������������������������������������������������������
-        LambdaQueryWrapper<AppUser> lqw = Wrappers.lambdaQuery();
-        lqw.eq(AppUser::getOpenId, openid);
-//        User user = userService.getOne(lqw);
-        AppUser user = appUserMapper.selectOne(lqw);
-
-        if (user == null) {
-            // ������������������
-            String nickName = rawDataJson.getString("nickName");
-            String avatarUrl = rawDataJson.getString("avatarUrl");
-            user = new AppUser();
-            user.setOpenId(Integer.parseInt(openid));
-            user.setAvatarUrl(avatarUrl);
-            user.setNickName(nickName);
-            appUserMapper.insert(user);
-        }
-        return ResultMessage.ok(user);
+    @GetMapping("/wx/login")
+    @ApiOperation(value = "���������������")
+    public ResultMessage userLogin(@RequestParam(value = "code") String code
+                        ) {
+        Map<String, Object> result = userService.wxLogin(code);
+        return ResultMessage.ok(result);
     }
 
 
diff --git a/screen-api/src/main/java/com/moral/api/entity/User.java b/screen-api/src/main/java/com/moral/api/entity/User.java
index 0ae2a49..beba49b 100644
--- a/screen-api/src/main/java/com/moral/api/entity/User.java
+++ b/screen-api/src/main/java/com/moral/api/entity/User.java
@@ -104,6 +104,9 @@
      */
     private String isDelete;
 
+
+    private String openId;
+
     @TableField(exist = false)
     private Integer unitCode;
 
diff --git a/screen-api/src/main/java/com/moral/api/pojo/enums/AppAllocationStateEnum.java b/screen-api/src/main/java/com/moral/api/pojo/enums/AppAllocationStateEnum.java
new file mode 100644
index 0000000..90d749f
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/pojo/enums/AppAllocationStateEnum.java
@@ -0,0 +1,59 @@
+package com.moral.api.pojo.enums;
+
+
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.moral.api.exception.BusinessException;
+
+@Getter
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+public enum AppAllocationStateEnum implements IntegerValueEnum {
+    /**
+     *���������
+     */
+    TO_BE_PROCESSED(20, "���������"),
+    /**
+     *���������
+     */
+    TO_BE_COMPLETED(30, "���������"),
+    /**
+     * 40���50 ���������������
+     */
+    COMPLETED(40, "���������"),
+
+
+    ;
+
+    @EnumValue
+    public  final Integer value;
+    public  final String name;
+
+    AppAllocationStateEnum(Integer value, String name) {
+        this.value = value;
+        this.name = name;
+    }
+
+    private static Map<Integer, AllocationExtensionApproveEnum> valueMap = new HashMap<>();
+    static {
+        for (AllocationExtensionApproveEnum v : AllocationExtensionApproveEnum.values()) {
+            valueMap.put(v.value, v);
+        }
+    }
+    @JsonCreator
+    public static AllocationExtensionApproveEnum getByValue(Integer value) {
+        if (value == null) {
+            return null;
+        }
+        AllocationExtensionApproveEnum result = valueMap.get(value);
+        if (result == null) {
+            throw new BusinessException("������������������" + value);
+        }
+        return result;
+    }
+}
diff --git a/screen-api/src/main/java/com/moral/api/pojo/query/AppUserCond.java b/screen-api/src/main/java/com/moral/api/pojo/query/AppUserCond.java
new file mode 100644
index 0000000..4e8301b
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/pojo/query/AppUserCond.java
@@ -0,0 +1,31 @@
+package com.moral.api.pojo.query;
+
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="AppUserCond - ���������������������", description="AppUserCond - ���������������������")
+public class AppUserCond implements Serializable {
+
+    @ApiModelProperty(value = "������������������code")
+    @NotNull(message = "code���������������")
+    private Integer code;
+
+
+    @ApiModelProperty(value = "���������")
+    private String account;
+
+
+    @ApiModelProperty(value = "������")
+    private  String password;
+}
diff --git a/screen-api/src/main/java/com/moral/api/pojo/vo/allocation/AllocationFindVo.java b/screen-api/src/main/java/com/moral/api/pojo/vo/allocation/AllocationFindVo.java
index 70fefd6..7e443a3 100644
--- a/screen-api/src/main/java/com/moral/api/pojo/vo/allocation/AllocationFindVo.java
+++ b/screen-api/src/main/java/com/moral/api/pojo/vo/allocation/AllocationFindVo.java
@@ -63,6 +63,9 @@
     @ApiModelProperty(value = "������������")
     private Integer isApprove;
 
+    @ApiModelProperty(value = "������������")
+    private String stateName;
+
     public Integer getResidueDay() {
         int day = this.changeDay;
         if(AllocationApproveEnum.UNDER_RECTIFICATION.value.equals(state)){
diff --git a/screen-api/src/main/java/com/moral/api/service/UserService.java b/screen-api/src/main/java/com/moral/api/service/UserService.java
index 6336d44..109c3ac 100644
--- a/screen-api/src/main/java/com/moral/api/service/UserService.java
+++ b/screen-api/src/main/java/com/moral/api/service/UserService.java
@@ -9,6 +9,7 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import com.moral.api.pojo.bo.UserBO;
+import com.moral.api.pojo.query.AppUserCond;
 
 /**
  * <p>
@@ -44,8 +45,11 @@
     //������������������������������������
     UserBO selectUserInfo(Map<String, Object> parameters);
 
-    //���������������
+    //���������������������������
     Map<String, Object> loginSmallRoutine(Map<String, Object> parameters);
 
+    //���������������������
+    Map<String, Object> wxLogin(String code);
+
 
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/AllocationServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/AllocationServiceImpl.java
index fbfcd40..7c8898d 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/AllocationServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/AllocationServiceImpl.java
@@ -640,7 +640,6 @@
     public List<AllocationFindVo> selectSmallRoutine(Integer state,String startTime,String endTime) {
         ArrayList<AllocationFindVo> allocationFindVos = new ArrayList<>();
         LambdaQueryWrapper<Allocation> wrapper = new LambdaQueryWrapper<>();
-        wrapper.orderByDesc(Allocation::getEscalationTime);
         //������������������
         List<Integer> list = unitResult();
         if (!ObjectUtils.isEmpty(list)){
@@ -675,16 +674,31 @@
             wrapper.between(Allocation::getEscalationTime,startTime,endTime);
         }
         wrapper.eq(Allocation::getIsDel,0).eq(Allocation::getIsInvalid,0);
+        wrapper.orderByDesc(Allocation::getEscalationTime);
         List<Allocation> allocations = allocationMapper.selectList(wrapper);
         for (Allocation allocation : allocations) {
             AllocationFindVo allocationFindVo = new AllocationFindVo();
             BeanUtils.copyProperties(allocation,allocationFindVo);
+            Integer state1 = allocationFindVo.getState();
             if (integer==0 || integer==1){
-
+                if (state1==20){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.TO_BE_PROCESSED.name);
+                }else if (state1==30){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.TO_BE_PROCESSED.name);
+                }else if (state1==40 ||state1==50){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.COMPLETED.name);
+                }
+            }else {
+                if (state1==20){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.TO_BE_PROCESSED.name);
+                }else if (state1==30){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.TO_BE_PROCESSED.name);
+                }else if (state1==40||state1==50){
+                    allocationFindVo.setStateName(AppAllocationStateEnum.COMPLETED.name);
+                }
             }
             allocationFindVos.add(allocationFindVo);
         }
-        List<AllocationFindVo> allocationFindVo = allocationMapper.selectSmallRoutine(state,startTime,endTime);
         return allocationFindVos;
     }
 
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
index 74d935a..b21803f 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -1,11 +1,13 @@
 package com.moral.api.service.impl;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
@@ -23,8 +25,10 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.moral.api.entity.Group;
@@ -34,6 +38,7 @@
 import com.moral.api.entity.User;
 import com.moral.api.entity.UserGroup;
 import com.moral.api.entity.UserLog;
+import com.moral.api.exception.BusinessException;
 import com.moral.api.mapper.MenuMapper;
 import com.moral.api.mapper.ResponsibilityUnitMapper;
 import com.moral.api.mapper.UserGroupMapper;
@@ -42,9 +47,12 @@
 import com.moral.api.pojo.bo.UserBO;
 import com.moral.api.service.ResponsibilityUnitService;
 import com.moral.api.service.UserService;
+import com.moral.api.utils.HttpClientUtil;
 import com.moral.api.utils.OperationLogUtils;
+import com.moral.api.utils.WechatUtils;
 import com.moral.constant.Constants;
 import com.moral.constant.ResponseCodeEnum;
+import com.moral.constant.ResultMessage;
 import com.moral.util.AESUtils;
 import com.moral.util.ConvertUtils;
 import com.moral.util.DateUtils;
@@ -52,6 +60,7 @@
 import com.moral.util.RegexUtils;
 import com.moral.util.TokenUtils;
 import com.moral.util.WebUtils;
+import com.sun.org.apache.regexp.internal.RE;
 
 /**
  * <p>
@@ -93,8 +102,10 @@
     }
 
     @Override
+    @Transactional
     public Map<String, Object> loginSmallRoutine(Map<String, Object> parameters) {
         UserBO userBo = selectUserInfo(parameters);
+        String openId = parameters.get("openId").toString();
         Map<String, Object> result = new HashMap<>();
         //������������
         if (userBo == null) {
@@ -123,6 +134,9 @@
             result.put("msg", ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getMsg());
             return result;
         }
+//        JSONObject SessionKeyOpenId = WechatUtils.getSessionKeyOrOpenId(parameters.get("code").toString());
+//        String openid = SessionKeyOpenId.getString("openid");
+//        String sessionKey = SessionKeyOpenId.getString("session_key");
         ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(userBo.getUnitId());
         //������������������
         Map<String, Object> userInfo = new LinkedHashMap<>();
@@ -136,6 +150,8 @@
         userInfo.put("wechat", userBo.getWechat());
         userInfo.put("expireTime", DateUtils.dateToDateString(userBo.getExpireTime()));
         userInfo.put("isAdmin", userBo.getIsAdmin());
+        userInfo.put("openid", openId);
+
         try {
             //������token������������redis
             String token = TokenUtils.getToken(userBo.getId().toString(), userInfo);
@@ -155,6 +171,72 @@
         userLog.setOrganizationId(userBo.getOrganizationId());
         userLog.setContent("������������������" + userBo.getAccount());
         userLogMapper.insert(userLog);
+        //������openId���user������
+
+        User user = userMapper.selectById(userBo.getId());
+        user.setOpenId(openId);
+        userMapper.updateById(user);
+        return result;
+    }
+
+    @Override
+    public Map<String, Object> wxLogin(String code) {
+        Map<String, Object> result = new HashMap<>();
+        // ������������������������rawData
+        // ���������signature
+//        JSONObject rawDataJson = JSON.parseObject(rawData);
+        // 1.������������������������code
+        // 2.������������������ ������������������������ appi + appsecret + code
+        JSONObject SessionKeyOpenId = WechatUtils.getSessionKeyOrOpenId(code);
+
+        // 3.������������������������ ���������������������
+        String openid = SessionKeyOpenId.getString("openid");
+        String sessionKey = SessionKeyOpenId.getString("session_key");
+
+        // 4.������������ ������������������������signature������������������������������signature2 = sha1(rawData + sessionKey)
+//        String signature2 = DigestUtils.sha1Hex(rawData + sessionKey);
+//        if (!signature.equals(signature2)) {
+//           return ResultMessage.ok().message("������������������");
+//            return ResultMessage.ok("������������������");
+//            throw new BusinessException("������������������");
+//        }
+        // 5.���������������User������������������������������������������������������������������������������������������
+        LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
+        lqw.eq(User::getOpenId, openid);
+        User user = userMapper.selectOne(lqw);
+        if (user == null) {
+            result.put("code", ResponseCodeEnum.USER_NOT_EXIST.getCode());
+            result.put("msg", ResponseCodeEnum.USER_NOT_EXIST.getMsg());
+            result.put("openId",openid);
+            return result;
+            // ������������������
+//            String nickName = rawDataJson.getString("nickName");
+//            String avatarUrl = rawDataJson.getString("avatarUrl");
+        }
+
+        Map<String, Object> userInfo = new LinkedHashMap<>();
+        userInfo.put("userId", user.getId());
+        userInfo.put("account", user.getAccount());
+        userInfo.put("userName", user.getUserName());
+        userInfo.put("email", user.getEmail());
+        userInfo.put("mobile", user.getMobile());
+        userInfo.put("unitId",user.getUnitId());
+//        userInfo.put("unName",user.getAreaName());
+        userInfo.put("wechat", user.getWechat());
+        userInfo.put("expireTime", DateUtils.dateToDateString(user.getExpireTime()));
+        userInfo.put("isAdmin", user.getIsAdmin());
+        try {
+            //������token������������redis
+            String token = TokenUtils.getToken(user.getId().toString(), userInfo);
+            result.put("token", token);
+        } catch (Exception e) {
+            log.error("token���������������" + e.getMessage());
+            result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode());
+            result.put("msg", ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg());
+            return result;
+        }
+        result.put("code", ResponseCodeEnum.SUCCESS.getCode());
+        result.put("msg", ResponseCodeEnum.SUCCESS.getMsg());
         return result;
     }
 
diff --git a/screen-api/src/main/java/com/moral/api/utils/WechatUtils.java b/screen-api/src/main/java/com/moral/api/utils/WechatUtils.java
index 59a933d..de7e889 100644
--- a/screen-api/src/main/java/com/moral/api/utils/WechatUtils.java
+++ b/screen-api/src/main/java/com/moral/api/utils/WechatUtils.java
@@ -3,19 +3,33 @@
 
 
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
 import java.util.HashMap;
 import java.util.Map;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.moral.api.service.UserLogService;
 
 public class WechatUtils {
 
-    public static final String APPID = "yyyy";
-    public static final String SECRET = "yyyy";
 
+    public static final String APPID = "wx41f4c3c007545088";
+    public static final String SECRET = "9e1a328ad525dd169252a1cc5067a6f3";
 
     public static JSONObject getSessionKeyOrOpenId(String code) {
+
         String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
         Map<String, String> requestUrlParam = new HashMap<>();
         // https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
@@ -29,6 +43,7 @@
         requestUrlParam.put("grant_type", "authorization_code");
         //������post������������������������������������openid������������������
         JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(requestUrl, requestUrlParam));
+
         return jsonObject;
     }
 }

--
Gitblit v1.8.0