|
@@ -1,10 +1,24 @@
|
|
|
package cn.iselab.mooctest.user.web.logic.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.rpc.user.data.MedalCaughtDTO;
|
|
|
+import cn.iselab.mooctest.rpc.user.data.MedalDTO;
|
|
|
+import cn.iselab.mooctest.user.constants.DeleteStatus;
|
|
|
+import cn.iselab.mooctest.user.model.Medal;
|
|
|
+import cn.iselab.mooctest.user.model.User2Medal;
|
|
|
import cn.iselab.mooctest.user.service.MedalService;
|
|
|
+import cn.iselab.mooctest.user.web.exception.HttpBadRequestException;
|
|
|
+import cn.iselab.mooctest.user.web.logic.BaseLogic;
|
|
|
import cn.iselab.mooctest.user.web.logic.MedalLogic;
|
|
|
+import cn.iselab.mooctest.user.web.wrapper.MedalCaughtWrapper;
|
|
|
+import cn.iselab.mooctest.user.web.wrapper.Medalwrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.convert.converter.Converter;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
+
|
|
|
|
|
|
* @Author ROKG
|
|
|
* @Description
|
|
@@ -12,8 +26,79 @@ import org.springframework.stereotype.Service;
|
|
|
* @Modified By:
|
|
|
*/
|
|
|
@Service
|
|
|
-public class MedalLogicImpl implements MedalLogic {
|
|
|
+public class MedalLogicImpl extends BaseLogic implements MedalLogic {
|
|
|
|
|
|
@Autowired
|
|
|
MedalService medalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ Medalwrapper medalwrapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MedalCaughtWrapper medalCaughtWrapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MedalDTO saveMedal(MedalDTO dto){
|
|
|
+ Medal medal=medalwrapper.unwrap(dto);
|
|
|
+ medal.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ medal.setDeleted(DeleteStatus.IS_NOT_DELETED);
|
|
|
+ medal=medalService.saveMedal(medal);
|
|
|
+ return medalwrapper.wrap(medal);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MedalDTO updateMedal(MedalDTO dto){
|
|
|
+ Medal medal=medalService.findById(dto.getId());
|
|
|
+ if (medal == null) {
|
|
|
+ throw new HttpBadRequestException("medal not exists");
|
|
|
+ }
|
|
|
+ medal.setName(dto.getName());
|
|
|
+ medal.setDescription(dto.getDescription());
|
|
|
+ medal.setImgUrl(dto.getImgUrl());
|
|
|
+ medalService.saveMedal(medal);
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteMedal(long medalId){
|
|
|
+ Medal medal=medalService.findById(medalId);
|
|
|
+ if (medal == null) {
|
|
|
+ throw new HttpBadRequestException("medal not exists");
|
|
|
+ }
|
|
|
+ medal.setDeleted(DeleteStatus.IS_DELETED);
|
|
|
+ medalService.saveMedal(medal);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<MedalDTO> getMedals(String keyword, Pageable pageable){
|
|
|
+ Page<Medal> medals=medalService.findByPage2(keyword, pageable);
|
|
|
+ return medals.map(new Converter<Medal, MedalDTO>() {
|
|
|
+ @Override
|
|
|
+ public MedalDTO convert(Medal medal) {
|
|
|
+ return medalwrapper.wrap(medal);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MedalCaughtDTO saveMedalCaughtDTO(MedalCaughtDTO dto){
|
|
|
+ User2Medal user2Medal=medalCaughtWrapper.unwrap(dto);
|
|
|
+ user2Medal.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ user2Medal=medalService.saveUser2Medal(user2Medal);
|
|
|
+ return medalCaughtWrapper.wrap(user2Medal);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<MedalCaughtDTO> getMedalList(long userId, Pageable pageable){
|
|
|
+ Page<User2Medal> user2Medals=medalService.findByPage(userId,pageable);
|
|
|
+ return user2Medals.map(new Converter<User2Medal, MedalCaughtDTO>() {
|
|
|
+ @Override
|
|
|
+ public MedalCaughtDTO convert(User2Medal user2Medal) {
|
|
|
+ MedalCaughtDTO dto=medalCaughtWrapper.wrap(user2Medal);
|
|
|
+ Medal medal =medalService.findById(user2Medal.getMedalId());
|
|
|
+ dto.setMedalDTO(medalwrapper.wrap(medal));
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|