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

}
最近下载更多
justin8023  LV3 2023年7月10日
泓鼎168  LV19 2023年6月27日
841146628  LV4 2023年6月12日
ly4910  LV3 2023年5月31日
tingyus  LV5 2023年4月22日
斧头帮副帮主  LV5 2023年4月16日
zxc131313  LV12 2023年4月8日
李亮  LV19 2023年3月5日
1515890105  LV2 2023年3月4日
yunYUN123  LV1 2023年2月19日
最近浏览更多
WBelong  LV7 3月29日
quartz  LV7 3月13日
段贤锐  LV8 2月29日
graceful 2023年10月18日
暂无贡献等级
zhaozhiqi  LV5 2023年10月10日
微信网友_6658091507814400  LV3 2023年10月9日
000000000000000000 2023年9月21日
暂无贡献等级
木木不爱安妮酱  LV10 2023年9月16日
czdczd  LV3 2023年9月7日
小温ggggg  LV6 2023年9月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友