|
@@ -0,0 +1,112 @@
|
|
|
|
+package com.huimv.video.service.impl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.huimv.video.domain.MobileAttention;
|
|
|
|
+import com.huimv.video.repo.MobileAttentionRepository;
|
|
|
|
+import com.huimv.video.repo.MobileUserRepository;
|
|
|
|
+import com.huimv.video.repo.PastureAreaRepo;
|
|
|
|
+import com.huimv.video.result.Result;
|
|
|
|
+import com.huimv.video.result.ResultStatus;
|
|
|
|
+import com.huimv.video.service.MobileAttentionService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class MobileAttentionServiceImpl implements MobileAttentionService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MobileAttentionRepository rep;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PastureAreaRepo areaRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result add(MobileAttention entity){
|
|
|
|
+ if (entity == null){
|
|
|
|
+ return new Result(10002, ResultStatus.addNull);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ rep.save(entity);
|
|
|
|
+ return new Result(10000,ResultStatus.addSuccess);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(10001,ResultStatus.addFailed);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result remove(Integer[] ids) {
|
|
|
|
+ if (ids == null || ids.length==0){
|
|
|
|
+ return new Result(10002,ResultStatus.deleteNull);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ for (Integer id : ids) {
|
|
|
|
+ rep.deleteById(id);
|
|
|
|
+ }
|
|
|
|
+ return new Result(10000,ResultStatus.deleteSuccess);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(10001,ResultStatus.deleteFailed);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result update(MobileAttention entity) {
|
|
|
|
+ if (entity == null){
|
|
|
|
+ return new Result(10002,ResultStatus.updateNull);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ rep.save(entity);
|
|
|
|
+ return new Result(10000,ResultStatus.updateSuccess);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(10001,ResultStatus.updateFailed);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result findAll() {
|
|
|
|
+ try {
|
|
|
|
+ List<MobileAttention> all = rep.findAll();
|
|
|
|
+ return new Result(10000,ResultStatus.findSuccess,all);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(10001,ResultStatus.findFailed,null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result findAllById(Integer id) {
|
|
|
|
+ try {
|
|
|
|
+ MobileAttention entity = rep.findById(id).get();
|
|
|
|
+ return new Result(10000,ResultStatus.findSuccess,entity);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ return new Result(10001,ResultStatus.findFailed,null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result findAllByAttention(Integer userId) {
|
|
|
|
+ List endList = new ArrayList();
|
|
|
|
+ List<MobileAttention> allByUserId = rep.findAllByUserId(userId);
|
|
|
|
+
|
|
|
|
+ for (MobileAttention mobileAttention : allByUserId) {
|
|
|
|
+ endList.add(areaRepo.findAllById(mobileAttention.getAreaId()));
|
|
|
|
+ }
|
|
|
|
+ return new Result(10000,"查询成功",endList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result updateAttention(Integer userId, Integer areaId) {
|
|
|
|
+ MobileAttention mobileAttention = new MobileAttention();
|
|
|
|
+ MobileAttention byUserIdAndAreaId = rep.findByUserIdAndAreaId(userId, areaId);
|
|
|
|
+ if (byUserIdAndAreaId ==null ){
|
|
|
|
+
|
|
|
|
+ mobileAttention.setAreaId(areaId);
|
|
|
|
+ mobileAttention.setUserId(userId);
|
|
|
|
+ rep.save(mobileAttention);
|
|
|
|
+ return new Result(10000,"关注成功");
|
|
|
|
+ }
|
|
|
|
+ rep.delete(byUserIdAndAreaId);
|
|
|
|
+ return new Result(10000,"取消关注成功");
|
|
|
|
+ }
|
|
|
|
+}
|