| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.Jwt.JwtPayLoad; |
| | | import com.doumee.config.Jwt.JwtTokenUtil; |
| | | import com.doumee.core.annotation.excel.ExcelImporter; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.admin.request.ShopImport; |
| | | import com.doumee.dao.admin.request.UserImport; |
| | | import com.doumee.dao.business.ShopMapper; |
| | | import com.doumee.core.wx.WxMiniConfig; |
| | | import com.doumee.dao.business.UsersMapper; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.dao.business.model.News; |
| | | import com.doumee.dao.business.model.Shop; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Users; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.dao.web.response.AccountResponse; |
| | | import com.doumee.service.business.UsersService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.catalina.User; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | /** |
| | | * 员工信息表Service实现 |
| | |
| | | @Service |
| | | public class UsersServiceImpl implements UsersService { |
| | | |
| | | |
| | | ExecutorService executor = Executors.newFixedThreadPool(1); |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | @Autowired |
| | | private UsersMapper usersMapper; |
| | | @Autowired |
| | |
| | | QueryWrapper<Users> wrapper = new QueryWrapper<>(users); |
| | | return usersMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AccountResponse phoneLogin(String phone,String code){ |
| | | if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(code)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getPhone,phone).last("limit 1")); |
| | | if(Objects.isNull(users)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到账户信息"); |
| | | } |
| | | if(!Constants.equalsInteger(users.getIsdeleted(), Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已删除"); |
| | | } |
| | | if(!StringUtils.equals(users.getStatus(),Constants.ZERO+"")){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已停用,请联系管理员"); |
| | | } |
| | | //TODO 验证短信信息 |
| | | if(!StringUtils.equals(code,"123456")){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"验证码错误"); |
| | | } |
| | | //创建token |
| | | JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE); |
| | | String token = JwtTokenUtil.generateToken(payLoad); |
| | | AccountResponse accountResponse = new AccountResponse(); |
| | | accountResponse.setToken(token); |
| | | accountResponse.setUsers(users); |
| | | return accountResponse; |
| | | } |
| | | |
| | | @Override |
| | | public AccountResponse wxLogin(String code){ |
| | | try { |
| | | //获取微信敏感数据 |
| | | WxMaJscode2SessionResult session = WxMiniConfig.wxPersonnelService.getUserService().getSessionInfo(code); |
| | | String openId = session.getOpenid(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(openId)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取openid失败!请联系管理员"); |
| | | } |
| | | AccountResponse accountResponse = new AccountResponse(); |
| | | accountResponse.setSessionKey(session.getSessionKey()); |
| | | Users users = usersMapper.selectOne(new QueryWrapper<Users>().lambda().eq(Users::getOpenid,openId).last("limit 1")); |
| | | if(Objects.isNull(users)){ |
| | | return accountResponse; |
| | | } |
| | | if(!Constants.equalsInteger(users.getIsdeleted(),Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已删除"); |
| | | } |
| | | if(!StringUtils.equals(users.getStatus(),Constants.ZERO+"")){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已停用,请联系管理员"); |
| | | } |
| | | //创建token |
| | | JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE); |
| | | String token = JwtTokenUtil.generateToken(payLoad); |
| | | accountResponse.setToken(token); |
| | | accountResponse.setUsers(users); |
| | | return accountResponse; |
| | | } catch (WxErrorException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"微信登录异常!请联系管理员"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void bindingOpenid(String code,Long userId){ |
| | | try { |
| | | //获取微信敏感数据 |
| | | WxMaJscode2SessionResult session = WxMiniConfig.wxPersonnelService.getUserService().getSessionInfo(code); |
| | | String openId = session.getOpenid(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(openId)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取openid失败!请联系管理员"); |
| | | } |
| | | usersMapper.update(new UpdateWrapper<Users>().lambda().set(Users::getOpenid,null).eq(Users::getOpenid,openId)); |
| | | Users users = usersMapper.selectById(userId); |
| | | users.setOpenid(openId); |
| | | users.setEditDate(new Date()); |
| | | usersMapper.updateById(users); |
| | | } catch (WxErrorException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public String importBatch(MultipartFile file){ |
| | | Boolean importing = (Boolean) redisTemplate.opsForValue().get(Constants.RedisKeys.IMPORTING_USERS); |
| | | if(importing!=null && importing){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,已存在导入或者上下级重置任务正在执行中,请稍后再试!"); |
| | | } |
| | | redisTemplate.opsForValue().set(Constants.RedisKeys.IMPORTING_USERS,true); |
| | | try { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | ExcelImporter ie = null; |
| | | List<UserImport> dataList =null; |
| | | try { |
| | | ie = new ExcelImporter(file,0,0); |
| | | dataList = ie.getDataList(UserImport.class,null); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(dataList == null || dataList.size() ==0){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!"); |
| | | } |
| | | Date date =new Date(); |
| | | List<UserImport> finalDataList = dataList; |
| | | Callable<String> task = () -> { |
| | | dealUserDataBiz(finalDataList,date,loginUserInfo); |
| | | return "异步任务完成"; |
| | | }; |
| | | executor.submit(task); |
| | | |
| | | return "导入成功"; |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"信息导入失败,请稍后重试"); |
| | | } |
| | | } |
| | | |
| | | private void dealUserDataBiz(List<UserImport> finalDataList, Date date, LoginUserInfo loginUserInfo) { |
| | | |
| | | } |
| | | |
| | | } |