UserServiceImpl.java 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. package com.sqx.modules.app.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONException;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.aliyun.oss.ClientException;
  6. import com.aliyuncs.CommonRequest;
  7. import com.aliyuncs.CommonResponse;
  8. import com.aliyuncs.DefaultAcsClient;
  9. import com.aliyuncs.IAcsClient;
  10. import com.aliyuncs.http.MethodType;
  11. import com.aliyuncs.profile.DefaultProfile;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  14. import com.baomidou.mybatisplus.core.metadata.IPage;
  15. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  16. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  17. import com.getui.push.v2.sdk.ApiHelper;
  18. import com.getui.push.v2.sdk.GtApiConfiguration;
  19. import com.getui.push.v2.sdk.api.PushApi;
  20. import com.getui.push.v2.sdk.common.ApiResult;
  21. import com.getui.push.v2.sdk.dto.req.Audience;
  22. import com.getui.push.v2.sdk.dto.req.message.PushChannel;
  23. import com.getui.push.v2.sdk.dto.req.message.PushDTO;
  24. import com.getui.push.v2.sdk.dto.req.message.PushMessage;
  25. import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
  26. import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
  27. import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
  28. import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
  29. import com.github.qcloudsms.SmsSingleSender;
  30. import com.github.qcloudsms.SmsSingleSenderResult;
  31. import com.github.qcloudsms.httpclient.HTTPException;
  32. import com.sqx.common.utils.PageUtils;
  33. import com.sqx.common.utils.Result;
  34. import com.sqx.modules.app.dao.MsgDao;
  35. import com.sqx.modules.app.dao.UserDao;
  36. import com.sqx.modules.app.dao.UserMoneyDao;
  37. import com.sqx.modules.app.dao.UserMoneyDetailsDao;
  38. import com.sqx.modules.app.entity.*;
  39. import com.sqx.modules.app.form.UpdateUserTypeForm;
  40. import com.sqx.modules.app.service.MsgService;
  41. import com.sqx.modules.app.service.UserBrowseService;
  42. import com.sqx.modules.app.service.UserMoneyDetailsService;
  43. import com.sqx.modules.app.service.UserService;
  44. import com.sqx.modules.app.utils.JwtUtils;
  45. import com.sqx.modules.app.utils.UserConstantInterface;
  46. import com.sqx.modules.chat.entity.ChatContent;
  47. import com.sqx.modules.chat.entity.ChatConversation;
  48. import com.sqx.modules.chat.service.ChatContentService;
  49. import com.sqx.modules.chat.service.ChatConversationService;
  50. import com.sqx.modules.common.entity.CommonInfo;
  51. import com.sqx.modules.common.service.CommonInfoService;
  52. import com.sqx.modules.file.utils.Md5Utils;
  53. import com.sqx.modules.interviewRecord.entity.InterviewRecord;
  54. import com.sqx.modules.interviewRecord.service.InterviewRecordService;
  55. import com.sqx.modules.invite.service.InviteService;
  56. import com.sqx.modules.message.entity.MessageInfo;
  57. import com.sqx.modules.message.service.MessageService;
  58. import com.sqx.modules.myCollection.entity.MyCollection;
  59. import com.sqx.modules.myCollection.service.MyCollectionService;
  60. import com.sqx.modules.resumes.entity.Company;
  61. import com.sqx.modules.resumes.entity.PostPush;
  62. import com.sqx.modules.resumes.service.CompanyService;
  63. import com.sqx.modules.resumes.service.PostPushService;
  64. import com.sqx.modules.sendRecord.entity.SendRecord;
  65. import com.sqx.modules.sendRecord.service.SendRecordService;
  66. import com.sqx.modules.utils.HttpClientUtil;
  67. import com.sqx.modules.utils.InvitationCodeUtil;
  68. import com.sqx.modules.utils.excel.ExcelData;
  69. import lombok.extern.slf4j.Slf4j;
  70. import org.apache.commons.codec.digest.DigestUtils;
  71. import org.apache.commons.lang.StringUtils;
  72. import org.apache.http.client.utils.DateUtils;
  73. import org.springframework.beans.factory.annotation.Autowired;
  74. import org.springframework.stereotype.Service;
  75. import org.springframework.web.bind.annotation.RequestBody;
  76. import weixin.popular.api.SnsAPI;
  77. import weixin.popular.util.JsonUtil;
  78. import java.io.IOException;
  79. import java.math.BigDecimal;
  80. import java.text.SimpleDateFormat;
  81. import java.time.DayOfWeek;
  82. import java.time.LocalDate;
  83. import java.time.LocalDateTime;
  84. import java.time.LocalTime;
  85. import java.time.format.DateTimeFormatter;
  86. import java.time.temporal.TemporalAdjusters;
  87. import java.util.*;
  88. import java.util.stream.Collectors;
  89. /**
  90. * 用户
  91. *
  92. * @author fang
  93. * @date 2021/2/27
  94. */
  95. @Service("userService")
  96. @Slf4j
  97. public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
  98. @Autowired
  99. private CommonInfoService commonInfoService;
  100. @Autowired
  101. private MsgDao msgDao;
  102. @Autowired
  103. private JwtUtils jwtUtils;
  104. private int number = 1;
  105. @Autowired
  106. private InviteService inviteService;
  107. @Autowired
  108. private MyCollectionService collectionService;
  109. @Autowired
  110. private UserMoneyDao userMoneyDao;
  111. @Autowired
  112. private MessageService messageService;
  113. @Autowired
  114. private UserService userService;
  115. @Autowired
  116. private UserBrowseService userBrowseService;
  117. @Autowired
  118. private CompanyService companyService;
  119. @Autowired
  120. private SendRecordService sendRecordService;
  121. @Autowired
  122. private UserMoneyDetailsService detailsService;
  123. @Autowired
  124. private UserMoneyDetailsDao detailsDao;
  125. @Autowired
  126. private MsgService msgService;
  127. @Autowired
  128. private ChatConversationService chatConversationService;
  129. @Autowired
  130. private ChatContentService chatContentService;
  131. @Autowired
  132. private InterviewRecordService interviewRecordService;
  133. @Autowired
  134. private PostPushService postPushService;
  135. @Override
  136. public UserEntity queryByPhone(String phone) {
  137. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("phone", phone));
  138. }
  139. @Override
  140. public UserEntity queryByOpenId(String openId) {
  141. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("open_id", openId));
  142. }
  143. @Override
  144. public UserEntity queryByShopOpenId(String shopOpenId) {
  145. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("shop_open_id", shopOpenId));
  146. }
  147. @Override
  148. public UserEntity queryByWxOpenId(String openId) {
  149. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("wx_open_id", openId));
  150. }
  151. @Override
  152. public UserEntity queryByAppleId(String appleId) {
  153. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("apple_id", appleId));
  154. }
  155. @Override
  156. public UserEntity queryByUserId(Long userId) {
  157. return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("user_id", userId));
  158. }
  159. @Override
  160. public UserEntity queryByInvitationCode(String invitationCode) {
  161. UserEntity user = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("invitation_code", invitationCode));
  162. if (user != null) {
  163. if (user.getZhiRate() == null) {
  164. user.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
  165. }
  166. if (user.getFeiRate() == null) {
  167. user.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
  168. }
  169. baseMapper.updateById(user);
  170. }
  171. return user;
  172. }
  173. @Override
  174. public Result updatePhone(String phone, String msg, Long userId) {
  175. Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
  176. //校验短信验证码
  177. if (msg1 != null) {
  178. UserEntity userInfo = queryByPhone(phone);
  179. if (userInfo != null) {
  180. return Result.error("手机号已经被其他账号绑定");
  181. } else {
  182. UserEntity one = baseMapper.selectById(userId);
  183. one.setPhone(phone);
  184. baseMapper.updateById(one);
  185. return Result.success();
  186. }
  187. }
  188. return Result.error("验证码不正确");
  189. }
  190. @Override
  191. public Result iosRegister(String appleId) {
  192. if (StringUtils.isEmpty(appleId)) {
  193. return Result.error("账号信息获取失败,请退出重试!");
  194. }
  195. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  196. String date = sdf.format(new Date());
  197. // 根据返回的user实体类,判断用户是否是新用户,不是的话,更新最新登录时间,是的话,将用户信息存到数据库
  198. UserEntity userInfo = queryByAppleId(appleId);
  199. if (userInfo != null) {
  200. if (userInfo.getStatus().equals(2)) {
  201. return Result.error("账号已被封禁,请联系客服处理!");
  202. }
  203. userInfo.setUpdateTime(date);
  204. baseMapper.updateById(userInfo);
  205. //返回用户信息
  206. UserEntity user = queryByAppleId(appleId);
  207. return getResult(user);
  208. } else {
  209. return Result.error(-200, "请先绑定手机号账号!");
  210. }
  211. }
  212. @Override
  213. public Result wxLogin(String code, Integer type) {
  214. try {
  215. String appid;
  216. String secret;
  217. //微信小程序APPID
  218. appid = commonInfoService.findOne(45).getValue();
  219. //微信小程序秘钥
  220. secret = commonInfoService.findOne(46).getValue();
  221. // 配置请求参数
  222. Map<String, String> param = new HashMap<>();
  223. param.put("appid", appid);
  224. param.put("secret", secret);
  225. param.put("js_code", code);
  226. param.put("grant_type", UserConstantInterface.WX_LOGIN_GRANT_TYPE);
  227. param.put("scope", "snsapi_userinfo");
  228. // 发送请求
  229. String wxResult = HttpClientUtil.doGet(UserConstantInterface.WX_LOGIN_URL, param);
  230. log.info(wxResult);
  231. JSONObject jsonObject = JSONObject.parseObject(wxResult);
  232. // 获取参数返回的
  233. String session_key = jsonObject.get("session_key").toString();
  234. //返回微信小程序openId
  235. String open_id = jsonObject.get("openid").toString();
  236. Map<String, String> map = new HashMap<>();
  237. //判断是否注册过
  238. UserEntity userEntity = queryByOpenId(open_id);
  239. if (userEntity != null) {
  240. map.put("flag", "1");
  241. } else {
  242. map.put("flag", "2");
  243. }
  244. // 封装返回小程序
  245. map.put("session_key", session_key);
  246. map.put("open_id", open_id);
  247. if (jsonObject.get("unionid") != null) {
  248. String unionid = jsonObject.get("unionid").toString();
  249. map.put("unionid", unionid);
  250. } else {
  251. map.put("unionid", "-1");
  252. }
  253. return Result.success("登陆成功").put("data", map);
  254. } catch (Exception e) {
  255. System.err.println(e.toString());
  256. return Result.success("登录失败!");
  257. }
  258. }
  259. @Override
  260. public Result wxRegister(UserEntity userInfo1) {
  261. if (StringUtils.isEmpty(userInfo1.getOpenId())) {
  262. return Result.error("账号信息获取失败,请退出重试!");
  263. }
  264. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  265. String date = sdf.format(new Date());
  266. // 根据返回的user实体类,判断用户是否是新用户,不是的话,更新最新登录时间,是的话,将用户信息存到数据库
  267. UserEntity userInfo;
  268. userInfo = queryByOpenId(userInfo1.getOpenId());
  269. if (userInfo != null) {
  270. if (userInfo.getStatus().equals(2)) {
  271. return Result.error("账号已被封禁,请联系客服处理!");
  272. }
  273. if (StringUtils.isNotEmpty(userInfo1.getPhone())) {
  274. userInfo.setPhone(userInfo1.getPhone());
  275. }
  276. userInfo.setUpdateTime(date);
  277. baseMapper.updateById(userInfo);
  278. } else {
  279. //判断是否在app登陆过 手机号是否有账号
  280. UserEntity userByMobile = queryByPhone(userInfo1.getPhone());
  281. if (userByMobile != null) {
  282. //有账号则绑定账号
  283. userByMobile.setOpenId(userInfo1.getOpenId());
  284. if (StringUtils.isBlank(userByMobile.getAvatar())) {
  285. userByMobile.setAvatar(userInfo1.getAvatar());
  286. }
  287. baseMapper.updateById(userByMobile);
  288. MessageInfo messageInfo = new MessageInfo();
  289. messageInfo.setContent("小程序账号绑定成功!");
  290. messageInfo.setTitle("系统通知");
  291. messageInfo.setState(String.valueOf(5));
  292. messageInfo.setUserName(userByMobile.getUserName());
  293. messageInfo.setUserId(String.valueOf(userByMobile.getUserId()));
  294. messageInfo.setCreateAt(sdf.format(new Date()));
  295. messageInfo.setIsSee("0");
  296. messageService.saveBody(messageInfo);
  297. if (userByMobile.getStatus().equals(2)) {
  298. return Result.error("账号已被封禁,请联系客服处理!");
  299. }
  300. baseMapper.updateById(userByMobile);
  301. } else {
  302. //没有则生成新账号
  303. userInfo1.setCreateTime(date);
  304. userInfo1.setPlatform("小程序");
  305. userInfo1.setStatus(1);
  306. userInfo1.setInvitationCode(InvitationCodeUtil.toSerialCode());
  307. if (StringUtils.isNotEmpty(userInfo1.getPhone())) {
  308. userInfo1.setPassword(DigestUtils.sha256Hex(userInfo1.getPhone()));
  309. } else {
  310. userInfo1.setPassword(DigestUtils.sha256Hex(userInfo1.getOpenId()));
  311. }
  312. if (StringUtils.isNotBlank(userInfo1.getInviterCode())) {
  313. UserEntity userEntity = queryByInvitationCode(userInfo1.getInviterCode());
  314. if (userEntity != null) {
  315. userInfo1.setInviterCode(userInfo1.getInviterCode());
  316. //判断邀请员是否有上级
  317. UserEntity parentParentUser = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
  318. if (parentParentUser != null) {
  319. userInfo1.setInviterInviterCode(parentParentUser.getInvitationCode());
  320. }
  321. } else {
  322. return Result.error("邀请码不存在");
  323. }
  324. }
  325. userInfo1.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
  326. userInfo1.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
  327. baseMapper.insert(userInfo1);
  328. //给用户创建钱包
  329. UserMoney userMoney = new UserMoney();
  330. userMoney.setUserId(userInfo1.getUserId());
  331. userMoney.setMoney(BigDecimal.valueOf(0));
  332. userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
  333. userMoneyDao.insert(userMoney);
  334. //赠送钻石数
  335. String give = commonInfoService.findOne(424).getValue();
  336. if (StringUtils.isNotBlank(give)) {
  337. userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
  338. userMoneyDao.updateById(userMoney);
  339. }
  340. MessageInfo messageInfo = new MessageInfo();
  341. messageInfo.setContent("恭喜您,账号注册成功!");
  342. messageInfo.setTitle("系统通知");
  343. messageInfo.setState(String.valueOf(5));
  344. messageInfo.setUserName(userInfo1.getUserName());
  345. messageInfo.setUserId(String.valueOf(userInfo1.getUserId()));
  346. messageInfo.setCreateAt(sdf.format(new Date()));
  347. messageInfo.setIsSee("0");
  348. messageService.saveBody(messageInfo);
  349. UserEntity userEntity = queryByInvitationCode(userInfo1.getInviterCode());
  350. if (userEntity != null) {
  351. inviteService.saveBody(userInfo1.getUserId(), userEntity);
  352. }
  353. }
  354. }
  355. //返回用户信息
  356. UserEntity user;
  357. user = queryByOpenId(userInfo1.getOpenId());
  358. return getResult(user);
  359. }
  360. @Override
  361. public Result wxBindMobile(String phone, String code, String wxOpenId, String token, String platform, Integer sysPhone) {
  362. Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, code);
  363. if (byPhoneAndCode == null) {
  364. return Result.error("验证码错误");
  365. }
  366. msgDao.deleteById(byPhoneAndCode.getId());
  367. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  368. String time = simpleDateFormat.format(new Date());
  369. UserEntity userInfo = queryByPhone(phone);
  370. if (userInfo != null) {
  371. if (StringUtils.isNotEmpty(userInfo.getWxOpenId())) {
  372. return Result.error("当前手机号已经被其他微信绑定");
  373. }
  374. //小程序登陆过
  375. userInfo.setWxOpenId(wxOpenId);
  376. String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
  377. AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
  378. if (user != null && user.getNickname() != null) {
  379. if (user.getHeadimgurl() != null) {
  380. userInfo.setAvatar(user.getHeadimgurl());
  381. }
  382. userInfo.setSex(user.getSex());
  383. if (user.getNickname() != null) {
  384. userInfo.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
  385. }
  386. }
  387. baseMapper.updateById(userInfo);
  388. } else {
  389. //小程序没有登陆过
  390. userInfo = new UserEntity();
  391. String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
  392. AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
  393. if (user != null && user.getNickname() != null) {
  394. if (user.getHeadimgurl() != null) {
  395. userInfo.setAvatar(user.getHeadimgurl());
  396. }
  397. userInfo.setSex(user.getSex());
  398. if (user.getNickname() != null) {
  399. userInfo.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
  400. }
  401. }
  402. userInfo.setWxOpenId(wxOpenId);
  403. userInfo.setPhone(phone);
  404. userInfo.setPlatform(platform);
  405. userInfo.setCreateTime(time);
  406. userInfo.setSysPhone(sysPhone);
  407. userInfo.setStatus(1);
  408. userInfo.setUpdateTime(time);
  409. userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
  410. baseMapper.insert(userInfo);
  411. }
  412. UserEntity userEntity = queryByWxOpenId(userInfo.getWxOpenId());
  413. return getResult(userEntity);
  414. }
  415. @Override
  416. public Result iosBindMobile(String phone, String code, String appleId, String platform, Integer sysPhone) {
  417. Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, code);
  418. if (byPhoneAndCode == null) {
  419. return Result.error("验证码错误");
  420. }
  421. msgDao.deleteById(byPhoneAndCode.getId());
  422. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  423. String time = simpleDateFormat.format(new Date());
  424. UserEntity userInfo = queryByPhone(phone);
  425. if (userInfo != null) {
  426. if (StringUtils.isNotEmpty(userInfo.getAppleId())) {
  427. return Result.error("当前手机号已经被其他苹果绑定");
  428. }
  429. userInfo.setAppleId(appleId);
  430. userInfo.setUpdateTime(simpleDateFormat.format(new Date()));
  431. baseMapper.updateById(userInfo);
  432. } else {
  433. userInfo = new UserEntity();
  434. userInfo.setSex(0);
  435. userInfo.setUserName(phone.replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
  436. userInfo.setPhone(phone);
  437. userInfo.setPlatform(platform);
  438. userInfo.setCreateTime(time);
  439. userInfo.setSysPhone(sysPhone);
  440. userInfo.setStatus(1);
  441. userInfo.setUpdateTime(time);
  442. userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
  443. baseMapper.insert(userInfo);
  444. }
  445. UserEntity userEntity = queryByAppleId(userInfo.getAppleId());
  446. return getResult(userEntity);
  447. }
  448. @Override
  449. public Result wxAppLogin(String wxOpenId, String token) {
  450. UserEntity userEntity = queryByWxOpenId(wxOpenId);
  451. if (userEntity != null) {
  452. if (userEntity.getStatus().equals(2)) {
  453. return Result.error("账号已被禁用,请联系客服处理!");
  454. }
  455. String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
  456. AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
  457. if (user != null && user.getNickname() != null) {
  458. if (user.getHeadimgurl() != null) {
  459. userEntity.setAvatar(user.getHeadimgurl());
  460. }
  461. userEntity.setSex(user.getSex());
  462. if (user.getNickname() != null) {
  463. userEntity.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
  464. }
  465. }
  466. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  467. userEntity.setUpdateTime(sdf.format(new Date()));
  468. baseMapper.updateById(userEntity);
  469. return getResult(userEntity);
  470. } else {
  471. return Result.error(-200, "请先绑定手机号账号!");
  472. }
  473. }
  474. @Override
  475. public Result loginByOpenId(String openId) {
  476. UserEntity userEntity = queryByWxOpenId(openId);
  477. if (userEntity == null) {
  478. return Result.error(-200, "未注册!");
  479. }
  480. String token = jwtUtils.generateToken(userEntity.getUserId());
  481. Map<String, Object> map = new HashMap<>();
  482. map.put("token", token);
  483. map.put("expire", jwtUtils.getExpire());
  484. map.put("user", userEntity);
  485. return Result.success(map);
  486. }
  487. @Override
  488. public Result registerCode(String phone, String msg, String platform, Integer sysPhone, String openId, String inviterCode) {
  489. Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
  490. //校验短信验证码
  491. if (msg1 == null) {
  492. return Result.error("验证码不正确");
  493. }
  494. msgDao.deleteById(msg1.getId());
  495. //校验手机号是否存在
  496. UserEntity userInfo = queryByPhone(phone);
  497. if (userInfo != null) {
  498. if (userInfo.getStatus().equals(2)) {
  499. return Result.error("账号已被禁用,请联系客服处理!");
  500. }
  501. userInfo.setWxOpenId(openId);
  502. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  503. userInfo.setUpdateTime(sdf.format(new Date()));
  504. baseMapper.updateById(userInfo);
  505. return getResult(userInfo);
  506. } else {
  507. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  508. String time = simpleDateFormat.format(new Date());
  509. userInfo = new UserEntity();
  510. userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
  511. userInfo.setPhone(phone);
  512. if (StringUtils.isNotBlank(inviterCode)) {
  513. UserEntity userEntity = queryByInvitationCode(inviterCode);
  514. if (userEntity != null) {
  515. userInfo.setInviterCode(inviterCode);
  516. //判断邀请员是否有上级
  517. UserEntity parentParentUser = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
  518. if (parentParentUser != null) {
  519. userInfo.setInviterInviterCode(parentParentUser.getInvitationCode());
  520. }
  521. } else {
  522. return Result.error("邀请码不存在");
  523. }
  524. }
  525. userInfo.setUserName(phone.replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
  526. userInfo.setPlatform(platform);
  527. userInfo.setCreateTime(time);
  528. userInfo.setSysPhone(sysPhone);
  529. userInfo.setStatus(1);
  530. userInfo.setWxOpenId(openId);
  531. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  532. userInfo.setUpdateTime(sdf.format(new Date()));
  533. baseMapper.insert(userInfo);
  534. msgDao.deleteById(msg1.getId());
  535. //给用户创建钱包
  536. UserMoney userMoney = new UserMoney();
  537. userMoney.setUserId(userInfo.getUserId());
  538. userMoney.setMoney(BigDecimal.valueOf(0));
  539. userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
  540. //赠送钻石数
  541. String give = commonInfoService.findOne(424).getValue();
  542. if (StringUtils.isNotBlank(give)) {
  543. userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
  544. userMoneyDao.updateById(userMoney);
  545. }
  546. userMoneyDao.insert(userMoney);
  547. MessageInfo messageInfo = new MessageInfo();
  548. messageInfo.setContent("恭喜您,账号注册成功!");
  549. messageInfo.setTitle("系统通知");
  550. messageInfo.setState(String.valueOf(5));
  551. messageInfo.setUserName(userInfo.getUserName());
  552. messageInfo.setUserId(String.valueOf(userInfo.getUserId()));
  553. messageInfo.setCreateAt(sdf.format(new Date()));
  554. messageInfo.setIsSee("0");
  555. messageService.saveBody(messageInfo);
  556. UserEntity userEntity = queryByInvitationCode(userInfo.getInviterCode());
  557. if (userEntity != null) {
  558. inviteService.saveBody(userInfo.getUserId(), userEntity);
  559. }
  560. return getResult(userInfo);
  561. }
  562. }
  563. @Override
  564. public Result login(String phone, String pwd) {
  565. UserEntity userEntity = queryByPhone(phone);
  566. if (userEntity == null) {
  567. return Result.error("手机号未注册!");
  568. }
  569. if (!userEntity.getPassword().equals(DigestUtils.sha256Hex(pwd))) {
  570. return Result.error("密码不正确!");
  571. }
  572. if (userEntity.getStatus().equals(2)) {
  573. return Result.error("账号已被禁用,请联系客服处理!");
  574. }
  575. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  576. userEntity.setUpdateTime(sdf.format(new Date()));
  577. baseMapper.updateById(userEntity);
  578. return getResult(userEntity);
  579. }
  580. @Override
  581. public Result getResult(UserEntity user) {
  582. //生成token
  583. String token = jwtUtils.generateToken(user.getUserId());
  584. Map<String, Object> map = new HashMap<>();
  585. map.put("token", token);
  586. map.put("expire", jwtUtils.getExpire());
  587. map.put("user", user);
  588. return Result.success(map);
  589. }
  590. @Override
  591. public Result sendMsg(String phone, String state) {
  592. int code = (int) ((Math.random() * 9 + 1) * 100000);
  593. System.out.println("sendMsg code is " + code);
  594. SmsSingleSenderResult result = null;
  595. if (phone != null) {
  596. if ("forget".equals(state)) {
  597. UserEntity userByPhone = queryByPhone(phone);
  598. if (userByPhone == null) {
  599. return Result.error("手机号未注册");
  600. }
  601. } else if ("bind".equals(state)) {
  602. } else {
  603. UserEntity userByPhone = queryByPhone(phone);
  604. if (userByPhone != null) {
  605. return Result.error("当前手机号已被其他账号绑定");
  606. }
  607. }
  608. }
  609. CommonInfo three = commonInfoService.findOne(79);
  610. //默认使用腾讯云
  611. if (three == null || "1".equals(three.getValue())) {
  612. //腾讯云短信发送
  613. return sendMsgTencent(phone, state, code);
  614. } else if ("2".equals(three.getValue())) {
  615. //阿里云短信发送
  616. return sendMsgAlibaba(phone, code);
  617. } else {
  618. return sendMsgDXB(phone, state, code);
  619. }
  620. }
  621. @Override
  622. public Result sendMsg(String phone, String state, Integer code) {
  623. CommonInfo three = commonInfoService.findOne(79);
  624. //默认使用腾讯云
  625. if (three == null || "1".equals(three.getValue())) {
  626. //腾讯云短信发送
  627. return sendMsgTencent(phone, state, code);
  628. } else if ("2".equals(three.getValue())) {
  629. //阿里云短信发送
  630. return sendMsgAlibaba(phone, code);
  631. } else {
  632. return sendMsgDXB(phone, state, code);
  633. }
  634. }
  635. private Result sendMsgAlibaba(String phone, int code) {
  636. //阿里云短信accessKeyId
  637. CommonInfo three = commonInfoService.findOne(83);
  638. String accessKeyId = three.getValue();
  639. //阿里云短信accessSecret
  640. CommonInfo four = commonInfoService.findOne(84);
  641. String accessSecret = four.getValue();
  642. DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
  643. IAcsClient client = new DefaultAcsClient(profile);
  644. CommonInfo name = commonInfoService.findOne(6);
  645. CommonRequest request = new CommonRequest();
  646. request.setSysMethod(MethodType.POST);
  647. request.setSysDomain("dysmsapi.aliyuncs.com");
  648. request.setSysVersion("2017-05-25");
  649. request.setSysAction("SendSms");
  650. request.putQueryParameter("RegionId", "cn-hangzhou");
  651. request.putQueryParameter("PhoneNumbers", phone);
  652. request.putQueryParameter("SignName", name.getValue());
  653. String value = commonInfoService.findOne(80).getValue();
  654. request.putQueryParameter("TemplateCode", value);
  655. request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
  656. try {
  657. CommonResponse response = client.getCommonResponse(request);
  658. System.out.println(response.getData());
  659. String data = response.getData();
  660. JSONObject jsonObject = JSON.parseObject(data);
  661. if ("OK".equals(jsonObject.get("Code"))) {
  662. Msg byPhone = msgDao.findByPhone(phone);
  663. if (byPhone != null) {
  664. byPhone.setCode(String.valueOf(code));
  665. byPhone.setPhone(phone);
  666. msgDao.updateById(byPhone);
  667. } else {
  668. Msg msg = new Msg();
  669. msg.setCode(String.valueOf(code));
  670. msg.setPhone(phone);
  671. msgDao.insert(msg);
  672. }
  673. /* UserEntity userByPhone = queryByPhone(phone);
  674. if (userByPhone != null) {
  675. return Result.success("login");
  676. } else {
  677. return Result.success("register");
  678. }*/
  679. return Result.success("login");
  680. } else {
  681. if (jsonObject.get("Message").toString().contains("分钟")) {
  682. return Result.error("短信发送过于频繁,请一分钟后再试!");
  683. } else if (jsonObject.get("Message").toString().contains("小时")) {
  684. return Result.error("短信发送过于频繁,请一小时后再试!");
  685. } else if (jsonObject.get("Message").toString().contains("天")) {
  686. return Result.error("短信发送过于频繁,请明天再试!");
  687. }
  688. log.info(jsonObject.get("Message").toString());
  689. return Result.error("短信发送失败!");
  690. }
  691. } catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
  692. e.printStackTrace();
  693. }
  694. return Result.error("验证码发送失败");
  695. }
  696. private Result sendMsgTencent(String phone, String state, int code) {
  697. SmsSingleSenderResult result = null;
  698. try {
  699. CommonInfo three = commonInfoService.findOne(31);
  700. String clientId = three.getValue();
  701. CommonInfo four = commonInfoService.findOne(32);
  702. String clientSecret = four.getValue();
  703. CommonInfo name = commonInfoService.findOne(6);
  704. /**
  705. * 发送短信验证码的状态、
  706. *
  707. * 在h5登录环境中 传的状态不是以下三种状态
  708. */
  709. SmsSingleSender ssender = new SmsSingleSender(Integer.valueOf(clientId), clientSecret);
  710. switch (state) {
  711. case "register":
  712. result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
  713. break;
  714. case "forget":
  715. result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",您正在执行找回密码操作,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
  716. break;
  717. case "bind":
  718. result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",您正在执行绑定手机号操作,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
  719. break;
  720. case "dx":
  721. result = ssender.send(0, "86", phone, "您有" + code + "条未读消息,赶快上线查看吧!", "", "");
  722. break;
  723. default:
  724. result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
  725. break;
  726. }
  727. System.out.println(result);
  728. if (result.result == 0) {
  729. Msg byPhone = msgDao.findByPhone(phone);
  730. if (byPhone != null) {
  731. byPhone.setCode(String.valueOf(code));
  732. byPhone.setPhone(phone);
  733. msgDao.updateById(byPhone);
  734. } else {
  735. Msg msg = new Msg();
  736. msg.setCode(String.valueOf(code));
  737. msg.setPhone(phone);
  738. msgDao.insert(msg);
  739. }
  740. UserEntity userByPhone = queryByPhone(phone);
  741. if (userByPhone != null) {
  742. return Result.success("login");
  743. } else {
  744. return Result.success("register");
  745. }
  746. } else {
  747. return Result.error(6, result.errMsg);
  748. }
  749. } catch (HTTPException | JSONException | IOException e) {
  750. // HTTP 响应码错误
  751. e.printStackTrace();
  752. }
  753. return Result.error("验证码发送失败");
  754. }
  755. private Result sendMsgDXB(String phone, String state, int code) {
  756. CommonInfo three = commonInfoService.findOne(164);
  757. CommonInfo four = commonInfoService.findOne(165);
  758. CommonInfo name = commonInfoService.findOne(6);
  759. String testUsername = three.getValue(); //在短信宝注册的用户名
  760. String testPassword = four.getValue(); //在短信宝注册的密码
  761. String value = "";
  762. switch (state) {
  763. case "register":
  764. value = "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息";
  765. break;
  766. case "forget":
  767. value = "【" + name.getValue() + "】您的验证码是" + code + "。如非本人操作,请忽略本短信";
  768. break;
  769. case "bind":
  770. value = "【" + name.getValue() + "】验证码: " + code + ",您正在执行绑定手机号操作,10分钟内有效,如非您本人操作,可忽略本条消息";
  771. break;
  772. case "dx":
  773. value = "【" + name.getValue() + "】您有" + code + "条未读消息,赶快上线查看吧!";
  774. break;
  775. default:
  776. value = "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息";
  777. break;
  778. }
  779. StringBuilder httpArg = new StringBuilder();
  780. httpArg.append("u=").append(testUsername).append("&");
  781. httpArg.append("p=").append(Md5Utils.md5s(testPassword)).append("&");
  782. httpArg.append("m=").append(phone).append("&");
  783. httpArg.append("c=").append(Md5Utils.encodeUrlString(value, "UTF-8"));
  784. String result = Md5Utils.request("https://api.smsbao.com/sms", httpArg.toString());
  785. log.error("短信包返回值:" + result);
  786. if ("0".equals(result)) {
  787. Msg byPhone = msgDao.findByPhone(phone);
  788. if (byPhone != null) {
  789. byPhone.setCode(String.valueOf(code));
  790. byPhone.setPhone(phone);
  791. msgDao.updateById(byPhone);
  792. } else {
  793. Msg msg = new Msg();
  794. msg.setCode(String.valueOf(code));
  795. msg.setPhone(phone);
  796. msgDao.insert(msg);
  797. }
  798. UserEntity userByPhone = queryByPhone(phone);
  799. if (userByPhone != null) {
  800. return Result.success("login");
  801. } else {
  802. return Result.success("register");
  803. }
  804. } else {
  805. // return ResultUtil.error(6, result.errMsg);
  806. if ("30".equals(result)) {
  807. return Result.error("错误密码");
  808. } else if ("40".equals(result)) {
  809. return Result.error("账号不存在");
  810. } else if ("41".equals(result)) {
  811. return Result.error("余额不足");
  812. } else if ("43".equals(result)) {
  813. return Result.error("IP地址限制");
  814. } else if ("50".equals(result)) {
  815. return Result.error("内容含有敏感词");
  816. } else if ("51".equals(result)) {
  817. return Result.error("手机号码不正确");
  818. }
  819. }
  820. return Result.error("验证码发送失败");
  821. }
  822. @Override
  823. public Result getOpenId(String code, Long userId) {
  824. try {
  825. //微信appid
  826. CommonInfo one = commonInfoService.findOne(5);
  827. //微信秘钥
  828. CommonInfo two = commonInfoService.findOne(21);
  829. String openid = SnsAPI.oauth2AccessToken(one.getValue(), two.getValue(), code).getOpenid();
  830. if (StringUtils.isNotEmpty(openid)) {
  831. UserEntity userEntity = new UserEntity();
  832. userEntity.setUserId(userId);
  833. userEntity.setOpenId(openid);
  834. baseMapper.updateById(userEntity);
  835. return Result.success().put("data", openid);
  836. }
  837. return Result.error("获取失败");
  838. } catch (Exception e) {
  839. log.error("GET_OPENID_FAIL");
  840. return Result.error("获取失败,出错了!");
  841. }
  842. }
  843. @Override
  844. public UserEntity selectUserById(Long userId) {
  845. UserEntity userEntity = baseMapper.selectById(userId);
  846. if (userEntity != null) {
  847. if (userEntity.getUserType() == 2) {
  848. Company company = companyService.getOne(new QueryWrapper<Company>().eq("user_id", userEntity.getUserId()).eq("status",2));
  849. if (company != null) {
  850. userEntity.setCompanyId(company.getCompanyId());
  851. }
  852. }
  853. }
  854. return userEntity;
  855. }
  856. @Override
  857. public PageUtils selectUserPage(Integer page, Integer limit, String startTime, String endTime, UserEntity userEntity) {
  858. Page<UserEntity> pages = new Page<>(page, limit);
  859. return new PageUtils(baseMapper.selectUserPage(pages, startTime, endTime, userEntity));
  860. }
  861. @Override
  862. public int queryInviterCount(String inviterCode) {
  863. return baseMapper.queryInviterCount(inviterCode);
  864. }
  865. @Override
  866. public int queryUserCount(int type, String date, Integer userType) {
  867. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  868. if (StringUtils.isEmpty(date)) {
  869. date = simpleDateFormat.format(new Date());
  870. }
  871. return baseMapper.queryUserCount(type, date, userType);
  872. }
  873. @Override
  874. public Double queryPayMoney(int type) {
  875. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
  876. String date = simpleDateFormat.format(new Date());
  877. return baseMapper.queryPayMoney(type, date);
  878. }
  879. @Override
  880. public IPage<Map<String, Object>> queryCourseOrder(Page<Map<String, Object>> iPage, int type, String date) {
  881. return baseMapper.queryCourseOrder(iPage, type, date);
  882. }
  883. @Override
  884. public int userMessage(String date, int type) {
  885. return baseMapper.userMessage(date, type);
  886. }
  887. @Override
  888. public void pushToSingle(String title, String content, String clientId) {
  889. try {
  890. if (StringUtils.isNotEmpty(clientId)) {
  891. UserEntity userEntity = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("clientid", clientId));
  892. GtApiConfiguration apiConfiguration = new GtApiConfiguration();
  893. //填写应用配置
  894. apiConfiguration.setAppId(commonInfoService.findOne(61).getValue());
  895. apiConfiguration.setAppKey(commonInfoService.findOne(60).getValue());
  896. apiConfiguration.setMasterSecret(commonInfoService.findOne(62).getValue());
  897. // 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
  898. apiConfiguration.setDomain("https://restapi.getui.com/v2/");
  899. // 实例化ApiHelper对象,用于创建接口对象
  900. ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
  901. // 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
  902. PushApi pushApi = apiHelper.creatApi(PushApi.class);
  903. //根据cid进行单推
  904. PushDTO<Audience> pushDTO = new PushDTO<Audience>();
  905. // 设置推送参数
  906. pushDTO.setRequestId(System.currentTimeMillis() + "");
  907. PushMessage pushMessage = new PushMessage();
  908. //安卓推送
  909. GTNotification notification = new GTNotification();
  910. pushDTO.setPushMessage(pushMessage);
  911. // 配置通知栏图标
  912. notification.setLogo(commonInfoService.findOne(19).getValue() + "/logo.png"); //配置通知栏图标,需要在客户端开发时嵌入,默认为push.png
  913. // 配置通知栏网络图标
  914. notification.setLogoUrl(commonInfoService.findOne(19).getValue() + "/logo.png");
  915. notification.setTitle(title);
  916. notification.setBody(content);
  917. notification.setClickType("startapp");
  918. notification.setUrl(commonInfoService.findOne(19).getValue());
  919. notification.setChannelLevel("3");
  920. pushMessage.setNotification(notification);
  921. // 设置接收人信息
  922. Audience audience = new Audience();
  923. audience.addCid(clientId);
  924. pushDTO.setAudience(audience);
  925. // 进行cid单推
  926. ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
  927. if (apiResult.isSuccess()) {
  928. // success
  929. log.info("安卓消息推送成功:" + apiResult.getData());
  930. } else {
  931. // failed
  932. log.error("安卓消息推送失败:code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
  933. pushMessage.setTransmission(title);
  934. pushDTO.setPushMessage(pushMessage);
  935. PushChannel pushChannel = new PushChannel();
  936. IosDTO iosDTO = new IosDTO();
  937. Aps aps = new Aps();
  938. Alert alert = new Alert();
  939. alert.setTitle(title);
  940. alert.setBody(content);
  941. aps.setAlert(alert);
  942. aps.setSound("default");
  943. iosDTO.setAps(aps);
  944. pushChannel.setIos(iosDTO);
  945. pushDTO.setPushChannel(pushChannel);
  946. // 进行cid单推
  947. apiResult = pushApi.pushToSingleByCid(pushDTO);
  948. if (apiResult.isSuccess()) {
  949. // success
  950. log.info("苹果消息推送成功:" + apiResult.getData());
  951. } else {
  952. // failed
  953. log.error("苹果消息推送失败:code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
  954. }
  955. }
  956. }
  957. } catch (Exception e) {
  958. e.printStackTrace();
  959. log.error("消息推送异常:" + e.getMessage(), e);
  960. }
  961. }
  962. @Override
  963. public Result loginApp(String phone, String password) {
  964. //md5加密
  965. String pwd = DigestUtils.sha256Hex(password);
  966. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  967. queryWrapper.eq("phone", phone);
  968. UserEntity userEntity = baseMapper.selectOne(queryWrapper);
  969. if (userEntity == null) {
  970. return Result.error("手机号未注册!");
  971. }
  972. if (!userEntity.getPassword().equals(pwd)) {
  973. return Result.error("密码不正确!");
  974. }
  975. if (userEntity.getStatus().equals(2)) {
  976. return Result.error("账号已被禁用,请联系客服处理!");
  977. }
  978. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  979. userEntity.setUpdateTime(sdf.format(new Date()));
  980. baseMapper.updateById(userEntity);
  981. return getResult(userEntity);
  982. }
  983. @Override
  984. public Result registApp(String userName, String phone, String password, String msg, String platform, String inviterCode) {
  985. Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
  986. //校验短信验证码
  987. if (msg1 == null) {
  988. return Result.error("验证码不正确");
  989. }
  990. msgDao.deleteById(msg1.getId());
  991. //校验手机号是否存在
  992. UserEntity userInfo = queryByPhone(phone);
  993. if (userInfo != null) {
  994. return Result.error("手机号已经被注册!");
  995. } else {
  996. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  997. String time = simpleDateFormat.format(new Date());
  998. userInfo = new UserEntity();
  999. userInfo.setPhone(phone);
  1000. userInfo.setUserName(userName);
  1001. //对密码进行MD5加密
  1002. userInfo.setPassword(DigestUtils.sha256Hex(password));
  1003. userInfo.setPlatform(platform);
  1004. userInfo.setCreateTime(time);
  1005. userInfo.setStatus(1);
  1006. UserEntity userEntity = queryByInvitationCode(inviterCode);
  1007. if (StringUtils.isNotBlank(inviterCode)) {
  1008. if (userEntity != null) {
  1009. userInfo.setInviterCode(inviterCode);
  1010. //判断邀请员是否有上级
  1011. UserEntity parentParentUser = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
  1012. if (parentParentUser != null) {
  1013. userInfo.setInviterInviterCode(parentParentUser.getInvitationCode());
  1014. }
  1015. } else {
  1016. return Result.error("邀请码不存在");
  1017. }
  1018. }
  1019. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1020. userInfo.setCreateTime(sdf.format(new Date()));
  1021. userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
  1022. baseMapper.insert(userInfo);
  1023. //给用户创建钱包
  1024. UserMoney userMoney = new UserMoney();
  1025. userMoney.setUserId(userInfo.getUserId());
  1026. userMoney.setMoney(BigDecimal.valueOf(0));
  1027. userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
  1028. userMoneyDao.insert(userMoney);
  1029. //赠送钻石数
  1030. String give = commonInfoService.findOne(424).getValue();
  1031. if (StringUtils.isNotBlank(give)) {
  1032. userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
  1033. userMoneyDao.updateById(userMoney);
  1034. }
  1035. MessageInfo messageInfo = new MessageInfo();
  1036. messageInfo.setContent("恭喜您,账号注册成功!");
  1037. messageInfo.setTitle("系统通知");
  1038. messageInfo.setState(String.valueOf(5));
  1039. messageInfo.setUserName(userInfo.getUserName());
  1040. messageInfo.setUserId(String.valueOf(userInfo.getUserId()));
  1041. messageInfo.setCreateAt(sdf.format(new Date()));
  1042. messageInfo.setIsSee("0");
  1043. messageService.saveBody(messageInfo);
  1044. if (userEntity != null) {
  1045. inviteService.saveBody(userInfo.getUserId(), userEntity);
  1046. }
  1047. return getResult(userInfo);
  1048. }
  1049. }
  1050. @Override
  1051. public Result forgetPwd(String pwd, String phone, String msg) {
  1052. try {
  1053. Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, msg);
  1054. //校验短信验证码
  1055. if (byPhoneAndCode == null) {
  1056. return Result.error("验证码不正确");
  1057. }
  1058. UserEntity userByPhone = queryByPhone(phone);
  1059. userByPhone.setPassword(DigestUtils.sha256Hex(pwd));
  1060. msgDao.deleteById(byPhoneAndCode.getId());
  1061. baseMapper.updateById(userByPhone);
  1062. return Result.success();
  1063. } catch (Exception e) {
  1064. e.printStackTrace();
  1065. return Result.error("服务器内部错误");
  1066. }
  1067. }
  1068. @Override
  1069. public Result takingOrdersMessage(Page<Map<String, Object>> iPage, Long type, String date) {
  1070. //接单分析
  1071. return Result.success().put("data", new PageUtils(baseMapper.takingOrdersMessage(iPage, type, date)));
  1072. }
  1073. @Override
  1074. public Result selectInviterCodeByUserIdLists(int page, int limit, String invitationCode,Integer userType,Long userId) {
  1075. Page<UserEntity> pages = new Page<>(page, limit);
  1076. IPage<UserEntity> userEntityIPage = baseMapper.selectInviterCodeByUserIdLists(pages, invitationCode,userType,userId);
  1077. return Result.success().put("data", userEntityIPage);
  1078. }
  1079. @Override
  1080. public HashMap<String, Object> userData(Long userId) {
  1081. HashMap<String, Object> map = new HashMap<>();
  1082. UserEntity userEntity = baseMapper.selectById(userId);
  1083. QueryWrapper<UserBrowse> wrapper = new QueryWrapper<UserBrowse>().eq("user_id", userId);
  1084. QueryWrapper<MyCollection> queryWrapper =new QueryWrapper<MyCollection>().eq("user_id",userId);
  1085. QueryWrapper<SendRecord> queryWrapper1 =new QueryWrapper<>();
  1086. QueryWrapper<InterviewRecord>queryWrapper2 =new QueryWrapper<>();
  1087. QueryWrapper<ChatConversation> queryWrapper3 =new QueryWrapper<>();
  1088. if (userEntity.getUserType() == 1) {
  1089. wrapper.eq("browse_type", 1);
  1090. queryWrapper.eq("type",1);
  1091. queryWrapper1.eq("user_id",userId);
  1092. queryWrapper2.eq("interviewer_id",userId);
  1093. queryWrapper3.eq("use_id",userId);
  1094. //企业
  1095. } else {
  1096. wrapper.eq("browse_type", 2);
  1097. queryWrapper.eq("type",2);
  1098. queryWrapper1.eq("company_user_id",userId);
  1099. queryWrapper2.eq("user_id",userId);
  1100. queryWrapper3.eq("focused_user_id",userId);
  1101. }
  1102. int browseCount = userBrowseService.count(wrapper);
  1103. int collectionCount = collectionService.count(queryWrapper);
  1104. int deliveryCount = sendRecordService.count(queryWrapper1);
  1105. int chatCount = chatConversationService.count();
  1106. int interviewCount = interviewRecordService.count(queryWrapper2);
  1107. //浏览记录
  1108. map.put("browseCount", browseCount);
  1109. //收藏记录
  1110. map.put("collectionCount", collectionCount);
  1111. //投递记录
  1112. map.put("deliveryCount", deliveryCount);
  1113. map.put("chatCount",chatCount);
  1114. map.put("interviewCount",interviewCount);
  1115. return map;
  1116. }
  1117. @Override
  1118. public void buyVipCallBack(Long userId, Integer userType) {
  1119. UserEntity userEntity = baseMapper.selectById(userId);
  1120. BigDecimal money;
  1121. if (userType == 1) {
  1122. CommonInfo userVipMoney = commonInfoService.findOne(331);
  1123. money = new BigDecimal(userVipMoney.getValue());
  1124. userEntity.setIsUserVip(1);
  1125. userEntity.setIsUserAdd(0);
  1126. if (userEntity.getUserMonthTime() == null || LocalDateTime.now().isAfter(userEntity.getUserMonthTime())) {
  1127. userEntity.setUserMonthTime(LocalDateTime.now().plusDays(30));
  1128. } else {
  1129. userEntity.setUserMonthTime(userEntity.getUserMonthTime().plusDays(30));
  1130. }
  1131. } else {
  1132. CommonInfo companyVipMoney = commonInfoService.findOne(332);
  1133. money = new BigDecimal(companyVipMoney.getValue());
  1134. userEntity.setIsCompanyVip(1);
  1135. userEntity.setIsCompanyAdd(0);
  1136. if (userEntity.getCompanyMonthTime() == null || LocalDateTime.now().isAfter(userEntity.getCompanyMonthTime())) {
  1137. userEntity.setCompanyMonthTime(LocalDateTime.now().plusDays(30));
  1138. } else {
  1139. userEntity.setCompanyMonthTime(userEntity.getCompanyMonthTime().plusDays(30));
  1140. }
  1141. }
  1142. CommonInfo commonInfo = commonInfoService.findOne(209);
  1143. if ("是".equals(commonInfo.getValue())) {
  1144. UserEntity parentEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", userEntity.getInviterCode()));
  1145. //一级分佣
  1146. if (parentEntity != null) {
  1147. if (parentEntity.getZhiRate().compareTo(BigDecimal.ZERO) > 0) {
  1148. BigDecimal rate = money.multiply(parentEntity.getZhiRate()).setScale(2, BigDecimal.ROUND_HALF_UP);
  1149. parentEntity.setBalance(parentEntity.getBalance().add(rate));
  1150. userService.updateById(parentEntity);
  1151. detailsService.setParentMoneyDetails(userId, parentEntity.getUserId(), rate, 1);
  1152. UserEntity parentParentEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", parentEntity.getInviterCode()));
  1153. //二级分佣
  1154. if (parentParentEntity != null) {
  1155. if (parentParentEntity.getFeiRate().compareTo(BigDecimal.ZERO) > 0) {
  1156. rate = money.multiply(parentParentEntity.getFeiRate()).setScale(2, BigDecimal.ROUND_HALF_UP);
  1157. parentParentEntity.setBalance(parentParentEntity.getBalance().add(rate));
  1158. userService.updateById(parentParentEntity);
  1159. detailsService.setParentMoneyDetails(userId, parentParentEntity.getUserId(), rate, 2);
  1160. }
  1161. }
  1162. }
  1163. }
  1164. }
  1165. baseMapper.updateById(userEntity);
  1166. }
  1167. @Override
  1168. public ExcelData exportExcelUser(String startTime, String endTime, UserEntity userEntity) {
  1169. List<UserEntity> userList = baseMapper.exportExcelUser(startTime, endTime, userEntity);
  1170. ExcelData data = new ExcelData();
  1171. data.setName("用户列表");
  1172. List<String> titles = new ArrayList<>();
  1173. titles.add("编号");
  1174. titles.add("用户名");
  1175. titles.add("手机号");
  1176. titles.add("头像");
  1177. titles.add("微信号");
  1178. titles.add("性别");
  1179. titles.add("年龄");
  1180. titles.add("微信小程序openId");
  1181. titles.add("微信AppOpenId");
  1182. titles.add("密码");
  1183. titles.add("创建时间");
  1184. titles.add("更新时间");
  1185. titles.add("状态");
  1186. titles.add("来源");
  1187. titles.add("邀请码");
  1188. titles.add("邀请人邀请码");
  1189. titles.add("支付宝名称");
  1190. titles.add("支付宝账号");
  1191. titles.add("微信二维码");
  1192. titles.add("佣金");
  1193. titles.add("直属佣金");
  1194. titles.add("非直属佣金");
  1195. titles.add("用户类型");
  1196. titles.add("用户刷新次数");
  1197. titles.add("用户是否是会员");
  1198. titles.add("用户是否已增加次数");
  1199. titles.add("用户月卡到期时间");
  1200. DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1201. data.setTitles(titles);
  1202. List<List<Object>> rows = new ArrayList<>();
  1203. for (UserEntity entity : userList) {
  1204. List<Object> row = new ArrayList<>();
  1205. row.add(entity.getUserId());
  1206. row.add(entity.getUserName());
  1207. row.add(entity.getPhone());
  1208. row.add(entity.getAvatar());
  1209. row.add(entity.getWeChatNum());
  1210. if (entity.getSex() != null && entity.getSex() == 1) {
  1211. row.add("男");
  1212. } else {
  1213. row.add("女");
  1214. }
  1215. row.add(entity.getAge());
  1216. row.add(entity.getOpenId());
  1217. row.add(entity.getWxOpenId());
  1218. row.add(entity.getPassword());
  1219. row.add(entity.getCreateTime());
  1220. row.add(entity.getUpdateTime());
  1221. if (entity.getStatus() != null && entity.getStatus() == 1) {
  1222. row.add("正常");
  1223. } else {
  1224. row.add("禁用");
  1225. }
  1226. row.add(entity.getPlatform());
  1227. row.add(entity.getInvitationCode());
  1228. row.add(entity.getInviterCode());
  1229. row.add(entity.getZhiFuBaoName());
  1230. row.add(entity.getZhiFuBao());
  1231. row.add(entity.getWxImg());
  1232. row.add(entity.getZhiRate());
  1233. row.add(entity.getFeiRate());
  1234. if (entity.getUserType() != null && entity.getUserType() == 1) {
  1235. row.add("用户");
  1236. } else {
  1237. row.add("企业");
  1238. }
  1239. row.add(entity.getUserRefreshCount());
  1240. if (entity.getIsUserVip() == 0) {
  1241. row.add("否");
  1242. } else {
  1243. row.add("是");
  1244. }
  1245. if (entity.getIsUserAdd() == 0) {
  1246. row.add("否");
  1247. } else {
  1248. row.add("是");
  1249. }
  1250. if (entity.getUserMonthTime() != null) {
  1251. row.add(df.format(entity.getUserMonthTime()));
  1252. }
  1253. rows.add(row);
  1254. }
  1255. data.setRows(rows);
  1256. return data;
  1257. }
  1258. @Override
  1259. public HashMap<String, Object> getExtensionData(Long userId) {
  1260. UserEntity userEntity = userService.getById(userId);
  1261. HashMap<String, Object> map = new HashMap<>();
  1262. Integer countChildren = userService.count(new QueryWrapper<UserEntity>().eq("inviter_code", userEntity.getInvitationCode()));
  1263. Integer countChildrenChildren = userService.count(new QueryWrapper<UserEntity>().eq("inviter_inviter_code", userEntity.getInvitationCode()));
  1264. BigDecimal oneMoney = detailsService.getOneProfit(userId, 1);
  1265. BigDecimal twoMoney = detailsService.getOneProfit(userId, 2);
  1266. map.put("countChildren", countChildren);
  1267. map.put("countChildrenChildren", countChildrenChildren);
  1268. map.put("extensionProfit", oneMoney.add(twoMoney));
  1269. map.put("oneMoney", oneMoney);
  1270. map.put("twoMoney", twoMoney);
  1271. return map;
  1272. }
  1273. @Override
  1274. public IPage<UserEntity> getExtensionList(Long userId, Integer type, Integer page, Integer limit) {
  1275. Page<UserEntity> pages;
  1276. if (page != null && limit != null) {
  1277. pages = new Page<>(page, limit);
  1278. } else {
  1279. pages = new Page<>();
  1280. pages.setSize(-1);
  1281. }
  1282. UserEntity loginEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("user_id", userId));
  1283. if (loginEntity != null) {
  1284. if (type == 1) {
  1285. return userService.page(pages, new QueryWrapper<UserEntity>().eq("inviter_code", loginEntity.getInvitationCode()));
  1286. } else if (type == 2) {
  1287. return userService.page(pages, new QueryWrapper<UserEntity>().eq("inviter_inviter_code", loginEntity.getInvitationCode()));
  1288. } else {
  1289. return null;
  1290. }
  1291. } else {
  1292. return null;
  1293. }
  1294. }
  1295. @Override
  1296. public IPage<HashMap<String, Object>> getProfitList(Long userId, Integer type, Integer page, Integer limit) {
  1297. Page<HashMap<String, Object>> pages;
  1298. if (page != null && limit != null) {
  1299. pages = new Page<>(page, limit);
  1300. } else {
  1301. pages = new Page<>();
  1302. pages.setSize(-1);
  1303. }
  1304. return detailsDao.getProfitList(pages, userId, type);
  1305. }
  1306. @Override
  1307. public Result getUser(String tempId) {
  1308. UserEntity user = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("temp_id", tempId));
  1309. if (user != null) {
  1310. return getResult(user);
  1311. } else {
  1312. return Result.error("未查到");
  1313. }
  1314. }
  1315. @Override
  1316. public Result bindUser(String phone, String wxOpenId, String msg) {
  1317. Msg code = msgService.findByPhoneAndCode(phone, msg);
  1318. if (code == null) {
  1319. return Result.error("验证码错误");
  1320. }
  1321. UserEntity userEntity;
  1322. msgService.removeById(code.getId());
  1323. userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("phone", phone));
  1324. if (userEntity != null) {
  1325. UserEntity query = userService.queryByWxOpenId(wxOpenId);
  1326. userService.removeById(query);
  1327. } else {
  1328. userEntity = userService.queryByWxOpenId(wxOpenId);
  1329. userEntity.setPhone(phone);
  1330. }
  1331. userEntity.setWxOpenId(wxOpenId);
  1332. userService.updateById(userEntity);
  1333. return getResult(userEntity);
  1334. }
  1335. @Override
  1336. public IPage<UserEntity> getNotHasCompanyUserList(Integer page, Integer limit, UserEntity userEntity) {
  1337. Page<UserEntity> pages;
  1338. if (page != null && limit != null) {
  1339. pages = new Page<>(page, limit);
  1340. } else {
  1341. pages = new Page<>();
  1342. pages.setSize(-1);
  1343. }
  1344. return baseMapper.getNotHasCompanyUserList(pages, userEntity);
  1345. }
  1346. @Override
  1347. public Result saveUser(UserEntity userEntity){
  1348. userEntity.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
  1349. userEntity.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
  1350. userEntity.setCreateTime(DateUtils.formatDate(new Date()));
  1351. baseMapper.insert(userEntity);
  1352. //给用户创建钱包
  1353. UserMoney userMoney = new UserMoney();
  1354. userMoney.setUserId(userEntity.getUserId());
  1355. userMoney.setMoney(BigDecimal.valueOf(0));
  1356. userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
  1357. userMoneyDao.insert(userMoney);
  1358. //赠送钻石数
  1359. String give = commonInfoService.findOne(424).getValue();
  1360. if (StringUtils.isNotBlank(give)) {
  1361. userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
  1362. userMoneyDao.updateById(userMoney);
  1363. }
  1364. MessageInfo messageInfo = new MessageInfo();
  1365. messageInfo.setContent("恭喜您,账号注册成功!");
  1366. messageInfo.setTitle("系统通知");
  1367. messageInfo.setState(String.valueOf(5));
  1368. messageInfo.setUserName(userEntity.getUserName());
  1369. messageInfo.setUserId(String.valueOf(userEntity.getUserId()));
  1370. messageInfo.setCreateAt(DateUtils.formatDate(new Date()));
  1371. messageInfo.setIsSee("0");
  1372. messageService.saveBody(messageInfo);
  1373. UserEntity superUserEntity = queryByInvitationCode(userEntity.getInviterCode());
  1374. if (superUserEntity != null) {
  1375. inviteService.saveBody(userEntity.getUserId(), superUserEntity);
  1376. }
  1377. return Result.success();
  1378. }
  1379. @Override
  1380. public Result updateUserType(UpdateUserTypeForm updateUserTypeForm) {
  1381. this.update(new UserEntity(), new LambdaUpdateWrapper<UserEntity>()
  1382. .eq(UserEntity::getUserId, updateUserTypeForm.getUserId())
  1383. .set(UserEntity::getUserType, updateUserTypeForm.getUserType())
  1384. );
  1385. return Result.success();
  1386. }
  1387. @Override
  1388. /**
  1389. * 获取指定用户的今日招聘数据
  1390. * @param userId 用户ID(企业用户,对应user_type=2)
  1391. * @return 包含各指标今日数据及较昨日变化的Map
  1392. */
  1393. public HashMap<String, Object> userYesterdayData(Long userId,Integer dateType) {
  1394. HashMap<String, Object> resultMap = new HashMap<>();
  1395. LocalDateTime todayStart;
  1396. LocalDateTime todayEnd;
  1397. LocalDateTime yesterdayStart;
  1398. LocalDateTime yesterdayEnd;
  1399. if (dateType==1) {
  1400. // 1. 定义时间范围:今日00:00:00至23:59:59
  1401. todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
  1402. todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
  1403. // 2. 定义昨日时间范围:昨日00:00:00至23:59:59(用于计算较昨日变化)
  1404. yesterdayStart = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN);
  1405. yesterdayEnd = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX);
  1406. }else {
  1407. LocalDate today = LocalDate.now();
  1408. // 本周一 00:00:00
  1409. LocalDate thisWeekMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
  1410. // 本周日 23:59:59
  1411. LocalDate thisWeekSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
  1412. todayStart = LocalDateTime.of(thisWeekMonday, LocalTime.MIN);
  1413. todayEnd = LocalDateTime.of(thisWeekSunday, LocalTime.MAX);
  1414. // 上周一 00:00:00
  1415. LocalDate lastWeekMonday = thisWeekMonday.minusWeeks(1);
  1416. // 上周日 23:59:59
  1417. LocalDate lastWeekSunday = thisWeekSunday.minusWeeks(1);
  1418. yesterdayStart = LocalDateTime.of(lastWeekMonday, LocalTime.MIN);
  1419. yesterdayEnd = LocalDateTime.of(lastWeekSunday, LocalTime.MAX);
  1420. }
  1421. // 4. 统计各指标今日数据及昨日数据
  1422. // 4.1 我看过(当前企业查看的求职者数量)
  1423. int todayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",todayStart,todayEnd));
  1424. int yesterdayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",yesterdayStart,yesterdayEnd));
  1425. resultMap.put("iSaw", todayISaw);
  1426. resultMap.put("tyIsaw",todayISaw-yesterdayISaw);
  1427. // 4.2 看过我(求职者查看当前企业的数量)
  1428. List<Object> postIdObjs = postPushService.listObjs(
  1429. new QueryWrapper<PostPush>()
  1430. .eq("user_id", userId) // 筛选“我发布的岗位”
  1431. .select("post_push_id")); // 只查岗位ID);
  1432. if (postIdObjs == null || postIdObjs.isEmpty()) {
  1433. resultMap.put("sawMe",0);
  1434. resultMap.put("tySawMe",0);
  1435. }
  1436. List<Long> myPostIds = postIdObjs.stream()
  1437. .map(obj -> Long.valueOf(obj.toString()))
  1438. .collect(Collectors.toList());
  1439. int todaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",todayStart,todayEnd));
  1440. int yesterdaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",yesterdayStart,yesterdayEnd));
  1441. resultMap.put("sawMe",todaySawMe);
  1442. resultMap.put("tySawMe",todaySawMe-yesterdaySawMe);
  1443. // 4.3 我沟通(企业主动发起的沟通数量)
  1444. int todayICommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",todayStart,todayEnd));
  1445. int yesterdayICommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",yesterdayStart,yesterdayEnd));
  1446. resultMap.put("iCommunicated",todayICommunicated);
  1447. resultMap.put("tyICommunicated",todayICommunicated-yesterdayICommunicated);
  1448. // 4.4 求职者沟通(求职者主动发起的沟通数量)
  1449. int todayCandidateCommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",todayStart,todayEnd));
  1450. int yesterdayCandidateCommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",yesterdayStart,yesterdayEnd));
  1451. resultMap.put("candidateCommunicated", todayCandidateCommunicated);
  1452. resultMap.put("tyCandidateCommunicated",todayCandidateCommunicated-yesterdayCandidateCommunicated);
  1453. // 4.5 收获简历(企业收到的简历数量,对应is_send_resumes=1)
  1454. int todayReceivedResumes = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",todayStart,todayEnd));
  1455. int yesterdayReceivedResumes =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",yesterdayStart,yesterdayEnd));
  1456. resultMap.put("receivedResumes", todayReceivedResumes);
  1457. resultMap.put("tyReceivedResumes",todayReceivedResumes-yesterdayReceivedResumes);
  1458. // 4.6 交换电话微信(电话/微信交换成功数量,对应is_send_phone=1或is_send_wx=1)
  1459. int todayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd));
  1460. int yesterdayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd));
  1461. resultMap.put("exchangedContact", todayExchangedContact);
  1462. resultMap.put("tyExchangeContact",todayExchangedContact-yesterdayExchangedContact);
  1463. // 4.7 接受面试(求职者接受面试的数量,需结合status字段定义)
  1464. int todayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",todayStart,todayEnd));
  1465. int yesterdayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",yesterdayStart,yesterdayEnd));
  1466. resultMap.put("acceptedInterview", todayAcceptedInterview);
  1467. resultMap.put("tyAcceptedInterview",todayAcceptedInterview-yesterdayAcceptedInterview);
  1468. return resultMap;
  1469. }
  1470. }