package com.hmit.kernes.controller;


import com.hmit.kernes.entity.ZhghCloudAddressEntity;
import com.hmit.kernes.service.ZhghCloudAddressService;
import com.hmit.kernes.utils.PageUtils;
import com.hmit.kernes.utils.Query;
import com.hmit.kernes.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/zhgh/address")
public class ZhghCloudAddressController extends AbstractController {
    @Autowired
    ZhghCloudAddressService zhghCloudAddressService;
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        List<ZhghCloudAddressEntity> list= zhghCloudAddressService.queryList(query);
        int total=zhghCloudAddressService.queryTotal(params);
        PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    @RequestMapping("/info/{id}")
    //@RequiresPermissions("sys:recommend:info")
    public R info(@PathVariable("") Long id){
        ZhghCloudAddressEntity zhghReceptionEntity=zhghCloudAddressService.queryObject(id);

        return R.ok().put("address",zhghReceptionEntity);

    }


    @RequestMapping("/save")
    //@RequiresPermissions("sys:recommend:save")
    public R save(@RequestBody ZhghCloudAddressEntity zhghCloudAddressEntity){
        //数据校验

       zhghCloudAddressEntity.setUpdateTime(new Date());

       zhghCloudAddressService.save(zhghCloudAddressEntity);

        return R.ok();
    }


    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){

        zhghCloudAddressService.deleteBatch(ids);


        return R.ok();
    }

    @RequestMapping("/update")

    public R update(@RequestBody ZhghCloudAddressEntity zhghCloudAddressEntity){
        zhghCloudAddressEntity.setUpdateTime(new Date());
        zhghCloudAddressService.update(zhghCloudAddressEntity);

        return R.ok();
    }

}