|
|
@@ -0,0 +1,115 @@
|
|
|
+package com.zhongzheng.modules.user.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
|
+import com.zhongzheng.modules.user.bo.UserQueryBo;
|
|
|
+import com.zhongzheng.modules.user.bo.UserEditBo;
|
|
|
+import com.zhongzheng.modules.user.domain.User;
|
|
|
+import com.zhongzheng.modules.user.mapper.UserMapper;
|
|
|
+import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
+import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2021-05-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserVo queryById(Long userId){
|
|
|
+ User db = this.baseMapper.selectById(userId);
|
|
|
+ return BeanUtil.toBean(db, UserVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserVo> queryList(UserQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getUserAccout()), User::getUserAccout, bo.getUserAccout());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getNickname()), User::getNickname, bo.getNickname());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getRealname()), User::getRealname, bo.getRealname());
|
|
|
+ lqw.eq(bo.getSex() != null, User::getSex, bo.getSex());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getIdCard()), User::getIdCard, bo.getIdCard());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getTelphone()), User::getTelphone, bo.getTelphone());
|
|
|
+ lqw.eq(bo.getUserLevel() != null, User::getUserLevel, bo.getUserLevel());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getUserBirth()), User::getUserBirth, bo.getUserBirth());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getEduLevel()), User::getEduLevel, bo.getEduLevel());
|
|
|
+ lqw.eq(bo.getSchoolId() != null, User::getSchoolId, bo.getSchoolId());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getMajor()), User::getMajor, bo.getMajor());
|
|
|
+ lqw.eq(bo.getEntranceTime() != null, User::getEntranceTime, bo.getEntranceTime());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getOpenId()), User::getOpenId, bo.getOpenId());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getStudentCertificateImg()), User::getStudentCertificateImg, bo.getStudentCertificateImg());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getIdCardImg1()), User::getIdCardImg1, bo.getIdCardImg1());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getIdCardImg2()), User::getIdCardImg2, bo.getIdCardImg2());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCountry()), User::getCountry, bo.getCountry());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getProvince()), User::getProvince, bo.getProvince());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCity()), User::getCity, bo.getCity());
|
|
|
+ lqw.eq(bo.getIntegral() != null, User::getIntegral, bo.getIntegral());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<UserVo> entity2Vo(Collection<User> collection) {
|
|
|
+ List<UserVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, UserVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<User> page = (Page<User>)collection;
|
|
|
+ Page<UserVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(UserAddBo bo) {
|
|
|
+ User add = BeanUtil.toBean(bo, User.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(UserEditBo bo) {
|
|
|
+ User update = BeanUtil.toBean(bo, User.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(User entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|