从 10月22号组长安排活儿,到现在一周半的时间,开发这样一个功能:读取Excel中指定的行与列,以图形化的形式展现给用户。
具体需求:
用户每天会登录系统填报今天的日报,而我需要做的是从今天的日报中读取指定行与列存入数据库,并以图形化形式展现给用户。其中包含两列:36个专业和9个模块,每种专业从属于一种模块。
我和同事彭捷一起开发,他负责前期前台展示(特别厉害),我负责后台取值,后期又在彭捷的基础上增加了模块名称(图形上面的红色部分)。
需求:
1、 柱子的颜色与专业和模块相对应
2、生产资源显示其他的值,而非百分
3、显示36个专业,同时显示9个模块
一、实体
1、专业
@Entity
@Table(name="DAYRECORDINFO")
public class DayRecordInfo {
private Long id;
private String fileName; //excel文件名称
private String template; //所属模版
private String majorName; //专业名称
private String templateName; //模版名称
private String kaiLeiValue; //开累数量
private String baiFenBiValue; //百分比
private Long departmentID; //建设单位id
private String unit; //单位
private String designValue; //设计数量
private String fileDate; //文件日期
@Id
@TableGenerator(name = "rails_tab_pk", table = "PBS_PKS_TABLE", pkColumnName = "G_KEY", pkColumnValue = "DOCUMENT_ATTACHMENTS_PK", valueColumnName = "G_VALUE", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "rails_tab_pk")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name="FILENAME")
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
@Column(name="TEMPLATE")
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
@Column(name="MAJORNAME")
public String getMajorName() {
return majorName;
}
public void setMajorName(String majorName) {
this.majorName = majorName;
}
@Column(name="TEMPLATENAME")
public String getTemplateName() {
return templateName;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
@Column(name="KAILEVALUE")
public String getKaiLeiValue() {
return kaiLeiValue;
}
public void setKaiLeiValue(String kaiLeiValue) {
this.kaiLeiValue = kaiLeiValue;
}
@Column(name="BAIFENBIVALUE")
public String getBaiFenBiValue() {
return baiFenBiValue;
}
public void setBaiFenBiValue(String baiFenBiValue) {
this.baiFenBiValue = baiFenBiValue;
}
@Column(name="DEPARTMENTID")
public Long getDepartmentID() {
return departmentID;
}
public void setDepartmentID(Long departmentID) {
this.departmentID = departmentID;
}
@Column(name="UNIT")
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
@Column(name="DESIGNVALUE")
public String getDesignValue() {
return designValue;
}
public void setDesignValue(String designValue) {
this.designValue = designValue;
}
@Column(name="FILEDATE")
public String getFileDate() {
return fileDate;
}
public void setFileDate(String fileDate) {
this.fileDate = fileDate;
}
}
2、模块
/**
* 模块
* @author Administrator
*
*/
public class RecordModule {
private Integer index; //索引
private String name; //模块名称
private List dayRecordInfos; //模块包含的专业
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List getDayRecordInfos() {
return dayRecordInfos;
}
public void setDayRecordInfos(List dayRecordInfos) {
this.dayRecordInfos = dayRecordInfos;
}
}
二、Action
/**
* 显示每日记录
*
* @return
*/
public String show() {
String template="showImageTemplateVersionThree";
// ==============================数据库中获取当天36个专业的信息============================
List listAllMajor = new ArrayList();
listAllMajor=recordImageManager.checkDayRecord(template);
if(listAllMajor.size()>0){
Set moduleNames = new LinkedHashSet();
for(int i = 0; i < listAllMajor.size(); i++ ){
moduleNames.add(listAllMajor.get(i).getTemplateName());
}
System.out.println(moduleNames);
List moduleList = new ArrayList();
List majorNums = new ArrayList();
//遍历所有的模块及专业,记录相应的模块下包含哪些专业
int i = 0;
int maxPr = 0;
for (String moduleName : moduleNames) {
i ++;
RecordModule module = new RecordModule();
module.setName(moduleName);
List mjList = new ArrayList();
int count = 0;
for (DayRecordInfo dayRecordInfo : listAllMajor) {
if(dayRecordInfo.getTemplateName().equals("生产资源")){
//System.out.println("开累:"+major.getKailei());
maxPr = Integer.valueOf(dayRecordInfo.getKaiLeiValue()) > maxPr
? Integer.valueOf(dayRecordInfo.getKaiLeiValue()) : maxPr;
}
if(dayRecordInfo.getTemplateName().equals(moduleName)){
mjList.add(dayRecordInfo);
count ++;
}
}
majorNums.add(count);
module.setIndex(i);
module.setDayRecordInfos(mjList);
moduleList.add(module);
}
//初始化几种颜色
String[] colors = new String[]{"#C1232B", "#B5C334","#FCCE10", "#E87C25", "#27727B",
"#FE8463", "#9BCA63", "#FAD860",
"#F3A43B", "#60C0DD", "#D7504B",
"#C6E579", "#F4E001", "#F0805A","#26C0C0" };
List persentList = new ArrayList();
List kaileiList = new ArrayList();
List colorList = new ArrayList();
List majorNames = new ArrayList();
List unitList=new ArrayList();
List designList=new ArrayList();
//如果模块名称为生产资源则将其开累值放到百分比集合中
for (RecordModule module : moduleList) {
for (DayRecordInfo dayRecordInfo : module.getDayRecordInfos()) {
colorList.add(colors[module.getIndex()]);
if(dayRecordInfo.getTemplateName().equals("生产资源")){
persentList.add(Double.valueOf(dayRecordInfo.getKaiLeiValue())/maxPr*100+"");
}else{
persentList.add(dayRecordInfo.getBaiFenBiValue());
}
kaileiList.add(dayRecordInfo.getKaiLeiValue());
majorNames.add(dayRecordInfo.getMajorName());
unitList.add(dayRecordInfo.getUnit());
designList.add(dayRecordInfo.getDesignValue());
}
}
//转json并放到栈顶
ActionContext.getContext().put("persentList", JSONArray.fromObject(persentList,MyJSONObject.jsonConfig).toString());
ActionContext.getContext().put("kaileiList", JSONArray.fromObject(kaileiList,MyJSONObject.jsonConfig).toString());
ActionContext.getContext().put("colorList", JSONArray.fromObject(colorList).toString());
ActionContext.getContext().put("majorNames", JSONArray.fromObject(majorNames).toString());
ActionContext.getContext().put("majorNums", JSONArray.fromObject(majorNums).toString());
ActionContext.getContext().put("moduleNames", JSONArray.fromObject(moduleNames).toString());
ActionContext.getContext().put("maxPr", JSONArray.fromObject(maxPr).toString());
ActionContext.getContext().put("unitList",JSONArray.fromObject(unitList).toString());
ActionContext.getContext().put("designList",JSONArray.fromObject(designList).toString());
System.out.println(JSONArray.fromObject(majorNums).toString());
System.out.println(unitList);
}
return "view";
}
三、jsp <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/rails.jsp"%>
<%@ include file="/theme/theme.jsp"%>
注:
模块名称现在还是写死的,位置并未相对于本模块内的所有专业对齐
两个横坐标的实现思路:将柱状图的很坐标模块名称放在图形顶部,再重新构建一个新的柱状图只显示36个专业(通过坐标和文字旋转,将两个图形一一对应)
小结:
第一版做的时候无法同时显示模块名称与专业,由于echarts无法同时显示两个坐标,但用户又要求同时显示专业和模块。当时那个无助,不知道怎么去实现,问了大牛彭捷,彭捷直接就回绝了(别的可以,这个做不了),那怎么办!查资料的时候突然看到横坐标可以置顶就想到了再创建一个只有横坐标的柱状图,虽然办法看起来笨笨的,但是满足了用户需求,还是蛮欣慰的。做这个功能时,因为各方面原因,有些急躁了,没有好好去想办法解决这个问题。最后在用户和组长的强烈要求下,我也也一步步实现了用户要求的想法,万事不要着急,多去思考。