|
@@ -14,10 +14,19 @@ import java.util.Map;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFTable;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
|
|
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
|
|
|
+
|
|
|
+import com.deepoove.poi.NiceXWPFDocument;
|
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
|
import com.deepoove.poi.data.MiniTableRenderData;
|
|
|
import com.deepoove.poi.data.RowRenderData;
|
|
|
import com.deepoove.poi.data.TextRenderData;
|
|
|
+import com.deepoove.poi.data.style.TableStyle;
|
|
|
+import com.deepoove.poi.policy.DynamicTableRenderPolicy;
|
|
|
+import com.deepoove.poi.policy.MiniTableRenderPolicy;
|
|
|
import com.minpay.common.bean.User;
|
|
|
import com.minpay.common.format.IFormatService;
|
|
|
import com.minpay.common.service.IDownloadService;
|
|
@@ -79,7 +88,7 @@ public class TemplateExportAction implements IMINAction {
|
|
|
map1.put("acicId", acicId);
|
|
|
User u = session.getUser();
|
|
|
//获取部门
|
|
|
- String brandId = u.getBranchId();
|
|
|
+ String branchId = u.getBranchId();
|
|
|
//
|
|
|
List<Map<String, Object>> list = Service.lookup(IMINDataBaseService.class)
|
|
|
.getMybatisMapper(LongContractMapper.class)
|
|
@@ -219,7 +228,7 @@ public class TemplateExportAction implements IMINAction {
|
|
|
.selectByExample(example);
|
|
|
List<Map<String, String>> newlist = new ArrayList<>();
|
|
|
|
|
|
- if(!CommonUtil.isYHL(brandId)){//铝产品部
|
|
|
+ if(!CommonUtil.isYHL(branchId)){//铝产品部
|
|
|
//查询合同
|
|
|
ApContractInfExample ex = new ApContractInfExample();
|
|
|
ex.createCriteria().andIdEqualTo(acicId);
|
|
@@ -320,12 +329,12 @@ public class TemplateExportAction implements IMINAction {
|
|
|
List<RowRenderData> datas = new ArrayList<RowRenderData>();
|
|
|
|
|
|
|
|
|
- if (!CommonUtil.isYHL(brandId)) {
|
|
|
+ if (!CommonUtil.isYHL(branchId)) {
|
|
|
allweight = "0";
|
|
|
allamt = "0";
|
|
|
}
|
|
|
for(int i = 0;i < newlist.size();i++) {
|
|
|
- if(!CommonUtil.isYHL(brandId)){
|
|
|
+ if(!CommonUtil.isYHL(branchId)){
|
|
|
allweight = CommonUtil.add(allweight, CommonUtil.objToString(newlist.get(i).get("reaWeight")),4);
|
|
|
allamt = CommonUtil.add(allamt, CommonUtil.multiply(CommonUtil.objToString(newlist.get(i).get("reaWeight")),CommonUtil.objToString(newlist.get(i).get("sjPrice"))),2);
|
|
|
RowRenderData rowDto = RowRenderData.build(CommonUtil.objToString(newlist.get(i).get("abfName")), CommonUtil.objToString(newlist.get(i).get("value")), CommonUtil.objToString(newlist.get(i).get("warehouseName")), CommonUtil.objToString(newlist.get(i).get("reaWeight")),CommonUtil.objToString(newlist.get(i).get("sjPrice")), CommonUtil.multiply(CommonUtil.objToString(newlist.get(i).get("reaWeight")),CommonUtil.objToString(newlist.get(i).get("sjPrice")),2));
|
|
@@ -374,7 +383,7 @@ public class TemplateExportAction implements IMINAction {
|
|
|
String price = "";
|
|
|
if(newlist.size() > 0 && newlist != null){
|
|
|
proName = CommonUtil.objToString(newlist.get(0).get("apiName"));
|
|
|
- if(!CommonUtil.isYHL(brandId)){
|
|
|
+ if(!CommonUtil.isYHL(branchId)){
|
|
|
price = CommonUtil.objToString(newlist.get(0).get("sjPrice"));
|
|
|
weight = CommonUtil.objToString(newlist.get(0).get("reaWeight"));
|
|
|
}else{
|
|
@@ -422,7 +431,14 @@ public class TemplateExportAction implements IMINAction {
|
|
|
put("allamt", amtAll);//总金额
|
|
|
put("allAmtTaxExclusive", CommonUtil.divide(amtAll, "1.13", 2));//不含税总金额
|
|
|
put("chineseNb", chineseNb);//中文大写
|
|
|
- put("table", new MiniTableRenderData(header, datas));// 产品表格信息
|
|
|
+
|
|
|
+ // 增加合计行
|
|
|
+ if(!CommonUtil.isYHL(branchId)){
|
|
|
+ RowRenderData lastRenderData = RowRenderData.build("合计", "", "", weightAll, CommonUtil.divide(amtAll, weightAll, 2), amtAll);
|
|
|
+ datas.add(lastRenderData);
|
|
|
+ }
|
|
|
+ MiniTableRenderData table = new MiniTableRenderData(header, datas);
|
|
|
+ put("table", table);// 产品表格信息
|
|
|
Date date = new Date();
|
|
|
SimpleDateFormat sb = new SimpleDateFormat("yyyy年/MM月/dd日");
|
|
|
put("payDate", sb.format(date));//支付日期
|
|
@@ -451,6 +467,13 @@ public class TemplateExportAction implements IMINAction {
|
|
|
|
|
|
}});
|
|
|
|
|
|
+ // 合并合计单元格
|
|
|
+ if(!CommonUtil.isYHL(branchId)) {
|
|
|
+ NiceXWPFDocument xwpfDocument = template.getXWPFDocument();
|
|
|
+ XWPFTable table = xwpfDocument.getTableArray(0);
|
|
|
+ mergeCellsHorizontal(table, table.getRows().size() - 1, 0, 2);
|
|
|
+ }
|
|
|
+
|
|
|
response.setContentType("multipart/form-data");
|
|
|
String formFileName = new String(name.getBytes("UTF-8"), "ISO-8859-1");
|
|
|
if (CommonUtil.isEmpty(formFileName)) {
|
|
@@ -515,4 +538,17 @@ public class TemplateExportAction implements IMINAction {
|
|
|
res.set(IMINBusinessConstant.F_PAGING_LAY, list);
|
|
|
return res;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ private void mergeCellsHorizontal(XWPFTable table, Integer row, Integer fromCell, Integer toCell) {
|
|
|
+ for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {
|
|
|
+ XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
|
|
|
+ if ( cellIndex == fromCell ) {
|
|
|
+ // The first merged cell is set with RESTART merge value
|
|
|
+ cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
|
|
|
+ } else {
|
|
|
+ // Cells which join (merge) the first one, are set with CONTINUE
|
|
|
+ cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|