package org.linlinjava.jz.admin.web;


import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.jz.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.jz.admin.util.SecurityHelper;
import org.linlinjava.jz.core.util.ResponseUtil;
import org.linlinjava.jz.core.validator.Order;
import org.linlinjava.jz.core.validator.Sort;
import org.linlinjava.jz.db.domain.SysCity;
import org.linlinjava.jz.db.service.JzSysCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "Admin-Sys-City-Controller",description = "业务城市")
@RestController
@RequestMapping("/admin/city")
@Validated
public class AdminSysCityController {
    private final Log logger = LogFactory.getLog(AdminDmTicketConsultTypeController.class);

    @Autowired
    private JzSysCityService sysCityService;

    @RequiresPermissions("admin:city:list")
    @RequiresPermissionsDesc(menu = {"配置管理", "业务城市"}, button = "查询")
    @GetMapping("/list")
    public Object list(String name,String city,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "create_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {

        List<SysCity> shopList = sysCityService.querySelective( page, limit, sort, order);
        return ResponseUtil.okList(shopList);
    }

    @RequiresPermissions("admin:city:create")
    @RequiresPermissionsDesc(menu = {"配置管理", "业务城市"}, button = "添加")
    @PostMapping("/create")
    public Object create(@RequestBody SysCity city) {
        city.setCreateUser((long)SecurityHelper.getAdminId());
        city.setIsDelete(false);
        sysCityService.add(city);
        return ResponseUtil.ok(city);
    }

    @RequiresPermissions("admin:city:update")
    @RequiresPermissionsDesc(menu = {"配置管理", "业务城市"}, button = "编辑")
    @PostMapping("/update")
    public Object update(@RequestBody SysCity city) {
        sysCityService.add(city);
        return ResponseUtil.ok();
    }

    @RequiresPermissions("admin:city:delete")
    @RequiresPermissionsDesc(menu = {"配置管理", "业务城市"}, button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody SysCity city) {
        city.setIsDelete(true);
        sysCityService.delete(city);
        return ResponseUtil.ok();
    }


    @RequiresPermissions("admin:city:all")
    @RequiresPermissionsDesc(menu = {"配置管理", "业务城市"}, button = "查询所有")
    @GetMapping("/all")
    public Object all() {
        return ResponseUtil.ok(sysCityService.queryAll());
    }



}
