|
@@ -7,12 +7,14 @@ import com.miaxis.collection.service.ICollectionInfoService;
|
|
|
import com.miaxis.collection.vo.CollectionCustomerVo;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.customer.mapper.CustomerInfoMapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -48,15 +50,46 @@ public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper,
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- @SneakyThrows
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Response collectionBusiness(UserInfo userInfo, Long id) {
|
|
|
- //保存收藏表
|
|
|
- CollectionInfo collectionInfo = new CollectionInfo();
|
|
|
- collectionInfo.setUserId(userInfo.getId());
|
|
|
- collectionInfo.setCustomerId(id);
|
|
|
- collectionInfoMapper.insert(collectionInfo);
|
|
|
- return Response.success();
|
|
|
+ try{
|
|
|
+ List<CollectionInfo> infoList = collectionInfoMapper.selectByMap(new HashMap<String, Object>() {{
|
|
|
+ put("user_id", userInfo.getId());
|
|
|
+ put("customer_id", id);
|
|
|
+ }});
|
|
|
+ if (infoList.isEmpty()){
|
|
|
+ //保存收藏表
|
|
|
+ CollectionInfo collectionInfo = new CollectionInfo();
|
|
|
+ collectionInfo.setUserId(userInfo.getId());
|
|
|
+ collectionInfo.setCustomerId(id);
|
|
|
+ collectionInfoMapper.insert(collectionInfo);
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消收藏
|
|
|
+ * @param userId 当前用户id
|
|
|
+ * @param ids 商家id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response removeCollectionByIds(Long userId, Long[] ids) {
|
|
|
+ try{
|
|
|
+ for (Long id : ids) {
|
|
|
+ collectionInfoMapper.deleteByMap(new HashMap<String, Object>(){{
|
|
|
+ put("user_id",userId);
|
|
|
+ put("customer_id",id);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|