package com.kmall.admin.controller;

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

import com.google.common.collect.ImmutableBiMap;
import com.kmall.admin.entity.ThirdMerchExpressEntity;
import com.kmall.admin.service.ThirdMerchExpressService;
import com.kmall.admin.utils.ParamUtils;
import com.kmall.admin.utils.ShiroUtils;
import com.kmall.common.utils.*;
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 huangyq
 * @email admin@qhdswl.com
 * @date 2019-04-03 16:52:21
 */
@Controller
@RequestMapping("thirdmerchexpress")
public class ThirdMerchExpressController {
    @Autowired
    private ThirdMerchExpressService thirdMerchExpressService;

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

        List<ThirdMerchExpressEntity> thirdMerchExpressList = thirdMerchExpressService.queryList(query);
        int total = thirdMerchExpressService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("thirdmerchexpress:info")
    @ResponseBody
    public R info(@PathVariable("id") Integer id) {
        ThirdMerchExpressEntity thirdMerchExpress = thirdMerchExpressService.queryObject(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("thirdmerchexpress:save")
    @ResponseBody
    public R save(@RequestBody ThirdMerchExpressEntity thirdMerchExpress) {
        Map<String, Object> valideDate = MapBeanUtil.fromObject(thirdMerchExpress);
        ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
        builder.put("expressAccount", "商户快递账号");
        builder.put("expressPwd", "商户快递密码");
        builder.put("expressCusId", "商户快递月结账号");
        builder.put("thirdPartyMerchCode", "第三方商户代码");
        R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
        thirdMerchExpressService.save(thirdMerchExpress);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("thirdmerchexpress:update")
    @ResponseBody
    public R update(@RequestBody ThirdMerchExpressEntity thirdMerchExpress) {
        Map<String, Object> valideDate = MapBeanUtil.fromObject(thirdMerchExpress);
        ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
        builder.put("expressAccount", "商户快递账号");
        builder.put("expressPwd", "商户快递密码");
        builder.put("expressCusId", "商户快递月结账号");
        builder.put("thirdPartyMerchCode", "第三方商户代码");
        R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
        thirdMerchExpressService.update(thirdMerchExpress);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("thirdmerchexpress:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]ids) {
        thirdMerchExpressService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {
        ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");

        List<ThirdMerchExpressEntity> list = thirdMerchExpressService.queryList(params);

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