Commit 289005df authored by muhong's avatar muhong

修改 收藏册

parent 512a3cb7
package com.wwdz.ch.db.service;
package com.wwdz.ch.db.manager;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
......
package com.wwdz.ch.db.service;
package com.wwdz.ch.db.manager;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites;
......
package com.wwdz.ch.db.service.impl;
package com.wwdz.ch.db.manager.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.dao.FavoritesCoinsRelationMapper;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import com.wwdz.ch.db.domain.FavoritesCoinsRelationExample;
import com.wwdz.ch.db.service.FavoritesCoinsRelationDao;
import com.wwdz.ch.db.manager.FavoritesCoinsRelationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
......
package com.wwdz.ch.db.service.impl;
package com.wwdz.ch.db.manager.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.dao.FavoritesMapper;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.domain.FavoritesExample;
import com.wwdz.ch.db.service.FavoritesDao;
import com.wwdz.ch.db.manager.FavoritesDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
......
package com.wwdz.ch.wx.service;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
public interface FavoritesService {
Object page(FavoritesRequestDto dto);
Result page(FavoritesRequestDto dto);
Object add(FavoritesRequestDto dto);
Result add(FavoritesRequestDto dto);
Object update(FavoritesRequestDto dto);
Result update(FavoritesRequestDto dto);
Object info(FavoritesRequestDto dto);
Result info(FavoritesRequestDto dto);
Object delete(FavoritesRequestDto dto);
Result delete(FavoritesRequestDto dto);
Object batchDelete(FavoritesRequestDto dto);
Result batchDelete(FavoritesRequestDto dto);
}
package com.wwdz.ch.wx.service.impl;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import com.wwdz.ch.db.service.FavoritesCoinsRelationDao;
import com.wwdz.ch.db.service.FavoritesDao;
import com.wwdz.ch.db.manager.FavoritesCoinsRelationDao;
import com.wwdz.ch.db.manager.FavoritesDao;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.service.FavoritesService;
import org.apache.commons.collections.CollectionUtils;
......@@ -29,22 +29,22 @@ public class FavoritesServiceImpl implements FavoritesService {
private FavoritesCoinsRelationDao favoritesCoinsRelationDao;
@Override
public Object page(FavoritesRequestDto dto) {
public Result page(FavoritesRequestDto dto) {
try {
return ResponseUtil.ok(favoritesDao.pageByUid(dto.getUid(), dto.getPage(), dto.getSize()));
return Result.success(favoritesDao.pageByUid(dto.getUid(), dto.getPage(), dto.getSize()));
} catch (Exception e) {
logger.error("查询收藏册列表失败,原因:" + e.getMessage(), e);
return ResponseUtil.fail(-1, "查询收藏册列表失败");
return Result.failed(-1, "查询收藏册列表失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object add(FavoritesRequestDto dto) {
public Result add(FavoritesRequestDto dto) {
try {
// 判断收藏册标题是否已存在
if (favoritesDao.isExisted(null, dto.getUid(), dto.getTitle())) {
return ResponseUtil.fail(-1, "收藏册的标题不能重复");
return Result.failed(-1, "收藏册的标题不能重复");
}
Favorites favorites = new Favorites();
......@@ -57,25 +57,25 @@ public class FavoritesServiceImpl implements FavoritesService {
favorites.setUpdateTime(date);
favorites.setDeleted(false);
favoritesDao.add(favorites);
return ResponseUtil.ok();
return Result.success();
} catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "新增收藏册失败");
return Result.failed(-1, "新增收藏册失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object update(FavoritesRequestDto dto) {
public Result update(FavoritesRequestDto dto) {
try {
Favorites favorites = favoritesDao.info(dto.getId());
if (Objects.isNull(favorites)) {
return ResponseUtil.fail(-1, "数据异常,记录不存在");
return Result.failed("数据异常,记录不存在");
}
// 判断收藏册标题是否已存在
if (favoritesDao.isExisted(dto.getId(), dto.getUid(), dto.getTitle())) {
return ResponseUtil.fail(-1, "收藏册的标题不能重复");
return Result.failed("收藏册的标题不能重复");
}
favorites.setTitle(dto.getTitle());
......@@ -83,35 +83,35 @@ public class FavoritesServiceImpl implements FavoritesService {
favorites.setImages(dto.getImages());
favorites.setUpdateTime(new Date());
favoritesDao.update(favorites);
return ResponseUtil.ok();
return Result.success();
} catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "新增收藏册失败");
return Result.failed("新增收藏册失败");
}
}
@Override
public Object info(FavoritesRequestDto dto) {
public Result info(FavoritesRequestDto dto) {
try {
Favorites favorites = favoritesDao.info(dto.getId());
if (Objects.isNull(favorites)) {
return ResponseUtil.fail(-1, "数据异常,记录不存在");
return Result.failed("数据异常,记录不存在");
}
return ResponseUtil.ok(favorites);
return Result.success(favorites);
} catch (Exception e) {
logger.error("查看收藏册详情失败,原因:" + e.getMessage(), e);
return ResponseUtil.fail(-1, "查看收藏册详情失败");
return Result.failed("查看收藏册详情失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object delete(FavoritesRequestDto dto) {
public Result delete(FavoritesRequestDto dto) {
try {
List<FavoritesCoinsRelation> list = favoritesCoinsRelationDao.listByFavoritesId(dto.getId(), null);
if (CollectionUtils.isNotEmpty(list)) {
return ResponseUtil.fail(-1, "收藏册内有藏品,清先移除藏品");
return Result.failed("收藏册内有藏品,清先移除藏品");
}
//TODO 删除该收藏册下用户创建的钱币
......@@ -121,17 +121,17 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册
favoritesDao.delete(dto.getId(), null);
return ResponseUtil.ok();
return Result.success();
} catch (Exception e) {
logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "批量删除收藏册失败");
return Result.failed("批量删除收藏册失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object batchDelete(FavoritesRequestDto dto) {
public Result batchDelete(FavoritesRequestDto dto) {
try {
List<FavoritesCoinsRelation> list = favoritesCoinsRelationDao.listByFavoritesId(null, dto.getIds());
//TODO 删除该收藏册下用户创建的钱币
......@@ -141,11 +141,11 @@ public class FavoritesServiceImpl implements FavoritesService {
// 删除收藏册
favoritesDao.delete(null, dto.getIds());
return ResponseUtil.ok();
return Result.success();
} catch (Exception e) {
logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "批量删除收藏册失败");
return Result.failed("批量删除收藏册失败");
}
}
}
package com.wwdz.ch.wx.web;
import com.github.pagehelper.Page;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.service.FavoritesService;
import com.xxdxxs.support.Delete;
......@@ -29,37 +29,37 @@ public class WxFavoritesController {
private FavoritesService favoritesService;
@PostMapping("/page")
public Object page(@RequestBody @Validated(Page.class)FavoritesRequestDto dto) {
public Result page(@RequestBody @Validated(Page.class)FavoritesRequestDto dto) {
return favoritesService.page(dto);
}
@PostMapping("/add")
public Object add(@RequestBody @Validated(Insert.class)FavoritesRequestDto dto) {
public Result add(@RequestBody @Validated(Insert.class)FavoritesRequestDto dto) {
return favoritesService.add(dto);
}
@PostMapping("/update")
public Object update(@RequestBody @Validated(Update.class)FavoritesRequestDto dto) {
public Result update(@RequestBody @Validated(Update.class)FavoritesRequestDto dto) {
return favoritesService.update(dto);
}
@PostMapping("/info")
public Object info(@RequestBody @Validated(Select.class) FavoritesRequestDto dto) {
public Result info(@RequestBody @Validated(Select.class) FavoritesRequestDto dto) {
return favoritesService.info(dto);
}
@PostMapping("/delete")
public Object delete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
public Result delete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (Objects.isNull(dto.getId())) {
return ResponseUtil.fail(-1, "id不能为空");
return Result.failed("id不能为空");
}
return favoritesService.delete(dto);
}
@PostMapping("/batchDelete")
public Object batchDelete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
public Result batchDelete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (CollectionUtils.isEmpty(dto.getIds())) {
return ResponseUtil.fail(-1, "请选择收藏册");
return Result.failed("请选择收藏册");
}
return favoritesService.batchDelete(dto);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment