guoshilong
2023-06-21 d2c223581c67fe23a4867bbd31a1c466eb41d6bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cn.gistack.sm.collect.service.impl;
 
import cn.gistack.sm.collect.entity.UserCollect;
import cn.gistack.sm.collect.mapper.UserCollectMapper;
import cn.gistack.sm.collect.service.IUserCollectService;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Service;
 
@Service
public class UserCollectServiceImpl extends BaseServiceImpl<UserCollectMapper, UserCollect> implements IUserCollectService {
 
    @Override
    public String getMyCollect(String userId) {
        String resIds = baseMapper.getMyCollect(userId);
        return resIds;
    }
 
    @Override
    public String updateCollect(UserCollect userCollect) {
        if (ObjectUtil.isEmpty(userCollect.getUserId())){
            userCollect.setUserId(AuthUtil.getUserId().toString());
        }
 
        if (ObjectUtil.isEmpty(userCollect.getResId())){
            throw new ServiceException("请选择水库!");
        }
 
        UserCollect params = new UserCollect();
        params.setUserId(userCollect.getUserId());
        params.setResId(userCollect.getResId());
 
        UserCollect detail = baseMapper.selectOne(Condition.getQueryWrapper(params));
        if (ObjectUtil.isEmpty(detail)){
            //库里不存在该数据就新增
            save(userCollect);
        }else {
            //更新收藏状态
            detail.setStatus(userCollect.getStatus());
             updateById(detail);
        }
        return baseMapper.getMyCollect(userCollect.getUserId());
    }
 
 
}