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);
    }

}
最近下载更多
taoshen95  LV16 4月6日
china_hdh  LV7 2024年8月29日
全斐  LV6 2024年6月19日
TY0165  LV20 2024年6月18日
justin8023  LV3 2023年7月10日
泓鼎168  LV20 2023年6月27日
841146628  LV4 2023年6月12日
ly4910  LV3 2023年5月31日
tingyus  LV5 2023年4月22日
斧头帮副帮主  LV5 2023年4月16日
最近浏览更多
可是不知道么  LV23 3月29日
天空java  LV8 3月23日
哪里的完整版  LV8 3月1日
wlax99  LV12 2月17日
talete  LV3 2024年9月29日
微信网友_7151914139078656  LV2 2024年9月4日
china_hdh  LV7 2024年8月29日
全斐  LV6 2024年6月19日
TY0165  LV20 2024年6月18日
chirsbey2 2024年5月10日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友