package cn.pluss.platform.controller.notification;

import cn.pluss.platform.activityEnroll.ActivityEnrollService;
import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.cash.CashService;
import cn.pluss.platform.deviceMerchantBuy.DeviceMerchantBuyService;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.notification.NotificationService;
import cn.pluss.platform.officialGoods.exchange.OfficialGoodsExchangeService;
import cn.pluss.platform.suggest.SuggestService;
import cn.pluss.platform.transferCash.MerchantTransferCashService;
import cn.pluss.platform.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.*;

@Controller
@RequestMapping("/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(){
        return "notification/notificationList";
    }

    @GetMapping("/countStatus")
    @ResponseBody
    public Integer count(){
        QueryWrapper<Notification> notificationQueryWrapper=new QueryWrapper<Notification>().eq("status","1");
        int count = notificationService.count(notificationQueryWrapper);
        return count;
    }

    @GetMapping("/page")
    @ResponseBody
    public Map<String,Object> notificationQuery(@RequestParam(defaultValue = "1") Integer currPage, Integer size){
        Map<String,Object> map = new HashMap<>();
        map.put("pageSize", size);
        map.put("offset", (currPage - 1) * size);
        List<Notification> notificationList = notificationService.queryNotification(map);
        int count = notificationService.count();
        Map<String,Object> result = new HashMap<>();
        result.put("notificationList",notificationList);
        result.put("count", count);
        result.put("pageCount", StringUtil.getPageCount(count, size));
        result.put("currPage", currPage);
        result.put("code", 200);
        return result;
    }

    @PostMapping("/delete")
    @ResponseBody
    public Result<Notification> delete(@RequestBody Notification notification){
        notification.setStatus("0");
        notificationService.updateById(notification);
        return ResultGenerator.genSuccessResult("已读！",null);
    }

    @PostMapping("/already")
    @ResponseBody
    public Result<Notification> already(){
        String status="0";
        notificationService.updateAll(status);
        return ResultGenerator.genSuccessResult("全部已读！",null);
    }

    @PostMapping("/whithout")
    @ResponseBody
    public Result<Notification> whithout(){
        String status="1";
        notificationService.updateAll(status);
        return ResultGenerator.genSuccessResult("全部未读！",null);
    }

}
