package com.sptg.estate.biz.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sptg.estate.api.entity.BillsItem;
import com.sptg.estate.api.feigns.BillsItemFeign;
import com.sptg.estate.biz.service.IBillsItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lianghanqiang
 * @since 2021-01-19
 */
@RestController
@RequestMapping("/bills-item")
public class BillsItemController implements BillsItemFeign {
    @Autowired
    private IBillsItemService billsItemService;

    /**
     *  获取缴费项列表
     * */
    @GetMapping("/list")
    @Override
    public  List<BillsItem> list(@RequestParam("billsId") Long billsId) {
        return billsItemService.selectList(new EntityWrapper<>(new BillsItem()).eq("pid",billsId));
    }

    /**
     *  获取缴费项详情
     * */
    @GetMapping("/detail")
    @Override
    public BillsItem detail(@RequestParam(value = "id",required = true) Long id) {
        return billsItemService.selectById(id);
    }

    /**
     *  根据id删除缴费项
     * */
    @GetMapping("/delete")
    @Override
    public boolean delete(@RequestParam(value = "billsId",required = true) Long billsId) {
        return billsItemService.delete(new EntityWrapper<>(new BillsItem()).eq("pid",billsId));
//        return billsItemService.deleteById(id);
    }

    /**
     *  编辑缴费项
     * */
    @GetMapping("/edit")
    @Override
    public boolean edit(@RequestBody BillsItem billsItem) {
        return billsItemService.updateById(billsItem);
    }

    /**
     *  编辑缴费项
     * */
    @PostMapping("/add")
    @Override
    public boolean add(@RequestBody BillsItem billsItem) {
        return billsItemService.insert(billsItem);
    }
}

