|
@@ -1,6 +1,7 @@
|
|
|
package com.hssx.cloudmodel.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -10,18 +11,18 @@ import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
import com.hssx.cloudmodel.mapper.*;
|
|
|
import com.hssx.cloudmodel.service.UserService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
-import com.hssx.cloudmodel.util.ListUtil;
|
|
|
-import com.hssx.cloudmodel.util.MD5Util;
|
|
|
-import com.hssx.cloudmodel.util.PageUtil;
|
|
|
+import com.hssx.cloudmodel.util.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
@@ -50,9 +51,27 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@Value("${sysPwd}")
|
|
|
private String sysPwd;
|
|
|
|
|
|
+ @Value("${wxAppId}")
|
|
|
+ private String wxAppId;
|
|
|
+ @Value("${wxAppSecret}")
|
|
|
+ private String wxAppSecret;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private LoginLogMapper loginLogMapper;
|
|
|
+ @Resource
|
|
|
+ private PowerMapper powerMapper;
|
|
|
+
|
|
|
+
|
|
|
+ public static final String GET_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
+ public static final String GET_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=accessToken&openid=openId&lang=zh_CN";
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public HttpRespMsg login(UserVO userVO, HttpServletRequest request) {
|
|
|
- System.out.println("user" + userVO);
|
|
|
+ public HttpRespMsg login(UserVO userVO, boolean checkFirst, HttpServletRequest request) {
|
|
|
+ System.out.println("user account== " + userVO.getAccount());
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
//验证用户名是否存在
|
|
|
QueryWrapper<User> qw = new QueryWrapper<>();
|
|
@@ -68,6 +87,25 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
if (projectMapper.selectCount(new QueryWrapper<Project>().eq("manager_id", newUser.getId())) > 0) {
|
|
|
newUser.setIsManager(1);
|
|
|
}
|
|
|
+
|
|
|
+ //是否是首次登陆
|
|
|
+ if (checkFirst) {
|
|
|
+ Integer selectCount = loginLogMapper.selectCount(new QueryWrapper<LoginLog>().eq("user_id", newUser.getId()));
|
|
|
+ if (selectCount == 0) {
|
|
|
+ newUser.setFirstLogin(true);
|
|
|
+ } else {
|
|
|
+ //非第一次才自动记录
|
|
|
+ LoginLog log = new LoginLog();
|
|
|
+ log.setUserId(newUser.getId());
|
|
|
+ loginLogMapper.insert(log);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //前端用户确认后,不需要再检查是否首次登陆
|
|
|
+ LoginLog log = new LoginLog();
|
|
|
+ log.setUserId(newUser.getId());
|
|
|
+ loginLogMapper.insert(log);
|
|
|
+ }
|
|
|
+
|
|
|
msg.data = newUser;
|
|
|
} else {
|
|
|
msg.setError("密码错误");
|
|
@@ -104,13 +142,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
uIds.add(-1);
|
|
|
users = userMapper.selectUserListByCondition(roleType, companyId, flag, keyName, uIds,user);
|
|
|
} else if (user.getSubordinateType() == 1) {
|
|
|
-// List<Integer> projectIds = customCompanyMapper.selectList(new QueryWrapper<CustomCompany>().eq("company_id", user.getCompanyId())).stream().map(CustomCompany::getProjectId).collect(Collectors.toList());
|
|
|
-// projectIds.add(-1);
|
|
|
-// uIds = projectMapper.selectList(new QueryWrapper<Project>().in("id", projectIds)).stream().map(Project::getManagerId).collect(Collectors.toList());
|
|
|
-// List<Integer> projectUserIds = projectUserMapper.selectList(new QueryWrapper<ProjectUser>().in("project_id", projectIds)).stream().map(ProjectUser::getUserId).collect(Collectors.toList());
|
|
|
-// uIds.addAll(projectUserIds);
|
|
|
-// List<Integer> projectApproveIds = projectApproveMapper.selectList(new QueryWrapper<ProjectApprove>().in("project_id", projectIds)).stream().map(ProjectApprove::getApproverId).collect(Collectors.toList());
|
|
|
-// uIds.addAll(projectApproveIds);
|
|
|
uIds = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId())).stream().map(User::getId).collect(Collectors.toList());
|
|
|
uIds.add(-1);
|
|
|
users = userMapper.selectUserListByCondition(roleType, companyId, flag, keyName, uIds,user);
|
|
@@ -374,6 +405,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
} else if (Constant.SYS_ID.equals(user.getParentId())) {
|
|
|
//只有资产方管理员有权限,获取该公司下的所有人员,包括相关的生产方的人员
|
|
|
if (user.getSubordinateType().equals(0)) {
|
|
|
+ System.out.println("=========getAllAvailableUserList=============");
|
|
|
List<Integer> integerList = new ArrayList<>();
|
|
|
integerList.add(compId);
|
|
|
//相关的生产方的公司
|
|
@@ -387,6 +419,101 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg bindWeiXin(String code, String token) {
|
|
|
+ HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
+ log.debug("code=="+code);
|
|
|
+ System.out.println("code==" + code);
|
|
|
+ // 拼接用户授权接口信息
|
|
|
+ String requestUrl = GET_TOKEN_URL.replace("APPID", wxAppId).replace("SECRET", wxAppSecret)
|
|
|
+ .replace("CODE", code);
|
|
|
+ // 存储获取到的授权字段信息
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(requestUrl,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ log.debug("返回信息=="+resp);
|
|
|
+ System.out.println("返回信息=="+resp);
|
|
|
+ dataMap.put("resp", resp);
|
|
|
+ JSONObject OpenidJSONO = JSONObject.parseObject(resp);
|
|
|
+ result = OpenidJSONO;
|
|
|
+ //{"access_token":"32_sheMcGJRDYXVaBoc06o8iT9CyxquudqHl90qGKHg_MGxFhpFA5S8WKUL_mCnfY7O1gcJpS_gBFa4w5Vqb8pCHA","expires_in":7200,"refresh_token":"32_c4ocyhmbbbKyEmG4pS-ywgbV7FkK3A29F_GdZdHKrcvidy0amQeGmhBAo1WBcEWn0T7kSxjbp0BI4lYYtY4wAw","openid":"o1L3L5lOrOl3_UEJjONaoT2Rne1I","scope":"snsapi_userinfo"}
|
|
|
+ if (OpenidJSONO.containsKey("access_token")) {
|
|
|
+ // OpenidJSONO可以得到的内容:access_token expires_in refresh_token openid scope
|
|
|
+ String openid = String.valueOf(OpenidJSONO.get("openid"));
|
|
|
+ String accessToken = String.valueOf(OpenidJSONO.get("access_token"));
|
|
|
+ // 用户保存的作用域
|
|
|
+ String scope = String.valueOf(OpenidJSONO.get("scope"));
|
|
|
+ String refresh_token = String.valueOf(OpenidJSONO.get("refresh_token"));
|
|
|
+
|
|
|
+ // 第四步:拉取用户信息(需scope为 snsapi_userinfo)
|
|
|
+ String url = GET_USERINFO_URL.replaceAll("accessToken", accessToken).replaceAll("openId", openid);
|
|
|
+ responseEntity = this.restTemplate.exchange(url,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ resp = responseEntity.getBody();
|
|
|
+ log.debug("获取微信个人信息返回=="+resp);
|
|
|
+ System.out.println("获取微信个人信息返回=="+resp);
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ //更新用户微信信息
|
|
|
+ User curUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
+ if (curUser != null) {
|
|
|
+ if (!json.containsKey("errcode")) {
|
|
|
+ curUser.setOpenid(openid);
|
|
|
+ curUser.setNickname(EmojiHttpServletRequestWraper.filterEmoji(json.getString("nickname")));
|
|
|
+ curUser.setAvatar(json.getString("headimgurl"));
|
|
|
+ userMapper.updateById(curUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ respMsg.data = curUser;
|
|
|
+ } else {
|
|
|
+ respMsg.setError(OpenidJSONO.getString("errcode")+":"+OpenidJSONO.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return respMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg addNewAdmin(User user) {
|
|
|
+ //获取该账号的创建者
|
|
|
+ User parentUser = userMapper.selectById(user.getParentId());
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ if (Constant.SYS_PARENT_ID.equals(parentUser.getParentId())) {
|
|
|
+ User oldAdmin = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", user.getCompanyId()).eq("parent_id", parentUser.getId()));
|
|
|
+ //添加用户
|
|
|
+ QueryWrapper<User> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("account", user.getAccount());
|
|
|
+ int count = userMapper.selectCount(qw);
|
|
|
+ if (count > 0) {
|
|
|
+ User existingUser = userMapper.selectOne(qw);
|
|
|
+ msg.setError("账号已存在");
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ //创建账号默认密码"000000"
|
|
|
+ user.setPassword(MD5Util.getPassword(Constant.DEFAULT_PWD));
|
|
|
+ user.setHeadImgurl(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+ //获取角色所属的团体
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ if (Constant.ASSETS_COMPANY.equals(company.getCompanyType())) {
|
|
|
+ user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
+ user.setTeamName("资产方");
|
|
|
+ } else if (Constant.PRODUCER_COMPANY.equals(company.getCompanyType())) {
|
|
|
+ user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
+ user.setTeamName("生产方");
|
|
|
+ }
|
|
|
+ userMapper.insert(user);
|
|
|
+ //老的管理员归到新管理员名下
|
|
|
+ oldAdmin.setParentId(user.getId());
|
|
|
+ userMapper.updateById(oldAdmin);
|
|
|
+ company.setAdministratorId(user.getId());
|
|
|
+ company.setAdministrator(user.getUsername());
|
|
|
+ companyMapper.updateById(company);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg addAndUpdateUser(User user, Integer flag, Integer addType, String projectIds) {
|
|
|
//获取该账号的创建者
|
|
@@ -435,14 +562,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}
|
|
|
} else if (flag == 1) {
|
|
|
//更新角色信息
|
|
|
-// Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
-// if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
-// user.setTeamName("资产方");
|
|
|
-// } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
-// user.setTeamName("生产方");
|
|
|
-// }
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
+ user.setTeamName("资产方");
|
|
|
+ } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
+ user.setTeamName("生产方");
|
|
|
+ }
|
|
|
userMapper.updateById(user);
|
|
|
}
|
|
|
} else if (Constant.SYS_ID.equals(parentUser.getParentId())) {
|
|
@@ -538,14 +665,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}
|
|
|
} else if (flag == 1) {
|
|
|
//更新角色信息
|
|
|
-// Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
-// if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
-// user.setTeamName("资产方");
|
|
|
-// } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
-// user.setTeamName("生产方");
|
|
|
-// }
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
+ user.setTeamName("资产方");
|
|
|
+ } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
+ user.setTeamName("生产方");
|
|
|
+ }
|
|
|
userMapper.updateById(user);
|
|
|
}
|
|
|
} else {
|
|
@@ -638,18 +765,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}
|
|
|
} else if (flag == 1) {
|
|
|
//更新角色信息
|
|
|
-// Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
-// if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
-// user.setTeamName("资产方");
|
|
|
-// } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
-// user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
-// user.setTeamName("生产方");
|
|
|
-// }
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ if (Constant.ASSETS_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.ASSETS_COMPANY);
|
|
|
+ user.setTeamName("资产方");
|
|
|
+ } else if (Constant.PRODUCER_COMPANY == company.getCompanyType()) {
|
|
|
+ user.setSubordinateType(Constant.PRODUCER_COMPANY);
|
|
|
+ user.setTeamName("生产方");
|
|
|
+ }
|
|
|
userMapper.updateById(user);
|
|
|
}
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|