package com.kmall.admin.controller;

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

import com.kmall.admin.entity.SysCusNationCodeEntity;
import com.kmall.admin.service.SysCusNationCodeService;
import com.kmall.admin.fromcomm.entity.SysUserEntity;
import com.kmall.common.utils.PageUtils;
import com.kmall.common.utils.Query;
import com.kmall.common.utils.R;
import com.kmall.admin.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 国别地区代码Controller
 *
 * @author emato
 * @email admin@qhdswl.com
 * @date 2018-11-10 15:26:44
 */
@Controller
@RequestMapping("syscusnationcode")
public class SysCusNationCodeController {
    @Autowired
    private SysCusNationCodeService sysCusNationCodeService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("syscusnationcode:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SysCusNationCodeEntity> sysCusNationCodeList = sysCusNationCodeService.queryList(query);
        int total = sysCusNationCodeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sysCusNationCodeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{sn}")
    @RequiresPermissions("syscusnationcode:info")
    @ResponseBody
    public R info(@PathVariable("sn") String sn) {
        SysCusNationCodeEntity sysCusNationCode = sysCusNationCodeService.queryObject(sn);
        return R.ok().put("sysCusNationCode", sysCusNationCode);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("syscusnationcode:save")
    @ResponseBody
    public R save(@RequestBody SysCusNationCodeEntity sysCusNationCode) {

        SysUserEntity user = ShiroUtils.getUserEntity();
        sysCusNationCode.setCreaterSn(user.getUserId().toString());
        sysCusNationCode.setCreateTime(new Date());
        sysCusNationCode.setModerSn(user.getUserId().toString());
        sysCusNationCode.setModTime(new Date());

        sysCusNationCodeService.save(sysCusNationCode);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("syscusnationcode:update")
    @ResponseBody
    public R update(@RequestBody SysCusNationCodeEntity sysCusNationCode) {
        SysUserEntity user = ShiroUtils.getUserEntity();
        sysCusNationCode.setModerSn(user.getUserId().toString());
        sysCusNationCode.setModTime(new Date());
        sysCusNationCodeService.update(sysCusNationCode);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("syscusnationcode:delete")
    @ResponseBody
    public R delete(@RequestBody String[]sns) {
        sysCusNationCodeService.deleteBatch(sns);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<SysCusNationCodeEntity> list = sysCusNationCodeService.queryList(params);

        return R.ok().put("list", list);
    }
}
