package cn.pluss.platform.controller.device;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.device.DeviceBsjService;
import cn.pluss.platform.entity.DeviceBsj;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/deivceBsj")
@Controller
public class DeviceBsjController extends BaseModelController<DeviceBsjService, DeviceBsj> {

    @Autowired
    private DeviceBsjService bsjService;

    @Override
    public Result<Page<DeviceBsj>> page(Page<DeviceBsj> page, DeviceBsj condition, OrderItem orderItem) {
        orderItem = OrderItem.desc("simExpireTime");
        return super.page(page, condition, orderItem);
    }

    /**
     * 数据展示页面
     * @return
     */
    @GetMapping("/index")
    public String index() {
        return "device/deviceBsj/list";
    }

    @PostMapping("/importExpiredTime")
    @ResponseBody
    public Result<?> importExpiredTime(@RequestBody MultipartFile file) {
        try {
            bsjService.importExpiredTime(file);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genFailResult("操作异常，请稍后重试");
        }

        return ResultGenerator.genSuccessResult("数据导入成功", null);
    }

    @PostMapping("/sendExpiredTime")
    @ResponseBody
    public Result<?> sendExpiredTime() {
        bsjService.sendBatchExpiredNotice();
        return ResultGenerator.genSuccessResult("流量卡到期通知已发送", null);
    }
}
