Commit f218f619 by 熊付

【动态生成表头】

1 parent 7b0f44e0
......@@ -16,25 +16,25 @@ public class ExportModel {
@ExcelIgnore()
private String product_line_type;
@Excel(name="产品线类型")
private String product_line_type_name; //产品线类型
@Excel(name="签订日期",format="yyyy-MM-dd",width=15)
private Date sign_date; //签订日期
private String product_line_type_name="-"; //产品线类型
@Excel(name="签订日期",width=15)
private String sign_date="-"; //签订日期
@Excel(name="所属月份")
private String month; //所属月份
private String month="-"; //所属月份
@Excel(name="销售员")
private String salesperson_name="-"; //销售员名称
@Excel(name="省")
private String province_name="-"; //省份
@ExcelIgnore()
private String province;
private String province="-";
@Excel(name="市")
private String city_name="-"; //城市
@ExcelIgnore()
private String city;
private String city="-";
@Excel(name="县")
private String county_name="-"; //县
@ExcelIgnore()
private String county;
private String county="-";
@Excel(name="客户名称",width=20)
private String customer_name="-"; //顾客名称
@Excel(name="项目名称",width=20)
......@@ -54,7 +54,7 @@ public class ExportModel {
@Excel(name="合同余额",width=15,type=1,numFormat="###,###.00")
private Double contract_remain; //合同余额
@Excel(name="账款状态",width=15)
private String amount_state_unid_name; //账款 状态
private String amount_state_unid_name="-"; //账款 状态
@ExcelIgnore()
private String amount_state_unid;
@Excel(name="累计应收款",width=15,type=1,numFormat="###,###.00")
......@@ -65,24 +65,24 @@ public class ExportModel {
private Integer over_days; //逾期天数
@Excel(name="预付款金额",width=15,type=1,numFormat="###,###.00")
private Double advance_pay; //预付款金额
@Excel(name="预付款到期日",format="yyyy-MM-dd",width=15)
private Date advance_pay_date; //预付款到期日
@Excel(name="预付款到期日",width=15)
private String advance_pay_date="-"; //预付款到期日
@Excel(name="到货款金额",width=15,type=1,numFormat="###,###.00")
private Double arrive_pay; //到货款金额
@Excel(name="发货日期",format="yyyy-MM-dd",width=15)
private Date deliver_date; //发货日期
@Excel(name="到货款到期日",format="yyyy-MM-dd",width=15)
private Date arrive_pay_date; //到货款到期日
@Excel(name="发货日期",width=15)
private String deliver_date="-"; //发货日期
@Excel(name="到货款到期日",width=15)
private String arrive_pay_date="-"; //到货款到期日
@Excel(name="验收款金额",width=15,type=1,numFormat="###,###.00")
private Double acceptanc_pay; //验收款金额
@Excel(name="验收日期",format="yyyy-MM-dd",width=15)
private Date acceptanc_date; //验收日期
@Excel(name="验收款到期日",format="yyyy-MM-dd",width=15)
private Date acceptanc_pay_date; //验货款到期日
@Excel(name="验收日期",width=15)
private String acceptanc_date="-"; //验收日期
@Excel(name="验收款到期日",width=15)
private String acceptanc_pay_date="-"; //验货款到期日
@Excel(name="质保金额",width=15,type=1,numFormat="###,###.00")
private Double mainten_pay; //质保金额
@Excel(name="质保款到期日",format="yyyy-MM-dd",width=15)
private Date mainten_pay_date; //质保款到期日
@Excel(name="质保款到期日",width=15)
private String mainten_pay_date="-"; //质保款到期日
private String salesperson_unid;
......@@ -104,12 +104,7 @@ public class ExportModel {
public void setProduct_line_type(String product_line_type) {
this.product_line_type = product_line_type;
}
public Date getSign_date() {
return sign_date;
}
public void setSign_date(Date sign_date) {
this.sign_date = sign_date;
}
public String getMonth() {
return month;
}
......@@ -218,60 +213,27 @@ public class ExportModel {
public void setAdvance_pay(Double advance_pay) {
this.advance_pay = advance_pay;
}
public Date getAdvance_pay_date() {
return advance_pay_date;
}
public void setAdvance_pay_date(Date advance_pay_date) {
this.advance_pay_date = advance_pay_date;
}
public Double getArrive_pay() {
return arrive_pay;
}
public void setArrive_pay(Double arrive_pay) {
this.arrive_pay = arrive_pay;
}
public Date getDeliver_date() {
return deliver_date;
}
public void setDeliver_date(Date deliver_date) {
this.deliver_date = deliver_date;
}
public Date getArrive_pay_date() {
return arrive_pay_date;
}
public void setArrive_pay_date(Date arrive_pay_date) {
this.arrive_pay_date = arrive_pay_date;
}
public Double getAcceptanc_pay() {
return acceptanc_pay;
}
public void setAcceptanc_pay(Double acceptanc_pay) {
this.acceptanc_pay = acceptanc_pay;
}
public Date getAcceptanc_date() {
return acceptanc_date;
}
public void setAcceptanc_date(Date acceptanc_date) {
this.acceptanc_date = acceptanc_date;
}
public Date getAcceptanc_pay_date() {
return acceptanc_pay_date;
}
public void setAcceptanc_pay_date(Date acceptanc_pay_date) {
this.acceptanc_pay_date = acceptanc_pay_date;
}
public Double getMainten_pay() {
return mainten_pay;
}
public void setMainten_pay(Double mainten_pay) {
this.mainten_pay = mainten_pay;
}
public Date getMainten_pay_date() {
return mainten_pay_date;
}
public void setMainten_pay_date(Date mainten_pay_date) {
this.mainten_pay_date = mainten_pay_date;
}
public String getSalesperson_unid() {
return salesperson_unid;
}
......@@ -314,5 +276,49 @@ public class ExportModel {
public void setProduct_line_type_name(String product_line_type_name) {
this.product_line_type_name = product_line_type_name;
}
public String getSign_date() {
return sign_date;
}
public void setSign_date(String sign_date) {
this.sign_date = sign_date;
}
public String getAdvance_pay_date() {
return advance_pay_date;
}
public void setAdvance_pay_date(String advance_pay_date) {
this.advance_pay_date = advance_pay_date;
}
public String getDeliver_date() {
return deliver_date;
}
public void setDeliver_date(String deliver_date) {
this.deliver_date = deliver_date;
}
public String getArrive_pay_date() {
return arrive_pay_date;
}
public void setArrive_pay_date(String arrive_pay_date) {
this.arrive_pay_date = arrive_pay_date;
}
public String getAcceptanc_date() {
return acceptanc_date;
}
public void setAcceptanc_date(String acceptanc_date) {
this.acceptanc_date = acceptanc_date;
}
public String getAcceptanc_pay_date() {
return acceptanc_pay_date;
}
public void setAcceptanc_pay_date(String acceptanc_pay_date) {
this.acceptanc_pay_date = acceptanc_pay_date;
}
public String getMainten_pay_date() {
return mainten_pay_date;
}
public void setMainten_pay_date(String mainten_pay_date) {
this.mainten_pay_date = mainten_pay_date;
}
}
......@@ -11,6 +11,7 @@ import org.apache.poi.ss.usermodel.Workbook;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
public class DownLoad {
private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName, HttpServletResponse response,
......@@ -34,5 +35,10 @@ public class DownLoad {
HttpServletResponse response) throws Exception {
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
}
public static void dynamicExportExcel(String title, String sheetName,List<ExcelExportEntity> titlelist,List<Map<String, Object>> vallist,String fileName,HttpServletResponse response) throws Exception{
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(title, sheetName), titlelist, vallist);
if (workbook != null)
downLoadExcel(fileName, response, workbook);
}
}
......@@ -577,11 +577,11 @@
</if>
from (select
contract_unid, salesperson_unid, province, city, county, province_name,city_name,county_name,
guarantee_period, sign_date, product_line_type, contract_state,
guarantee_period,to_char(sign_date, 'yyyy-MM-dd') as sign_date, product_line_type, contract_state,
contract_type, cast(contract_amount as decimal(18,2)), cast(deduct_amount as decimal(18,2)), contract_amount_note,
cast(stop_amount as decimal(18,2)), reback_note, cast(exemptions_amount as decimal(18,2)), contract_remain_note,
is_archive, cast(bad_amount as decimal(18,2)), bad_amount_note, cast(confirm_income_amount as decimal(18,2)),
amount_state_unid, start_guarantee_date, end_guarantee_date,
amount_state_unid, to_char(start_guarantee_date, 'yyyy-MM-dd') as start_guarantee_date, to_char(end_guarantee_date, 'yyyy-MM-dd') as end_guarantee_date,
mainten_start_point, contract_note, is_delete, project_unid,
customer_unid,
to_char(sign_date,'yyyy') as year, to_char(sign_date,'MM') as month,
......@@ -596,14 +596,14 @@
(select cast(e18_view.e18 as decimal(18,2)) from e18_view where e18_view.contract_unid=tb_contract.contract_unid) as arrive_pay,
(select cast(e19_view.e19 as decimal(18,2)) from e19_view where e19_view.contract_unid=tb_contract.contract_unid) as acceptanc_pay,
(select cast(e21_view.e21 as decimal(18,2)) from e21_view where e21_view.contract_unid=tb_contract.contract_unid) as mainten_pay,
(select d18_view.d18 from d18_view where d18_view.contract_unid=tb_contract.contract_unid) as advance_pay_date,
(select d19_view.d19 from d19_view where d19_view.contract_unid=tb_contract.contract_unid) as arrive_pay_date,
(select d20_view.d20 from d20_view where d20_view.contract_unid=tb_contract.contract_unid) as acceptanc_pay_date,
(select d22_view.d21 from d22_view where d22_view.contract_unid=tb_contract.contract_unid) as mainten_pay_date,
to_char((select d18_view.d18 from d18_view where d18_view.contract_unid=tb_contract.contract_unid), 'yyyy-MM-dd') as advance_pay_date,
to_char((select d19_view.d19 from d19_view where d19_view.contract_unid=tb_contract.contract_unid), 'yyyy-MM-dd') as arrive_pay_date,
to_char((select d20_view.d20 from d20_view where d20_view.contract_unid=tb_contract.contract_unid), 'yyyy-MM-dd') as acceptanc_pay_date,
to_char((select d22_view.d21 from d22_view where d22_view.contract_unid=tb_contract.contract_unid), 'yyyy-MM-dd') as mainten_pay_date,
<!-- (select d21_view.d21 from d21_view where d21_view.contract_unid=tb_contract.contract_unid) as mainten_pay_deliver_date,
(select d22_view.d21 from d22_view where d22_view.contract_unid=tb_contract.contract_unid) as mainten_pay_acceptanc_date, -->
(select max(tb_deliver_goods.deliver_goods_date) from tb_deliver_goods where tb_deliver_goods.contract_unid=tb_contract.contract_unid ) as deliver_date,
(select max(tb_project_acceptanc.acceptanc_date) from tb_project_acceptanc where tb_project_acceptanc.contract_unid=tb_contract.contract_unid ) as acceptanc_date
to_char((select max(tb_deliver_goods.deliver_goods_date) from tb_deliver_goods where tb_deliver_goods.contract_unid=tb_contract.contract_unid ), 'yyyy-MM-dd') as deliver_date,
to_char((select max(tb_project_acceptanc.acceptanc_date) from tb_project_acceptanc where tb_project_acceptanc.contract_unid=tb_contract.contract_unid ), 'yyyy-MM-dd') as acceptanc_date
from tb_contract where 1=1
<if test="contract_unid !=null and contract_unid !=''">
and
......
......@@ -57,7 +57,9 @@ import com.vion.financial.vo.ResultVo;
import com.vion.financial.vo.SelectVo;
import com.vion.financial.vo.SuccessCode;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
......@@ -65,7 +67,78 @@ import cn.afterturn.easypoi.handler.inter.IExcelDataHandler;
@Service
public class ContractServiceImpl implements ContractService {
Logger logger = LoggerFactory.getLogger(ContractServiceImpl.class);
Logger logger = LoggerFactory.getLogger(ContractServiceImpl.class);
private static Map<String,String> head_title_name = new HashMap<String,String>();
{
//head_title.put("合同编号", "contract_unid");
head_title_name.put("year","所属年份");
head_title_name.put( "product_line_type","产品线类型");
head_title_name.put("sign_date","签订日期");
head_title_name.put("month","所属月份");
head_title_name.put("salesperson_unid","销售员");
head_title_name.put("province","省");
head_title_name.put("city","市");
head_title_name.put("county","县");
head_title_name.put("customer_unid","客户名称");
head_title_name.put("project_name","项目名称");
head_title_name.put("contract_amount","合同金额");
head_title_name.put("stop_amount","暂停金额");
head_title_name.put("bad_amount","坏账金额");
head_title_name.put("exemptions_amount","豁免金额");
head_title_name.put("deduct_amount","折扣金额");
head_title_name.put("total_reback_amount","累计已收款");
head_title_name.put("contract_remain","合同余额");
head_title_name.put("amount_state_unid","账款状态");
head_title_name.put("total_receive_amount","累计应收款");
head_title_name.put("total_amount_remain","应收账款余额");
head_title_name.put("over_days","逾期天数");
head_title_name.put("advance_pay","预付款金额");
head_title_name.put("advance_pay_date","预付款到期日");
head_title_name.put("arrive_pay","到货款金额");
head_title_name.put("deliver_date","发货日期");
head_title_name.put("arrive_pay_date","到货款到期日");
head_title_name.put("acceptanc_pay","验收款金额");
head_title_name.put("acceptanc_date","验收日期");
head_title_name.put("acceptanc_pay_date","验收款到期日");
head_title_name.put("mainten_pay","质保金额");
head_title_name.put("mainten_pay_date","质保款到期日");
}
private static Map<String,String> head_title_key = new HashMap<String,String>();
{
//head_title.put("合同编号", "contract_unid");
head_title_key.put("year","year");
head_title_key.put( "product_line_type","product_line_type_name");
head_title_key.put("sign_date","sign_date");
head_title_key.put("month","month");
head_title_key.put("salesperson_unid","salesperson_name");
head_title_key.put("province","province_name");
head_title_key.put("city","city_name");
head_title_key.put("county","county_name");
head_title_key.put("customer_unid","customer_name");
head_title_key.put("project_name","project_name");
head_title_key.put("contract_amount","contract_amount");
head_title_key.put("stop_amount","stop_amount");
head_title_key.put("bad_amount","bad_amount");
head_title_key.put("exemptions_amount","exemptions_amount");
head_title_key.put("deduct_amount","deduct_amount");
head_title_key.put("total_reback_amount","total_reback_amount");
head_title_key.put("contract_remain","contract_remain");
head_title_key.put("amount_state_unid","amount_state_unid_name");
head_title_key.put("total_receive_amount","total_receive_amount");
head_title_key.put("total_amount_remain","total_amount_remain");
head_title_key.put("over_days","over_days");
head_title_key.put("advance_pay","advance_pay");
head_title_key.put("advance_pay_date","advance_pay_date");
head_title_key.put("arrive_pay","arrive_pay");
head_title_key.put("deliver_date","deliver_date");
head_title_key.put("arrive_pay_date","arrive_pay_date");
head_title_key.put("acceptanc_pay","acceptanc_pay");
head_title_key.put("acceptanc_date","acceptanc_date");
head_title_key.put("acceptanc_pay_date","acceptanc_pay_date");
head_title_key.put("mainten_pay","mainten_pay");
head_title_key.put("mainten_pay_date","mainten_pay_date");
}
@Autowired
ContractMapper contractMapper;
@Autowired
......@@ -261,7 +334,7 @@ public class ContractServiceImpl implements ContractService {
selectVo.setSalesperson_unids(salesperson_unids.size() > 0 ? salesperson_unids : null);
}
if(salesperson_unids.size() == 0) {
resultVo.setList_data(new ArrayList<>());
resultVo.setList_data(new ArrayList<ContractVo>());
resultVo.setList_size(selectVo.getLimit()== null ? 0 : selectVo.getLimit());
resultVo.setOffset(selectVo.getOffset()== null ? 0 : selectVo.getOffset());
resultVo.setTotal_number(0);
......@@ -590,7 +663,11 @@ public class ContractServiceImpl implements ContractService {
}else {
downLoad.exportExcel(list, "合同Excel表格", "合同Excel表格", ExportModel.class, "合同.xls", response);
}*/
downLoad.exportExcel(list, "合同Excel表格", "合同Excel表格", ExportModel.class, "合同.xls", response);
if(selectVo.getColumns() != null && selectVo.getColumns().length > 0) {
downLoad.dynamicExportExcel("合同Excel表格", "合同Excel表格", dynamicCreatTableHead(selectVo),dynamicCreatTableDatas(list), "合同.xls", response);
}else {
downLoad.exportExcel(list, "合同Excel表格", "合同Excel表格", ExportModel.class, "合同.xls", response);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -1135,5 +1212,38 @@ public class ContractServiceImpl implements ContractService {
return failCode;
}
/***
* 动态生成表头
* @return
*/
private List<ExcelExportEntity> dynamicCreatTableHead(SelectVo selectVo){
String[] cloumns = selectVo.getColumns();
int length = 1 + cloumns.length;
List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>(length);
ExcelExportEntity excelExportEntity = new ExcelExportEntity("合同编号", "contract_unid");
colList.add(excelExportEntity);
Object title_name = null;
Object title_key = null;
for(String clo : cloumns) {
title_name = head_title_name.get(clo);
title_key = head_title_key.get(clo);
if(title_name != null) {
excelExportEntity = new ExcelExportEntity(head_title_name.get(clo), head_title_key.get(clo));
colList.add(excelExportEntity);
}
}
return colList;
}
/***
*动态生成表数据
*/
private List<Map<String, Object>> dynamicCreatTableDatas(List<ExportModel> list) {
List<Map<String, Object>> listValues = null;
if(list != null && list.size() > 0 ) {
listValues = JavaBean2Json.transBean2ListMap(list);
}
return listValues;
}
}
......@@ -5,6 +5,7 @@ import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
......@@ -168,5 +169,45 @@ public class JavaBean2Json {
}
}
return obj;
}
}
public static List<Map<String, Object>> transBean2ListMap(List<?> objs) {
if(objs == null || objs.size() == 0){
return null;
}
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>(objs.size());
for(Object obj : objs) {
maps.add(transBean2Map(obj));
}
return maps;
}
// Bean --> Map 1: 利用Introspector和PropertyDescriptor 将Bean --> Map
public static Map<String, Object> transBean2Map(Object obj) {
if(obj == null){
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
// 过滤class属性
if (!key.equals("class")) {
// 得到property对应的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj);
if(value != null) {
map.put(key, value);
}
}
}
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
return map;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!