package com.bootdo.system.controller;

import com.bootdo.common.utils.*;

import com.bootdo.system.domain.RegistrationDO;
import com.bootdo.system.service.RegistrationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: wangp
 * @Date: 2021/6/7 14:35
 * @Return: null
 */
@Controller
@RequestMapping("/system/registration")
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    //@Autowired
    //private FeginService feginService;

    @GetMapping()
    @RequiresPermissions("system:registration:registration")
    String Registration() {
        return "system/registration/registration";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("system:registration:registration")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<RegistrationDO> registrationList = registrationService.list(query);
        int total = registrationService.count(query);
        PageUtils pageUtils = new PageUtils(registrationList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("system:registration:add")
    String add() {
        return "system/registration/add";
    }


    @GetMapping("/edit/{id}")
    @RequiresPermissions("system:registration:edit")
    String edit(@PathVariable("id") Long id, Model model) {
        RegistrationDO registration = registrationService.get(id);
        model.addAttribute("registration", registration);
        return "system/registration/edit";
    }

    ///**
    // * 保存
    // */
    //@ResponseBody
    //@PostMapping("/save")
    //@RequiresPermissions("system:registration:add")
    //public R save(RegistrationDO registration) {
    //
    //    String key = registration.getDeviceName() + registration.getDeviceMac() +registration.getDeviceSn();
    //    String uniqe = MD5.getMd5String(key);
    //    registration.setDeviceUniqe(uniqe);
    //    registration.setDeviceResult("success");
    //    AuthNetDeviceVo authNetDeviceVo = new AuthNetDeviceVo();
    //    authNetDeviceVo.setDeviceName(registration.getDeviceName());
    //    authNetDeviceVo.setDeviceMac(registration.getDeviceMac());
    //    authNetDeviceVo.setDeviceType("01");
    //    authNetDeviceVo.setDeviceSno(registration.getDeviceSn());
    //    authNetDeviceVo.setLoginPwd("123456");
    //    authNetDeviceVo.setDeviceIp(registration.getDeviceAssetNum());
    //    authNetDeviceVo.setDevicePort(registration.getDevicePort());
    //    authNetDeviceVo.setDeviceProtol("http://");
    //    authNetDeviceVo.setDeviceModel("1234");
    //    authNetDeviceVo.setDeviceCode(registration.getDeviceCode());
    //    authNetDeviceVo.setDeviceNetid("true");
    //    authNetDeviceVo.setDeviceOwner("测试部门");
    //    authNetDeviceVo.setDeviceOrg("Haier");
    //    //接入认证系统设备注册接口
    //    feginService.deviceRegister(authNetDeviceVo);
    //    if (registrationService.save(registration) > 0) {
    //        return R.ok();
    //    }
    //    return R.error();
    //}

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("system:registration:edit")
    public R update(RegistrationDO registration) {
        registrationService.update(registration);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("system:registration:remove")
    public R remove(Long id) {
        if (registrationService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("system:registration:batchRemove")
    public R remove(@RequestParam("ids[]") Long[] ids) {
        registrationService.batchRemove(ids);
        return R.ok();
    }

}
