package com.gk.hotwork.Service.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gk.hotwork.Domain.Exception.BusinessException; import com.gk.hotwork.Domain.UserFace; import com.gk.hotwork.Mapper.UserFaceMapper; import com.gk.hotwork.Service.UserFaceService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; @Service("userFaceService") public class UserFaceServiceImpl extends ServiceImpl implements UserFaceService { @Autowired private UserFaceMapper userFaceMapper; @Override public void copeWith(Long userId, String code) { if (userId == null) throw new BusinessException("参数错误,用户id为空"); if (StringUtils.isBlank(code)) throw new BusinessException("参数错误,用户脸部code为空"); UserFace userFace = this.selectByUserId(userId); if (userFace == null) { UserFace newOne = new UserFace(); newOne.setCode(code); newOne.setUserid(userId); newOne.setUpdatetime(new Date()); this.save(newOne); }else{ userFace.setCode(code); this.updateOne(userFace); } } @Override public UserFace selectByUserId(Long id) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(UserFace::getUserid, id); return userFaceMapper.selectOne(queryWrapper); } @Override public void updateOne(UserFace userFace) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.set(UserFace::getCode, userFace.getCode()) .set(UserFace::getUpdatetime, new Date()) .eq(UserFace::getUserid,userFace.getUserid()); this.update(updateWrapper); } }