Commit 7870d491 authored by kevin's avatar kevin

Merge branch 'dev_mysql' of http://code.tech.tax.asia.pwcinternal.com/root/atms into dev_mysql

# Conflicts:
#	atms-web/src/main/webapp/app/common/webservices/common.svc.js
parent 7fc6a1ca
......@@ -22,4 +22,5 @@ public class Exceptions {
public static final FormulaException PROJECT_NOT_FOUND = new FormulaException("project not found");;
public static final FormulaException PSUM_CELL_TEMP_NULL = new FormulaException("cell template group is null or empty");
public static final ApiException NOT_FOUND_INSTANCE_EXCEPTION = new NotFoundException("not found instance");
public static final FormulaException parameterError = new FormulaException("formula parameter is error");
}
......@@ -132,4 +132,11 @@ public class FormulaAgent {
return cellData;
}
public List<CellTemplatePerGroupDto> getCellDataByPos(Long templateId, Integer period, String cellRow, String cellCol, String projectId){
return adminMp.getCellDataByPos(templateId, period, cellRow, cellCol, projectId);
}
public List<CellTemplatePerGroupDto> getTableData(String tableName, String getField, String selectFilter, String year, String selectPeriod) {
return adminMp.getTableData(tableName, getField, selectFilter, year, selectPeriod);
}
}
......@@ -552,6 +552,8 @@ public class ReportServiceImpl extends BaseService {
private ProfitLossStatementMapper profitLossStatementMapper;
@Autowired
private JournalEntryMapper journalEntryMapper;
@Autowired
private DataUtil dataUtil;
/* @Autowired
private CitJour*/
//数据校验
......@@ -593,7 +595,7 @@ public class ReportServiceImpl extends BaseService {
Map<String, Object> map = new HashMap<>();
map.put("period", periodParam);
map.put("projectId", projectId);
Map<String, Object> mapProject = new DataUtil().getProjectById(projectId);
Map<String, Object> mapProject = dataUtil.getProjectById(projectId);
map.put("companyCode", mapProject.get("code"));
map.put("companyName", mapProject.get("name"));
List<JournalEntry> journalEntries = journalEntryMapper.selectNowAdjustData(map2);
......@@ -623,8 +625,14 @@ public class ReportServiceImpl extends BaseService {
setStatus(genJob, STATUS_END);
map.put("validateResult", "success");
map.put("result", "");
map.put("tmsPeriod", journalEntries.get(0).getTmsPeriod());
map.put("organizationId", journalEntries.get(0).getOrganizationId());
if(journalEntries.size()==0){
map.put("tmsPeriod", 0);
}else{
map.put("tmsPeriod", journalEntries.get(0).getTmsPeriod());
}
map.put("organizationId", mapProject.get("organizationId"));
insertDataValidateResult(map);
periodJobMapper.updateByPrimaryKey(genJob);
}
......
......@@ -10,9 +10,8 @@ import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceDetailType;
import pwc.taxtech.atms.constant.enums.FormulaDataSourceType;
import pwc.taxtech.atms.vat.entity.PeriodDataSource;
import pwc.taxtech.atms.vat.entity.PeriodDataSourceDetail;
import pwc.taxtech.atms.vat.entity.PeriodFormulaBlock;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.impl.FormulaAgent;
import java.lang.reflect.Field;
......@@ -139,7 +138,7 @@ public class FunctionBase {
dataSource.setPeriod(period);
dataSource.setProjectId(projectId);
SpringContextUtil.periodDataSourceMapper.insertSelective(dataSource);
if(CollectionUtils.isNotEmpty(dataSourceList)){
if (CollectionUtils.isNotEmpty(dataSourceList)) {
for (Object obj : dataSourceList) {
if (obj.getClass() == java.util.ArrayList.class) {
for (Object obj2 : (ArrayList<Object>) obj) {
......@@ -163,7 +162,7 @@ public class FunctionBase {
SpringContextUtil.periodDataSourceDetailMapper.insertSelective(dataSourceDetail);
}
}
}else{
} else {
PeriodDataSourceDetail dataSourceDetail = new PeriodDataSourceDetail();
dataSourceDetail.setId(SpringContextUtil.distributedIdService.nextId());
dataSourceDetail.setDataSourceId(dataSourceId);
......@@ -214,10 +213,10 @@ public class FunctionBase {
String evalStr = OperandResolver.coerceValueToString(eval);
LOGGER.debug("[Formula_debug] eval other cell value {}", evalStr);
try {
BigDecimal bigDecimal= new BigDecimal(evalStr);
BigDecimal bigDecimal = new BigDecimal(evalStr);
if (!dss.isEmpty()) {
return bigDecimal.add(dss.get(0).getAmount());
}else {
return bigDecimal.add(dss.get(0).getAmount());
} else {
return bigDecimal;
}
} catch (Exception e) {
......@@ -230,4 +229,35 @@ public class FunctionBase {
return new BigDecimal(0);
}
public String StringBuddler(String target, String design) {
if (target.equals("")) {
target = design;
} else {
target = target + ", " + design;
}
return target;
}
public Long getSUM2Data(Long reportTemplateId, Integer period, Map map) {
String bufferString = "";
Long refValue = null;
PeriodCellTemplateExample example = new PeriodCellTemplateExample();
PeriodCellTemplateExample.Criteria criteria = example.createCriteria();
criteria.andReportTemplateIdEqualTo(reportTemplateId);
criteria.andPeriodEqualTo(period);
criteria.andColumnIndexEqualTo(Integer.parseInt(map.get("colIndex").toString()));
criteria.andRowIndexBetween(Integer.parseInt(map.get("rowIndexBegin").toString()), Integer.parseInt(map.get("rowIndexEnd").toString()));
List<PeriodCellTemplate> periodCellTemplates = SpringContextUtil.periodCellTemplateMapper.selectByExample(example);
for (PeriodCellTemplate p : periodCellTemplates) {
StringBuddler(bufferString, p.getCellTemplateId().toString());
}
List<PeriodCellData> list = SpringContextUtil.periodCellDataMapper.selectDataByCellTemplateIdAround(bufferString);
for (PeriodCellData periodCellData : list) {
if (refValue == null) refValue = Long.parseLong(periodCellData.getData());
refValue += Long.parseLong(periodCellData.getData());
}
return refValue;
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.dpo.CellTemplatePerGroupDto;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.exception.FormulaException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverInteger;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverString;
/**
* @ClassName RSUMIF
* Description TODO 公式还需要校验
* @Author pwc kevin
* @Date 3/8/2019 5:21 PM
* Version 1.0
**/
public class RSUMIF extends FunctionBase implements FreeRefFunction {
final static ValueEval defaultEval = new StringEval("0");
static final Logger LOGGER = LoggerFactory.getLogger(BB.class);
String tableName;
String getField;//取值列字段
Map<String, String> fileterMap = new HashMap<String, String>();
String year;
int period;
String selectPeriod = "";
String selectFilter = "";
Long result;
int argsLength;
int selectCount;
public RSUMIF(FormulaContext formulaContext) {
super(formulaContext);
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
try {
return wrapExceptionEval(valueEvals, operationEvaluationContext);
} catch (Exception e) {
if (e instanceof FormulaException)
LOGGER.warn("Formula Exception || {}", e.getMessage());
e.printStackTrace();
return defaultEval;
}
}
public ValueEval wrapExceptionEval(ValueEval[] args, OperationEvaluationContext ec) throws Exception {
List<Object> ds = new ArrayList<>();
parameterCheck(args);
setWhere(args, ec);
List<CellTemplatePerGroupDto> tableData = null;
try {
tableData = agent.getTableData(tableName, getField, selectFilter, year, selectPeriod);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("公式参数配置错误");
}
for (CellTemplatePerGroupDto cellTemplatePerGroupDto : tableData) {
result = result + Long.parseLong(cellTemplatePerGroupDto.getData());
}
return new NumberEval(result);
}
//进行参数验证
public void parameterCheck(ValueEval[] args) {
argsLength = args.length;
if (argsLength < 4) {//参数小于3当做异常处理, 最后俩参数可以取默认值
throw Exceptions.parameterError;
}
}
private void setWhere(ValueEval[] args, OperationEvaluationContext ec) {
try {
selectCount = (argsLength - 4) / 2;
tableName = resolverString(args, ec, 0);
getField = resolverString(args, ec, 1);
period = resolverInteger(args, ec, argsLength - 1);//会计期间
year = resolverString(args, ec, argsLength - 2);//会计年度
if (selectCount % 2 != 0)
throw Exceptions.parameterError;
for (int i = 3; i < selectCount * 2 + 3; i++) {
if (i % 2 != 0) {
fileterMap.put(resolverString(args, ec, i), resolverString(args, ec, i + 1));
}
}
if (period == 0) {
selectPeriod = "t.period = " + formulaContext.getPeriod();
} else if (period == -99) {
selectPeriod = "t.period between '0' and " + (formulaContext.getPeriod() - 1);
} else if (period == 99) {
selectPeriod = "t.period between '0' and " + (formulaContext.getPeriod() - 1);
} else {
selectPeriod = "t.period between " + (formulaContext.getPeriod() - period) + " and " + (formulaContext.getPeriod() - 1);
}
for (Map.Entry<String, String> entry : fileterMap.entrySet()) {
if (selectFilter.equals("")) {
selectFilter = "t." + entry.getKey() + entry.getValue();
} else {
selectFilter = selectFilter + " and " + "t." + entry.getKey() + entry.getValue();
}
}
} catch (EvaluationException e) {
e.printStackTrace();
}
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.exception.Exceptions;
/**
* author kevin
*/
import java.math.BigDecimal;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverString;
public class SUM extends FunctionBase implements FreeRefFunction {
final static ValueEval defaultEval = new StringEval("0");
static final Logger LOGGER = LoggerFactory.getLogger(BB.class);
public BigDecimal cellValue;
public SUM(FormulaContext formulaContext) {
super(formulaContext);
}
//检查参数合法性
public String parameter(String parameter) {
if (parameter.length() != 2)
throw Exceptions.parameterError;
return parameter;
}
//数据获取
public BigDecimal getData(String cellPos) {
String cellCol = cellPos.substring(0, 1);
String cellRow = cellPos.substring(1, 1);
Long reportTemplateGroupId = formulaContext.getReportTemplateGroupId();
return BigDecimal.valueOf(Long.parseLong(agent.getCellDataByPos(reportTemplateGroupId, formulaContext.getPeriod(), cellRow, cellCol, formulaContext.getProjectId()).get(0).getData()));
}
//进行sum计算
public BigDecimal sum(BigDecimal bigDecimal) {
cellValue.add(bigDecimal);
return cellValue;
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
for (int i = 0, j = valueEvals.length; i < j; i++) {
try {
return new NumberEval(sum(getData(parameter(resolverString(valueEvals, operationEvaluationContext, i)))).doubleValue());
} catch (EvaluationException e) {
e.printStackTrace();
return defaultEval;
}
}
return defaultEval;
}
}
package pwc.taxtech.atms.vat.service.impl.report.functions;
import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.thirdparty.ExcelCell;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverInteger;
import static pwc.taxtech.atms.common.util.FormulaUtil.resolverString;
/**
* author kevin
* todo 需要检验公式的准确性
*/
public class SUM2 extends FunctionBase implements FreeRefFunction {
final static ValueEval defaultEval = new StringEval("0");
static final Logger LOGGER = LoggerFactory.getLogger(BB.class);
public BigDecimal cellValue;
public SUM2(FormulaContext formulaContext) {
super(formulaContext);
}
//检查参数合法性
public Map parameterCheck(ValueEval[] valueEvals, OperationEvaluationContext ec) {
Map<String, Object> map = new HashMap<String, Object>();
if(valueEvals.length != 2)
throw Exceptions.parameterError;
try {
String argsOne = resolverString(valueEvals, ec, 0);
String argsTwo = resolverString(valueEvals, ec, 1);
if(!argsOne.substring(0,1).equals(argsTwo.substring(0,1)))
throw Exceptions.parameterError;
map.put("colIndex", argsOne.substring(0,1));
map.put("rowIndexBegin", argsOne.substring(1,1));
map.put("rowIndexEnd", argsTwo.subSequence(1,1));
} catch (EvaluationException e) {
e.printStackTrace();
return null;
}
return map;
}
@Override
public ValueEval evaluate(ValueEval[] valueEvals, OperationEvaluationContext operationEvaluationContext) {
Map map = parameterCheck(valueEvals, operationEvaluationContext);
if(map != null){
return new NumberEval(getSUM2Data(formulaContext.getReportTemplateGroupId(), formulaContext.getPeriod(), map));
};
return null;
/* for (int i = 0, j = valueEvals.length; i < j; i++) {
try {
return new NumberEval(sum(getData(parameter(resolverString(valueEvals, operationEvaluationContext, i)))).doubleValue());
} catch (EvaluationException e) {
e.printStackTrace();
return defaultEval;
}
}*/
}
}
......@@ -58,7 +58,6 @@ public interface FormulaAdminMapper extends MyMapper {
List<GroupId> getTemplateGroupId(@Param("projectId") String projectId);
@Select("SELECT " +
" p.id " +
"FROM " +
......@@ -97,41 +96,41 @@ public interface FormulaAdminMapper extends MyMapper {
" source_cell.row_name AS rowName," +
" source_cell.data_type AS resultType " +
"from (" +
" select " +
" template.template_id AS reportTemplateID," +
" template.template_group_id AS reportTemplateGroupID," +
" template.code AS reportCode," +
" cell_template.row_index AS rowIndex " +
" from period_template as template " +
" inner join period_cell_template as cell_template" +
" on template.template_id = cell_template.report_template_id" +
" where template.template_group_id = #{templateGroupId}" +
" and template.is_active_association = 1" +
" and template.code = #{code}" +
" and template.project_id = #{projectId}" +
" and template.period = #{period}" +
" and cell_template.project_id = #{projectId}" +
" and cell_template.period = #{period}" +
" and cell_template.column_index = #{rowColumnIndex}" +
" and cell_template.row_name = #{rowName}) as detail," +
" select " +
" template.template_id AS reportTemplateID," +
" template.template_group_id AS reportTemplateGroupID," +
" template.code AS reportCode," +
" cell_template.row_index AS rowIndex " +
" from period_template as template " +
" inner join period_cell_template as cell_template" +
" on template.template_id = cell_template.report_template_id" +
" where template.template_group_id = #{templateGroupId}" +
" and template.is_active_association = 1" +
" and template.code = #{code}" +
" and template.project_id = #{projectId}" +
" and template.period = #{period}" +
" and cell_template.project_id = #{projectId}" +
" and cell_template.period = #{period}" +
" and cell_template.column_index = #{rowColumnIndex}" +
" and cell_template.row_name = #{rowName}) as detail," +
" period_cell_template as source_cell" +
" where source_cell.project_id = #{projectId}" +
" and source_cell.period = #{period}" +
" and detail.reportTemplateID = source_cell.report_template_id" +
" and detail.rowIndex = source_cell.row_index" +
" and source_cell.column_index = #{columnIndex}"
)
)
List<CellTemplatePerGroupDto> getCellTemplateByNameAndIndex(
@Param("templateGroupId") Long templateGroupId,
@Param("code") String code,
@Param("rowColumnIndex") Integer rowColumnIndex,
@Param("rowName") String rowName,
@Param("columnIndex") Integer columnIndex,
@Param("projectId") String projectId,
@Param("period") Integer period);
@Param("templateGroupId") Long templateGroupId,
@Param("code") String code,
@Param("rowColumnIndex") Integer rowColumnIndex,
@Param("rowName") String rowName,
@Param("columnIndex") Integer columnIndex,
@Param("projectId") String projectId,
@Param("period") Integer period);
List<CellTemplatePerGroupDto> getCellTemplateByTypeAndIndex(
List<CellTemplatePerGroupDto> getCellTemplateByTypeAndIndex(
@Param("templateGroupId") Long templateGroupId,
@Param("projectId") String projectId,
@Param("code") String code,
......@@ -144,4 +143,48 @@ public interface FormulaAdminMapper extends MyMapper {
@Param("orgId") String orgId,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
@Select("" +
"SELECT " +
" cell_template.cell_template_id AS cellTemplateID, " +
" template.template_id AS reportTemplateID, " +
" template.template_group_id AS reportTemplateGroupID, " +
" cell_template.row_index AS rowIndex, " +
" cell_template.column_index AS columnIndex, " +
" template.code AS reportCode, " +
" cell_template.column_name AS columnName, " +
" cell_template.row_name AS rowName, " +
" cell_template.data_type AS resultType " +
"d.data AS content" +
"FROM " +
" period_template template " +
" LEFT JOIN period_cell_template cell_template ON template.template_id = cell_template.report_template_id " +
" LEFT JOIN period_cell_data d on d.cell_template_id = cell_template.cell_template_id" +
"WHERE " +
" template.template_id IN ( SELECT template_id FROM period_template WHERE template_group_id = #{templateGroupId} " +
" AND is_active_association = 1 AND code = #{code} ) " +
" AND row_index = #{cellRow} " +
" AND column_index = #{cellCol} " +
" AND template.project_id = #{projectId} " +
" AND template.period = #{period} " +
" AND cell_template.project_id = #{projectId} " +
" AND cell_template.period = #{period}" +
"")
List<CellTemplatePerGroupDto> getCellDataByPos(@Param("templateId") Long templateId, @Param("period") Integer period, @Param("cellRow") String cellRow, @Param("cellCol") String cellCol, @Param("projectId") String projectId);
@Select("" +
"SELECT " +
"${getField} as data" +
"FROM ${tableName} " +
"inner join project pro on pro.organization_id = t.organization_id " +
" and ${selectFilter}" +
" and pro.year = #{year}" +
"")
List<CellTemplatePerGroupDto> getTableData(@Param("tableName") String tableName,
@Param("getField") String getField,
@Param("selectFilter") String selectFilter,
@Param("year") String year,
@Param("selectPeriod") String selectPeriod);
}
......@@ -15,6 +15,24 @@ public class CellTemplatePerGroupDto {
private String rowName;
private String columnName;
private Integer resultType;
private Long Content;
String Data;
public String getData() {
return Data;
}
public void setData(String data) {
Data = data;
}
public Long getContent() {
return Content;
}
public void setContent(Long content) {
Content = content;
}
public String getCellTemplateId() {
return cellTemplateId;
......
......@@ -107,4 +107,6 @@ public interface PeriodCellDataMapper extends MyVatMapper {
int updateByPrimaryKey(PeriodCellData record);
int batchInsert(List<PeriodCellData> list);
List<PeriodCellData> selectDataByCellTemplateIdAround(@Param("bufferString") String bufferString);
}
\ No newline at end of file
......@@ -92,4 +92,11 @@
</foreach>;
SELECT 1 FROM DUAL;
</insert>
<select id = "selectDataByCellTemplateIdAround" parameterType="java.lang.String" resultType="pwc.taxtech.atms.vat.entity.PeriodCellData">
select * from period_cell_data t where 1=1
<if test="bufferString != null and bufferString != '' ">
and t.cell_template_id in #{bufferString}
</if>
</select>
</mapper>
\ No newline at end of file
......@@ -387,10 +387,8 @@
$scope.templateFormulaList = getResult.data.filter(function (item) {
return !item.isReadOnly;
});
refreshSpreadUI();
});
};
// 刷新选中的过滤凭证科目代码
......@@ -1522,8 +1520,6 @@ ng-show="hasEditPermission && ToggleSaveAs && editModel.hasModel"/>');
$scope.activeSheet.setActiveCell(row.rowIndex, row.columnIndex);
releaseParameter();
}
//spreadJsTipService.setCellTipString(cell, "测试数据源");
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment