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);
}
}
最近下载更多
最近浏览更多
奋斗的小蚂蚁 LV16
9月22日
hsghsg123465
6月20日
暂无贡献等级
user100
6月10日
暂无贡献等级
13188866605 LV12
4月18日
可是不知道么 LV23
3月29日
天空java LV8
3月23日
哪里的完整版 LV8
3月1日
wlax99 LV12
2月17日
talete LV3
2024年9月29日
微信网友_7151914139078656 LV2
2024年9月4日

