package com.product.server.report.service;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.service.support.AbstractBaseService;
|
import com.product.core.service.support.QueryFilterService;
|
import com.product.core.transfer.Transactional;
|
import com.product.server.report.config.CmnConst;
|
import com.product.server.report.service.idel.IChartPropertyConfigService;
|
import com.product.util.BaseUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
@Service
|
public class ChartPropertyConfigService extends AbstractBaseService implements IChartPropertyConfigService {
|
|
@Autowired
|
BaseDao baseDao;
|
|
@Autowired
|
QueryFilterService queryFilterService;
|
@Override
|
@Transactional
|
public String addChartsMasterTable(FieldSetEntity fse) throws BaseException {
|
DataTableEntity chartsData = fse.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS);
|
if(chartsData.getRows() == 1){
|
fse.setValue("type_uuid", chartsData.getString(0, "report_type_config_uuid"));
|
fse.setValue("is_valid", 1);
|
}
|
fse.removeSubData(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS);
|
fse.setValue("is_load", 0);
|
String uuid = baseDao.add(fse);
|
for (int i = 0; i < chartsData.getRows(); i++) {
|
FieldSetEntity chartsField = chartsData.getFieldSetEntity(i);
|
chartsField.setValue("report_config_uuid",uuid);
|
if("empty".equals(chartsField.getString("type"))){
|
baseDao.add(chartsField);
|
continue;
|
}
|
DataTableEntity attributeData = chartsField.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
|
chartsField.removeSubData(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
|
String chartsUuid = baseDao.add(chartsField);
|
for (int j = 0; j < attributeData.getRows(); j++) {
|
FieldSetEntity attributeField = attributeData.getFieldSetEntity(j);
|
attributeField.setValue("report_config_uuid", chartsUuid);
|
String report_type_attr_value = attributeField.getString("report_type_attr_value");
|
if(!BaseUtil.strIsNull(report_type_attr_value) && report_type_attr_value.contains("{#") && report_type_attr_value.contains("#}")){
|
String field_name = report_type_attr_value.replace("{#", "").replace("#}", "");
|
attributeField.setValue("field_name", field_name);
|
}
|
baseDao.add(attributeField);
|
}
|
}
|
return uuid;
|
}
|
|
@Override
|
@Transactional
|
public Boolean upChartsMasterTable(FieldSetEntity fse) throws BaseException {
|
//具体类型子表
|
DataTableEntity subChartsData = fse.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS);
|
if(subChartsData.getRows() == 1){
|
fse.setValue("type_uuid", subChartsData.getString(0, "report_type_config_uuid"));
|
fse.setValue("is_valid", 1);
|
}
|
fse.setValue("is_load", 0);
|
fse.removeSubData(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS);
|
if(!BaseUtil.dataTableIsEmpty(subChartsData)){
|
for (int i = 0; i < subChartsData.getRows(); i++) {
|
FieldSetEntity subChartsFieldSet = subChartsData.getFieldSetEntity(i);
|
String status = subChartsFieldSet.getString("status");
|
subChartsFieldSet.remove("status");
|
String subChartsUuid = subChartsFieldSet.getUUID();
|
subChartsFieldSet.setValue("report_config_uuid", fse.getUUID());
|
//处理空白
|
if("empty".equals(subChartsFieldSet.getString("type"))){
|
if("add".equals(status)) {
|
baseDao.add(subChartsFieldSet);
|
}else if("delete".equals(status)){
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS, new String[]{subChartsUuid});
|
}else if("update".equals(status)){
|
baseDao.update(subChartsFieldSet);
|
}
|
continue;
|
}
|
DataTableEntity attributeDataTable = subChartsFieldSet.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
|
subChartsFieldSet.removeSubData(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
|
|
//删除当前选择的图表类型 及属性值子表
|
if("delete".equals(status)){
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS, new String[]{subChartsUuid});
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, " report_config_uuid = ? ",new String[]{subChartsUuid});
|
continue;
|
}
|
if ("add".equals(status)) {
|
String uuid = baseDao.add(subChartsFieldSet);
|
if(!BaseUtil.dataTableIsEmpty(attributeDataTable)){
|
for (int j = 0; j < attributeDataTable.getRows(); j++) {
|
FieldSetEntity fieldSetEntity = attributeDataTable.getFieldSetEntity(j);
|
fieldSetEntity.setValue("report_config_uuid", uuid);
|
baseDao.add(fieldSetEntity);
|
}
|
}
|
continue;
|
}
|
//先删除之前所有属性值子表数据
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, " report_config_uuid = ? ", new String[]{subChartsUuid});
|
//再添加数据
|
if(!BaseUtil.dataTableIsEmpty(attributeDataTable)){
|
for (int j = 0; j < attributeDataTable.getRows(); j++) {
|
FieldSetEntity fieldSetEntity = attributeDataTable.getFieldSetEntity(j);
|
fieldSetEntity.setValue("report_config_uuid", subChartsUuid);
|
String report_type_attr_value = fieldSetEntity.getString("report_type_attr_value");
|
if(!BaseUtil.strIsNull(report_type_attr_value) && report_type_attr_value.contains("{#") && report_type_attr_value.contains("#}")){
|
String field_name = report_type_attr_value.replace("{#", "").replace("#}", "");
|
fieldSetEntity.setValue("field_name", field_name);
|
}
|
baseDao.add(fieldSetEntity);
|
}
|
}
|
if("update".equals(status)){
|
baseDao.update(subChartsFieldSet);
|
}
|
}
|
}
|
return baseDao.update(fse);
|
}
|
|
@Override
|
@Transactional
|
public Boolean delChartsMasterTable(FieldSetEntity fse) throws BaseException {
|
String[] uuids = fse.getUUID().split(",");
|
for (int i = 0; i < uuids.length; i++) {
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS, "report_config_uuid = ?",new String[]{uuids[i]});
|
baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, "report_config_uuid in (SELECT uuid FROM product_sys_report_config_charts where report_config_uuid = ?)",new String[]{uuids[i]});
|
}
|
return baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG, uuids);
|
}
|
|
@Override
|
public JSONObject getChartsMasterTable(String uuid) throws BaseException {
|
FieldSetEntity configField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG,uuid,false);
|
DataTableEntity dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS, "report_config_uuid = ?", new String[]{uuid});
|
JSONArray jsonArray = new JSONArray();
|
for (int i = 0; i < dataTableEntity.getRows(); i++) {
|
FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
|
String config_charts_uuid = fieldSetEntity.getString(CmnConst.UUID);
|
String report_type_config_uuid = fieldSetEntity.getString("report_type_config_uuid");
|
JSONObject chartsObj = BaseUtil.fieldSetEntityToJson(fieldSetEntity);
|
//获取元素及元素值
|
chartsObj.put("element",this.getEChartsElement(report_type_config_uuid, config_charts_uuid));
|
jsonArray.add(chartsObj);
|
}
|
JSONObject object = new JSONObject();
|
object.put("report_name",configField.getString("report_name"));
|
object.put("report_width_type",configField.getString("report_width_type"));
|
object.put("report_width_value",configField.getString("report_width_value"));
|
object.put("is_valid",configField.getString("is_valid"));
|
object.put("chartsObject", jsonArray);
|
return object;
|
}
|
|
@Override
|
public DataTableEntity getChartsMasterList(FieldSetEntity fse) throws BaseException {
|
StringBuffer sql = new StringBuffer();
|
sql.append(" SELECT * FROM ( ")
|
.append(" select b.uuid,b.report_name FROM product_sys_report_config_charts a left join PRODUCT_SYS_report_config b on a.report_config_uuid = b.uuid WHERE b.function_uuid is null or b.function_uuid = '' group by b.uuid,b.report_name ) c ");
|
if (!BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))) {
|
sql.append(" where " + queryFilterService.getQueryFilter(fse));
|
}
|
return baseDao.listTable(sql.toString(), new String[]{}, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
|
}
|
|
@Override
|
public JSONObject getChartsTypeData(String uuid) throws BaseException {
|
// FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_CONFIG, uuid, false);
|
// DataTableEntity dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE, "type_uuid = ? and config_properties = 1", new String[]{uuid});
|
// fieldSetEntity.addSubDataTable(dataTableEntity);
|
return this.getEChartsElement(uuid, null);
|
}
|
|
/**
|
* 获取上级属性树
|
* report_type_config_uuid 属性类型主表uuid
|
* config_charts_uuid 中间表uuid
|
* xinluo
|
* @return
|
*/
|
public JSONObject getEChartsElement(String report_type_config_uuid,String config_charts_uuid) throws BaseException {
|
FieldSetEntity masterField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_CONFIG,report_type_config_uuid,false);
|
DataTableEntity dataTableEntity = this.getEChartsElementList(report_type_config_uuid);
|
String[] parameter = new String[]{"f", "e", "d", "c", "b", "a"};
|
JSONArray array = new JSONArray();
|
for (int j = 0; j < parameter.length; j++) {
|
for (int i = 0; i <dataTableEntity.getRows(); i++) {
|
FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
|
if(BaseUtil.strIsNull(fieldSetEntity.getString("nonRepeating"))){
|
//如果父属性或属性不为空,取出当前数据所有父子元素
|
if(!BaseUtil.strIsNull(fieldSetEntity.getString(parameter[j]+"name"))){
|
array = this.returnTree(fieldSetEntity,parameter,j, array, config_charts_uuid);
|
//存入树的元素需要从dataTableEntity里面剃掉
|
fieldSetEntity.setValue("nonRepeating", 1);
|
}
|
}
|
}
|
}
|
JSONObject object = BaseUtil.fieldSetEntityToJson(masterField);
|
//获取是否子元素有分组字段 如有分组字段 需添加分组
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject jsonObject = array.getJSONObject(i);
|
this.getGroupAttributes(jsonObject);
|
}
|
|
object.put(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE,array);
|
return object;
|
}
|
|
/**
|
* 获取子集分组元素
|
* @param jsonObject
|
*/
|
public void getGroupAttributes(JSONObject jsonObject){
|
JSONArray children = jsonObject.getJSONArray("children");
|
if(children != null && children.size() > 0) {
|
for (int i = 0; i < children.size(); i++) {
|
JSONObject object = children.getJSONObject(i);
|
String grouping = object.getString("grouping");
|
JSONArray subChildren = object.getJSONArray("children");
|
if ("1".equals(grouping) && "1".equals(jsonObject.getString("subordinateElementType"))) {
|
JSONObject group = new JSONObject();
|
group.put("children", JSONArray.parseArray(children.toJSONString()));
|
group.put("label", "组名");
|
group.put("value", "1");
|
JSONArray newArray = new JSONArray();
|
newArray.add(group);
|
jsonObject.put("children", newArray);
|
String reportConfigUuid = object.getString("report_config_uuid");
|
String reportTypeAttr = object.getString("report_type_attr");
|
DataTableEntity dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, " report_type_attr = ? AND report_config_uuid = ? and grouping != 1 ", new String[]{reportTypeAttr, reportConfigUuid});
|
for (int j = 0; j < dataTableEntity.getRows(); j++) {
|
JSONObject groupNew = JSONObject.parseObject(group.toJSONString());
|
String key = dataTableEntity.getString(j, "grouping");
|
groupNew.put("label", "组名");
|
groupNew.put("value", key);
|
newArray.add(this.addGroupAttributes(groupNew, key));
|
}
|
} else if (subChildren != null && subChildren.size() > 0) {
|
this.getGroupAttributes(object);
|
}
|
}
|
}
|
}
|
|
/**
|
* 添加子集分组元素
|
* @param group
|
*/
|
public JSONObject addGroupAttributes(JSONObject group, String key){
|
JSONArray children = group.getJSONArray("children");
|
if(children != null && children.size() > 0) {
|
for (int i = 0; i < children.size(); i++) {
|
this.addGroupAttributes(children.getJSONObject(i), key);
|
}
|
}
|
String reportConfigUuid = group.getString("report_config_uuid");
|
String reportTypeAttr = group.getString("report_type_attr");
|
if(!BaseUtil.strIsNull(reportConfigUuid) && !BaseUtil.strIsNull(reportTypeAttr)){
|
FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, " report_type_attr = ? AND report_config_uuid = ? AND grouping = ? ", new String[]{reportTypeAttr, reportConfigUuid, key}, false);
|
if(fieldSetEntity != null) {
|
group.put("config_attribute_uuid", fieldSetEntity.getString("uuid"));
|
//列表关.PRODUCT_SYS_report_config,图表关.PRODUCT_SYS_report_config_charts表UUID
|
group.put("report_config_uuid", fieldSetEntity.getString("report_config_uuid"));
|
//关联属.PRODUCT_SYS_report_type_attribute表UUID
|
group.put("report_type_attr", fieldSetEntity.getString("report_type_attr"));
|
//字段名称
|
group.put("field_name", fieldSetEntity.getString("field_name"));
|
//属性值
|
group.put("report_type_attr_value", fieldSetEntity.getString("report_type_attr_value"));
|
//分组标识,加载多条数据需要加标识
|
group.put("grouping", key);
|
}
|
}
|
return group;
|
}
|
|
/**
|
* 获取上级属性列表
|
* xinluo
|
* @return
|
*/
|
public DataTableEntity getEChartsElementList(String uuid)throws BaseException{
|
StringBuffer sql = new StringBuffer();
|
sql.append(" SELECT a.uuid auuid,a.detail adetail,a.attribute_name aname,a.subordinateElementType asubordinateElementType,a.prompt_name,a.default_value, ")
|
.append(" b.uuid buuid,b.detail bdetail,b.attribute_name bname,b.subordinateElementType bsubordinateElementType, ")
|
.append(" c.uuid cuuid,c.detail cdetail,c.attribute_name cname,c.subordinateElementType csubordinateElementType, ")
|
.append(" d.uuid duuid,d.detail ddetail,d.attribute_name dname,d.subordinateElementType dsubordinateElementType, ")
|
.append(" e.uuid euuid,e.detail edetail,e.attribute_name ename,e.subordinateElementType esubordinateElementType, ")
|
.append(" f.uuid fuuid,f.detail fdetail,f.attribute_name fname,f.subordinateElementType fsubordinateElementType FROM ")
|
.append("product_sys_report_type_attribute a LEFT JOIN ")
|
.append("product_sys_report_type_attribute b on a.parentAttributeUuid = b.uuid LEFT JOIN ")
|
.append("product_sys_report_type_attribute c on b.parentAttributeUuid = c.uuid LEFT JOIN ")
|
.append("product_sys_report_type_attribute d on c.parentAttributeUuid = d.uuid LEFT JOIN ")
|
.append("product_sys_report_type_attribute e on d.parentAttributeUuid = e.uuid LEFT JOIN ")
|
.append("product_sys_report_type_attribute f on e.parentAttributeUuid = f.uuid ")
|
.append(" WHERE a.config_properties = 1 ")
|
.append(" AND a.type_uuid = ? ");
|
|
return baseDao.listTable(sql.toString(), new String[]{uuid});
|
}
|
|
/**
|
* @param fieldSetEntity
|
* @param parameter
|
* @param paramIndex
|
* @param array
|
* @return
|
* 同级元素不能重复 xinluo
|
*/
|
public JSONArray returnTree(FieldSetEntity fieldSetEntity, String[] parameter, int paramIndex,JSONArray array, String config_charts_uuid){
|
boolean flag = true;
|
String value = fieldSetEntity.getString(parameter[paramIndex]+"name");
|
if(array.size() > 0) {
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject jsonObject = array.getJSONObject(i);
|
String objValue = jsonObject.getString("value");
|
//子属性相同
|
if(objValue == null)
|
System.out.println("null");
|
if (objValue.equals(value)) {
|
paramIndex++;
|
JSONArray childrenArray = jsonObject.getJSONArray("children");
|
flag = false;
|
if (paramIndex < parameter.length && childrenArray != null && childrenArray.size() > 0) {
|
this.returnTree(fieldSetEntity, parameter, paramIndex, childrenArray, config_charts_uuid);
|
}
|
}
|
}
|
//子属性不同
|
if(flag){
|
return this.returnChildrenTree(fieldSetEntity, parameter, paramIndex, array, config_charts_uuid);
|
}
|
}else {
|
return this.returnChildrenTree(fieldSetEntity, parameter, paramIndex, array, config_charts_uuid);
|
}
|
return array;
|
}
|
//封装子元素 xinluo
|
public JSONArray returnChildrenTree(FieldSetEntity fieldSetEntity, String[] parameter, Integer paramIndex,JSONArray array, String config_charts_uuid){
|
Boolean is_addGroup = true;
|
//元素名
|
String name = fieldSetEntity.getString(parameter[paramIndex]+"name");
|
//元素描述
|
String detail = fieldSetEntity.getString(parameter[paramIndex]+"detail");
|
//元素uuid
|
String uuid = fieldSetEntity.getString(parameter[paramIndex]+"uuid");
|
//元素子元素类型
|
String subType = fieldSetEntity.getString(parameter[paramIndex]+"subordinateElementType");
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("value",name);
|
jsonObject.put("label",detail);
|
jsonObject.put("uuid",uuid);
|
jsonObject.put("subordinateElementType",subType);
|
jsonObject.put("config_properties",fieldSetEntity.getString("config_properties"));
|
paramIndex++;
|
if(paramIndex < parameter.length) {
|
JSONArray childrenArray = new JSONArray();
|
jsonObject.put("children", this.returnTree(fieldSetEntity, parameter, paramIndex, childrenArray, config_charts_uuid));
|
}else {
|
// 字典值
|
jsonObject.put("prompt_name",fieldSetEntity.getString("prompt_name"));
|
// 默认值
|
jsonObject.put("default_value",fieldSetEntity.getString("default_value"));
|
// 获取
|
if(!BaseUtil.strIsNull(config_charts_uuid)) {
|
DataTableEntity dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, " report_type_attr = ? AND report_config_uuid = ? ", new String[]{uuid, config_charts_uuid});
|
if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
|
if(dataTableEntity.getRows() > 1) {
|
for (int i = 0; i < dataTableEntity.getRows(); i++) {
|
FieldSetEntity fse = dataTableEntity.getFieldSetEntity(i);
|
String grouping = fse.getString("grouping");
|
if("1".equals(grouping)) {
|
jsonObject.put("config_attribute_uuid", fse.getString("uuid"));
|
//列表关.PRODUCT_SYS_report_config,图表关.PRODUCT_SYS_report_config_charts表UUID
|
jsonObject.put("report_config_uuid", fse.getString("report_config_uuid"));
|
//关联属.PRODUCT_SYS_report_type_attribute表UUID
|
jsonObject.put("report_type_attr", fse.getString("report_type_attr"));
|
//字段名称
|
jsonObject.put("field_name", fse.getString("field_name"));
|
//属性值
|
jsonObject.put("report_type_attr_value", fse.getString("report_type_attr_value"));
|
//分组标识,加载多条数据需要加标识
|
jsonObject.put("grouping",grouping);
|
}
|
}
|
}else if(dataTableEntity.getRows() == 1){
|
jsonObject.put("config_attribute_uuid", dataTableEntity.getString(0,"uuid"));
|
//列表关.PRODUCT_SYS_report_config,图表关.PRODUCT_SYS_report_config_charts表UUID
|
jsonObject.put("report_config_uuid", dataTableEntity.getString(0,"report_config_uuid"));
|
//关联属.PRODUCT_SYS_report_type_attribute表UUID
|
jsonObject.put("report_type_attr", dataTableEntity.getString(0,"report_type_attr"));
|
//字段名称
|
jsonObject.put("field_name", dataTableEntity.getString(0,"field_name"));
|
//属性值
|
jsonObject.put("report_type_attr_value", dataTableEntity.getString(0,"report_type_attr_value"));
|
}
|
}
|
}
|
}
|
array.add(jsonObject);
|
return array;
|
}
|
|
public void addLayerOf(JSONArray childrenArray){
|
if(childrenArray != null && childrenArray.size() > 0){
|
for (int i = 0; i < childrenArray.size(); i++) {
|
JSONObject o = childrenArray.getJSONObject(i);
|
JSONArray children = o.getJSONArray("children");
|
if(!BaseUtil.strIsNull(o.getString("grouping"))){
|
o.getInteger("grouping");
|
}else if(children != null && children.size() > 0){
|
this.addLayerOf(children);
|
}
|
}
|
}
|
}
|
}
|