package com.ssx.controller;

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

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssx.entity.Bill;
import com.ssx.service.BillService;
import com.ssx.utils.DataGridViewResult;
import com.ssx.vo.BillVo;

/**
 * @author WANG
 *
 */
@RestController
@RequestMapping("/bill")
public class BillController {

    @Resource
    private BillService billService;

    @RequestMapping("/list")
    public DataGridViewResult list(BillVo billVo){
        //设置分页信息(当前页码,每页显示数量)
        PageHelper.startPage(billVo.getPage(),billVo.getLimit());
        //调用分页查询账单列表的方法
        List<Bill> billList = billService.findBillList(billVo);
        //创建分页对象
        PageInfo<Bill> pageInfo = new PageInfo<Bill>(billList);
        //返回数据
        return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 添加账单
     * @param bill
     * @return
     */
    @RequestMapping("/addBill")
    public String addBill(Bill bill){
        Map<String,Object> map = new HashMap<String,Object>();
        if(billService.addBill(bill)>0){
            map.put("success",true);
            map.put("message","添加成功");
        }else{
            map.put("success",false);
            map.put("message","添加失败");
        }
        return JSON.toJSONString(map);
    }


    /**
     * 修改账单
     * @param bill
     * @return
     */
    @RequestMapping("/updateBill")
    public String updateBill(Bill bill){
        Map<String,Object> map = new HashMap<String,Object>();
        if(billService.updateBill(bill)>0){
            map.put("success",true);
            map.put("message","修改成功");
        }else{
            map.put("success",false);
            map.put("message","修改失败");
        }
        return JSON.toJSONString(map);
    }


    /**
     * 删除账单
     * @param id
     * @return
     */
    @RequestMapping("/deleteById")
    public String deleteById(Integer id){
        Map<String,Object> map = new HashMap<String,Object>();
        if(billService.deleteById(id)>0){
            map.put("success",true);
            map.put("message","删除成功");
        }else{
            map.put("success",false);
            map.put("message","删除失败");
        }
        return JSON.toJSONString(map);
    }

    /**
     * 批量删除账单
     * @param ids
     * @return
     */
    @RequestMapping("/batchDelete")
    public String batchDelete(String ids){
        Map<String,Object> map = new HashMap<String,Object>();
        int count = 0;
        //将字符串拆分成数组
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            count = billService.deleteById(Integer.valueOf(idsStr[i]));
            if(count>0){
                map.put("success",true);
                map.put("message","删除成功");
            }
        }
        //判断受影响行数是否为0
        if(count<=0){
            map.put("success",false);
            map.put("message","删除失败");
        }
        return JSON.toJSONString(map);
    }

}
最近下载更多
李亮  LV19 3月5日
1515890105  LV2 3月4日
yunYUN123  LV1 2月19日
jlmarket  LV20 2022年12月2日
大张旗鼓  LV4 2022年11月27日
jay1992  LV10 2022年4月27日
huyyyyy  LV8 2021年12月24日
543666826  LV33 2021年11月28日
xuyongff  LV24 2021年11月25日
Fireloli  LV9 2021年11月24日
最近浏览更多
暂无贡献等级
斧头帮副帮主  LV1 3月24日
uni-code_0123  LV1 3月23日
tatakai  LV2 3月22日
zengxq056  LV2 3月22日
laochen3000  LV1 3月20日
全栈小白  LV18 3月18日
guviva  LV6 3月9日
夜起星河  LV6 3月9日
起名字是个麻烦事  LV12 3月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友