|
@@ -1,8 +1,10 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.constant.Constant;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.vo.UserVO;
|
|
|
import com.management.platform.mapper.*;
|
|
@@ -14,8 +16,14 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+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.util.NumberUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -40,6 +48,21 @@ import java.util.Map;
|
|
|
*/
|
|
|
@Service
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
|
+
|
|
|
+ @Value("${wx.template_report_fill}")
|
|
|
+ public String TEMPLATE_REPORT_FILL;
|
|
|
+ @Value("${wx.app_id}")
|
|
|
+ public String appId;
|
|
|
+ @Value("${wx.app_secret}")
|
|
|
+ public String appSecret;
|
|
|
+ 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";
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
@Resource
|
|
|
private HttpServletRequest request;
|
|
|
@Resource
|
|
@@ -421,6 +444,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
//首先先搞到公司id
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
|
|
|
+ //检查人数是否已达上限
|
|
|
+ Company company = companyMapper.selectById(companyId);
|
|
|
+ int maxCnt = company.getStaffCountMax();
|
|
|
+ long cnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active", 1));
|
|
|
+ if (cnt >= maxCnt) {
|
|
|
+ httpRespMsg.setError("人数已达上限,无法导入.请联系客服提高人数上限。");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ int canImportNum = (int)(maxCnt - cnt);
|
|
|
//查询工作时长设置
|
|
|
TimeType time = timeTypeMapper.selectById(companyId);
|
|
|
BigDecimal monthHours = time.getMonthDays().multiply(new BigDecimal(time.getAllday()));
|
|
@@ -510,14 +542,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
// if (!file.delete()) {
|
|
|
// System.out.println("临时文件" + file.getName() + "删除失败");
|
|
|
// }
|
|
|
- //校验是否有重复账号
|
|
|
- if (userMapper.selectCount(new QueryWrapper<User>().in("phone", phoneList)) == 0) {
|
|
|
- for (User user : userList) {
|
|
|
- userMapper.insert(user);
|
|
|
- }
|
|
|
+ //检查本次导入人数是否超过上限
|
|
|
+ if (userList.size() > canImportNum) {
|
|
|
+ httpRespMsg.setError("仅剩余"+canImportNum+"人可添加,请减少本次导入的人员数量或者联系客服提高人数上限。");
|
|
|
} else {
|
|
|
- httpRespMsg.setError("手机号有重复 批量新建账号失败");
|
|
|
- /*这里以后可能需要返回重复的手机号的具体信息*/
|
|
|
+ //校验是否有重复账号
|
|
|
+ if (userMapper.selectCount(new QueryWrapper<User>().in("phone", phoneList)) == 0) {
|
|
|
+ for (User user : userList) {
|
|
|
+ userMapper.insert(user);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ httpRespMsg.setError("手机号有重复 批量新建账号失败");
|
|
|
+ /*这里以后可能需要返回重复的手机号的具体信息*/
|
|
|
+ }
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -609,4 +646,119 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
return msg;
|
|
|
}
|
|
|
+//
|
|
|
+// private String getAccessToken(String code) {
|
|
|
+// String accessToken = "";
|
|
|
+//
|
|
|
+// if (redisUtil.existsKey("wxAccessToken")) {
|
|
|
+// accessToken = redisUtil.getKey("wxAccessToken");
|
|
|
+// } else {
|
|
|
+// // 拼接用户授权接口信息
|
|
|
+// String requestUrl = GET_TOKEN_URL.replace("APPID", appId).replace("SECRET", appSecret)
|
|
|
+// .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;
|
|
|
+// if (OpenidJSONO.containsKey("access_token")) {
|
|
|
+// accessToken = OpenidJSONO.getString("access_token");
|
|
|
+// redisUtil.setKeyWithExpireTime("wxAccessToken", accessToken, 7200);
|
|
|
+// return accessToken;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg bindWeiXin(String code, String userId) {
|
|
|
+ HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
+ log.debug("code==" + code);
|
|
|
+ System.out.println("code==" + code);
|
|
|
+ // 拼接用户授权接口信息
|
|
|
+ String requestUrl = GET_TOKEN_URL.replace("APPID", appId).replace("SECRET", appSecret)
|
|
|
+ .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 user = new User();
|
|
|
+ user.setId(userId);
|
|
|
+ user.setWxOpenid(openid);
|
|
|
+ userMapper.updateById(user);
|
|
|
+// if (!json.containsKey("errcode")) {
|
|
|
+// user.setWxOpenid(openid);
|
|
|
+// }
|
|
|
+ //创建用户
|
|
|
+// int cnt = wechatUserMapper.selectCount(new QueryWrapper<WechatUser>().eq("open_id", openid));
|
|
|
+// if (cnt == 0) {
|
|
|
+// //检查昵称是否存在
|
|
|
+// WechatUser one = wechatUserMapper.selectOne(new QueryWrapper<WechatUser>().eq("nickname", user.getNickname()));
|
|
|
+// if (one != null) {
|
|
|
+// //按昵称更新
|
|
|
+// one.setAvatar(user.getAvatar());
|
|
|
+// one.setOpenId(user.getOpenId());
|
|
|
+// wechatUserMapper.updateById(one);
|
|
|
+// } else {
|
|
|
+// wechatUserMapper.insert(user);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ //检测密码正确时
|
|
|
+ User u = userMapper.selectById(userId);
|
|
|
+
|
|
|
+ Company company = companyMapper.selectById(u.getCompanyId());
|
|
|
+ UserVO userVO = new UserVO().setCompanyName(company.getCompanyName());
|
|
|
+ userVO.setCompany(company);
|
|
|
+ BeanUtils.copyProperties(u, userVO);
|
|
|
+ //还要多返回一个公司名字
|
|
|
+ userVO.setPassword("");
|
|
|
+ LocalDateTime remainingTime = company.getExpirationDate() == null ? LocalDateTime.now() : company.getExpirationDate();
|
|
|
+ userVO.setRemainingTime(remainingTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() -
|
|
|
+ LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
|
|
+ //检测是否是项目经理,项目经理有审核功能权限
|
|
|
+ int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("incharger_id", userVO.getId()));
|
|
|
+ if (cnt > 0) {
|
|
|
+ userVO.setLeader(true);
|
|
|
+ }
|
|
|
+ respMsg.data = userVO;
|
|
|
+ } else {
|
|
|
+ respMsg.setError(OpenidJSONO.getString("errcode") + ":" + OpenidJSONO.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return respMsg;
|
|
|
+ }
|
|
|
}
|