package com.zhujizheng.IHome.collect.service; import com.zhujizheng.IHome.collect.dto.PYCollectDTO; import com.zhujizheng.IHome.collect.vo.PYCollectVO; import com.zhujizheng.IHome.generator.dao.PYCollect; import com.zhujizheng.IHome.generator.mapper.PYCollectMapper; import com.zhujizheng.IHome.util.CodeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.http.fileupload.util.LimitedInputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @Slf4j @Service @Transactional(rollbackFor = RuntimeException.class) public class PYCollectServiceimpl implements PYCollectService { @Autowired private CodeUtil codeUtil; @Autowired private PYCollectMapper collectMapper; private static final int DEFAULT_NUM = 10; @Override public PYCollectVO pushCollectWithDTO(PYCollectDTO dto) { PYCollect collect = PYCollect.createCollectWithDTO(dto); int result = collectMapper.insertCollect(collect); if (result == 0) { return null; } return PYCollectVO.createVOWithCollect(collect); } @Override public List getAllCollect(int userId, int collectId) { int cId = codeUtil.dealInt(collectId); List collectList = collectMapper.selectAllCollect(userId, cId, DEFAULT_NUM);; if (collectList != null) { List voList = new ArrayList<>(); for (PYCollect collect : collectList) { PYCollectVO vo = PYCollectVO.createVOWithCollect(collect); voList.add(vo); } return voList; } return null; } @Override public List getCollectWithType(int userId, int collectId, int type) { int cId = codeUtil.dealInt(collectId); List collectList = collectMapper.selectCollectWithType(userId, cId, type, DEFAULT_NUM);; if (collectList != null) { List voList = new ArrayList<>(); for (PYCollect collect : collectList) { PYCollectVO vo = PYCollectVO.createVOWithCollect(collect); voList.add(vo); } return voList; } return null; } @Override public int cancelCollectWithId(int collectId) { return collectMapper.updateCollect(collectId); } }