报表分组和饼图

                报表分组和饼图

效果图:

Donmain层的配置:

private Long id; //编号

private String supplier; //供应商名称

private String buyer; //采购员名称

private String product; //产品名称

private String productType; //产品分类

private Date vdate; //交易时间

private BigDecimal num; //采购数量

private BigDecimal price; //价格

private BigDecimal amount; //小计 = 价格*数量

private Integer status;

private String groupField = ""; //分组字段

//构造方法简介建立关系
public PurchaseBillItemVo(Purchasebillitem item){
this.id=item.getId();
this.supplier=item.getBill().getSupplier().getName();
this.buyer=item.getBill().getBuyer().getUsername();
this.product=item.getProduct().getName();
this.productType=item.getProduct().getTypes().getName();
this.vdate=item.getBill().getVdate();
this.num=item.getNum();
this.price=item.getPrice();
this.amount=item.getAmount();
this.status=item.getBill().getStatus();

}
//分组
public PurchaseBillItemVo(Purchasebillitem item,String groupBy){
this.id = item.getId();
this.supplier = item.getBill().getSupplier().getName();
this.buyer = item.getBill().getBuyer().getUsername();
this.product = item.getProduct().getName();
this.productType = item.getProduct().getTypes().getName();
this.vdate = item.getBill().getVdate();
this.num = item.getNum();
this.price = item.getPrice();
this.amount = item.getAmount();
this.status = item.getBill().getStatus();
//根据传入的条件 进行分组
if("o.bill.supplier.name".equals(groupBy)){
this.groupField = this.supplier;
}else if("o.bill.buyer.username".equals(groupBy)){
this.groupField = this.buyer;
}else if("MONTH(o.bill.vdate)".equals(groupBy)){
//this.groupField = this.vdate; 7 8
this.groupField = (DateUtils.toCalendar(this.vdate).get(Calendar.MONTH)+1)+"";
}else{
this.groupField = this.supplier;
}
}
//无参
public PurchaseBillItemVo (){}


public String getGroupField() {
//设置分组字段 默认按照供应商分组
// this.groupField = this.supplier;
return groupField;
}

public void setGroupField(String groupField) {
this.groupField = groupField;
}

Service层方法的:

//分组方法的实现
@Override
public List<PurchaseBillItemVo> findItems(PurchasebillitemQuery itemQuery) {

List<Purchasebillitem> items = purchasebillitemRepository.findByQuery(itemQuery);

List<PurchaseBillItemVo> itemsvolist = new ArrayList<>();

for (Purchasebillitem item : items) {
PurchaseBillItemVo itemVo = new PurchaseBillItemVo(item,itemQuery.getGroupBy());
itemsvolist.add(itemVo);
}

return itemsvolist;
}

流程:点击报表加载数据进去conreoller层调用service的方法进行分组查询  返回json数据  前端页面自动封装

controller层map的封装

饼状图的实现:

定义两个按钮分别为2D  3D定义在高级查询下面

引入饼状图需要的配置文件:

粘贴JS代码进行查询封装:

$(function(){
//定义form表单
var searchForm = $("#searchForm");
var purchasebillitemDialog = $("#purchasebillitemDialog");
$("a[data-method]").on('click',function(){
//获取 data-method属性 <a data-method="seacher">
var methodName = $(this).data("method");
//动态调用方法 itsource["seacher"]
itsource[methodName]();
});
//对象
var itsource = {
search:function(){
//该方法返回一个 JSON Object,返回对象中的每个数据都表示一个表单控件值。
var param = searchForm.serializeObject();
//发送查询数据库 --加载表格 发送请求 /purchasebillitem/page
$('#purchasebillitemDatagrid').datagrid('load',param);
},
charts3D:function(){
//发送ajax请求到后台查询的数据
var param = searchForm.serializeObject();
$.post("/purchaseBillItem/findAllGraphic",param,function(result){

Highcharts.chart('purchasebillitemDialog', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45, //倾斜角度
beta: 0
}
},
title: {
text: '比例图'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
depth: 35,//深度
dataLabels: {
enabled: true,
format: '{point.name}'
}
}
},
series: [{
type: 'pie',
name: '消费比例',
data:result
}]
});
})




//2D图表 --打开对话框
purchasebillitemDialog.dialog('center').dialog('open');
},
//2D事件
charts2D:function(){

var param = searchForm.serializeObject();
$.post("/purchaseBillItem/findAllGraphic",param,function(result){

Highcharts.chart('purchasebillitemDialog', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 0, //倾斜角度
beta: 0
}
},
title: {
text: '比例图'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
depth: 35,//深度
dataLabels: {
enabled: true,
format: '{point.name}'
}
}
},
series: [{
type: 'pie',
name: '消费比例',
data:result
}]
});
})




purchasebillitemDialog.dialog('center').dialog('open');

}
}



});





$(function(){
$('#purchasebillitemDatagrid').datagrid({
width:500,
height:250,
fit:true,
rownumbers:true,
remoteSort:false,
nowrap:false,
fitColumns:true,
toolbar:'#tb',
url:'/purchaseBillItem/findAllItemVo',
columns:[[
{field:'id',title:'编号',width:100,sortable:true},
{field:'supplier',title:'供应商名称',width:80,align:'right',sortable:true},
{field:'buyer',title:'采购员名称',width:80,align:'right',sortable:true},
{field:'product',title:'产品名称',width:150,sortable:true},
{field:'productType',title:'产品分类',width:60,align:'center'},
{field:'vdate',title:'交易时间',width:180,align:'right',sortable:true},
{field:'num',title:'数量',width:50,sortable:true},
{field:'price',title:'价格',width:60,align:'center'},
{field:'amount',title:'小计',width:60,align:'center'},
{field:'status',title:'状态',width:60,align:'center',formatter:statusFormatter}
]],
groupField:'groupField',
view: groupview,
groupFormatter:function(value, rows){
var totalNum =0;
var totalAmount = 0;
//rows表示当前分组下面的行
for(var i=0;i<rows.length;i++){
var row = rows[i];//循环每一行
totalNum += row.num;
totalAmount += row.amount;
}
return value + ' - ' + rows.length + ' 条数据' +" <span style='color:green;'>"+totalNum+"件商品</span>" +"<span style='color:#6b3980;'>总金额:"+totalAmount+"</span>";
} })
;})
;

 初始化状态:

 饼状图根据查询传递的参数进行拼装sqpl语句:

public String getWhereSql(){

String sql = "";

if(beginDate != null && !"".equals(beginDate)){
sql += " and b.vdate >= ?";
params.add(beginDate);
}

if(endDate != null && !"".equals(endDate)){
sql += " and b.vdate < ?";
params.add(endDate);
}

if(status != null && !"".equals(status)){
sql += " and b.status = ?";
params.add(status);
}

return sql.replace("and", "where");

}

public List getParams() {
return params;
}

public void setParams(List params) {
this.params = params;
}

 饼状图效果图:

 

猜你喜欢

转载自www.cnblogs.com/1999wang/p/11361016.html
今日推荐