package cn.pluss.platform.controller.deviceSignUnbind;

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

import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.util.StringUtil;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.pluss.platform.entity.DeviceSignUnbind;
import cn.pluss.platform.deviceSignUnbind.DeviceSignUnbindService;

@Controller
@RequestMapping("deviceSignUnbind")
public class DeviceSignUnbindController extends BaseModelController<DeviceSignUnbindService, DeviceSignUnbind> {

    private Integer PAGE_SIZE = 12;

    @Autowired
    private DeviceSignUnbindService deviceSignUnbindService;

    /**
     * 引导页
     *
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
        return "deviceSignUnbind/deviceSignUnbindList";
    }

    /**
     * 分页查询
     */
    @RequestMapping(value = "/queryDeviceSignUnbindByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryDeviceSignUnbindByPage(Integer currPage, String startTime, String endTime, DeviceSignUnbind deviceSignUnbind) {
        if (currPage == null) {
            currPage = 1;
        }
        Map<String, Object> map = new HashMap<>(16);
        map.put("pageSize", PAGE_SIZE);
        map.put("offset", (currPage - 1) * PAGE_SIZE);
        map.put("orderNo", deviceSignUnbind.getOrderNo());
        map.put("merchantName", deviceSignUnbind.getMerchantName());
        map.put("status", deviceSignUnbind.getStatus());
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("userId", deviceSignUnbind.getUserId());
        List<DeviceSignUnbind> deviceSignUnbindList = deviceSignUnbindService.queryDeviceSignUnbindPage(map);
        Integer count = deviceSignUnbindService.queryDeviceSignUnbindPageCount(map);
        Map<String, Object> result = new HashMap<>(16);
        result.put("deviceSignUnbindList", deviceSignUnbindList);
        result.put("count", count);
        result.put("pageCount", StringUtil.getPageCount(count, PAGE_SIZE));
        result.put("currPage", currPage);
        return result;
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryDeviceSignUnbindDetails", method = RequestMethod.GET)
    public String queryDeviceSignUnbindDetails(HttpServletRequest request, Integer id, Integer pageIndex) {

        if (id != null && id != 0) {
            DeviceSignUnbind deviceSignUnbind = new DeviceSignUnbind();
            deviceSignUnbind.setId(id);
            deviceSignUnbind = deviceSignUnbindService.queryDeviceSignUnbind(deviceSignUnbind);
            request.setAttribute("deviceSignUnbind", deviceSignUnbind);
            request.setAttribute("pageIndex", pageIndex);
        }
        return "deviceSignUnbind/deviceSignUnbindDetails";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryDeviceSignUnbindBaseInfo", method = RequestMethod.GET)
    public String queryDeviceSignUnbindBaseInfo(HttpServletRequest request, Integer id, Integer pageIndex) {

        if (id != null && id != 0) {
            DeviceSignUnbind deviceSignUnbind = new DeviceSignUnbind();
            deviceSignUnbind.setId(id);
            deviceSignUnbind = deviceSignUnbindService.queryDeviceSignUnbind(deviceSignUnbind);
            request.setAttribute("deviceSignUnbind", deviceSignUnbind);
            request.setAttribute("pageIndex", pageIndex);
        }
        return "deviceSignUnbind/deviceSignUnbindBaseInfo";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryDeviceSignUnbindExtendsInfo", method = RequestMethod.GET)
    public String queryDeviceSignUnbindExtendsInfo() {
        return "deviceSignUnbind/deviceSignUnbindExtendsInfo";
    }

    /**
     * 查询详情
     */
    @RequestMapping(value = "/queryDeviceSignUnbindFunctionsInfo", method = RequestMethod.GET)
    public String queryDeviceSignUnbindFunctionsInfo() {
        return "deviceSignUnbind/deviceSignUnbindFunctionsInfo";
    }

    /**
     * 保存对象
     *
     */
    @RequestMapping(value = "/saveDeviceSignUnbind", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> saveDeviceSignUnbind(DeviceSignUnbind deviceSignUnbind) {

        if (deviceSignUnbind.getId() != null && deviceSignUnbind.getId() != 0) {
            deviceSignUnbindService.updateById(deviceSignUnbind);
        } else {
            deviceSignUnbindService.save(deviceSignUnbind);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("resultCode", "1");
        result.put("resultMessage", "保存成功!");
        return result;
    }

    /**
     * 删除对象
     *
     */
    @RequestMapping(value = "/deleteDeviceSignUnbind", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> deleteDeviceSignUnbind(Integer id) {
        deviceSignUnbindService.removeById(id);
        Map<String, Object> result = new HashMap<>();
        result.put("resultCode", "1");
        result.put("resultMessage", "保存成功!");
        return result;
    }

    /**
     * 修改状态
     *
     */
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateStatus(DeviceSignUnbind deviceSignUnbind) {
        Map<String, Object> result = new HashMap<>(16);
        try {
            deviceSignUnbindService.updateById(deviceSignUnbind);
            result.put("msg", "操作成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result.put("msg", "操作失败!");
        }
        return result;
    }

}


