| | |
| | | package com.yeshi.fanli.service.impl.activity;
|
| | |
|
| | | import java.io.InputStream;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.activity.ActivityRuleUserMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.activity.ActivityUserMapper;
|
| | | import com.yeshi.fanli.entity.bus.activity.ActivityRuleUser;
|
| | | import com.yeshi.fanli.entity.bus.activity.ActivityUser;
|
| | | import com.yeshi.fanli.exception.dynamic.ActivityUserException;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityUserService;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class ActivityUserServiceImpl implements ActivityUserService {
|
| | |
| | | activityRuleUserMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public ActivityUser getActivityUserByNickName(ActivityUser record, MultipartFile file) throws ActivityUserException{
|
| | | if (record == null || StringUtil.isNullOrEmpty(record.getNickName()))
|
| | | throw new ActivityUserException(1, "昵称不能为空");
|
| | | try {
|
| | | ActivityUser userExist = activityUserMapper.selectByName(record.getNickName().trim());
|
| | | if (userExist != null) {
|
| | | return userExist;
|
| | | }
|
| | | |
| | | // 不存在则新增
|
| | | if (file == null) {
|
| | | throw new ActivityUserException(1, "头像不能为空");
|
| | | }
|
| | | String portrait = uploadPicture(file);
|
| | | record.setPortrait(portrait);
|
| | | record.setCreateTime(new Date());
|
| | | activityUserMapper.insertSelective(record);
|
| | | |
| | | return record;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | throw new ActivityUserException(1, "用户信息保存异常");
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 上传图片
|
| | | * @param file
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public String uploadPicture(MultipartFile file) throws Exception {
|
| | | // 文件解析 |
| | | InputStream inputStream = file.getInputStream();
|
| | | String contentType = file.getContentType();
|
| | | String type = contentType.substring(contentType.indexOf("/") + 1);
|
| | | // 文件路径
|
| | | String filePath= FilePathEnum.activityUser.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type;
|
| | | // 执行上传
|
| | | String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
|
| | | |
| | | return fileLink;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<ActivityRuleUser> listByRuleCode(Integer ruleCode, int page, int pageSize) {
|
| | | return activityRuleUserMapper.listByRuleCode(ruleCode, (page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ActivityUser selectByName(String nickName) {
|
| | | return activityUserMapper.selectByName(nickName);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public long countByRuleCode(Integer ruleCode) {
|
| | | return activityRuleUserMapper.countByRuleCode(ruleCode);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public void deleteByRuleUserId(Long id) {
|
| | | ActivityRuleUser user = activityRuleUserMapper.selectByPrimaryKey(id);
|
| | |
| | | activityRuleUserMapper.updateByPrimaryKeySelective(au);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ActivityUser getRandomByDaTaoKeCid(int cid) {
|
| | | int ruleId = 100 + cid;
|
| | | List<ActivityRuleUser> ruleList = activityRuleUserMapper.listByRuleCode(ruleId, 0, 100);
|
| | | return ruleList.get((int) (ruleList.size() * Math.random())).getActivityUser();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ActivityUser getRandomHaoHuo() {
|
| | | List<ActivityRuleUser> ruleList = activityRuleUserMapper.listByRuleCode(ActivityRuleUser.RULE_HAOHUO, 0, 100);
|
| | | return ruleList.get((int) (ruleList.size() * Math.random())).getActivityUser();
|
| | | }
|
| | |
|
| | | }
|