文件备份---何朝阳
parent
e23fc2161e
commit
0284f4c70b
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2018 泛微软件.
|
||||
* 泛微协同商务系统,版权所有.
|
||||
*
|
||||
*/
|
||||
package com.api.chaoyang.he.browser.service.impl;
|
||||
|
||||
import com.api.browser.bean.ListHeadBean;
|
||||
import com.api.browser.bean.SearchConditionItem;
|
||||
import com.api.browser.bean.SplitTableBean;
|
||||
import com.api.browser.bean.SplitTableColBean;
|
||||
import com.api.browser.service.BrowserService;
|
||||
import com.api.browser.util.*;
|
||||
import com.cloudstore.dev.api.bean.SplitMobileDataBean;
|
||||
import com.cloudstore.dev.api.bean.SplitMobileTemplateBean;
|
||||
import com.cloudstore.dev.api.util.Util_MobileData;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.fna.e9.controller.base.FnaInvoiceLedgerController;
|
||||
import weaver.fna.invoice.Constants;
|
||||
import weaver.general.Util;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangwj
|
||||
* @Description:多发票浏览按钮
|
||||
* @version 1.0
|
||||
*/
|
||||
public class MultiInvoiceBrowserService extends BrowserService {
|
||||
|
||||
//移动端返回数据格式的json配置
|
||||
public static final String JSON_CONFIG="[" +
|
||||
" {" +
|
||||
" \"key\": \"col1\"," +
|
||||
" \"configs\": [" +
|
||||
" {" +
|
||||
" \"key\": \"col1_row1\"," +
|
||||
" \"configs\": [" +
|
||||
" {" +
|
||||
" \"key\": \"invoiceNumber\"" +
|
||||
" }," +
|
||||
" {" +
|
||||
" \"key\": \"invoiceCode\"," +
|
||||
" \"style\": {" +
|
||||
" \"float\": \"right\"" +
|
||||
" }" +
|
||||
" }" +
|
||||
" ]" +
|
||||
" }," +
|
||||
" {" +
|
||||
" \"key\": \"col1_row2\"," +
|
||||
" \"configs\": [" +
|
||||
" {" +
|
||||
" \"key\": \"taxIncludedPrice\"" +
|
||||
" }," +
|
||||
" {" +
|
||||
" \"key\": \"invoiceTypeName\"," +
|
||||
" \"style\": {" +
|
||||
" \"float\": \"right\"" +
|
||||
" }" +
|
||||
" }" +
|
||||
" ]" +
|
||||
" }" +
|
||||
" {" +
|
||||
" \"key\": \"col1_row3\"," +
|
||||
" \"configs\": [" +
|
||||
" {" +
|
||||
" \"key\": \"billingdate\"" +
|
||||
" }," +
|
||||
" ]" +
|
||||
" }" +
|
||||
" ]" +
|
||||
" }" +
|
||||
"]";
|
||||
|
||||
/**
|
||||
* 多发票浏览
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getBrowserData(Map<String, Object> params) throws Exception {
|
||||
Map<String, Object> apidatas = new HashMap<String, Object>();
|
||||
if(user == null){
|
||||
apidatas.put(BrowserConstant.BROWSER_RESULT_DATA, null);
|
||||
return apidatas;
|
||||
}
|
||||
String advQry_kprq1 = Util.null2String(params.get("createdatestart")).trim();
|
||||
String advQry_kprq2 = Util.null2String(params.get("createdateend")).trim();
|
||||
String invoiceNumber = Util.null2String(params.get("invoiceNumber"));
|
||||
String seller = Util.null2String(params.get("seller"));
|
||||
|
||||
//发票代码,发票类型,开票日期,金额
|
||||
FnaInvoiceLedgerController fnaInvoiceLedgerController = FnaInvoiceLedgerController.getInstance();
|
||||
String sqlAppend = fnaInvoiceLedgerController.getCaseWhenSql4InvoiceTypeList("invoiceTypeName", "a.invoiceType", user.getLanguage())+" ";
|
||||
//设置好搜索条件
|
||||
String backFields =" a.*, "+
|
||||
fnaInvoiceLedgerController.getCaseWhenSql4InvoiceTypeList("invoiceTypeName", "a.invoiceType", user.getLanguage())+" ";
|
||||
String fromSql = " from FnaInvoiceLedger a ";
|
||||
//验票为真的发票才能选择的到
|
||||
StringBuffer sqlWhere = new StringBuffer(" where 1=1 and (checkStatus = 1 or checkStatus = 2) ");
|
||||
if(!"".equals(advQry_kprq2)){
|
||||
sqlWhere.append(" and a.billingDate <= '").append(StringEscapeUtils.escapeSql(advQry_kprq2)).append("' ");
|
||||
}
|
||||
if(!"".equals(advQry_kprq1)){
|
||||
sqlWhere.append(" and a.billingDate >= '").append(StringEscapeUtils.escapeSql(advQry_kprq1)).append("' ");
|
||||
}
|
||||
if(!"".equals(invoiceNumber)){
|
||||
sqlWhere.append(" and a.invoiceNumber like '%").append(StringEscapeUtils.escapeSql(invoiceNumber.trim())).append("%'");
|
||||
}
|
||||
if(!"".equals(seller)){
|
||||
sqlWhere.append(" and a.seller like '%").append(StringEscapeUtils.escapeSql(seller.trim())).append("%'");
|
||||
}
|
||||
sqlWhere.append(" and (a.userid_new = ").append(user.getUID()).append(" or a.id in ( select invoiceId from fnaInvoiceSharer where sharer = ").append(user.getUID()).append(") ").append(") ");
|
||||
sqlWhere.append(" and a.status = '0' ");
|
||||
//AP航信过滤浏览按钮中的数据-hcy
|
||||
// sqlWhere.append(" and hxjksflr is null ");
|
||||
String orderBy=" a.id desc ";
|
||||
|
||||
//writeLog("select "+backFields+" "+fromSql+" "+sqlWhere);
|
||||
List<SplitTableColBean> cols = new ArrayList<SplitTableColBean>();
|
||||
cols.add(new SplitTableColBean("true","id"));
|
||||
cols.add(new SplitTableColBean("30%",SystemEnv.getHtmlLabelName(900,user.getLanguage()),"invoiceNumber","invoiceNumber",1).setIsInputCol(BoolAttr.TRUE));
|
||||
cols.add(new SplitTableColBean("30%",SystemEnv.getHtmlLabelName(17213,user.getLanguage()),"invoiceCode","invoiceCode"));
|
||||
cols.add(new SplitTableColBean("30%",SystemEnv.getHtmlLabelName(17213,user.getLanguage()),"invoiceTypeName","invoiceTypeName"));
|
||||
cols.add(new SplitTableColBean("30%",SystemEnv.getHtmlLabelName(17213,user.getLanguage()),"billingdate","billingdate"));
|
||||
cols.add(new SplitTableColBean("30%",SystemEnv.getHtmlLabelName(17213,user.getLanguage()),"taxIncludedPrice","taxIncludedPrice"));
|
||||
SplitTableBean tableBean = new SplitTableBean(backFields,fromSql,sqlWhere.toString(),orderBy,"a.id","DESC",cols);
|
||||
|
||||
|
||||
//移动端返回数据
|
||||
List<SplitMobileDataBean> mobileDataBeanList=Util_MobileData.createList(JSON_CONFIG);
|
||||
SplitMobileTemplateBean bean=Util_MobileData.createJsonTemplateBean("theme_default", mobileDataBeanList);
|
||||
tableBean.createMobileTemplate(bean);
|
||||
|
||||
apidatas.putAll(SplitTableUtil.makeListDataResult(tableBean));
|
||||
return apidatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* 高级搜索
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getBrowserConditionInfo(Map<String, Object> params) throws Exception {
|
||||
Map<String, Object> apidatas = new HashMap<String, Object>();
|
||||
List<SearchConditionItem> conditions = new ArrayList<SearchConditionItem>();
|
||||
ConditionFactory conditionFactory = new ConditionFactory(user);
|
||||
conditions.add(conditionFactory.createCondition(ConditionType.INPUT, 900, "invoiceNumber").setIsQuickSearch(true));
|
||||
apidatas.put(BrowserConstant.BROWSER_RESULT_CONDITIONS, conditions);
|
||||
return apidatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多发票(多选界面右侧选中部分)
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getMultBrowserDestData(Map<String, Object> params) throws Exception {
|
||||
Map<String, Object> apidatas = new HashMap<String, Object>();
|
||||
|
||||
String selectids = Util.null2String(params.get(BrowserConstant.BROWSER_MULT_DEST_SELECTIDS));
|
||||
|
||||
List<Map<String,Object>> datas = new ArrayList<Map<String,Object>>();
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(" select a.* from FnaInvoiceLedger a ");
|
||||
buffer.append(" where a.id in (").append(selectids).append(")");
|
||||
buffer.append(" order by a.id desc ");
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.execute(buffer.toString());
|
||||
while(rs.next()){
|
||||
Map<String,Object> item = new HashMap<String,Object>();
|
||||
item.put("id",Util.null2String(rs.getString("id")));
|
||||
item.put("invoiceNumber",Util.null2String(rs.getString("invoiceNumber")));
|
||||
item.put("invoiceCode",Util.null2String(rs.getString("invoiceCode")));
|
||||
item.put("invoiceTypeName", Constants.INVOICETYPE.get(Util.null2String(rs.getString("invoicetype"))));
|
||||
item.put("billingdate", Util.null2String(rs.getString("billingdate")));
|
||||
item.put("taxIncludedPrice", Util.null2String(rs.getString("taxIncludedPrice")));
|
||||
datas.add(item);
|
||||
}
|
||||
List<ListHeadBean> tableHeadColumns = new ArrayList<ListHeadBean>();
|
||||
tableHeadColumns.add(new ListHeadBean("id",BoolAttr.TRUE).setIsPrimarykey(BoolAttr.TRUE));
|
||||
tableHeadColumns.add(new ListHeadBean("invoiceNumber","",1,BoolAttr.TRUE));
|
||||
tableHeadColumns.add(new ListHeadBean("invoiceCode",""));
|
||||
tableHeadColumns.add(new ListHeadBean("invoiceTypeName",""));
|
||||
tableHeadColumns.add(new ListHeadBean("billingdate",""));
|
||||
tableHeadColumns.add(new ListHeadBean("taxIncludedPrice",""));
|
||||
|
||||
apidatas.put(BrowserConstant.BROWSER_RESULT_COLUMN, tableHeadColumns);
|
||||
apidatas.put(BrowserConstant.BROWSER_RESULT_DATA, BrowserBaseUtil.sortDatas(datas,selectids,"id"));
|
||||
apidatas.put(BrowserConstant.BROWSER_RESULT_TYPE, BrowserDataType.LIST_ALL_DATA.getTypeid());
|
||||
|
||||
return apidatas;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.controller;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.service.ChangeFpytService;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.service.impl.ChangeFpytServiceImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/hcy_aphangxin")
|
||||
public class ChangeFpytController {
|
||||
|
||||
/**
|
||||
* 用于处理修改发票用途的主要逻辑
|
||||
*/
|
||||
private ChangeFpytService changeFpytService = new ChangeFpytServiceImpl();
|
||||
|
||||
/**
|
||||
* 日志处理
|
||||
*/
|
||||
private Logger logger = Util.getLogger();
|
||||
/**
|
||||
* <h2>AP发票库-航信台账中修改发票用途</h2>
|
||||
* @param request,response
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/3/13 14:28
|
||||
*/
|
||||
@POST
|
||||
@Path("/change/fpyt")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String checkRequestInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
String s = changeFpytService.changeFpytValue(split);
|
||||
return ApiResult.success(s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.controller;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.DeleteInvoiceNotApService;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.impl.DeleteInvoiceNotApServiceimpl;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Path("/hcy_aphangxin/delete")
|
||||
public class DeleteInvoiceNotApController {
|
||||
|
||||
/**
|
||||
* 日志处理
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* service层、用于处理主要逻辑
|
||||
*/
|
||||
private final DeleteInvoiceNotApService deleteInvoiceNotApService = new DeleteInvoiceNotApServiceimpl();
|
||||
|
||||
/**
|
||||
* <h2>根据数据id删除非AP发票</h2>
|
||||
* @param request
|
||||
* @param response
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 15:21
|
||||
*/
|
||||
@POST
|
||||
@Path("/invoice/not/ap")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String deleteInvoiceNotAp(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
//前端查询到的数据id
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
//备份数据之前,首先查询要备份和要删除的数据的发票用途字段是否为非AP,若为非AP字段则删除,若不是非AP字段则不删除,并返回前端提醒用户选择ap字段进行删除
|
||||
List<String> fpytList = deleteInvoiceNotApService.selectFpyt(split);
|
||||
List<String> fpytCollection = fpytList.stream().filter(items -> items.equals("1")).collect(Collectors.toList());
|
||||
if (fpytList.size() != fpytCollection.size()){
|
||||
logger.info("删除数据发票用途字段不为非AP,请重新选择");
|
||||
return ApiResult.success(1,"删除数据发票用途字段不为非AP,请重新选择");
|
||||
}
|
||||
//删除非AP数据之前首先备份数据
|
||||
boolean backupBoolean = deleteInvoiceNotApService.backUpAfterDelete(split);
|
||||
if (backupBoolean==true){
|
||||
logger.info("数据备份成功");
|
||||
}else{
|
||||
logger.info("数据备份失败");
|
||||
}
|
||||
//开始删除数据
|
||||
boolean deleteBoolean = deleteInvoiceNotApService.deleteDateById(split);
|
||||
if (deleteBoolean){
|
||||
logger.info("数据删除成功");
|
||||
return ApiResult.success(0,"数据删除成功!");
|
||||
}else {
|
||||
logger.info("数据删除失败");
|
||||
return ApiResult.success(1,"数据删除失败!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BackupFnaDataEntity {
|
||||
|
||||
int requestId;
|
||||
|
||||
int formmodeid;
|
||||
|
||||
int modedatacreater;
|
||||
|
||||
int modedatacreatertype;
|
||||
|
||||
String modedatacreatedate;
|
||||
|
||||
String modedatacreatetime;
|
||||
|
||||
String MODEUUID;
|
||||
|
||||
String form_biz_id;
|
||||
|
||||
double taxRate;
|
||||
|
||||
String billingdate;
|
||||
|
||||
String invoicenumber;
|
||||
|
||||
String invoicecode;
|
||||
|
||||
String invoicetype;
|
||||
|
||||
double taxincludedprice;
|
||||
|
||||
double pricewithouttax;
|
||||
|
||||
double tax;
|
||||
|
||||
String purchaser;
|
||||
|
||||
String purchasertaxno;
|
||||
|
||||
String seller;
|
||||
|
||||
String salestaxno;
|
||||
|
||||
String purp;
|
||||
|
||||
String hxjksflr;
|
||||
|
||||
int checkStatus;
|
||||
|
||||
int status;
|
||||
|
||||
int authenticity;
|
||||
|
||||
int fpyt;
|
||||
|
||||
int check_status;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.*;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface DeleteInvoiceNotApMapper {
|
||||
|
||||
|
||||
|
||||
@Select("select * from fnainvoiceledger where id in ($t{split})")
|
||||
List<Map<String, Object>> selectDate(@ParamMapper("split") String[] split);
|
||||
|
||||
@Insert("insert into uf_apfpscsj (billingDate,invoiceCode,invoiceNumber," +
|
||||
"invoiceType,seller,purchaser,invoiceServiceYype,priceWithoutTax,taxRate," +
|
||||
"tax,taxIncludedPrice,authenticity,reimbursementDate,reimbursePerson,requestId,userid_new," +
|
||||
"invoiceSource_new,checkcode,status,card_id_new,encrypt_code_new,openid_new,wechatstatus,imageID,purchaserTaxNo," +
|
||||
"salesTaxNo,entryTime,company_seal,form_type,form_name,kind,ciphertext,category,imageDocId,checkStatus," +
|
||||
"updateOperate,cloudId,codeConfirm,numberConfirm,receiptor,reviewer,issuer,province,city,travel_tax,fylx," +
|
||||
"purp,iele,orf,hxjksflr,fpyt) " +
|
||||
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
boolean backupDate(@ParamMapper("backupDataLists") List<Object> backupDataLists);
|
||||
|
||||
@Delete("delete from fnainvoiceledger where id = #{id}")
|
||||
boolean deleteDateById(@ParamMapper("id") String id);
|
||||
|
||||
/**
|
||||
* <h2>查询发票用途字段是否为非航行</h2>
|
||||
* @param id 数据id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/3/20 13:56
|
||||
*/
|
||||
@Select("select fpyt from fnainvoiceledger where id = #{id}")
|
||||
String selectFpyt(String id);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeleteInvoiceNotApService {
|
||||
boolean backUpAfterDelete(String[] split);
|
||||
boolean deleteDateById(String[] split);
|
||||
|
||||
List<String> selectFpyt(String[] split);
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.mapper.DeleteInvoiceNotApMapper;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.DeleteInvoiceNotApService;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteInvoiceNotApServiceimpl implements DeleteInvoiceNotApService {
|
||||
|
||||
/**
|
||||
* 用于sql处理
|
||||
*/
|
||||
private final DeleteInvoiceNotApMapper deleteInvoiceNotApMapper = Util.getMapper(DeleteInvoiceNotApMapper.class);
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>用于查询数据,查询到的数据进行数据备份</h2>
|
||||
* @param split requestid
|
||||
* @return boolean 数据备份是否成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 17:48
|
||||
*/
|
||||
public boolean backUpAfterDelete(String[] split) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
for (String id : split) {
|
||||
String backupDataSql = "INSERT INTO fnabackup (billingdate,\t\n" +
|
||||
"invoicenumber,\t\n" +
|
||||
"invoicecode,\n" +
|
||||
"invoicetype,\t\n" +
|
||||
"taxincludedprice,pricewithouttax,\t\n" +
|
||||
"tax,\n" +
|
||||
"purchaser,purchasertaxno,\t\n" +
|
||||
"seller,salestaxno,purp,hxjksflr,checkStatus,status,authenticity,fpyt,taxrate\n" +
|
||||
") SELECT \n" +
|
||||
"billingdate,\t\n" +
|
||||
"invoicenumber,\t\n" +
|
||||
"invoicecode,\n" +
|
||||
"invoicetype,\t\n" +
|
||||
"taxincludedprice,pricewithouttax,\t\n" +
|
||||
"tax,\n" +
|
||||
"purchaser,purchasertaxno,\t\n" +
|
||||
"seller,salestaxno,purp,hxjksflr,checkStatus,status,authenticity,fpyt,taxrate\n" +
|
||||
" FROM fnainvoiceledger WHERE id = ?";
|
||||
boolean backupBool = recordSet.executeUpdate(backupDataSql, id);
|
||||
if (!backupBool){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//开始备份数据
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据数据id、删除数据</h2>
|
||||
* @param split id
|
||||
* @return boolean 数据删除是否成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 18:00
|
||||
*/
|
||||
public boolean deleteDateById(String[] split) {
|
||||
List<Boolean> booleanList = new ArrayList<>();
|
||||
|
||||
for (String s : split) {
|
||||
boolean deleteBoolean = deleteInvoiceNotApMapper.deleteDateById(s);
|
||||
booleanList.add(deleteBoolean);
|
||||
}
|
||||
List<Boolean> collect = booleanList.stream().distinct().collect(Collectors.toList());
|
||||
if (collect != null && collect.size()==1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectFpyt(String[] split) {
|
||||
List<String> fpytLists = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
String fpyt = deleteInvoiceNotApMapper.selectFpyt(s);
|
||||
fpytLists.add(fpyt);
|
||||
}
|
||||
return fpytLists;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.mapper.DeleteInvoiceNotApMapper;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.DeleteInvoiceNotApService;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteInvoiceNotApServiceimpl_copy implements DeleteInvoiceNotApService {
|
||||
|
||||
/**
|
||||
* 用于sql处理
|
||||
*/
|
||||
private final DeleteInvoiceNotApMapper deleteInvoiceNotApMapper = Util.getMapper(DeleteInvoiceNotApMapper.class);
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>用于查询数据,查询到的数据进行数据备份</h2>
|
||||
* @param split requestid
|
||||
* @return boolean 数据备份是否成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 17:48
|
||||
*/
|
||||
public boolean backUpAfterDelete(String[] split) {
|
||||
//导入数据之前先查询数据
|
||||
List<Map<String,Object>> backupDate = deleteInvoiceNotApMapper.selectDate(split);//拿到需要备份的数据
|
||||
//开始备份数据
|
||||
List<Boolean> bool = new ArrayList<>();//存放sql语句insert动作是否成功
|
||||
for (Map<String, Object> map : backupDate) {
|
||||
List<Object> backupDataLists = new ArrayList<>();
|
||||
backupDataLists.add(map.get("billingDate"));
|
||||
backupDataLists.add(map.get("invoiceCode"));
|
||||
backupDataLists.add(map.get("invoiceNumber"));
|
||||
backupDataLists.add(map.get("invoiceType"));
|
||||
backupDataLists.add(map.get("seller"));
|
||||
backupDataLists.add(map.get("purchaser"));
|
||||
backupDataLists.add(map.get("invoiceServiceYype"));
|
||||
backupDataLists.add(map.get("priceWithoutTax"));
|
||||
backupDataLists.add(map.get("taxRate"));
|
||||
backupDataLists.add(map.get("tax"));
|
||||
backupDataLists.add(map.get("taxIncludedPrice"));
|
||||
backupDataLists.add(map.get("authenticity"));
|
||||
backupDataLists.add(map.get("reimbursementDate"));
|
||||
backupDataLists.add(map.get("reimbursePerson"));
|
||||
backupDataLists.add(map.get("requestId"));
|
||||
backupDataLists.add(map.get("useridNew"));
|
||||
backupDataLists.add(map.get("invoiceSourceNew"));
|
||||
backupDataLists.add(map.get("checkcode"));
|
||||
backupDataLists.add(map.get("status"));
|
||||
backupDataLists.add(map.get("cardIdNew"));
|
||||
backupDataLists.add(map.get("encryptCodeNew"));
|
||||
backupDataLists.add(map.get("openidNew"));
|
||||
backupDataLists.add(map.get("wechatstatus"));
|
||||
backupDataLists.add(map.get("imageID"));
|
||||
backupDataLists.add(map.get("purchaserTaxNo"));
|
||||
backupDataLists.add(map.get("salesTaxNo"));
|
||||
backupDataLists.add(map.get("entryTime"));
|
||||
backupDataLists.add(map.get("companySeal"));
|
||||
backupDataLists.add(map.get("formType"));
|
||||
backupDataLists.add(map.get("formName"));
|
||||
backupDataLists.add(map.get("kind"));
|
||||
backupDataLists.add(map.get("ciphertext"));
|
||||
backupDataLists.add(map.get("category"));
|
||||
backupDataLists.add(map.get("imageDocId"));
|
||||
backupDataLists.add(map.get("checkStatus"));
|
||||
backupDataLists.add(map.get("updateOperate"));
|
||||
backupDataLists.add(map.get("cloudId"));
|
||||
backupDataLists.add(map.get("codeConfirm"));
|
||||
backupDataLists.add(map.get("numberConfirm"));
|
||||
backupDataLists.add(map.get("receiptor"));
|
||||
backupDataLists.add(map.get("reviewer"));
|
||||
backupDataLists.add(map.get("issuer"));
|
||||
backupDataLists.add(map.get("province"));
|
||||
backupDataLists.add(map.get("city"));
|
||||
backupDataLists.add(map.get("travelTax"));
|
||||
// backupDataLists.add(map.get("fylx"));
|
||||
backupDataLists.add(map.get("purp"));
|
||||
// backupDataLists.add(map.get("iele"));
|
||||
backupDataLists.add(map.get("orf"));
|
||||
backupDataLists.add(map.get("hxjksflr"));
|
||||
backupDataLists.add(map.get("fpyt"));
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String backupdate = "insert into fnabackup (billingDate,invoiceCode,invoiceNumber," +
|
||||
"invoiceType,seller,purchaser,invoiceServiceYype,priceWithoutTax,taxRate," +
|
||||
"tax,taxIncludedPrice,authenticity,reimbursementDate,reimbursePerson,requestId,userid_new," +
|
||||
"invoiceSource_new,checkcode,status,card_id_new,encrypt_code_new,openid_new,wechatstatus,imageID,purchaserTaxNo," +
|
||||
"salesTaxNo,entryTime,company_seal,form_type,form_name,kind,ciphertext,category,imageDocId,checkStatus," +
|
||||
"updateOperate,cloudId,codeConfirm,numberConfirm,receiptor,reviewer,issuer,province,city,travel_tax," +
|
||||
"purp,orf,hxjksflr,fpyt) " +
|
||||
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
boolean insertIntoBoolean = recordSet.executeUpdate(backupdate, backupDataLists);
|
||||
// boolean insertIntoBoolean = deleteInvoiceNotApMapper.backupDate(backupDataLists);
|
||||
bool.add(insertIntoBoolean);
|
||||
logger.info("插入语句是否成功==="+insertIntoBoolean);
|
||||
}
|
||||
List<Boolean> collect = bool.stream().distinct().collect(Collectors.toList());
|
||||
if (collect!=null && collect.size()==1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据数据id、删除数据</h2>
|
||||
* @param split id
|
||||
* @return boolean 数据删除是否成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 18:00
|
||||
*/
|
||||
public boolean deleteDateById(String[] split) {
|
||||
List<Boolean> booleanList = new ArrayList<>();
|
||||
|
||||
for (String s : split) {
|
||||
boolean deleteBoolean = deleteInvoiceNotApMapper.deleteDateById(s);
|
||||
booleanList.add(deleteBoolean);
|
||||
}
|
||||
List<Boolean> collect = booleanList.stream().distinct().collect(Collectors.toList());
|
||||
if (collect != null && collect.size()==1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectFpyt(String[] split) {
|
||||
List<String> fpytLists = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
String fpyt = deleteInvoiceNotApMapper.selectFpyt(s);
|
||||
fpytLists.add(fpyt);
|
||||
}
|
||||
return fpytLists;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
import aiyh.utils.annotation.recordset.Update;
|
||||
|
||||
/**
|
||||
* <h1>根据数据id,修改发票用途字段值</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/3/13 14:41
|
||||
*/
|
||||
@SqlMapper
|
||||
public interface ChangeFpytMapper {
|
||||
|
||||
@Update("update fnainvoiceledger set fpyt = 1 where id = #{id}")
|
||||
boolean updateFpytValue(@ParamMapper("id") String id);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.service;
|
||||
|
||||
public interface ChangeFpytService {
|
||||
/**
|
||||
* <h2>修改发票用途主要逻辑</h2>
|
||||
* @param split
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/3/13 14:38
|
||||
*/
|
||||
public String changeFpytValue(String[] split);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.api.chaoyang.he.hcy_aphangxin.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.mapper.ChangeFpytMapper;
|
||||
import com.api.chaoyang.he.hcy_aphangxin.service.ChangeFpytService;
|
||||
|
||||
|
||||
public class ChangeFpytServiceImpl implements ChangeFpytService {
|
||||
|
||||
/**
|
||||
* 用于直接操作数据库的Mapper类
|
||||
*/
|
||||
private final ChangeFpytMapper changeFpytMapper = Util.getMapper(ChangeFpytMapper.class);
|
||||
|
||||
@Override
|
||||
public String changeFpytValue(String[] split) {
|
||||
int num = 0;
|
||||
for (String s : split) {
|
||||
if (!s.equals("")){
|
||||
boolean b = changeFpytMapper.updateFpytValue(s);
|
||||
if (b){
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num == split.length){
|
||||
return "所有数据更新成功";
|
||||
}else {
|
||||
return "数据更新失败";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.controller;
|
||||
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.service.ExportPDFService;
|
||||
import com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.service.impl.ExportPDFServiceImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Path("/hcy_dingxinjituan")
|
||||
public class ExportPDFController {
|
||||
|
||||
private final ExportPDFService exportPDFService = new ExportPDFServiceImpl();
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
@GET
|
||||
@Path("/export/pdf")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response exportPDF(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
StreamingOutput output = null;
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
//第二步更新导出次+1
|
||||
exportPDFService.updateDccs(split);
|
||||
|
||||
//第一步查询数据封装到List<Map<String,Object>>类型的集合中
|
||||
List<Map<String,Object>> dataList = exportPDFService.selectDataList(split);
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
String exportUser = user.getLastname();
|
||||
//第三步同步数据
|
||||
List<Boolean> insertBooleanLists = exportPDFService.backupData(dataList,exportUser,this.getCurrentTime());
|
||||
for (Boolean list : insertBooleanLists) {
|
||||
if (list == false){
|
||||
logger.info("备份数据失败");
|
||||
}
|
||||
}
|
||||
//第四步根据第一步拿到的数据导出pdf
|
||||
String exportTime = getCurrentDateTime();//导出时间
|
||||
|
||||
|
||||
byte[] pdfBytes = exportPDFService.exportPDF(dataList,exportUser,exportTime);
|
||||
output = outputStream -> {
|
||||
outputStream.write(pdfBytes);
|
||||
outputStream.close();
|
||||
};
|
||||
String fileName = "顶新集团-"+ getCurrentTime() + ".pdf";
|
||||
try {
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String(fileName.getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return header.build();
|
||||
}
|
||||
|
||||
public static String getCurrentDateTime() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
return now.format(formatter);
|
||||
}
|
||||
|
||||
public static String getCurrentTime() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
return now.format(formatter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
import aiyh.utils.annotation.recordset.Update;
|
||||
import org.directwebremoting.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface ExportPDFMapper {
|
||||
|
||||
|
||||
@Select("select * from uf_sapywdj where id in ($t{split})")
|
||||
List<Map<String, Object>> selectDataList(String[] split);
|
||||
|
||||
@Update("update uf_sapywdj set dccs = #{s} where id = #{id}")
|
||||
boolean updateDccs(@ParamMapper("s") String s, @ParamMapper("id") String id);
|
||||
|
||||
|
||||
@Select("select dccs from uf_sapywdj where id = #{id}")
|
||||
String selectDccs(String id);
|
||||
|
||||
@Select("select requestname from workflow_requestbase where requestid = #{stringXglc}")
|
||||
String selectRequestName(String stringXglc);
|
||||
|
||||
@Select("select gysmc from uf_sapgys where id= #{gfdw} ")
|
||||
String setGfdw(String gfdw);
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ExportPDFService {
|
||||
List<Map<String, Object>> selectDataList(String[] split);
|
||||
|
||||
void updateDccs(String[] split);
|
||||
|
||||
byte[] exportPDF(List<Map<String, Object>> dataList, String exportUser, String exportTime);
|
||||
|
||||
List<Boolean> backupData(List<Map<String, Object>> dataList,String exportUser,String exportTime);
|
||||
}
|
|
@ -0,0 +1,275 @@
|
|||
package com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.mapper.ExportPDFMapper;
|
||||
import com.api.chaoyang.he.hcy_dingxinjituan.exportpdf.service.ExportPDFService;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.*;
|
||||
import com.itextpdf.text.pdf.*;
|
||||
import de.schlichtherle.io.File;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.GCONST;
|
||||
|
||||
|
||||
public class ExportPDFServiceImpl implements ExportPDFService {
|
||||
|
||||
private final ExportPDFMapper exportPDFMapper = Util.getMapper(ExportPDFMapper.class);
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public List<Map<String, Object>> selectDataList(String[] split) {
|
||||
return exportPDFMapper.selectDataList(split);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDccs(String[] split) {
|
||||
for (String s : split) {
|
||||
String dccs = Util.null2String(exportPDFMapper.selectDccs(s));
|
||||
if (!"".equals(dccs) && Util.getIntValue(dccs)!=-1){
|
||||
int dccsInt = Integer.parseInt(dccs);
|
||||
dccsInt++;
|
||||
dccs = String.valueOf(dccsInt);
|
||||
boolean updateBool = exportPDFMapper.updateDccs(dccs,s);
|
||||
}else if (!"".equals(dccs) && Util.getIntValue(dccs)==-1){
|
||||
boolean updateBool = exportPDFMapper.updateDccs("1",s);
|
||||
}
|
||||
else{
|
||||
boolean updateBool = exportPDFMapper.updateDccs("1",s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] exportPDF(List<Map<String, Object>> dataList, String exportUser, String exportTime) {
|
||||
|
||||
// 创建PDF文档
|
||||
Document document = new Document();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
PdfWriter.getInstance(document, baos);
|
||||
// 打开PDF文档
|
||||
document.open();
|
||||
|
||||
// 创建页面并设置属性
|
||||
// Rectangle pageSize = PageSize.A4;
|
||||
// document.setPageSize(pageSize.rotate()); // 横向页面
|
||||
// document.setMargins(36, 36, 36, 36); // 36pt边距
|
||||
|
||||
// 创建表格
|
||||
PdfPTable table = new PdfPTable(10);
|
||||
table.setWidthPercentage(100f);
|
||||
table.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
table.setHeaderRows(1);
|
||||
//字体
|
||||
String rootPath = GCONST.getRootPath();
|
||||
// new File(GCONST.getRootPath()+"WEB-INF"+File.separatorChar+"meeting"+File.separatorChar);
|
||||
// String fontPath = rootPath + "/WEB-INF/font/simfang.ttf";
|
||||
String fontPath = "/app/ecology/WEB-INF/font/simfang.ttf";
|
||||
logger.info("fontPath==="+fontPath);
|
||||
// BaseFont bfChinese = BaseFont.createFont("D:\\WEAVER\\ecology\\WEB-INF\\font\\simfang.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
BaseFont bfChinese = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
|
||||
|
||||
// 添加标题
|
||||
Font titleFont = new Font(bfChinese, 18, Font.BOLD);
|
||||
Paragraph title = new Paragraph("SAP-业务单据数据", titleFont);
|
||||
title.setAlignment(Element.ALIGN_CENTER);
|
||||
document.add(title);
|
||||
|
||||
|
||||
|
||||
//// 添加导出人和导出日期信息
|
||||
|
||||
Paragraph info = new Paragraph("导出人:"+exportUser+" 导出日期:"+exportTime,
|
||||
new Font(bfChinese, 10f, Font.NORMAL, BaseColor.BLACK));
|
||||
info.setAlignment(Element.ALIGN_RIGHT);
|
||||
document.add(info);
|
||||
|
||||
// 添加表头行
|
||||
// 设置表头样式及内容
|
||||
Font headerFont = new Font(bfChinese, 10, Font.BOLD, BaseColor.WHITE);
|
||||
PdfPCell headerCell = new PdfPCell();
|
||||
headerCell.setBackgroundColor(BaseColor.BLACK);
|
||||
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
headerCell.setPadding(5);
|
||||
|
||||
headerCell.setPhrase(new Phrase("申请编号", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("相关流程", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("法人公司编码", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("地址号", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("给付单位", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("开户行", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("银行账号", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("金额", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("SAP凭证号", headerFont));
|
||||
table.addCell(headerCell);
|
||||
headerCell.setPhrase(new Phrase("导出次数", headerFont));
|
||||
table.addCell(headerCell);
|
||||
|
||||
// 添加数据行
|
||||
|
||||
Font dataFont = new Font(bfChinese, 9, Font.NORMAL, BaseColor.BLACK);
|
||||
for (Map<String, Object> row : dataList) {
|
||||
table.addCell(createCell(String.valueOf(row.get("sqbh")), dataFont, Element.ALIGN_CENTER));
|
||||
String stringXglc = Util.null2String(row.get("xglc"));
|
||||
String requstName = exportPDFMapper.selectRequestName(stringXglc);
|
||||
table.addCell(createCell(requstName, dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("frgsbm")), dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("dzh")), dataFont, Element.ALIGN_CENTER));
|
||||
String gfdw = Util.null2String(row.get("gfdw"));
|
||||
String gfdwString = exportPDFMapper.setGfdw(gfdw);
|
||||
table.addCell(createCell(gfdwString, dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("khh")), dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("yhzh")), dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("je")), dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("sappzh")), dataFont, Element.ALIGN_CENTER));
|
||||
table.addCell(createCell(String.valueOf(row.get("dccs")), dataFont, Element.ALIGN_CENTER));
|
||||
}
|
||||
|
||||
// 设置表格样式和行样式
|
||||
table.setSpacingBefore(8f);
|
||||
table.setSpacingAfter(8f);
|
||||
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
table.getDefaultCell().setPadding(4f);
|
||||
|
||||
// 添加表格到页面
|
||||
document.add(table);
|
||||
|
||||
// 添加导出人和导出日期信息
|
||||
|
||||
|
||||
// 关闭PDF文档
|
||||
document.close();
|
||||
|
||||
// 将PDF文档写入输出流
|
||||
return baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("导出PDF文档异常原因==="+e);
|
||||
}
|
||||
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
public List<Boolean> backupData(List<Map<String, Object>> dataList,String exportuser,String exporttime) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
List<Boolean> insertBooleanLists = new ArrayList();
|
||||
try {
|
||||
for (Map<String, Object> map : dataList) {
|
||||
//toDo:
|
||||
String insertSql = "insert into uf_sapywdj_backup (requestId,formmodeid,modedatacreater,modedatacreatertype," +
|
||||
"modedatacreatedate,modedatacreatetime,MODEUUID,lclx,sfmdfy,qklx,fkfs,yfklx,dx,xglc,sqr,cgbs,fhxx,sappzh,sqbm," +
|
||||
"khh,yhzh,ytsm,je,frgsbm,dpmc,dpbh,qwfkrq,dzh,szgs,sqbh,cwgzrq,ph,cwjb,paystatus,completetime,fygz,jybgse,jybgwsje,jybghsje," +
|
||||
"jybgfhxx1,jybgfhxx2,jybgfhxx3,jybgfhzt1,jybgfhzt2,jybgfhzt3,jybgpzh1,jybgpzh2,jybgpzh3,dh,jybglshjl,gtddh,frgs,gfdw,cbzx,ywlx,mdcwjb," +
|
||||
"mdcwkzg,cwkzg,zbchbzg,zbchbzg1,mdcwkzg1,dpmc1,zhcyr,modedatamodifier,modedatamodifydatetime,dccs,exportuser,exporttime) values (?,?,?,?,?,?,?,?,?,?," +
|
||||
"?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
logger.info("sql==="+insertSql);
|
||||
boolean insertBool = recordSet.executeUpdate(insertSql,
|
||||
Util.null2String(map.get("requestId")),
|
||||
Util.null2String(map.get("formmodeid")),
|
||||
Util.null2String(map.get("formmodeid")),
|
||||
Util.null2String(map.get("modedatacreatertype")),
|
||||
Util.null2String(map.get("modedatacreatedate")),
|
||||
Util.null2String(map.get("modedatacreatetime")),
|
||||
Util.null2String(map.get("MODEUUID")),
|
||||
Util.null2String(map.get("lclx")),
|
||||
Util.null2String(map.get("sfmdfy")),
|
||||
Util.null2String(map.get("qklx")),
|
||||
Util.null2String(map.get("fkfs")),
|
||||
Util.null2String(map.get("yfklx")),
|
||||
Util.null2String(map.get("dx")),
|
||||
Util.null2String(map.get("xglc")),
|
||||
Util.null2String(map.get("sqr")),
|
||||
Util.null2String(map.get("cgbs")),
|
||||
Util.null2String(map.get("fhxx")),
|
||||
Util.null2String(map.get("sappzh")),
|
||||
Util.null2String(map.get("sqbm")),
|
||||
Util.null2String(map.get("khh")),
|
||||
Util.null2String(map.get("yhzh")),
|
||||
Util.null2String(map.get("ytsm")),
|
||||
Util.null2String(map.get("je")),
|
||||
Util.null2String(map.get("frgsbm")),
|
||||
Util.null2String(map.get("dpmc")),
|
||||
Util.null2String(map.get("dpbh")),
|
||||
Util.null2String(map.get("qwfkrq")),
|
||||
Util.null2String(map.get("dzh")),
|
||||
Util.null2String(map.get("szgs")),
|
||||
Util.null2String(map.get("sqbh")),
|
||||
Util.null2String(map.get("cwgzrq")),
|
||||
Util.null2String(map.get("ph")),
|
||||
Util.null2String(map.get("cwjb")),
|
||||
Util.null2String(map.get("paystatus")),
|
||||
Util.null2String(map.get("completetime")),
|
||||
Util.null2String(map.get("fygz")),
|
||||
Util.null2String(map.get("jybgse")),
|
||||
Util.null2String(map.get("jybgwsje")),
|
||||
Util.null2String(map.get("jybghsje")),
|
||||
Util.null2String(map.get("jybgfhxx1")),
|
||||
Util.null2String(map.get("jybgfhxx2")),
|
||||
Util.null2String(map.get("jybgfhxx3")),
|
||||
Util.null2String(map.get("jybgfhzt1")),
|
||||
Util.null2String(map.get("jybgfhzt2")),
|
||||
Util.null2String(map.get("jybgfhzt3")),
|
||||
Util.null2String(map.get("jybgpzh1")),
|
||||
Util.null2String(map.get("jybgpzh2")),
|
||||
Util.null2String(map.get("jybgpzh3")),
|
||||
Util.null2String(map.get("dh")),
|
||||
Util.null2String(map.get("jybglshjl")),
|
||||
Util.null2String(map.get("gtddh")),
|
||||
Util.null2String(map.get("frgs")),
|
||||
Util.null2String(map.get("gfdw")),
|
||||
Util.null2String(map.get("cbzx")),
|
||||
Util.null2String(map.get("ywlx")),
|
||||
Util.null2String(map.get("mdcwjb")),
|
||||
Util.null2String(map.get("mdcwkzg")),
|
||||
Util.null2String(map.get("cwkzg")),
|
||||
Util.null2String(map.get("zbchbzg")),
|
||||
Util.null2String(map.get("zbchbzg1")),
|
||||
Util.null2String(map.get("mdcwkzg1")),
|
||||
Util.null2String(map.get("dpmc1")),
|
||||
Util.null2String(map.get("zhcyr")),
|
||||
Util.null2String(map.get("modedatamodifier")),
|
||||
Util.null2String(map.get("modedatamodifydatetime")),
|
||||
Util.null2String(map.get("dccs")),
|
||||
exportuser,
|
||||
exporttime
|
||||
);
|
||||
insertBooleanLists.add(insertBool);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("错误原因==="+e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
return insertBooleanLists;
|
||||
}
|
||||
|
||||
private PdfPCell createCell(String text, Font font, int align) {
|
||||
PdfPCell cell = new PdfPCell(new Phrase(text, font));
|
||||
cell.setHorizontalAlignment(align);
|
||||
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
||||
cell.setPadding(4f);
|
||||
return cell;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.controller;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_fengtianfangzhi.service.DetailDataExportExcelApi;
|
||||
import com.api.chaoyang.he.hcy_fengtianfangzhi.service.impl.DetailDataExportExcelService;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/hcy_fengtianfangzhi")
|
||||
public class DetailDataExportExcelController {
|
||||
|
||||
|
||||
private DetailDataExportExcelApi detailDataExportExcelService = new DetailDataExportExcelService();
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
*导出AVPN Excel表格
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("/detailDataExportExcel")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response checkRequestInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
String requestid = request.getParameter("requestid");
|
||||
logger.info("requestid=="+requestid);
|
||||
String lsxjd = request.getParameter("lsxjd");
|
||||
logger.info("lsxjd=="+lsxjd);//lsxjd
|
||||
Response response1 = detailDataExportExcelService.exportExcel(requestid,lsxjd);
|
||||
return response1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.controller;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import com.engine.workflow.biz.requestForm.WfToDocBiz;
|
||||
import com.engine.workflow.biz.requestForm.WfWaterMark4WfToDocBiz;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.file.FileUpload;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.workflow.action.WorkflowToDoc;
|
||||
import weaver.system.SystemComInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>导出状态修改</h1>
|
||||
* @Author jiacheng.deng
|
||||
* @Date 2023/1/18 14:50
|
||||
*/
|
||||
//"tb/djc/changeStatus/download/requestid=" + requestId + "&workflowid=" + workflowId + "&nodeid=" + nodeId
|
||||
@Path("/tb")
|
||||
public class TbSheetChangeDownloadStatusController {
|
||||
|
||||
|
||||
//流程保存文档源码
|
||||
private WorkflowToDoc workflowToDoc = new WorkflowToDoc();
|
||||
//流程保存文档源码
|
||||
private WfToDocBiz wfToDocBiz = new WfToDocBiz();
|
||||
//数据库链接驱动
|
||||
private RecordSet recordSet = new RecordSet();
|
||||
//日志
|
||||
private final Logger log = Util.getLogger();
|
||||
//底部签字意见列表显示数量
|
||||
private int pageSize =100;
|
||||
//下载的输入流
|
||||
private ImageFileManager imageFileManager = new ImageFileManager();
|
||||
|
||||
/**
|
||||
* <h2>修改导出状态</h2>
|
||||
* @param request,response
|
||||
* @return String
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@GET
|
||||
@Path("/changeStatus/download")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response changeStatus(@Context HttpServletRequest request,
|
||||
@Context HttpServletResponse response
|
||||
) {
|
||||
|
||||
try {
|
||||
User logInUser = HrmUserVarify.getUser(request, response);
|
||||
String uid = String.valueOf(logInUser.getUID());
|
||||
log.info("用户的id===>" + uid);
|
||||
String findUserRole = "select * from HrmRoleMembers where resourceid = " + uid;
|
||||
boolean b = recordSet.execute(findUserRole);
|
||||
log.info("查询用户数据sql===> " + findUserRole + " ===>是否执行 :" + b);
|
||||
recordSet.next();
|
||||
String roleid = recordSet.getString("roleid");
|
||||
log.info("用户角色roleid===>" + roleid);
|
||||
|
||||
// log.info("requsetid===>" + requestid + "workflowid===>" + workflowid + "nodeid===>" + nodeid);
|
||||
|
||||
|
||||
if ("1031".equals(roleid)) {
|
||||
|
||||
try {
|
||||
// StreamingOutput downloadStream = download2changeStatus(uid,request,response,requestid,workflowid,nodeid);
|
||||
|
||||
// InputStream is = imageFileManager.getInputStreamById(this.getImageFileId(requestid));
|
||||
|
||||
String updateDownloadStatusSQl = "update formtable_main_368 set dczt = ?" ;
|
||||
|
||||
int flag = 1;
|
||||
boolean b1 = recordSet.executeUpdate(updateDownloadStatusSQl, flag);
|
||||
log.info("执行修改导出状态代码===>" + b1);
|
||||
|
||||
|
||||
// return Response.ok(downloadStream, MediaType.APPLICATION_OCTET_STREAM).type("application/")
|
||||
// .header("Content-Disposition", "attachment;filename=workflow.pdf").build();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("转换失败:" + e.toString());
|
||||
return Response.ok(ApiResult.error("出现错误,错误原因: " + e), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
// StreamingOutput downloadStream = download2changeStatus(uid,request,response,requestid,workflowid,nodeid);
|
||||
// return Response.ok(downloadStream, MediaType.APPLICATION_OCTET_STREAM).type("application/pdf")
|
||||
// .header("Content-Disposition", "attachment;filename=contracts.zip").build();
|
||||
} catch (Exception e) {
|
||||
log.error("转换失败:" + e.toString());
|
||||
|
||||
return Response.ok(ApiResult.error("出现错误,错误原因: " + e), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>修改导出状态</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
public StreamingOutput download2changeStatus(String uid,HttpServletRequest request,HttpServletResponse response,String requestid,String workflowid,String nodeid){
|
||||
|
||||
LinkedHashMap<String, String> fileids = new LinkedHashMap<String, String> ();
|
||||
|
||||
User user = new User(weaver.general.Util.getIntValue(uid));
|
||||
|
||||
String docFiles = getDocFiles(workflowid);
|
||||
//是否签名
|
||||
int keepSign = getKeepSign(workflowid);
|
||||
String filename = UUID.randomUUID().toString();
|
||||
String temppath = getFileSavePath();
|
||||
|
||||
//是否开启水印
|
||||
boolean isOpenWaterMark = WfWaterMark4WfToDocBiz.isOpenWaterMark(weaver.general.Util.getIntValue(workflowid));
|
||||
//在这里先获取到modeid 线程中获取时流程可能已经到了下个节点导致模板获取的不对
|
||||
String modeid = wfToDocBiz.getModeid(Util.getIntValue(requestid), Util.getIntValue(workflowid), Util.getIntValue(nodeid));
|
||||
|
||||
WfToDocBiz wfToDocBiz = new WfToDocBiz(user,pageSize,keepSign,docFiles,modeid,isOpenWaterMark);
|
||||
wfToDocBiz.generatepdfandhtml(requestid,filename,temppath,"1");
|
||||
fileids.putAll(wfToDocBiz.getfileids("",filename,temppath));
|
||||
|
||||
StreamingOutput output = outputStream -> {
|
||||
|
||||
String docID;
|
||||
if (recordSet.next()){
|
||||
|
||||
docID = wfToDocBiz.getWfDocPath(workflowid, requestid);
|
||||
log.info("文档生成路径=="+docID);
|
||||
ImageFileManager imageFileManager = new ImageFileManager();
|
||||
int imageFileId = this.getImageFileId(requestid);
|
||||
log.info("imageFileId ==" + imageFileId);
|
||||
InputStream is = imageFileManager.getInputStreamById(this.getImageFileId(requestid));
|
||||
|
||||
String fileName = this.getImageFileName(requestid);
|
||||
|
||||
};
|
||||
|
||||
//关闭流
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getImageFileName(String requestid) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获得文件保存目录</h2>
|
||||
* @param
|
||||
* @return String
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
public String getFileSavePath() {
|
||||
SystemComInfo syscominfo = new SystemComInfo();
|
||||
String createdir = FileUpload.getCreateDir(syscominfo.getFilesystem());
|
||||
return createdir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据requestId返回docimagefile表中imagefileId</h2>
|
||||
* @param requestid
|
||||
* @return int
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
public int getImageFileId(String requestid){
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_imagefileid_sql = "select tablename \n" +
|
||||
"from workflow_bill \n" +
|
||||
"where id = (select formid from workflow_base where id = \n" +
|
||||
"(select workflowid from workflow_requestbase where requestid = ?)\n" +
|
||||
")";
|
||||
boolean b = recordSet.executeQuery(get_imagefileid_sql, requestid);
|
||||
log.info("b是否执行"+b);
|
||||
boolean next = recordSet.next();
|
||||
String tablename = recordSet.getString("tablename");
|
||||
String docid_key = this.getWfDocRelateFieldName(requestid);//每一流程表单中用来存放docid的字段名称
|
||||
|
||||
String get_docid_sql = "select "+docid_key+" from "+tablename+" where requestid = ?";
|
||||
boolean b1 = recordSet.executeQuery(get_docid_sql, requestid);
|
||||
log.info("b1是否执行=="+b1);
|
||||
recordSet.next();
|
||||
String docid = recordSet.getString(docid_key);
|
||||
if (Util.null2String(docid).equals("")){
|
||||
return -1;
|
||||
}
|
||||
String get_imagefileid = "select imagefileid from DocImageFile where docid = ? order by versionId";
|
||||
boolean b2 = recordSet.executeQuery(get_imagefileid, docid);
|
||||
log.info("b2是否执行=="+b2);
|
||||
recordSet.next();
|
||||
String imagefileid = recordSet.getString("imagefileid");
|
||||
return Integer.parseInt(imagefileid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据requestId反查 文档关联到的表单字段
|
||||
* @param requestid
|
||||
* @return
|
||||
*/
|
||||
public String getWfDocRelateFieldName(String requestid){
|
||||
String get_wfdocrelatefilename_sql = "select fieldname from workflow_billfield \n" +
|
||||
"where id =(select wfdocrelatefieldid from workflow_base \n" +
|
||||
"where id = (select workflowid from workflow_requestbase where requestid = ?))";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(get_wfdocrelatefilename_sql, requestid);
|
||||
log.info("getWfDocRelateFieldName---b是否执行=="+b);
|
||||
boolean next = recordSet.next();
|
||||
String fieldname = recordSet.getString("fieldname");
|
||||
return Util.null2String(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>得到docfiles 文档附件 在线表单/离线表单(HTML)/离线表单(PDF)</h2>
|
||||
* @param workflowid
|
||||
* @return String
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
public String getDocFiles(String workflowid){
|
||||
RecordSet rs = new RecordSet();
|
||||
String docfiles = "";
|
||||
String wfdocpath = "";
|
||||
rs.executeQuery("select docfiles,wfdocpath from workflow_base where id = ?",workflowid);
|
||||
if (rs.next()){
|
||||
docfiles = weaver.general.Util.null2String(rs.getString("docfiles"));
|
||||
wfdocpath = weaver.general.Util.null2String(rs.getString("wfdocpath"));
|
||||
}
|
||||
if ("".equals(docfiles)&&!"".equals(wfdocpath)){
|
||||
docfiles="1";
|
||||
rs.executeUpdate("update workflow_base set docfiles ='1' where id = ?",workflowid);
|
||||
}
|
||||
return docfiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>得到keepsign 是否保留签字意见</h2>
|
||||
* @param workflowid
|
||||
* @return int
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
public int getKeepSign(String workflowid){
|
||||
RecordSet rs = new RecordSet();
|
||||
int keepsign = 0;
|
||||
rs.executeQuery("select keepsign from workflow_base where id = ?",workflowid);
|
||||
if (rs.next()){
|
||||
keepsign = rs.getInt("keepsign");
|
||||
}
|
||||
return keepsign;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface DetailDataExportExcelMapper{
|
||||
|
||||
@Select("select * from formtable_main_378 fm " +
|
||||
"inner join formtable_main_378_dt1 fmdt " +
|
||||
"on fm.id = fmdt.mainid where fm.requestid = #{requestid}")
|
||||
List<Map<String, Object>> selectTotalData(String requestId);
|
||||
|
||||
// @Select("select * from formtable_main_35 fm " +
|
||||
// "inner join formtable_main_35_dt1 fmdt " +
|
||||
// "on fm.id = fmdt.mainid where fm.requestid = #{requestid}")
|
||||
// List<Map<String, Object>> selectTotalData(String requestId);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.service;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* 生成excel接口文档
|
||||
*/
|
||||
public interface DetailDataExportExcelApi {
|
||||
|
||||
|
||||
/**
|
||||
* 用于生成最终的excel表格
|
||||
*/
|
||||
public Response exportExcel(String requestId,String lsxjd);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,403 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_fengtianfangzhi.mapper.DetailDataExportExcelMapper;
|
||||
import com.api.chaoyang.he.hcy_fengtianfangzhi.service.DetailDataExportExcelApi;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DetailDataExportExcelService implements DetailDataExportExcelApi {
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
public Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
/**
|
||||
* sql
|
||||
*/
|
||||
private DetailDataExportExcelMapper detailDataExportExcelMapper = Util.getMapper(DetailDataExportExcelMapper.class);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用来返回生成的excel流对象
|
||||
* @param requestId requestid
|
||||
*/
|
||||
public Response exportExcel(String requestId,String lsxjd) {
|
||||
|
||||
//创建一个工作簿
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
//创建一个工作表sheet
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
//设置sheet表名称
|
||||
workbook.setSheetName(0, "询价单明细表单");
|
||||
//设置表单列宽
|
||||
sheet.autoSizeColumn(1, true);
|
||||
|
||||
RecordSet recordSet = new RecordSet();//创建sql执行对象
|
||||
|
||||
List<Map<String,Object>> totalDataList = detailDataExportExcelMapper.selectTotalData(requestId);
|
||||
for (Map<String, Object> map : totalDataList) {
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object v = entry.getValue();
|
||||
if (key.equals("sqrxm")){//申请人姓名
|
||||
String get_sqrxm_sql = "select lastname from hrmresource where id=?";
|
||||
recordSet.executeQuery(get_sqrxm_sql,Util.null2String(v));
|
||||
recordSet.next();
|
||||
map.put("sqrxm",recordSet.getString("lastname"));
|
||||
}
|
||||
if (key.equals("gys")){//供应商
|
||||
String get_gys_sql = "select gysqm from uf_gyszsjxx where id=?";
|
||||
recordSet.executeQuery(get_gys_sql, Util.null2String(v));
|
||||
recordSet.next();
|
||||
map.put("gys",recordSet.getString("gysqm"));
|
||||
}
|
||||
if("xjr".equals(key)){//询价人
|
||||
String get_sqrxm_sql = "select lastname from hrmresource where id=?";
|
||||
recordSet.executeQuery(get_sqrxm_sql,Util.null2String(v));
|
||||
recordSet.next();
|
||||
map.put("xjr",recordSet.getString("lastname"));
|
||||
}
|
||||
if ("ylbm".equals(key) ||"sqrbm".equals(key) || "sqrfb".equals(key) || "xjbm".equals(key)){//依赖部门 //申请人部门 //申请人分部 //询价部门
|
||||
String getYlbm = "select departmentname from HrmDepartment where id = ? ";
|
||||
recordSet.executeQuery(getYlbm,Util.null2String(v));
|
||||
recordSet.next();
|
||||
map.put(key,recordSet.getString("departmentname"));
|
||||
}
|
||||
|
||||
if ("lsxjd".equals(key)){//历史询价单
|
||||
String getLsxjd = "select requestname from workflow_requestbase where requestid = ? ";
|
||||
recordSet.executeQuery(getLsxjd,Util.null2String(v));
|
||||
recordSet.next();
|
||||
map.put(key,recordSet.getString("requestname"));
|
||||
}
|
||||
|
||||
// if("sqrbm".equals(key)){//申请人部门
|
||||
// String getYlbm = "select departmentname from HrmDepartment where id = ? ";
|
||||
// recordSet.executeQuery(getYlbm,Util.null2String(v));
|
||||
// recordSet.next();
|
||||
// map.put(key,recordSet.getString("departmentname"));
|
||||
// }
|
||||
// if ("sqrfb".equals(key)){//申请人分部
|
||||
// String getYlbm = "select departmentname from HrmDepartment where id = ? ";
|
||||
// recordSet.executeQuery(getYlbm,Util.null2String(v));
|
||||
// recordSet.next();
|
||||
// map.put(key,recordSet.getString("departmentname"));
|
||||
// }
|
||||
// if("xjbm".equals(key)){//询价部门
|
||||
// String getYlbm = "select departmentname from HrmDepartment where id = ? ";
|
||||
// recordSet.executeQuery(getYlbm,Util.null2String(v));
|
||||
// recordSet.next();
|
||||
// map.put(key,recordSet.getString("departmentname"));
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
String getMainTableValueSql = "select id from uf_xjdmxbdczdpzbd where wybs = 'ftfz_exportExcel' ";
|
||||
boolean b = recordSet.executeQuery(getMainTableValueSql);
|
||||
logger.info("getMainTableValueSql是否执行=="+b);
|
||||
String mainId = "";
|
||||
if (recordSet.next()){
|
||||
mainId = recordSet.getString("id");
|
||||
}
|
||||
String getDetailTableValueSql = "select * from uf_xjdmxbdczdpzbd_dt1 where mainId = ?";
|
||||
boolean b1 = recordSet.executeQuery(getDetailTableValueSql, mainId);
|
||||
logger.info("getDetailTableValueSql是否执行==="+b1);
|
||||
List<String> fieldNamesList = new ArrayList<>();//用于存放excel第一个行的明细表显示名
|
||||
List<String> dBNamesList = new ArrayList<>();//用于存放明细表数据库名
|
||||
|
||||
while (recordSet.next()){
|
||||
String mxzdxsm = recordSet.getString("mxzdxsm");//字段显示名
|
||||
String mxzdsjkm = recordSet.getString("mxzdsjkm");//字段数据库名
|
||||
fieldNamesList.add(mxzdxsm);
|
||||
dBNamesList.add(mxzdsjkm);
|
||||
}
|
||||
logger.info("fieldNamesList=="+fieldNamesList);
|
||||
|
||||
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
|
||||
for (int colNum=0;colNum<fieldNamesList.size();colNum++){
|
||||
XSSFCell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(fieldNamesList.get(colNum));
|
||||
}
|
||||
|
||||
try {
|
||||
for (int cowNum=1;cowNum<totalDataList.size()+1;cowNum++){
|
||||
XSSFRow row1 = sheet.createRow(cowNum);
|
||||
Map<String, Object> map1 = totalDataList.get(cowNum-1);
|
||||
|
||||
for (int colNum=0;colNum<dBNamesList.size();colNum++){
|
||||
XSSFCell cell = row1.createCell(colNum);
|
||||
String field = dBNamesList.get(colNum);
|
||||
|
||||
if (!"".equals(field)){
|
||||
if (field.equals("pl")){//品类---下拉框 :28-消耗品、29-工事、30-劳保用品、31-IT
|
||||
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(Util.null2String(map1.get(field)));
|
||||
|
||||
}else if (field.equals("sqsl")){//申请数量--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (field.equals("bz")){//币种--浏览按钮
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
if (String.valueOf(o).equals("1")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("RMB");
|
||||
}
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (field.equals("wsdj")){//未税单价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("wszj")){//未税总价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("sl")){//税率(%)--整数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
int value = Integer.parseInt(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("se")){//税额--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("hsdj")){//含税单价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
}else if (field.equals("hszj")){//含税总价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
}else if (field.equals("ddhfqwnqt")){//调达回复期望纳期(天)--整数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
int value = Integer.parseInt(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("");
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("chzx")){//存货属性--下拉框:32-临时品、33-定期品
|
||||
if (map1.get(field).equals("0")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("临时品");
|
||||
}else if (map1.get(field).equals("1")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("定期品");
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
}
|
||||
}else if (field.equals("chbm")){//存货编码--自定义单选
|
||||
String get_chbm_sql = "select chbm from uf_chtz_tbtj where id=?";
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b4 = recordSet1.executeQuery(get_chbm_sql, map1.get(field));
|
||||
logger.info("get_chbm_sql语句是否查询成功==="+b4);
|
||||
if (recordSet1.next()){
|
||||
String chbmValue = recordSet1.getString("chbm");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(chbmValue);
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(String.valueOf(map1.get(field)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("NumberFormatException==="+e);
|
||||
}
|
||||
|
||||
StreamingOutput output;
|
||||
Response build;
|
||||
Response.ResponseBuilder header = null;
|
||||
|
||||
try {
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String("询价单明细表单.xlsx".getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
}
|
||||
build = header.build();
|
||||
logger.info("走到导出excel这一步");
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置字体样式,并设置字体加粗
|
||||
*
|
||||
* @param workbook workbook对象
|
||||
* @return CellStyle对象
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook worKbook对象
|
||||
* @return CellStyle 字体样式
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook workbook对象
|
||||
* @return inputStream流
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,497 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_fengtianfangzhi.service.DetailDataExportExcelApi;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DetailDataExportExcelService_copy implements DetailDataExportExcelApi {
|
||||
|
||||
|
||||
public Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* 用来返回生成的excel流对象
|
||||
* @param requestId requestid
|
||||
*/
|
||||
public Response exportExcel(String requestId,String lsxjd) {
|
||||
|
||||
//创建一个工作簿
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
//创建一个工作表sheet
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
//设置sheet表名称
|
||||
workbook.setSheetName(0, "询价单明细表单");
|
||||
//设置表单列宽
|
||||
sheet.autoSizeColumn(1, true);
|
||||
|
||||
RecordSet recordSet = new RecordSet();//创建sql执行对象
|
||||
String getMainIdSql = "select * from formtable_main_378 where requestId = ?";
|
||||
// String getMainIdSql = "select * from formtable_main_35 where requestId = ?";
|
||||
|
||||
boolean b2 = recordSet.executeQuery(getMainIdSql, requestId);
|
||||
logger.info("getMainIdSql语句是否执行==="+b2);
|
||||
String formtable_main_35_id="";//询价单流程表单id,作为明细表的mianId使用
|
||||
Map<String, Object> mainDataMap = new HashMap<>();//用于存放主表的数据
|
||||
if (recordSet.next()){
|
||||
formtable_main_35_id = recordSet.getString("id");
|
||||
String sqdh = recordSet.getString("sqdh");//申请单号
|
||||
mainDataMap.put("sqdh",sqdh);
|
||||
String sqrxmID = recordSet.getString("sqrxm");//申请人姓名
|
||||
String get_sqrxm_sql = "select lastname from hrmresource where id=?";
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
recordSet1.executeQuery(get_sqrxm_sql, sqrxmID);
|
||||
if (recordSet1.next()){
|
||||
String lastname = recordSet1.getString("lastname");
|
||||
mainDataMap.put("sqrxm",lastname);
|
||||
}
|
||||
String sqrbm = recordSet.getString("sqrbm");//申请人部门
|
||||
mainDataMap.put("sqrbm",sqrbm);
|
||||
String sqrfb = recordSet.getString("sqrfb");//申请人分部
|
||||
mainDataMap.put("sqrfb",sqrfb);
|
||||
String sqrq = recordSet.getString("sqrq");//申请日期
|
||||
mainDataMap.put("sqrq",sqrq);
|
||||
// String lsxjd = recordSet.getString("lsxjd");//历史询价单
|
||||
mainDataMap.put("lsxjd",lsxjd);
|
||||
String xjbm = recordSet.getString("xjbm");//询价部门
|
||||
mainDataMap.put("xjbm",xjbm);
|
||||
String bz = recordSet.getString("bz");//备注
|
||||
mainDataMap.put("bz",bz);
|
||||
String bjfj = recordSet.getString("bjfj");//报价附件
|
||||
mainDataMap.put("bjfj",bjfj);
|
||||
String yafj = recordSet.getString("yafj");//议案附件
|
||||
mainDataMap.put("yafj",yafj);
|
||||
String sysfj = recordSet.getString("sysfj");//式样书附件
|
||||
mainDataMap.put("sysfj",sysfj);
|
||||
String hszje = recordSet.getString("hszje");//含税总金额
|
||||
mainDataMap.put("hszje",hszje);
|
||||
String wszje = recordSet.getString("wszje");//未税总金额
|
||||
mainDataMap.put("wszje",wszje);
|
||||
String fkblhj = recordSet.getString("fkblhj");//付款比例(合计)
|
||||
mainDataMap.put("fkblhj",fkblhj);
|
||||
String ylbmId = recordSet.getString("ylbm");//依赖部门
|
||||
String getYlbm = "select departmentname from HrmDepartment where id = ? ";
|
||||
recordSet1.executeQuery(getYlbm,ylbmId);
|
||||
recordSet1.next();
|
||||
String departmentname = recordSet1.getString("departmentname");
|
||||
mainDataMap.put("ylbm",departmentname);
|
||||
String xjrid = recordSet.getString("xjr");//询价人
|
||||
recordSet1.executeQuery(get_sqrxm_sql,xjrid);
|
||||
recordSet1.next();
|
||||
String xjr = recordSet1.getString("lastname");
|
||||
mainDataMap.put("xjr",xjr);
|
||||
String gysId = recordSet.getString("gys");//供应商
|
||||
String get_gys_sql = "select gysqm from uf_gyszsjxx where id=?";
|
||||
recordSet1.executeQuery(get_gys_sql, gysId);
|
||||
if (recordSet1.next()){
|
||||
String gysqm = recordSet1.getString("gysqm");
|
||||
mainDataMap.put("gys",gysqm);
|
||||
}
|
||||
|
||||
}
|
||||
logger.info("mainDataMap主表数据==="+mainDataMap);
|
||||
String getDetailDataSql = "select * from formtable_main_378_dt1 where mainId = ?";
|
||||
// String getDetailDataSql = "select * from formtable_main_35_dt1 where mainId = ?";
|
||||
boolean b3 = recordSet.executeQuery(getDetailDataSql, formtable_main_35_id);
|
||||
logger.info("getDetailDataSql语句是否执行==="+b3);
|
||||
List<Map<String,Object>> listMap = new ArrayList<>();//用于存放明细表数据
|
||||
while (recordSet.next()){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String id = recordSet.getString("id");
|
||||
map.put("id",id);
|
||||
String mainId1 = recordSet.getString("mainId");
|
||||
map.put("mainId",mainId1);
|
||||
String pl = Util.null2String(recordSet.getString("pl"));
|
||||
String plValue = "";
|
||||
if (!"".equals(pl)){
|
||||
//消耗品 设备工事 劳保用品 IT
|
||||
switch(pl){
|
||||
case "0":
|
||||
plValue = "消耗品";
|
||||
break;
|
||||
case "1" :
|
||||
plValue = "设备工事";
|
||||
break;
|
||||
case "2" :
|
||||
plValue = "劳保用品";
|
||||
break;
|
||||
case "3":
|
||||
break;
|
||||
default :
|
||||
plValue = "";
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
map.put("pl", "");
|
||||
}
|
||||
map.put("pl", plValue);
|
||||
String pm = recordSet.getString("pm");
|
||||
map.put("pm",pm);
|
||||
String pp = recordSet.getString("pp");
|
||||
map.put("pp",pp);
|
||||
String ggxh = recordSet.getString("ggxh");
|
||||
map.put("ggxh",ggxh);
|
||||
String jldw = recordSet.getString("jldw");
|
||||
map.put("jldw",jldw);
|
||||
String sqsl = recordSet.getString("sqsl");
|
||||
map.put("sqsl",sqsl);
|
||||
String bz = recordSet.getString("bz");
|
||||
map.put("bz",bz);
|
||||
String wsdj = recordSet.getString("wsdj");
|
||||
map.put("wsdj",wsdj);
|
||||
String wszj = recordSet.getString("wszj");
|
||||
map.put("wszj",wszj);
|
||||
String sl = recordSet.getString("sl");
|
||||
map.put("sl",sl);
|
||||
String se = recordSet.getString("se");
|
||||
map.put("se",se);
|
||||
String hsdj = recordSet.getString("hsdj");
|
||||
map.put("hsdj",hsdj);
|
||||
String hszj = recordSet.getString("hszj");
|
||||
map.put("hszj",hszj);
|
||||
String qwnq = recordSet.getString("qwnq");
|
||||
map.put("qwnq",qwnq);
|
||||
String ddhfqwnqt = recordSet.getString("ddhfqwnqt");
|
||||
map.put("ddhfqwnqt",ddhfqwnqt);
|
||||
String gys = recordSet.getString("gys");
|
||||
map.put("gys",gys);
|
||||
String cx = recordSet.getString("cx");
|
||||
map.put("cx",cx);
|
||||
String jd = recordSet.getString("jd");
|
||||
map.put("jd",jd);
|
||||
String bz1 = recordSet.getString("bz1");
|
||||
map.put("bz1",bz1);
|
||||
String fj = recordSet.getString("fj");
|
||||
map.put("fj",fj);
|
||||
String chzx = recordSet.getString("chzx");
|
||||
map.put("chzx",chzx);
|
||||
String chbm = recordSet.getString("chbm");
|
||||
map.put("chbm",chbm);
|
||||
listMap.add(map);
|
||||
}
|
||||
logger.info("listMap明细表数据==="+listMap);
|
||||
String getMainTableValueSql = "select id from uf_xjdmxbdczdpzbd where wybs = 'ftfz_exportExcel' ";
|
||||
boolean b = recordSet.executeQuery(getMainTableValueSql);
|
||||
logger.info("getMainTableValueSql是否执行=="+b);
|
||||
String mainId = "";
|
||||
if (recordSet.next()){
|
||||
mainId = recordSet.getString("id");
|
||||
}
|
||||
String getDetailTableValueSql = "select * from uf_xjdmxbdczdpzbd_dt1 where mainId = ?";
|
||||
boolean b1 = recordSet.executeQuery(getDetailTableValueSql, mainId);
|
||||
logger.info("getDetailTableValueSql是否执行==="+b1);
|
||||
List<String> fieldNamesList = new ArrayList<>();//用于存放excel第一个行的明细表显示名
|
||||
List<String> mainFieldNamesList = new ArrayList<>();//用于存放excel第一个行的主表显示名
|
||||
List<String> detalsDBName = new ArrayList<>();//用于存放明细表数据库名
|
||||
List<String> mainDBName = new ArrayList<>();//用于存放主表数据库字段名
|
||||
while (recordSet.next()){
|
||||
String sjly = recordSet.getString("sjly");//数据来源
|
||||
String mxzdxsm = recordSet.getString("mxzdxsm");//字段显示名
|
||||
// String mxzdlx = recordSet.getString("mxzdlx");//字段类型
|
||||
String mxzdsjkm = recordSet.getString("mxzdsjkm");//字段数据库名
|
||||
if (!"".equals(sjly)&&sjly.equals("0")){
|
||||
mainFieldNamesList.add(mxzdxsm);
|
||||
mainDBName.add(mxzdsjkm);
|
||||
}else if (!"".equals(sjly)&&sjly.equals("1")){
|
||||
fieldNamesList.add(mxzdxsm);
|
||||
detalsDBName.add(mxzdsjkm);
|
||||
}
|
||||
|
||||
}
|
||||
logger.info("fieldNamesList=="+fieldNamesList);
|
||||
logger.info("mainFieldNamesList=="+mainFieldNamesList);
|
||||
logger.info("detalsDBName=="+detalsDBName);
|
||||
logger.info("mainDBName=="+mainDBName);
|
||||
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
for (int colNum=0;colNum<mainFieldNamesList.size();colNum++){
|
||||
XSSFCell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(mainFieldNamesList.get(colNum));
|
||||
}
|
||||
for (int colNum=mainFieldNamesList.size();colNum<fieldNamesList.size()+mainFieldNamesList.size();colNum++){
|
||||
XSSFCell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(fieldNamesList.get(colNum-mainFieldNamesList.size()));
|
||||
}
|
||||
|
||||
try {
|
||||
for (int cowNum=1;cowNum<listMap.size()+1;cowNum++){
|
||||
XSSFRow row1 = sheet.createRow(cowNum);
|
||||
Map<String, Object> map1 = listMap.get(cowNum-1);
|
||||
for (int colMainDataNum=0;colMainDataNum<mainDBName.size();colMainDataNum++){
|
||||
XSSFCell cell = row1.createCell(colMainDataNum);
|
||||
String value = mainDBName.get(colMainDataNum);
|
||||
if (!"".equals(value)){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(String.valueOf(mainDataMap.get(value)));
|
||||
}
|
||||
}
|
||||
|
||||
for (int colNum=mainDBName.size();colNum<detalsDBName.size()+mainDBName.size();colNum++){
|
||||
XSSFCell cell = row1.createCell(colNum);
|
||||
String field = detalsDBName.get(colNum-mainDBName.size());
|
||||
|
||||
if (!"".equals(field)){
|
||||
if (field.equals("pl")){//品类---下拉框 :28-消耗品、29-工事、30-劳保用品、31-IT
|
||||
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(Util.null2String(map1.get(field)));
|
||||
|
||||
}else if (field.equals("sqsl")){//申请数量--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (field.equals("bz")){//币种--浏览按钮
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
if (String.valueOf(o).equals("1")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("RMB");
|
||||
}
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (field.equals("wsdj")){//未税单价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("wszj")){//未税总价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("sl")){//税率(%)--整数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
int value = Integer.parseInt(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("se")){//税额--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("hsdj")){//含税单价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
}else if (field.equals("hszj")){//含税总价--浮点数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
double value = Double.parseDouble(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
cell.setCellValue("");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
}
|
||||
}else if (field.equals("ddhfqwnqt")){//调达回复期望纳期(天)--整数
|
||||
Object o = map1.get(field);
|
||||
if (!String.valueOf(o).equals("")){
|
||||
int value = Integer.parseInt(String.valueOf(o));
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("");
|
||||
}
|
||||
|
||||
|
||||
}else if (field.equals("chzx")){//存货属性--下拉框:32-临时品、33-定期品
|
||||
if (map1.get(field).equals("0")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("临时品");
|
||||
}else if (map1.get(field).equals("1")){
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue("定期品");
|
||||
}else {
|
||||
cell.setCellValue("");
|
||||
}
|
||||
}else if (field.equals("chbm")){//存货编码--自定义单选
|
||||
String get_chbm_sql = "select chbm from uf_chtz_tbtj where id=?";
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b4 = recordSet1.executeQuery(get_chbm_sql, map1.get(field));
|
||||
logger.info("get_chbm_sql语句是否查询成功==="+b4);
|
||||
if (recordSet1.next()){
|
||||
String chbmValue = recordSet1.getString("chbm");
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(chbmValue);
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyWordStyle(workbook));
|
||||
cell.setCellValue(String.valueOf(map1.get(field)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("NumberFormatException==="+e);
|
||||
}
|
||||
|
||||
StreamingOutput output;
|
||||
Response build;
|
||||
Response.ResponseBuilder header = null;
|
||||
|
||||
try {
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String("询价单明细表单.xlsx".getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
}
|
||||
build = header.build();
|
||||
logger.info("走到导出excel这一步");
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置字体样式,并设置字体加粗
|
||||
*
|
||||
* @param workbook workbook对象
|
||||
* @return CellStyle对象
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook worKbook对象
|
||||
* @return CellStyle 字体样式
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook workbook对象
|
||||
* @return inputStream流
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
package com.api.chaoyang.he.hcy_fengtianfangzhi.wflistdonestore;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import com.engine.workflow.biz.requestForm.WfToDocBiz;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.tools.zip.ZipEntry;
|
||||
import org.apache.tools.zip.ZipOutputStream;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Path("/hcy_fengtianfangzhi/wflistdonestore")
|
||||
public class ExportPDF {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* 源码内容
|
||||
*/
|
||||
private final WfToDocBiz wfToDocBiz = new WfToDocBiz();
|
||||
|
||||
/**
|
||||
*已办流程批量导出pdf
|
||||
* @param request 请求
|
||||
* @param response 响应
|
||||
* @return Response 包含所有勾选的压缩包
|
||||
*/
|
||||
@GET
|
||||
@Path("/ExportPDF")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response exportPDF(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
try {
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
String getWorkflowId_sql = "select workflowid from workflow_requestbase where requestid = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
int amountWorkflowToDoc = this.getAmountWorkflowToDoc(split);//用来统计流程转文档的流程的数量,如果数量为0,返回文件为空
|
||||
StreamingOutput output = outputStream -> {
|
||||
ZipOutputStream zipOut = new ZipOutputStream(outputStream);
|
||||
for (String requestId : split) {
|
||||
boolean b = recordSet.executeQuery(getWorkflowId_sql, requestId);
|
||||
logger.info("b是否执行"+b);
|
||||
String docID;
|
||||
if (recordSet.next()){
|
||||
String workflowid = recordSet.getString("workflowid");
|
||||
docID = wfToDocBiz.getWfDocPath(workflowid, requestId);
|
||||
logger.info("文档生成路径=="+docID);
|
||||
int imageFileId = this.getImageFileId(requestId);
|
||||
if (imageFileId==-1){
|
||||
continue;
|
||||
}
|
||||
InputStream is = ImageFileManager.getInputStreamById(this.getImageFileId(requestId));
|
||||
String fileName = this.getImageFileName(requestId);
|
||||
if (Util.null2String(fileName).equals("")){
|
||||
break;
|
||||
}
|
||||
this.addToZip(is,zipOut,fileName);//向zipout对象中插入每个pdf文件
|
||||
}
|
||||
}
|
||||
//关闭流
|
||||
zipOut.flush();
|
||||
zipOut.close();
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
if (amountWorkflowToDoc == 0){
|
||||
return Response.ok(ApiResult.error("文件为空"),MediaType.TEXT_PLAIN).build();
|
||||
}
|
||||
String lastname = HrmUserVarify.getUser(request, response).getLastname();
|
||||
String pdfName = lastname + "_" +getCurrentTime() + "_" + split.length;
|
||||
return Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).type("application/zip")
|
||||
.header("Content-Disposition", "attachment;filename=\"" +
|
||||
new String(pdfName.getBytes("GBK"), StandardCharsets.ISO_8859_1) + ".zip" + "\"").build();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Response.ok(ApiResult.error("出现错误,错误原因:"+e),MediaType.TEXT_PLAIN).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当某个流程成功导出pdf时,更新导出状态字段为已导出
|
||||
* @param requestId requestid
|
||||
*/
|
||||
public void updateValue(String requestId){
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_imagefileid_sql = "select tablename \n" +
|
||||
"from workflow_bill \n" +
|
||||
"where id = (select formid from workflow_base where id = \n" +
|
||||
"(select workflowid from workflow_requestbase where requestid = ?)\n" +
|
||||
")";
|
||||
boolean b = recordSet.executeQuery(get_imagefileid_sql, requestId);
|
||||
logger.info("updateValue()----b是否执行"+b);
|
||||
recordSet.next();
|
||||
String tablename = recordSet.getString("tablename");
|
||||
boolean b1 = recordSet.executeUpdate("update " + tablename + " set dczt = 0,dcsj = ? where requestid = ?",getCurrentTime(), requestId);
|
||||
logger.info("updatevalue()----b1是否执行==="+b1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用来统计流程转文档的流程的数量,如果数量为0,返回文件为空,
|
||||
* 并将已经流程转流程并且导出pdf的流程字段更新相关流程的导出字段为已导出
|
||||
* @param split requestid组成的数组集合
|
||||
* @return int 返回一个整型数字用于判断
|
||||
*/
|
||||
public int getAmountWorkflowToDoc(String[] split){
|
||||
int amount = 0;
|
||||
String getWorkflowId_sql = "select workflowid from workflow_requestbase where requestid = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
for (String requestId : split) {
|
||||
boolean b = recordSet.executeQuery(getWorkflowId_sql, requestId);
|
||||
logger.info("getAmountWorkflowToDoc----b是否执行==="+b);
|
||||
if (recordSet.next()){
|
||||
int imageFileId = this.getImageFileId(requestId);
|
||||
if (imageFileId==-1){
|
||||
continue;
|
||||
}else {
|
||||
amount++;
|
||||
//用来更新更新具体哪个流程表单的导出状态为已导出
|
||||
this.updateValue(requestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据requestId返回docimagefile表中imagefileId
|
||||
* @param requestId requestid
|
||||
* @return int
|
||||
*/
|
||||
public int getImageFileId(String requestId){
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_imagefileid_sql = "select tablename \n" +
|
||||
"from workflow_bill \n" +
|
||||
"where id = (select formid from workflow_base where id = \n" +
|
||||
"(select workflowid from workflow_requestbase where requestid = ?)\n" +
|
||||
")";
|
||||
boolean b = recordSet.executeQuery(get_imagefileid_sql, requestId);
|
||||
logger.info("b是否执行"+b);
|
||||
recordSet.next();
|
||||
String tablename = recordSet.getString("tablename");
|
||||
String docid_key = this.getWfDocRelateFieldName(requestId);//每一流程表单中用来存放docid的字段名称
|
||||
|
||||
String get_docid_sql = "select "+docid_key+" from "+tablename+" where requestid = ?";
|
||||
boolean b1 = recordSet.executeQuery(get_docid_sql, requestId);
|
||||
logger.info("b1是否执行=="+b1);
|
||||
recordSet.next();
|
||||
String docid = recordSet.getString(docid_key);
|
||||
if (Util.null2String(docid).equals("")){
|
||||
return -1;
|
||||
}
|
||||
String get_imagefileid = "select imagefileid from DocImageFile where docid = ? order by versionId";
|
||||
boolean b2 = recordSet.executeQuery(get_imagefileid, docid);
|
||||
logger.info("b2是否执行=="+b2);
|
||||
recordSet.next();
|
||||
String imagefileid = recordSet.getString("imagefileid");
|
||||
return Integer.parseInt(imagefileid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据requestId返回docimagefile表中imagefilename
|
||||
* @param requestId requestid
|
||||
* @return String 返回imagefilename
|
||||
*/
|
||||
public String getImageFileName(String requestId){
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_tablename_sql = "select tablename \n" +
|
||||
"from workflow_bill \n" +
|
||||
"where id = (select formid from workflow_base where id = \n" +
|
||||
"(select workflowid from workflow_requestbase where requestid = ?)\n" +
|
||||
")";
|
||||
boolean b = recordSet.executeQuery(get_tablename_sql, requestId);
|
||||
logger.info("b是否执行"+b);
|
||||
recordSet.next();
|
||||
String tablename = recordSet.getString("tablename");
|
||||
String docid_key = this.getWfDocRelateFieldName(requestId);//每一流程表单中用来存放docid的字段名称
|
||||
|
||||
String get_docid_sql = "select "+docid_key+" from "+tablename+" where requestid = ?";
|
||||
boolean b1 = recordSet.executeQuery(get_docid_sql, requestId);
|
||||
logger.info("b1是否执行=="+b1);
|
||||
recordSet.next();
|
||||
String docid = recordSet.getString(docid_key);
|
||||
String get_imagefilename = "select imagefilename from DocImageFile where docid = ? order by versionId";
|
||||
boolean b2 = recordSet.executeQuery(get_imagefilename, docid);
|
||||
logger.info("b2是否执行=="+b2);
|
||||
recordSet.next();
|
||||
return recordSet.getString("imagefilename");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据requestId反查 文档关联到的表单字段
|
||||
* @param requestid requestid
|
||||
* @return String 返回filename
|
||||
*/
|
||||
public String getWfDocRelateFieldName(String requestid){
|
||||
String get_wfdocrelatefilename_sql = "select fieldname from workflow_billfield \n" +
|
||||
"where id =(select wfdocrelatefieldid from workflow_base \n" +
|
||||
"where id = (select workflowid from workflow_requestbase where requestid = ?))";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(get_wfdocrelatefilename_sql, requestid);
|
||||
recordSet.next();
|
||||
logger.info("getWfDocRelateFieldName---b是否执行=="+b);
|
||||
String fieldname = recordSet.getString("fieldname");
|
||||
return Util.null2String(fieldname);
|
||||
}
|
||||
/**
|
||||
* 添加压缩文件
|
||||
* @param is 文件输入流
|
||||
* @param zipOut zipOUtPutStream
|
||||
* @param fileName 文件名称
|
||||
*/
|
||||
private void addToZip(InputStream is, ZipOutputStream zipOut, String fileName) {
|
||||
try{
|
||||
ZipEntry entry = new ZipEntry(fileName);
|
||||
zipOut.putNextEntry(entry);
|
||||
int len;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((len = is.read(buffer)) > 0) {
|
||||
zipOut.write(buffer, 0, len);
|
||||
}
|
||||
zipOut.closeEntry();
|
||||
is.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取系统当前日期时间</h2>
|
||||
* @return String
|
||||
* @author hcy
|
||||
* 2023/4/4 17:31
|
||||
*/
|
||||
public String getCurrentTime() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
return now.format(formatter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,683 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin;
|
||||
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@Path("/hcy_xintiantongxin")
|
||||
public class ExportExcelAVPNApi {
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
*导出AVPN Excel表格
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("/ExportExcelAVPNApi")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response checkRequestInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
try {
|
||||
//查询到 uf_avpn_export AVPN导出表中的一条数据的ids
|
||||
String ids = request.getParameter("ids");
|
||||
RecordSet rs = new RecordSet();
|
||||
StreamingOutput output = null;
|
||||
|
||||
String sql_AVPN_db = "select * from uf_avpn_export where id = ?";
|
||||
rs.executeQuery(sql_AVPN_db, ids);
|
||||
|
||||
//创建一个工作簿
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
String[] dbFiled = new String[10];
|
||||
String mainId = "";
|
||||
|
||||
while (rs.next()) {
|
||||
//查询到uf_avpn_export表的id作为查询明细表的mainid
|
||||
mainId = rs.getString("id");
|
||||
String pd_nameId = rs.getString("pd_name");//uf_pd_base_inf 得到的pd_name是字段的id
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String getPd_nameByIdSql = "select pd_name from uf_pd_base_inf where id =?";
|
||||
boolean b1 = recordSet.executeQuery(getPd_nameByIdSql, pd_nameId);
|
||||
|
||||
logger.info("查询pd_namesql语句是否成功==" + b1);
|
||||
if (recordSet.next()) {
|
||||
String pd_name = recordSet.getString("pd_name");//查询到pd_name的值
|
||||
dbFiled[0] = pd_name;
|
||||
}
|
||||
String billing_model = rs.getString("billing_model");
|
||||
if (billing_model.equals("0")){
|
||||
billing_model = "Assignment Model Billing in China";
|
||||
}
|
||||
dbFiled[1] = billing_model;
|
||||
String customer_name = rs.getString("customer_name");
|
||||
dbFiled[2] = customer_name;
|
||||
String ecrm_opportunity = rs.getString("ecrm_opportunity");
|
||||
dbFiled[3] = ecrm_opportunity;
|
||||
String igloo = rs.getString("igloo");
|
||||
dbFiled[4] = igloo;
|
||||
String terms = rs.getString("terms");
|
||||
dbFiled[5] = terms;
|
||||
String att_lead_pricer = rs.getString("att_lead_pricer");
|
||||
dbFiled[6] = att_lead_pricer;
|
||||
String requestjustificationoptional = rs.getString("requestjustificationoptional");
|
||||
dbFiled[7] = requestjustificationoptional;
|
||||
String specialrequesttosstoptional = rs.getString("specialrequesttosstoptional");
|
||||
dbFiled[8] = specialrequesttosstoptional;
|
||||
String sst_contact = rs.getString("sst_contact");
|
||||
dbFiled[9] = sst_contact;
|
||||
}
|
||||
//表单字段
|
||||
String[] tableFiled = new String[]{"Service Type", "Billing Model", "Customer Name", "ECRM Opportunity#", "Igloo #", "Contract Term (in months)", "AT&T Lead Pricer", "Request Justification (optional)", "Special Request to SST (Optional)", "SST Contact"};
|
||||
//明细表字段
|
||||
String[] mergerDetailTableFiled = new String[]{"Site ID", "Description", "Bandwidth", "OTC in RMB", "MRC in RMB"};
|
||||
|
||||
//创建一个工作表sheet
|
||||
Sheet sheet = workbook.createSheet();
|
||||
workbook.setSheetName(0, "AVPN表单");
|
||||
sheet.autoSizeColumn(1, true);
|
||||
//写入数据 //写入1-11行第一列 第二列数据
|
||||
for (int rowNum = 1; rowNum < 11; rowNum++) {
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell0 = row.createCell(0);
|
||||
cell0.setCellStyle(this.setWordStyle(workbook, true));
|
||||
cell0.setCellValue(tableFiled[rowNum - 1]);
|
||||
Cell cell1 = row.createCell(1);
|
||||
cell1.setCellStyle(setWordStyle(workbook, true));
|
||||
cell1.setCellValue(dbFiled[rowNum - 1]);
|
||||
}
|
||||
Row row12 = sheet.createRow(12);//第13行
|
||||
Cell cell12_11 = row12.createCell(11);
|
||||
cell12_11.setCellStyle(setWordStyle(workbook, true));
|
||||
cell12_11.setCellValue("Default Assignment Model-Billing in China in RMB");
|
||||
Cell cell12_12 = row12.createCell(12);
|
||||
cell12_12.setCellStyle(setNolyBorderStyle(workbook));
|
||||
sheet.addMergedRegion(new CellRangeAddress(12, 12, 11, 12));
|
||||
|
||||
//设置14行到15行前5列内容
|
||||
Row row13 = sheet.createRow(13);
|
||||
Row row14 = sheet.createRow(14);
|
||||
for (int colNum = 0; colNum < 5; colNum++) {
|
||||
Cell cell = row13.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook, true));
|
||||
cell.setCellValue(mergerDetailTableFiled[colNum]);
|
||||
Cell cell1 = row14.createCell(colNum);
|
||||
cell1.setCellStyle(setWordStyle(workbook, true));
|
||||
cell1.setCellValue(mergerDetailTableFiled[colNum]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 14, colNum, colNum));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//设置14行第六列到第13列的内容
|
||||
String[] mergerDetailTableFiled02 = new String[]{"Discount Requested (%)", "Discount SST approved (%)", "Net Price to AT&T Customer", "Royalty to SST without Tax(contra-revenue)"};
|
||||
Cell cell13_5 = row13.createCell(5);
|
||||
cell13_5.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_5.setCellValue(mergerDetailTableFiled02[0]);
|
||||
Cell cell113_6 = row13.createCell(6);
|
||||
cell113_6.setCellStyle(setWordStyle(workbook, true));
|
||||
cell113_6.setCellValue(mergerDetailTableFiled02[0]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 5, 6));
|
||||
|
||||
|
||||
Cell cell13_7 = row13.createCell(7);
|
||||
cell13_7.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_7.setCellValue(mergerDetailTableFiled02[1]);
|
||||
Cell cell13_8 = row13.createCell(8);
|
||||
cell13_8.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_8.setCellValue(mergerDetailTableFiled02[1]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 7, 8));
|
||||
|
||||
Cell cell13_9 = row13.createCell(9);
|
||||
cell13_9.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_9.setCellValue(mergerDetailTableFiled02[2]);
|
||||
Cell cell13_10 = row13.createCell(10);
|
||||
cell13_10.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_10.setCellValue(mergerDetailTableFiled02[2]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 9, 10));
|
||||
|
||||
Cell cell13_11 = row13.createCell(11);
|
||||
cell13_11.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_11.setCellValue(mergerDetailTableFiled02[3]);
|
||||
Cell cell13_12 = row13.createCell(12);
|
||||
cell13_12.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_12.setCellValue(mergerDetailTableFiled02[3]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 11, 12));
|
||||
|
||||
|
||||
//设置15行第六列到第13列的内容
|
||||
String[] mergerDetailTableFiled03 = new String[]{"OTC", "MRC", "OTC", "MRC", "OTC in RMB", "MRC in RMB", "OTC in RMB", "MRC in RMB"};
|
||||
for (int colNum = 5; colNum < 13; colNum++) {
|
||||
Cell cell = row14.createCell(colNum);
|
||||
for (int num = 0; num < 8; num++) {
|
||||
cell.setCellStyle(setWordStyle(workbook, true));
|
||||
cell.setCellValue(mergerDetailTableFiled03[num]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<Map<String, String>> siteMap = new ArrayList<>();//用来存放site的类型和每个site的状态
|
||||
|
||||
String getSiteSql = "select site ,count(site) siteNum from uf_avpn_export_dt1 where mainId =? group by site ;";
|
||||
RecordSet rs02 = new RecordSet();
|
||||
boolean b = rs02.executeQuery(getSiteSql, mainId);
|
||||
logger.info("查询site,以及site的数量的sql语句===" + b);
|
||||
|
||||
while (rs02.next()) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
String site = rs02.getString("site");
|
||||
String siteNum = rs02.getString("siteNum");
|
||||
map.put(site, siteNum);
|
||||
siteMap.add(map);//将site的类型和每个site的类型的个数放到siteList数组中,用来循环遍历再放入单元格中
|
||||
}
|
||||
int firstCow = 15;//从第15行开始写入明细表,固定死
|
||||
int finalyCow = 0;
|
||||
|
||||
|
||||
Double sum9 = 0D;
|
||||
Double sum10 = 0D;
|
||||
Double sum11 = 0D;
|
||||
Double sum12 = 0D;
|
||||
for (Map<String, String> map : siteMap) {
|
||||
Set<String> siteKeySet = map.keySet();
|
||||
List<List<Object>> detailDateList = new ArrayList();
|
||||
int cowLength = 0;//每一个site类型的数据的长度
|
||||
for (String s1 : siteKeySet) {
|
||||
cowLength = Integer.parseInt(map.get(s1));//每一个site类型的数据的长度
|
||||
String getDetailDataSql = "select * from uf_avpn_export_dt1 where mainId =? and site = ?";
|
||||
rs02.executeQuery(getDetailDataSql, mainId, s1);
|
||||
while (rs02.next()) {
|
||||
String site = rs02.getString("site");//Site ID
|
||||
String itemId = rs02.getString("Item");//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
|
||||
String categoryId = rs02.getString("Category");//Bandwidth
|
||||
String getCategoryByIdSql = "select category from uf_pd_category_inf where id = ?";
|
||||
boolean b3 = recordSet1.executeQuery(getCategoryByIdSql, categoryId);
|
||||
logger.info("查询categorySql是否执行成功==" + b3);
|
||||
String category = "";
|
||||
if (recordSet1.next()) {
|
||||
category = recordSet1.getString("category");
|
||||
}
|
||||
String otc_price = rs02.getString("otc_price");//OTC in RMB
|
||||
String mrc_price = rs02.getString("mrc_price");//MRC in RMB
|
||||
String otcdiscountrequest = rs02.getString("otcdiscountrequest");//Discount Requested (%) OTC
|
||||
String mrcdiscountrequest = rs02.getString("mrcdiscountrequest");//Discount Requested (%) MRC
|
||||
String otcdiscountapproved = rs02.getString("otcdiscountapproved");//Discount SST approved (%) OTC
|
||||
String mrcdiscountapproved = rs02.getString("mrcdiscountapproved");//Discount SST approved (%)MRC
|
||||
String otc_tariff = rs02.getString("otc_tariff");//Net Price to AT&T Customer(OTC in RMB)
|
||||
String mrc_tariff = rs02.getString("mrc_tariff");//Net Price to AT&T Customer(MRC in RMB)
|
||||
String otc_scale = rs02.getString("otc_scale");//Royalty to SST without Tax (contra-revenue)(OTC in RMB)
|
||||
String mrc_scale = rs02.getString("mrc_scale");//Royalty to SST without Tax (contra-revenue)(MRC in RMB)
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
list.add(site);//list.add(site);
|
||||
list.add(item);
|
||||
list.add(category);
|
||||
list.add(otc_price);
|
||||
list.add(mrc_price);
|
||||
list.add(otcdiscountrequest);
|
||||
list.add(mrcdiscountrequest);
|
||||
list.add(otcdiscountapproved);
|
||||
list.add(mrcdiscountapproved);
|
||||
list.add(otc_tariff);
|
||||
list.add(mrc_tariff);
|
||||
list.add(otc_scale);
|
||||
list.add(mrc_scale);
|
||||
detailDateList.add(list);
|
||||
}
|
||||
}
|
||||
Double amount9 = 0D;//用来统计每一个site种类的 Grand-Total(RMB)
|
||||
Double amount10 = 0D;
|
||||
Double amount11 = 0D;
|
||||
Double amount12 = 0D;
|
||||
//得到list类型的数据、有得到每种site类型的数据长度
|
||||
//开始向excel中导入明细表中的数据
|
||||
int i = 0;//用它来增加detailDateList的下标
|
||||
for (int cowNum = firstCow; cowNum < firstCow + cowLength; cowNum++) {
|
||||
Row row = sheet.createRow(cowNum);
|
||||
for (int colNum = 0; colNum < 13; colNum++) {
|
||||
if (colNum == 9) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount9 = Double.valueOf(amount9) + value;
|
||||
sum9 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 10) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount10 = amount10 + value;
|
||||
sum10 += value;
|
||||
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
}
|
||||
} else if (colNum == 11) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount11 = amount11 + value;
|
||||
sum11 += value;
|
||||
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 12) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount12 = amount12 + value;
|
||||
sum12 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
|
||||
if (colNum == 5 || colNum == 6 || colNum == 7 || colNum == 8) {
|
||||
Cell cell = row.createCell(colNum);
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue( (int)(value*100) + "%");
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
else if (colNum == 0||colNum==1||colNum==2){
|
||||
Cell cell = row.createCell(colNum);
|
||||
String value = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (value!=""){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum == 3||colNum==4){
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
//合并单元格
|
||||
int lastCow = firstCow + cowLength;
|
||||
|
||||
if (cowLength > 1) {
|
||||
sheet.addMergedRegion(new CellRangeAddress(firstCow, lastCow - 1, 0, 0));
|
||||
}
|
||||
//开始写入Sub-Total(RMB)
|
||||
Row rowSubTotal = sheet.createRow(lastCow);
|
||||
for (int colNum = 8; colNum < 13; colNum++) {
|
||||
if (colNum == 8) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue("Sub-Total(RMB)");
|
||||
} else if (colNum == 9) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount9);
|
||||
} else if (colNum == 10) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount10);
|
||||
} else if (colNum == 11) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount11);
|
||||
} else if (colNum == 12) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount12);
|
||||
}
|
||||
}
|
||||
|
||||
firstCow = firstCow + cowLength + 1;
|
||||
finalyCow = firstCow;
|
||||
}//处理插入数据以及合并单元格
|
||||
//处理明细表最后一行的统计情况
|
||||
Row row_Grand_Total_RMB = sheet.createRow(finalyCow);
|
||||
for (int colNum = 8; colNum < 13; colNum++) {
|
||||
if (colNum == 8) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue("Grand-Total(RMB)");
|
||||
} else if (colNum == 9) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum9);
|
||||
} else if (colNum == 10) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum10);
|
||||
} else if (colNum == 11) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum11);
|
||||
} else if (colNum == 12) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum12);
|
||||
}
|
||||
}
|
||||
|
||||
//输入最下面的固定值
|
||||
String[] lastStringLeft = new String[]{
|
||||
"Notes:",
|
||||
"1.This is NOT AT&T Pricing Approval. Forward this SST quote to your Lead ICB Pricer to issue the official Rate Letter",
|
||||
"2.Access price must be quoted by SST, request SST as \"access provider\" in Igloo. Do NOT use quote from other access providers",
|
||||
"3.Discount is only applicable to the demand set listed below, any changes in bandwidth/design/billing model, need to re-submit to SST and AT&T Pricer for approval", "" +
|
||||
"4.Under in-country billing, AT&T must follow the discount% offered by SST. Do NOT deviate from the SST quoted discount.",
|
||||
"5.SST can support repeatable discount for the same solution design(port/CDR/CPE) of same contract term which was approved already. Local Loop part are non-repeatable.",
|
||||
"6.For ICB only - Royalty in columns L and M are contra-revenue,ICB to verify if BCRL captured these amount.",
|
||||
"7.Save this SST approved quote to eCRM (without release) for record.",
|
||||
"8.The quotation shall be exclusive of any applicable taxes and Customer shall pay all the taxes and charges relating to the payment if any. The VAT rate for CPE and related modules and license are 16%, the rest is 6%.",
|
||||
"9.Thank you for considering SST, this engagement may be subject to a credit check, we appreciate your cooperation and look forward to doing business in the near future."
|
||||
};
|
||||
int lastLineTag = finalyCow + 2;//固定值Note所在的行
|
||||
int k = 0;//用来增加lastStringLeft的下标
|
||||
for (int rowNum = lastLineTag; rowNum < lastLineTag + 10; rowNum++) {
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 11));
|
||||
cell.setCellStyle(setTotalStyle(workbook,"微软雅黑",true,false,HorizontalAlignment.LEFT, VerticalAlignment.CENTER,false));
|
||||
cell.setCellValue(lastStringLeft[k]);
|
||||
k++;
|
||||
}
|
||||
sheet.autoSizeColumn(0,true);
|
||||
sheet.setColumnWidth(0,sheet.getColumnWidth(0)*5/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 13; num++) {
|
||||
sheet.autoSizeColumn(num,true);
|
||||
sheet.setColumnWidth(num, (sheet.getColumnWidth(num)));
|
||||
}
|
||||
|
||||
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String("AVPN表单.xlsx".getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
}
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
/**
|
||||
* <h2>设置每个单元格样式:包含字体类型,字体是否加粗,是否包含边框,元素水平方向的位置,元素垂直方向的位置,是否设置元素的数据格式,</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/13 18:08
|
||||
*/
|
||||
public static CellStyle setTotalStyle(Workbook workbook,String type,boolean setBold,boolean setBorder,HorizontalAlignment horizontalDirection,VerticalAlignment verticalAlignmentDirection ,boolean setDataFormat){
|
||||
//new一个cellStyle用于设置每一个单元格样式
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName(type);
|
||||
//设置字体是否加粗
|
||||
font.setBold(setBold);
|
||||
//将字体样式渲染cellStyle对象中
|
||||
cellStyle.setFont(font);
|
||||
if (setBorder == true){
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
}
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(horizontalDirection);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(verticalAlignmentDirection);
|
||||
|
||||
//此处设置数据格式
|
||||
if(setDataFormat == true){
|
||||
DataFormat dataFormat = workbook.createDataFormat();
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
}
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只设置边框样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyBorderStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置单元格格式为数值型
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,581 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@Path("/hcy_xintiantongxin2")
|
||||
public class ExportExcelL3NSApi {
|
||||
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* 校验
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("/ExportExcelL3NSApi")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response checkRequestInfo(@Context HttpServletRequest request, @Context HttpServletResponse response){
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
try {
|
||||
|
||||
|
||||
//查询到 uf_L3NS_exportt AVPN导出表中的一条数据的ids
|
||||
String ids = request.getParameter("ids");
|
||||
RecordSet rs = new RecordSet();
|
||||
StreamingOutput output = null;
|
||||
|
||||
|
||||
String sql_L3NS_db = "select * from uf_L3NS_exportt where id = ?";
|
||||
boolean b = rs.executeQuery(sql_L3NS_db, ids);
|
||||
logger.info("是否查询uf_L3NS_exportt=="+b);
|
||||
|
||||
//创建一个工作簿
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
String[] dbFiled = new String[13];
|
||||
String[] tableFiled = new String[]{"Service Type", "Billing Model", "Customer Name", "ROME Opportunity #", "ROME WR#", "Request Type", "Original SST Order NO", "Request Justification", "Special Request to SST", "Target Service Provision date","ATT Order number:","SST Pre-Sales Contact","Date of SST Approval"};
|
||||
|
||||
String mainId = "";
|
||||
|
||||
//得到主表数据,用来写入excel中的固定值
|
||||
while (rs.next()) {
|
||||
//查询到uf_avpn_export表的id作为查询明细表的mainid
|
||||
mainId = rs.getString("id");
|
||||
|
||||
|
||||
String pd_nameId = rs.getString("pd_name");//uf_pd_base_inf 得到的pd_name是字段的id
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String getPd_nameByIdSql = "select pd_name from uf_pd_base_inf where id =?";
|
||||
boolean b1 = recordSet.executeQuery(getPd_nameByIdSql, pd_nameId);
|
||||
|
||||
logger.info("查询pd_namesql语句是否成功==" + b1);
|
||||
if (recordSet.next()) {
|
||||
String pd_name = recordSet.getString("pd_name");//查询到pd_name的值
|
||||
dbFiled[0] = pd_name;
|
||||
}
|
||||
String billingmodel = rs.getString("billingmodel");//Billing Model===billingmodel
|
||||
if (billingmodel.equals("0")){
|
||||
billingmodel = "Custom Subcontract";
|
||||
}else if (billingmodel == null){
|
||||
billingmodel = "";
|
||||
}
|
||||
dbFiled[1] = billingmodel;
|
||||
String customer_name = rs.getString("customer_name");//Customer Name===customer_name
|
||||
dbFiled[2] = customer_name;
|
||||
String rome_opportunity = rs.getString("rome_opportunity");//ROME Opportunity #====rome_opportunity
|
||||
dbFiled[3] = rome_opportunity;
|
||||
String rome_wr = rs.getString("rome_wr");//ROME WR#====rome_wr
|
||||
dbFiled[4] = rome_wr;
|
||||
String request_type = rs.getString("request_type");//Request Type====request_type
|
||||
dbFiled[5] = request_type;
|
||||
String original_sst_order_no = rs.getString("original_sst_order_no");//Original SST Order NO====original_sst_order_no
|
||||
dbFiled[6] = original_sst_order_no;
|
||||
String requestjustificationoptional = rs.getString("requestjustificationoptional");//Request Justification====requestjustificationoptional
|
||||
dbFiled[7] = requestjustificationoptional;
|
||||
String specialrequesttosstoptional = rs.getString("specialrequesttosstoptional");//Special Request to SST====specialrequesttosstoptional
|
||||
dbFiled[8] = specialrequesttosstoptional;
|
||||
String targetserviceprovisiondate = rs.getString("targetserviceprovisiondate");//Target Service Provision date====targetserviceprovisiondate
|
||||
dbFiled[9] = targetserviceprovisiondate;
|
||||
String attordernumber = rs.getString("attordernumber");//ATT Order number:====attordernumber
|
||||
dbFiled[10] = attordernumber;
|
||||
String sstpresalescontact = rs.getString("sstpresalescontact");//SST Pre-Sales Contact====sstpresalescontact
|
||||
dbFiled[11] = sstpresalescontact;
|
||||
String dateofsstapproval = rs.getString("dateofsstapproval");//Date of SST Approval====dateofsstapproval
|
||||
dbFiled[12] = dateofsstapproval;
|
||||
}
|
||||
|
||||
//开始写入固定值
|
||||
Sheet sheet = workbook.createSheet();
|
||||
workbook.setSheetName(0, "L3NS表单");
|
||||
sheet.autoSizeColumn(1, true);
|
||||
|
||||
for (int cowNum=1;cowNum<14;cowNum++){
|
||||
Row row = sheet.createRow(cowNum);
|
||||
Cell cell0 = row.createCell(0);
|
||||
cell0.setCellStyle(setWordStyle(workbook,true));
|
||||
cell0.setCellValue(tableFiled[cowNum-1]);
|
||||
Cell cell1 = row.createCell(1);
|
||||
cell1.setCellStyle(setWordStyle(workbook,true));
|
||||
cell1.setCellValue(dbFiled[cowNum-1]);
|
||||
}
|
||||
|
||||
Row row14 = sheet.createRow(14);//写入15行数据
|
||||
Cell cell14_0 = row14.createCell(0);
|
||||
Cell cell114_1 = row14.createCell(1);
|
||||
cell14_0.setCellStyle(setWordStyle(workbook,true));
|
||||
cell14_0.setCellValue("This Quote is valid for 180 days from \"Date of SST approval\"");
|
||||
cell114_1.setCellStyle(setWordStyle(workbook,true));
|
||||
cell114_1.setCellValue("This Quote is valid for 180 days from \"Date of SST approval\"");
|
||||
sheet.addMergedRegion(new CellRangeAddress(14, 14, 0, 1));
|
||||
|
||||
|
||||
// 写入18行,19行数据
|
||||
// Site ID Description Bandwidth OTC in RMB MRC in RMB
|
||||
String[] detailFileds = new String[]{"Site ID", "Description","Bandwidth", "OTC in RMB", "MRC in RMB"};
|
||||
Row row17 = sheet.createRow(17);
|
||||
Row row18 = sheet.createRow(18);
|
||||
for (int colNum =0;colNum<5;colNum++){
|
||||
Cell cell = row17.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellStyle(setWordStyle(workbook,true));
|
||||
cell.setCellValue(detailFileds[colNum]);
|
||||
}
|
||||
for (int colNum =0;colNum<5;colNum++){
|
||||
Cell cell = row18.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellStyle(setWordStyle(workbook,true));
|
||||
cell.setCellValue(detailFileds[colNum]);
|
||||
}
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 0, 0));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 1, 1));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 2, 2));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 3, 3));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 4, 4));
|
||||
|
||||
// Relief Requested (%) Relief SST approved (%) Tariff to SST (include VAT) 6-11列
|
||||
// OTC MRC OTC MRC OTC in RMB MRC in RMB
|
||||
String[] detailFileds01 = new String[]{"Relief Requested (%)","Relief Requested (%)","Relief SST approved (%)","Relief SST approved (%)","Tariff to SST (include VAT)","Tariff to SST (include VAT)",""};
|
||||
String[] detailFileds02 = new String[]{"OTC","MRC","OTC","MRC","OTC in RMB","MRC in RMB"};
|
||||
int i=0;
|
||||
int j = 0;
|
||||
for(int colNum=5;colNum<11;colNum++){
|
||||
Cell cell17 = row17.createCell(colNum);
|
||||
Cell cell18 = row18.createCell(colNum);
|
||||
cell17.setCellValue(detailFileds01[i]);
|
||||
cell17.setCellStyle(setWordStyle(workbook,true));
|
||||
// cell17.setCellStyle(setCellStyleFrame(workbook));
|
||||
|
||||
cell18.setCellValue(detailFileds02[j]);
|
||||
cell18.setCellStyle(setWordStyle(workbook,true));
|
||||
// cell18.setCellStyle(setCellStyleFrame(workbook));
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
//合并18行,19行
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 5, 6));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 7, 8));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 9, 10));
|
||||
|
||||
|
||||
//开始写入20开始一直往下的动态表格中的内容
|
||||
//
|
||||
|
||||
List<Map<String, String>> siteMap = new ArrayList<>();//用来存放site的类型和每个site的状态
|
||||
String getSiteSql = "select site ,count(site) siteNum from uf_L3NS_exportt_dt1 where mainId =? group by site ;";
|
||||
RecordSet rs02 = new RecordSet();
|
||||
boolean b1 = rs02.executeQuery(getSiteSql, mainId);
|
||||
logger.info("查询site,以及site的数量的sql语句===" + b1);
|
||||
while (rs02.next()) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
String site = rs02.getString("site");
|
||||
String siteNum = rs02.getString("siteNum");
|
||||
map.put(site, siteNum);
|
||||
siteMap.add(map);//将site的类型和每个site的类型的个数放到siteList数组中,用来循环遍历再放入单元格中
|
||||
}
|
||||
|
||||
int firstCow = 19;//从第15行开始写入明细表,固定死
|
||||
int finalyCow = 0;
|
||||
Double sum10 = 0D;//用来统计所有site种类的Grand-Total (RMB) #REF!
|
||||
Double sum9 = 0D;
|
||||
for (Map<String, String> map : siteMap) {
|
||||
|
||||
Set<String> siteKeySet = map.keySet();
|
||||
List<List<Object>> detailDateList = new ArrayList();
|
||||
int cowLength = 0;//每一个site类型的数据的长度
|
||||
for (String s1 : siteKeySet) {
|
||||
cowLength = Integer.parseInt(map.get(s1));//每一个site类型的数据的长度
|
||||
String getDetailDataSql = "select * from uf_L3NS_exportt_dt1 where mainId =? and site = ?";
|
||||
rs02.executeQuery(getDetailDataSql,mainId,s1);
|
||||
while(rs02.next()){
|
||||
//明细表数据
|
||||
String site = rs02.getString("site");//Site ID
|
||||
String itemId = rs02.getString("Item");//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";//uf_pd_item_inf
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
String categoryId = rs02.getString("Category");//Bandwidth
|
||||
String getCategoryByIdSql = "select category from uf_pd_category_inf where id = ?";//uf_pd_category_inf
|
||||
boolean b3 = recordSet1.executeQuery(getCategoryByIdSql, categoryId);
|
||||
logger.info("查询categorySql是否执行成功==" + b3);
|
||||
String category = "";
|
||||
if (recordSet1.next()) {
|
||||
category = recordSet1.getString("category");
|
||||
}
|
||||
String otc_price = rs02.getString("otc_price");//OTC in RMB
|
||||
String mrc_price = rs02.getString("mrc_price");//MRC in RMB
|
||||
String otc_relief_requested = rs02.getString("otc_relief_requested");//Relief Requested (%)OTC
|
||||
String mrc_relief_requested = rs02.getString("mrc_relief_requested");//Relief Requested (%)MRC
|
||||
String otc_relief_approved = rs02.getString("otc_relief_approved");//Relief SST approved (%)OTC
|
||||
String mrc_relief_approved = rs02.getString("mrc_relief_approved");//Relief SST approved (%)MRC
|
||||
String otc_tariff = rs02.getString("otc_tariff");//Tariff to SST (include VAT)(OTC in RMB)
|
||||
String mrc_tariff = rs02.getString("mrc_tariff");//Tariff to SST (include VAT)(MRC in RMB)
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
list.add(site);
|
||||
list.add(item);
|
||||
list.add(category);
|
||||
list.add(otc_price);
|
||||
list.add(mrc_price);
|
||||
list.add(otc_relief_requested);
|
||||
list.add(mrc_relief_requested);
|
||||
list.add(otc_relief_approved);
|
||||
list.add(mrc_relief_approved);
|
||||
list.add(otc_tariff);
|
||||
list.add(mrc_tariff);
|
||||
detailDateList.add(list);
|
||||
}
|
||||
}
|
||||
Double amount10 = 0D;//用来统计每一个site种类的 Sub-Total
|
||||
Double amount9 = 0D;
|
||||
|
||||
//得到list类型的数据、有得到每种site类型的数据长度
|
||||
//开始向excel中导入明细表中的数据
|
||||
int k = 0;//用它来增加detailDateList的下标
|
||||
for (int cowNum = firstCow; cowNum < firstCow + cowLength; cowNum++) {
|
||||
Row row = sheet.createRow(cowNum);
|
||||
for (int colNum = 0; colNum < 11; colNum++) {
|
||||
if (colNum == 10) {
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != ""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount10 = amount10 + value;
|
||||
sum10 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 9){
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != "") {
|
||||
Double value = Double.valueOf(s);
|
||||
amount9 = amount9 + value;
|
||||
sum9 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
if (colNum == 5 || colNum == 6 || colNum == 7 || colNum == 8) {
|
||||
Cell cell = row.createCell(colNum);
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value * 100) + "%");
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 3 || colNum==4){
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != ""){
|
||||
Double value = Double.valueOf(s);
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
else if (colNum == 0||colNum==1||colNum==2){
|
||||
Cell cell = row.createCell(colNum);
|
||||
String value = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (value!=""){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
k++;
|
||||
}
|
||||
//合并单元格
|
||||
int lastCow = firstCow + cowLength;
|
||||
|
||||
if (cowLength > 1) {
|
||||
sheet.addMergedRegion(new CellRangeAddress(firstCow, lastCow - 1, 0, 0));
|
||||
}
|
||||
//开始写入Sub-Total(RMB)
|
||||
Row rowSubTotal = sheet.createRow(lastCow);
|
||||
Cell cellSubToTal10 = rowSubTotal.createCell(10);
|
||||
cellSubToTal10.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal10.setCellValue(amount10);
|
||||
|
||||
Cell cellSubToTal9 = rowSubTotal.createCell(9);
|
||||
cellSubToTal9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal9.setCellValue(amount9);
|
||||
|
||||
Cell cellSubToTal8 = rowSubTotal.createCell(8);
|
||||
cellSubToTal8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal8.setCellValue("Sub-Total");
|
||||
|
||||
|
||||
firstCow = firstCow + cowLength + 1;
|
||||
finalyCow = firstCow;
|
||||
|
||||
}
|
||||
Row rowFinalyCow = sheet.createRow(finalyCow);
|
||||
Cell cellFinalyCow_10 = rowFinalyCow.createCell(10);
|
||||
cellFinalyCow_10.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_10.setCellValue(sum10);
|
||||
Cell cellFinalyCow_9 = rowFinalyCow.createCell(9);
|
||||
cellFinalyCow_9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_9.setCellValue(sum9);
|
||||
Cell cellFinalyCow_8 = rowFinalyCow.createCell(8);
|
||||
cellFinalyCow_8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_8.setCellValue("Grand-Total (RMB)");
|
||||
|
||||
|
||||
//输入最下面的固定值
|
||||
String[] lastStringright = new String[]{
|
||||
"Notes:",
|
||||
"1.This form should be submitted by Lead ICB via a ROME WR to \"AP Pricing Team\". Do NOT send this direct to SST.",
|
||||
"2.Fill in full Site Address or at least provide Name of City.",
|
||||
"3.Tariff relief requested should be calculated by lead ICB. Do not fill in target AVPN discount as \"Relief Requested\".",
|
||||
"4.VPN Tariff is port base pricing, no charges on COS or COS profile.",
|
||||
"5.AT&T GAM will place order to SST on no longer than 12 months term for Custom Subcontract, regardless of the commitment term between end customer and AT&T.",
|
||||
"6.China VAT is irrecoverable cost to AT&T under custom subcontracting billing. Ttariff and Access price listed below is VAT inclusive. ICB has to cater for this cost in deal financials.",
|
||||
"7.Tariff Relief is only applicable to the demand set listed below, any changes in bandwidth/design/billing model, need to re-submit to SST for approval;",
|
||||
};
|
||||
int lastLineTag = finalyCow + 2;//固定值Note所在的行
|
||||
int h=0;
|
||||
for (int rowNum=lastLineTag;rowNum<lastLineTag+8;rowNum++){
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 11));
|
||||
cell.setCellValue(lastStringright[h]);
|
||||
h++;
|
||||
}
|
||||
sheet.autoSizeColumn(0,true);
|
||||
sheet.setColumnWidth(0,sheet.getColumnWidth(0)*4/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 11; num++) {
|
||||
sheet.autoSizeColumn(num,true);
|
||||
sheet.setColumnWidth(num, (sheet.getColumnWidth(num)));
|
||||
}
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String("L3NS表单.xlsx".getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
} catch (IOException e) {
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyBorderStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单元格格式为数值型
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Path("/hcy_xintiantongxin4")
|
||||
public class CheckRequestInfo {
|
||||
|
||||
Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* 校验
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Path("/checkRequestInfo")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String checkRequestInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
|
||||
RecordSet recordSet = new RecordSet();
|
||||
|
||||
List<Map<String,String>> lists = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
String getCheckData = "select customername,currencyused,contractterminmonths,contractmodel from uf_other_export where id =?";
|
||||
boolean b = recordSet.executeQuery(getCheckData, s);
|
||||
logger.info("查询验证信息sql是否执行"+b);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (recordSet.next()){
|
||||
String customername = recordSet.getString("customername");//系统-客户名
|
||||
String currencyused = recordSet.getString("currencyused");
|
||||
String contractterminmonths = recordSet.getString("contractterminmonths");
|
||||
String contractmodel = recordSet.getString("contractmodel");
|
||||
map.put("customername",customername);
|
||||
map.put("currencyused",currencyused);
|
||||
map.put("contractterminmonths",contractterminmonths);
|
||||
map.put("contractmodel",contractmodel);
|
||||
lists.add(map);
|
||||
}
|
||||
}
|
||||
|
||||
String checkTag = "0";
|
||||
List<Map<String, String>> collect = lists.stream().distinct().collect(Collectors.toList());//用stream流处理相同数据,如果得到的是一条数据,那么证明满足客户条件
|
||||
if (collect.size() == 1){
|
||||
checkTag = "1";
|
||||
}else {
|
||||
checkTag = "0";
|
||||
}
|
||||
// Map<String, String> firstMap = lists.get(0);
|
||||
// String first_customername = firstMap.get("customername");
|
||||
// String first_currencyused = firstMap.get("currencyused");
|
||||
// String first_contractterminmonths = firstMap.get("contractterminmonths");
|
||||
// String first_contractmodel = firstMap.get("contractmodel");
|
||||
//
|
||||
// for (Map<String, String> list : lists) {
|
||||
// if (first_customername.equals(list.get("customername")) & first_currencyused.equals(list.get("currencyused")) & first_contractterminmonths.equals(list.get("contractterminmonths")) & first_contractmodel.equals(list.get("contractmodel")) ){
|
||||
// checkTag = "1";
|
||||
// }else {
|
||||
// checkTag = "0";
|
||||
// return ApiResult.success(checkTag);
|
||||
// }
|
||||
// }
|
||||
String getMsgSql = "select * from uf_cus_dev_config where only_mark = ?";
|
||||
recordSet.executeQuery(getMsgSql,"prompt_after_fail");
|
||||
recordSet.next();
|
||||
String msg = recordSet.getString("param_value");
|
||||
return ApiResult.success(checkTag,msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>mapper--sql映射类,用于查找数据库中的数据</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/9 13:26
|
||||
*/
|
||||
@SqlMapper
|
||||
public interface DemoMapper {
|
||||
|
||||
/**
|
||||
* <h2>根据前端返回的id内连接查询其他产品中主表和明细表中所有的数据</h2>
|
||||
* @param ids
|
||||
* @return List<Map<String,Object>>
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:25
|
||||
*/
|
||||
@Select("select * from \n" +
|
||||
"uf_other_export main \n" +
|
||||
"inner join uf_other_export_dt1 dt \n" +
|
||||
"on dt.mainid = main.id where main.id in (${ids})")
|
||||
List<Map<String,Object>> selectAll(@ParamMapper("ids") List<String> ids);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据前端返回的id内连接查询其他产品中主表和明细表中所有的数据</h2>
|
||||
* @param ids
|
||||
* @return List<Map<String,Object>>
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:25
|
||||
*/
|
||||
@Select("select * from \n" +
|
||||
"uf_other_export main \n" +
|
||||
"inner join uf_other_export_dt1 dt \n" +
|
||||
"on dt.mainid = main.id where main.id in (${ids})\n")
|
||||
List<Map<String,Object>> selectCMRData(@ParamMapper("ids") List<String> ids);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据人员id在hrmresource中查询到人员姓名</h2>
|
||||
* @param id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:23
|
||||
*/
|
||||
@Select("select lastname from hrmresource where id = #{id}")
|
||||
String selectLastName(@ParamMapper("id") String id);
|
||||
|
||||
/**
|
||||
* <h2>根据id向uf_pd_base表中查找pd_name</h2>
|
||||
* @param id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:22
|
||||
*/
|
||||
@Select("select pd_name from uf_pd_base_inf where id = #{id} ")
|
||||
public String getServiceTypeSql(@ParamMapper("id") String id);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>mapper--sql映射类,用于查找数据库中的数据</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/9 13:26
|
||||
*/
|
||||
@SqlMapper
|
||||
public interface DemoMapper_copy {
|
||||
|
||||
/**
|
||||
* <h2>根据前端返回的id内连接查询其他产品中主表和明细表中所有的数据</h2>
|
||||
* @param ids
|
||||
* @return List<Map<String,Object>>
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:25
|
||||
*/
|
||||
@Select("select main.id mainid,main.servicetype,main.contractterminmonths,\n" +
|
||||
"dt.*\n" +
|
||||
" from uf_other_export main\n" +
|
||||
"inner join uf_other_export_dt1 dt on dt.mainid = main.id\n" +
|
||||
"where main.id in (${ids})\n")
|
||||
List<Map<String,Object>> selectAll(@ParamMapper("ids") List<String> ids);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据前端返回的id内连接查询其他产品中主表和明细表中所有的数据</h2>
|
||||
* @param ids
|
||||
* @return List<Map<String,Object>>
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:25
|
||||
*/
|
||||
@Select("select main.id mainid,main.servicetype,main.contractterminmonths,main.channel_fee_per,main.channel_fee_type,\n" +
|
||||
"dt.*\n" +
|
||||
" from uf_other_export main\n" +
|
||||
"inner join uf_other_export_dt1 dt on dt.mainid = main.id\n" +
|
||||
"where main.id in (${ids})\n")
|
||||
List<Map<String,Object>> selectCMRData(@ParamMapper("ids") List<String> ids);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据人员id在hrmresource中查询到人员姓名</h2>
|
||||
* @param id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:23
|
||||
*/
|
||||
@Select("select lastname from hrmresource where id = #{id}")
|
||||
String selectLastName(@ParamMapper("id") String id);
|
||||
|
||||
/**
|
||||
* <h2>根据id向uf_pd_base表中查找pd_name</h2>
|
||||
* @param id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:22
|
||||
*/
|
||||
@Select("select pd_name from uf_pd_base_inf where id = #{id} ")
|
||||
public String getServiceTypeSql(@ParamMapper("id") String id);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Path("/hcy_xintiantongxin1")
|
||||
public class ExportExcelOtherApi {
|
||||
|
||||
Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
*获取其他产品uf_other_export表中的数据,渲染到sheet1---CMR中
|
||||
*/
|
||||
private SheetCMRPOI sheetCMRPOI = new SheetCMRPOI();
|
||||
/**
|
||||
* 获取其他产品uf_other_export表中的数据,渲染到sheet2---Quotation中
|
||||
*/
|
||||
private SheetQuotationPOI sheetQuotationPOI = new SheetQuotationPOI();
|
||||
/**
|
||||
* 获取其他产品uf_other_export表中的数据,渲染到sheet3---Cost中
|
||||
*/
|
||||
private SheetCostPOI sheetCostPOI = new SheetCostPOI();
|
||||
|
||||
|
||||
/**
|
||||
* <h2>将数据库中的数据放入sheet1---Quotation中</h2>
|
||||
* @param request,response
|
||||
* @return Response
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 14:21
|
||||
*/
|
||||
@GET
|
||||
@Path("/ExportExcelOtherApi")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response exportExcel(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
StreamingOutput output = null;
|
||||
String ids = request.getParameter("ids");
|
||||
String[] split = ids.split(",");
|
||||
|
||||
//创建一个工作簿
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
//创建一个工作表sheet
|
||||
|
||||
sheetCMRPOI.setSheetCMR(workbook,split);//创建第一个sheet1---sheet_CMR,并向sheet中渲染内容
|
||||
sheetQuotationPOI.setQuotationSheet(workbook,split);//创建第二个sheet2---sheet_Quotation,并向sheet中渲染内容
|
||||
sheetCostPOI.getSheetCost(workbook,split);//创建第三个sheet3---sheet_Cost,并向sheet中渲染内容
|
||||
try {
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String("其他产品表.xlsx".getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,419 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* <h1>poi设置单元格样式</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/9 14:34
|
||||
*/
|
||||
public class SetCellStylePOI {
|
||||
/**
|
||||
* <h2>设置每个单元格样式:包含字体类型,字体是否加粗,是否包含边框,元素水平方向的位置,元素垂直方向的位置,是否设置元素的数据格式,是否自动换行</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/13 18:08
|
||||
*/
|
||||
public static CellStyle setTotalStyle(Workbook workbook,String type,boolean setBold,boolean setBorder,HorizontalAlignment horizontalDirection,VerticalAlignment verticalAlignmentDirection ,boolean setDataFormat,boolean setWrapText){
|
||||
//new一个cellStyle用于设置每一个单元格样式
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName(type);
|
||||
//设置字体是否加粗
|
||||
font.setBold(setBold);
|
||||
//将字体样式渲染cellStyle对象中
|
||||
cellStyle.setFont(font);
|
||||
if (setBorder == true){
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
}
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(horizontalDirection);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(verticalAlignmentDirection);
|
||||
cellStyle.setWrapText(setWrapText);
|
||||
|
||||
//此处设置数据格式
|
||||
if(setDataFormat == true){
|
||||
DataFormat dataFormat = workbook.createDataFormat();
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
}
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>设置每个单元格样式:包含字体类型,字体是否加粗,是否包含边框,元素水平方向的位置,元素垂直方向的位置,是否设置元素的数据格式,</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/13 18:08
|
||||
*/
|
||||
public static CellStyle setTotalStyle(Workbook workbook,String type,boolean setBold,boolean setBorder,HorizontalAlignment horizontalDirection,VerticalAlignment verticalAlignmentDirection ,boolean setDataFormat){
|
||||
//new一个cellStyle用于设置每一个单元格样式
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName(type);
|
||||
//设置字体是否加粗
|
||||
font.setBold(setBold);
|
||||
//将字体样式渲染cellStyle对象中
|
||||
cellStyle.setFont(font);
|
||||
if (setBorder == true){
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
}
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(horizontalDirection);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(verticalAlignmentDirection);
|
||||
|
||||
//此处设置数据格式
|
||||
if(setDataFormat == true){
|
||||
DataFormat dataFormat = workbook.createDataFormat();
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
}
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* <h2>设置每个单元格的样式,并且加粗字体,设置边框,字体位置</h2>
|
||||
* @param workbook,setBold,
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/8 20:43
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold,boolean setLocation) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
if (setLocation == true) {
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>设置字体颜色和边框</h2>
|
||||
* @param workbook
|
||||
* @return CellStyle
|
||||
* @author hcy
|
||||
* @Date 2023/2/8 17:25
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>仅设置字体样式</h2>
|
||||
* @param workbook,setBold
|
||||
* @return CellStyle
|
||||
* @author hcy
|
||||
* @Date '2023/2/8' 17:50
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
/**
|
||||
* <h2>仅设置字体样式,并设置字体位置</h2>
|
||||
* @param workbook,setBold
|
||||
* @return CellStyle
|
||||
* @author hcy
|
||||
* @Date '2023/2/8' 17:50
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold,Boolean setLocation) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
if (setLocation == true) {
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
}
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只设置边框样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyBorderStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置单元格格式为数值型
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>设置字体颜色,是否加粗,设置单元格格式为数值型,设置字体居中</h2>
|
||||
* @param workbook,setBold,setLocation
|
||||
* @return CellStyle
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 13:39
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook,boolean setBold,boolean setLocation){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
if (setBold == true){
|
||||
font.setBold(setBold);
|
||||
}
|
||||
if (setLocation == true){
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>POI设置文字水平居中、垂直居中</h2>
|
||||
* @param workbook
|
||||
* @return CellStyle
|
||||
* @author hcy
|
||||
* @Date 2023/2/8 20:08
|
||||
*/
|
||||
public static CellStyle setCellLocations(Workbook workbook){
|
||||
CellStyle cellStyle = workbook.createCellStyle();//创建文本单元格样式
|
||||
//水平居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
return cellStyle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,437 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>获取其他产品uf_other_export表中的数据,渲染到sheet1---CMR中</h1>
|
||||
* hcy
|
||||
* 2023/2/9 15:40
|
||||
*/
|
||||
public class SheetCMRPOI extends SetCellStylePOI{
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>将数据库中的数据放入sheet1---CMR中</h2>
|
||||
* workbook,split
|
||||
* @author hcy
|
||||
2023/2/9 14:19
|
||||
*/
|
||||
public void setSheetCMR(Workbook workbook, String[] split){
|
||||
logger.info("SheetCMRPOI----开始执行");
|
||||
Sheet sheet_CMR = workbook.createSheet();
|
||||
workbook.setSheetName(0,"CMR");
|
||||
|
||||
// 将第一行数据放入CMR-sheet_0中
|
||||
Row row0 = sheet_CMR.createRow(0);
|
||||
sheet_CMR.autoSizeColumn(0);
|
||||
Cell cell0_0 = row0.createCell(0);
|
||||
cell0_0.setCellValue("CMR Analysis Form");
|
||||
cell0_0.setCellStyle(setNolyWordStyle(workbook,true,true));
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(0,0,0,7));
|
||||
// 将第二行数据放入CMR-sheet_0中
|
||||
Row row1 = sheet_CMR.createRow(1);
|
||||
sheet_CMR.autoSizeColumn(1);
|
||||
Cell cell1_0 = row1.createCell(0);
|
||||
cell1_0.setCellValue("General Information");
|
||||
cell1_0.setCellStyle(setWordStyle(workbook,true,false));
|
||||
Cell cell1_1 = row1.createCell(1);
|
||||
cell1_1.setCellValue("General Information");
|
||||
cell1_1.setCellStyle(setWordStyle(workbook,true,false));
|
||||
for (int colNum = 1;colNum<8;colNum++){
|
||||
Cell cell = row1.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(1,1,0,7));
|
||||
String[] value_row3_9 = new String[]
|
||||
{"Customer Name",
|
||||
"Sales Name",
|
||||
"Presales Name",
|
||||
"Service Delivery Date",
|
||||
"Contract Period (Months)",
|
||||
"Customer Requirements",
|
||||
"Service Description"};
|
||||
|
||||
// 从其他产品表单数据库表中导出主表中3-9行所需数据
|
||||
|
||||
String getValue3_9FromDB = "select * from uf_other_export where id = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(getValue3_9FromDB,split[0]);
|
||||
logger.info("b是否执行=="+b);
|
||||
List<String> value3_9FromDB = new ArrayList<>();
|
||||
String contractterminmonths = "";
|
||||
if (recordSet.next()){
|
||||
String customerName = recordSet.getString("customername");//Customer Name 系统-客户名
|
||||
value3_9FromDB.add(customerName);
|
||||
value3_9FromDB.add("");//Sales Name---手工(导出后填写) 这里设置为空
|
||||
String cjr = recordSet.getString("cjr");//Presales Name---报价单创建人
|
||||
DemoMapper getLastNameMapper = Util.getMapper(DemoMapper.class);
|
||||
String getCreaterName = getLastNameMapper.selectLastName(cjr);//根据id在hrmsource表中查到LastName 姓名
|
||||
value3_9FromDB.add(getCreaterName);
|
||||
value3_9FromDB.add("");//Service Delivery Date---手工(导出后填写)---这里设置为空
|
||||
contractterminmonths = recordSet.getString("contractterminmonths");//Contract Period (Months)---系统- Contract Term(in months)(contractterminmonths)
|
||||
value3_9FromDB.add(contractterminmonths);
|
||||
value3_9FromDB.add("");//Customer Requirements---手工(导出后填写) 这里设置为空
|
||||
value3_9FromDB.add("");////Service Description---手工(导出后填写) 这里设置为空
|
||||
}
|
||||
|
||||
for (int rowNum = 2;rowNum<9;rowNum++){
|
||||
Row row = sheet_CMR.createRow(rowNum);
|
||||
sheet_CMR.autoSizeColumn(rowNum);
|
||||
Cell cell0 = row.createCell(0);
|
||||
Cell cell1 = row.createCell(1);
|
||||
cell0.setCellValue(value_row3_9[rowNum-2]);//将3-9行第一列固定数据放入sheet0中
|
||||
cell0.setCellStyle(setWordStyle(workbook,true));
|
||||
cell1.setCellValue(value3_9FromDB.get(rowNum-2));//将3-9行第二列数据库中查到的数据放入sheet0中
|
||||
cell1.setCellStyle(setWordStyle(workbook,false));
|
||||
for (int colNum =2;colNum<8;colNum++){
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(rowNum,rowNum,1,7));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 开始写入11-12行固定值数据
|
||||
String[] valueRow11 = new String[]
|
||||
{"Revenue Information(RMB) VAT Exclusive",
|
||||
"",
|
||||
"Quotation",
|
||||
"Quotation",
|
||||
"COST",
|
||||
"COST",
|
||||
"Agent fee",
|
||||
"Agent fee"
|
||||
};
|
||||
String[] valueRow12 = new String[]
|
||||
{"Revenue Information(RMB) VAT Exclusive",
|
||||
"Revenue Information(RMB) VAT Exclusive",
|
||||
"One Time Charge",
|
||||
"Recurring Monthly Charge",
|
||||
"One Time Charge",
|
||||
"Recurring Monthly Charge",
|
||||
"One Time Charge",
|
||||
"Recurring Monthly Charge"
|
||||
};
|
||||
List<String> list11 = Arrays.asList(valueRow11);
|
||||
List<String> list12 = Arrays.asList(valueRow12);
|
||||
List<List<String>> list11_12 = new ArrayList<>();//new 一个list对象用于存放12-13行所有的元素
|
||||
list11_12.add(list11);
|
||||
list11_12.add(list12);
|
||||
|
||||
for (int rowNum = 10;rowNum<12;rowNum++){
|
||||
Row row = sheet_CMR.createRow(rowNum);
|
||||
sheet_CMR.autoSizeColumn(rowNum);
|
||||
List<String> list = list11_12.get(rowNum - 10);//将list11_12中数据放入list中
|
||||
for (int cowNum = 0;cowNum<8;cowNum++){
|
||||
Cell cell = row.createCell(cowNum);
|
||||
cell.setCellStyle(setWordStyle(workbook,true));
|
||||
cell.setCellValue(list.get(cowNum));//开始写入数据
|
||||
}
|
||||
}
|
||||
//开始合并12-13行数据
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(10,11,0,1));
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(10,10,2,3));
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(10,10,4,5));
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(10,10,6,7));
|
||||
|
||||
//开始处理14行及其14行一下的其他产品明细表中的数据
|
||||
List<String> splitList = Arrays.asList(split);
|
||||
DemoMapper mapper = Util.getMapper(DemoMapper.class);//获得mapper对象
|
||||
List<Map<String, Object>> dynamicData = mapper.selectCMRData(splitList);//13行及其13行一下的动态数据获取到dynamicData对象中
|
||||
logger.info("dynamicData==="+dynamicData);
|
||||
|
||||
Map<Object, List<Map<String, Object>>> newMap = dynamicData.stream()
|
||||
.collect(Collectors.groupingBy(map1 -> map1.get("servicetype")));
|
||||
List<Map<String, Object>> result = new ArrayList<>();//明细表中动态表格最终的数据来源
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> e : newMap.entrySet()) {
|
||||
Object key = e.getKey();
|
||||
List<Map<String, Object>> maps = e.getValue();
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
for (Map<String, Object> map1 : maps) {
|
||||
for (Map.Entry<String, Object> entry : map1.entrySet()) {
|
||||
String k = entry.getKey();
|
||||
Object v = entry.getValue();
|
||||
if ("priceexcludingtaxotc".equals(k) || "priceexcludingtaxmrc".equals(k) || k.equals("costexcludingtaxotc") || k.equals("costexcludingtaxmrc") ) {
|
||||
if ("".equals(Util.null2String(v))) {
|
||||
v = 0;
|
||||
}
|
||||
resultMap.merge(k, v, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}
|
||||
|
||||
if ("xxfylx".equals(k)){ //代理费用类型(xxfylx)== 0.项目百分比 1.固定金额 2.月租百分比
|
||||
String channeltype = Util.null2String(v);
|
||||
if ("0".equals(channeltype)){//项目百分比 = 0时 One Time Charge = agentfee
|
||||
Object agent_fee = map1.get("agentfee");//代理费用(不含税)
|
||||
String price = Util.null2String(agent_fee);
|
||||
logger.info("最后一次需求变更----price===="+price);
|
||||
// Object channelfeeper = map1.get("channelFeePer");
|
||||
// String percent = Util.null2String(channelfeeper);//代理费用占比
|
||||
double Agent_fee_One_Time_Charge;
|
||||
if (!"".equals(price)){
|
||||
Agent_fee_One_Time_Charge = Double.parseDouble(price);
|
||||
resultMap.merge("OneTimeCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}else{
|
||||
Agent_fee_One_Time_Charge = 0;
|
||||
resultMap.merge("OneTimeCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}
|
||||
}else if ("1".equals(channeltype)) {//固定金额
|
||||
Object agent_fee = map1.get("agentfee");
|
||||
String price = Util.null2String(agent_fee);
|
||||
logger.info("最后一次需求变更----price===="+price);
|
||||
double Agent_fee_One_Time_Charge;
|
||||
if (!"".equals(price)){
|
||||
Agent_fee_One_Time_Charge = Double.parseDouble(price);
|
||||
resultMap.merge("OneTimeCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}else{
|
||||
Agent_fee_One_Time_Charge = 0;
|
||||
resultMap.merge("OneTimeCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}
|
||||
}else if ("2".equals(channeltype)){//月租百分比
|
||||
// Object xxfyzb = map1.get("xxfyzb");//代理费用占比
|
||||
// String percent = Util.null2String(xxfyzb);
|
||||
Object agent_fee = map1.get("agentfee");
|
||||
String price = Util.null2String(agent_fee);
|
||||
logger.info("最后一次需求变更----price===="+price);
|
||||
int terms = Util.getIntValue(Util.null2String(map1.get("terms")));
|
||||
logger.info("最后一次需求变更----terms===="+terms);
|
||||
double Agent_fee_One_Time_Charge;
|
||||
if (!"".equals(price)){
|
||||
double priceDouble = Double.parseDouble(price);
|
||||
// double percentDouble = Double.parseDouble(percent);
|
||||
Agent_fee_One_Time_Charge = priceDouble / terms;
|
||||
logger.info("最后一次需求变更----Agent_fee_One_Time_Charge===="+Agent_fee_One_Time_Charge);
|
||||
resultMap.merge("RecurringMonthlyCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}else{
|
||||
Agent_fee_One_Time_Charge = 0;
|
||||
resultMap.merge("RecurringMonthlyCharge", Agent_fee_One_Time_Charge, (v1, v2) -> Double.parseDouble(Util.null2String(v1)) + Double.parseDouble(Util.null2String(v2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resultMap.put("servicetype", key);
|
||||
result.add(resultMap);
|
||||
}
|
||||
//-------新的业务逻辑---------
|
||||
int tag = 0;
|
||||
double totalColumn3 = 0;
|
||||
double totalColumn4 = 0;
|
||||
double totalColumn5 = 0;
|
||||
double totalColumn6 = 0;
|
||||
double totalColumn7 = 0;
|
||||
double totalColumn8 = 0;
|
||||
|
||||
for (int cowNum=12;cowNum < result.size()+12;cowNum++ ){
|
||||
Row row = sheet_CMR.createRow(cowNum);
|
||||
sheet_CMR.autoSizeColumn(cowNum);
|
||||
Map<String, Object> map = result.get(cowNum - 12);
|
||||
for (int colNum = 0;colNum < 8;colNum++){
|
||||
if (colNum==0){
|
||||
Cell cell = row.createCell(colNum);
|
||||
tag++;
|
||||
cell.setCellValue(tag);
|
||||
cell.setCellStyle(setWordStyle(workbook,false,true));
|
||||
}else if (colNum == 1){ //servicetype
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object servicetype = map.get("servicetype");
|
||||
String string = Util.null2String(servicetype);
|
||||
if (!"".equals(string) && (int)Double.parseDouble(string)!=-1) {
|
||||
DemoMapper getServicetyeMapper = Util.getMapper(DemoMapper.class);
|
||||
String serviceTypeSql = getServicetyeMapper.getServiceTypeSql(string);
|
||||
cell.setCellValue(serviceTypeSql);
|
||||
cell.setCellStyle(setWordStyle(workbook,false,true));
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum == 2) { //priceexcludingtaxotc
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object priceexcludingtaxotc = map.get("priceexcludingtaxotc");
|
||||
String string = Util.null2String(priceexcludingtaxotc);
|
||||
if (!"".equals(string)){
|
||||
if ((int)Double.parseDouble(string)!=-1){
|
||||
double stringToDouble = Double.parseDouble(string);
|
||||
totalColumn3 += stringToDouble;//统计第三列数据的和
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));//设置为数值型
|
||||
cell.setCellValue(stringToDouble);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else{
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum == 3) {//priceexcludingtaxmrc
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object priceexcludingtaxmrc = map.get("priceexcludingtaxmrc");
|
||||
String string = Util.null2String(priceexcludingtaxmrc);
|
||||
if (!"".equals(string)){
|
||||
if ((int)Double.parseDouble(string)!=-1){
|
||||
double stringToDouble = Double.parseDouble(string);
|
||||
totalColumn4 += stringToDouble;
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));//设置为数值型
|
||||
cell.setCellValue(stringToDouble);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 4) {//costexcludingtaxotc
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object costexcludingtaxotc = map.get("costexcludingtaxotc");
|
||||
String string = Util.null2String(costexcludingtaxotc);
|
||||
if (!"".equals(string)){
|
||||
if ((int)Double.parseDouble(string)!=-1){
|
||||
double stringToDouble = Double.parseDouble(string);
|
||||
totalColumn5 += stringToDouble;
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));//设置为数值型
|
||||
cell.setCellValue(stringToDouble);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 5) {//costexcludingtaxmrc
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object costexcludingtaxmrc = map.get("costexcludingtaxmrc");
|
||||
String string = Util.null2String(costexcludingtaxmrc);
|
||||
if (!"".equals(string)){
|
||||
if ((int)Double.parseDouble(string)!=-1){
|
||||
double stringToDouble = Double.parseDouble(string);
|
||||
totalColumn6 += stringToDouble;
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));//设置为数值型
|
||||
cell.setCellValue(stringToDouble);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 6) {//channel_fee_type channelfeetype channel_fee_per channelfeeper
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object oneTimeCharge = map.get("OneTimeCharge");
|
||||
String oneTimeChargeValue = Util.null2String(oneTimeCharge);
|
||||
if (!"".equals(oneTimeChargeValue)){
|
||||
double oneTimeChargeDouble = Double.parseDouble(oneTimeChargeValue);
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));
|
||||
cell.setCellValue(oneTimeChargeDouble);
|
||||
totalColumn7 += oneTimeChargeDouble;
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else{//channel_fee_per channelfeeper
|
||||
Cell cell = row.createCell(colNum);
|
||||
Object recurringMonthlyCharge = map.get("RecurringMonthlyCharge");
|
||||
String recurringMonthlyChargeValue = Util.null2String(recurringMonthlyCharge);
|
||||
if (!"".equals(recurringMonthlyChargeValue)){
|
||||
double recurringMonthlyChargeDouble= Double.parseDouble(recurringMonthlyChargeValue);
|
||||
cell.setCellStyle(setCellToNumber(workbook,false,true));
|
||||
cell.setCellValue(recurringMonthlyChargeDouble);
|
||||
totalColumn8 += recurringMonthlyChargeDouble;
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//开始写入Total一行,用来统计第三列到第八列明细表中数据的和
|
||||
int cowNumTotal = 12 + result.size();
|
||||
Row row_cowNumTotal = sheet_CMR.createRow(cowNumTotal);
|
||||
sheet_CMR.autoSizeColumn(cowNumTotal);
|
||||
Cell cell_cowNumTotal_0 = row_cowNumTotal.createCell(0);
|
||||
cell_cowNumTotal_0.setCellValue("Total");
|
||||
cell_cowNumTotal_0.setCellStyle(setWordStyle(workbook,true,true));
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(cowNumTotal,cowNumTotal,0,1));
|
||||
|
||||
//开始写入数据和具体数值 第三列到第八列
|
||||
Cell cell_cowNumTotal_2 = row_cowNumTotal.createCell(2);
|
||||
cell_cowNumTotal_2.setCellValue(totalColumn3);//写入第三列总和
|
||||
cell_cowNumTotal_2.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
Cell cell_cowNumTotal_3 = row_cowNumTotal.createCell(3);
|
||||
cell_cowNumTotal_3.setCellValue(totalColumn4);//写入第4列总和
|
||||
cell_cowNumTotal_3.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
Cell cell_cowNumTotal_4 = row_cowNumTotal.createCell(4);
|
||||
cell_cowNumTotal_4.setCellValue(totalColumn5);//写入第5列总和
|
||||
cell_cowNumTotal_4.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
Cell cell_cowNumTotal_5 = row_cowNumTotal.createCell(5);
|
||||
cell_cowNumTotal_5.setCellValue(totalColumn6);//写入第6列总和
|
||||
cell_cowNumTotal_5.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
Cell cell_cowNumTotal_6 = row_cowNumTotal.createCell(6);
|
||||
cell_cowNumTotal_6.setCellValue(totalColumn7);//写入第7列总和
|
||||
cell_cowNumTotal_6.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
Cell cell_cowNumTotal_7 = row_cowNumTotal.createCell(7);
|
||||
cell_cowNumTotal_7.setCellValue(totalColumn8);//写入第4列总和
|
||||
cell_cowNumTotal_7.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
|
||||
// 开始写入最后一行数据
|
||||
Row finalRow = sheet_CMR.createRow(cowNumTotal + 1);
|
||||
sheet_CMR.autoSizeColumn(cowNumTotal +1);
|
||||
Cell cell_final_0 = finalRow.createCell(0);
|
||||
cell_final_0.setCellValue("Contribution Margin");
|
||||
cell_final_0.setCellStyle(setWordStyle(workbook,true,true));
|
||||
Cell cell_final_1 = finalRow.createCell(1);
|
||||
cell_final_1.setCellValue("CMR(%)");
|
||||
cell_final_1.setCellStyle(setWordStyle(workbook,true,true));
|
||||
|
||||
//开始计算最后一行的公式:="【D20+E20*C8-F20-G20*C8-H20-I20*C8】/【D20+E20*C8】"
|
||||
double month =0;
|
||||
if (!contractterminmonths.equals("") ){
|
||||
month = Double.parseDouble(contractterminmonths);
|
||||
if ((int)month == -1){
|
||||
month = 0;
|
||||
}
|
||||
}
|
||||
// -36 / (120+120*12)
|
||||
double expressions = ( totalColumn3 + totalColumn4 * month - totalColumn5 - totalColumn6 * month - totalColumn7 - totalColumn8 * month) / ( totalColumn3 + totalColumn4 * month);
|
||||
Cell cell_final_2 = finalRow.createCell(2);
|
||||
|
||||
cell_final_2.setCellType(CellType.NUMERIC);
|
||||
cell_final_2.setCellValue(getPercentFormat(expressions,2,2));
|
||||
cell_final_2.setCellStyle(setWordStyle(workbook,true,true));
|
||||
for (int colNmu = 3 ;colNmu < 8 ;colNmu++){
|
||||
Cell cell = finalRow.createCell(colNmu);
|
||||
cell.setCellStyle(setCellToNumber(workbook,true,true));
|
||||
}
|
||||
sheet_CMR.addMergedRegion(new CellRangeAddress(cowNumTotal+1,cowNumTotal+1,2,7));
|
||||
|
||||
sheet_CMR.setColumnWidth(10,sheet_CMR.getColumnWidth(10)*17/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 0; num < 8; num++) {
|
||||
sheet_CMR.autoSizeColumn(num);
|
||||
sheet_CMR.setColumnWidth(num, (sheet_CMR.getColumnWidth(num)));
|
||||
}
|
||||
sheet_CMR.setColumnWidth(1, 20*256);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Double转化成百分数</h2>
|
||||
* @param d 要转换的内容
|
||||
* @param IntegerDigits 整数部分
|
||||
* @param FractionDigits 小数部分
|
||||
* @return String
|
||||
* @author hcy
|
||||
2023/2/21 17:50
|
||||
*/
|
||||
public static String getPercentFormat(double d,int IntegerDigits,int FractionDigits) {
|
||||
NumberFormat nf = NumberFormat.getPercentInstance();
|
||||
nf.setMaximumIntegerDigits(IntegerDigits);//小数点前保留几位
|
||||
nf.setMinimumFractionDigits(FractionDigits);// 小数点后保留几位
|
||||
return nf.format(d);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,452 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>获取其他产品uf_other_export表中的数据,渲染到sheet3---Cost中</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/9 14:27
|
||||
*/
|
||||
public class SheetCostPOI extends SetCellStylePOI{
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h2>将数据库中的数据渲染到sheet3---Cost中</h2>
|
||||
* @param workbook:poi workbook对象用来操作excel表, split:前端传来的数据的id组成的数组
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 14:35
|
||||
*/
|
||||
public void getSheetCost(Workbook workbook,String[] split){
|
||||
try {
|
||||
Sheet sheet_Cost = workbook.createSheet();
|
||||
workbook.setSheetName(2,"Cost");
|
||||
|
||||
String[] tableFiled = new String[]{"Customer Name", "Service Provider", "Contract Term(in months)", "Currency Used", "Issueing Date", "Expiration Date"};
|
||||
List<String> systemFiled = new ArrayList<>();
|
||||
String sql_other_export_db = "select * from uf_other_export where id = ?";
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(sql_other_export_db,split[0]);
|
||||
while (rs.next()){
|
||||
String customername = rs.getString("customername");
|
||||
systemFiled.add(customername);//Customer Name
|
||||
systemFiled.add("SST");//Service Provider
|
||||
systemFiled.add(rs.getString("contractterminmonths"));//Contract Term(in months)
|
||||
systemFiled.add("RMB");//Currency Used
|
||||
//系统当前时间
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
systemFiled.add(formatter.format(date));//Issueing Date
|
||||
//系统当前时间再往后推30天
|
||||
Calendar currentdate = Calendar.getInstance();
|
||||
//在这里进行加30天(ps:周六周日也算在里边了)
|
||||
currentdate.add(Calendar.DATE, 30);
|
||||
//得到最后的时间
|
||||
Date finalday = currentdate.getTime();
|
||||
|
||||
systemFiled.add(formatter.format(finalday));//Expiration Date
|
||||
}
|
||||
//将1-6行固定值数据放入excel中
|
||||
for (int cowNum = 0; cowNum < 6; cowNum++) {
|
||||
Row row = sheet_Cost.createRow(cowNum);
|
||||
Cell cell0col = row.createCell(0);
|
||||
Cell cell1col = row.createCell(1);
|
||||
cell0col.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell0col.setCellValue(tableFiled[cowNum]);
|
||||
cell1col.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell1col.setCellValue(systemFiled.get(cowNum));
|
||||
}
|
||||
//将8行数据放入excel中
|
||||
//Quotation Breakdown:
|
||||
Row row7 = sheet_Cost.createRow(7);
|
||||
Cell cell7_0 = row7.createCell(0);
|
||||
cell7_0.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell7_0.setCellValue("Quotation Breakdown:");
|
||||
Cell cell7_1 = row7.createCell(1);
|
||||
cell7_1.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell7_1.setCellValue("Quotation Breakdown:");
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(7,7,0,1));
|
||||
|
||||
//将第九行第十行前四列放入excel中并合并单元格
|
||||
//1Service Type 2.Site 3.Item 4.Service Description
|
||||
String[] string8_4 = new String[]{"Service Type","Site","Item","Service Description"};
|
||||
Row row8 = sheet_Cost.createRow(8);
|
||||
Row row9 = sheet_Cost.createRow(9);
|
||||
for (int colNum = 0;colNum<4;colNum++){
|
||||
Cell cell8 = row8.createCell(colNum);
|
||||
cell8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8.setCellValue(string8_4[colNum]);
|
||||
Cell cell9 = row9.createCell(colNum);
|
||||
cell9.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9.setCellValue("");
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(8,9,colNum,colNum));
|
||||
}
|
||||
//Price Plus tax VAT rate % Price Excluding tax
|
||||
//第九行三个字段并合并字段 5-10列
|
||||
Cell cell8_4 = row8.createCell(4);
|
||||
cell8_4.setCellValue("Cost Plus tax");
|
||||
cell8_4.setCellStyle(setWordStyle(workbook,true));
|
||||
Cell cell8_5 = row8.createCell(5);
|
||||
cell8_5.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(8,8,4,5));
|
||||
Cell cell8_6 = row8.createCell(6);
|
||||
cell8_6.setCellValue("VAT rate %");
|
||||
cell8_6.setCellStyle(setWordStyle(workbook,true));
|
||||
Cell cell8_7 = row8.createCell(7);
|
||||
cell8_7.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Cost.addMergedRegionUnsafe(new CellRangeAddress(8,8,6,7));
|
||||
Cell cell8_8 = row8.createCell(8);
|
||||
cell8_8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8_8.setCellValue("Cost Excluding tax");
|
||||
Cell cell8_9 = row8.createCell(9);
|
||||
cell8_9.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Cost.addMergedRegionUnsafe(new CellRangeAddress(8,8,8,9));
|
||||
|
||||
//OTC MRC OTC MRC OTC MRC
|
||||
//写入10行第5列到第10列的内容
|
||||
Cell cell9_4 = row9.createCell(4);
|
||||
cell9_4.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_4.setCellValue("OTC");
|
||||
Cell cell9_5 = row9.createCell(5);
|
||||
cell9_5.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_5.setCellValue("MRC");
|
||||
Cell cell9_6 = row9.createCell(6);
|
||||
cell9_6.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_6.setCellValue("OTC");
|
||||
Cell cell9_7 = row9.createCell(7);
|
||||
cell9_7.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_7.setCellValue("MRC");
|
||||
Cell cell9_8 = row9.createCell(8);
|
||||
cell9_8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_8.setCellValue("OTC");
|
||||
Cell cell9_9 = row9.createCell(9);
|
||||
cell9_9.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_9.setCellValue("MRC");
|
||||
//写入remark 9行11列 并合并9行10行
|
||||
Cell cell8_10 = row8.createCell(10);
|
||||
cell8_10.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8_10.setCellValue("Remark");
|
||||
Cell cell9_10 = row9.createCell(10);
|
||||
cell9_10.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_10.setCellValue("");
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(8,9,10,10));
|
||||
|
||||
//开始写入动态表格中的内容
|
||||
DemoMapper mapper = Util.getMapper(DemoMapper.class);
|
||||
List<String> idList = Arrays.asList(split);
|
||||
|
||||
List<Map<String, Object>> maps = mapper.selectAll(idList);
|
||||
Map<Object, List<Map<String, Object>>> servicetype = maps.stream()
|
||||
.collect(Collectors.groupingBy(item -> item.get("servicetype")));//servicetype的种类,以及每个种类的数量
|
||||
// System.out.println("servicetype===="+JSON.toJSONString(servicetype));
|
||||
// servicetype.forEach((key,value)->{
|
||||
// System.out.println(key + " : " + value.size());
|
||||
// });
|
||||
Map<Object, Map<Object, List<Map<String, Object>>>> result = new HashMap<>();
|
||||
servicetype.forEach((key,value)->{
|
||||
Map<Object, List<Map<String, Object>>> site = value.stream().collect(Collectors.groupingBy(item -> item.get("site")));
|
||||
result.put(key,site);
|
||||
});
|
||||
|
||||
|
||||
List<Map<String,Object>> list = new ArrayList<>();
|
||||
System.out.println("result===="+ JSON.toJSONString(result));
|
||||
result.forEach((key,value)->{
|
||||
AtomicInteger serviceSize = new AtomicInteger();
|
||||
value.forEach((itemKey,itemValue)->{
|
||||
serviceSize.addAndGet(itemValue.size());
|
||||
list.addAll(itemValue);
|
||||
});
|
||||
// System.out.println(key + " : " + serviceSize.get());
|
||||
// value.forEach((itemKey,itemValue)->{
|
||||
// System.out.println("\t\t" + itemKey + " : " + itemValue.size());
|
||||
// });
|
||||
});
|
||||
// System.out.println(JSON.toJSONString(list));
|
||||
|
||||
|
||||
//从第11行开始插入明细表中的数据
|
||||
int fisrtCowCol_0 = 10;
|
||||
int lastCowCol_1;
|
||||
double sum4 = 0d;
|
||||
double sum5 = 0d;
|
||||
double sum8 = 0d;
|
||||
double sum9 = 0d;
|
||||
|
||||
int i = 0;
|
||||
for (int cowNum=10;cowNum<10+ list.size();cowNum++){
|
||||
Row row = sheet_Cost.createRow(cowNum);
|
||||
Map<String, Object> map = list.get(i);
|
||||
for (int colNum=0;colNum<11;colNum++){
|
||||
Cell cell = row.createCell(colNum);
|
||||
if (colNum==0){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
String servicetypeId = String.valueOf(map.get("servicetype"));
|
||||
String getServiceTypeSql = "select pd_name from uf_pd_base_inf where id = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(getServiceTypeSql, servicetypeId);
|
||||
logger.info("查询serviceType在数据库中的值的sql语句是否查询成功=="+b);
|
||||
if (recordSet.next()){
|
||||
String pd_name = recordSet.getString("pd_name");
|
||||
cell.setCellValue(pd_name);
|
||||
}
|
||||
}else if (colNum==1){
|
||||
String value = String.valueOf(map.get("site"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(String.valueOf(map.get("site")));
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum ==2){
|
||||
String itemId = String.valueOf(map.get("item"));//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";//uf_pd_item_inf
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
if (!itemId.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(item);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 3){
|
||||
String value = String.valueOf(map.get("servicedescription"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
// String valueHtml = stringEscapeUtils.escapeHtml(value);//此处完成国际特殊字符转译
|
||||
String newValue = value.replace(" ", " ");
|
||||
cell.setCellValue(newValue);
|
||||
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum== 4){
|
||||
try {
|
||||
String value = String.valueOf(map.get("costplustaxotc"));//costplustaxotc
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1){
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum4 += newValue;
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
}else{
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else if (colNum==5){
|
||||
String value = String.valueOf(map.get("costplustaxmrc"));//costplustaxmrc
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1){
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum5 += newValue;
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
}else{
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum ==6){
|
||||
String vatrateotc = String.valueOf(map.get("vatrateotc"));//vatrateotc
|
||||
double value;
|
||||
if (!vatrateotc.equals("")){
|
||||
if ((int)Double.parseDouble(vatrateotc)!=-1) {
|
||||
value = Double.parseDouble(vatrateotc);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value*100)+"%");
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum==7){
|
||||
String vatratemrc = String.valueOf(map.get("vatratemrc"));//vatratemrc
|
||||
double value;
|
||||
if (!vatratemrc.equals("")){
|
||||
if ((int)Double.parseDouble(vatratemrc)!=-1) {
|
||||
value = Double.parseDouble(vatratemrc);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value*100)+"%");
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 8){
|
||||
|
||||
String value = String.valueOf(map.get("costexcludingtaxotc"));//costexcludingtaxotc
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1) {
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum8 += newValue;
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum ==9){
|
||||
String value = String.valueOf(map.get("costexcludingtaxmrc"));//costexcludingtaxmrc
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1) {
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum9 += newValue;
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else{
|
||||
String value = String.valueOf(map.get("remark"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//合并第一列单元格
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> entry : servicetype.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
List<Map<String, Object>> value = entry.getValue();
|
||||
System.out.println(key + " : " + value.size());
|
||||
int size = value.size();
|
||||
lastCowCol_1 = fisrtCowCol_0 + size;
|
||||
if (size>1){
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(fisrtCowCol_0, lastCowCol_1-1, 0, 0));
|
||||
}
|
||||
fisrtCowCol_0 = lastCowCol_1;
|
||||
}
|
||||
|
||||
//合并明细表里面第二列单元格
|
||||
|
||||
int firstRowCol_1 = 10;
|
||||
int lastRowCol_1;
|
||||
for (Map.Entry<Object, Map<Object, List<Map<String, Object>>>> entry : result.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
Map<Object, List<Map<String, Object>>> value = entry.getValue();
|
||||
AtomicInteger serviceSize = new AtomicInteger();
|
||||
value.forEach((itemKey, itemValue) -> {
|
||||
serviceSize.addAndGet(itemValue.size());
|
||||
list.addAll(itemValue);
|
||||
});
|
||||
System.out.println(key + " : " + serviceSize.get());
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> e : value.entrySet()) {
|
||||
Object itemKey = e.getKey();
|
||||
List<Map<String, Object>> itemValue = e.getValue();
|
||||
System.out.println("\t\t" + itemKey + " : " + itemValue.size());
|
||||
int size = itemValue.size();
|
||||
lastRowCol_1 = size + firstRowCol_1;
|
||||
if (size>1){
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(firstRowCol_1, lastRowCol_1-1, 1, 1));
|
||||
}
|
||||
firstRowCol_1 = lastRowCol_1;
|
||||
}
|
||||
}
|
||||
|
||||
//写入统计第四列内容 Grand Total
|
||||
Row row = sheet_Cost.createRow(fisrtCowCol_0);
|
||||
Cell cellGrandToTal_3 = row.createCell(3);
|
||||
cellGrandToTal_3.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_3.setCellValue("Grand Total");
|
||||
|
||||
Cell cellGrandToTal_4 = row.createCell(4);
|
||||
Cell cellGrandToTal_5 = row.createCell(5);
|
||||
Cell cellGrandToTal_8 = row.createCell(8);
|
||||
Cell cellGrandToTal_9 = row.createCell(9);
|
||||
|
||||
cellGrandToTal_4.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_5.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_4.setCellValue(sum4);
|
||||
cellGrandToTal_5.setCellValue(sum5);
|
||||
cellGrandToTal_8.setCellValue(sum8);
|
||||
cellGrandToTal_9.setCellValue(sum9);
|
||||
|
||||
|
||||
String[] finalyString = new String[]{
|
||||
"Note:",
|
||||
"1.This price is for budgetary use only and subject to SST's final confirmation;",
|
||||
"2.OTC stands for one time charge and MRC stands for monthly recurring charge.",
|
||||
"3. The price is exclusive of any in-house wiring charge which may be needed in customer's building.",
|
||||
"4. In case the resources of the local telecom operator at the customer premises can not meet the requirement of the Service in such spot, customer will assume the additional engineering cost.",
|
||||
"5.A PSTN line should be provided by the customer at each location for out-of-band access to the managed CPE;",
|
||||
"6.Managed CPE contains router installation, configuring, on-going MA (subject to the actual site addresses) and helpdesk support;",
|
||||
"7. There is no SLA for the performance of Internet access;",
|
||||
"8. The early termination penalty is 100% of the monthly charges of remaining contract period.",
|
||||
"9. Customer acknowledges and agrees that SST is entitled to withdraw, revoke or terminate this quotation for convenience at any time upon written notice to Customer due to applicable policy " +
|
||||
"adjustment which is relevant to SST’s cost led by the authority or any other government agencies, such as tariff increase, even if Customer had received or confirmed this quotation. SST will reissue the quotation with updated OTC and MRC to Customer at its request.",
|
||||
};
|
||||
|
||||
int finalyCow = fisrtCowCol_0+2;
|
||||
int j=0;
|
||||
for (int cowNum = finalyCow;cowNum<finalyCow+10;cowNum++){
|
||||
Row row1 = sheet_Cost.createRow(cowNum);
|
||||
if (cowNum == (finalyCow+9)) {
|
||||
row1.setHeight((short)(20*46));
|
||||
}
|
||||
sheet_Cost.addMergedRegion(new CellRangeAddress(cowNum, cowNum, 0, 10));
|
||||
Cell cell = row1.createCell(0);
|
||||
cell.setCellStyle(setTotalStyle(workbook,"微软雅黑",true,false,HorizontalAlignment.LEFT, VerticalAlignment.CENTER,false,true));
|
||||
cell.setCellValue(finalyString[j]);
|
||||
j++;
|
||||
}
|
||||
//设置第一列列宽
|
||||
sheet_Cost.autoSizeColumn(0,true);
|
||||
sheet_Cost.setColumnWidth(0,sheet_Cost.getColumnWidth(0)*6/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 11; num++) {
|
||||
sheet_Cost.autoSizeColumn(num,true);
|
||||
sheet_Cost.setColumnWidth(num,sheet_Cost.getColumnWidth(num)*17/10);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("报错信息==="+e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,450 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>获取其他产品uf_other_export表中的数据,渲染到sheet2---Quotation中</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/9 15:49
|
||||
*/
|
||||
public class SheetQuotationPOI extends SetCellStylePOI{
|
||||
|
||||
Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
/**
|
||||
* <h2>将数据库中的数据放入sheet2---Quotation中</h2>
|
||||
* @param workbook,split
|
||||
* @return void
|
||||
* @author hcy
|
||||
* @Date 2023/2/9 15:50
|
||||
*/
|
||||
public void setQuotationSheet(Workbook workbook, String[] split){
|
||||
|
||||
try {
|
||||
Sheet sheet_Quotation = workbook.createSheet();
|
||||
workbook.setSheetName(1,"Quotation");
|
||||
|
||||
|
||||
String[] tableFiled = new String[]{"Customer Name", "Service Provider", "Contract Term(in months)", "Currency Used", "Issueing Date", "Expiration Date"};
|
||||
List<String> systemFiled = new ArrayList<>();
|
||||
String sql_other_export_db = "select * from uf_other_export where id = ?";
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(sql_other_export_db,split[0]);
|
||||
while (rs.next()){
|
||||
String customername = rs.getString("customername");
|
||||
systemFiled.add(customername);//Customer Name
|
||||
systemFiled.add("SST");//Service Provider
|
||||
systemFiled.add(rs.getString("contractterminmonths"));//Contract Term(in months)
|
||||
systemFiled.add("RMB");//Currency Used
|
||||
//系统当前时间
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
systemFiled.add(formatter.format(date));//Issueing Date
|
||||
//系统当前时间再往后推30天
|
||||
Calendar currentdate = Calendar.getInstance();
|
||||
//在这里进行加30天(ps:周六周日也算在里边了)
|
||||
currentdate.add(Calendar.DATE, 30);
|
||||
//得到最后的时间
|
||||
Date finalday = currentdate.getTime();
|
||||
systemFiled.add(formatter.format(finalday));//Expiration Date
|
||||
}
|
||||
//将1-6行固定值数据放入excel中
|
||||
for (int cowNum = 0; cowNum < 6; cowNum++) {
|
||||
Row row = sheet_Quotation.createRow(cowNum);
|
||||
Cell cell0col = row.createCell(0);
|
||||
Cell cell1col = row.createCell(1);
|
||||
cell0col.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell0col.setCellValue(tableFiled[cowNum]);
|
||||
cell1col.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell1col.setCellValue(systemFiled.get(cowNum));
|
||||
}
|
||||
//将8行数据放入excel中
|
||||
//Quotation Breakdown:
|
||||
Row row7 = sheet_Quotation.createRow(7);
|
||||
Cell cell7_0 = row7.createCell(0);
|
||||
cell7_0.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell7_0.setCellValue("Quotation Breakdown:");
|
||||
Cell cell7_1 = row7.createCell(1);
|
||||
cell7_1.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell7_1.setCellValue("Quotation Breakdown:");
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(7,7,0,1));
|
||||
|
||||
//将第九行第十行前四列放入excel中并合并单元格
|
||||
//1Service Type 2.Site 3.Item 4.Service Description
|
||||
String[] string8_4 = new String[]{"Service Type","Site","Item","Service Description"};
|
||||
Row row8 = sheet_Quotation.createRow(8);
|
||||
Row row9 = sheet_Quotation.createRow(9);
|
||||
for (int colNum = 0;colNum<4;colNum++){
|
||||
Cell cell8 = row8.createCell(colNum);
|
||||
cell8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8.setCellValue(string8_4[colNum]);
|
||||
Cell cell9 = row9.createCell(colNum);
|
||||
cell9.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9.setCellValue("");
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(8,9,colNum,colNum));
|
||||
}
|
||||
//Price Plus tax VAT rate % Price Excluding tax
|
||||
//第九行三个字段并合并字段 5-10列
|
||||
Cell cell8_4 = row8.createCell(4);
|
||||
cell8_4.setCellValue("Price Plus tax");
|
||||
cell8_4.setCellStyle(setWordStyle(workbook,true));
|
||||
Cell cell8_5 = row8.createCell(5);
|
||||
cell8_5.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(8,8,4,5));
|
||||
Cell cell8_6 = row8.createCell(6);
|
||||
cell8_6.setCellValue("VAT rate %");
|
||||
cell8_6.setCellStyle(setWordStyle(workbook,true));
|
||||
Cell cell8_7 = row8.createCell(7);
|
||||
cell8_7.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Quotation.addMergedRegionUnsafe(new CellRangeAddress(8,8,6,7));
|
||||
Cell cell8_8 = row8.createCell(8);
|
||||
cell8_8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8_8.setCellValue("Price Excluding tax");
|
||||
Cell cell8_9 = row8.createCell(9);
|
||||
cell8_9.setCellStyle(setWordStyle(workbook,true));
|
||||
sheet_Quotation.addMergedRegionUnsafe(new CellRangeAddress(8,8,8,9));
|
||||
|
||||
//OTC MRC OTC MRC OTC MRC
|
||||
//写入10行第5列到第10列的内容
|
||||
Cell cell9_4 = row9.createCell(4);
|
||||
cell9_4.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_4.setCellValue("OTC");
|
||||
Cell cell9_5 = row9.createCell(5);
|
||||
cell9_5.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_5.setCellValue("MRC");
|
||||
Cell cell9_6 = row9.createCell(6);
|
||||
cell9_6.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_6.setCellValue("OTC");
|
||||
Cell cell9_7 = row9.createCell(7);
|
||||
cell9_7.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_7.setCellValue("MRC");
|
||||
Cell cell9_8 = row9.createCell(8);
|
||||
cell9_8.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_8.setCellValue("OTC");
|
||||
Cell cell9_9 = row9.createCell(9);
|
||||
cell9_9.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_9.setCellValue("MRC");
|
||||
//写入remark 9行11列 并合并9行10行
|
||||
Cell cell8_10 = row8.createCell(10);
|
||||
cell8_10.setCellStyle(setWordStyle(workbook,true));
|
||||
cell8_10.setCellValue("Remark");
|
||||
Cell cell9_10 = row9.createCell(10);
|
||||
cell9_10.setCellStyle(setWordStyle(workbook,true));
|
||||
cell9_10.setCellValue("");
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(8,9,10,10));
|
||||
|
||||
//开始写入动态表格中的内容
|
||||
DemoMapper mapper = Util.getMapper(DemoMapper.class);
|
||||
List<String> idList = Arrays.asList(split);
|
||||
|
||||
List<Map<String, Object>> maps = mapper.selectAll(idList);
|
||||
Map<Object, List<Map<String, Object>>> servicetype = maps.stream()
|
||||
.collect(Collectors.groupingBy(item -> item.get("servicetype")));//servicetype的种类,以及每个种类的数量
|
||||
// System.out.println("servicetype===="+JSON.toJSONString(servicetype));
|
||||
// servicetype.forEach((key,value)->{
|
||||
// System.out.println(key + " : " + value.size());
|
||||
// });
|
||||
Map<Object, Map<Object, List<Map<String, Object>>>> result = new HashMap<>();
|
||||
servicetype.forEach((key,value)->{
|
||||
Map<Object, List<Map<String, Object>>> site = value.stream().collect(Collectors.groupingBy(item -> item.get("site")));
|
||||
result.put(key,site);
|
||||
});
|
||||
|
||||
|
||||
List<Map<String,Object>> list = new ArrayList<>();
|
||||
System.out.println("result===="+ JSON.toJSONString(result));
|
||||
result.forEach((key,value)->{
|
||||
AtomicInteger serviceSize = new AtomicInteger();
|
||||
value.forEach((itemKey,itemValue)->{
|
||||
serviceSize.addAndGet(itemValue.size());
|
||||
list.addAll(itemValue);
|
||||
});
|
||||
// System.out.println(key + " : " + serviceSize.get());
|
||||
// value.forEach((itemKey,itemValue)->{
|
||||
// System.out.println("\t\t" + itemKey + " : " + itemValue.size());
|
||||
// });
|
||||
});
|
||||
// System.out.println(JSON.toJSONString(list));
|
||||
|
||||
|
||||
//从第11行开始插入明细表中的数据
|
||||
int fisrtCowCol_0 = 10;
|
||||
int lastCowCol_1;
|
||||
double sum4 = 0d;
|
||||
double sum5 = 0d;
|
||||
double sum8 = 0d;
|
||||
double sum9 = 0d;
|
||||
|
||||
int i = 0;
|
||||
for (int cowNum=10;cowNum<10+ list.size();cowNum++){
|
||||
Row row = sheet_Quotation.createRow(cowNum);
|
||||
Map<String, Object> map = list.get(i);
|
||||
for (int colNum=0;colNum<11;colNum++){
|
||||
Cell cell = row.createCell(colNum);
|
||||
if (colNum==0){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
String servicetypeId = String.valueOf(map.get("servicetype"));
|
||||
String getServiceTypeSql = "select pd_name from uf_pd_base_inf where id = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(getServiceTypeSql, servicetypeId);
|
||||
logger.info("查询serviceType在数据库中的值的sql语句是否查询成功=="+b);
|
||||
if (recordSet.next()){
|
||||
String pd_name = recordSet.getString("pd_name");
|
||||
cell.setCellValue(pd_name);
|
||||
}
|
||||
}else if (colNum==1){
|
||||
String value = String.valueOf(map.get("site"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(String.valueOf(map.get("site")));
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum ==2){
|
||||
String itemId = String.valueOf(map.get("item"));//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";//uf_pd_item_inf
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
if (!itemId.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(item);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 3){
|
||||
String value = String.valueOf(map.get("servicedescription"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
// String valueHtml = stringEscapeUtils.escapeHtml(value);//此处完成国际特殊字符转译
|
||||
String newValue = value.replace(" ", " ");
|
||||
cell.setCellValue(newValue);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum== 4){
|
||||
try {
|
||||
String value = String.valueOf(map.get("priceplustaxotc"));
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1){
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum4 += newValue;
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
}else{
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else if (colNum==5){
|
||||
String value = String.valueOf(map.get("priceplustaxmrc"));
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1){
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum5 += newValue;
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
}else{
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum ==6){
|
||||
String vatrateotc = String.valueOf(map.get("vatrateotc"));
|
||||
double value;
|
||||
if (!vatrateotc.equals("")){
|
||||
if ((int)Double.parseDouble(vatrateotc)!=-1) {
|
||||
value = Double.parseDouble(vatrateotc);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value*100)+"%");
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum==7){
|
||||
String vatratemrc = String.valueOf(map.get("vatratemrc"));
|
||||
double value;
|
||||
if (!vatratemrc.equals("")){
|
||||
if ((int)Double.parseDouble(vatratemrc)!=-1) {
|
||||
value = Double.parseDouble(vatratemrc);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value*100)+"%");
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 8){
|
||||
|
||||
String value = String.valueOf(map.get("priceexcludingtaxotc"));
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1) {
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum8 += newValue;
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum ==9){
|
||||
String value = String.valueOf(map.get("priceexcludingtaxmrc"));
|
||||
if (!value.equals("")){
|
||||
if ((int)Double.parseDouble(value)!=-1) {
|
||||
double newValue = Double.parseDouble(value);
|
||||
sum9 += newValue;
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(newValue);
|
||||
} else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else{
|
||||
String value = String.valueOf(map.get("remark"));
|
||||
if (!value.equals("")){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//合并第一列单元格
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> entry : servicetype.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
List<Map<String, Object>> value = entry.getValue();
|
||||
System.out.println(key + " : " + value.size());
|
||||
int size = value.size();
|
||||
lastCowCol_1 = fisrtCowCol_0 + size;
|
||||
if (size>1){
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(fisrtCowCol_0, lastCowCol_1-1, 0, 0));
|
||||
}
|
||||
fisrtCowCol_0 = lastCowCol_1;
|
||||
}
|
||||
|
||||
//合并明细表里面第二列单元格
|
||||
|
||||
int firstRowCol_1 = 10;
|
||||
int lastRowCol_1;
|
||||
for (Map.Entry<Object, Map<Object, List<Map<String, Object>>>> entry : result.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
Map<Object, List<Map<String, Object>>> value = entry.getValue();
|
||||
AtomicInteger serviceSize = new AtomicInteger();
|
||||
value.forEach((itemKey, itemValue) -> {
|
||||
serviceSize.addAndGet(itemValue.size());
|
||||
list.addAll(itemValue);
|
||||
});
|
||||
System.out.println(key + " : " + serviceSize.get());
|
||||
for (Map.Entry<Object, List<Map<String, Object>>> e : value.entrySet()) {
|
||||
Object itemKey = e.getKey();
|
||||
List<Map<String, Object>> itemValue = e.getValue();
|
||||
System.out.println("\t\t" + itemKey + " : " + itemValue.size());
|
||||
int size = itemValue.size();
|
||||
lastRowCol_1 = size + firstRowCol_1;
|
||||
if (size>1){
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(firstRowCol_1, lastRowCol_1-1, 1, 1));
|
||||
}
|
||||
firstRowCol_1 = lastRowCol_1;
|
||||
}
|
||||
}
|
||||
|
||||
//写入统计第四列内容 Grand Total
|
||||
Row row = sheet_Quotation.createRow(fisrtCowCol_0);
|
||||
Cell cellGrandToTal_3 = row.createCell(3);
|
||||
cellGrandToTal_3.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_3.setCellValue("Grand Total");
|
||||
|
||||
Cell cellGrandToTal_4 = row.createCell(4);
|
||||
Cell cellGrandToTal_5 = row.createCell(5);
|
||||
Cell cellGrandToTal_8 = row.createCell(8);
|
||||
Cell cellGrandToTal_9 = row.createCell(9);
|
||||
|
||||
cellGrandToTal_4.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_5.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellGrandToTal_4.setCellValue(sum4);
|
||||
cellGrandToTal_5.setCellValue(sum5);
|
||||
cellGrandToTal_8.setCellValue(sum8);
|
||||
cellGrandToTal_9.setCellValue(sum9);
|
||||
|
||||
|
||||
String[] finalyString = new String[]{
|
||||
"Note:",
|
||||
"1.This price is for budgetary use only and subject to SST's final confirmation;",
|
||||
"2.OTC stands for one time charge and MRC stands for monthly recurring charge.",
|
||||
"3. The price is exclusive of any in-house wiring charge which may be needed in customer's building.",
|
||||
"4. In case the resources of the local telecom operator at the customer premises can not meet the requirement of the Service in such spot, customer will assume the additional engineering cost.",
|
||||
"5.A PSTN line should be provided by the customer at each location for out-of-band access to the managed CPE;",
|
||||
"6.Managed CPE contains router installation, configuring, on-going MA (subject to the actual site addresses) and helpdesk support;",
|
||||
"7. There is no SLA for the performance of Internet access;",
|
||||
"8. The early termination penalty is 100% of the monthly charges of remaining contract period.",
|
||||
"9. Customer acknowledges and agrees that SST is entitled to withdraw, revoke or terminate this quotation for convenience at any time upon written notice to Customer due to applicable policy adjustment which is relevant to SST’s cost led by the authority or any other government agencies, such as tariff increase, even if Customer had received or confirmed this quotation. SST will reissue the quotation with updated OTC and MRC to Customer at its request.",
|
||||
};
|
||||
|
||||
int finalyCow = fisrtCowCol_0+2;
|
||||
int j=0;
|
||||
for (int cowNum = finalyCow;cowNum<finalyCow+10;cowNum++){
|
||||
Row row1 = sheet_Quotation.createRow(cowNum);
|
||||
if (cowNum == (finalyCow+9)) {
|
||||
row1.setHeight((short)(20*46));
|
||||
}
|
||||
sheet_Quotation.addMergedRegion(new CellRangeAddress(cowNum, cowNum, 0, 10));
|
||||
Cell cell = row1.createCell(0);
|
||||
cell.setCellStyle(setTotalStyle(workbook,"微软雅黑",true,false,HorizontalAlignment.LEFT, VerticalAlignment.CENTER,false,true));
|
||||
cell.setCellValue(finalyString[j]);
|
||||
j++;
|
||||
}
|
||||
sheet_Quotation.autoSizeColumn(0,true);
|
||||
sheet_Quotation.setColumnWidth(0,sheet_Quotation.getColumnWidth(0)*6/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 11; num++) {
|
||||
logger.info(num);
|
||||
sheet_Quotation.autoSizeColumn(num,true);
|
||||
sheet_Quotation.setColumnWidth(num, sheet_Quotation.getColumnWidth(num)*17/10);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("报错信息==="+e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class StringEscapeUtils {
|
||||
|
||||
|
||||
private static final Map<String, String> escapeMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
escapeMap.put("&", "&");
|
||||
escapeMap.put("<", "<");
|
||||
escapeMap.put(">", ">");
|
||||
escapeMap.put("\"", """);
|
||||
escapeMap.put("'", "'");
|
||||
escapeMap.put("/", "/");
|
||||
escapeMap.put(" "," ");//空格
|
||||
}
|
||||
|
||||
public static String escapeHtml(String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder output = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
String escape = escapeMap.get(Character.toString(c));
|
||||
if (escape != null) {
|
||||
output.append(escape);
|
||||
} else {
|
||||
output.append(c);
|
||||
}
|
||||
}
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.controller;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.wechat.util.Utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>校验项目报价记录查询中,项目名称是否是同一个</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/17 14:55
|
||||
*/
|
||||
@Path("/projectorder")
|
||||
public class CheckProjectNameApi {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
/**
|
||||
* <h2>接收前端传过来的主表id</h2>
|
||||
* @param request,response
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/17 15:36
|
||||
*/
|
||||
@POST
|
||||
@Path("/checkProjectNameApi")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String checkProjectNameApi(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
String ids = request.getParameter("ids");
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String[] split = ids.split(",");
|
||||
List<Map<String,String>> projectLists = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
String getDataSql = "select project_name,order_record,servicetype from uf_project_order where id = ?";
|
||||
if (recordSet.executeQuery(getDataSql,s)){
|
||||
while (recordSet.next()){
|
||||
String project_name = recordSet.getString("project_name");//项目名称
|
||||
map.put("project_name",project_name);
|
||||
String order_record = recordSet.getString("order_record");//报价记录
|
||||
map.put("order_record",order_record);
|
||||
String servicetype = Utils.null2String(recordSet.getString("servicetype"));//服务类型
|
||||
map.put("servicetype",servicetype);
|
||||
projectLists.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String,String>> lists = new ArrayList<>();//用于存放其他产品中customername,currencyused,contractterminmonths,contractmodel
|
||||
for (Map<String, String> projectList : projectLists) {
|
||||
String project_name = Util.null2String(projectList.get("project_name"));
|
||||
String order_record = Util.null2String(projectList.get("order_record"));
|
||||
String servicetype = Utils.null2String(projectList.get("servicetype"));
|
||||
String getCheckData = "select customername,currencyused,contractterminmonths,contractmodel from uf_other_export where lcid =?";
|
||||
boolean b = recordSet.executeQuery(getCheckData, order_record);
|
||||
logger.info("查询验证信息sql是否执行"+b);
|
||||
if ((!servicetype.equals("373")) && (!servicetype.equals("384"))){
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String customername = recordSet.getString("customername");//系统-客户名
|
||||
String currencyused = recordSet.getString("currencyused");
|
||||
String contractterminmonths = recordSet.getString("contractterminmonths");
|
||||
String contractmodel = recordSet.getString("contractmodel");
|
||||
map.put("customername",customername);
|
||||
map.put("currencyused",currencyused);
|
||||
map.put("contractterminmonths",contractterminmonths);
|
||||
map.put("contractmodel",contractmodel);
|
||||
map.put("project_name",project_name);
|
||||
lists.add(map);
|
||||
}
|
||||
}
|
||||
logger.info("lists==="+lists);
|
||||
List<Map<String, String>> collect1 = lists.stream().distinct().collect(Collectors.toList());
|
||||
String checkTag;
|
||||
String getMsgSql = "select * from uf_cus_dev_config where only_mark = ?";
|
||||
recordSet.executeQuery(getMsgSql,"exportProject");
|
||||
recordSet.next();
|
||||
String msg = recordSet.getString("param_value");
|
||||
//校验项目名称是否一致
|
||||
if (collect1.size()==1) {
|
||||
checkTag = "1";
|
||||
return ApiResult.success(checkTag);
|
||||
}else {
|
||||
checkTag = "0";
|
||||
return ApiResult.success(checkTag,msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("异常==="+e);
|
||||
return ApiResult.success(0,"代码异常");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.controller;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelAVPNService;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelL3NSService;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelOtherService;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl.ExportExcelAVPNServiceImpl;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl.ExportExcelL3NSServiceImpl;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl.ExportExcelOtherServiceImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.wechat.util.Utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Path("/export")
|
||||
public class ExportExcelApi {
|
||||
|
||||
/**
|
||||
* 用于处理AVPN的excel导出的业务处理
|
||||
*/
|
||||
private final ExportExcelAVPNService exportExcelAVPNService = new ExportExcelAVPNServiceImpl();
|
||||
/**
|
||||
* 用于处理L3NS的excel导出的业务处理
|
||||
*/
|
||||
private final ExportExcelL3NSService exportExcelL3NSService = new ExportExcelL3NSServiceImpl();
|
||||
|
||||
/**
|
||||
* 用于处理other的excel导出的业务处理
|
||||
*/
|
||||
private final ExportExcelOtherService exportExcelOtherService = new ExportExcelOtherServiceImpl();
|
||||
|
||||
/**
|
||||
* 日志处理
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/exportProjectExcel")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response exportProjectExcel(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
|
||||
String ids = request.getParameter("ids");
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String[] split = ids.split(",");
|
||||
List<String> datas = Arrays.asList(split);
|
||||
List<Map<String,Object>> listMapData = new ArrayList<>();//用于存放每一条数据的报价记录、serviceType
|
||||
|
||||
for (String data : datas) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String getDataSql = "select * from uf_project_order where id = ?";
|
||||
if (recordSet.executeQuery(getDataSql,data)){
|
||||
while (recordSet.next()){
|
||||
String id = Utils.null2String(recordSet.getString("id"));//id
|
||||
map.put("id",id);
|
||||
String servicetype = Utils.null2String(recordSet.getString("servicetype"));//Service Type
|
||||
map.put("servicetype",servicetype);
|
||||
String order_record = Utils.null2String(recordSet.getString("order_record"));//报价记录
|
||||
map.put("order_record",order_record);
|
||||
listMapData.add(map);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
String otherIds = "";
|
||||
String projectId = "";
|
||||
for (Map<String, Object> map : listMapData) {
|
||||
int servicetype = Integer.parseInt(String.valueOf(map.get("servicetype")));
|
||||
//AVPN=373 L3NS=384
|
||||
if (servicetype == 373){
|
||||
String AVPNIds = String.valueOf(map.get("id"));
|
||||
String AVPNFileName = getAVPNFileName(AVPNIds);
|
||||
//表名:uf_avpn_export
|
||||
//uf_project_order.order_record = uf_avpn_export.lcid
|
||||
String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
String get_uf_avpn_export_id = "select id from uf_avpn_export where lcid = ?";
|
||||
if (recordSet.executeQuery(get_uf_avpn_export_id,order_record)){
|
||||
recordSet.next();
|
||||
String id = recordSet.getString("id");
|
||||
Response response1 = exportExcelAVPNService.exportExcelAVPN(id,AVPNFileName);
|
||||
return response1;
|
||||
}
|
||||
}else if (servicetype == 384){
|
||||
//数据库表名:uf_L3NS_exportt
|
||||
String L3NSIds = Utils.null2String(map.get("id"));
|
||||
String L3NSFileName = getL3NSFileName(L3NSIds);
|
||||
String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
String get_uf_L3NS_exportt_id = "select id from uf_L3NS_exportt where lcid = ?";
|
||||
if (recordSet.executeQuery(get_uf_L3NS_exportt_id,order_record)){
|
||||
recordSet.next();
|
||||
String id = recordSet.getString("id");
|
||||
Response response1 = exportExcelL3NSService.exportExcelL3NSService(id,L3NSFileName);
|
||||
return response1;
|
||||
}
|
||||
}else { //servicetype == other
|
||||
//数据库表名:uf_other_export
|
||||
String projectOrderId = Utils.null2String(map.get("id"));
|
||||
projectId += projectOrderId + ",";
|
||||
String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
String get_uf_other_export = "select id from uf_other_export where lcid = ?";
|
||||
if (recordSet.executeQuery(get_uf_other_export,order_record)&&recordSet.next()){
|
||||
String id = Utils.null2String(recordSet.getString("id"));
|
||||
if(!id.equals("")){
|
||||
otherIds += id +",";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//处理导出other-excel的业务
|
||||
if (!otherIds.equals("")){{
|
||||
String otherFileName = getOtherFileName(projectId);
|
||||
Response response1 = exportExcelOtherService.exportExcelOther(otherIds,otherFileName);
|
||||
return response1;
|
||||
}}
|
||||
|
||||
return Response.ok(ApiResult.error("出现错误,错误原因: " ), MediaType.TEXT_PLAIN).build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取导出AVPN类型的excel的文件名称</h2>
|
||||
* @param AVPNIds:数据id
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/2/28 12:20
|
||||
*/
|
||||
public String getAVPNFileName(String AVPNIds) {
|
||||
|
||||
//“CMR” + customer_name + (select uf_project_inf .project_name from uf_project_inf where id = 导出数据表.project_name) + project_code + 日期(导出的日期)
|
||||
//CMR
|
||||
//project_name
|
||||
String fileName = "SST Discount Request Form";
|
||||
RecordSet rs = new RecordSet();
|
||||
String getDBFrom_uf_project_order = "select order_record,project_name from uf_project_order where id = ?";
|
||||
Map map = new HashMap<>();
|
||||
if (rs.executeQuery(getDBFrom_uf_project_order,AVPNIds) && rs.next()){
|
||||
String order_record = Utils.null2String(rs.getString("order_record"));
|
||||
map.put("order_record",order_record);
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));//项目名称
|
||||
map.put("project_name",project_name);
|
||||
}
|
||||
String get_customer_name = "select * from uf_avpn_export where lcid = ?";
|
||||
if (rs.executeQuery(get_customer_name,map.get("order_record")) && rs.next()){
|
||||
String customer_name = Utils.null2String(rs.getString("customer_name"));
|
||||
if (!customer_name.equals("")){
|
||||
fileName += "-"+customer_name;//拼接customer_name
|
||||
}
|
||||
}
|
||||
|
||||
String get_project_name = "select project_name,project_code from uf_project_inf where id = ?";
|
||||
if (rs.executeQuery(get_project_name,map.get("project_name")) && rs.next()){
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));
|
||||
String project_code = Utils.null2String(rs.getString("project_code"));
|
||||
if (!project_name.equals("")){
|
||||
fileName += "-"+project_name;
|
||||
}
|
||||
if (!project_code.equals("")){
|
||||
fileName += "-"+project_code;
|
||||
}
|
||||
}
|
||||
|
||||
//获取系统当前时间
|
||||
String currentTime = this.getCurrentTime();
|
||||
fileName += "-"+currentTime+".xlsx";
|
||||
//拼接后缀名
|
||||
|
||||
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* <h2>获取导出L3NS类型的excel的文件名称</h2>
|
||||
* @param L3NSIds:数据id
|
||||
* @return String:文件名称
|
||||
* @author hcy
|
||||
* @Date 2023/2/28 12:22
|
||||
*/
|
||||
public String getL3NSFileName(String L3NSIds) {
|
||||
|
||||
//“CMR” + customer_name + (select uf_project_inf .project_name from uf_project_inf where id = 导出数据表.project_name) + project_code + 日期(导出的日期)
|
||||
//CMR
|
||||
//project_name
|
||||
String fileName = "SST Discount Request Form";
|
||||
RecordSet rs = new RecordSet();
|
||||
String getDBFrom_uf_project_order = "select order_record,project_name from uf_project_order where id = ?";
|
||||
Map map = new HashMap<>();
|
||||
if (rs.executeQuery(getDBFrom_uf_project_order,L3NSIds) && rs.next()){
|
||||
String order_record = Utils.null2String(rs.getString("order_record"));
|
||||
map.put("order_record",order_record);
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));//项目名称
|
||||
map.put("project_name",project_name);
|
||||
}
|
||||
String get_customer_name = "select * from uf_L3NS_exportt where lcid = ?";
|
||||
if (rs.executeQuery(get_customer_name,map.get("order_record")) && rs.next()){
|
||||
String customer_name = Utils.null2String(rs.getString("customer_name"));
|
||||
if (!customer_name.equals("")){
|
||||
fileName += "-"+customer_name;//拼接customer_name
|
||||
}
|
||||
}
|
||||
|
||||
String get_project_name = "select project_name,project_code from uf_project_inf where id = ?";
|
||||
if (rs.executeQuery(get_project_name,map.get("project_name")) && rs.next()){
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));
|
||||
String project_code = Utils.null2String(rs.getString("project_code"));
|
||||
if (!project_name.equals("")){
|
||||
fileName += "-"+project_name;
|
||||
}
|
||||
if (!project_code.equals("")){
|
||||
fileName += "-"+project_code;
|
||||
}
|
||||
}
|
||||
|
||||
//获取系统当前时间
|
||||
String currentTime = this.getCurrentTime();
|
||||
fileName += "-"+currentTime+".xlsx";
|
||||
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* <h2>获取导出OtherIds类型的excel的文件名称</h2>
|
||||
* @param OtherIds:数据id
|
||||
* @return String:文件名称
|
||||
* @author hcy
|
||||
* @Date 2023/2/28 12:23
|
||||
*/
|
||||
public String getOtherFileName(String OtherIds) {
|
||||
|
||||
//“CMR” + customer_name + (select uf_project_inf .project_name from uf_project_inf where id = 导出数据表.project_name) + project_code + 日期(导出的日期)
|
||||
//CMR
|
||||
//project_name
|
||||
String[] split = OtherIds.split(",");
|
||||
String fileName = "CMR";
|
||||
RecordSet rs = new RecordSet();
|
||||
String getDBFrom_uf_project_order = "select order_record,project_name from uf_project_order where id = ?";
|
||||
Map<String,String> map = new HashMap<>();
|
||||
if (rs.executeQuery(getDBFrom_uf_project_order,split[0]) && rs.next()){
|
||||
String order_record = Utils.null2String(rs.getString("order_record"));
|
||||
map.put("order_record",order_record);
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));//项目名称
|
||||
map.put("project_name",project_name);
|
||||
}
|
||||
String get_customer_name = "select * from uf_other_export where lcid = ?";
|
||||
if (rs.executeQuery(get_customer_name,map.get("order_record")) && rs.next()){
|
||||
String customer_name = Utils.null2String(rs.getString("customername"));
|
||||
if (!customer_name.equals("")){
|
||||
fileName += "-"+customer_name;//拼接customer_name
|
||||
}
|
||||
}
|
||||
|
||||
String get_project_name = "select project_name,project_code from uf_project_inf where id = ?";
|
||||
if (rs.executeQuery(get_project_name,map.get("project_name")) && rs.next()){
|
||||
String project_name = Utils.null2String(rs.getString("project_name"));
|
||||
String project_code = Utils.null2String(rs.getString("project_code"));
|
||||
if (!project_name.equals("")){
|
||||
fileName += "-"+project_name;
|
||||
}
|
||||
if (!project_code.equals("")){
|
||||
fileName += "-"+project_code;
|
||||
}
|
||||
}
|
||||
|
||||
//获取系统当前时间
|
||||
String currentTime = this.getCurrentTime();
|
||||
fileName += "-"+currentTime+".xlsx";
|
||||
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* <h2>返回系统当前日期时间</h2>
|
||||
* @param
|
||||
* @return String 当前日期
|
||||
* @author hcy
|
||||
*/
|
||||
public String getCurrentTime(){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.controller;//package com.api.hcy_xintiantongxin.projectorder.controller;
|
||||
//
|
||||
//import aiyh.utils.ApiResult;
|
||||
//import aiyh.utils.Util;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.ExportExcelAVPNService;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.ExportExcelL3NSService;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.ExportExcelOtherService;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.impl.ExportExcelAVPNServiceImpl;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.impl.ExportExcelL3NSServiceImpl;
|
||||
//import com.api.hcy_xintiantongxin.projectorder.service.impl.ExportExcelOtherServiceImpl;
|
||||
//import org.apache.log4j.Logger;
|
||||
//import weaver.conn.RecordSet;
|
||||
//import weaver.wechat.util.Utils;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import javax.ws.rs.GET;
|
||||
//import javax.ws.rs.Path;
|
||||
//import javax.ws.rs.Produces;
|
||||
//import javax.ws.rs.core.Context;
|
||||
//import javax.ws.rs.core.MediaType;
|
||||
//import javax.ws.rs.core.Response;
|
||||
//import javax.ws.rs.core.StreamingOutput;
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.UnsupportedEncodingException;
|
||||
//import java.nio.charset.StandardCharsets;
|
||||
//import java.util.*;
|
||||
//import java.util.zip.ZipEntry;
|
||||
//import java.util.zip.ZipOutputStream;
|
||||
//
|
||||
//import static com.caucho.server.log.AccessLog.BUFFER_SIZE;
|
||||
//
|
||||
//@Path("/export")
|
||||
//public class ExportExcelApi_copy {
|
||||
//
|
||||
//*
|
||||
// * 用于处理AVPN的excel导出的业务处理
|
||||
//
|
||||
//
|
||||
// private final ExportExcelAVPNService exportExcelAVPNService = new ExportExcelAVPNServiceImpl();
|
||||
//*
|
||||
// * 用于处理L3NS的excel导出的业务处理
|
||||
//
|
||||
//
|
||||
// private final ExportExcelL3NSService exportExcelL3NSService = new ExportExcelL3NSServiceImpl();
|
||||
//
|
||||
//*
|
||||
// * 用于处理other的excel导出的业务处理
|
||||
//
|
||||
//
|
||||
// private final ExportExcelOtherService exportExcelOtherService = new ExportExcelOtherServiceImpl();
|
||||
//
|
||||
//*
|
||||
// * 日志处理
|
||||
//
|
||||
//
|
||||
// private final Logger logger = Util.getLogger();
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// @GET
|
||||
// @Path("/exportProjectExcel")
|
||||
// @Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
// public Response exportProjectExcel(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
//
|
||||
// String ids = request.getParameter("ids");
|
||||
// RecordSet recordSet = new RecordSet();
|
||||
// String[] split = ids.split(",");
|
||||
// List<String> datas = Arrays.asList(split);
|
||||
// List<Map<String,Object>> listMapData = new ArrayList<>();//用于存放每一条数据的报价记录、serviceType
|
||||
//
|
||||
// for (String data : datas) {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// String getDataSql = "select * from uf_project_order where id = ?";
|
||||
// if (recordSet.executeQuery(getDataSql,data)){
|
||||
// while (recordSet.next()){
|
||||
// String servicetype = Utils.null2String(recordSet.getString("servicetype"));//Service Type
|
||||
// map.put("servicetype",servicetype);
|
||||
// String order_record = Utils.null2String(recordSet.getString("order_record"));//报价记录
|
||||
// map.put("order_record",order_record);
|
||||
// listMapData.add(map);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// logger.info("listMapData==="+listMapData);
|
||||
// StreamingOutput output = outputStream -> {
|
||||
// ZipOutputStream zipOut = new ZipOutputStream(outputStream);
|
||||
// String otherIds = "";
|
||||
// for (Map<String, Object> map : listMapData) {
|
||||
// int servicetype = Integer.parseInt(String.valueOf(map.get("servicetype")));
|
||||
// //AVPN=373 L3NS=384
|
||||
// if (servicetype == 373){
|
||||
// //表名:uf_avpn_export
|
||||
// //uf_project_order.order_record = uf_avpn_export.lcid
|
||||
// String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
// String get_uf_avpn_export_id = "select id from uf_avpn_export where lcid = ?";
|
||||
// if (recordSet.executeQuery(get_uf_avpn_export_id,order_record)){
|
||||
// recordSet.next();
|
||||
// String id = recordSet.getString("id");
|
||||
// InputStream inputStream = exportExcelAVPNService.exportExcelAVPN(id);
|
||||
// //文件名称的获取规则为:“CMR” + customer_name + (select uf_project_inf .project_name from uf_project_inf where id = 导出数据表.project_name) + project_code + 日期(导出的日期)
|
||||
// String filename = exportExcelAVPNService.getFilename(id);
|
||||
// toZip(inputStream,zipOut,filename);
|
||||
// }
|
||||
// }else if (servicetype == 384){
|
||||
// //数据库表名:uf_L3NS_exportt
|
||||
// String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
// String get_uf_L3NS_exportt_id = "select id from uf_L3NS_exportt where lcid = ?";
|
||||
// if (recordSet.executeQuery(get_uf_L3NS_exportt_id,order_record)){
|
||||
// recordSet.next();
|
||||
// String id = recordSet.getString("id");
|
||||
// InputStream inputStream = exportExcelL3NSService.exportExcelL3NSService(id);
|
||||
// String filename = exportExcelL3NSService.getFilename(id);
|
||||
// toZip(inputStream,zipOut,filename);
|
||||
// }
|
||||
// }else { //servicetype == other
|
||||
// //数据库表名:uf_other_export
|
||||
// String order_record = Utils.null2String(String.valueOf(map.get("order_record")));
|
||||
// String get_uf_other_export = "select id from uf_other_export where lcid = ?";
|
||||
// if (recordSet.executeQuery(get_uf_other_export,order_record)&&recordSet.next()){
|
||||
// String id = Utils.null2String(recordSet.getString("id"));
|
||||
// if(!id.equals("")){
|
||||
// otherIds += id +",";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //处理导出other-excel的业务
|
||||
// if (!otherIds.equals("")){{
|
||||
// InputStream inputStream = exportExcelOtherService.exportExcelOther(otherIds);
|
||||
// String filename = exportExcelOtherService.getFilename(otherIds);
|
||||
// toZip(inputStream,zipOut,filename);
|
||||
// }}
|
||||
// //关闭流
|
||||
// zipOut.flush();
|
||||
// zipOut.close();
|
||||
// outputStream.flush();
|
||||
// outputStream.close();
|
||||
// };
|
||||
//
|
||||
// try {
|
||||
// return Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).type("application/zip")
|
||||
// .header("Content-Disposition", "attachment;filename=\"" +
|
||||
// new String("项目报价记录".getBytes("GBK"), StandardCharsets.ISO_8859_1) + ".zip" + "\"").build();
|
||||
// } catch (UnsupportedEncodingException e) {
|
||||
// e.printStackTrace();
|
||||
// return Response.ok(ApiResult.error("出现错误,错误原因:"+e),MediaType.TEXT_PLAIN).build();
|
||||
// }
|
||||
// }
|
||||
//*
|
||||
// * <h2>添加压缩文件</h2>
|
||||
// * @param is,zipOut,fileName
|
||||
// * @return
|
||||
// * @author hcy
|
||||
// * @Date 2023/2/18 16:59
|
||||
//
|
||||
//
|
||||
// private static void addToZip(InputStream is, ZipOutputStream zipOut, String fileName) {
|
||||
// try{
|
||||
// ZipEntry entry = new ZipEntry(fileName);
|
||||
// zipOut.putNextEntry(entry);
|
||||
// int len;
|
||||
// byte[] buffer = new byte[1024];
|
||||
// while ((len = is.read(buffer)) > 0) {
|
||||
// zipOut.write(buffer, 0, len);
|
||||
// }
|
||||
// zipOut.closeEntry();
|
||||
// is.close();
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//*
|
||||
// * <h2>压缩成ZIP</h2>
|
||||
// * @param is,out,filename
|
||||
// * @return
|
||||
// * @author hcy
|
||||
// * @Date 2023/2/23 18:29
|
||||
//
|
||||
//
|
||||
// public static void toZip(InputStream is, ZipOutputStream zos,String fileName) throws RuntimeException {
|
||||
// long start = System.currentTimeMillis();
|
||||
// try {
|
||||
// byte[] buf = new byte[BUFFER_SIZE];
|
||||
// zos.putNextEntry(new ZipEntry(fileName));
|
||||
// int len;
|
||||
// FileInputStream is1 = (FileInputStream) is;
|
||||
// while ((len = is1.read(buf)) != -1) {
|
||||
// zos.write(buf, 0, len);
|
||||
// }
|
||||
// zos.finish();
|
||||
// zos.closeEntry();
|
||||
// is1.close();
|
||||
//
|
||||
// long end = System.currentTimeMillis();
|
||||
// System.out.println("压缩完成,耗时:" + (end - start) + " ms");
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("zip error from ZipUtils", e);
|
||||
// } finally {
|
||||
// if (zos != null) {
|
||||
// try {
|
||||
// zos.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,20 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* <h1>用于导出AVPN--excel</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/18 14:59
|
||||
*/
|
||||
public interface ExportExcelAVPNService {
|
||||
|
||||
/**
|
||||
* <h2>传入数据id,查询当前数据id对应的数据库数据,然后插入到excel表单中,返回response</h2>
|
||||
* @param ids :数据id,用逗号分割
|
||||
* @return Response
|
||||
* @author hcy
|
||||
* @Date 2023/2/18 15:04
|
||||
*/
|
||||
public Response exportExcelAVPN(String ids,String AVPNFileName);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* <h1>用于处理导出L3NS.xlsx业务处理</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/18 15:11
|
||||
*/
|
||||
public interface ExportExcelL3NSService {
|
||||
|
||||
/**
|
||||
* <h2>传入数据id,查询当前数据id对应的数据库数据,然后插入到excel表单中,返回response</h2>
|
||||
* @param ids :数据id,用逗号隔开
|
||||
* @return Response
|
||||
* @author hcy
|
||||
* @Date 2023/2/18 15:13
|
||||
*/
|
||||
public Response exportExcelL3NSService(String ids,String L3NSFileName);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* <h1>用于导出other--excel业务处理</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/2/18 14:59
|
||||
*/
|
||||
public interface ExportExcelOtherService {
|
||||
|
||||
/**
|
||||
* <h2>传入数据id,查询当前数据id对应的数据库数据,然后插入到excel表单中,返回InputStream</h2>
|
||||
* @param ids :数据id,用逗号分割
|
||||
* @return InputStream
|
||||
* @author hcy
|
||||
* @Date 2023/2/18 15:04
|
||||
*/
|
||||
public Response exportExcelOther(String ids,String otherFileName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,678 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelAVPNService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class ExportExcelAVPNServiceImpl implements ExportExcelAVPNService {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
public Response exportExcelAVPN(String ids,String AVPNName) {
|
||||
logger.info("ExportExcelAVPNServiceImpl-----开始");
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
try {
|
||||
//查询到 uf_avpn_export AVPN导出表中的一条数据的ids
|
||||
RecordSet rs = new RecordSet();
|
||||
StreamingOutput output = null;
|
||||
|
||||
String sql_AVPN_db = "select * from uf_avpn_export where id = ?";
|
||||
rs.executeQuery(sql_AVPN_db, ids);
|
||||
|
||||
//创建一个工作簿
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
String[] dbFiled = new String[10];
|
||||
String mainId = "";
|
||||
|
||||
while (rs.next()) {
|
||||
//查询到uf_avpn_export表的id作为查询明细表的mainid
|
||||
mainId = rs.getString("id");
|
||||
String pd_nameId = rs.getString("pd_name");//uf_pd_base_inf 得到的pd_name是字段的id
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String getPd_nameByIdSql = "select pd_name from uf_pd_base_inf where id =?";
|
||||
boolean b1 = recordSet.executeQuery(getPd_nameByIdSql, pd_nameId);
|
||||
|
||||
logger.info("查询pd_namesql语句是否成功==" + b1);
|
||||
if (recordSet.next()) {
|
||||
String pd_name = recordSet.getString("pd_name");//查询到pd_name的值
|
||||
dbFiled[0] = pd_name;
|
||||
}
|
||||
String billing_model = rs.getString("billing_model");
|
||||
if (billing_model.equals("0")){
|
||||
billing_model = "Assignment Model Billing in China";
|
||||
}
|
||||
dbFiled[1] = billing_model;
|
||||
String customer_name = rs.getString("customer_name");
|
||||
dbFiled[2] = customer_name;
|
||||
String ecrm_opportunity = rs.getString("ecrm_opportunity");
|
||||
dbFiled[3] = ecrm_opportunity;
|
||||
String igloo = rs.getString("igloo");
|
||||
dbFiled[4] = igloo;
|
||||
String terms = rs.getString("terms");
|
||||
dbFiled[5] = terms;
|
||||
String att_lead_pricer = rs.getString("att_lead_pricer");
|
||||
dbFiled[6] = att_lead_pricer;
|
||||
String requestjustificationoptional = rs.getString("requestjustificationoptional");
|
||||
dbFiled[7] = requestjustificationoptional;
|
||||
String specialrequesttosstoptional = rs.getString("specialrequesttosstoptional");
|
||||
dbFiled[8] = specialrequesttosstoptional;
|
||||
String sst_contact = rs.getString("sst_contact");
|
||||
dbFiled[9] = sst_contact;
|
||||
}
|
||||
//表单字段
|
||||
String[] tableFiled = new String[]{"Service Type", "Billing Model", "Customer Name", "ECRM Opportunity#", "Igloo #", "Contract Term (in months)", "AT&T Lead Pricer", "Request Justification (optional)", "Special Request to SST (Optional)", "SST Contact"};
|
||||
//明细表字段
|
||||
String[] mergerDetailTableFiled = new String[]{"Site ID", "Description", "Bandwidth", "OTC in RMB", "MRC in RMB"};
|
||||
|
||||
//创建一个工作表sheet
|
||||
Sheet sheet = workbook.createSheet();
|
||||
workbook.setSheetName(0, "AVPN表单");
|
||||
sheet.autoSizeColumn(1, true);
|
||||
//写入数据 //写入1-11行第一列 第二列数据
|
||||
for (int rowNum = 1; rowNum < 11; rowNum++) {
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell0 = row.createCell(0);
|
||||
cell0.setCellStyle(this.setWordStyle(workbook, true));
|
||||
cell0.setCellValue(tableFiled[rowNum - 1]);
|
||||
Cell cell1 = row.createCell(1);
|
||||
cell1.setCellStyle(setWordStyle(workbook, true));
|
||||
cell1.setCellValue(dbFiled[rowNum - 1]);
|
||||
}
|
||||
Row row12 = sheet.createRow(12);//第13行
|
||||
Cell cell12_11 = row12.createCell(11);
|
||||
cell12_11.setCellStyle(setWordStyle(workbook, true));
|
||||
cell12_11.setCellValue("Default Assignment Model-Billing in China in RMB");
|
||||
Cell cell12_12 = row12.createCell(12);
|
||||
cell12_12.setCellStyle(setNolyBorderStyle(workbook));
|
||||
sheet.addMergedRegion(new CellRangeAddress(12, 12, 11, 12));
|
||||
|
||||
//设置14行到15行前5列内容
|
||||
Row row13 = sheet.createRow(13);
|
||||
Row row14 = sheet.createRow(14);
|
||||
for (int colNum = 0; colNum < 5; colNum++) {
|
||||
Cell cell = row13.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook, true));
|
||||
cell.setCellValue(mergerDetailTableFiled[colNum]);
|
||||
Cell cell1 = row14.createCell(colNum);
|
||||
cell1.setCellStyle(setWordStyle(workbook, true));
|
||||
cell1.setCellValue(mergerDetailTableFiled[colNum]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 14, colNum, colNum));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//设置14行第六列到第13列的内容
|
||||
String[] mergerDetailTableFiled02 = new String[]{"Discount Requested (%)", "Discount SST approved (%)", "Net Price to AT&T Customer", "Royalty to SST without Tax(contra-revenue)"};
|
||||
Cell cell13_5 = row13.createCell(5);
|
||||
cell13_5.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_5.setCellValue(mergerDetailTableFiled02[0]);
|
||||
Cell cell113_6 = row13.createCell(6);
|
||||
cell113_6.setCellStyle(setWordStyle(workbook, true));
|
||||
cell113_6.setCellValue(mergerDetailTableFiled02[0]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 5, 6));
|
||||
|
||||
|
||||
Cell cell13_7 = row13.createCell(7);
|
||||
cell13_7.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_7.setCellValue(mergerDetailTableFiled02[1]);
|
||||
Cell cell13_8 = row13.createCell(8);
|
||||
cell13_8.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_8.setCellValue(mergerDetailTableFiled02[1]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 7, 8));
|
||||
|
||||
Cell cell13_9 = row13.createCell(9);
|
||||
cell13_9.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_9.setCellValue(mergerDetailTableFiled02[2]);
|
||||
Cell cell13_10 = row13.createCell(10);
|
||||
cell13_10.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_10.setCellValue(mergerDetailTableFiled02[2]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 9, 10));
|
||||
|
||||
Cell cell13_11 = row13.createCell(11);
|
||||
cell13_11.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_11.setCellValue(mergerDetailTableFiled02[3]);
|
||||
Cell cell13_12 = row13.createCell(12);
|
||||
cell13_12.setCellStyle(setWordStyle(workbook, true));
|
||||
cell13_12.setCellValue(mergerDetailTableFiled02[3]);
|
||||
sheet.addMergedRegion(new CellRangeAddress(13, 13, 11, 12));
|
||||
|
||||
|
||||
//设置15行第六列到第13列的内容
|
||||
String[] mergerDetailTableFiled03 = new String[]{"OTC", "MRC", "OTC", "MRC", "OTC in RMB", "MRC in RMB", "OTC in RMB", "MRC in RMB"};
|
||||
for (int colNum = 5; colNum < 13; colNum++) {
|
||||
Cell cell = row14.createCell(colNum);
|
||||
for (int num = 0; num < 8; num++) {
|
||||
cell.setCellStyle(setWordStyle(workbook, true));
|
||||
cell.setCellValue(mergerDetailTableFiled03[num]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<Map<String, String>> siteMap = new ArrayList<>();//用来存放site的类型和每个site的状态
|
||||
|
||||
String getSiteSql = "select site ,count(site) siteNum from uf_avpn_export_dt1 where mainId =? group by site ;";
|
||||
RecordSet rs02 = new RecordSet();
|
||||
boolean b = rs02.executeQuery(getSiteSql, mainId);
|
||||
logger.info("查询site,以及site的数量的sql语句===" + b);
|
||||
|
||||
while (rs02.next()) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
String site = rs02.getString("site");
|
||||
String siteNum = rs02.getString("siteNum");
|
||||
map.put(site, siteNum);
|
||||
siteMap.add(map);//将site的类型和每个site的类型的个数放到siteList数组中,用来循环遍历再放入单元格中
|
||||
}
|
||||
int firstCow = 15;//从第15行开始写入明细表,固定死
|
||||
int finalyCow = 0;
|
||||
|
||||
|
||||
Double sum9 = 0D;
|
||||
Double sum10 = 0D;
|
||||
Double sum11 = 0D;
|
||||
Double sum12 = 0D;
|
||||
for (Map<String, String> map : siteMap) {
|
||||
Set<String> siteKeySet = map.keySet();
|
||||
List<List<Object>> detailDateList = new ArrayList();
|
||||
int cowLength = 0;//每一个site类型的数据的长度
|
||||
for (String s1 : siteKeySet) {
|
||||
cowLength = Integer.parseInt(map.get(s1));//每一个site类型的数据的长度
|
||||
String getDetailDataSql = "select * from uf_avpn_export_dt1 where mainId =? and site = ?";
|
||||
rs02.executeQuery(getDetailDataSql, mainId, s1);
|
||||
while (rs02.next()) {
|
||||
String site = rs02.getString("site");//Site ID
|
||||
String itemId = rs02.getString("Item");//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
|
||||
String categoryId = rs02.getString("Category");//Bandwidth
|
||||
String getCategoryByIdSql = "select category from uf_pd_category_inf where id = ?";
|
||||
boolean b3 = recordSet1.executeQuery(getCategoryByIdSql, categoryId);
|
||||
logger.info("查询categorySql是否执行成功==" + b3);
|
||||
String category = "";
|
||||
if (recordSet1.next()) {
|
||||
category = recordSet1.getString("category");
|
||||
}
|
||||
String otc_price = rs02.getString("otc_price");//OTC in RMB
|
||||
String mrc_price = rs02.getString("mrc_price");//MRC in RMB
|
||||
String otcdiscountrequest = rs02.getString("otcdiscountrequest");//Discount Requested (%) OTC
|
||||
String mrcdiscountrequest = rs02.getString("mrcdiscountrequest");//Discount Requested (%) MRC
|
||||
String otcdiscountapproved = rs02.getString("otcdiscountapproved");//Discount SST approved (%) OTC
|
||||
String mrcdiscountapproved = rs02.getString("mrcdiscountapproved");//Discount SST approved (%)MRC
|
||||
String otc_tariff = rs02.getString("otc_tariff");//Net Price to AT&T Customer(OTC in RMB)
|
||||
String mrc_tariff = rs02.getString("mrc_tariff");//Net Price to AT&T Customer(MRC in RMB)
|
||||
String otc_scale = rs02.getString("otc_scale");//Royalty to SST without Tax (contra-revenue)(OTC in RMB)
|
||||
String mrc_scale = rs02.getString("mrc_scale");//Royalty to SST without Tax (contra-revenue)(MRC in RMB)
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
list.add(site);//list.add(site);
|
||||
list.add(item);
|
||||
list.add(category);
|
||||
list.add(otc_price);
|
||||
list.add(mrc_price);
|
||||
list.add(otcdiscountrequest);
|
||||
list.add(mrcdiscountrequest);
|
||||
list.add(otcdiscountapproved);
|
||||
list.add(mrcdiscountapproved);
|
||||
list.add(otc_tariff);
|
||||
list.add(mrc_tariff);
|
||||
list.add(otc_scale);
|
||||
list.add(mrc_scale);
|
||||
detailDateList.add(list);
|
||||
}
|
||||
}
|
||||
Double amount9 = 0D;//用来统计每一个site种类的 Grand-Total(RMB)
|
||||
Double amount10 = 0D;
|
||||
Double amount11 = 0D;
|
||||
Double amount12 = 0D;
|
||||
//得到list类型的数据、有得到每种site类型的数据长度
|
||||
//开始向excel中导入明细表中的数据
|
||||
int i = 0;//用它来增加detailDateList的下标
|
||||
for (int cowNum = firstCow; cowNum < firstCow + cowLength; cowNum++) {
|
||||
Row row = sheet.createRow(cowNum);
|
||||
for (int colNum = 0; colNum < 13; colNum++) {
|
||||
if (colNum == 9) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount9 = Double.valueOf(amount9) + value;
|
||||
sum9 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else{
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 10) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount10 = amount10 + value;
|
||||
sum10 += value;
|
||||
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
}
|
||||
} else if (colNum == 11) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount11 = amount11 + value;
|
||||
sum11 += value;
|
||||
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 12) {
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount12 = amount12 + value;
|
||||
sum12 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
|
||||
if (colNum == 5 || colNum == 6 || colNum == 7 || colNum == 8) {
|
||||
Cell cell = row.createCell(colNum);
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue( (int)(value*100) + "%");
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
else if (colNum == 0||colNum==1||colNum==2){
|
||||
Cell cell = row.createCell(colNum);
|
||||
String value = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (value!=""){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}else if (colNum == 3||colNum==4){
|
||||
String s = String.valueOf(detailDateList.get(i).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
//合并单元格
|
||||
int lastCow = firstCow + cowLength;
|
||||
|
||||
if (cowLength > 1) {
|
||||
sheet.addMergedRegion(new CellRangeAddress(firstCow, lastCow - 1, 0, 0));
|
||||
}
|
||||
//开始写入Sub-Total(RMB)
|
||||
Row rowSubTotal = sheet.createRow(lastCow);
|
||||
for (int colNum = 8; colNum < 13; colNum++) {
|
||||
if (colNum == 8) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue("Sub-Total(RMB)");
|
||||
} else if (colNum == 9) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount9);
|
||||
} else if (colNum == 10) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount10);
|
||||
} else if (colNum == 11) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount11);
|
||||
} else if (colNum == 12) {
|
||||
Cell cellSubToTal = rowSubTotal.createCell(colNum);
|
||||
cellSubToTal.setCellStyle(setNolyWordStyle(workbook, true));
|
||||
cellSubToTal.setCellValue(amount12);
|
||||
}
|
||||
}
|
||||
|
||||
firstCow = firstCow + cowLength + 1;
|
||||
finalyCow = firstCow;
|
||||
}//处理插入数据以及合并单元格
|
||||
//处理明细表最后一行的统计情况
|
||||
Row row_Grand_Total_RMB = sheet.createRow(finalyCow);
|
||||
for (int colNum = 8; colNum < 13; colNum++) {
|
||||
if (colNum == 8) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue("Grand-Total(RMB)");
|
||||
} else if (colNum == 9) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum9);
|
||||
} else if (colNum == 10) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum10);
|
||||
} else if (colNum == 11) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum11);
|
||||
} else if (colNum == 12) {
|
||||
Cell cell = row_Grand_Total_RMB.createCell(colNum);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cell.setCellValue(sum12);
|
||||
}
|
||||
}
|
||||
|
||||
//输入最下面的固定值
|
||||
String[] lastStringLeft = new String[]{
|
||||
"Notes:",
|
||||
"1.This is NOT AT&T Pricing Approval. Forward this SST quote to your Lead ICB Pricer to issue the official Rate Letter",
|
||||
"2.Access price must be quoted by SST, request SST as \"access provider\" in Igloo. Do NOT use quote from other access providers",
|
||||
"3.Discount is only applicable to the demand set listed below, any changes in bandwidth/design/billing model, need to re-submit to SST and AT&T Pricer for approval", "" +
|
||||
"4.Under in-country billing, AT&T must follow the discount% offered by SST. Do NOT deviate from the SST quoted discount.",
|
||||
"5.SST can support repeatable discount for the same solution design(port/CDR/CPE) of same contract term which was approved already. Local Loop part are non-repeatable.",
|
||||
"6.For ICB only - Royalty in columns L and M are contra-revenue,ICB to verify if BCRL captured these amount.",
|
||||
"7.Save this SST approved quote to eCRM (without release) for record.",
|
||||
"8.The quotation shall be exclusive of any applicable taxes and Customer shall pay all the taxes and charges relating to the payment if any. The VAT rate for CPE and related modules and license are 16%, the rest is 6%.",
|
||||
"9.Thank you for considering SST, this engagement may be subject to a credit check, we appreciate your cooperation and look forward to doing business in the near future."
|
||||
};
|
||||
int lastLineTag = finalyCow + 2;//固定值Note所在的行
|
||||
int k = 0;//用来增加lastStringLeft的下标
|
||||
for (int rowNum = lastLineTag; rowNum < lastLineTag + 10; rowNum++) {
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 11));
|
||||
cell.setCellStyle(setTotalStyle(workbook,"微软雅黑",true,false,HorizontalAlignment.LEFT, VerticalAlignment.CENTER,false));
|
||||
cell.setCellValue(lastStringLeft[k]);
|
||||
k++;
|
||||
}
|
||||
sheet.autoSizeColumn(0,true);
|
||||
sheet.setColumnWidth(0,sheet.getColumnWidth(0)*8/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 13; num++) {
|
||||
sheet.autoSizeColumn(num,true);
|
||||
sheet.setColumnWidth(num, (sheet.getColumnWidth(num)));
|
||||
}
|
||||
|
||||
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
header = Response.ok(output,MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String(AVPNName.getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
}
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>设置每个单元格样式:包含字体类型,字体是否加粗,是否包含边框,元素水平方向的位置,元素垂直方向的位置,是否设置元素的数据格式,</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/2/13 18:08
|
||||
*/
|
||||
public static CellStyle setTotalStyle(Workbook workbook,String type,boolean setBold,boolean setBorder,HorizontalAlignment horizontalDirection,VerticalAlignment verticalAlignmentDirection ,boolean setDataFormat){
|
||||
//new一个cellStyle用于设置每一个单元格样式
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName(type);
|
||||
//设置字体是否加粗
|
||||
font.setBold(setBold);
|
||||
//将字体样式渲染cellStyle对象中
|
||||
cellStyle.setFont(font);
|
||||
if (setBorder == true){
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
}
|
||||
|
||||
//水平居中
|
||||
cellStyle.setAlignment(horizontalDirection);
|
||||
//垂直居中
|
||||
cellStyle.setVerticalAlignment(verticalAlignmentDirection);
|
||||
|
||||
//此处设置数据格式
|
||||
if(setDataFormat == true){
|
||||
DataFormat dataFormat = workbook.createDataFormat();
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
}
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
/**
|
||||
* <h2>返回系统当前日期时间</h2>
|
||||
* @param
|
||||
* @return String 当前日期
|
||||
* @author hcy
|
||||
*/
|
||||
public String getCurrentTime(){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
String currentTime = dateFormat.format(date);
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyBorderStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单元格格式为数值型
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,571 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelL3NSService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class ExportExcelL3NSServiceImpl implements ExportExcelL3NSService {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
public Response exportExcelL3NSService(String ids,String L3NSFileName) {
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
try {
|
||||
//查询到 uf_L3NS_exportt AVPN导出表中的一条数据的ids
|
||||
RecordSet rs = new RecordSet();
|
||||
StreamingOutput output = null;
|
||||
|
||||
|
||||
String sql_L3NS_db = "select * from uf_L3NS_exportt where id = ?";
|
||||
boolean b = rs.executeQuery(sql_L3NS_db, ids);
|
||||
logger.info("是否查询uf_L3NS_exportt=="+b);
|
||||
|
||||
//创建一个工作簿
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
String[] dbFiled = new String[13];
|
||||
String[] tableFiled = new String[]{"Service Type", "Billing Model", "Customer Name", "ROME Opportunity #", "ROME WR#", "Request Type", "Original SST Order NO", "Request Justification", "Special Request to SST", "Target Service Provision date","ATT Order number:","SST Pre-Sales Contact","Date of SST Approval"};
|
||||
|
||||
String mainId = "";
|
||||
|
||||
//得到主表数据,用来写入excel中的固定值
|
||||
while (rs.next()) {
|
||||
//查询到uf_avpn_export表的id作为查询明细表的mainid
|
||||
mainId = rs.getString("id");
|
||||
|
||||
|
||||
String pd_nameId = rs.getString("pd_name");//uf_pd_base_inf 得到的pd_name是字段的id
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String getPd_nameByIdSql = "select pd_name from uf_pd_base_inf where id =?";
|
||||
boolean b1 = recordSet.executeQuery(getPd_nameByIdSql, pd_nameId);
|
||||
|
||||
logger.info("查询pd_namesql语句是否成功==" + b1);
|
||||
if (recordSet.next()) {
|
||||
String pd_name = recordSet.getString("pd_name");//查询到pd_name的值
|
||||
dbFiled[0] = pd_name;
|
||||
}
|
||||
String billingmodel = rs.getString("billingmodel");//Billing Model===billingmodel
|
||||
if (billingmodel.equals("0")){
|
||||
billingmodel = "Custom Subcontract";
|
||||
}else if (billingmodel == null){
|
||||
billingmodel = "";
|
||||
}
|
||||
dbFiled[1] = billingmodel;
|
||||
String customer_name = rs.getString("customer_name");//Customer Name===customer_name
|
||||
dbFiled[2] = customer_name;
|
||||
String rome_opportunity = rs.getString("rome_opportunity");//ROME Opportunity #====rome_opportunity
|
||||
dbFiled[3] = rome_opportunity;
|
||||
String rome_wr = rs.getString("rome_wr");//ROME WR#====rome_wr
|
||||
dbFiled[4] = rome_wr;
|
||||
String request_type = rs.getString("request_type");//Request Type====request_type
|
||||
dbFiled[5] = request_type;
|
||||
String original_sst_order_no = rs.getString("original_sst_order_no");//Original SST Order NO====original_sst_order_no
|
||||
dbFiled[6] = original_sst_order_no;
|
||||
String requestjustificationoptional = rs.getString("requestjustificationoptional");//Request Justification====requestjustificationoptional
|
||||
dbFiled[7] = requestjustificationoptional;
|
||||
String specialrequesttosstoptional = rs.getString("specialrequesttosstoptional");//Special Request to SST====specialrequesttosstoptional
|
||||
dbFiled[8] = specialrequesttosstoptional;
|
||||
String targetserviceprovisiondate = rs.getString("targetserviceprovisiondate");//Target Service Provision date====targetserviceprovisiondate
|
||||
dbFiled[9] = targetserviceprovisiondate;
|
||||
String attordernumber = rs.getString("attordernumber");//ATT Order number:====attordernumber
|
||||
dbFiled[10] = attordernumber;
|
||||
String sstpresalescontact = rs.getString("sstpresalescontact");//SST Pre-Sales Contact====sstpresalescontact
|
||||
dbFiled[11] = sstpresalescontact;
|
||||
String dateofsstapproval = rs.getString("dateofsstapproval");//Date of SST Approval====dateofsstapproval
|
||||
dbFiled[12] = dateofsstapproval;
|
||||
}
|
||||
|
||||
//开始写入固定值
|
||||
Sheet sheet = workbook.createSheet();
|
||||
workbook.setSheetName(0, "L3NS表单");
|
||||
sheet.autoSizeColumn(1, true);
|
||||
|
||||
for (int cowNum=1;cowNum<14;cowNum++){
|
||||
Row row = sheet.createRow(cowNum);
|
||||
Cell cell0 = row.createCell(0);
|
||||
cell0.setCellStyle(setWordStyle(workbook,true));
|
||||
cell0.setCellValue(tableFiled[cowNum-1]);
|
||||
Cell cell1 = row.createCell(1);
|
||||
cell1.setCellStyle(setWordStyle(workbook,true));
|
||||
cell1.setCellValue(dbFiled[cowNum-1]);
|
||||
}
|
||||
|
||||
Row row14 = sheet.createRow(14);//写入15行数据
|
||||
Cell cell14_0 = row14.createCell(0);
|
||||
Cell cell114_1 = row14.createCell(1);
|
||||
cell14_0.setCellStyle(setWordStyle(workbook,true));
|
||||
cell14_0.setCellValue("This Quote is valid for 180 days from \"Date of SST approval\"");
|
||||
cell114_1.setCellStyle(setWordStyle(workbook,true));
|
||||
cell114_1.setCellValue("This Quote is valid for 180 days from \"Date of SST approval\"");
|
||||
sheet.addMergedRegion(new CellRangeAddress(14, 14, 0, 1));
|
||||
|
||||
|
||||
// 写入18行,19行数据
|
||||
// Site ID Description Bandwidth OTC in RMB MRC in RMB
|
||||
String[] detailFileds = new String[]{"Site ID", "Description","Bandwidth", "OTC in RMB", "MRC in RMB"};
|
||||
Row row17 = sheet.createRow(17);
|
||||
Row row18 = sheet.createRow(18);
|
||||
for (int colNum =0;colNum<5;colNum++){
|
||||
Cell cell = row17.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellStyle(setWordStyle(workbook,true));
|
||||
cell.setCellValue(detailFileds[colNum]);
|
||||
}
|
||||
for (int colNum =0;colNum<5;colNum++){
|
||||
Cell cell = row18.createCell(colNum);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellStyle(setWordStyle(workbook,true));
|
||||
cell.setCellValue(detailFileds[colNum]);
|
||||
}
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 0, 0));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 1, 1));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 2, 2));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 3, 3));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 18, 4, 4));
|
||||
|
||||
// Relief Requested (%) Relief SST approved (%) Tariff to SST (include VAT) 6-11列
|
||||
// OTC MRC OTC MRC OTC in RMB MRC in RMB
|
||||
String[] detailFileds01 = new String[]{"Relief Requested (%)","Relief Requested (%)","Relief SST approved (%)","Relief SST approved (%)","Tariff to SST (include VAT)","Tariff to SST (include VAT)",""};
|
||||
String[] detailFileds02 = new String[]{"OTC","MRC","OTC","MRC","OTC in RMB","MRC in RMB"};
|
||||
int i=0;
|
||||
int j = 0;
|
||||
for(int colNum=5;colNum<11;colNum++){
|
||||
Cell cell17 = row17.createCell(colNum);
|
||||
Cell cell18 = row18.createCell(colNum);
|
||||
cell17.setCellValue(detailFileds01[i]);
|
||||
cell17.setCellStyle(setWordStyle(workbook,true));
|
||||
// cell17.setCellStyle(setCellStyleFrame(workbook));
|
||||
|
||||
cell18.setCellValue(detailFileds02[j]);
|
||||
cell18.setCellStyle(setWordStyle(workbook,true));
|
||||
// cell18.setCellStyle(setCellStyleFrame(workbook));
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
//合并18行,19行
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 5, 6));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 7, 8));
|
||||
sheet.addMergedRegion(new CellRangeAddress(17, 17, 9, 10));
|
||||
|
||||
|
||||
//开始写入20开始一直往下的动态表格中的内容
|
||||
//
|
||||
|
||||
List<Map<String, String>> siteMap = new ArrayList<>();//用来存放site的类型和每个site的状态
|
||||
String getSiteSql = "select site ,count(site) siteNum from uf_L3NS_exportt_dt1 where mainId =? group by site ;";
|
||||
RecordSet rs02 = new RecordSet();
|
||||
boolean b1 = rs02.executeQuery(getSiteSql, mainId);
|
||||
logger.info("查询site,以及site的数量的sql语句===" + b1);
|
||||
while (rs02.next()) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
String site = rs02.getString("site");
|
||||
String siteNum = rs02.getString("siteNum");
|
||||
map.put(site, siteNum);
|
||||
siteMap.add(map);//将site的类型和每个site的类型的个数放到siteList数组中,用来循环遍历再放入单元格中
|
||||
}
|
||||
|
||||
int firstCow = 19;//从第15行开始写入明细表,固定死
|
||||
int finalyCow = 0;
|
||||
Double sum10 = 0D;//用来统计所有site种类的Grand-Total (RMB) #REF!
|
||||
Double sum9 = 0D;
|
||||
for (Map<String, String> map : siteMap) {
|
||||
|
||||
Set<String> siteKeySet = map.keySet();
|
||||
List<List<Object>> detailDateList = new ArrayList();
|
||||
int cowLength = 0;//每一个site类型的数据的长度
|
||||
for (String s1 : siteKeySet) {
|
||||
cowLength = Integer.parseInt(map.get(s1));//每一个site类型的数据的长度
|
||||
String getDetailDataSql = "select * from uf_L3NS_exportt_dt1 where mainId =? and site = ?";
|
||||
rs02.executeQuery(getDetailDataSql,mainId,s1);
|
||||
while(rs02.next()){
|
||||
//明细表数据
|
||||
String site = rs02.getString("site");//Site ID
|
||||
String itemId = rs02.getString("Item");//Description
|
||||
String getItemValueSql = "select item from uf_pd_item_inf where id =?";//uf_pd_item_inf
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
boolean b2 = recordSet1.executeQuery(getItemValueSql, itemId);
|
||||
logger.info("查询item值sql是否执行成功=" + b2);
|
||||
String item = "";//从数据库中查询到item的值
|
||||
if (recordSet1.next()) {
|
||||
item = recordSet1.getString("Item");
|
||||
}
|
||||
String categoryId = rs02.getString("Category");//Bandwidth
|
||||
String getCategoryByIdSql = "select category from uf_pd_category_inf where id = ?";//uf_pd_category_inf
|
||||
boolean b3 = recordSet1.executeQuery(getCategoryByIdSql, categoryId);
|
||||
logger.info("查询categorySql是否执行成功==" + b3);
|
||||
String category = "";
|
||||
if (recordSet1.next()) {
|
||||
category = recordSet1.getString("category");
|
||||
}
|
||||
String otc_price = rs02.getString("otc_price");//OTC in RMB
|
||||
String mrc_price = rs02.getString("mrc_price");//MRC in RMB
|
||||
String otc_relief_requested = rs02.getString("otc_relief_requested");//Relief Requested (%)OTC
|
||||
String mrc_relief_requested = rs02.getString("mrc_relief_requested");//Relief Requested (%)MRC
|
||||
String otc_relief_approved = rs02.getString("otc_relief_approved");//Relief SST approved (%)OTC
|
||||
String mrc_relief_approved = rs02.getString("mrc_relief_approved");//Relief SST approved (%)MRC
|
||||
String otc_tariff = rs02.getString("otc_tariff");//Tariff to SST (include VAT)(OTC in RMB)
|
||||
String mrc_tariff = rs02.getString("mrc_tariff");//Tariff to SST (include VAT)(MRC in RMB)
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
list.add(site);
|
||||
list.add(item);
|
||||
list.add(category);
|
||||
list.add(otc_price);
|
||||
list.add(mrc_price);
|
||||
list.add(otc_relief_requested);
|
||||
list.add(mrc_relief_requested);
|
||||
list.add(otc_relief_approved);
|
||||
list.add(mrc_relief_approved);
|
||||
list.add(otc_tariff);
|
||||
list.add(mrc_tariff);
|
||||
detailDateList.add(list);
|
||||
}
|
||||
}
|
||||
Double amount10 = 0D;//用来统计每一个site种类的 Sub-Total
|
||||
Double amount9 = 0D;
|
||||
|
||||
//得到list类型的数据、有得到每种site类型的数据长度
|
||||
//开始向excel中导入明细表中的数据
|
||||
int k = 0;//用它来增加detailDateList的下标
|
||||
for (int cowNum = firstCow; cowNum < firstCow + cowLength; cowNum++) {
|
||||
Row row = sheet.createRow(cowNum);
|
||||
for (int colNum = 0; colNum < 11; colNum++) {
|
||||
if (colNum == 10) {
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != ""){
|
||||
Double value = Double.valueOf(s);
|
||||
amount10 = amount10 + value;
|
||||
sum10 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}else if (colNum == 9){
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != "") {
|
||||
Double value = Double.valueOf(s);
|
||||
amount9 = amount9 + value;
|
||||
sum9 += value;
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
if (colNum == 5 || colNum == 6 || colNum == 7 || colNum == 8) {
|
||||
Cell cell = row.createCell(colNum);
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s!=""){
|
||||
Double value = Double.valueOf(s);
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue((int)(value * 100) + "%");
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
} else if (colNum == 3 || colNum==4){
|
||||
String s = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (s != ""){
|
||||
Double value = Double.valueOf(s);
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setCellToNumber(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
Cell cell = row.createCell(colNum);
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
}
|
||||
else if (colNum == 0||colNum==1||colNum==2){
|
||||
Cell cell = row.createCell(colNum);
|
||||
String value = String.valueOf(detailDateList.get(k).get(colNum));
|
||||
if (value!=""){
|
||||
cell.setCellStyle(setWordStyle(workbook));
|
||||
cell.setCellValue(value);
|
||||
}else {
|
||||
cell.setCellStyle(setNolyBorderStyle(workbook));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
k++;
|
||||
}
|
||||
//合并单元格
|
||||
int lastCow = firstCow + cowLength;
|
||||
|
||||
if (cowLength > 1) {
|
||||
sheet.addMergedRegion(new CellRangeAddress(firstCow, lastCow - 1, 0, 0));
|
||||
}
|
||||
//开始写入Sub-Total(RMB)
|
||||
Row rowSubTotal = sheet.createRow(lastCow);
|
||||
Cell cellSubToTal10 = rowSubTotal.createCell(10);
|
||||
cellSubToTal10.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal10.setCellValue(amount10);
|
||||
|
||||
Cell cellSubToTal9 = rowSubTotal.createCell(9);
|
||||
cellSubToTal9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal9.setCellValue(amount9);
|
||||
|
||||
Cell cellSubToTal8 = rowSubTotal.createCell(8);
|
||||
cellSubToTal8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellSubToTal8.setCellValue("Sub-Total");
|
||||
|
||||
|
||||
firstCow = firstCow + cowLength + 1;
|
||||
finalyCow = firstCow;
|
||||
|
||||
}
|
||||
Row rowFinalyCow = sheet.createRow(finalyCow);
|
||||
Cell cellFinalyCow_10 = rowFinalyCow.createCell(10);
|
||||
cellFinalyCow_10.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_10.setCellValue(sum10);
|
||||
Cell cellFinalyCow_9 = rowFinalyCow.createCell(9);
|
||||
cellFinalyCow_9.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_9.setCellValue(sum9);
|
||||
Cell cellFinalyCow_8 = rowFinalyCow.createCell(8);
|
||||
cellFinalyCow_8.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
cellFinalyCow_8.setCellValue("Grand-Total (RMB)");
|
||||
|
||||
|
||||
//输入最下面的固定值
|
||||
String[] lastStringright = new String[]{
|
||||
"Notes:",
|
||||
"1.This form should be submitted by Lead ICB via a ROME WR to \"AP Pricing Team\". Do NOT send this direct to SST.",
|
||||
"2.Fill in full Site Address or at least provide Name of City.",
|
||||
"3.Tariff relief requested should be calculated by lead ICB. Do not fill in target AVPN discount as \"Relief Requested\".",
|
||||
"4.VPN Tariff is port base pricing, no charges on COS or COS profile.",
|
||||
"5.AT&T GAM will place order to SST on no longer than 12 months term for Custom Subcontract, regardless of the commitment term between end customer and AT&T.",
|
||||
"6.China VAT is irrecoverable cost to AT&T under custom subcontracting billing. Ttariff and Access price listed below is VAT inclusive. ICB has to cater for this cost in deal financials.",
|
||||
"7.Tariff Relief is only applicable to the demand set listed below, any changes in bandwidth/design/billing model, need to re-submit to SST for approval;",
|
||||
};
|
||||
int lastLineTag = finalyCow + 2;//固定值Note所在的行
|
||||
int h=0;
|
||||
for (int rowNum=lastLineTag;rowNum<lastLineTag+8;rowNum++){
|
||||
Row row = sheet.createRow(rowNum);
|
||||
Cell cell = row.createCell(0);
|
||||
cell.setCellStyle(setNolyWordStyle(workbook,true));
|
||||
sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 11));
|
||||
cell.setCellValue(lastStringright[h]);
|
||||
h++;
|
||||
}
|
||||
sheet.autoSizeColumn(0,true);
|
||||
sheet.setColumnWidth(0,sheet.getColumnWidth(0)*8/10);
|
||||
// 设置自动列宽
|
||||
for (int num = 1; num < 11; num++) {
|
||||
sheet.autoSizeColumn(num,true);
|
||||
sheet.setColumnWidth(num, (sheet.getColumnWidth(num)));
|
||||
}
|
||||
|
||||
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
|
||||
header = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String(L3NSFileName.getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
} catch (IOException e) {
|
||||
logger.error("导出excel错误:" + Util.getErrString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h2>返回系统当前日期时间</h2>
|
||||
* @param
|
||||
* @return String 当前日期
|
||||
* @author hcy
|
||||
*/
|
||||
public String getCurrentTime(){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
String currentTime = dateFormat.format(date);
|
||||
return currentTime;
|
||||
}
|
||||
/**
|
||||
* 设置每个单元格的样式,并且加粗字体,设置边框
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook, Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setWordStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyWordStyle(Workbook workbook,Boolean setBold) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
font.setBold(setBold);
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只设置字体样式
|
||||
*
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setNolyBorderStyle(Workbook workbook) {
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单元格格式为数值型
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static CellStyle setCellToNumber(Workbook workbook){
|
||||
// 设置字体
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//设置样式对象,这里仅设置了边框属性
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
|
||||
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
||||
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);//上边框
|
||||
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
||||
Font font = workbook.createFont();
|
||||
//颜色
|
||||
font.setColor(Font.COLOR_NORMAL);
|
||||
//设置字体大小
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
//字体
|
||||
font.setFontName("微软雅黑");
|
||||
cellStyle.setFont(font);
|
||||
DataFormat dataFormat = workbook.createDataFormat();//此处设置数据格式
|
||||
cellStyle.setDataFormat(dataFormat.getFormat("0.00_ "));
|
||||
return cellStyle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel.SheetCMRPOI;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel.SheetCostPOI;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.exportotherexcel.SheetQuotationPOI;
|
||||
import com.api.chaoyang.he.hcy_xintiantongxin.projectorder.service.ExportExcelOtherService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ExportExcelOtherServiceImpl implements ExportExcelOtherService {
|
||||
|
||||
/**
|
||||
*获取其他产品uf_other_export表中的数据,渲染到sheet1---CMR中
|
||||
*/
|
||||
private final SheetCMRPOI sheetCMRPOI = new SheetCMRPOI();
|
||||
/**
|
||||
* 获取其他产品uf_other_export表中的数据,渲染到sheet2---Quotation中
|
||||
*/
|
||||
private final SheetQuotationPOI sheetQuotationPOI = new SheetQuotationPOI();
|
||||
/**
|
||||
* 获取其他产品uf_other_export表中的数据,渲染到sheet3---Cost中
|
||||
*/
|
||||
private final SheetCostPOI sheetCostPOI = new SheetCostPOI();
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
public Response exportExcelOther(String ids,String otherFileName) {
|
||||
logger.info("ExportExcelOtherServiceImpl----开始");
|
||||
Response build = null;
|
||||
Response.ResponseBuilder header = null;
|
||||
StreamingOutput output = null;
|
||||
String[] split = ids.split(",");
|
||||
|
||||
//创建一个工作簿
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
//创建一个工作表sheet
|
||||
|
||||
sheetCMRPOI.setSheetCMR(workbook,split);//创建第一个sheet1---sheet_CMR,并向sheet中渲染内容
|
||||
sheetQuotationPOI.setQuotationSheet(workbook,split);//创建第二个sheet2---sheet_Quotation,并向sheet中渲染内容
|
||||
sheetCostPOI.getSheetCost(workbook,split);//创建第三个sheet3---sheet_Cost,并向sheet中渲染内容
|
||||
try {
|
||||
InputStream inputStream = workbookConvertorStream(workbook);
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
output = outputStream -> {
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
header = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM)
|
||||
.type("application/xlsx")
|
||||
.header("Content-Disposition",
|
||||
"attachment; filename=\""+ new String(otherFileName.getBytes("GBK"), StandardCharsets.ISO_8859_1)+"\"");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
build = header.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h2>返回系统当前日期时间</h2>
|
||||
* @param
|
||||
* @return String 当前日期
|
||||
* @author hcy
|
||||
*/
|
||||
public String getCurrentTime(){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
/**
|
||||
* SXSSFWorkbook 转 InputStream
|
||||
* @param workbook
|
||||
* @return
|
||||
*/
|
||||
public static InputStream workbookConvertorStream(Workbook workbook) {
|
||||
InputStream in = null;
|
||||
try{
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
//创建临时文件
|
||||
workbook.write(out);
|
||||
byte [] bookByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(bookByteAry);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.action;
|
||||
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.service.TbSheetService;
|
||||
import weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.service.impl.TbSheetServiceImpl;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.DetailTable;
|
||||
import weaver.soa.workflow.request.DetailTableInfo;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>询价单调达担当节点后附加操作</h1>
|
||||
* @Author jiacheng.deng
|
||||
* @Date 2022/12/27 14:41
|
||||
*/
|
||||
public class TbSheetAction implements Action {
|
||||
|
||||
private static TbSheetService tbSheetService = new TbSheetServiceImpl();
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>重写execute,获取明细数据</h2>
|
||||
* @param requestInfo
|
||||
* @return null
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
|
||||
try {
|
||||
DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo();
|
||||
DetailTable[] detailTable = detailTableInfo.getDetailTable();
|
||||
List<Map<String, Object>> detailData = tbSheetService.getDetailData(requestInfo);
|
||||
for (Map<String, Object> stringObjectMap : detailData) {
|
||||
String chbm = (String) stringObjectMap.get("chbm");
|
||||
if("".equals(chbm)){
|
||||
tbSheetService.insertTbDetailDataToLedger(stringObjectMap,requestInfo);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(Util.getErrString(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class TbDetailData {
|
||||
|
||||
|
||||
/** 存货编码 */
|
||||
public String chbm;
|
||||
|
||||
/** 控制明细只读字段 */
|
||||
public int kzmxzdzd;
|
||||
|
||||
/** 品类 */
|
||||
public int pl;
|
||||
|
||||
/** 品名 */
|
||||
public String pm;
|
||||
|
||||
/** 品牌 */
|
||||
public String pp;
|
||||
|
||||
/** 规格型号 */
|
||||
public String ggxh;
|
||||
|
||||
/** 计量单位 */
|
||||
public String jldw;
|
||||
|
||||
/** 存货属性 */
|
||||
public int chzx;
|
||||
|
||||
/** 未税单价*/
|
||||
public float wsdj;
|
||||
|
||||
/** 税率 */
|
||||
public int sl;
|
||||
|
||||
/** 含税单价 */
|
||||
public float hsdj;
|
||||
|
||||
/** 供应商 */
|
||||
public String gys;
|
||||
|
||||
/** 纳期 */
|
||||
public int ddhfqwnqt;
|
||||
|
||||
/** 说明 */
|
||||
public String bz1;
|
||||
|
||||
/** 附件*/
|
||||
public String fj;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.Insert;
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SqlMapper
|
||||
public interface TbSheetMapper {
|
||||
|
||||
@Select("select id,chbm,kzmxzdzd,pl,pm,pp,ggxh,jldw,chzx,wsdj,sl,hsdj,ddhfqwnqt,bz1,fj from formtable_main_35_dt1 where mainid = #{mainid}")
|
||||
List<Map<String,Object>> getDetailDatas(@ParamMapper("mainid") String mainId);
|
||||
|
||||
@Insert("insert into uf_chtz_tbtj(chbm,kzmxzdzd,pl,pm,pp,ggxh,jldw,chzx,wsdj,sl,hsdj,gys,ddhfqwnqt,bz1,fj) values(#{chbm},#{kzmxzdzd},#{pl},#{pm},#{pp},#{ggxh},#{jldw},#{chzx},#{wsdj},#{sl},#{hsdj},#{gys},#{ddhfqwnqt},#{bz1},#{fj})")
|
||||
void insertDetailData(@ParamMapper("chbm") String chbm,
|
||||
@ParamMapper("kzmxzdzd") int kzmxzdzd,
|
||||
@ParamMapper("pl") int pl,
|
||||
@ParamMapper("pm") String pm,
|
||||
@ParamMapper("pp") String pp,
|
||||
@ParamMapper("ggxh") String ggxh,
|
||||
@ParamMapper("jldw") String jldw,
|
||||
@ParamMapper("chzx") int chzx,
|
||||
@ParamMapper("wsdj") float wsdj,
|
||||
@ParamMapper("sl") int sl,
|
||||
@ParamMapper("hsdj") float hsdj,
|
||||
@ParamMapper("gys") String gys,
|
||||
@ParamMapper("ddhfqwnqt") int ddhfqwnqt,
|
||||
@ParamMapper("bz1") String bz1,
|
||||
@ParamMapper("fj") String fj);
|
||||
|
||||
@Select("select id from formtable_main_35 where requestid = #{requestid}")
|
||||
String getMainTableId(@ParamMapper("requestid") String requestId);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.service;
|
||||
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface TbSheetService {
|
||||
|
||||
|
||||
List<Map<String, Object>> getDetailData(RequestInfo requestInfo);
|
||||
|
||||
void insertTbDetailDataToLedger(Map<String, Object> stringObjectMap,RequestInfo requestInfo);
|
||||
|
||||
String getMainTableId(String requestId);
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.mapper.TbSheetMapper;
|
||||
import weaver.chaoyang.he.fengtianfangzhi.djc.tayota.boshoku.service.TbSheetService;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.soa.workflow.request.Property;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>Action逻辑处理</h1>
|
||||
* @Author jiacheng.deng
|
||||
* @Date 2022/12/27 14:42
|
||||
*/
|
||||
public class TbSheetServiceImpl implements TbSheetService {
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
TbSheetMapper tbSheetMapper = Util.getMapper(TbSheetMapper.class);
|
||||
|
||||
/**
|
||||
* <h2>获取明细数据</h2>
|
||||
* @param requestInfo
|
||||
* @return list
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getDetailData(RequestInfo requestInfo) {
|
||||
|
||||
String mainId = this.getMainTableId(requestInfo.getRequestid());
|
||||
log.info("main table id is :" + mainId);
|
||||
List<Map<String, Object>> detailDatas = tbSheetMapper.getDetailDatas(mainId);
|
||||
log.info(JSON.toJSONString(detailDatas));
|
||||
return detailDatas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>将明细数据插入台账</h2>
|
||||
* @param stringObjectMap,requestInfo
|
||||
* @return void
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@Override
|
||||
public void insertTbDetailDataToLedger(Map<String, Object> stringObjectMap,RequestInfo requestInfo) {
|
||||
|
||||
List<Object> list = new ArrayList<>();
|
||||
|
||||
Map<String, String> wfMainTableInfo = this.getWfMainTableInfo(requestInfo);
|
||||
String gys = wfMainTableInfo.get("gys");
|
||||
log.info("main table gys is :" + gys);
|
||||
|
||||
String chbm = "12345";
|
||||
|
||||
list.add(chbm);
|
||||
list.add(stringObjectMap.get("kzmxzdzd"));
|
||||
list.add(stringObjectMap.get("pl"));
|
||||
list.add(stringObjectMap.get("pm"));
|
||||
list.add(stringObjectMap.get("pp"));
|
||||
list.add(stringObjectMap.get("ggxh"));
|
||||
list.add(stringObjectMap.get("jldw"));
|
||||
list.add(stringObjectMap.get("chzx"));
|
||||
list.add(stringObjectMap.get("wsdj"));
|
||||
list.add(stringObjectMap.get("sl"));
|
||||
list.add(stringObjectMap.get("hsdj"));
|
||||
list.add(gys);
|
||||
list.add(stringObjectMap.get("ddhfqwnqt"));
|
||||
list.add(stringObjectMap.get("bz1"));
|
||||
list.add(stringObjectMap.get("fj"));
|
||||
|
||||
String stringsql = "insert into uf_chtz_tbtj(chbm,kzmxzdzd,pl,pm,pp,ggxh,jldw,chzx,wsdj,sl,hsdj,gys,ddhfqwnqt,bz1,fj) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
|
||||
boolean b = recordSet.executeUpdate(stringsql, list);
|
||||
|
||||
log.info("recordSet是否执行:" + b);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取主表id</h2>
|
||||
* @param requestId
|
||||
* @return mainTableId
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@Override
|
||||
public String getMainTableId(String requestId) {
|
||||
String mainTableId = tbSheetMapper.getMainTableId(requestId);
|
||||
return mainTableId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程主表数据
|
||||
*
|
||||
* @param requestInfo 流程信息对象
|
||||
* @return Map<String, String> key 字段名 value 字段值
|
||||
*/
|
||||
public Map<String, String> getWfMainTableInfo(RequestInfo requestInfo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Property property : requestInfo.getMainTableInfo().getProperty()) {
|
||||
map.put(property.getName(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package weaver.chaoyang.he.fengtianfangzhi.tbsheet.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TBSheetAction implements Action {
|
||||
public Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
String requestid = requestInfo.getRequestid();
|
||||
String sql = "select id,gys from formtable_main_35 where requestId = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(sql, requestid);
|
||||
logger.info("sql是否执行=="+b);
|
||||
String mainId = "";
|
||||
String gys = "";
|
||||
if (recordSet.next()){
|
||||
mainId = recordSet.getString("id");
|
||||
gys = recordSet.getString("gys");
|
||||
}
|
||||
|
||||
String detailSql = "select * from formtable_main_35_dt1 where mainId = ?";
|
||||
boolean b1 = recordSet.executeQuery(detailSql, mainId);
|
||||
logger.info("b1是否执行=="+b1);
|
||||
|
||||
List<Map<String,Object>> listMap = new ArrayList<>();
|
||||
while (recordSet.next()){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
/** 存货编码 */
|
||||
String chbm = recordSet.getString("chbm");
|
||||
map.put("chbm",chbm);
|
||||
/** 控制明细只读字段 */
|
||||
String kzmxzdzd = recordSet.getString("kzmxzdzd");
|
||||
map.put("kzmxzdzd",kzmxzdzd);
|
||||
/** 品类 */
|
||||
String pl = recordSet.getString("pl");
|
||||
map.put("pl",pl);
|
||||
/** 品名 */
|
||||
String pm = recordSet.getString("pm");
|
||||
map.put("pm",pm);
|
||||
/** 品牌 */
|
||||
String pp = recordSet.getString("pp");
|
||||
map.put("pp",pp);
|
||||
/** 规格型号 */
|
||||
String ggxh = recordSet.getString("ggxh");
|
||||
map.put("ggxh",ggxh);
|
||||
/** 计量单位 */
|
||||
String jldw = recordSet.getString("jldw");
|
||||
map.put("jldw",jldw);
|
||||
/** 存货属性 */
|
||||
String chzx = recordSet.getString("chzx");
|
||||
map.put("chzx",chzx);
|
||||
/** 未税单价*/
|
||||
String wsdj = recordSet.getString("wsdj");
|
||||
map.put("wsdj",wsdj);
|
||||
/** 税率 */
|
||||
String sl = recordSet.getString("sl");
|
||||
map.put("sl",sl);
|
||||
/** 含税单价 */
|
||||
String hsdj = recordSet.getString("hsdj");
|
||||
map.put("hsdj",hsdj);
|
||||
// /** 供应商 */
|
||||
// String gys = recordSet.getString("gys");
|
||||
// map.put("gys",gys);
|
||||
/** 纳期 */
|
||||
String ddhfqwnqt = recordSet.getString("ddhfqwnqt");
|
||||
map.put("ddhfqwnqt",ddhfqwnqt);
|
||||
/** 说明 */
|
||||
String bz11 = recordSet.getString("bz1");
|
||||
map.put("bz11",bz11);
|
||||
/**附件*/
|
||||
String fj = recordSet.getString("fj");
|
||||
map.put("fj",fj);
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
String id = recordSet.getString("id");
|
||||
map.put("gys",gys);
|
||||
map.put("id",id);
|
||||
|
||||
listMap.add(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (Map<String, Object> map : listMap) {
|
||||
String chbm = String.valueOf(map.get("chbm"));
|
||||
if (chbm.equals("")){
|
||||
List<Object> list = new ArrayList<>();
|
||||
String stringsql = "insert into uf_chtz_tbtj(chbm,pl,pm,pp,ggxh,jldw,chzx,wsdj,sl,hsdj,nqt,gys,sm,fj) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
chbm = "12345";
|
||||
list.add(chbm);//chbm-chbm
|
||||
list.add(map.get("pl"));//pl-pl
|
||||
list.add(map.get("pm"));//pm-pm
|
||||
list.add(map.get("pp"));//pp-pp
|
||||
list.add(map.get("ggxh"));//ggxh-ggxh
|
||||
list.add(map.get("jldw"));//jldw-jldw
|
||||
list.add(map.get("chzx"));//chzx-chzx
|
||||
list.add(map.get("wsdj"));//wsdj-wsdj
|
||||
list.add(map.get("sl"));//sl-sl
|
||||
list.add(map.get("hsdj"));//hsdj-hsdj
|
||||
list.add(map.get("qwnq"));//nqt-qwnq
|
||||
list.add(map.get("gys"));//gys-gys
|
||||
list.add(map.get("bz1"));//sm-bz1
|
||||
list.add(map.get("fj"));//fj-fj
|
||||
|
||||
boolean b2 = recordSet.executeUpdate(stringsql, list);
|
||||
logger.info("b2是否执行=="+b2);
|
||||
String id = String.valueOf(map.get("id"));
|
||||
if (b2){
|
||||
String afterSuccessInsertSql = "insert into formtable_main_35_dt1 (chbm) values (?) where id = ?";
|
||||
boolean b3 = recordSet.executeUpdate(afterSuccessInsertSql, chbm, id);
|
||||
logger.info("b3是否执行=="+b3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package weaver.chaoyang.he.formmode.customjavacode.modeexpand;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChangeState extends AbstractModeExpandJavaCodeNew {
|
||||
private Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public Map<String, String> doModeExpand(Map<String, Object> map) {
|
||||
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
logger.info(key+":"+value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package weaver.chaoyang.he.formmode.customjavacode.modeexpand;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
|
||||
import weaver.hrm.User;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModeExpandTemplate extends AbstractModeExpandJavaCodeNew {
|
||||
private Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public Map<String, String> doModeExpand(Map<String, Object> param) {
|
||||
|
||||
// for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// Object value = entry.getValue();
|
||||
// logger.info(key+":"+value);
|
||||
// }
|
||||
// return null;
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
try {
|
||||
User user = (User)param.get("user");
|
||||
int billid = -1;//数据id
|
||||
int modeid = -1;//模块id
|
||||
RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo");
|
||||
if(requestInfo!=null){
|
||||
billid = weaver.general.Util.getIntValue(requestInfo.getRequestid());
|
||||
modeid = weaver.general.Util.getIntValue(requestInfo.getWorkflowid());
|
||||
if(billid>0&&modeid>0){
|
||||
//------请在下面编写业务逻辑代码------
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.put("errmsg","自定义出错信息");
|
||||
result.put("flag", "false");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package weaver.chaoyang.he.formmode.interfaces.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.file.ExcelParseForPOI;
|
||||
import weaver.formmode.interfaces.ImportPreInterfaceForPOIAction;
|
||||
import weaver.hrm.User;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>在excel导入前校验字段是否符合要求</h1>
|
||||
* hcy
|
||||
* 2023/4/13 8:50
|
||||
*/
|
||||
public class CheckFieldTemplate implements ImportPreInterfaceForPOIAction {
|
||||
|
||||
//日志
|
||||
private final Logger logger = Util.getLogger();
|
||||
//sql
|
||||
private final CheckFieldTemplateMapper checkFieldTemplateMap = Util.getMapper(CheckFieldTemplateMapper.class);
|
||||
|
||||
@Override
|
||||
public String checkImportData(Map<String, Object> param, User user, ExcelParseForPOI excelParse) {
|
||||
|
||||
|
||||
//从配置表中查询到数据
|
||||
List<Map<String, Object>> configData = checkFieldTemplateMap.getConfigurationTable();
|
||||
logger.info("configData===="+configData);
|
||||
int rowSum = excelParse.getRowSum("1", 2,Util.getIntValue(Util.null2String(configData.get(0).get("bgjtnyl"))));
|
||||
logger.info("rowSum==="+rowSum);
|
||||
//获取建模表单里面所有的数据
|
||||
List<Map<String, Object>> dbDataMapList = checkFieldTemplateMap.getDBDataMapList();
|
||||
logger.info("dbDataMapList===="+dbDataMapList);
|
||||
|
||||
logger.info("dbDataMapList===="+dbDataMapList);
|
||||
for (Map<String, Object> configDatum : configData) {
|
||||
int colNum = Util.getIntValue(Util.null2String(configDatum.get("bgjtnyl")));//具体那一列
|
||||
logger.info("colNum==="+colNum);
|
||||
String targetValue = Util.null2String(configDatum.get("dyjmbdjtzdsjkm"));//建模表单中具体哪个字段名称
|
||||
logger.info("targetValue==="+targetValue);
|
||||
// int rowSum = excelParse.getRowSum("1", 100,colNum);
|
||||
|
||||
for (int i = 2; i < 2+rowSum; i++) {
|
||||
//获取第 sheetindex 个sheet的第row行第col列的单元格的值 (下标都是从1开始)
|
||||
String value = excelParse.getValue("1", i, colNum);
|
||||
logger.info("value==="+value);
|
||||
//开始比较数据是否正确
|
||||
boolean compareBool = compareValue(dbDataMapList,value,targetValue);
|
||||
logger.info("compareBool==="+compareBool);
|
||||
if (!compareBool) {
|
||||
//书写校验逻辑 返回空则表示校验通过,否则验证不通过,不允许导入
|
||||
return "第"+i+"行第"+(colNum) + "列的数据不符合要求";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private Boolean compareValue(List<Map<String, Object>> dbDataMapList, String value,String targetValue) {
|
||||
for (Map<String, Object> map : dbDataMapList) {
|
||||
String targetValueString = Util.null2String(map.get(targetValue));
|
||||
if (targetValueString.equals(value)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package weaver.chaoyang.he.formmode.interfaces.impl;
|
||||
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface CheckFieldTemplateMapper {
|
||||
|
||||
@Select("select * from uf_dept")
|
||||
List<Map<String,Object>> getDBDataMapList();
|
||||
|
||||
|
||||
@Select("select * from uf_exceldrzddypzb_dt1 where mainid in (select id from uf_exceldrzddypzb where wybs = 'fw001') ")
|
||||
List<Map<String, Object>> getConfigurationTable();
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package weaver.chaoyang.he.formmode.interfaces.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.formmode.interfaces.ExportFieldTransAction;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>TBTJ-询价单明细台账更新到处状态</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/1/31 13:09
|
||||
*/
|
||||
public class ExportFieldTransTemplate implements ExportFieldTransAction{
|
||||
|
||||
private Logger logger = aiyh.utils.Util.getLogger();
|
||||
|
||||
@Override
|
||||
public String getTransValue(Map<String, Object> param,User user) {
|
||||
// 获取当前登录人员ID
|
||||
Integer userId = user.getUID();
|
||||
logger.info(JSON.toJSONString(param));
|
||||
// 获取模块ID
|
||||
Integer modeId = Util.getIntValue(param.get("modeid").toString());
|
||||
//表单id
|
||||
Integer formId = Util.getIntValue(param.get("formid").toString());
|
||||
//当前字段id
|
||||
String fieldid = Util.null2String(param.get("fieldid"));
|
||||
//查询列表id
|
||||
String customid = Util.null2String(param.get("customid"));
|
||||
//当前列名称(明细表会有d_前缀)
|
||||
String columnname = Util.null2String(param.get("columnname"));
|
||||
//当前列数据
|
||||
String value = Util.null2String(param.get("value"));
|
||||
|
||||
Map data1 = (Map) param.get("data");
|
||||
String mxid = String.valueOf(data1.get("d_mxid"));
|
||||
String mainId = String.valueOf(data1.get("id"));
|
||||
this.updateValueIntoDB(mainId,mxid);
|
||||
//当前行数据
|
||||
Map data = (Map) param.get("data");
|
||||
|
||||
new BaseBean().writeLog(userId+" "+modeId+" "+formId+" "+fieldid+" "+customid+" "+columnname+" "+value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>update导出状态为已导出</h2>
|
||||
* @param mainId,id
|
||||
* @return
|
||||
* @author hcy
|
||||
*/
|
||||
public void updateValueIntoDB(String mainId,String mxid){
|
||||
// String updateSql = "update formtable_main_99_dt1 set dczt = ? where mainId = ? and mxid = ?";
|
||||
String updateSql = "update uf_xjdmx_dt1 set dczt = ? where mainId = ? and mxid = ?";
|
||||
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeUpdate(updateSql, "0", mainId,mxid);
|
||||
logger.info("updateSql是否导出=="+b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package weaver.chaoyang.he.formmode.interfaces.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.formmode.interfaces.ExportFieldTransAction;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>TBTJ-询价单明细台账更新到处状态</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/1/31 13:09
|
||||
*/
|
||||
public class ExportFieldTransTemplate_copy implements ExportFieldTransAction{
|
||||
|
||||
private Logger logger = aiyh.utils.Util.getLogger();
|
||||
|
||||
@Override
|
||||
public String getTransValue(Map<String, Object> param,User user) {
|
||||
// 获取当前登录人员ID
|
||||
Integer userId = user.getUID();
|
||||
logger.info(JSON.toJSONString(param));
|
||||
// 获取模块ID
|
||||
Integer modeId = Util.getIntValue(param.get("modeid").toString());
|
||||
//表单id
|
||||
Integer formId = Util.getIntValue(param.get("formid").toString());
|
||||
//当前字段id
|
||||
String fieldid = Util.null2String(param.get("fieldid"));
|
||||
//查询列表id
|
||||
String customid = Util.null2String(param.get("customid"));
|
||||
//当前列名称(明细表会有d_前缀)
|
||||
String columnname = Util.null2String(param.get("columnname"));
|
||||
//当前列数据
|
||||
String value = Util.null2String(param.get("value"));
|
||||
|
||||
Map data1 = (Map) param.get("data");
|
||||
String mxid = String.valueOf(data1.get("d_mxid"));
|
||||
String mainId = String.valueOf(data1.get("id"));
|
||||
this.updateValueIntoDB(mainId,mxid);
|
||||
//当前行数据
|
||||
Map data = (Map) param.get("data");
|
||||
|
||||
new BaseBean().writeLog(userId+" "+modeId+" "+formId+" "+fieldid+" "+customid+" "+columnname+" "+value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>update导出状态为已导出</h2>
|
||||
* @param mainId,id
|
||||
* @return
|
||||
* @author hcy
|
||||
*/
|
||||
public void updateValueIntoDB(String mainId,String mxid){
|
||||
String updateSql = "update formtable_main_99_dt1 set dczt = ? where mainId = ? and mxid = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeUpdate(updateSql, "0", mainId,mxid);
|
||||
logger.info("updateSql是否导出=="+b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.Delete;
|
||||
import aiyh.utils.annotation.recordset.Insert;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface DeleteInvoiceNotApMapper {
|
||||
|
||||
/**
|
||||
* <h2>查询到发票用途为非AP的数据id</h2>
|
||||
* @return List<String> 包含数据id的list集合
|
||||
* @author hcy
|
||||
2023/3/21 10:09
|
||||
*/
|
||||
@Select("select id from fnainvoiceledger where fpyt = 1")
|
||||
List<String> selectIdByNotAP();
|
||||
|
||||
/**
|
||||
* <h2>根据数据id查询到数据</h2>
|
||||
* @param idNotAPList id组成的List集合
|
||||
* @return List<Map<String,Object>> data
|
||||
* @author hcy
|
||||
* 2023/3/21 10:19
|
||||
*/
|
||||
@Select("select * from fnainvoiceledger where id in ($t{idNotAPList})")
|
||||
List<Map<String, Object>> selectDataById(List<String> idNotAPList);
|
||||
|
||||
@Insert("insert into fnabackup (billingDate,invoiceCode,invoiceNumber," +
|
||||
"invoiceType,seller,purchaser,invoiceServiceYype,priceWithoutTax,taxRate," +
|
||||
"tax,taxIncludedPrice,authenticity,reimbursementDate,reimbursePerson,requestId,userid_new," +
|
||||
"invoiceSource_new,checkcode,status,card_id_new,encrypt_code_new,openid_new,wechatstatus,imageID,purchaserTaxNo," +
|
||||
"salesTaxNo,entryTime,company_seal,form_type,form_name,kind,ciphertext,category,imageDocId,checkStatus," +
|
||||
"updateOperate,cloudId,codeConfirm,numberConfirm,receiptor,reviewer,issuer,province,city,travel_tax,fylx," +
|
||||
"purp,iele,orf,hxjksflr,fpyt) " +
|
||||
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
boolean backupData(List<Object> dataList);
|
||||
|
||||
@Delete("delete from fnainvoiceledger where id = #{id}")
|
||||
boolean deleteDataById(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeleteInvoiceNotApService {
|
||||
|
||||
List<String> selectIdByNotAP();
|
||||
|
||||
boolean backupdate(List<String> idNotAPList);
|
||||
|
||||
boolean deleteDataById(List<String> idNotAPList);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.mapper.DeleteInvoiceNotApMapper;
|
||||
import weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.DeleteInvoiceNotApService;
|
||||
import weaver.conn.RecordSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeleteInvoiceNotApServiceImpl implements DeleteInvoiceNotApService {
|
||||
|
||||
|
||||
private final DeleteInvoiceNotApMapper deleteInvoiceNotApMapper = Util.getMapper(DeleteInvoiceNotApMapper.class);
|
||||
@Override
|
||||
public List<String> selectIdByNotAP() {
|
||||
return deleteInvoiceNotApMapper.selectIdByNotAP();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>备份数据</h2>
|
||||
* @param idNotAPList 需要备份数据的id
|
||||
* @return boolean
|
||||
* @author hcy
|
||||
* 2023/3/21 10:15
|
||||
*/
|
||||
public boolean backupdate(List<String> idNotAPList) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
for (String id : idNotAPList) {
|
||||
String backupDataSql = "INSERT INTO fnabackup (billingdate,\t\n" +
|
||||
"invoicenumber,\t\n" +
|
||||
"invoicecode,\n" +
|
||||
"invoicetype,\t\n" +
|
||||
"taxincludedprice,pricewithouttax,\t\n" +
|
||||
"tax,\n" +
|
||||
"purchaser,purchasertaxno,\t\n" +
|
||||
"seller,salestaxno,purp,hxjksflr,checkStatus,status,authenticity,fpyt,taxrate\n" +
|
||||
") SELECT \n" +
|
||||
"billingdate,\t\n" +
|
||||
"invoicenumber,\t\n" +
|
||||
"invoicecode,\n" +
|
||||
"invoicetype,\t\n" +
|
||||
"taxincludedprice,pricewithouttax,\t\n" +
|
||||
"tax,\n" +
|
||||
"purchaser,purchasertaxno,\t\n" +
|
||||
"seller,salestaxno,purp,hxjksflr,checkStatus,status,authenticity,fpyt,taxrate\n" +
|
||||
" FROM fnainvoiceledger WHERE id = ?";
|
||||
boolean backupBool = recordSet.executeUpdate(backupDataSql, id);
|
||||
if (!backupBool){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//开始备份数据
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据数据id删除数据</h2>
|
||||
* @param idNotAPList 数据id
|
||||
* @return boolean 是否删除成功
|
||||
* @author hcy
|
||||
* 2023/3/21 10:31
|
||||
*/
|
||||
public boolean deleteDataById(List<String> idNotAPList) {
|
||||
for (String id : idNotAPList) {
|
||||
boolean deleteBool = deleteInvoiceNotApMapper.deleteDataById(id);
|
||||
if (!deleteBool){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.web;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.DeleteInvoiceNotApService;
|
||||
import weaver.chaoyang.he.hcy_aphangxin.deleteinvoicenotap.service.impl.DeleteInvoiceNotApServiceImpl;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteInvoiceNotApAction extends BaseCronJob {
|
||||
|
||||
private final DeleteInvoiceNotApService deleteInvoiceNotAPservice = new DeleteInvoiceNotApServiceImpl();
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
public void execute() {
|
||||
//第一步查询fnainvoiceledger中每一条数据中发票用途是否为非AP
|
||||
List<String> idNotAPList = deleteInvoiceNotAPservice.selectIdByNotAP();
|
||||
//第二步:根据第一步查询到的数据id,将想要删除的数据备份到fnabackup表中
|
||||
boolean backupBool = deleteInvoiceNotAPservice.backupdate(idNotAPList);
|
||||
logger.info("数据备份是否成功==="+backupBool);
|
||||
if (backupBool){
|
||||
//第三步:开始删除数据
|
||||
boolean deleteBool = deleteInvoiceNotAPservice.deleteDataById(idNotAPList);
|
||||
if (deleteBool){
|
||||
logger.info("数据删除成功");
|
||||
}else {
|
||||
logger.info("数据删除失败");
|
||||
}
|
||||
}else{
|
||||
logger.info("数据备份失败,请重新操作");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
package weaver.chaoyang.he.hcy_dingxinjituan.sendfilebyftp.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.integration.util.FTPUtil;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Property;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.workflow.request.RequestManager;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SendFileByFTPAction implements Action {
|
||||
//ip
|
||||
private String SERVER;
|
||||
|
||||
//端口号
|
||||
private String PORT;
|
||||
|
||||
//用户名
|
||||
private String USERNAME;
|
||||
|
||||
//密码
|
||||
private String PASSWORD;
|
||||
|
||||
//上传的指定路径
|
||||
private String REMOTEDIRAPTH;
|
||||
|
||||
//日志
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
|
||||
RequestManager requestManager = requestInfo.getRequestManager();
|
||||
//获取当前流程附件的附件流
|
||||
Map<String, String> wfMainTableInfo = this.getWfMainTableInfo(requestInfo);
|
||||
String fj = wfMainTableInfo.get("fj");
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_imageFiledId = "select imagefileid,imagefilename from DocImageFile where docid = ? order by versionId";
|
||||
// Util.selectImageInfoByDocId()
|
||||
boolean b = recordSet.executeQuery(get_imageFiledId, fj);
|
||||
logger.info("get_imageFiledId是否执行===" + b);
|
||||
recordSet.next();
|
||||
String imagefileid = Util.null2String(recordSet.getString("imagefileid"));
|
||||
String imagefilename = Util.null2String(recordSet.getString("imagefilename"));
|
||||
logger.info("文件imagefileid为==="+imagefileid+" 文件名称为==="+imagefilename);
|
||||
int imagefileidInt;
|
||||
if (!"".equals(imagefileid)) {
|
||||
imagefileidInt = Integer.parseInt(imagefileid);
|
||||
} else {
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("附件上传ftp系统失败");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
InputStream is = ImageFileManager.getInputStreamById(imagefileidInt);
|
||||
if (is==null){
|
||||
logger.info("文件输入流为空");
|
||||
}else{
|
||||
logger.info("文件输入流不为空");
|
||||
}
|
||||
|
||||
try {
|
||||
if (is!=null){
|
||||
this.uploadFile(is, imagefilename);
|
||||
}else {
|
||||
logger.info("附件内容为空");
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("附件内容为空");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("附件上传失败,失败原因==="+e);
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("附件上传ftp系统失败");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
//上传文件到指定的ftp
|
||||
public void uploadFile(InputStream inputStream, String fileName) throws IOException {
|
||||
// FTPFileUtil fileUtil = new FTPFileUtil(SERVER,Util.getIntValue(PORT,21),USERNAME,PASSWORD);
|
||||
FTPUtil ftpUtil = new FTPUtil(SERVER,Util.getIntValue(PORT,21),USERNAME,PASSWORD);
|
||||
|
||||
if(!ftpUtil.isConnected()){
|
||||
ftpUtil.login();
|
||||
}
|
||||
|
||||
boolean isSuccess = ftpUtil.uploadFile(inputStream,fileName,REMOTEDIRAPTH);
|
||||
|
||||
if (isSuccess) {
|
||||
logger.info("文件上传成功");
|
||||
}else{
|
||||
logger.info("文件上传失败");
|
||||
}
|
||||
ftpUtil.logout();
|
||||
/*
|
||||
FTPClient ftpClient = new FTPClient();
|
||||
ftpClient.setControlEncoding("GBK");
|
||||
|
||||
try {
|
||||
ftpClient.connect(SERVER, Integer.parseInt(PORT));
|
||||
ftpClient.login(USERNAME, PASSWORD);
|
||||
ftpClient.enterLocalPassiveMode();
|
||||
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
|
||||
ftpClient.changeWorkingDirectory("/"+REMOTEDIRAPTH);
|
||||
boolean success = ftpClient.storeFile(fileName, inputStream);
|
||||
logger.info("文件上传是否成功==="+success);
|
||||
if (success) {
|
||||
logger.info("文件上传成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("文件上传失败的原因==="+e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (ftpClient.isConnected()) {
|
||||
ftpClient.logout();
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getSERVER() {
|
||||
return SERVER;
|
||||
}
|
||||
|
||||
public void setSERVER(String SERVER) {
|
||||
this.SERVER = SERVER;
|
||||
}
|
||||
|
||||
|
||||
public String getUSERNAME() {
|
||||
return USERNAME;
|
||||
}
|
||||
|
||||
public void setUSERNAME(String USERNAME) {
|
||||
this.USERNAME = USERNAME;
|
||||
}
|
||||
|
||||
public String getPASSWORD() {
|
||||
return PASSWORD;
|
||||
}
|
||||
|
||||
public void setPASSWORD(String PASSWORD) {
|
||||
this.PASSWORD = PASSWORD;
|
||||
}
|
||||
|
||||
public String getREMOTEDIRAPTH() {
|
||||
return REMOTEDIRAPTH;
|
||||
}
|
||||
|
||||
public void setREMOTEDIRAPTH(String REMOTEDIRAPTH) {
|
||||
this.REMOTEDIRAPTH = REMOTEDIRAPTH;
|
||||
}
|
||||
|
||||
public String getPORT() {
|
||||
return PORT;
|
||||
}
|
||||
|
||||
public void setPORT(String PORT) {
|
||||
this.PORT = PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程主表数据
|
||||
*
|
||||
* @param requestInfo 流程信息对象
|
||||
* @return Map<String, String> key 字段名 value 字段值
|
||||
*/
|
||||
public Map<String, String> getWfMainTableInfo(RequestInfo requestInfo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Property property : requestInfo.getMainTableInfo().getProperty()) {
|
||||
map.put(property.getName(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
package weaver.chaoyang.he.hcy_dingxinjituan.sendfilebyftp.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Property;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.workflow.request.RequestManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SendFileByFTPAction_copy implements Action {
|
||||
//ip
|
||||
private String SERVER;
|
||||
|
||||
//端口号
|
||||
private String PORT;
|
||||
|
||||
//用户名
|
||||
private String USERNAME;
|
||||
|
||||
//密码
|
||||
private String PASSWORD;
|
||||
|
||||
//上传的指定路径
|
||||
private String REMOTEDIRAPTH;
|
||||
|
||||
//日志
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
RequestManager requestManager = requestInfo.getRequestManager();
|
||||
|
||||
FTPClient ftp = new FTPClient();
|
||||
|
||||
try {
|
||||
//连接ftp
|
||||
if (!"".equals(PORT)){
|
||||
ftp.connect(SERVER, Integer.parseInt(PORT));
|
||||
}
|
||||
//登录
|
||||
ftp.login(USERNAME, PASSWORD);
|
||||
ftp.enterLocalPassiveMode();
|
||||
ftp.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
|
||||
//获取当前流程附件的附件流
|
||||
Map<String, String> wfMainTableInfo = this.getWfMainTableInfo(requestInfo);
|
||||
String fj = wfMainTableInfo.get("fj");
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String get_imageFiledId = "select imagefileid from DocImageFile where docid = ? order by versionId";
|
||||
boolean b = recordSet.executeQuery(get_imageFiledId, fj);
|
||||
logger.info("get_imageFiledId是否执行==="+b);
|
||||
recordSet.next();
|
||||
String imagefileid = Util.null2String(recordSet.getString("imagefileid"));
|
||||
int imagefileidInt ;
|
||||
if (!"".equals(imagefileid)){
|
||||
imagefileidInt = Integer.parseInt(imagefileid);
|
||||
}else {
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("附件上传ftp系统失败");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
InputStream is = ImageFileManager.getInputStreamById(imagefileidInt);
|
||||
String remoteFilePath = REMOTEDIRAPTH;//上传路径
|
||||
boolean uploaded = ftp.storeFile(remoteFilePath, is);//文件导入
|
||||
if (uploaded) {
|
||||
logger.info("File uploaded successfully");
|
||||
} else {
|
||||
logger.info("File uploaded fail!");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Error: " + ex.getMessage());
|
||||
logger.info("Error:"+ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("附件上传ftp系统失败");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
} finally {
|
||||
try {
|
||||
ftp.logout();
|
||||
ftp.disconnect();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
logger.info("Error:"+ex.getMessage());
|
||||
}
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getSERVER() {
|
||||
return SERVER;
|
||||
}
|
||||
|
||||
public void setSERVER(String SERVER) {
|
||||
this.SERVER = SERVER;
|
||||
}
|
||||
|
||||
|
||||
public String getUSERNAME() {
|
||||
return USERNAME;
|
||||
}
|
||||
|
||||
public void setUSERNAME(String USERNAME) {
|
||||
this.USERNAME = USERNAME;
|
||||
}
|
||||
|
||||
public String getPASSWORD() {
|
||||
return PASSWORD;
|
||||
}
|
||||
|
||||
public void setPASSWORD(String PASSWORD) {
|
||||
this.PASSWORD = PASSWORD;
|
||||
}
|
||||
|
||||
public String getREMOTEDIRAPTH() {
|
||||
return REMOTEDIRAPTH;
|
||||
}
|
||||
|
||||
public void setREMOTEDIRAPTH(String REMOTEDIRAPTH) {
|
||||
this.REMOTEDIRAPTH = REMOTEDIRAPTH;
|
||||
}
|
||||
|
||||
public String getPORT() {
|
||||
return PORT;
|
||||
}
|
||||
|
||||
public void setPORT(String PORT) {
|
||||
this.PORT = PORT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程主表数据
|
||||
*
|
||||
* @param requestInfo 流程信息对象
|
||||
* @return Map<String, String> key 字段名 value 字段值
|
||||
*/
|
||||
public Map<String, String> getWfMainTableInfo(RequestInfo requestInfo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Property property : requestInfo.getMainTableInfo().getProperty()) {
|
||||
map.put(property.getName(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.controller;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.service.CheckAndChangeValueService;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.service.impl.CheckAndChangeValueServiceImpl;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Cell;
|
||||
import weaver.soa.workflow.request.DetailTable;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.soa.workflow.request.Row;
|
||||
import weaver.workflow.request.RequestManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CheckAndChangeValueAction implements Action {
|
||||
/**
|
||||
* 校验字段、取uf_OfficeInventory表数据以及进行加减计算
|
||||
*/
|
||||
private final CheckAndChangeValueService checkAndChangeValueService = new CheckAndChangeValueServiceImpl();
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
RequestManager requestManager = requestInfo.getRequestManager();
|
||||
Map<String, List<Map<String, String>>> detailTableValue = getDetailTableValue(requestInfo);
|
||||
List<Map<String, String>> detailLists = detailTableValue.get("1");
|
||||
logger.info("detailLists==="+detailLists);
|
||||
Map<String, List<String>> checkMaps = checkAndChangeValueService.checkfield(detailLists);
|
||||
logger.info("checkMaps==="+checkMaps);
|
||||
if (checkMaps==null || checkMaps.size()==0){
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("后端代码异常");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
//开始校验字段是否符合要求
|
||||
for (Map.Entry<String, List<String>> entry : checkMaps.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
List<String> values = entry.getValue();
|
||||
if (!"".equals(key) && key.equals("lingyong")){
|
||||
for (String value : values) {
|
||||
if (value.equals("false")){
|
||||
logger.error("requestid:" + requestInfo.getRequestid() );
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("领用数量超过库存数量,请核对信息!");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
}
|
||||
}else if (!"".equals(key) && key.equals("tuihuan")){
|
||||
for (String value : values) {
|
||||
if (value.equals("false")){
|
||||
logger.error("requestid:" + requestInfo.getRequestid() );
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("退货数量超过实收数量,请核对信息!");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//开始更新台账数据
|
||||
checkAndChangeValueService.changeDBValue(detailLists);
|
||||
return Action.SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>获取所有明细数据</h2>
|
||||
*
|
||||
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||
*/
|
||||
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
|
||||
for (DetailTable detailTable : detailTableArr) {
|
||||
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||
detailDataList.put(detailTable.getId(), detailData);
|
||||
}
|
||||
return detailDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据明细表信息获取明细表数据</h2>
|
||||
*
|
||||
* @param detailTable 明细表对象
|
||||
* @return 明细表数据
|
||||
*/
|
||||
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||
Row[] rowArr = detailTable.getRow();
|
||||
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||
for (Row row : rowArr) {
|
||||
Cell[] cellArr = row.getCell();
|
||||
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
|
||||
for (Cell cell : cellArr) {
|
||||
String fieldName = cell.getName();
|
||||
String value = cell.getValue();
|
||||
rowData.put(fieldName, value);
|
||||
}
|
||||
detailData.add(rowData);
|
||||
}
|
||||
return detailData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
import aiyh.utils.annotation.recordset.Update;
|
||||
|
||||
|
||||
@SqlMapper
|
||||
public interface CheckAndChangeValueMapper {
|
||||
|
||||
/**
|
||||
* <h2>根据产品编号查询领用数量</h2>
|
||||
* @param id 产品编号
|
||||
* @return String 查询到的领用数量
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 10:36
|
||||
*/
|
||||
@Select("select lysl from uf_OfficeInventory where id = #{id}")
|
||||
String selectLysl(@ParamMapper("id") String id);
|
||||
|
||||
/**
|
||||
* <h2>更新领用数量</h2>
|
||||
* @param lysl 领用数量
|
||||
* @param id id
|
||||
* @return boolean update是否更新成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 10:30
|
||||
*/
|
||||
@Update("update uf_OfficeInventory set lysl = #{lysl} where id = #{id}")
|
||||
boolean updateLysl(@ParamMapper("lysl") String lysl,
|
||||
@ParamMapper("id") String id);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>根据产品编号查询退还数量</h2>
|
||||
* @param id id
|
||||
* @return String 查询到的退还数量
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 10:36
|
||||
*/
|
||||
@Select("select thsl from uf_OfficeInventory where id = #{id}")
|
||||
String selectThsl(@ParamMapper("id") String id);
|
||||
|
||||
|
||||
/**
|
||||
* <h2>更新退还数量</h2>
|
||||
* @param thsl 退还数量
|
||||
* @param id id
|
||||
* @return boolean update是否更新成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/17 10:30
|
||||
*/
|
||||
@Update("update uf_OfficeInventory set thsl = #{thsl} where id = #{id}")
|
||||
boolean updaThsl(@ParamMapper("thsl") String thsl,
|
||||
@ParamMapper("id") String id);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CheckAndChangeValueService {
|
||||
|
||||
public Map<String, List<String>> checkfield(List<Map<String, String>> detailLists);
|
||||
|
||||
public void changeDBValue(List<Map<String, String>> detailLists);
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.mapper.CheckAndChangeValueMapper;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.checkandchangevalue.action.service.CheckAndChangeValueService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CheckAndChangeValueServiceImpl implements CheckAndChangeValueService {
|
||||
|
||||
|
||||
private final CheckAndChangeValueMapper checkAndChangeValueMapper = Util.getMapper(CheckAndChangeValueMapper.class);
|
||||
private final Logger logger = Util.getLogger();
|
||||
/**
|
||||
* <h2>校验字段是否符合流程流转的需求</h2>
|
||||
* @param detailLists 明细表所有数据
|
||||
* @return boolean 不符合返回false
|
||||
* @author hcy
|
||||
* 2023/3/16 15:22
|
||||
*/
|
||||
public Map<String, List<String>> checkfield(List<Map<String, String>> detailLists) {
|
||||
try {
|
||||
Map<String, List<Map<String, String>>> detailMap = detailLists.stream().collect(Collectors.groupingBy(items -> items.get("ywlx")));
|
||||
List<String> booleanLingYong = new ArrayList<>();//用来存放 false 和 true 校验字段是否属于符合标准
|
||||
List<String> booleanTuiHuan = new ArrayList<>();//用来存放 false 和 true 校验字段是否属于符合标准
|
||||
|
||||
for (Map.Entry<String, List<Map<String, String>>> entry : detailMap.entrySet()) {
|
||||
String key = Util.null2String(entry.getKey());
|
||||
List<Map<String, String>> value = entry.getValue();
|
||||
if (key.equals("0")){
|
||||
Map<String, List<Map<String, String>>> cpbh = value.stream().collect(Collectors.groupingBy(items -> items.get("cpbh")));//产品编号
|
||||
for (Map.Entry<String, List<Map<String, String>>> cpbhentry : cpbh.entrySet()) {
|
||||
// String cpbhkey = Util.null2String(cpbhentry.getKey());
|
||||
List<Map<String, String>> cpbhvalue = cpbhentry.getValue();
|
||||
double total = 0;
|
||||
for (Map<String, String> stringStringMap : cpbhvalue) {
|
||||
String lythsl = Util.null2String(stringStringMap.get("lythsl"));//领用/退还数量
|
||||
if (!"".equals(lythsl)){
|
||||
total += Double.parseDouble(lythsl);
|
||||
}
|
||||
}
|
||||
String kcyesl = Util.null2String(value.get(0).get("kcyesl"));
|
||||
double kcyeslDouble = 0;
|
||||
if (!"".equals(kcyesl)){
|
||||
kcyeslDouble = Double.parseDouble(kcyesl);
|
||||
}
|
||||
if (total <= kcyeslDouble){
|
||||
booleanLingYong.add("true");
|
||||
}else {
|
||||
booleanLingYong.add("false");
|
||||
}
|
||||
}
|
||||
}else if (key.equals("1")){
|
||||
Map<String, List<Map<String, String>>> cpbh = value.stream().collect(Collectors.groupingBy(items -> items.get("cpbh")));//产品编号
|
||||
for (Map.Entry<String, List<Map<String, String>>> cpbhentry : cpbh.entrySet()) {
|
||||
// String cpbhkey = Util.null2String(cpbhentry.getKey());
|
||||
List<Map<String, String>> cpbhvalue = cpbhentry.getValue();
|
||||
double total = 0;
|
||||
for (Map<String, String> stringStringMap : cpbhvalue) {
|
||||
String lythsl = Util.null2String(stringStringMap.get("lythsl"));//领用/退还数量
|
||||
if (!lythsl.equals("")){
|
||||
total += Double.parseDouble(lythsl);
|
||||
}
|
||||
}
|
||||
String sssl = Util.null2String(cpbhvalue.get(0).get("sssl"));//实收数量
|
||||
String kcyesl = Util.null2String(cpbhvalue.get(0).get("kcyesl"));//剩余库存数量
|
||||
double ssslDouble = 0;
|
||||
double kcyeslDouble = 0;
|
||||
if (!"".equals(sssl)&&!"".equals(kcyesl)){
|
||||
ssslDouble = Double.parseDouble(sssl);
|
||||
kcyeslDouble = Double.parseDouble(kcyesl);
|
||||
}
|
||||
double subtractionValue = ssslDouble - kcyeslDouble;
|
||||
logger.info("subtractionValue==="+subtractionValue);
|
||||
logger.info("total==="+total);
|
||||
if (total <= subtractionValue){
|
||||
booleanTuiHuan.add("true");
|
||||
}else {
|
||||
booleanTuiHuan.add("false");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, List<String>> booleanMap = new HashMap<>();
|
||||
booleanMap.put("lingyong",booleanLingYong);
|
||||
booleanMap.put("tuihuan", booleanTuiHuan);
|
||||
return booleanMap;
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("checkfield方法异常==="+e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>修改uf_OfficeInventory表数据以及进行加减计算</h2>
|
||||
* @param detailLists 明细表所有数据
|
||||
* @author hcy
|
||||
* 2023/3/16 15:23
|
||||
*/
|
||||
public void changeDBValue(List<Map<String, String>> detailLists) {
|
||||
try {
|
||||
|
||||
Map<String, List<Map<String, String>>> detailMap = detailLists.stream().collect(Collectors.groupingBy(items -> items.get("ywlx")));
|
||||
Map<String, Integer> lingYongMap = new HashMap<>();//用于存放领用类型的数据
|
||||
Map<String, Integer> tuiHuanMap = new HashMap<>();//用于存放退还类型的数据
|
||||
for (Map.Entry<String, List<Map<String, String>>> entry : detailMap.entrySet()) {
|
||||
String key = Util.null2String(entry.getKey());
|
||||
List<Map<String, String>> value = entry.getValue();
|
||||
if (!("".equals(key)) && key.equals("0")){
|
||||
Map<String, List<Map<String, String>>> cpbh = value.stream().collect(Collectors.groupingBy(items -> items.get("cpbh")));//产品编号
|
||||
for (Map.Entry<String, List<Map<String, String>>> cpbhentry : cpbh.entrySet()) {
|
||||
String cpbhkey = Util.null2String(cpbhentry.getKey());
|
||||
List<Map<String, String>> cpbhvalue = cpbhentry.getValue();
|
||||
int total = 0;
|
||||
for (Map<String, String> stringStringMap : cpbhvalue) {
|
||||
String lythsl = Util.null2String(stringStringMap.get("lythsl"));//领用/退还数量
|
||||
if (!lythsl.equals("")){
|
||||
total += Integer.parseInt(lythsl);
|
||||
}
|
||||
}
|
||||
lingYongMap.put(cpbhkey,total);
|
||||
}
|
||||
}else if (!("".equals(key)) && key.equals("1")){
|
||||
Map<String, List<Map<String, String>>> cpbh = value.stream().collect(Collectors.groupingBy(items -> items.get("cpbh")));//产品编号
|
||||
for (Map.Entry<String, List<Map<String, String>>> cpbhentry : cpbh.entrySet()) {
|
||||
String cpbhkey = Util.null2String(cpbhentry.getKey());
|
||||
List<Map<String, String>> cpbhvalue = cpbhentry.getValue();
|
||||
int total = 0;
|
||||
for (Map<String, String> stringStringMap : cpbhvalue) {
|
||||
String lythsl = Util.null2String(stringStringMap.get("lythsl"));//领用/退还数量
|
||||
if (!lythsl.equals("")){
|
||||
total += Integer.parseInt(lythsl);
|
||||
}
|
||||
}
|
||||
tuiHuanMap.put(cpbhkey,total);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//开始updte数据库
|
||||
for (Map.Entry<String, Integer> entry : lingYongMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
String selectLysl = checkAndChangeValueMapper.selectLysl(key);
|
||||
int lyslDB = 0;
|
||||
if (!selectLysl.equals("")){
|
||||
lyslDB = Integer.parseInt(selectLysl);
|
||||
}
|
||||
//减库存
|
||||
boolean updateLysl = checkAndChangeValueMapper.updateLysl(String.valueOf(lyslDB + value),key);
|
||||
logger.info("减库存是否成功==="+updateLysl);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Integer> entry : tuiHuanMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
String selectThsl = checkAndChangeValueMapper.selectThsl(key);
|
||||
int thslDB = 0;
|
||||
if (!selectThsl.equals("")){
|
||||
thslDB = Integer.parseInt(selectThsl);
|
||||
}
|
||||
//增加库存
|
||||
String finalThsl = String.valueOf(thslDB + value);
|
||||
boolean updateThsl = checkAndChangeValueMapper.updaThsl(finalThsl,key);
|
||||
logger.info("增加库存是否成功"+updateThsl);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("changeDBValue异常为==="+e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.createworkflow.controller;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.createworkflow.mapper.GetWorkflowDataMapper;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.createworkflow.service.GetWorkflowDataService;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.createworkflow.service.impl.GetWorkflowDataServiceImpl;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>计划任务一段时间收集《office库存领用/退还登记》流程中的数据,用收集到的数据创建《office库存领用/退还汇总签批》流程</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/3/15 11:45
|
||||
*/
|
||||
public class GetDataCreateWorkflowController extends BaseCronJob {
|
||||
//获取数据主表的名称
|
||||
private String getDataMainTableName;
|
||||
//获取数据的和主表数据对应的明细表的名称
|
||||
private String getDataDetailTableName;
|
||||
//流程id
|
||||
private String workflowId;
|
||||
//配置表的唯一标识
|
||||
private String wybs;
|
||||
//校验日志
|
||||
private String datetime;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取《office库存领用/退还申请》流程中的数据
|
||||
*/
|
||||
private final GetWorkflowDataService getWorkflowDataService = (GetWorkflowDataService) new GetWorkflowDataServiceImpl();
|
||||
|
||||
private final GetWorkflowDataMapper getWorkflowDataMapper = Util.getMapper(GetWorkflowDataMapper.class);
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>获取流程数据,创建新的流程</h2>
|
||||
* @param
|
||||
* @return
|
||||
* @author hcy
|
||||
* @Date 2023/3/15 13:54
|
||||
*/
|
||||
public void execute() {
|
||||
|
||||
try {
|
||||
String month = this.getlastdayDate();
|
||||
//第一步拿到数据
|
||||
List<Map<String, Object>> totalData = new ArrayList<>();
|
||||
|
||||
if (!"".equals(Util.null2String(datetime))){
|
||||
totalData = getWorkflowDataService.getTotalData(getDataMainTableName, getDataDetailTableName,datetime);
|
||||
}else {
|
||||
totalData = getWorkflowDataService.getTotalData(getDataMainTableName, getDataDetailTableName,month);
|
||||
}
|
||||
|
||||
logger.info("===totalData==="+totalData);
|
||||
//这一步是获取权限区分字段名称
|
||||
String distinctField = getWorkflowDataMapper.getDistincteField(wybs);
|
||||
Map<Object, List<Map<String, Object>>> datas = totalData.stream().collect(Collectors.groupingBy(items -> items.get(distinctField)));//单个流程,过滤数据
|
||||
logger.info("===datas===="+datas);
|
||||
User user = new User();
|
||||
//第二步创建流程
|
||||
datas.forEach((key,value)->{
|
||||
//拿到数据创建流程
|
||||
String s = getWorkflowDataService.startWorkflow(workflowId, value, user, "1",wybs,distinctField);
|
||||
logger.info("============"+s+"============");
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("controller层出现问题---问题为:"+e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h2>获取系统当前时间的前一天日期</h2>
|
||||
* @param
|
||||
* @return String
|
||||
* @author hcy
|
||||
* @Date 2023/3/16 10:50
|
||||
*/
|
||||
public String getlastdayDate(){
|
||||
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
||||
date = calendar.getTime();
|
||||
System.out.println(sdf.format(date));
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public String getGetDataMainTableName() {
|
||||
return getDataMainTableName;
|
||||
}
|
||||
|
||||
public void setGetDataMainTableName(String getDataMainTableName) {
|
||||
this.getDataMainTableName = getDataMainTableName;
|
||||
}
|
||||
|
||||
public String getGetDataDetailTableName() {
|
||||
return getDataDetailTableName;
|
||||
}
|
||||
|
||||
public void setGetDataDetailTableName(String getDataDetailTableName) {
|
||||
this.getDataDetailTableName = getDataDetailTableName;
|
||||
}
|
||||
|
||||
|
||||
public String getWorkflowId() {
|
||||
return workflowId;
|
||||
}
|
||||
|
||||
public void setWorkflowId(String workflowId) {
|
||||
this.workflowId = workflowId;
|
||||
}
|
||||
|
||||
public GetWorkflowDataService getGetWorkflowDataService() {
|
||||
return getWorkflowDataService;
|
||||
}
|
||||
|
||||
public String getWybs() {
|
||||
return wybs;
|
||||
}
|
||||
|
||||
public void setWybs(String wybs) {
|
||||
this.wybs = wybs;
|
||||
}
|
||||
|
||||
public String getDatetime() {
|
||||
return datetime;
|
||||
}
|
||||
|
||||
public void setDatetime(String datetime) {
|
||||
this.datetime = datetime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.createworkflow.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SqlMapper
|
||||
public interface GetWorkflowDataMapper {
|
||||
|
||||
/**
|
||||
* <h2>内连接主表以及明细表查询出来放入List中</h2>
|
||||
* @param mainTableName,detailTableName
|
||||
* @return List<Map<String,Object>>
|
||||
* @author hcy
|
||||
* @Date 2023/3/15 14:47
|
||||
*/
|
||||
|
||||
@Select("select * from $t{mainTableName} m inner join $t{detailTableName} d on m.id = d.mainid where LEFT(sqrq,7) = LEFT(#{month},7)")
|
||||
List<Map<String,Object>> selectTotalData(@ParamMapper("mainTableName") String mainTableName,
|
||||
@ParamMapper("detailTableName") String detailTableName,
|
||||
@ParamMapper("month") String month
|
||||
);
|
||||
@Select("select bmmc from uf_dept where id = #{ppbm}")
|
||||
String selectPpName(@ParamMapper("ppbm")String ppbm);
|
||||
|
||||
@Select("select * from uf_xjlcbdzddypzb uf inner join uf_xjlcbdzddypzb_dt1 ufdt1 on uf.id = ufdt1.mainid where uf.wybs = #{wybs}")
|
||||
List<Map<String, Object>> selectfromCustomizeTable(@ParamMapper("wybs") String wybs);
|
||||
|
||||
@Select("select qxqfzdsjkmc from uf_xjlcbdzddypzb where wybs = #{wybs}")
|
||||
String getDistincteField(String wybs);
|
||||
|
||||
@Select("select bmmc from uf_dept where id= #{ppbm}")
|
||||
String getPpbmValue(String ppbm);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.createworkflow.service;
|
||||
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GetWorkflowDataService {
|
||||
|
||||
public List<Map<String,Object>> getTotalData(String mainTableName,String detailTableName,String month);
|
||||
|
||||
/**
|
||||
* <h2>创建一个流程</h2>
|
||||
* @param workflowId 流程id
|
||||
* @param totalDatas:主表数据,明细表数据:数据形式:key:value
|
||||
* @param user 当前用户信息
|
||||
* @param isNextFlow 是否自动提交至下一个节点 0:否 1:是
|
||||
* @return String:流程创建是否成功
|
||||
* @author hcy
|
||||
* @Date 2023/3/15 16:42
|
||||
*/
|
||||
public String startWorkflow(String workflowId,List<Map<String,Object>> totalDatas,User user, String isNextFlow,String wybs,String distinctField);
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.createworkflow.service.impl;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.createworkflow.mapper.GetWorkflowDataMapper;
|
||||
import weaver.chaoyang.he.hcy_esteelauder.createworkflow.service.GetWorkflowDataService;
|
||||
import weaver.hrm.User;
|
||||
import weaver.workflow.webservices.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class GetWorkflowDataServiceImpl implements GetWorkflowDataService {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
private final GetWorkflowDataMapper getWorkflowDataMapper = Util.getMapper(GetWorkflowDataMapper.class);
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getTotalData(String mainTableName, String detailTableName,String month) {
|
||||
return getWorkflowDataMapper.selectTotalData(mainTableName, detailTableName,month);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>创建流程</h2>
|
||||
* @param workflowId:流程id
|
||||
* @return String:流程创建成功与否
|
||||
* @author hcy
|
||||
* 2023/3/15 22:45
|
||||
*/
|
||||
public String startWorkflow(String workflowId, List<Map<String, Object>> totalDatas, User user, String isNextFlow,String wybs,String distinctField) {
|
||||
|
||||
|
||||
try {
|
||||
List<Map<String,Object>> customizeDataList = getWorkflowDataMapper.selectfromCustomizeTable(wybs);
|
||||
List<Map<String, Object>> mailTableDatas = new ArrayList<>();
|
||||
List<Map<String, Object>> detailDataDatas = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> map : customizeDataList) {
|
||||
if (Util.null2String(map.get("sjly")).equals("0")&&Util.null2String(map.get("mbzdsjly")).equals("0")){
|
||||
mailTableDatas.add(map);
|
||||
}
|
||||
if (Util.null2String(map.get("sjly")).equals("0")&&Util.null2String(map.get("mbzdsjly")).equals("1")){
|
||||
detailDataDatas.add(map);
|
||||
}
|
||||
if (Util.null2String(map.get("sjly")).equals("1")&&Util.null2String(map.get("mbzdsjly")).equals("1")){
|
||||
detailDataDatas.add(map);
|
||||
}
|
||||
}
|
||||
WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[mailTableDatas.size()];
|
||||
|
||||
//配置表动态处理主表字段
|
||||
for (int i = 0; i <mailTableDatas.size(); i++){
|
||||
Map<String, Object> dataMap = mailTableDatas.get(i);
|
||||
wrti[i] = new WorkflowRequestTableField();
|
||||
String targetField = Util.null2String(dataMap.get("mblczdsjkm"));
|
||||
wrti[i].setFieldName(targetField);
|
||||
Object ylczdsjkm = dataMap.get("ylczdsjkm");
|
||||
Object sourceField = totalDatas.get(i).get(ylczdsjkm);
|
||||
wrti[i].setFieldValue(Util.null2String(sourceField));
|
||||
wrti[i].setView(true);
|
||||
wrti[i].setEdit(true);
|
||||
|
||||
}
|
||||
|
||||
WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[1];//主字段只有一行数据
|
||||
wrtri[0] = new WorkflowRequestTableRecord();
|
||||
wrtri[0].setWorkflowRequestTableFields(wrti);
|
||||
WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
|
||||
wmi.setRequestRecords(wrtri);
|
||||
//主表end
|
||||
int detailrows = totalDatas.size();//添加指定条数明细
|
||||
|
||||
// 添加明细数据
|
||||
wrtri = new WorkflowRequestTableRecord[totalDatas.size()];//添加指定条数行明细数据
|
||||
//每行明细对应的字段
|
||||
|
||||
for (int i = 0; i < detailrows; i++) {
|
||||
//字段信息
|
||||
wrti = new WorkflowRequestTableField[detailDataDatas.size()];
|
||||
int j=0;
|
||||
for (Map<String, Object> detailDataData : detailDataDatas) {
|
||||
wrti[j] = new WorkflowRequestTableField();
|
||||
String targetField = Util.null2String(detailDataData.get("mblczdsjkm"));//目标字段,字段名
|
||||
wrti[j].setFieldName(targetField);//服务类型
|
||||
Object ylczdsjkm = detailDataData.get("ylczdsjkm");
|
||||
Object sourceField = totalDatas.get(i).get(ylczdsjkm);
|
||||
String sourceFieldString = Util.null2String(sourceField);
|
||||
if (Util.null2String(totalDatas.get(i).get("ywlx")).equals("0")&&Util.null2String(ylczdsjkm).equals("lythsl")){
|
||||
sourceFieldString = "-"+sourceFieldString;
|
||||
}
|
||||
wrti[j].setFieldValue(sourceFieldString);
|
||||
wrti[j].setView(true);//字段是否可见
|
||||
wrti[j].setEdit(true);//字段是否可编辑
|
||||
j++;
|
||||
}
|
||||
wrtri[i] = new WorkflowRequestTableRecord();
|
||||
wrtri[i].setWorkflowRequestTableFields(wrti);
|
||||
}
|
||||
//添加到明细表中
|
||||
WorkflowDetailTableInfo WorkflowDetailTableInfo[] = new WorkflowDetailTableInfo[1];//指定明细表的个数,多个明细表指定多个,顺序按照明细的顺序
|
||||
WorkflowDetailTableInfo[0] = new WorkflowDetailTableInfo();
|
||||
WorkflowDetailTableInfo[0].setWorkflowRequestTableRecords(wrtri);
|
||||
//添加工作流id
|
||||
WorkflowBaseInfo wbi = new WorkflowBaseInfo();
|
||||
wbi.setWorkflowId(workflowId);//workflowid 流程接口演示流程2016==38
|
||||
WorkflowRequestInfo wri = new WorkflowRequestInfo();//流程基本信息
|
||||
wri.setCreatorId("1");//创建人id ToDo:这里先写死,稍后再做改写
|
||||
wri.setRequestLevel("0");//0 正常,1重要,2紧急
|
||||
String ppbmValue = getWorkflowDataMapper.getPpbmValue(Util.null2String(totalDatas.get(0).get(distinctField)));
|
||||
String workflowTitle = this.getWorkflowTitle(ppbmValue);
|
||||
wri.setRequestName(workflowTitle);//流程标题
|
||||
wri.setWorkflowMainTableInfo(wmi);//添加主字段数据
|
||||
wri.setWorkflowDetailTableInfos(WorkflowDetailTableInfo);//添加明细数据
|
||||
wri.setWorkflowBaseInfo(wbi);
|
||||
// wri.setIsnextflow(isNextFlow);//是否提交下一个节点
|
||||
WorkflowService workflowService = new WorkflowServiceImpl();
|
||||
String requestid =workflowService.doCreateWorkflowRequest(wri,1);
|
||||
logger.info("===requestid==="+requestid);
|
||||
if (!requestid.equals("")){
|
||||
return "流程创建成功";
|
||||
}else {
|
||||
return "流程创建失败";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("流程创建异常===异常信息===="+e);
|
||||
return "流程创建异常===异常信息===="+e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取流程标题</h2>
|
||||
* @param pp 品牌名称
|
||||
* @return String
|
||||
* @author hcy
|
||||
* 2023/3/16 11:27
|
||||
*/
|
||||
public String getWorkflowTitle(String pp){
|
||||
|
||||
String workflowName = pp + "-" + getSystemDate() + "-" + "office库存领用/退还明细";
|
||||
logger.info("workflowName==="+workflowName);
|
||||
return workflowName;
|
||||
}
|
||||
/**
|
||||
* <h2>获取系统当年份</h2>
|
||||
* @return String
|
||||
* @author hcy
|
||||
* 2023/3/15 13:52
|
||||
*/
|
||||
public String getSystemDate(){
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
package weaver.chaoyang.he.hcy_esteelauder.createworkflow.service.impl;//package weaver.hcy_esteelauder.createworkflow.service.impl;
|
||||
//
|
||||
//import aiyh.utils.Util;
|
||||
//import org.apache.log4j.Logger;
|
||||
//import weaver.hcy_esteelauder.createworkflow.mapper.GetWorkflowDataMapper;
|
||||
//import weaver.hcy_esteelauder.createworkflow.service.GetWorkflowDataService;
|
||||
//import weaver.hrm.User;
|
||||
//import weaver.workflow.webservices.*;
|
||||
//
|
||||
//import java.text.SimpleDateFormat;
|
||||
//import java.util.Date;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class GetWorkflowDataServiceImpl_copy implements GetWorkflowDataService {
|
||||
//
|
||||
// private final Logger logger = Util.getLogger();
|
||||
// private final GetWorkflowDataMapper getWorkflowDataMapper = Util.getMapper(GetWorkflowDataMapper.class);
|
||||
//
|
||||
// @Override
|
||||
// public List<Map<String, Object>> getTotalData(String mainTableName, String detailTableName,String month) {
|
||||
// return getWorkflowDataMapper.selectTotalData(mainTableName, detailTableName,month);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * <h2>创建流程</h2>
|
||||
// * @param workflowId:流程id
|
||||
// * @param workflowId:流程id
|
||||
// * @param workflowId:流程id
|
||||
// * @return String:流程创建成功与否
|
||||
// * @author hcy
|
||||
// * @Date 2023/3/15 22:45
|
||||
// */
|
||||
// public String startWorkflow(String workflowId, List<Map<String, Object>> totalDatas, User user, String isNextFlow,String wybs) {
|
||||
//
|
||||
//
|
||||
// try {
|
||||
//// List<Map<String,String>> customizeDataList = getWorkflowDataMapper.selectfromCustomizeTable(wybs);
|
||||
//
|
||||
// WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[4];
|
||||
//
|
||||
// //字段信息
|
||||
// wrti[0] = new WorkflowRequestTableField();
|
||||
// wrti[0].setFieldName("sqr");
|
||||
// wrti[0].setFieldValue(Util.null2String(String.valueOf(totalDatas.get(0).get("sqr"))));
|
||||
// wrti[0].setView(true);
|
||||
// wrti[0].setEdit(true);
|
||||
//
|
||||
// wrti[1] = new WorkflowRequestTableField();
|
||||
// wrti[1].setFieldName("sqrbm");
|
||||
// wrti[1].setFieldValue(Util.null2String(String.valueOf(totalDatas.get(0).get("sqrbm"))));
|
||||
// wrti[1].setView(true);
|
||||
// wrti[1].setEdit(true);
|
||||
//
|
||||
// wrti[2] = new WorkflowRequestTableField();
|
||||
// wrti[2].setFieldName("sqrq");
|
||||
// wrti[2].setFieldValue(Util.null2String(String.valueOf(totalDatas.get(0).get("sqrq"))));
|
||||
// wrti[2].setView(true);
|
||||
// wrti[2].setEdit(true);
|
||||
//
|
||||
// wrti[3] = new WorkflowRequestTableField();
|
||||
// wrti[3].setFieldName("ppbm");
|
||||
// String ppbmValue = Util.null2String(String.valueOf(totalDatas.get(0).get("ppbm")));
|
||||
// if (!ppbmValue.equals("")){
|
||||
// wrti[3].setFieldValue(ppbmValue);
|
||||
// }
|
||||
// wrti[3].setView(true);
|
||||
// wrti[3].setEdit(true);
|
||||
//
|
||||
//
|
||||
// WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[1];//主字段只有一行数据
|
||||
// wrtri[0] = new WorkflowRequestTableRecord();
|
||||
// wrtri[0].setWorkflowRequestTableFields(wrti);
|
||||
// WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
|
||||
// wmi.setRequestRecords(wrtri);
|
||||
// //主表end
|
||||
// int detailrows = totalDatas.size();//添加指定条数明细
|
||||
// // 添加明细数据
|
||||
// wrtri = new WorkflowRequestTableRecord[totalDatas.size()];//添加指定条数行明细数据
|
||||
// for (int i = 0; i < detailrows; i++) {
|
||||
// //每行明细对应的字段
|
||||
// wrti = new WorkflowRequestTableField[20];
|
||||
// //字段信息
|
||||
// //0
|
||||
// wrti[0] = new WorkflowRequestTableField();
|
||||
// wrti[0].setFieldName("ywlx");//服务类型
|
||||
// wrti[0].setFieldValue(String.valueOf(totalDatas.get(i).get("ywlx")));
|
||||
// wrti[0].setView(true);//字段是否可见
|
||||
// wrti[0].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[1] = new WorkflowRequestTableField();
|
||||
// wrti[1].setFieldName("pp");//品牌
|
||||
// wrti[1].setFieldValue(String.valueOf(totalDatas.get(i).get("ppbm")));
|
||||
// wrti[1].setView(true);//字段是否可见
|
||||
// wrti[1].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[2] = new WorkflowRequestTableField();
|
||||
// wrti[2].setFieldName("bm");//部门
|
||||
// wrti[2].setFieldValue(String.valueOf(totalDatas.get(i).get("sqrbm")));
|
||||
// wrti[2].setView(true);//字段是否可见
|
||||
// wrti[2].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
//
|
||||
// wrti[3] = new WorkflowRequestTableField();
|
||||
// wrti[3].setFieldName("stockowner");//stockowner
|
||||
// wrti[3].setFieldValue(String.valueOf(totalDatas.get(i).get("stockowner")));
|
||||
// wrti[3].setView(true);//字段是否可见
|
||||
// wrti[3].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[4] = new WorkflowRequestTableField();
|
||||
// wrti[4].setFieldName("sqr");//申请人
|
||||
// wrti[4].setFieldValue(String.valueOf(totalDatas.get(i).get("sqr")));
|
||||
// wrti[4].setView(true);//字段是否可见
|
||||
// wrti[4].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[5] = new WorkflowRequestTableField();
|
||||
// wrti[5].setFieldName("cs");//城市
|
||||
// wrti[5].setFieldValue(String.valueOf(totalDatas.get(i).get("cs")));
|
||||
// wrti[5].setView(true);//字段是否可见
|
||||
// wrti[5].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[6] = new WorkflowRequestTableField();
|
||||
// wrti[6].setFieldName("stocklocation");//stocklocation
|
||||
// wrti[6].setFieldValue(String.valueOf(totalDatas.get(i).get("stocklocation")));
|
||||
// wrti[6].setView(true);//字段是否可见
|
||||
// wrti[6].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[7] = new WorkflowRequestTableField();
|
||||
// wrti[7].setFieldName("hgbh");//货柜编号
|
||||
// wrti[7].setFieldValue(String.valueOf(totalDatas.get(i).get("hgbh")));
|
||||
// wrti[7].setView(true);//字段是否可见
|
||||
// wrti[7].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[8] = new WorkflowRequestTableField();
|
||||
// wrti[8].setFieldName("cpbh");//产品编号
|
||||
// wrti[8].setFieldValue(String.valueOf(totalDatas.get(i).get("cpbh")));
|
||||
// wrti[8].setView(true);//字段是否可见
|
||||
// wrti[8].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[9] = new WorkflowRequestTableField();
|
||||
// wrti[9].setFieldName("ddbh");//订单编号
|
||||
// wrti[9].setFieldValue(String.valueOf(totalDatas.get(i).get("ddbh")));
|
||||
// wrti[9].setView(true);//字段是否可见
|
||||
// wrti[9].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[10] = new WorkflowRequestTableField();
|
||||
// wrti[10].setFieldName("zwms");//中文描述
|
||||
// wrti[10].setFieldValue(String.valueOf(totalDatas.get(i).get("zwms")));
|
||||
// wrti[10].setView(true);//字段是否可见
|
||||
// wrti[10].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[11] = new WorkflowRequestTableField();
|
||||
// wrti[11].setFieldName("kcyesl");//剩余库存
|
||||
// wrti[11].setFieldValue(String.valueOf(totalDatas.get(i).get("kcyesl")));
|
||||
// wrti[11].setView(true);//字段是否可见
|
||||
// wrti[11].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[12] = new WorkflowRequestTableField();
|
||||
// wrti[12].setFieldName("lythrq");//领用/退还日期
|
||||
// wrti[12].setFieldValue(String.valueOf(totalDatas.get(i).get("lythrq")));
|
||||
// wrti[12].setView(true);//字段是否可见
|
||||
// wrti[12].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[13] = new WorkflowRequestTableField();
|
||||
// wrti[13].setFieldName("dqrq");//到期日期
|
||||
// wrti[13].setFieldValue(String.valueOf(totalDatas.get(i).get("dqrq")));
|
||||
// wrti[13].setView(true);//字段是否可见
|
||||
// wrti[13].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[14] = new WorkflowRequestTableField();
|
||||
// wrti[14].setFieldName("lythsl");//领用退还数量
|
||||
// if (Util.null2String(totalDatas.get(i).get("ywlx")).equals("1")){
|
||||
// wrti[14].setFieldValue(String.valueOf("-"+totalDatas.get(i).get("lythsl")));
|
||||
// }else if (Util.null2String(totalDatas.get(i).get("ywlx")).equals("0")){
|
||||
// wrti[14].setFieldValue(String.valueOf(totalDatas.get(i).get("lythsl")));
|
||||
// }
|
||||
// wrti[14].setView(true);//字段是否可见
|
||||
// wrti[14].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
//
|
||||
// wrti[15] = new WorkflowRequestTableField();
|
||||
// wrti[15].setFieldName("cplx");//产品类型
|
||||
// wrti[15].setFieldValue(String.valueOf(totalDatas.get(i).get("cplx")));
|
||||
// wrti[15].setView(true);//字段是否可见
|
||||
// wrti[15].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[16] = new WorkflowRequestTableField();
|
||||
// wrti[16].setFieldName("kdzjxx");//快递/转交信息
|
||||
// wrti[16].setFieldValue(String.valueOf(totalDatas.get(i).get("kdzjxx")));
|
||||
// wrti[16].setView(true);//字段是否可见
|
||||
// wrti[16].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[17] = new WorkflowRequestTableField();
|
||||
// wrti[17].setFieldName("cpyt");//产品用途
|
||||
// wrti[17].setFieldValue(String.valueOf(totalDatas.get(i).get("cpyt")));
|
||||
// wrti[17].setView(true);//字段是否可见
|
||||
// wrti[17].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[18] = new WorkflowRequestTableField();
|
||||
// wrti[18].setFieldName("sssl");//实收数量
|
||||
// wrti[18].setFieldValue(String.valueOf(totalDatas.get(i).get("sssl")));
|
||||
// wrti[18].setView(true);//字段是否可见
|
||||
// wrti[18].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrti[19] = new WorkflowRequestTableField();
|
||||
// wrti[19].setFieldName("bz");//备注
|
||||
// wrti[19].setFieldValue(String.valueOf(totalDatas.get(i).get("bz")));
|
||||
// wrti[19].setView(true);//字段是否可见
|
||||
// wrti[19].setEdit(true);//字段是否可编辑
|
||||
//
|
||||
// wrtri[i] = new WorkflowRequestTableRecord();
|
||||
// wrtri[i].setWorkflowRequestTableFields(wrti);
|
||||
// }
|
||||
// //添加到明细表中
|
||||
// WorkflowDetailTableInfo WorkflowDetailTableInfo[] = new WorkflowDetailTableInfo[1];//指定明细表的个数,多个明细表指定多个,顺序按照明细的顺序
|
||||
// WorkflowDetailTableInfo[0] = new WorkflowDetailTableInfo();
|
||||
// WorkflowDetailTableInfo[0].setWorkflowRequestTableRecords(wrtri);
|
||||
// //添加工作流id
|
||||
// WorkflowBaseInfo wbi = new WorkflowBaseInfo();
|
||||
// wbi.setWorkflowId(workflowId);//workflowid 流程接口演示流程2016==38
|
||||
// WorkflowRequestInfo wri = new WorkflowRequestInfo();//流程基本信息
|
||||
// wri.setCreatorId("1");//创建人id ToDo:这里先写死,稍后再做改写
|
||||
// wri.setRequestLevel("0");//0 正常,1重要,2紧急
|
||||
// String workflowTitle = this.getWorkflowTitle(Util.null2String(String.valueOf(totalDatas.get(0).get("ppbm"))));
|
||||
// wri.setRequestName(workflowTitle);//流程标题
|
||||
// wri.setWorkflowMainTableInfo(wmi);//添加主字段数据
|
||||
// wri.setWorkflowDetailTableInfos(WorkflowDetailTableInfo);//添加明细数据
|
||||
// wri.setWorkflowBaseInfo(wbi);
|
||||
//// wri.setIsnextflow(isNextFlow);//是否提交下一个节点
|
||||
// WorkflowService workflowService = new WorkflowServiceImpl();
|
||||
// String requestid =workflowService.doCreateWorkflowRequest(wri,1);
|
||||
// logger.info("===requestid==="+requestid);
|
||||
// if (!requestid.equals("")){
|
||||
// return "流程创建成功";
|
||||
// }else {
|
||||
// return "流程创建失败";
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// logger.info("流程创建异常===异常信息===="+e);
|
||||
// return "流程创建异常===异常信息===="+e;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * <h2>获取流程标题</h2>
|
||||
// * @param pp 品牌名称
|
||||
// * @return String
|
||||
// * @author hcy
|
||||
// * @Date 2023/3/16 11:27
|
||||
// */
|
||||
// public String getWorkflowTitle(String pp){
|
||||
// String ppName = getWorkflowDataMapper.selectPpName(pp);
|
||||
// String workflowName = ppName + "-" + getSystemDate() + "-" + "office库存领用/退还明细";
|
||||
// logger.info("workflowName==="+workflowName);
|
||||
// return workflowName;
|
||||
// }
|
||||
// /**
|
||||
// * <h2>获取系统当年份</h2>
|
||||
// * @param
|
||||
// * @return String
|
||||
// * @author hcy
|
||||
// * @Date 2023/3/15 13:52
|
||||
// */
|
||||
// public String getSystemDate(){
|
||||
// Date date = new Date();
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// return dateFormat.format(date);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,119 @@
|
|||
package weaver.chaoyang.he.hcy_fengtianfangzhi.rollbackmoneytoworkflow.acton;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Cell;
|
||||
import weaver.soa.workflow.request.DetailTable;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.soa.workflow.request.Row;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>对公付款申请(一般采购)明细表二:验收入库单中的已申请金额/未申请金额计算后需要反填到验收入库单中</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/1/30 19:57
|
||||
*/
|
||||
public class RollbackMoneyToWorkflowAction implements Action {
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
try {
|
||||
Map<String, List<Map<String, String>>> detailTableValue = this.getDetailTableValue(requestInfo);
|
||||
|
||||
List<Map<String, String>> lists = detailTableValue.get("2");//获取到明细表2中的所有数据
|
||||
logger.info("lists=="+ lists);
|
||||
for (Map<String, String> list : lists) {
|
||||
String ysrkdh = Util.null2String(list.get("ysrkdh"));//验收入库单号字段
|
||||
logger.info("验收入库单号==="+ysrkdh);
|
||||
String bcfkjehs = Util.null2String(list.get("bcfkjehs"));//本次付款金额(含税)
|
||||
logger.info("本次付款金额(含税)---bcfkjehs==="+bcfkjehs);
|
||||
String selectValueSql = "select hszje,ysqje from uf_ysrkd where id=?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean b = recordSet.executeQuery(selectValueSql, ysrkdh);
|
||||
logger.info("b是否执行==="+b);
|
||||
Double hszjeTotal = 0.0;//wszje 含税总金额
|
||||
Double ysqjeTotal = 0.0;//ysqje 已申请金额
|
||||
Double wsqjeTotal = 0.0;//wsqje 未申请金额
|
||||
if (recordSet.next()) {
|
||||
String hszje = Util.null2String(recordSet.getString("hszje"));//hszje 含税总金额
|
||||
String ysqje = Util.null2String(recordSet.getString("ysqje"));// ysqje 已申请金额
|
||||
|
||||
logger.info("含税总金额---hszje==="+ysqje);
|
||||
if (!"".equals(ysqje) && !"".equals(bcfkjehs)){
|
||||
Double ysqjeDouble = Double.parseDouble(ysqje);
|
||||
Double bcfkjehsDouble = Double.parseDouble(bcfkjehs);
|
||||
ysqjeTotal = ysqjeDouble + bcfkjehsDouble;
|
||||
}
|
||||
if (!"".equals(hszje)) {
|
||||
hszjeTotal = Double.parseDouble(hszje);
|
||||
}
|
||||
|
||||
}
|
||||
logger.info("hszjeTotal==="+ysqjeTotal);
|
||||
|
||||
String updateYsqje_Sql = "update uf_ysrkd set ysqje = ? where id = ?";
|
||||
boolean b1 = recordSet.executeUpdate(updateYsqje_Sql, ysqjeTotal, ysrkdh);
|
||||
logger.info("b1是否执行==="+b1);
|
||||
|
||||
//开始更新未申请金额 = 含税总金额 - 已申请金额 :wsqje = hszje - ysqje
|
||||
wsqjeTotal = hszjeTotal - ysqjeTotal;
|
||||
String updateWsqje_sql = "update uf_ysrkd set wsqje = ? where id = ?";
|
||||
boolean b2 = recordSet.executeUpdate(updateWsqje_sql, wsqjeTotal, ysrkdh);
|
||||
logger.info("b2是否执行==="+b2);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("NumberFormatException==="+e);
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <h2>获取所有明细数据</h2>
|
||||
*
|
||||
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||
*/
|
||||
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
|
||||
for (DetailTable detailTable : detailTableArr) {
|
||||
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||
detailDataList.put(detailTable.getId(), detailData);
|
||||
}
|
||||
return detailDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据明细表信息获取明细表数据</h2>
|
||||
*
|
||||
* @param detailTable 明细表对象
|
||||
* @return 明细表数据
|
||||
*/
|
||||
@NotNull
|
||||
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||
Row[] rowArr = detailTable.getRow();
|
||||
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||
for (Row row : rowArr) {
|
||||
Cell[] cellArr = row.getCell();
|
||||
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
|
||||
for (Cell cell : cellArr) {
|
||||
String fieldName = cell.getName();
|
||||
String value = cell.getValue();
|
||||
rowData.put(fieldName, value);
|
||||
}
|
||||
detailData.add(rowData);
|
||||
}
|
||||
return detailData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package weaver.chaoyang.he.hcy_fengtianfangzhi.update_lqts.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>调用进项发票信息获取接口,将返回值回写到发票台账</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/1/30 15:49
|
||||
*/
|
||||
public class UpdateLqtsAction extends BaseCronJob {
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String getDB_Sql = "select * from uf_clgm_dt1";
|
||||
boolean b = recordSet.executeQuery(getDB_Sql);
|
||||
logger.info("getDB_Sql---b---是否执行==="+b);
|
||||
|
||||
while (recordSet.next()){
|
||||
String sjnq = recordSet.getString("sjnq");//实际纳期
|
||||
String id = recordSet.getString("id");
|
||||
logger.info("实际纳期==="+sjnq);
|
||||
String currentTime = this.getCurrentTime();//系统当前日期
|
||||
long daySub = getDaySub(currentTime, sjnq);
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
String update_lqts_Sql ="update uf_clgm_dt1 set lqts = ? where id = ?";
|
||||
boolean b1 = recordSet1.executeUpdate(update_lqts_Sql, daySub, id);
|
||||
logger.info("b1是否执行=="+b1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("Exception==="+e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>日期相减得到的天数</h2>
|
||||
* @param beginDateStr,endDateStr
|
||||
* @return long
|
||||
* @author hcy
|
||||
*/
|
||||
public static long getDaySub(String beginDateStr, String endDateStr) {
|
||||
|
||||
long day = 0;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate;
|
||||
Date endDate;
|
||||
try {
|
||||
beginDate = format.parse(beginDateStr);
|
||||
endDate = format.parse(endDateStr);
|
||||
day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("day:" + day);
|
||||
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>返回系统当前日期时间</h2>
|
||||
* @param
|
||||
* @return String 当前日期
|
||||
* @author hcy
|
||||
*/
|
||||
public String getCurrentTime(){
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
String currentTime = dateFormat.format(date);
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package weaver.chaoyang.he.hcy_fengtianfangzhi.updatepdfname.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* <h1>配置节点后附加操作,用于修改流程存为文档pdf的名称</h1>
|
||||
* @Author hcy
|
||||
* @Date 2023/4/8 0:23
|
||||
*/
|
||||
public class UpdatePDFNameAction implements Action {
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
Map<String, String> mainTableMap = this.getMainTableValue(requestInfo);//yczwzd
|
||||
String docid = mainTableMap.get("yczwzd");//隐藏正文字段 ---用于存放主文书(定期品)和注文书(临期品)的pdf字段 是DocImageFile中的docid
|
||||
logger.info("docid=="+docid);
|
||||
String imagefilename = this.getImagefilename(mainTableMap);
|
||||
logger.info("修改的文件名称==="+imagefilename);
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String selectpdfSql = "select imagefilename from DocImageFile where docid = ?";
|
||||
recordSet.executeQuery(selectpdfSql, docid);
|
||||
recordSet.next();
|
||||
String imagefilename1 = Util.null2String(recordSet.getString("imagefilename"));
|
||||
logger.info("修改前的文件名称为==="+imagefilename1);
|
||||
if (!"".equals(imagefilename1)&&imagefilename1.endsWith(".pdf")){
|
||||
String updatePdfNameSql = "update DocImageFile set imagefilename = ? where docid = ?";
|
||||
boolean updateFileName = recordSet.executeUpdate(updatePdfNameSql, imagefilename, docid);
|
||||
logger.info("修改文件名称是否成功"+updateFileName);
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
private String getImagefilename(Map<String,String> mainTableDataMap) {
|
||||
|
||||
//订单编号 :sqdh
|
||||
//供应商 : gys
|
||||
//申请人部门 : sqrbm
|
||||
String sqdh = mainTableDataMap.get("sqdh");//订单编号
|
||||
String gys = mainTableDataMap.get("gys");//供应商
|
||||
String sqrbm = mainTableDataMap.get("sqrbm");//申请人部门
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
String getGysValueSql = "select gysqm from uf_gyszsjxx where id=?";
|
||||
recordSet1.executeQuery(getGysValueSql,gys);
|
||||
recordSet1.next();
|
||||
String gysValue = recordSet1.getString("gysqm");//供应商的值
|
||||
String getSqrbmSql = "select departmentname from hrmdepartment where id = ?";
|
||||
recordSet1.executeQuery(getSqrbmSql,sqrbm);
|
||||
recordSet1.next();
|
||||
String departmentname = recordSet1.getString("departmentname");//申请人部门
|
||||
return sqdh+"_"+gysValue+"_"+departmentname+"_"+this.getSystemDate()+".pdf";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>获取系统当年份</h2>
|
||||
* @return String
|
||||
* @author hcy
|
||||
* 2023/3/15 13:52
|
||||
*/
|
||||
public String getSystemDate(){
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取流程主表数据</h2>
|
||||
*
|
||||
* @return 流程主表数据
|
||||
*/
|
||||
protected Map<String, String> getMainTableValue(RequestInfo requestInfo) {
|
||||
// 获取主表数据
|
||||
Property[] propertyArr = requestInfo.getMainTableInfo().getProperty();
|
||||
if (null == propertyArr) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, String> mainTable = new HashMap<>((int) Math.ceil(propertyArr.length * 1.4));
|
||||
for (Property property : propertyArr) {
|
||||
String fieldName = property.getName();
|
||||
String value = property.getValue();
|
||||
mainTable.put(fieldName, value);
|
||||
}
|
||||
return mainTable;
|
||||
}
|
||||
/**
|
||||
* <h2>获取所有明细数据</h2>
|
||||
*
|
||||
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||
*/
|
||||
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
|
||||
for (DetailTable detailTable : detailTableArr) {
|
||||
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||
detailDataList.put(detailTable.getId(), detailData);
|
||||
}
|
||||
return detailDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据明细表信息获取明细表数据</h2>
|
||||
*
|
||||
* @param detailTable 明细表对象
|
||||
* @return 明细表数据
|
||||
*/
|
||||
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||
Row[] rowArr = detailTable.getRow();
|
||||
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||
for (Row row : rowArr) {
|
||||
Cell[] cellArr = row.getCell();
|
||||
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
|
||||
for (Cell cell : cellArr) {
|
||||
String fieldName = cell.getName();
|
||||
String value = cell.getValue();
|
||||
rowData.put(fieldName, value);
|
||||
}
|
||||
detailData.add(rowData);
|
||||
}
|
||||
return detailData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
package weaver.chaoyang.he.hcy_pcn.noticeaftersigned.action;
|
||||
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Cell;
|
||||
import weaver.soa.workflow.request.DetailTable;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.soa.workflow.request.Row;
|
||||
import weaver.workflow.request.RequestManager;
|
||||
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NoticeAfterSigned implements Action {
|
||||
|
||||
|
||||
private String uniqueCode;//唯一标识
|
||||
private String apikey;
|
||||
private String accountMessageTableName; //台账数据表名
|
||||
private String statusName; //状态名
|
||||
private String updateFieldName; //更新标识字段
|
||||
private String valueUpdateFiledName;//明细字段名
|
||||
private String detailkey;//哪个明细表
|
||||
|
||||
private final Logger log = aiyh.utils.Util.getLogger();
|
||||
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
log.info("NoticeAfterSigned begin;requestid:" + requestInfo.getRequestid());
|
||||
RequestManager requestManager = requestInfo.getRequestManager();
|
||||
try{
|
||||
|
||||
String tableName = requestManager.getBillTableName();
|
||||
String requestid = requestInfo.getRequestid();
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "select * from " + tableName + " where requestid = ?";
|
||||
Map<String, Object> params = new HashMap<>();//请求体
|
||||
dealWithMapping.setMainTable(tableName);
|
||||
if (rs.executeQuery(sql,requestid) && rs.next()) {
|
||||
RequestMappingConfig conf = dealWithMapping.treeDealWithUniqueCode(uniqueCode);
|
||||
String requestUrl = conf.getRequestUrl();//目标url
|
||||
log.info("获取到的url为:"+requestUrl);
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("Accept", MediaType.APPLICATION_JSON);
|
||||
headers.put("Content-Type", "application/json");
|
||||
headers.put("apikey", apikey);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
|
||||
//请求体
|
||||
List<Map<String,Object>> li = new ArrayList<>(); //定义一个map元素的List集合用来存放
|
||||
List<Object> requestListParam = dealWithMapping.getRequestListParam(rs, conf);
|
||||
for (Object requestParam : requestListParam) {
|
||||
params = (Map<String, Object>) requestParam;
|
||||
log.info("得到的请求体内容为:"+params);
|
||||
try {
|
||||
ResponeVo responeVo = httpUtils.apiPost(requestUrl, params, headers);
|
||||
log.info("接口返回值===="+responeVo);
|
||||
int code = responeVo.getCode();
|
||||
log.info("状态码为:code===="+code);
|
||||
Map<String,Object> m = new HashMap<>();
|
||||
m.put("status","");
|
||||
|
||||
if (code == 200){
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
int errcode = (int)entityMap.get("errcode");
|
||||
int status = 4;
|
||||
//根据状态码更新台账合同状态
|
||||
if (errcode==200){
|
||||
status = 0;
|
||||
}else if (errcode==1000089){
|
||||
status = 1;
|
||||
}else if (errcode==1000090){
|
||||
status = 2;
|
||||
}else if (errcode==1000091){
|
||||
status = 3;
|
||||
}
|
||||
m.put("status",status);
|
||||
li.add(m);
|
||||
|
||||
}else {
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("对方接口链接超时");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("调用接口异常报错==="+e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Map<String, List<Map<String, String>>> detailTableValue = this.getDetailTableValue(requestInfo);
|
||||
|
||||
List<Map<String, String>> values = detailTableValue.get(detailkey);
|
||||
for(int i = 0;i < values.size();i ++){
|
||||
Map<String, String> m = values.get(i);
|
||||
String value = m.get(valueUpdateFiledName);
|
||||
int status = (int) li.get(i).get("status");
|
||||
log.info("li===="+li);
|
||||
String updateSql = "update "+accountMessageTableName+" set "+statusName+"= ? where "+updateFieldName+"= ?";
|
||||
log.info("updateSql更新的sql语句"+updateSql);
|
||||
boolean b = rs.executeUpdate(updateSql, status, value);
|
||||
log.info("更新合同台账信息===="+b);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("台账状态更新异常:"+e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
log.info("action done;requestid:" + requestid);
|
||||
return Action.SUCCESS;
|
||||
}catch (Exception e1){
|
||||
log.error("requestid:" + requestInfo.getRequestid() + ";mesage:" + e1.getMessage() + ";e:" + e1);
|
||||
requestManager.setMessageid(String.valueOf(System.currentTimeMillis()));
|
||||
requestManager.setMessagecontent("action 异常,请联系管理员!");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUniqueCode() {
|
||||
return uniqueCode;
|
||||
}
|
||||
|
||||
public void setUniqueCode(String uniqueCode) {
|
||||
this.uniqueCode = uniqueCode;
|
||||
}
|
||||
|
||||
public String getApikey() {
|
||||
return apikey;
|
||||
}
|
||||
|
||||
public void setApikey(String apikey) {
|
||||
this.apikey = apikey;
|
||||
}
|
||||
|
||||
public String getAccountMessageTableName() {
|
||||
return accountMessageTableName;
|
||||
}
|
||||
|
||||
public void setAccountMessageTableName(String accountMessageTableName) {
|
||||
this.accountMessageTableName = accountMessageTableName;
|
||||
}
|
||||
|
||||
public String getStatusName() {
|
||||
return statusName;
|
||||
}
|
||||
|
||||
public void setStatusName(String statusName) {
|
||||
this.statusName = statusName;
|
||||
}
|
||||
|
||||
public String getUpdateFieldName() {
|
||||
return updateFieldName;
|
||||
}
|
||||
|
||||
public void setUpdateFieldName(String updateFieldName) {
|
||||
this.updateFieldName = updateFieldName;
|
||||
}
|
||||
|
||||
public String getValueUpdateFiledName() {
|
||||
return valueUpdateFiledName;
|
||||
}
|
||||
|
||||
public void setValueUpdateFiledName(String valueUpdateFiledName) {
|
||||
this.valueUpdateFiledName = valueUpdateFiledName;
|
||||
}
|
||||
|
||||
public String getDetailkey() {
|
||||
return detailkey;
|
||||
}
|
||||
|
||||
public void setDetailkey(String detailkey) {
|
||||
this.detailkey = detailkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取所有明细数据</h2>
|
||||
*
|
||||
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||
*/
|
||||
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
|
||||
for (DetailTable detailTable : detailTableArr) {
|
||||
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||
detailDataList.put(detailTable.getId(), detailData);
|
||||
}
|
||||
return detailDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据明细表信息获取明细表数据</h2>
|
||||
*
|
||||
* @param detailTable 明细表对象
|
||||
* @return 明细表数据
|
||||
*/
|
||||
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||
Row[] rowArr = detailTable.getRow();
|
||||
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||
for (Row row : rowArr) {
|
||||
Cell[] cellArr = row.getCell();
|
||||
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
|
||||
for (Cell cell : cellArr) {
|
||||
String fieldName = cell.getName();
|
||||
String value = cell.getValue();
|
||||
rowData.put(fieldName, value);
|
||||
}
|
||||
detailData.add(rowData);
|
||||
}
|
||||
return detailData;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
package weaver.chaoyang.he.hcy_pcn.sendfieldstoothersystem.action;
|
||||
|
||||
import aiyh.utils.httpUtil.HttpMultipartFile;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.Util;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.xiao.commons.config.entity.MultipartFile;
|
||||
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||
import weaver.xiao.commons.config.service.DealWithMapping;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SendFieldsAction implements Action {
|
||||
|
||||
private String clientId; //由SBS提供clientId
|
||||
private String clientSecret; //由SBS提供clientSecret
|
||||
private final DealWithMapping dealWithMapping = new DealWithMapping();
|
||||
private String onlyMark;//用于查询配置表的唯一标识
|
||||
private final Logger log = aiyh.utils.Util.getLogger();
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
String tableName = requestInfo.getRequestManager().getBillTableName();
|
||||
String requestId = requestInfo.getRequestid();
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "select * from " + tableName + " where requestid = ?";
|
||||
log.info("sql======>" + sql);
|
||||
String response = "";
|
||||
int code;
|
||||
String data = "";
|
||||
dealWithMapping.setMainTable(tableName);
|
||||
try {
|
||||
if (rs.executeQuery(sql, requestId) && rs.next()) {
|
||||
RequestMappingConfig config = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
||||
String post_url = config.getRequestUrl();
|
||||
// 生成的map数据
|
||||
Map<String, Object> mapBodyParam = dealWithMapping.getRequestParam(rs, config);
|
||||
// 获取多文件数据信息
|
||||
List<MultipartFile> multipartFileList = dealWithMapping.getMultipartFileList();
|
||||
List<HttpMultipartFile> multipartFiles = new ArrayList<>();
|
||||
for (MultipartFile multipartFile : multipartFileList) {
|
||||
HttpMultipartFile multipart
|
||||
= new HttpMultipartFile();
|
||||
multipart.setFileKey(multipartFile.getFileKey());
|
||||
multipart.setFileName(multipartFile.getFileName());
|
||||
multipart.setFileSize(multipartFile.getFileSize());
|
||||
multipart.setStream(multipartFile.getStream());
|
||||
multipartFiles.add(multipart);
|
||||
}
|
||||
// 请求头
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String nonce = this.getRandomNumber();
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("Content-Type", MediaType.MULTIPART_FORM_DATA);
|
||||
headers.put("X-Timestamp", timestamp);
|
||||
headers.put("X-Client-Id", clientId);
|
||||
headers.put("X-Nonce", nonce);
|
||||
headers.put("user-agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36");
|
||||
headers.put("X-Sign", this.sign(timestamp, nonce));
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
try {
|
||||
// httpUtils.uploadFileByInputStream();//调用文件上传的接口
|
||||
ResponeVo responeVo = httpUtils.apiPutUploadFiles(post_url, multipartFiles, mapBodyParam, headers);
|
||||
response = Util.null2String(responeVo.getEntityString());
|
||||
code = responeVo.getCode();
|
||||
if (code == 200) {
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
data = String.valueOf(entityMap.get("data"));
|
||||
if (data.equals("true")) {
|
||||
return Action.SUCCESS;
|
||||
} else {
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
} else {
|
||||
log.info("状态请求失败,对方相应code不为200");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("fetch " + post_url + " error!");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("action execute fail! error msg : \n" + aiyh.utils.Util.getErrString(e));
|
||||
}
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getOnlyMark() {
|
||||
return onlyMark;
|
||||
}
|
||||
|
||||
public void setOnlyMark(String onlyMark) {
|
||||
this.onlyMark = onlyMark;
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机码
|
||||
*/
|
||||
private String getRandomNumber() {
|
||||
byte[] result = new byte[16];
|
||||
SecureRandom secRandom = new SecureRandom();
|
||||
secRandom.nextBytes(result);
|
||||
return Hex.encodeHexString(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST签名
|
||||
*/
|
||||
private String sign(String timestamp, String nonce) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(timestamp).append(nonce).append(clientSecret);
|
||||
log.info("body签名字符串:{},timestamp:{},nonce:{}");
|
||||
System.out.println("签名:" + SecureUtil.md5(sb.toString()));
|
||||
return SecureUtil.md5(sb.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package weaver.chaoyang.he.hcy_pcn.workflowsetvalue.action;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.Util;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Property;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.soa.workflow.request.RequestService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 业务需求在A流程归档前增加aciton,
|
||||
* 将A中的部分字段信息(包括附件),
|
||||
* 根据requestid更新到B流程中,
|
||||
* 并且将B流程提交到下一节点。
|
||||
*/
|
||||
public class SubmitAtoBAction implements Action {
|
||||
|
||||
/**
|
||||
* 目标请求参数字段
|
||||
*/
|
||||
private String targetRequestField;
|
||||
|
||||
/**
|
||||
* 配置文件唯一标识
|
||||
*/
|
||||
private String uniqueFieldId;
|
||||
|
||||
private final Logger log = aiyh.utils.Util.getLogger();
|
||||
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
|
||||
String sql = "select * from uf_lczdzdypzb where wybs = '" + uniqueFieldId +"'"; //查询uf_lczdzdypzb流程字段值对应配置表的数据
|
||||
RecordSet rs = new RecordSet(); //创建sql对象
|
||||
RecordSet rs02 = new RecordSet();//创建sql02对象
|
||||
rs.executeQuery(sql);//执行sql语句
|
||||
|
||||
Map<String, String> tableInfo = this.getWfMainTableInfo(requestInfo);//原流程数据
|
||||
|
||||
String mainId = "";//查询主表中id,用于对应明细表中mainid
|
||||
String mbzd="";//目标字段
|
||||
String yzd = "";//原字段
|
||||
String setRule = "";//update中set条件
|
||||
Map<String,String> mapKey = new HashMap<>();
|
||||
|
||||
if (rs.next()){
|
||||
mainId = rs.getString("id");//查询主表中id,用于对应明细表中mainid
|
||||
log.info("查询主表中id,用于对应明细表中mainid---mainid==="+mainId);
|
||||
//todo 通过workflowid查数据库表获取表名
|
||||
String sql_dt1 = "select ck1.fieldname mbzd, ck.fieldname yzd from uf_lczdzdypzb_dt1 dt left join workflow_field_table_view ck on dt.yzd = ck.id left join workflow_field_table_view ck1 on dt.mbzd = ck1.id where mainid = ?";//查询明细表
|
||||
rs02.executeQuery(sql_dt1,mainId);//执行明细表sql语句
|
||||
while (rs02.next()){
|
||||
mbzd = rs02.getString("mbzd");//目标字段
|
||||
yzd = rs02.getString("yzd");//原字段
|
||||
mapKey.put(mbzd,yzd);
|
||||
log.info("明细表执行结果>>>>>>>>>>"+"目标字段="+mbzd+"-----原字段="+yzd);
|
||||
}
|
||||
RequestService requestService=new RequestService();
|
||||
//todo 获取表名
|
||||
String targetRequestId = tableInfo.get(targetRequestField);
|
||||
String tableName = requestService.getRequest(Util.getIntValue(targetRequestId)).getRequestManager().getBillTableName();
|
||||
Set<String> keySet = mapKey.keySet();
|
||||
for (String s : keySet) {
|
||||
String valueYzd = tableInfo.get(mapKey.get(s));
|
||||
setRule += s + "= " + "'" + valueYzd + "'" +" ,";
|
||||
}
|
||||
setRule = setRule.substring(0,setRule.length()-1);
|
||||
log.info("update中set条件,setRule==="+setRule);
|
||||
|
||||
String sqlmbLc = "update "+tableName+" set " + setRule + " where requestid = ?";//update 目标流程 set 目标字段 = 原字段 where requestid = ? ;
|
||||
rs.executeUpdate(sqlmbLc,targetRequestId);
|
||||
log.info("更新语句update>>>>>>"+ sqlmbLc +"===requestid="+targetRequestId);
|
||||
log.info("B流程开始提交");
|
||||
boolean b = requestService.nextNodeBySubmit(requestService.getRequest(Util.getIntValue(targetRequestId)), Util.getIntValue(targetRequestId), 1, "action自动提交流程(流程字段赋值)");
|
||||
|
||||
log.info("B流程提交结束");
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
public String getTargetRequestField() {
|
||||
return targetRequestField;
|
||||
}
|
||||
|
||||
public void setTargetRequestField(String targetRequestField) {
|
||||
this.targetRequestField = targetRequestField;
|
||||
}
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程主表数据
|
||||
*
|
||||
* @param requestInfo 流程信息对象
|
||||
* @return Map<String, String> key 字段名 value 字段值
|
||||
*/
|
||||
public Map<String, String> getWfMainTableInfo(RequestInfo requestInfo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Property property : requestInfo.getMainTableInfo().getProperty()) {
|
||||
map.put(property.getName(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package weaver.chaoyang.he.hcy_pcn.workflowsetvalue.action;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.Util;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.Property;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.soa.workflow.request.RequestService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 业务需求在A流程归档前增加aciton,
|
||||
* 将A中的部分字段信息(包括附件),
|
||||
* 根据requestid更新到B流程中,
|
||||
* 并且将B流程提交到下一节点。
|
||||
*/
|
||||
public class SubmitAtoBActionCopy implements Action {
|
||||
|
||||
/**
|
||||
* 目标请求参数字段
|
||||
*/
|
||||
private String targetRequestField;
|
||||
|
||||
/**
|
||||
* 配置文件唯一标识
|
||||
*/
|
||||
private String uniqueFieldId;
|
||||
|
||||
private final Logger log = aiyh.utils.Util.getLogger();
|
||||
|
||||
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
|
||||
String sql = "select * from uf_lczdzdypzb where wybs = '" + uniqueFieldId +"'"; //查询uf_lczdzdypzb流程字段值对应配置表的数据
|
||||
RecordSet rs = new RecordSet(); //创建sql对象
|
||||
RecordSet rs02 = new RecordSet();//创建sql02对象
|
||||
rs.executeQuery(sql);//执行sql语句
|
||||
|
||||
Map<String, String> tableInfo = this.getWfMainTableInfo(requestInfo);//原流程数据
|
||||
|
||||
String mainId = "";//查询主表中id,用于对应明细表中mainid
|
||||
String mbzd="";//目标字段
|
||||
String yzd = "";//原字段
|
||||
String setRule = "";//update中set条件
|
||||
Map<String,String> mapKey = new HashMap<>();
|
||||
|
||||
if (rs.next()){
|
||||
mainId = rs.getString("id");//查询主表中id,用于对应明细表中mainid
|
||||
log.info("查询主表中id,用于对应明细表中mainid---mainid==="+mainId);
|
||||
//todo 通过workflowid查数据库表获取表名
|
||||
String sql_dt1 = "select ck1.fieldname mbzd, ck.fieldname yzd from uf_lczdzdypzb_dt1 dt left join workflow_field_table_view ck on dt.yzd = ck.id left join workflow_field_table_view ck1 on dt.mbzd = ck1.id where mainid = ?";//查询明细表
|
||||
rs02.executeQuery(sql_dt1,mainId);//执行明细表sql语句
|
||||
while (rs02.next()){
|
||||
mbzd = rs02.getString("mbzd");//目标字段
|
||||
yzd = rs02.getString("yzd");//原字段
|
||||
mapKey.put(mbzd,yzd);
|
||||
log.info("明细表执行结果>>>>>>>>>>"+"目标字段="+mbzd+"-----原字段="+yzd);
|
||||
}
|
||||
RequestService requestService=new RequestService();
|
||||
//todo 获取表名
|
||||
String targetRequestId = tableInfo.get(targetRequestField);
|
||||
String tableName = requestService.getRequest(Util.getIntValue(targetRequestId)).getRequestManager().getBillTableName();
|
||||
Set<String> keySet = mapKey.keySet();
|
||||
for (String s : keySet) {
|
||||
String valueYzd = tableInfo.get(mapKey.get(s));
|
||||
setRule += s + "= " + "'" + valueYzd + "'" +" ,";
|
||||
}
|
||||
setRule = setRule.substring(0,setRule.length()-1);
|
||||
log.info("update中set条件,setRule==="+setRule);
|
||||
|
||||
String sqlmbLc = "update "+tableName+" set " + setRule + " where requestid = ?";//update 目标流程 set 目标字段 = 原字段 where requestid = ? ;
|
||||
rs.executeUpdate(sqlmbLc,targetRequestId);
|
||||
log.info("更新语句update>>>>>>"+ sqlmbLc +"===requestid="+targetRequestId);
|
||||
log.info("B流程开始提交");
|
||||
boolean b = requestService.nextNodeBySubmit(requestService.getRequest(Util.getIntValue(targetRequestId)), Util.getIntValue(targetRequestId), 1, "action自动提交流程(流程字段赋值)");
|
||||
|
||||
log.info("B流程提交结束");
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
public String getTargetRequestField() {
|
||||
return targetRequestField;
|
||||
}
|
||||
|
||||
public void setTargetRequestField(String targetRequestField) {
|
||||
this.targetRequestField = targetRequestField;
|
||||
}
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程主表数据
|
||||
*
|
||||
* @param requestInfo 流程信息对象
|
||||
* @return Map<String, String> key 字段名 value 字段值
|
||||
*/
|
||||
public Map<String, String> getWfMainTableInfo(RequestInfo requestInfo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Property property : requestInfo.getMainTableInfo().getProperty()) {
|
||||
map.put(property.getName(), property.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.filterinvoice;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.engine.common.service.BrowserTabService;
|
||||
import com.engine.common.service.impl.BrowserTabServiceImpl;
|
||||
import com.engine.core.cfg.annotation.ServiceDynamicProxy;
|
||||
import com.engine.core.cfg.annotation.ServiceMethodDynamicProxy;
|
||||
import com.engine.core.impl.aop.AbstractServiceProxy;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ServiceDynamicProxy(target = BrowserTabServiceImpl.class, desc="实现BrowserTabService对象用于过滤除去航信的数据")
|
||||
public class FilterInvoiceService extends AbstractServiceProxy implements BrowserTabService {
|
||||
private final Logger logger = Util.getLogger();
|
||||
@Override
|
||||
@ServiceMethodDynamicProxy(desc="过滤除去AP航信的数据")
|
||||
public Map<String, Object> list(Map<String, Object> map) {
|
||||
Map result = (Map)executeMethod(map);
|
||||
logger.info("result==="+result);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(Map<String, Object> map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//api/common/browsetab/list?type=293&__random__=1677073032544
|
||||
}
|
|
@ -0,0 +1,326 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.sendinvoicevaluestoaccounttable.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
import weaver.wechat.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class InvoiceValuesToAccountTableAction extends BaseCronJob {
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
private String uniqueFieldId;
|
||||
|
||||
private String url;//请求的接口的url
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
String sql1 = "select taxNo,belongTo from uf_TaxNo_Config";
|
||||
RecordSet rs1 = new RecordSet();
|
||||
rs1.executeQuery(sql1);
|
||||
|
||||
//获取上一次操作的日期
|
||||
String startDay = Util.getCusConfigValue("getDataTime");
|
||||
|
||||
//获取当前的日期
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String endDay = dateFormat.format(date);
|
||||
|
||||
while(rs1.next()){
|
||||
|
||||
String taxNo = Util.null2String(rs1.getString("taxNo"));
|
||||
String belongTo = Util.null2String(rs1.getString("belongTo"));
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)");
|
||||
headers.put("Content-Type", "application/json");
|
||||
|
||||
String dateAddday3 = dateAdd3(startDay);
|
||||
logger.info("开始时间往前推3天--dateAddday3==="+dateAddday3);
|
||||
//设置请求体
|
||||
Map<String,Object> body = new HashMap<>();
|
||||
body.put("identity",taxNo);
|
||||
body.put("startDay",dateAddday3);
|
||||
body.put("endDay",endDay);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
|
||||
ResponeVo responeVo = httpUtils.apiPost(url, body, headers);
|
||||
int code = responeVo.getCode();
|
||||
if (code != 200){
|
||||
logger.info("对方接口状态码为:"+code+" 程序执行错误");
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
List<Object> datas = (List<Object>)entityMap.get("data");
|
||||
if (datas==null ||datas.isEmpty()){
|
||||
logger.info("接口返回主表参数为空,请查询税号是否准确");
|
||||
continue;
|
||||
}
|
||||
Map<String,Object> totalDataMap = new HashMap<String,Object>();
|
||||
String invoice_detail_Mainid = "";//用来判断台账表中是否含有相同记录
|
||||
for (Object data : datas){
|
||||
totalDataMap = (Map<String,Object>)data;//主表数据
|
||||
logger.info("主表数据==="+totalDataMap);
|
||||
//第五步:查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
Object invoiceCode = totalDataMap.get("invoiceCode");//发票代码
|
||||
Object invoiceNum = totalDataMap.get("invoiceNum");//发票号码
|
||||
|
||||
//需求更新:需要在主表数据中选出卖方税号,这里的卖方税号=供应商库uf_gysxx里面的供应商税号
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String serllerTaxNo = Utils.null2String(totalDataMap.get("sellerTaxNo"));//销方税号
|
||||
String sellerName = Utils.null2String(totalDataMap.get("sellerName"));//销方名称
|
||||
logger.info("销方税号--serllerTaxNo==="+serllerTaxNo+"--销方名称---sellerName==="+sellerName);
|
||||
String getuf_gysxx_countId = "select count(id) countId from uf_gysxx where gyssh = ?";
|
||||
boolean getuf_gysxx_countId_boolean = recordSet.executeQuery(getuf_gysxx_countId, serllerTaxNo);
|
||||
logger.info("getuf_gysxx_countId_boolean是否执行"+getuf_gysxx_countId_boolean);
|
||||
if (getuf_gysxx_countId_boolean&&recordSet.next()) {
|
||||
String countId = Utils.null2String(recordSet.getString("countId"));//查询到的数据的条数
|
||||
int countIdInt=0;
|
||||
if (!"".equals(countId)){
|
||||
countIdInt = Integer.parseInt(countId);
|
||||
logger.info("数据一共有几条==="+countId);
|
||||
}
|
||||
if (countIdInt==0){
|
||||
continue;
|
||||
}
|
||||
// if ((!countId.equals("1"))){
|
||||
// continue;
|
||||
// }
|
||||
RecordSet recordSet1 = new RecordSet();
|
||||
String getdataFrom_uf_gysxx = "select qfzd,hkyfjkgs from uf_gysxx where gyssh = ? and gysmc = ?";
|
||||
boolean getdataFrom_uf_gysxx_boolean = recordSet1.executeQuery(getdataFrom_uf_gysxx, serllerTaxNo, sellerName);
|
||||
logger.info("getdataFrom_uf_gysxx_boolean是否执行==="+getdataFrom_uf_gysxx_boolean);
|
||||
if (getdataFrom_uf_gysxx_boolean && recordSet1.next()){
|
||||
String qfzd = Utils.null2String(recordSet1.getString("qfzd"));//区分字段
|
||||
// String hkyfjkgs = Utils.null2String(recordSet1.getString("hkyfjkgs"));//货款/运费/进口关税
|
||||
if ((!qfzd.equals("0"))){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查询发票类型对应配置表:将想要转换的发票类型提前转换
|
||||
String queryInvoiceType = "select oaTypeValue from uf_InvoiceType_Mapping where interfaceTypeValue = ?";//改一下
|
||||
RecordSet rs2 = new RecordSet();
|
||||
rs2.executeQuery(queryInvoiceType,totalDataMap.get("invoiceType"));
|
||||
if (rs2.next()){
|
||||
String oaTypeValue = Util.null2String(rs2.getString("oaTypeValue"));
|
||||
totalDataMap.put("invoiceType",oaTypeValue);//转换发票类型
|
||||
logger.info("转换发票类型==="+oaTypeValue);
|
||||
}else {
|
||||
continue;
|
||||
// totalDataMap.put("invoiceType","-1");//如果接口中的发票类型
|
||||
}
|
||||
|
||||
//将时间戳转换成yyyy-MM-dd
|
||||
String invoiceDate = (String)totalDataMap.get("invoiceDate");
|
||||
String new_invoiceDate = this.stampToDate(invoiceDate);
|
||||
totalDataMap.put("invoiceDate",new_invoiceDate);
|
||||
logger.info("转换后的时间戳====="+new_invoiceDate);
|
||||
|
||||
//查询台账表中是否包含这个数据
|
||||
String sql2 = "select id from fnaInvoiceLedger where invoicecode = ? and invoicenumber = ?";
|
||||
|
||||
rs2.executeQuery(sql2,invoiceCode,invoiceNum);
|
||||
if (rs2.next()) {
|
||||
invoice_detail_Mainid = rs2.getString("id");
|
||||
logger.info("===invoice_detail_Mainid==="+invoice_detail_Mainid);
|
||||
}else{
|
||||
invoice_detail_Mainid = "";
|
||||
}
|
||||
|
||||
String mainId = "";
|
||||
String detailID = "";
|
||||
String updateSetkey = "";//当台账表中存在一条一样的数据的时候,我们需要设置更新条件
|
||||
List<Object> updateSetVaule = new ArrayList<>();//用来处理update条件下,?的赋值
|
||||
String insertSetKey = "(";//向台账中插入的key
|
||||
String insertSetValue = "(";//向台账中插入的value
|
||||
//第四步:通过配置的配置表获得到客户传的参数和台账字段的对应关系
|
||||
String sql3 = "select * from uf_fptzdypzbd where wybs = ?";//查询台账配置表
|
||||
if (rs2.executeQuery(sql3,uniqueFieldId)&&rs2.next()) {
|
||||
mainId = rs2.getString("id");//查询发票台账对应配置表的id对应查询明细表的mainid
|
||||
String sqlDetail1 = "select * from uf_fptzdypzbd_dt1 where mainid = ?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlDetail1,mainId);
|
||||
|
||||
while(rs3.next()){
|
||||
String jkhqcs = rs3.getString("jkhqcs");//接口获取主表参数
|
||||
String sjkzcs = rs3.getString("sjkzcs");//数据库中主表参数
|
||||
String zhlx = rs3.getString("zhlx");//转换类型
|
||||
String zdyz = rs3.getString("zdyz");//自定义值
|
||||
if (zhlx!=""&&zhlx.equals("0")){
|
||||
updateSetkey += sjkzcs + "=" + "?,";
|
||||
insertSetKey += sjkzcs + ",";
|
||||
insertSetValue += "?"+",";
|
||||
updateSetVaule.add(totalDataMap.get(jkhqcs));
|
||||
}else if (zhlx!=""&&zhlx.equals("1")){
|
||||
updateSetkey += sjkzcs + "=" + "?,";
|
||||
insertSetKey += sjkzcs + ",";
|
||||
insertSetValue += "?"+",";
|
||||
updateSetVaule.add(zdyz);
|
||||
}
|
||||
}
|
||||
//拼接 发票归属人
|
||||
updateSetkey = updateSetkey + "userid_new=?";
|
||||
updateSetVaule.add(Integer.parseInt(belongTo));
|
||||
insertSetKey = insertSetKey+"userid_new)";
|
||||
insertSetValue = insertSetValue+"?)";
|
||||
|
||||
|
||||
|
||||
logger.info("updateSetKey====="+updateSetkey);
|
||||
logger.info("updateSetVaule====="+updateSetVaule);
|
||||
logger.info("insertSetKey====="+insertSetKey);
|
||||
logger.info("insertSetValue====="+insertSetValue);
|
||||
}
|
||||
//查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
logger.info("主表数据id---invoice_detail_Mainid==="+invoice_detail_Mainid);
|
||||
if (!"".equals(Util.null2String(invoice_detail_Mainid))){//执行更新语句
|
||||
RecordSet recordSet4 = new RecordSet();
|
||||
String getHxjksflrSql = "select * from fnaInvoiceLedger where id = ?";
|
||||
boolean getHxjksflrBool = recordSet4.executeQuery(getHxjksflrSql, invoice_detail_Mainid);
|
||||
logger.info("getHxjksflrBool是否执行==="+getHxjksflrBool);
|
||||
String isApInvoice = "";
|
||||
if (getHxjksflrBool && recordSet4.next()){
|
||||
isApInvoice = Util.null2String(recordSet4.getString("hxjksflr"));// 判断这条数据是不是航信接口导入的数据
|
||||
logger.info("isApInvoice==="+isApInvoice);
|
||||
}
|
||||
|
||||
if ("Y".equals(isApInvoice)){
|
||||
updateSetVaule.add(invoiceCode);
|
||||
updateSetVaule.add(invoiceNum);
|
||||
String sqlUpdate = "update fnaInvoiceLedger set "+updateSetkey +" where invoicecode = ? and invoicenumber = ? ";
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
logger.info("sqlUpdate更新的update语句====="+sqlUpdate);
|
||||
boolean b = rs2.executeUpdate(sqlUpdate, objects);
|
||||
logger.info("主表的更新语句是否更新=="+b);
|
||||
}
|
||||
}else{
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
String sqlInsert = "insert into fnaInvoiceLedger "+insertSetKey+" values "+insertSetValue;
|
||||
logger.info("sqlInsert插入的insert语句======"+sqlInsert);
|
||||
boolean b = rs2.executeUpdate(sqlInsert, objects);
|
||||
logger.info("主表的插入语句是否插入=="+b);
|
||||
}
|
||||
//查询到刚插入的数据的id作为明细表的mainid
|
||||
String sqlSelectId = "select id from fnaInvoiceLedger where invoicecode=? and invoicenumber=?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlSelectId,invoiceCode,invoiceNum);
|
||||
if (rs3.next()){
|
||||
detailID= Util.null2String(rs3.getString("id"));
|
||||
logger.info("detailID==="+detailID);
|
||||
}
|
||||
//向台账明细表中插入数据操作
|
||||
List<Object> details = (List<Object>)totalDataMap.get("detail");//明细表数据
|
||||
logger.info("明细表数据"+details);
|
||||
String invoiceDetailSql = "delete from fnainvoiceledgerdetail where mainid = ?";//不管明细表中有没有内容一律删掉
|
||||
logger.info("不管明细表中有没有内容一律删掉sql语句==="+invoiceDetailSql);
|
||||
boolean b1 = rs3.executeUpdate(invoiceDetailSql, detailID);
|
||||
logger.info("删除操作是否成功b1===="+b1);
|
||||
Map<String,Object> detailsMap = new HashMap<>();
|
||||
if (details ==null || details.isEmpty()){
|
||||
logger.info("明细表内容为空!跳出明细表出入循环");
|
||||
continue;
|
||||
}
|
||||
//开始查询配置表获得到客户传的明细表中参数和台账明细表中字段的对应关系
|
||||
for (Object detail : details) {
|
||||
detailsMap = (Map<String,Object>)detail;
|
||||
String sqlDetail2 = "select * from uf_fptzdypzbd_dt2 where mainid = ?";
|
||||
rs3.executeQuery(sqlDetail2,mainId);
|
||||
String insertDetailSetKey = "(";//insert条件的拼接字符串1
|
||||
String insertDetailSetValue = "(";//insert条件的拼接字符串2
|
||||
List<Object> listDetail = new ArrayList<>();//用来将?赋值
|
||||
while (rs3.next()){
|
||||
String jkhqmxbzcs = Util.null2String(rs3.getString("jkhqmxbzcs"));//接口获取明细表中参数
|
||||
String jkhqmxbzcslx = Util.null2String(rs3.getString("jkhqmxbzcslx"));//接口获取明细表中参数类型
|
||||
String sjkzmxbcs = Util.null2String(rs3.getString("sjkzmxbcs"));//数据库中明细表参数
|
||||
String sjkzmxbcslx = Util.null2String(rs3.getString("sjkzmxbcslx"));//数据库中明细表参数类型
|
||||
insertDetailSetKey += sjkzmxbcs + ",";
|
||||
insertDetailSetValue += "?,";
|
||||
listDetail.add(detailsMap.get(jkhqmxbzcs));
|
||||
|
||||
}
|
||||
insertDetailSetKey = insertDetailSetKey + "mainid)";
|
||||
insertDetailSetValue = insertDetailSetValue+"?)";
|
||||
listDetail.add(detailID);
|
||||
logger.info("明细表中用来插入的setkey---insertDetailSetKey==="+insertDetailSetKey);
|
||||
logger.info("明细表中用来插入的setvalue---insertDetailSetValue==="+insertDetailSetValue);
|
||||
logger.info("用来拼接?的listDetail"+listDetail);
|
||||
|
||||
String insertIntoDetailSql = "insert into fnainvoiceledgerdetail "+insertDetailSetKey+ "values "+insertDetailSetValue ;
|
||||
logger.info("insertIntoDetailSql明细表的插入语句==="+insertIntoDetailSql);
|
||||
boolean b = rs3.executeUpdate(insertIntoDetailSql, listDetail);
|
||||
logger.info("明细表数据插入是否成功===="+b);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将当前时间设置到配置表中,作为下一次的开始时间
|
||||
logger.info("最后更新到配置表中的时间endDay==="+endDay);
|
||||
Util.insertOrUpdateConfigValue("getDataTime",endDay,"更新同步时间");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 将时间戳转换为时间
|
||||
*/
|
||||
public static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long lt = new Long(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String dateAdd3(String dateString){
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); //定义日期格式化的格式
|
||||
Date classDate = null;//把字符串转化成指定格式的日期
|
||||
try {
|
||||
classDate = format.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance(); //使用Calendar日历类对日期进行加减
|
||||
calendar.setTime(classDate);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -3);
|
||||
classDate = calendar.getTime();//获取加减以后的Date类型日期
|
||||
String lastDate = format.format(classDate);
|
||||
return lastDate;
|
||||
}
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.sendinvoicevaluestoaccounttable.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class InvoiceValuesToAccountTableAction01 extends BaseCronJob {
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
private String uniqueFieldId;
|
||||
|
||||
private String url;//请求的接口的url
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
String sql1 = "select taxNo,belongTo from uf_TaxNo_Config";
|
||||
RecordSet rs1 = new RecordSet();
|
||||
rs1.executeQuery(sql1);
|
||||
|
||||
//获取上一次操作的日期
|
||||
String startDay = Util.getCusConfigValue("getDataTime");
|
||||
|
||||
//获取当前的日期
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String endDay = dateFormat.format(date);
|
||||
|
||||
while(rs1.next()){
|
||||
|
||||
String taxNo = rs1.getString("taxNo");
|
||||
String belongTo = rs1.getString("belongTo");
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)");
|
||||
headers.put("Content-Type", "application/json");
|
||||
|
||||
|
||||
//设置请求体
|
||||
Map<String,Object> body = new HashMap<>();
|
||||
body.put("identity",taxNo);
|
||||
body.put("startDay",startDay);
|
||||
body.put("endDay",endDay);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
|
||||
ResponeVo responeVo = httpUtils.apiPost(url, body, headers);
|
||||
int code = responeVo.getCode();
|
||||
if (code != 200){
|
||||
logger.info("对方接口状态码为:"+code+" 程序执行错误");
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
List<Object> datas = (List<Object>)entityMap.get("data");
|
||||
if (datas==null ||datas.isEmpty()){
|
||||
logger.info("接口返回主表参数为空,请查询税号是否准确");
|
||||
continue;
|
||||
}
|
||||
Map<String,Object> totalDataMap = new HashMap<String,Object>();
|
||||
String invoice_detail_Mainid = "";//用来判断台账表中是否含有相同记录
|
||||
for (Object data : datas){
|
||||
totalDataMap = (Map<String,Object>)data;//主表数据
|
||||
logger.info("主表数据==="+totalDataMap);
|
||||
//第五步:查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
Object invoiceCode = totalDataMap.get("invoiceCode");//发票代码
|
||||
Object invoiceNum = totalDataMap.get("invoiceNum");//发票号码
|
||||
|
||||
//查询发票类型对应配置表:将想要转换的发票类型提前转换
|
||||
String queryInvoiceType = "select oaTypeValue from uf_InvoiceType_Mapping where interfaceTypeValue = ?";//改一下
|
||||
RecordSet rs2 = new RecordSet();
|
||||
rs2.executeQuery(queryInvoiceType,totalDataMap.get("invoiceType"));
|
||||
if (rs2.next()){
|
||||
String oaTypeValue = rs2.getString("oaTypeValue");
|
||||
totalDataMap.put("invoiceType",oaTypeValue);//转换发票类型
|
||||
logger.info("转换发票类型==="+oaTypeValue);
|
||||
}else {
|
||||
totalDataMap.put("invoiceType","-1");//如果接口中的发票类型
|
||||
}
|
||||
|
||||
//将时间戳转换成yyyy-MM-dd
|
||||
String invoiceDate = (String)totalDataMap.get("invoiceDate");
|
||||
String new_invoiceDate = this.stampToDate(invoiceDate);
|
||||
totalDataMap.put("invoiceDate",new_invoiceDate);
|
||||
logger.info("转换后的时间戳====="+new_invoiceDate);
|
||||
|
||||
//查询台账表中是否包含这个数据
|
||||
String sql2 = "select id from fnaInvoiceLedger where invoicecode = ? and invoicenumber = ?";
|
||||
|
||||
rs2.executeQuery(sql2,invoiceCode,invoiceNum);
|
||||
if (rs2.next()) {
|
||||
invoice_detail_Mainid = rs2.getString("id");
|
||||
}
|
||||
|
||||
String mainId = "";
|
||||
String detailID = "";
|
||||
String updateSetkey = "";//当台账表中存在一条一样的数据的时候,我们需要设置更新条件
|
||||
List<Object> updateSetVaule = new ArrayList<>();//用来处理update条件下,?的赋值
|
||||
String insertSetKey = "(";//向台账中插入的key
|
||||
String insertSetValue = "(";//向台账中插入的value
|
||||
//第四步:通过配置的配置表获得到客户传的参数和台账字段的对应关系
|
||||
String sql3 = "select * from uf_fptzdypzbd where wybs = ?";//查询台账配置表
|
||||
if (rs2.executeQuery(sql3,uniqueFieldId)&&rs2.next()) {
|
||||
mainId = rs2.getString("id");//查询发票台账对应配置表的id对应查询明细表的mainid
|
||||
String sqlDetail1 = "select * from uf_fptzdypzbd_dt1 where mainid = ?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlDetail1,mainId);
|
||||
while(rs3.next()){
|
||||
String jkhqcs = rs3.getString("jkhqcs");//接口获取主表参数
|
||||
String jkhqzbcslx = rs3.getString("jkhqzbcslx");//接口获取主表参数类型
|
||||
String sjkzcs = rs3.getString("sjkzcs");//数据库中主表参数
|
||||
String sjkzzbcslx = rs3.getString("sjkzzbcslx");//数据库中主表参数类型
|
||||
updateSetkey += sjkzcs + "=" + "?,";
|
||||
insertSetKey += sjkzcs + ",";
|
||||
insertSetValue += "?"+",";
|
||||
updateSetVaule.add(totalDataMap.get(jkhqcs));
|
||||
}
|
||||
//拼接 发票归属人
|
||||
updateSetkey = updateSetkey + "userid_new=?";
|
||||
updateSetVaule.add(Integer.parseInt(belongTo));
|
||||
insertSetKey = insertSetKey+"userid_new)";
|
||||
insertSetValue = insertSetValue+"?)";
|
||||
|
||||
logger.info("updateSetKey====="+updateSetkey);
|
||||
logger.info("updateSetVaule====="+updateSetVaule);
|
||||
logger.info("insertSetKey====="+insertSetKey);
|
||||
logger.info("insertSetValue====="+insertSetValue);
|
||||
}
|
||||
//查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
if (!"".equals(invoice_detail_Mainid)){//执行更新语句
|
||||
updateSetVaule.add(invoiceCode);
|
||||
updateSetVaule.add(invoiceNum);
|
||||
String sqlUpdate = "update fnaInvoiceLedger set "+updateSetkey +" where invoicecode = ? and invoicenumber = ? ";
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
logger.info("sqlUpdate更新的update语句====="+sqlUpdate);
|
||||
boolean b = rs2.executeUpdate(sqlUpdate, objects);
|
||||
logger.info("主表的更新语句是否更新=="+b);
|
||||
}else{
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
String sqlInsert = "insert into fnaInvoiceLedger "+insertSetKey+" values "+insertSetValue;
|
||||
logger.info("sqlInsert插入的insert语句======"+sqlInsert);
|
||||
boolean b = rs2.executeUpdate(sqlInsert, objects);
|
||||
logger.info("主表的插入语句是否插入=="+b);
|
||||
}
|
||||
//查询到刚插入的数据的id作为明细表的mainid
|
||||
String sqlSelectId = "select id from fnaInvoiceLedger where invoicecode=? and invoicenumber=?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlSelectId,invoiceCode,invoiceNum);
|
||||
if (rs3.next()){
|
||||
detailID= rs3.getString("id");
|
||||
logger.info("detailID==="+detailID);
|
||||
}
|
||||
//向台账明细表中插入数据操作
|
||||
List<Object> details = (List<Object>)totalDataMap.get("detail");//明细表数据
|
||||
logger.info("明细表数据"+details);
|
||||
String invoiceDetailSql = "delete from fnainvoiceledgerdetail where mainid = ?";//不管明细表中有没有内容一律删掉
|
||||
logger.info("不管明细表中有没有内容一律删掉sql语句==="+invoiceDetailSql);
|
||||
boolean b1 = rs3.executeUpdate(invoiceDetailSql, detailID);
|
||||
logger.info("删除操作是否成功b1===="+b1);
|
||||
Map<String,Object> detailsMap = new HashMap<>();
|
||||
if (details ==null || details.isEmpty()){
|
||||
logger.info("明细表内容为空!跳出明细表出入循环");
|
||||
continue;
|
||||
}
|
||||
//开始查询配置表获得到客户传的明细表中参数和台账明细表中字段的对应关系
|
||||
for (Object detail : details) {
|
||||
detailsMap = (Map<String,Object>)detail;
|
||||
String sqlDetail2 = "select * from uf_fptzdypzbd_dt2 where mainid = ?";
|
||||
rs3.executeQuery(sqlDetail2,mainId);
|
||||
String insertDetailSetKey = "(";//insert条件的拼接字符串1
|
||||
String insertDetailSetValue = "(";//insert条件的拼接字符串2
|
||||
List<Object> listDetail = new ArrayList<>();//用来将?赋值
|
||||
while (rs3.next()){
|
||||
String jkhqmxbzcs = rs3.getString("jkhqmxbzcs");//接口获取明细表中参数
|
||||
String jkhqmxbzcslx = rs3.getString("jkhqmxbzcslx");//接口获取明细表中参数类型
|
||||
String sjkzmxbcs = rs3.getString("sjkzmxbcs");//数据库中明细表参数
|
||||
String sjkzmxbcslx = rs3.getString("sjkzmxbcslx");//数据库中明细表参数类型
|
||||
insertDetailSetKey += sjkzmxbcs + ",";
|
||||
insertDetailSetValue += "?,";
|
||||
listDetail.add(detailsMap.get(jkhqmxbzcs));
|
||||
|
||||
}
|
||||
insertDetailSetKey = insertDetailSetKey + "mainid)";
|
||||
insertDetailSetValue = insertDetailSetValue+"?)";
|
||||
listDetail.add(detailID);
|
||||
logger.info("明细表中用来插入的setkey---insertDetailSetKey==="+insertDetailSetKey);
|
||||
logger.info("明细表中用来插入的setvalue---insertDetailSetValue==="+insertDetailSetValue);
|
||||
logger.info("用来拼接?的listDetail"+listDetail);
|
||||
|
||||
String insertIntoDetailSql = "insert into fnainvoiceledgerdetail "+insertDetailSetKey+ "values "+insertDetailSetValue ;
|
||||
logger.info("insertIntoDetailSql明细表的插入语句==="+insertIntoDetailSql);
|
||||
boolean b = rs3.executeUpdate(insertIntoDetailSql, listDetail);
|
||||
logger.info("明细表数据插入是否成功===="+b);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将当前时间设置到配置表中,作为下一次的开始时间
|
||||
logger.info("最后更新到配置表中的时间endDay==="+endDay);
|
||||
Util.insertOrUpdateConfigValue("getDataTime",endDay,"更新同步时间");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 将时间戳转换为时间
|
||||
*/
|
||||
public static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long lt = new Long(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,301 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.sendinvoicevaluestoaccounttable.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class InvoiceValuesToAccountTableAction02 extends BaseCronJob {
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
private String uniqueFieldId;
|
||||
|
||||
private String url;//请求的接口的url
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
//第一步首先获取税号
|
||||
//第二步获取开票开始时间 格式:yyyy-MM-dd 开票结束时间 格式:yyyy-MM-dd
|
||||
|
||||
try {
|
||||
String sql1 = "select taxNo,belongTo from uf_TaxNo_Config";
|
||||
RecordSet rs1 = new RecordSet();
|
||||
rs1.executeQuery(sql1);
|
||||
while (rs1.next()){
|
||||
//第三步:new一个okhttp这个对象然后获取到客户给我们传的参数
|
||||
String taxNo = rs1.getString("taxNo");
|
||||
String belongTo = rs1.getString("belongTo");
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)");
|
||||
headers.put("Content-Type", "application/json");
|
||||
|
||||
|
||||
//获取上一次操作的日期
|
||||
String startDay = Util.getCusConfigValue("getDataTime");
|
||||
|
||||
//获取当前的日期
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String endDay = dateFormat.format(date);
|
||||
|
||||
//设置请求体
|
||||
Map<String,Object> body = new HashMap<>();
|
||||
body.put("identity",taxNo);
|
||||
// body.put("startDay",startDay);
|
||||
body.put("startDay",startDay);
|
||||
// body.put("endDay",endDay);
|
||||
body.put("endDay",endDay);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
ResponeVo responeVo = httpUtils.apiPost(url, body, headers);
|
||||
int code = responeVo.getCode();
|
||||
if (code != 200){
|
||||
logger.info("对方接口状态码为:"+code+" 程序执行错误");
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
logger.info(entityMap);
|
||||
List<Object> datas = (List<Object>)entityMap.get("data");
|
||||
Map<String,Object> totalDataMap = new HashMap<String,Object>();
|
||||
if (datas == null || datas.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
String invoice_detail_Mainid = "";//用来判断台账表中是否含有相同记录
|
||||
for (Object data : datas) { //主循环,数据都在里面
|
||||
totalDataMap = (Map<String,Object>)data;//主表数据
|
||||
//第五步:查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
Object invoiceCode = totalDataMap.get("invoiceCode");//发票代码
|
||||
Object invoiceNum = totalDataMap.get("invoiceNum");//发票号码
|
||||
|
||||
//查询发票类型对应配置表:将想要转换的发票类型提前转换
|
||||
String queryInvoiceType = "select oaTypeValue from uf_InvoiceType_Mapping where interfaceTypeValue = ?";//改一下
|
||||
RecordSet rs9 = new RecordSet();
|
||||
rs9.executeQuery(queryInvoiceType,totalDataMap.get("invoiceType"));
|
||||
if (rs9.next()){
|
||||
String oaTypeValue = rs9.getString("oaTypeValue");
|
||||
totalDataMap.put("invoiceType",oaTypeValue);//转换发票类型
|
||||
}
|
||||
|
||||
//将时间戳转换成yyyy-hh-dd
|
||||
String invoiceDate = (String)totalDataMap.get("invoiceDate");
|
||||
String new_invoiceDate = this.stampToDate(invoiceDate);
|
||||
totalDataMap.put("invoiceDate",new_invoiceDate);
|
||||
|
||||
|
||||
RecordSet rs2 = new RecordSet();
|
||||
String sql2 = "select id from fnaInvoiceLedger where invoicecode = ? and invoicenumber = ?";//查询台账表中是否包含这个数据
|
||||
|
||||
rs2.executeQuery(sql2,invoiceCode,invoiceNum);
|
||||
if (rs2.next()) {
|
||||
invoice_detail_Mainid = rs2.getString("id");
|
||||
}
|
||||
|
||||
String mainId = "";
|
||||
String detailID = "";
|
||||
//第四步:通过配置的配置表获得到客户传的参数和台账字段的对应关系
|
||||
String sql3 = "select * from uf_fptzdypzbd where wybs = ?";//查询台账配置表
|
||||
String insertSetKey1 = "(";//insert条件的拼接字符串1
|
||||
String insertSetKey2 = "(";//insert条件的拼接字符串2
|
||||
String updateSetkey = "";//update条件的拼接字符串
|
||||
Map<String,String> updateMap = new HashMap<>();//update条件的拼接的map
|
||||
Map<String,Integer> updateIntMap = new HashMap<>();//update条件并且字段类型为int的拼接的map
|
||||
Map<String,Double> updataDoubleMap = new HashMap<>();//update条件并且字段类型为double的拼接的map
|
||||
RecordSet rs3 = new RecordSet();
|
||||
RecordSet rs4 = new RecordSet();
|
||||
if (rs3.executeQuery(sql3,uniqueFieldId)&&rs3.next()){
|
||||
mainId = rs3.getString("id");
|
||||
String sqlDetail1 = "select * from uf_fptzdypzbd_dt1 where mainid = ?";
|
||||
rs4.executeQuery(sqlDetail1,mainId);
|
||||
while (rs4.next()){
|
||||
String jkhqcs = rs4.getString("jkhqcs");//接口获取主表参数
|
||||
String jkhqzbcslx = rs4.getString("jkhqzbcslx");//接口获取主表参数类型
|
||||
String sjkzcs = rs4.getString("sjkzcs");//数据库中主表参数
|
||||
String sjkzzbcslx = rs4.getString("sjkzzbcslx");//数据库中主表参数类型
|
||||
totalDataMap.put(jkhqcs,String.valueOf(totalDataMap.get(jkhqcs)));
|
||||
|
||||
|
||||
if (Integer.valueOf(sjkzzbcslx)==0){
|
||||
updateMap.put(sjkzcs,String.valueOf(totalDataMap.get(jkhqcs)));
|
||||
} else if (Integer.valueOf(sjkzzbcslx)==1){
|
||||
if (Integer.valueOf(jkhqzbcslx)==2){
|
||||
updateIntMap.put(sjkzcs,Double.valueOf(String.valueOf(totalDataMap.get(jkhqcs))).intValue());
|
||||
}else if (Integer.valueOf(jkhqzbcslx)==0){
|
||||
updateIntMap.put(sjkzcs, Integer.parseInt(String.valueOf(totalDataMap.get(jkhqcs))));
|
||||
}
|
||||
} else if (Integer.valueOf(sjkzzbcslx)==2){
|
||||
updataDoubleMap.put(sjkzcs, Double.valueOf(String.valueOf(totalDataMap.get(jkhqcs))));
|
||||
}else if (Integer.valueOf(sjkzzbcslx)==3){
|
||||
updateMap.put(sjkzcs,String.valueOf(totalDataMap.get(jkhqcs)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
updateIntMap.put("userid_new",Integer.parseInt(belongTo));
|
||||
//拼接update的set语句
|
||||
Set<String> splicingUpdate = updateMap.keySet();
|
||||
for (String s : splicingUpdate) {
|
||||
updateSetkey += s + "= " + "'" + updateMap.get(s) + "'" +" ,";
|
||||
insertSetKey1 += s+",";
|
||||
insertSetKey2 += "'"+updateMap.get(s)+"',";
|
||||
}
|
||||
Set<String> splicingIntUpdate = updateIntMap.keySet();
|
||||
for (String s : splicingIntUpdate) {
|
||||
updateSetkey += s + "= " + updateIntMap.get(s) +" ,";
|
||||
insertSetKey1 += s+",";
|
||||
insertSetKey2 += updateIntMap.get(s)+",";
|
||||
}
|
||||
Set<String> splicingDoubleUpdate = updataDoubleMap.keySet();
|
||||
for (String s : splicingDoubleUpdate) {
|
||||
updateSetkey += s + "= " + updataDoubleMap.get(s) +" ,";
|
||||
insertSetKey1 += s+",";
|
||||
insertSetKey2 += updataDoubleMap.get(s)+",";
|
||||
}
|
||||
updateSetkey = updateSetkey.substring(0, updateSetkey.length()-1);
|
||||
insertSetKey1 = insertSetKey1.substring(0,insertSetKey1.length()-1)+")";
|
||||
insertSetKey2 = insertSetKey2.substring(0,insertSetKey2.length()-1)+")";
|
||||
logger.info("updateSetkey条件的查询结果:"+updateSetkey);
|
||||
logger.info("insertSetKey1条件的查询结果:"+insertSetKey1);
|
||||
logger.info("insertSetKey2条件的查询结果:"+insertSetKey2);
|
||||
//查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
if (!"".equals(invoice_detail_Mainid)){//执行更新语句
|
||||
String sqlUpdate = "update fnaInvoiceLedger set "+updateSetkey +" where invoicecode = ? and invoicenumber = ? ";
|
||||
RecordSet rs5 = new RecordSet();
|
||||
rs5.executeUpdate(sqlUpdate,invoiceCode,invoiceNum);
|
||||
}else{
|
||||
String sqlInsert = "insert into fnaInvoiceLedger "+insertSetKey1+" values "+insertSetKey2;
|
||||
logger.info("主表的查询语句sql====="+sqlInsert);
|
||||
RecordSet rs6 = new RecordSet();
|
||||
rs6.executeUpdate(sqlInsert);
|
||||
}
|
||||
|
||||
//查询到刚插入的数据的id作为明细表的mainid
|
||||
String sqlSelectId = "select id from fnaInvoiceLedger where invoicecode=? and invoicenumber=?";
|
||||
RecordSet rs10 = new RecordSet();
|
||||
rs10.executeQuery(sqlSelectId,invoiceCode,invoiceNum);
|
||||
if (rs10.next()){
|
||||
detailID= rs10.getString("id");
|
||||
logger.info("查询到刚插入的数据的id作为明细表的detailID====="+detailID);
|
||||
}
|
||||
|
||||
//向台账明细表中插入数据操作
|
||||
List<Object> details = (List<Object>)totalDataMap.get("detail");//明细表数据
|
||||
String invoiceDetailSql = "delete from fnainvoiceledgerdetail where mainid = ?";//不管明细表中有没有内容一律删掉
|
||||
RecordSet rs6 = new RecordSet();
|
||||
rs6.executeUpdate(invoiceDetailSql,detailID);
|
||||
Map<String,String> detailsMap = new HashMap<>();
|
||||
if (details == null || details.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
for (Object detail : details) {
|
||||
detailsMap = (Map<String,String>)detail;
|
||||
logger.info("查询到的明细表的数据detailsMap"+detailsMap);
|
||||
String sqlDetail2 = "select * from uf_fptzdypzbd_dt2 where mainid = ?";
|
||||
RecordSet rs7 = new RecordSet();
|
||||
rs7.executeQuery(sqlDetail2,mainId);
|
||||
Map<String,String> updateDetailMap = new HashMap<>();//update条件的拼接的明细表中的map
|
||||
Map<String,Integer> updateDetailIntMap = new HashMap<>();//update条件并且字段类型为int的明细表中拼接的map
|
||||
Map<String,Double> updateDetailDoubleMap = new HashMap<>();//update条件并且字段类型为double的明细表中拼接的map
|
||||
String insertDetailSetKey1 = "(";//insert条件的拼接字符串1
|
||||
String insertDetailSetKey2 = "(";//insert条件的拼接字符串2
|
||||
while(rs7.next()){
|
||||
String jkhqmxbzcs = rs7.getString("jkhqmxbzcs");//接口获取明细表中参数
|
||||
String jkhqmxbzcslx = rs7.getString("jkhqmxbzcslx");//接口获取明细表中参数类型
|
||||
String sjkzmxbcs = rs7.getString("sjkzmxbcs");//数据库中明细表参数
|
||||
String sjkzmxbcslx = rs7.getString("sjkzmxbcslx");//数据库中明细表参数类型
|
||||
detailsMap.put(jkhqmxbzcs,String.valueOf(detailsMap.get(jkhqmxbzcs)));
|
||||
|
||||
if (Integer.valueOf(sjkzmxbcslx)==0){
|
||||
updateDetailMap.put(sjkzmxbcs,detailsMap.get(jkhqmxbzcs));
|
||||
}else if (Integer.valueOf(sjkzmxbcslx)==1){
|
||||
if(Integer.valueOf(jkhqmxbzcslx)==2){
|
||||
updateDetailIntMap.put(sjkzmxbcs,Double.valueOf(detailsMap.get(jkhqmxbzcs)).intValue());
|
||||
}else if (Integer.valueOf(jkhqmxbzcslx)==1){
|
||||
updateDetailIntMap.put(sjkzmxbcs,Integer.parseInt(detailsMap.get(jkhqmxbzcs)));
|
||||
}
|
||||
}else if (Integer.valueOf(sjkzmxbcslx)==2){
|
||||
updateDetailDoubleMap.put(sjkzmxbcs,Double.valueOf(detailsMap.get(jkhqmxbzcs)));
|
||||
}
|
||||
}
|
||||
updateDetailIntMap.put("mainid",Integer.parseInt(detailID));//将明细表需要的id给他
|
||||
for (Map.Entry<String, String> entry : updateDetailMap.entrySet()) {
|
||||
String k = entry.getKey();
|
||||
String v = entry.getValue();
|
||||
insertDetailSetKey1 += k + ",";
|
||||
insertDetailSetKey2 += "'"+v+"'"+",";
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : updateDetailIntMap.entrySet()) {
|
||||
String k = entry.getKey();
|
||||
Integer v = entry.getValue();
|
||||
insertDetailSetKey1 += k + ",";
|
||||
insertDetailSetKey2 += v + ",";
|
||||
}
|
||||
for (Map.Entry<String, Double> entry : updateDetailDoubleMap.entrySet()) {
|
||||
String k = entry.getKey();
|
||||
Double v = entry.getValue();
|
||||
insertDetailSetKey1 += k + ",";
|
||||
insertDetailSetKey2 += v + ",";
|
||||
}
|
||||
|
||||
insertDetailSetKey1 = insertDetailSetKey1.substring(0,insertDetailSetKey1.length()-1)+")";
|
||||
insertDetailSetKey2 = insertDetailSetKey2.substring(0,insertDetailSetKey2.length()-1)+")";
|
||||
String insertIntoDetailSql = "insert into fnainvoiceledgerdetail "+insertDetailSetKey1 + "values "+insertDetailSetKey2 ;
|
||||
RecordSet rs8 = new RecordSet();
|
||||
rs8.executeUpdate(insertIntoDetailSql);
|
||||
}
|
||||
}
|
||||
//将当前时间设置到配置表中,作为下一次的开始时间
|
||||
Util.insertOrUpdateConfigValue("getDataTime",endDay,"更新同步时间");
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("异常类型说明====="+e);
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
logger.info("异常类型说明====="+e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 将时间戳转换为时间
|
||||
*/
|
||||
public static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long lt = new Long(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,247 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.sendinvoicevaluestoaccounttable.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class InvoiceValuesToAccountTableAction03 extends BaseCronJob {
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
private String uniqueFieldId;
|
||||
|
||||
private String url;//请求的接口的url
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
String sql1 = "select taxNo,belongTo from uf_TaxNo_Config";
|
||||
RecordSet rs1 = new RecordSet();
|
||||
rs1.executeQuery(sql1);
|
||||
|
||||
//获取上一次操作的日期
|
||||
String startDay = Util.getCusConfigValue("getDataTime");
|
||||
|
||||
//获取当前的日期
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String endDay = dateFormat.format(date);
|
||||
|
||||
while(rs1.next()){
|
||||
|
||||
String taxNo = rs1.getString("taxNo");
|
||||
String belongTo = rs1.getString("belongTo");
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)");
|
||||
headers.put("Content-Type", "application/json");
|
||||
|
||||
|
||||
//设置请求体
|
||||
Map<String,Object> body = new HashMap<>();
|
||||
body.put("identity",taxNo);
|
||||
body.put("startDay",startDay);
|
||||
body.put("endDay",endDay);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
|
||||
ResponeVo responeVo = httpUtils.apiPost(url, body, headers);
|
||||
int code = responeVo.getCode();
|
||||
if (code != 200){
|
||||
logger.info("对方接口状态码为:"+code+" 程序执行错误");
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
List<Object> datas = (List<Object>)entityMap.get("data");
|
||||
if (datas==null ||datas.isEmpty()){
|
||||
logger.info("接口返回主表参数为空,请查询税号是否准确");
|
||||
continue;
|
||||
}
|
||||
Map<String,Object> totalDataMap = new HashMap<String,Object>();
|
||||
String invoice_detail_Mainid = "";//用来判断台账表中是否含有相同记录
|
||||
for (Object data : datas){
|
||||
totalDataMap = (Map<String,Object>)data;//主表数据
|
||||
logger.info("主表数据==="+totalDataMap);
|
||||
//第五步:查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
Object invoiceCode = totalDataMap.get("invoiceCode");//发票代码
|
||||
Object invoiceNum = totalDataMap.get("invoiceNum");//发票号码
|
||||
|
||||
//查询发票类型对应配置表:将想要转换的发票类型提前转换
|
||||
String queryInvoiceType = "select oaTypeValue from uf_InvoiceType_Mapping where interfaceTypeValue = ?";//改一下
|
||||
RecordSet rs2 = new RecordSet();
|
||||
rs2.executeQuery(queryInvoiceType,totalDataMap.get("invoiceType"));
|
||||
if (rs2.next()){
|
||||
String oaTypeValue = rs2.getString("oaTypeValue");
|
||||
totalDataMap.put("invoiceType",oaTypeValue);//转换发票类型
|
||||
logger.info("转换发票类型==="+oaTypeValue);
|
||||
}else {
|
||||
break;
|
||||
// totalDataMap.put("invoiceType","-1");//如果接口中的发票类型
|
||||
}
|
||||
|
||||
//将时间戳转换成yyyy-MM-dd
|
||||
String invoiceDate = (String)totalDataMap.get("invoiceDate");
|
||||
String new_invoiceDate = this.stampToDate(invoiceDate);
|
||||
totalDataMap.put("invoiceDate",new_invoiceDate);
|
||||
logger.info("转换后的时间戳====="+new_invoiceDate);
|
||||
|
||||
//查询台账表中是否包含这个数据
|
||||
String sql2 = "select id from fnaInvoiceLedger where invoicecode = ? and invoicenumber = ?";
|
||||
|
||||
rs2.executeQuery(sql2,invoiceCode,invoiceNum);
|
||||
if (rs2.next()) {
|
||||
invoice_detail_Mainid = rs2.getString("id");
|
||||
}
|
||||
|
||||
String mainId = "";
|
||||
String detailID = "";
|
||||
String updateSetkey = "";//当台账表中存在一条一样的数据的时候,我们需要设置更新条件
|
||||
List<Object> updateSetVaule = new ArrayList<>();//用来处理update条件下,?的赋值
|
||||
String insertSetKey = "(";//向台账中插入的key
|
||||
String insertSetValue = "(";//向台账中插入的value
|
||||
//第四步:通过配置的配置表获得到客户传的参数和台账字段的对应关系
|
||||
String sql3 = "select * from uf_fptzdypzbd where wybs = ?";//查询台账配置表
|
||||
if (rs2.executeQuery(sql3,uniqueFieldId)&&rs2.next()) {
|
||||
mainId = rs2.getString("id");//查询发票台账对应配置表的id对应查询明细表的mainid
|
||||
String sqlDetail1 = "select * from uf_fptzdypzbd_dt1 where mainid = ?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlDetail1,mainId);
|
||||
while(rs3.next()){
|
||||
String jkhqcs = rs3.getString("jkhqcs");//接口获取主表参数
|
||||
String jkhqzbcslx = rs3.getString("jkhqzbcslx");//接口获取主表参数类型
|
||||
String sjkzcs = rs3.getString("sjkzcs");//数据库中主表参数
|
||||
String sjkzzbcslx = rs3.getString("sjkzzbcslx");//数据库中主表参数类型
|
||||
updateSetkey += sjkzcs + "=" + "?,";
|
||||
insertSetKey += sjkzcs + ",";
|
||||
insertSetValue += "?"+",";
|
||||
updateSetVaule.add(totalDataMap.get(jkhqcs));
|
||||
}
|
||||
//拼接 发票归属人
|
||||
updateSetkey = updateSetkey + "userid_new=?";
|
||||
updateSetVaule.add(Integer.parseInt(belongTo));
|
||||
insertSetKey = insertSetKey+"userid_new)";
|
||||
insertSetValue = insertSetValue+"?)";
|
||||
|
||||
logger.info("updateSetKey====="+updateSetkey);
|
||||
logger.info("updateSetVaule====="+updateSetVaule);
|
||||
logger.info("insertSetKey====="+insertSetKey);
|
||||
logger.info("insertSetValue====="+insertSetValue);
|
||||
}
|
||||
//查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
if (!"".equals(invoice_detail_Mainid)){//执行更新语句
|
||||
updateSetVaule.add(invoiceCode);
|
||||
updateSetVaule.add(invoiceNum);
|
||||
String sqlUpdate = "update fnaInvoiceLedger set "+updateSetkey +" where invoicecode = ? and invoicenumber = ? ";
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
logger.info("sqlUpdate更新的update语句====="+sqlUpdate);
|
||||
boolean b = rs2.executeUpdate(sqlUpdate, objects);
|
||||
logger.info("主表的更新语句是否更新=="+b);
|
||||
}else{
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
String sqlInsert = "insert into fnaInvoiceLedger "+insertSetKey+" values "+insertSetValue;
|
||||
logger.info("sqlInsert插入的insert语句======"+sqlInsert);
|
||||
boolean b = rs2.executeUpdate(sqlInsert, objects);
|
||||
logger.info("主表的插入语句是否插入=="+b);
|
||||
}
|
||||
//查询到刚插入的数据的id作为明细表的mainid
|
||||
String sqlSelectId = "select id from fnaInvoiceLedger where invoicecode=? and invoicenumber=?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlSelectId,invoiceCode,invoiceNum);
|
||||
if (rs3.next()){
|
||||
detailID= rs3.getString("id");
|
||||
logger.info("detailID==="+detailID);
|
||||
}
|
||||
//向台账明细表中插入数据操作
|
||||
List<Object> details = (List<Object>)totalDataMap.get("detail");//明细表数据
|
||||
logger.info("明细表数据"+details);
|
||||
String invoiceDetailSql = "delete from fnainvoiceledgerdetail where mainid = ?";//不管明细表中有没有内容一律删掉
|
||||
logger.info("不管明细表中有没有内容一律删掉sql语句==="+invoiceDetailSql);
|
||||
boolean b1 = rs3.executeUpdate(invoiceDetailSql, detailID);
|
||||
logger.info("删除操作是否成功b1===="+b1);
|
||||
Map<String,Object> detailsMap = new HashMap<>();
|
||||
if (details ==null || details.isEmpty()){
|
||||
logger.info("明细表内容为空!跳出明细表出入循环");
|
||||
continue;
|
||||
}
|
||||
//开始查询配置表获得到客户传的明细表中参数和台账明细表中字段的对应关系
|
||||
for (Object detail : details) {
|
||||
detailsMap = (Map<String,Object>)detail;
|
||||
String sqlDetail2 = "select * from uf_fptzdypzbd_dt2 where mainid = ?";
|
||||
rs3.executeQuery(sqlDetail2,mainId);
|
||||
String insertDetailSetKey = "(";//insert条件的拼接字符串1
|
||||
String insertDetailSetValue = "(";//insert条件的拼接字符串2
|
||||
List<Object> listDetail = new ArrayList<>();//用来将?赋值
|
||||
while (rs3.next()){
|
||||
String jkhqmxbzcs = rs3.getString("jkhqmxbzcs");//接口获取明细表中参数
|
||||
String jkhqmxbzcslx = rs3.getString("jkhqmxbzcslx");//接口获取明细表中参数类型
|
||||
String sjkzmxbcs = rs3.getString("sjkzmxbcs");//数据库中明细表参数
|
||||
String sjkzmxbcslx = rs3.getString("sjkzmxbcslx");//数据库中明细表参数类型
|
||||
insertDetailSetKey += sjkzmxbcs + ",";
|
||||
insertDetailSetValue += "?,";
|
||||
listDetail.add(detailsMap.get(jkhqmxbzcs));
|
||||
|
||||
}
|
||||
insertDetailSetKey = insertDetailSetKey + "mainid)";
|
||||
insertDetailSetValue = insertDetailSetValue+"?)";
|
||||
listDetail.add(detailID);
|
||||
logger.info("明细表中用来插入的setkey---insertDetailSetKey==="+insertDetailSetKey);
|
||||
logger.info("明细表中用来插入的setvalue---insertDetailSetValue==="+insertDetailSetValue);
|
||||
logger.info("用来拼接?的listDetail"+listDetail);
|
||||
|
||||
String insertIntoDetailSql = "insert into fnainvoiceledgerdetail "+insertDetailSetKey+ "values "+insertDetailSetValue ;
|
||||
logger.info("insertIntoDetailSql明细表的插入语句==="+insertIntoDetailSql);
|
||||
boolean b = rs3.executeUpdate(insertIntoDetailSql, listDetail);
|
||||
logger.info("明细表数据插入是否成功===="+b);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将当前时间设置到配置表中,作为下一次的开始时间
|
||||
logger.info("最后更新到配置表中的时间endDay==="+endDay);
|
||||
Util.insertOrUpdateConfigValue("getDataTime",endDay,"更新同步时间");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 将时间戳转换为时间
|
||||
*/
|
||||
public static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long lt = new Long(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,264 @@
|
|||
package weaver.chaoyang.he.hcy_yihong.sendinvoicevaluestoaccounttable.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.httpUtil.ResponeVo;
|
||||
import aiyh.utils.httpUtil.util.HttpUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class InvoiceValuesToAccountTableAction04 extends BaseCronJob {
|
||||
|
||||
|
||||
private Logger logger = Util.getLogger();
|
||||
|
||||
private String uniqueFieldId;
|
||||
|
||||
private String url;//请求的接口的url
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
String sql1 = "select taxNo,belongTo from uf_TaxNo_Config";
|
||||
RecordSet rs1 = new RecordSet();
|
||||
rs1.executeQuery(sql1);
|
||||
|
||||
//获取上一次操作的日期
|
||||
String startDay = Util.getCusConfigValue("getDataTime");
|
||||
|
||||
//获取当前的日期
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String endDay = dateFormat.format(date);
|
||||
|
||||
while(rs1.next()){
|
||||
|
||||
String taxNo = rs1.getString("taxNo");
|
||||
String belongTo = rs1.getString("belongTo");
|
||||
|
||||
//请求头
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", "Apifox/1.0.0 (https://www.apifox.cn)");
|
||||
headers.put("Content-Type", "application/json");
|
||||
|
||||
|
||||
//设置请求体
|
||||
Map<String,Object> body = new HashMap<>();
|
||||
body.put("identity",taxNo);
|
||||
body.put("startDay",startDay);
|
||||
body.put("endDay",endDay);
|
||||
HttpUtils httpUtils = new HttpUtils();
|
||||
|
||||
ResponeVo responeVo = httpUtils.apiPost(url, body, headers);
|
||||
int code = responeVo.getCode();
|
||||
if (code != 200){
|
||||
logger.info("对方接口状态码为:"+code+" 程序执行错误");
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> entityMap = responeVo.getEntityMap();
|
||||
List<Object> datas = (List<Object>)entityMap.get("data");
|
||||
if (datas==null ||datas.isEmpty()){
|
||||
logger.info("接口返回主表参数为空,请查询税号是否准确");
|
||||
continue;
|
||||
}
|
||||
Map<String,Object> totalDataMap = new HashMap<String,Object>();
|
||||
String invoice_detail_Mainid = "";//用来判断台账表中是否含有相同记录
|
||||
for (Object data : datas){
|
||||
totalDataMap = (Map<String,Object>)data;//主表数据
|
||||
logger.info("主表数据==="+totalDataMap);
|
||||
//第五步:查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
Object invoiceCode = totalDataMap.get("invoiceCode");//发票代码
|
||||
Object invoiceNum = totalDataMap.get("invoiceNum");//发票号码
|
||||
|
||||
//查询发票类型对应配置表:将想要转换的发票类型提前转换
|
||||
String queryInvoiceType = "select oaTypeValue from uf_InvoiceType_Mapping where interfaceTypeValue = ?";//改一下
|
||||
RecordSet rs2 = new RecordSet();
|
||||
rs2.executeQuery(queryInvoiceType,totalDataMap.get("invoiceType"));
|
||||
if (rs2.next()){
|
||||
String oaTypeValue = rs2.getString("oaTypeValue");
|
||||
totalDataMap.put("invoiceType",oaTypeValue);//转换发票类型
|
||||
logger.info("转换发票类型==="+oaTypeValue);
|
||||
}else {
|
||||
continue;
|
||||
// totalDataMap.put("invoiceType","-1");//如果接口中的发票类型
|
||||
}
|
||||
|
||||
//将时间戳转换成yyyy-MM-dd
|
||||
String invoiceDate = (String)totalDataMap.get("invoiceDate");
|
||||
String new_invoiceDate = this.stampToDate(invoiceDate);
|
||||
totalDataMap.put("invoiceDate",new_invoiceDate);
|
||||
logger.info("转换后的时间戳====="+new_invoiceDate);
|
||||
|
||||
//查询台账表中是否包含这个数据
|
||||
String sql2 = "select id from fnaInvoiceLedger where invoicecode = ? and invoicenumber = ?";
|
||||
|
||||
rs2.executeQuery(sql2,invoiceCode,invoiceNum);
|
||||
if (rs2.next()) {
|
||||
invoice_detail_Mainid = rs2.getString("id");
|
||||
}
|
||||
|
||||
String mainId = "";
|
||||
String detailID = "";
|
||||
String updateSetkey = "";//当台账表中存在一条一样的数据的时候,我们需要设置更新条件
|
||||
List<Object> updateSetVaule = new ArrayList<>();//用来处理update条件下,?的赋值
|
||||
String insertSetKey = "(";//向台账中插入的key
|
||||
String insertSetValue = "(";//向台账中插入的value
|
||||
//第四步:通过配置的配置表获得到客户传的参数和台账字段的对应关系
|
||||
String sql3 = "select * from uf_fptzdypzbd where wybs = ?";//查询台账配置表
|
||||
if (rs2.executeQuery(sql3,uniqueFieldId)&&rs2.next()) {
|
||||
mainId = rs2.getString("id");//查询发票台账对应配置表的id对应查询明细表的mainid
|
||||
String sqlDetail1 = "select * from uf_fptzdypzbd_dt1 where mainid = ?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlDetail1,mainId);
|
||||
|
||||
|
||||
String defaultValue = "";
|
||||
while(rs3.next()){
|
||||
String jkhqcs = rs3.getString("jkhqcs");//接口获取主表参数
|
||||
String sjkzcs = rs3.getString("sjkzcs");//数据库中主表参数
|
||||
String zhlx = rs3.getString("zhlx");//转换类型
|
||||
String zdyz = rs3.getString("zdyz");//自定义值
|
||||
if (zhlx!=""&&zhlx.equals("0")){
|
||||
updateSetkey += sjkzcs + "=" + "?,";
|
||||
insertSetKey += sjkzcs + ",";
|
||||
insertSetValue += "?"+",";
|
||||
updateSetVaule.add(totalDataMap.get(jkhqcs));
|
||||
}else if (zhlx!=""&&zhlx.equals("1")){
|
||||
defaultValue = zdyz;
|
||||
}
|
||||
|
||||
}
|
||||
//拼接 发票归属人
|
||||
updateSetkey = updateSetkey + "userid_new=?,";
|
||||
updateSetVaule.add(Integer.parseInt(belongTo));
|
||||
insertSetKey = insertSetKey+"userid_new,";
|
||||
insertSetValue = insertSetValue+"?,";
|
||||
|
||||
|
||||
//拼接固定值中的类型
|
||||
updateSetkey = updateSetkey + "hxjksflr=?";
|
||||
updateSetVaule.add(defaultValue);
|
||||
insertSetKey = insertSetKey+"hxjksflr)";
|
||||
insertSetValue = insertSetValue+"?)";
|
||||
|
||||
|
||||
|
||||
logger.info("updateSetKey====="+updateSetkey);
|
||||
logger.info("updateSetVaule====="+updateSetVaule);
|
||||
logger.info("insertSetKey====="+insertSetKey);
|
||||
logger.info("insertSetValue====="+insertSetValue);
|
||||
}
|
||||
//查询每一个参数在台账主表中是否包含记录,如果包含执行update操作,如果不包含,执行insert操作。
|
||||
if (!"".equals(invoice_detail_Mainid)){//执行更新语句
|
||||
updateSetVaule.add(invoiceCode);
|
||||
updateSetVaule.add(invoiceNum);
|
||||
String sqlUpdate = "update fnaInvoiceLedger set "+updateSetkey +" where invoicecode = ? and invoicenumber = ? ";
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
logger.info("sqlUpdate更新的update语句====="+sqlUpdate);
|
||||
boolean b = rs2.executeUpdate(sqlUpdate, objects);
|
||||
logger.info("主表的更新语句是否更新=="+b);
|
||||
}else{
|
||||
Object[] objects = updateSetVaule.toArray();
|
||||
String sqlInsert = "insert into fnaInvoiceLedger "+insertSetKey+" values "+insertSetValue;
|
||||
logger.info("sqlInsert插入的insert语句======"+sqlInsert);
|
||||
boolean b = rs2.executeUpdate(sqlInsert, objects);
|
||||
logger.info("主表的插入语句是否插入=="+b);
|
||||
}
|
||||
//查询到刚插入的数据的id作为明细表的mainid
|
||||
String sqlSelectId = "select id from fnaInvoiceLedger where invoicecode=? and invoicenumber=?";
|
||||
RecordSet rs3 = new RecordSet();
|
||||
rs3.executeQuery(sqlSelectId,invoiceCode,invoiceNum);
|
||||
if (rs3.next()){
|
||||
detailID= rs3.getString("id");
|
||||
logger.info("detailID==="+detailID);
|
||||
}
|
||||
//向台账明细表中插入数据操作
|
||||
List<Object> details = (List<Object>)totalDataMap.get("detail");//明细表数据
|
||||
logger.info("明细表数据"+details);
|
||||
String invoiceDetailSql = "delete from fnainvoiceledgerdetail where mainid = ?";//不管明细表中有没有内容一律删掉
|
||||
logger.info("不管明细表中有没有内容一律删掉sql语句==="+invoiceDetailSql);
|
||||
boolean b1 = rs3.executeUpdate(invoiceDetailSql, detailID);
|
||||
logger.info("删除操作是否成功b1===="+b1);
|
||||
Map<String,Object> detailsMap = new HashMap<>();
|
||||
if (details ==null || details.isEmpty()){
|
||||
logger.info("明细表内容为空!跳出明细表出入循环");
|
||||
continue;
|
||||
}
|
||||
//开始查询配置表获得到客户传的明细表中参数和台账明细表中字段的对应关系
|
||||
for (Object detail : details) {
|
||||
detailsMap = (Map<String,Object>)detail;
|
||||
String sqlDetail2 = "select * from uf_fptzdypzbd_dt2 where mainid = ?";
|
||||
rs3.executeQuery(sqlDetail2,mainId);
|
||||
String insertDetailSetKey = "(";//insert条件的拼接字符串1
|
||||
String insertDetailSetValue = "(";//insert条件的拼接字符串2
|
||||
List<Object> listDetail = new ArrayList<>();//用来将?赋值
|
||||
while (rs3.next()){
|
||||
String jkhqmxbzcs = rs3.getString("jkhqmxbzcs");//接口获取明细表中参数
|
||||
String jkhqmxbzcslx = rs3.getString("jkhqmxbzcslx");//接口获取明细表中参数类型
|
||||
String sjkzmxbcs = rs3.getString("sjkzmxbcs");//数据库中明细表参数
|
||||
String sjkzmxbcslx = rs3.getString("sjkzmxbcslx");//数据库中明细表参数类型
|
||||
insertDetailSetKey += sjkzmxbcs + ",";
|
||||
insertDetailSetValue += "?,";
|
||||
listDetail.add(detailsMap.get(jkhqmxbzcs));
|
||||
|
||||
}
|
||||
insertDetailSetKey = insertDetailSetKey + "mainid)";
|
||||
insertDetailSetValue = insertDetailSetValue+"?)";
|
||||
listDetail.add(detailID);
|
||||
logger.info("明细表中用来插入的setkey---insertDetailSetKey==="+insertDetailSetKey);
|
||||
logger.info("明细表中用来插入的setvalue---insertDetailSetValue==="+insertDetailSetValue);
|
||||
logger.info("用来拼接?的listDetail"+listDetail);
|
||||
|
||||
String insertIntoDetailSql = "insert into fnainvoiceledgerdetail "+insertDetailSetKey+ "values "+insertDetailSetValue ;
|
||||
logger.info("insertIntoDetailSql明细表的插入语句==="+insertIntoDetailSql);
|
||||
boolean b = rs3.executeUpdate(insertIntoDetailSql, listDetail);
|
||||
logger.info("明细表数据插入是否成功===="+b);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将当前时间设置到配置表中,作为下一次的开始时间
|
||||
logger.info("最后更新到配置表中的时间endDay==="+endDay);
|
||||
Util.insertOrUpdateConfigValue("getDataTime",endDay,"更新同步时间");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 将时间戳转换为时间
|
||||
*/
|
||||
public static String stampToDate(String s){
|
||||
String res;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long lt = new Long(s);
|
||||
Date date = new Date(lt);
|
||||
res = simpleDateFormat.format(date);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public String getUniqueFieldId() {
|
||||
return uniqueFieldId;
|
||||
}
|
||||
|
||||
public void setUniqueFieldId(String uniqueFieldId) {
|
||||
this.uniqueFieldId = uniqueFieldId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
package weaver.chaoyang.he.jiacheng.deng.toyota.boshoku.action;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
/**
|
||||
* <h1>附件上传后修改名称保存到目录</h1>
|
||||
* @Author jiacheng.deng
|
||||
* @Date 2023/2/13 10:41
|
||||
*/
|
||||
public class TbChangeTextNameAction implements Action {
|
||||
|
||||
//日志打印
|
||||
private final Logger log = Util.getLogger();
|
||||
|
||||
/**
|
||||
* <h2>附件上传后修改名称</h2>
|
||||
* @param requestInfo
|
||||
* @return Action.SUCCESS
|
||||
* @author jiacheng.deng
|
||||
*/
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
|
||||
Property[] property = requestInfo.getMainTableInfo().getProperty();
|
||||
|
||||
List<Map<String,String>> detailData = new ArrayList<>();
|
||||
|
||||
Map<String,String> mainMap = new HashMap<>();
|
||||
for (Property property1 : property) {
|
||||
String name = property1.getName();
|
||||
String value = property1.getValue();
|
||||
|
||||
mainMap.put(name,value);
|
||||
}
|
||||
|
||||
log.info("main table name and value is : " + mainMap);
|
||||
|
||||
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(0);
|
||||
|
||||
Row[] row2 = detailTable.getRow();
|
||||
|
||||
for (Row row : row2) {
|
||||
Cell[] cell = row.getCell();
|
||||
Map<String, String> detailMap = new HashMap<>();
|
||||
for (Cell cell1 : cell) {
|
||||
String name = cell1.getName();
|
||||
String value = cell1.getValue();
|
||||
detailMap.put(name,value);
|
||||
}
|
||||
detailData.add(detailMap);
|
||||
}
|
||||
|
||||
for (Map<String, String> detailDatum : detailData) {
|
||||
log.info("detail table name and value is : " + detailDatum );
|
||||
}
|
||||
|
||||
String workflowid = requestInfo.getWorkflowid();
|
||||
RecordSet refindFieldType = new RecordSet();
|
||||
String findFieldhtmltypeSQL = "select w3.billid,w3.showtablename,w3.fieldhtmltype,w3.fieldname from workflow_base w1 join workflow_bill w2 on w1.formid = w2.id \n " +
|
||||
" join workflow_field_table_view w3 on w3.billid = w2.id\n " +
|
||||
" where w1.id = ? and w3.fieldhtmltype='附件上传'";
|
||||
boolean findFieldhtmltype = refindFieldType.executeQuery(findFieldhtmltypeSQL, workflowid);
|
||||
log.info("查询表单字段类型sql是否执行:" + findFieldhtmltype);
|
||||
|
||||
String findMainParamValueSQL = "select paramvalue from uf_systemconfig where uuid = 'main_upload'";
|
||||
String findDetailParamValueSQL = "select paramvalue from uf_systemconfig where uuid = 'detail_upload'";
|
||||
|
||||
RecordSet refindMainParam = new RecordSet();
|
||||
boolean findMainParamValue = refindMainParam.executeQuery(findMainParamValueSQL);
|
||||
refindMainParam.next();
|
||||
String mainParamvalue = refindMainParam.getString("paramvalue");
|
||||
log.info("查询配置列表配置主表参数sql是否执行:" + findMainParamValue + "and 主表配置的附件参数为:" + mainParamvalue);
|
||||
|
||||
RecordSet refindDetailParam = new RecordSet();
|
||||
boolean findDetailParamValue = refindDetailParam.executeQuery(findDetailParamValueSQL);
|
||||
refindDetailParam.next();
|
||||
String detailParamvalue = refindDetailParam.getString("paramvalue");
|
||||
log.info("查询配置列表配置明细表参数sql是否执行:" + findDetailParamValue + "and 明细表配置的附件参数为:" + detailParamvalue);
|
||||
|
||||
List<String> showtablenameList = new ArrayList();
|
||||
List<String> fieldnameList = new ArrayList();
|
||||
String fieldname ;
|
||||
String showtablename;
|
||||
|
||||
while (refindFieldType.next()){
|
||||
showtablename = refindFieldType.getString("showtablename");
|
||||
fieldname = refindFieldType.getString("fieldname");
|
||||
showtablenameList.add(showtablename);
|
||||
fieldnameList.add(fieldname);
|
||||
}
|
||||
|
||||
List<String> collect = showtablenameList.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
if(collect.size() >= 2){
|
||||
log.info("明细表和主表都有附件上传框");
|
||||
|
||||
List<Integer> list = new ArrayList<>();
|
||||
if (!mainMap.get(mainParamvalue).equals("")) {
|
||||
String[] mainUploadSplitArr = mainMap.get(mainParamvalue).split(",");
|
||||
for (String mainUploadSplitNum : mainUploadSplitArr) {
|
||||
int i = Integer.parseInt(mainUploadSplitNum);
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
for ( Map<String, String> detailDatum : detailData) {
|
||||
if(! detailDatum.get(detailParamvalue).equals("")){
|
||||
String[] detailUploadSplitArr = detailDatum.get(detailParamvalue).split(",");
|
||||
for (String detailUploadSplitNum : detailUploadSplitArr) {
|
||||
int i = Integer.parseInt(detailUploadSplitNum);
|
||||
list.add(i);
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (Integer uploadNum : list) {
|
||||
String findFjSQL = "select * from docdetail where id = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean findFj= recordSet.executeQuery(findFjSQL, uploadNum);
|
||||
log.info("b1是否执行:" + findFj);
|
||||
while (recordSet.next()) {
|
||||
String docsubject = recordSet.getString("docsubject");
|
||||
log.info("find docsubject is : " + docsubject);
|
||||
if (!"".equals(docsubject)) {
|
||||
String fjName = mainMap.get("sqdh") + " - " + docsubject;
|
||||
log.info("附件修改后的名称:" + fjName);
|
||||
String updateFjNameSQL = "update docdetail set docsubject = ? where id = " + uploadNum;
|
||||
log.info("修改文件名称sql:" + updateFjNameSQL);
|
||||
//recordset使用重复
|
||||
boolean updateFjName = recordSet.executeUpdate(updateFjNameSQL,fjName);
|
||||
log.info("b2是否执行:" + updateFjName);
|
||||
// todo:处理逻辑
|
||||
String selectImageFileNameSql = "select imagefilename from docimagefile where docid = ?";
|
||||
while (recordSet.executeQuery(selectImageFileNameSql,uploadNum)&&recordSet.next()){
|
||||
String imageFileName = recordSet.getString("imagefilename");
|
||||
log.info("find imagefilename is : "+imageFileName);
|
||||
if (!"".equals(imageFileName)) {
|
||||
String fjName1 = mainMap.get("sqdh") + " - "+imageFileName;
|
||||
log.info("修改文件名称sql:"+fjName1);
|
||||
String updateImageFileNameSql = "update docimagefile set imagefilename = ? where id = ?";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (Map<String, String> detailDatum : detailData) {
|
||||
if(! detailDatum.get(detailParamvalue).equals("")){
|
||||
String[] detailUploadSplitArr = detailDatum.get(detailParamvalue).split(",");
|
||||
for (String detailUploadSplitNum : detailUploadSplitArr) {
|
||||
int i = Integer.parseInt(detailUploadSplitNum);
|
||||
list.add(i);
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (Integer uploadNum : list) {
|
||||
String findFjSQL = "select * from docdetail where id = ?";
|
||||
RecordSet recordSet = new RecordSet();
|
||||
boolean findFj= recordSet.executeQuery(findFjSQL, uploadNum);
|
||||
log.info("b1是否执行:" + findFj);
|
||||
while (recordSet.next()) {
|
||||
String docsubject = recordSet.getString("docsubject");
|
||||
log.info("find docsubject is : " + docsubject);
|
||||
if (!"".equals(docsubject)) {
|
||||
String fjName = mainMap.get("sqdh") + " - " + docsubject;
|
||||
log.info("附件修改后的名称:" + fjName);
|
||||
String updateFjNameSQL = "update docdetail set docsubject = ? where id = " + uploadNum;
|
||||
log.info("修改文件名称sql:" + updateFjNameSQL);
|
||||
//recordset使用重复
|
||||
boolean updateFjName = recordSet.executeUpdate(updateFjNameSQL,fjName);
|
||||
log.info("b2是否执行:" + updateFjName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
log.info("主表或者明细表只有一个有附件上传框,或者都没上传框");
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取所有明细数据</h2>
|
||||
*
|
||||
* @return 以明细表需要为键,以明细表数据为值的键值对明细数据信息
|
||||
*/
|
||||
protected Map<String, List<Map<String, String>>> getDetailTableValue(RequestInfo requestInfo) {
|
||||
DetailTable[] detailTableArr = requestInfo.getDetailTableInfo().getDetailTable();
|
||||
Map<String, List<Map<String, String>>> detailDataList = new HashMap<>((int) Math.ceil(detailTableArr.length * 0.75));
|
||||
for (DetailTable detailTable : detailTableArr) {
|
||||
List<Map<String, String>> detailData = getDetailValue(detailTable);
|
||||
detailDataList.put(detailTable.getId(), detailData);
|
||||
}
|
||||
return detailDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>根据明细表信息获取明细表数据</h2>
|
||||
*
|
||||
* @param detailTable 明细表对象
|
||||
* @return 明细表数据
|
||||
*/
|
||||
@NotNull
|
||||
private List<Map<String, String>> getDetailValue(DetailTable detailTable) {
|
||||
Row[] rowArr = detailTable.getRow();
|
||||
List<Map<String, String>> detailData = new ArrayList<>(rowArr.length);
|
||||
for (Row row : rowArr) {
|
||||
Cell[] cellArr = row.getCell();
|
||||
Map<String, String> rowData = new HashMap<>((int) Math.ceil(cellArr.length * 0.75));
|
||||
for (Cell cell : cellArr) {
|
||||
String fieldName = cell.getName();
|
||||
String value = cell.getValue();
|
||||
rowData.put(fieldName, value);
|
||||
}
|
||||
detailData.add(rowData);
|
||||
}
|
||||
return detailData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,273 @@
|
|||
package weaver.chaoyang.he.shangan.common.util;
|
||||
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.TimeUtil;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.workflow.webservices.*;
|
||||
import weaver.workflow.workflow.WorkflowComInfo;
|
||||
import weaver.zwl.common.ToolUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 常用通用工具方法
|
||||
* EBU七部
|
||||
*/
|
||||
public class CommonWFUtil {
|
||||
|
||||
private static final ToolUtil tu = new ToolUtil();
|
||||
/**
|
||||
*
|
||||
* 发起流程
|
||||
* @param workflowId 流程id
|
||||
* @param mainFormData 主表数据 key:数据库字段名称 value:值
|
||||
* @param dtlFormData 明细数据 key:明细表num value:每一行明细数据
|
||||
* @param defaultValue 是否需要默认值和节点前附加规则的设值,例如人力资源、日期等
|
||||
* @param user 当前用户信息
|
||||
*/
|
||||
public static String startWorkflow(String workflowId, Map<String, String> mainFormData,
|
||||
Map<String, List<Map<String, String>>> dtlFormData, boolean defaultValue, User user) throws Exception{
|
||||
return startWorkflow(workflowId,mainFormData,dtlFormData,defaultValue,user,"0");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 发起流程
|
||||
* @param workflowId 流程id
|
||||
* @param mainFormData 主表数据 key:数据库字段名称 value:值
|
||||
* @param dtlFormData 明细数据 key:明细表num value:每一行明细数据
|
||||
* @param defaultValue 是否需要默认值和节点前附加规则的设值,例如人力资源、日期等
|
||||
* @param user 当前用户信息
|
||||
* @param isNextFlow 是否自动提交至下一个节点 0:否 1:是
|
||||
*/
|
||||
public static String startWorkflow(String workflowId, Map<String, String> mainFormData,
|
||||
Map<String, List<Map<String, String>>> dtlFormData, boolean defaultValue, User user,String isNextFlow) {
|
||||
int formid = 0;
|
||||
String defaultName = "";
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = " select a.formId ,a.isValId,a.defaultName,a.version,a.activeVersionID from workflow_base a where a.id=?";
|
||||
rs.executeQuery(sql, workflowId);
|
||||
if (rs.next()) {
|
||||
formid = Math.abs(rs.getInt("formId"));
|
||||
defaultName = Util.null2String(rs.getString("defaultName")).trim();
|
||||
String activeVersionID = Util.null2String(rs.getString("activeVersionID"));
|
||||
|
||||
if(!"".equals(activeVersionID)){
|
||||
workflowId = activeVersionID;
|
||||
}
|
||||
}
|
||||
|
||||
//流程默认标题没有开启
|
||||
if("1".equals(defaultName) || "".equals(defaultName)){
|
||||
//生成默认标题
|
||||
WorkflowComInfo wc = new WorkflowComInfo();
|
||||
//流程标题
|
||||
defaultName = Util.formatMultiLang(wc.getWorkflowname(workflowId)) + "-" + user.getLastname() + "-" + TimeUtil.getCurrentDateString();
|
||||
}
|
||||
|
||||
//设置流程信息
|
||||
WorkflowBaseInfo wbi = new WorkflowBaseInfo();
|
||||
wbi.setWorkflowId(workflowId);
|
||||
WorkflowServiceImpl wsi = new WorkflowServiceImpl();
|
||||
WorkflowRequestInfo wri = new WorkflowRequestInfo();//流程基本信息
|
||||
wri.setCreatorId(user.getUID()+"");//创建人id
|
||||
wri.setCreatorName(user.getLastname());
|
||||
wri.setRequestLevel("0");//0 正常,1重要,2紧急
|
||||
wri.setRequestName(defaultName);//流程标题
|
||||
wri.setWorkflowBaseInfo(wbi); //流程类型
|
||||
wri.setIsnextflow(isNextFlow);
|
||||
|
||||
//主表
|
||||
WorkflowRequestTableRecord[] writ = new WorkflowRequestTableRecord[1];
|
||||
|
||||
if(mainFormData == null){
|
||||
mainFormData = new HashMap<>();
|
||||
}
|
||||
|
||||
if(defaultValue){
|
||||
//查询主表的附加规则设置
|
||||
rs.executeQuery("select a.customervalue,b.fieldname from workflow_addinoperate a " +
|
||||
" join workflow_billfield b on a.fieldid = b.id " +
|
||||
" join workflow_flownode c on c.nodeid = a.objid " +
|
||||
" where a.workflowid = ? and a.isnode = 1 and a.ispreadd = 1 and a.type = 0 and c.nodetype = 0 and b.viewtype = 0 ", workflowId);
|
||||
while(rs.next()){
|
||||
String fieldname = Util.null2String(rs.getString("fieldname"));
|
||||
String customervalue = Util.null2String(rs.getString("customervalue"));
|
||||
if(!mainFormData.containsKey(fieldname)){
|
||||
mainFormData.put(fieldname, customervalue);
|
||||
}
|
||||
}
|
||||
|
||||
defaultValueSet(mainFormData,user,workflowId,"");
|
||||
}
|
||||
if(mainFormData.size() > 0){
|
||||
int filedCount = mainFormData.size();//需要维护的字段数量
|
||||
WorkflowRequestTableField[] workflowRequestTableField = new WorkflowRequestTableField[filedCount]; //一行的字段数组
|
||||
int i = 0;
|
||||
for(Map.Entry<String, String> entry:mainFormData.entrySet()){
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
workflowRequestTableField[i] = new WorkflowRequestTableField();
|
||||
workflowRequestTableField[i].setFieldName(key);//字段名称
|
||||
workflowRequestTableField[i].setFieldValue(value);//字段的值
|
||||
workflowRequestTableField[i].setView(true);//字段是否可见
|
||||
workflowRequestTableField[i].setEdit(true);//字段是否可编辑
|
||||
i++;
|
||||
}
|
||||
writ[0] = new WorkflowRequestTableRecord();
|
||||
writ[0].setWorkflowRequestTableFields(workflowRequestTableField);
|
||||
}else{
|
||||
WorkflowRequestTableField[] workflowRequestTableField = new WorkflowRequestTableField[0]; //一行的字段数组
|
||||
writ[0] = new WorkflowRequestTableRecord();
|
||||
writ[0].setWorkflowRequestTableFields(workflowRequestTableField);
|
||||
}
|
||||
|
||||
WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
|
||||
wmi.setRequestRecords(writ);
|
||||
wri.setWorkflowMainTableInfo(wmi);//添加主字段数据
|
||||
//主表end
|
||||
|
||||
//明细表
|
||||
//查询流程共有几个明细表
|
||||
int maxDtl = 0;
|
||||
List<String> dtlTableList = new ArrayList<>();
|
||||
rs.executeQuery("select a.tableName,a.billId from workflow_billDetailTable a join workflow_base b on b.formId = a.billId where b.id = ? \n" +
|
||||
"order by a.orderId asc", workflowId);
|
||||
while(rs.next()){
|
||||
String tableName = Util.null2String(rs.getString("tableName"));
|
||||
|
||||
int dtlId = Util.getIntValue(tableName.substring(tableName.indexOf("_dt") + 3),-1);
|
||||
|
||||
if(dtlId>maxDtl){
|
||||
maxDtl = dtlId;
|
||||
}
|
||||
dtlTableList.add(""+dtlId);
|
||||
}
|
||||
if(dtlFormData != null && dtlFormData.size() > 0){
|
||||
WorkflowDetailTableInfo[] workflowDetailTableInfos = new WorkflowDetailTableInfo[maxDtl];
|
||||
for(int i = 0;i < dtlTableList.size();i++){
|
||||
List<Map<String, String>> dtlList = dtlFormData.get(dtlTableList.get(i)); //第i个明细表中的数据
|
||||
if(dtlList == null || dtlList.size() == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
WorkflowRequestTableRecord[] WorkflowRequestTableRecord = new WorkflowRequestTableRecord[dtlList.size()];
|
||||
Map<String, String> defaultData = new HashMap<>();
|
||||
if(defaultValue){
|
||||
//明细默认信息
|
||||
rs.executeQuery("select a.customerValue,b.fieldName from workflow_addinoperate a " +
|
||||
" join workflow_billfield b on a.fieldid = b.id " +
|
||||
" join workflow_flownode c on c.nodeid = a.objid " +
|
||||
" where a.workflowid = ? and a.isnode = 1 and a.ispreadd = 1 "
|
||||
+ " and a.type = 0 and c.nodetype = 0 and b.viewtype = 1 and b.detailtable = ?", workflowId,"formtable_main_"+formid+"_dt"+i);
|
||||
while(rs.next()){
|
||||
String fieldname = Util.null2String(rs.getString("fieldName"));
|
||||
String customervalue = Util.null2String(rs.getString("customerValue"));
|
||||
if(!defaultData.containsKey(fieldname)){
|
||||
defaultData.put(fieldname, customervalue);
|
||||
}
|
||||
}
|
||||
|
||||
defaultValueSet(defaultData,user,workflowId,"formtable_main_" + formid + "_dt" + i);
|
||||
}
|
||||
int num = 0;
|
||||
for(Map<String, String> dtlMap : dtlList){ //添加一行明细表数据
|
||||
tu.writeDebuggerLog("","明细表" + i + ",第" + (num + 1) + "行待写入字段信息:[" + dtlMap.toString() + "]!");
|
||||
|
||||
WorkflowRequestTableField[] workflowRequestTableFields = new WorkflowRequestTableField[dtlMap.size()+defaultData.size()];
|
||||
int j = 0;
|
||||
for(Map.Entry<String, String> entry:dtlMap.entrySet()){
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
workflowRequestTableFields[j] = new WorkflowRequestTableField();
|
||||
workflowRequestTableFields[j].setFieldName(key);//字段名称
|
||||
workflowRequestTableFields[j].setFieldValue(value);//字段的值
|
||||
workflowRequestTableFields[j].setView(true);//字段是否可见
|
||||
workflowRequestTableFields[j].setEdit(true);//字段是否可编辑
|
||||
j++;
|
||||
}
|
||||
if(defaultValue){
|
||||
for(Map.Entry<String, String> entry:defaultData.entrySet()){
|
||||
String key = entry.getKey();
|
||||
if(dtlMap.containsKey(key)){
|
||||
continue;
|
||||
}
|
||||
String value = entry.getValue();
|
||||
workflowRequestTableFields[j] = new WorkflowRequestTableField();
|
||||
workflowRequestTableFields[j].setFieldName(key);//字段名称
|
||||
workflowRequestTableFields[j].setFieldValue(value);//字段的值
|
||||
workflowRequestTableFields[j].setView(true);//字段是否可见
|
||||
workflowRequestTableFields[j].setEdit(true);//字段是否可编辑
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
tu.writeDebuggerLog("","明细表" + i + ",第" + (num + 1) + "行总有" + j + "字段!");
|
||||
|
||||
WorkflowRequestTableRecord[num] = new WorkflowRequestTableRecord();
|
||||
WorkflowRequestTableRecord[num].setWorkflowRequestTableFields(workflowRequestTableFields);
|
||||
num++;
|
||||
}
|
||||
|
||||
tu.writeDebuggerLog("","明细表" + i + ",共有" + WorkflowRequestTableRecord.length + "行记录!");
|
||||
|
||||
workflowDetailTableInfos[i] = new WorkflowDetailTableInfo();
|
||||
workflowDetailTableInfos[i].setWorkflowRequestTableRecords(WorkflowRequestTableRecord);
|
||||
}
|
||||
|
||||
tu.writeDebuggerLog("","创建的流程共有" + workflowDetailTableInfos.length + "个明细表!");
|
||||
wri.setWorkflowDetailTableInfos(workflowDetailTableInfos);//添加明细字段信息
|
||||
}
|
||||
return wsi.doCreateWorkflowRequest(wri,user.getUID());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认值
|
||||
* @param defaultData 默认数据集合
|
||||
* @param user 当前用户信息
|
||||
* @param workflowId 流程类型ID
|
||||
* @param tableName 流程表名称
|
||||
*/
|
||||
private static void defaultValueSet(Map<String, String> defaultData,User user,String workflowId,String tableName){
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
String selectSQL = "select a.fieldName,a.type from workflow_billfield a " +
|
||||
" join workflow_base b on a.billid = b.formid " +
|
||||
" where b.id = ? and a.fieldhtmltype = 3 " +
|
||||
" and a.type in(1,2,4,19,178,164)";
|
||||
|
||||
if(!"".equals(tableName)){
|
||||
selectSQL += " and a.detailtable = '" + tableName + "' and a.viewtype = 1";
|
||||
}else{
|
||||
selectSQL += " and a.viewtype = 0";
|
||||
}
|
||||
|
||||
//查询主表的人力资源、部门、分部、日期、年度等浏览按钮填写默认值
|
||||
rs.executeQuery(selectSQL, workflowId);
|
||||
|
||||
while(rs.next()){
|
||||
String fieldName = Util.null2String(rs.getString("fieldName"));
|
||||
int type = Util.getIntValue(rs.getString("type"),0);
|
||||
if(!defaultData.containsKey(fieldName)){
|
||||
if(type == 1){//人力资源
|
||||
defaultData.put(fieldName, ""+user.getUID());
|
||||
}else if(type == 2){//日期
|
||||
defaultData.put(fieldName, TimeUtil.getCurrentDateString());
|
||||
}else if(type == 4){//部门
|
||||
defaultData.put(fieldName, ""+user.getUserDepartment());
|
||||
}else if(type == 19){//时间
|
||||
String timestrformart = "HH:mm" ;
|
||||
SimpleDateFormat SDF = new SimpleDateFormat(timestrformart) ;
|
||||
Calendar calendar = Calendar.getInstance() ;
|
||||
defaultData.put(fieldName, SDF.format(calendar.getTime()));
|
||||
}else if(type == 178){ //年
|
||||
defaultData.put(fieldName, TimeUtil.getCurrentDateString().split("-")[0]);
|
||||
}else if(type == 164){//分部
|
||||
defaultData.put(fieldName, ""+user.getUserSubCompany1());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package weaver.chaoyang.he.shangan.cornjob;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件信息 实体类
|
||||
*/
|
||||
public class MailInfoDao {
|
||||
|
||||
/**
|
||||
* 发件人
|
||||
*/
|
||||
private String from ;
|
||||
|
||||
/**
|
||||
* 发件日期
|
||||
*/
|
||||
private Date date;
|
||||
|
||||
/**
|
||||
* 邮件主题
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 邮件内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 是否包含附件
|
||||
*/
|
||||
private boolean isContainAttachment;
|
||||
|
||||
/**
|
||||
* 附件ID(上传至OA系统)
|
||||
*/
|
||||
private List<Integer> attachmentIdList;
|
||||
|
||||
/**
|
||||
* 对象toString 方法
|
||||
* @return 字符串
|
||||
*/
|
||||
public String toString(){
|
||||
return "MailInfoDao Information: {" +
|
||||
"form :" + from + ",\n" +
|
||||
"date :" + date + ",\n" +
|
||||
"subject :" + subject + ",\n" +
|
||||
"content :" + content + ",\n" +
|
||||
"isContainAttachment :" + isContainAttachment + ",\n" +
|
||||
"attachmentIdList :" + StringUtils.join(attachmentIdList, ",") + "\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public boolean isContainAttachment() {
|
||||
return isContainAttachment;
|
||||
}
|
||||
|
||||
public void setContainAttachment(boolean containAttachment) {
|
||||
isContainAttachment = containAttachment;
|
||||
}
|
||||
|
||||
public List<Integer> getAttachmentIdList() {
|
||||
return attachmentIdList;
|
||||
}
|
||||
|
||||
public void setAttachmentIdList(List<Integer> attachmentIdList) {
|
||||
this.attachmentIdList = attachmentIdList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
package weaver.chaoyang.he.shangan.cornjob;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.chaoyang.he.shangan.common.util.CommonWFUtil;
|
||||
import weaver.chaoyang.he.zwl.common.ThreadPoolConfig;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.TimeUtil;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import weaver.zwl.common.ToolUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* 上海安装工程集团
|
||||
* 邮件触发流程 计划任务
|
||||
*/
|
||||
public class MailTriggerWorkflowCronJob extends BaseCronJob {
|
||||
|
||||
private final ToolUtil tool = new ToolUtil();
|
||||
|
||||
private final ReadMail readMail = new ReadMail();
|
||||
|
||||
|
||||
/**
|
||||
* 实现父类方法
|
||||
* 具体的业务实现
|
||||
*/
|
||||
@Override
|
||||
public synchronized void execute(){
|
||||
tool.writeDebuggerLog("","-------- MailTriggerWorkflowCronJob Begin---------------");
|
||||
//拿到一个线程池
|
||||
ExecutorService threadPool = ThreadPoolConfig.createThreadPoolInstance();
|
||||
List<Map<String,Object>> configList = readMail.getConfiguration();
|
||||
|
||||
tool.writeDebuggerLog("","configList:[" + configList.size() + "]");
|
||||
|
||||
// threadPool.execute(() -> {
|
||||
for(Map<String,Object> configMap : configList){
|
||||
try {
|
||||
getMainInfoAndCreateWorkflow(configMap);
|
||||
} catch (Exception e) {
|
||||
tool.writeDebuggerLog("","创建流程信息异常,异常信息:[" + e.getMessage() + "]");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// });
|
||||
|
||||
tool.writeDebuggerLog("","-------- MailTriggerWorkflowCronJob End---------------");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮箱中的邮件信息,且根据配置创建流程
|
||||
* @param dataMap 配置信息
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void getMainInfoAndCreateWorkflow(Map<String,Object> dataMap) throws Exception {
|
||||
try {
|
||||
//邮箱地址
|
||||
String mailAddress = (String) dataMap.get("mailAddress");
|
||||
//邮箱密码
|
||||
String mailPassword = (String) dataMap.get("mailPassword");
|
||||
//白名单列表
|
||||
String whiteList = Util.null2String(dataMap.get("whiteList"));
|
||||
//获取用户ID
|
||||
int remindUser = (int) dataMap.get("remindUser");
|
||||
//文档存储目录
|
||||
int secCategory = (int) dataMap.get("secCategory");
|
||||
//触发的流程类型ID
|
||||
String workflowId = (String) dataMap.get("workflowId");
|
||||
//邮件文件夹
|
||||
String mailFolder = Util.null2String(dataMap.get("mailFolder"));
|
||||
|
||||
//用户信息
|
||||
User createUser = new User(remindUser);
|
||||
|
||||
//流程字段与邮件信息匹配集合
|
||||
List<Map<Integer,Integer>> fieldList = (List<Map<Integer, Integer>>) dataMap.get("fieldList");
|
||||
|
||||
List<Map<String,Object>> newFieldList = new ArrayList<>();
|
||||
|
||||
//先对配置字段进行转换,将字段ID转成对应的字段数据库名
|
||||
for(Map<Integer,Integer> fieldMap : fieldList){
|
||||
for(int key : fieldMap.keySet()){
|
||||
int fieldId = fieldMap.get(key);
|
||||
//根据字段ID获取其字段名称
|
||||
String fieldName = getFieldNameByFieldid(fieldId);
|
||||
|
||||
Map<String,Object> dtMap = new HashMap<>();
|
||||
dtMap.put("fieldName",fieldName);
|
||||
dtMap.put("fieldId",fieldId);
|
||||
dtMap.put("mailField",key);
|
||||
|
||||
newFieldList.add(dtMap);
|
||||
}
|
||||
}
|
||||
|
||||
//获取邮箱中的未读邮件
|
||||
List<MailInfoDao> mailInfoDaoList = readMail.getMainInfo(mailAddress,mailPassword,whiteList,secCategory,remindUser,mailFolder);
|
||||
|
||||
tool.writeDebuggerLog("","mailInfoDaoList:[" + mailInfoDaoList.size() + "]");
|
||||
if(mailInfoDaoList.size() > 0){
|
||||
for(MailInfoDao mailInfoDao : mailInfoDaoList){
|
||||
System.out.println(mailInfoDao.toString());
|
||||
|
||||
createWorkflow(workflowId,createUser,mailInfoDao,newFieldList);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
tool.writeDebuggerLog("","导出邮箱中的未读邮件报错==="+e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段ID获取其对应的字段名称
|
||||
* @param fieldId 字段ID
|
||||
* @return 字段名称
|
||||
*/
|
||||
private String getFieldNameByFieldid(int fieldId){
|
||||
if(fieldId > 0){
|
||||
String querySQL = "select fieldname from workflow_billfield where id = ?";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(rs.executeQuery(querySQL,fieldId) && rs.next()){
|
||||
return Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建流程信息
|
||||
* @param mailInfoDao 邮件信息实体类
|
||||
* @param fieldList 流程字段与邮件信息匹配映射
|
||||
*/
|
||||
private void createWorkflow(String workflowId, User createUser, MailInfoDao mailInfoDao, List<Map<String, Object>> fieldList) throws Exception {
|
||||
Map<String,String> mainTableMap = new HashMap<>();
|
||||
|
||||
for(Map<String,Object> fieldMap : fieldList){
|
||||
tool.writeDebuggerLog("","fieldMap:[" + fieldMap.toString() + "]");
|
||||
//字段数据库名
|
||||
String fieldName = Util.null2String(fieldMap.get("fieldName"));
|
||||
|
||||
if(!"".equals(fieldName)){
|
||||
|
||||
int mailField = Util.getIntValue(Util.null2String(fieldMap.get("mailField")),-1);
|
||||
|
||||
String fieldValue = "";
|
||||
|
||||
switch (mailField){
|
||||
case 0 ://发件人
|
||||
fieldValue = mailInfoDao.getFrom();
|
||||
break;
|
||||
case 1 : //发件日期
|
||||
Date date = mailInfoDao.getDate();
|
||||
fieldValue = TimeUtil.getFormartString(date,"yyyy-MM-dd");
|
||||
break;
|
||||
case 2 : //邮件主题
|
||||
fieldValue = mailInfoDao.getSubject();
|
||||
break;
|
||||
case 3 : //邮件内容
|
||||
fieldValue = mailInfoDao.getContent();
|
||||
break;
|
||||
case 4 ://是否包含附件
|
||||
fieldValue = mailInfoDao.isContainAttachment() ? "1" : "0";
|
||||
break;
|
||||
case 5 : //附件
|
||||
List<Integer> docIds = mailInfoDao.getAttachmentIdList();
|
||||
fieldValue = StringUtils.join(docIds,",");
|
||||
break;
|
||||
}
|
||||
mainTableMap.put(fieldName,fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
tool.writeDebuggerLog("","mainTableMap:[" + mainTableMap.toString() + "]");
|
||||
|
||||
if(!mainTableMap.isEmpty()){
|
||||
String requestId = CommonWFUtil.startWorkflow(workflowId,mainTableMap,null,true,createUser,"0");
|
||||
|
||||
tool.writeDebuggerLog("","创建成功的流程请求ID:[" + requestId + "]");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,520 @@
|
|||
package weaver.chaoyang.he.shangan.cornjob;
|
||||
|
||||
import com.sun.mail.imap.IMAPFolder;
|
||||
import com.sun.mail.imap.IMAPStore;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.docs.docs.DocImageManager;
|
||||
import weaver.docs.webservices.DocInfo;
|
||||
import weaver.docs.webservices.DocServiceImpl;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.general.IOUtils;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.zwl.common.ToolUtil;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 上海安装工程集团
|
||||
* 读取邮件信息工具类
|
||||
*
|
||||
*/
|
||||
public class ReadMail extends ToolUtil {
|
||||
|
||||
/**
|
||||
* 定义SSL factory
|
||||
*/
|
||||
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
||||
|
||||
/**
|
||||
* 定义邮箱host (腾讯邮箱)暂不修改
|
||||
*/
|
||||
private static final String host = "imap.exmail.qq.com";
|
||||
|
||||
/**
|
||||
* 定义邮箱端口
|
||||
*/
|
||||
private static final String port = "993";
|
||||
|
||||
/**
|
||||
* 邮箱连接Session
|
||||
*/
|
||||
private static Session session;
|
||||
|
||||
/**
|
||||
* 配置表名称
|
||||
*/
|
||||
private final static String configTableName = "uf_mail_wf_config";
|
||||
|
||||
/**
|
||||
* 获取收件箱中的邮件信息
|
||||
* @param mailAddress 邮箱地址
|
||||
* @param mailPassword 邮箱密码
|
||||
* @param whiteList 发件人白名单
|
||||
* @param secCategory 附件目录ID
|
||||
* @param userId 操作者ID
|
||||
* @return 返回收件箱中的邮件信息集合
|
||||
*/
|
||||
public List<MailInfoDao> getMainInfo(String mailAddress,String mailPassword,String whiteList,int secCategory,int userId){
|
||||
return getMainInfo(mailAddress,mailPassword,whiteList,secCategory,userId,"");
|
||||
}
|
||||
/**
|
||||
* 获取收件箱中的邮件信息
|
||||
* @param mailAddress 邮箱地址
|
||||
* @param mailPassword 邮箱密码
|
||||
* @param whiteList 发件人白名单
|
||||
* @param secCategory 附件目录ID
|
||||
* @param userId 操作者ID
|
||||
* @param mailFolder 邮箱文件夹
|
||||
* @return 返回收件箱中的邮件信息集合
|
||||
*/
|
||||
public List<MailInfoDao> getMainInfo(String mailAddress,String mailPassword,String whiteList,int secCategory,int userId,String mailFolder){
|
||||
if(session == null){
|
||||
session = createSession();
|
||||
}
|
||||
|
||||
List<MailInfoDao> mailInfoDaoList = new ArrayList<>();
|
||||
//文件夹信息
|
||||
IMAPFolder folder = null;
|
||||
//邮箱会话信息
|
||||
IMAPStore store = null;
|
||||
try{
|
||||
store=(IMAPStore)session.getStore("imap"); // 使用imap会话机制,连接服务器
|
||||
store.connect(host,Util.getIntValue(port),mailAddress,mailPassword);
|
||||
|
||||
if(StringUtils.isBlank(mailFolder)){
|
||||
mailFolder = "INBOX";
|
||||
}
|
||||
|
||||
folder=(IMAPFolder)store.getFolder(mailFolder); //收件箱
|
||||
|
||||
// 使用只读方式打开收件箱
|
||||
folder.open(Folder.READ_WRITE);
|
||||
|
||||
//获取所有的邮件
|
||||
// Message[] mess = folder.getMessages();
|
||||
//获取未读邮件
|
||||
Message[] mess = folder.getMessages(folder.getMessageCount()-folder.getUnreadMessageCount()+1,folder.getMessageCount());
|
||||
|
||||
for (Message message : mess) {
|
||||
Flags flags = message.getFlags();
|
||||
if (!flags.contains(Flags.Flag.SEEN)) {//未读邮件处理
|
||||
String from = MimeUtility.decodeText(message.getFrom()[0].toString());
|
||||
|
||||
if (StringUtils.isNotBlank(whiteList) && !isBelongToWhite(whiteList, from)) {
|
||||
continue;
|
||||
}
|
||||
//设置已读
|
||||
message.setFlag(Flags.Flag.SEEN, true);
|
||||
|
||||
MailInfoDao mailInfoDao = analysisMessage(message, secCategory, userId);
|
||||
|
||||
mailInfoDaoList.add(mailInfoDao);
|
||||
}
|
||||
}
|
||||
}catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
this.writeDebuggerLog("","异常信息96:[" + e.getMessage() + "]");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.writeDebuggerLog("","异常信息99:[" + e.getMessage() + "]");
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (folder != null) {
|
||||
folder.close(false);
|
||||
}
|
||||
if (store != null) {
|
||||
store.close();
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
this.writeDebuggerLog("","异常信息110:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
return mailInfoDaoList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析邮件信息
|
||||
* @param message 邮件
|
||||
* @param secCategory 附件存储目录
|
||||
* @param userId 附件所属者
|
||||
* @return 返回邮件对象
|
||||
* @throws Exception 抛出异常信息
|
||||
*/
|
||||
private MailInfoDao analysisMessage(Message message,int secCategory,int userId) throws Exception {
|
||||
MailInfoDao dao = new MailInfoDao();
|
||||
//邮件发送主题
|
||||
String subject = message.getSubject();
|
||||
//发送日期
|
||||
Date date = message.getSentDate();
|
||||
//邮件正文
|
||||
String htmlContent = getTextFromMessage(message);
|
||||
|
||||
String from = MimeUtility.decodeText(message.getFrom()[0].toString());
|
||||
|
||||
|
||||
//是否包含附件
|
||||
boolean isContainAttachment = isContainAttachment(message);
|
||||
|
||||
dao.setFrom(from);
|
||||
dao.setSubject(subject);
|
||||
dao.setDate(date);
|
||||
dao.setContent(htmlContent);
|
||||
dao.setContainAttachment(isContainAttachment);
|
||||
if(isContainAttachment){
|
||||
List<Integer> docList = saveAttachment(message,secCategory,userId);
|
||||
dao.setAttachmentIdList(docList);
|
||||
}
|
||||
|
||||
return dao;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断邮件中是否包含附件
|
||||
* @return 邮件中存在附件返回true,不存在返回false
|
||||
* @throws MessagingException Message异常信息
|
||||
* @throws IOException IO异常信息
|
||||
*/
|
||||
private boolean isContainAttachment(Part part) throws MessagingException, IOException {
|
||||
boolean flag = false;
|
||||
if (part.isMimeType("multipart/*")) {
|
||||
MimeMultipart multipart = (MimeMultipart) part.getContent();
|
||||
int partCount = multipart.getCount();
|
||||
for (int i = 0; i < partCount; i++) {
|
||||
BodyPart bodyPart = multipart.getBodyPart(i);
|
||||
String disposition = bodyPart.getDisposition();
|
||||
if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
|
||||
flag = true;
|
||||
} else if (bodyPart.isMimeType("multipart/*")) {
|
||||
flag = isContainAttachment(bodyPart);
|
||||
} else {
|
||||
String contentType = bodyPart.getContentType();
|
||||
if (contentType.contains("application") || contentType.contains("name")) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) break;
|
||||
}
|
||||
} else if (part.isMimeType("message/rfc822")) {
|
||||
flag = isContainAttachment((Part)part.getContent());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取邮件附件信息,同时将附件上传至OA系统中返回对应的文档ID
|
||||
* @param part 邮件中多个组合体中的其中一个组合体
|
||||
* @throws Exception 抛出的异常信息
|
||||
*/
|
||||
private List<Integer> saveAttachment(Part part,int secCategory,int userId) throws Exception {
|
||||
|
||||
List<Integer> docList = new ArrayList<>();
|
||||
|
||||
if (part.isMimeType("multipart/*")) {
|
||||
Multipart multipart = (Multipart) part.getContent(); //复杂体邮件
|
||||
//复杂体邮件包含多个邮件体
|
||||
int partCount = multipart.getCount();
|
||||
for (int i = 0; i < partCount; i++) {
|
||||
//获得复杂体邮件中其中一个邮件体
|
||||
BodyPart bodyPart = multipart.getBodyPart(i);
|
||||
//某一个邮件体也有可能是由多个邮件体组成的复杂体
|
||||
String disposition = bodyPart.getDisposition();
|
||||
|
||||
if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
|
||||
InputStream is = bodyPart.getInputStream();
|
||||
//附件名称
|
||||
String fileName = MimeUtility.decodeText(bodyPart.getFileName());
|
||||
int imageFileId = createFileByInputSteam(is, fileName);
|
||||
|
||||
if(imageFileId > 0){
|
||||
int docId = createDocByImageFileId(fileName,secCategory,imageFileId,userId);
|
||||
|
||||
docList.add(docId);
|
||||
}
|
||||
} else if (bodyPart.isMimeType("multipart/*")) {
|
||||
docList.addAll(saveAttachment(bodyPart,secCategory,userId));
|
||||
} else {
|
||||
|
||||
/*String contentType = bodyPart.getContentType();
|
||||
if (contentType.contains("name") || contentType.contains("application")) {
|
||||
//附件名称
|
||||
String fileName = MimeUtility.decodeText(bodyPart.getFileName());
|
||||
int imageFileId = createFileByInputSteam(bodyPart.getInputStream(), fileName);
|
||||
|
||||
if(imageFileId > 0){
|
||||
int docId = createDocByImageFileId(fileName,secCategory,imageFileId,userId);
|
||||
docList.add(docId);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
} else if (part.isMimeType("message/rfc822")) {
|
||||
docList.addAll(saveAttachment((Part) part.getContent(),secCategory,userId));
|
||||
}
|
||||
|
||||
return docList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件信息,文件权限继承文档目录权限
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @param secCategory 文件目录
|
||||
* @param imageFileId 物理文件ID
|
||||
* @param userId 用户ID
|
||||
* @return 文档ID
|
||||
* @throws Exception 可能会出现的异常
|
||||
*/
|
||||
private int createDocByImageFileId(String fileName, int secCategory, int imageFileId, Integer userId) throws Exception {
|
||||
DocInfo docInfo = new DocInfo();
|
||||
docInfo.setImagefileId(imageFileId);
|
||||
docInfo.setSeccategory(secCategory);
|
||||
docInfo.setDocSubject(fileName);
|
||||
docInfo.setDoccontent("");
|
||||
DocServiceImpl docService = new DocServiceImpl();
|
||||
User user = new User(userId);
|
||||
user.setLanguage(7);
|
||||
|
||||
int docId = docService.createDocByUser(docInfo, user);
|
||||
DocImageManager imgManger = new DocImageManager();
|
||||
imgManger.resetParameter();
|
||||
imgManger.setDocid(docId);
|
||||
imgManger.setImagefileid(imageFileId);
|
||||
imgManger.setImagefilename(fileName);
|
||||
imgManger.setIsextfile("1");
|
||||
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
if ("doc".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("3");
|
||||
} else if ("xls".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("4");
|
||||
} else if ("ppt".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("5");
|
||||
} else if ("wps".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("6");
|
||||
} else if ("docx".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("7");
|
||||
} else if ("xlsx".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("8");
|
||||
} else if ("pptx".equalsIgnoreCase(ext)) {
|
||||
imgManger.setDocfiletype("9");
|
||||
} else {
|
||||
imgManger.setDocfiletype("2");
|
||||
}
|
||||
imgManger.AddDocImageInfo();
|
||||
return docId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建物理文件
|
||||
*
|
||||
* @param content 文件流
|
||||
* @param fileName 文件名
|
||||
* @return 文件id
|
||||
*/
|
||||
private int createFileByInputSteam(InputStream content, String fileName) {
|
||||
ImageFileManager imageFileManager = new ImageFileManager();
|
||||
int imgFileId = 0;
|
||||
try {
|
||||
Method saveImageFileByInputStream = ImageFileManager.class.getMethod("saveImageFileByInputStream", InputStream.class, String.class);
|
||||
imgFileId = (int) saveImageFileByInputStream.invoke(imageFileManager, content, fileName);
|
||||
} catch (NoSuchMethodException e) {
|
||||
imageFileManager.setImagFileName(fileName);
|
||||
try {
|
||||
imageFileManager.setData(IOUtils.toBytes(content));
|
||||
imgFileId = imageFileManager.saveImageFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
this.writeDebuggerLog("","创建文件失败,文件流转换失败,失败原因:[" + e.getMessage() + "]");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.writeDebuggerLog("","创建文件失败,失败原因:[" + e.getMessage() + "]");
|
||||
}
|
||||
return imgFileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析邮件正文
|
||||
* @param message 邮件消息类
|
||||
* @return 返回邮件正文
|
||||
* @throws MessagingException 信息异常
|
||||
* @throws IOException IO流异常
|
||||
*/
|
||||
private String getTextFromMessage(Message message) throws MessagingException, IOException {
|
||||
String result = "";
|
||||
|
||||
if (message.isMimeType("text/plain")) {
|
||||
result = message.getContent().toString();
|
||||
} else if (message.isMimeType("multipart/*")) {
|
||||
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
|
||||
result = getTextFromMimeMultipart(mimeMultipart);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂体 递归获取邮件正文
|
||||
* @param mimeMultipart 邮件复杂体类
|
||||
* @return 正文
|
||||
* @throws MessagingException 信息异常
|
||||
* @throws IOException IO流异常
|
||||
*/
|
||||
private String getTextFromMimeMultipart(
|
||||
MimeMultipart mimeMultipart) throws MessagingException, IOException{
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int count = mimeMultipart.getCount();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
|
||||
if (bodyPart.isMimeType("text/plain")) {
|
||||
result.append(bodyPart.getContent());
|
||||
break; // without break same text appears twice in my tests
|
||||
} else if (bodyPart.isMimeType("text/html")) {
|
||||
String html = (String) bodyPart.getContent();
|
||||
//result.append(org.jsoup.Jsoup.parse(html).text());
|
||||
result.append(html);
|
||||
} else if (bodyPart.getContent() instanceof MimeMultipart){
|
||||
result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断发件人 是否属于白名单中
|
||||
* @param whiteList 白名单列表
|
||||
* @param from 发件人
|
||||
* @return 返回判断结果
|
||||
*/
|
||||
private boolean isBelongToWhite(String whiteList,String from){
|
||||
boolean isContain = false;
|
||||
|
||||
List<String> list = Util.splitString2List(whiteList,";");
|
||||
|
||||
for(String mail : list){
|
||||
if(from.contains(mail)){
|
||||
isContain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isContain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录邮箱的Session信息
|
||||
* @return 返回创建的Session
|
||||
*/
|
||||
private Session createSession(){
|
||||
Properties props = System.getProperties();
|
||||
props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
|
||||
props.setProperty("mail.imap.socketFactory.port",port);
|
||||
props.setProperty("mail.store.protocol","imap");
|
||||
props.setProperty("mail.imap.host", host);
|
||||
props.setProperty("mail.imap.port", port);
|
||||
props.setProperty("mail.imap.auth.login.disable", "true");
|
||||
Session session = Session.getDefaultInstance(props,null);
|
||||
session.setDebug(false);
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取建模配置信息
|
||||
* @return 返回建模配置信息集合
|
||||
*/
|
||||
public List<Map<String,Object>> getConfiguration(){
|
||||
//查询配置信息
|
||||
String selectData = "select u.*,wb.docCategory from " + configTableName + " u left join workflow_base wb on u.workflowId = wb.id where u.status = 1";
|
||||
|
||||
String selectDetailData = "select * from " + configTableName + "_dt1 where mainId = ?";
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
List<Map<String,Object>> configList = new ArrayList<>();
|
||||
|
||||
RecordSet rs_d = new RecordSet();
|
||||
|
||||
int mainId;
|
||||
|
||||
if(rs.executeQuery(selectData)){
|
||||
while(rs.next()){
|
||||
mainId = Util.getIntValue(rs.getString("id"),-1);
|
||||
//流程类型ID
|
||||
String workflowId = Util.null2String(rs.getString("workflowId"));
|
||||
//收件人邮箱
|
||||
String mailAddress = Util.null2String(rs.getString("mailAddress"));
|
||||
//邮箱密码
|
||||
String mailPassword = Util.null2String(rs.getString("mailPassword"));
|
||||
//邮件内容写入字段ID
|
||||
//int contentField = Util.getIntValue(rs.getString("contentField"),0);
|
||||
//提醒人
|
||||
int remindUser = Util.getIntValue(rs.getString("remindUser"),0);
|
||||
//发件人白名单
|
||||
String whiteSender = Util.null2String(rs.getString("whiteSender"));
|
||||
//文件夹目录
|
||||
String docCategory = Util.null2String(rs.getString("docCategory"));
|
||||
//邮箱文件夹
|
||||
String mailFolder = Util.null2String(rs.getString("mailFolder"));
|
||||
|
||||
Map<String,Object> detailMap = new HashMap<>();
|
||||
|
||||
detailMap.put("workflowId",workflowId);
|
||||
detailMap.put("mailAddress",mailAddress);
|
||||
detailMap.put("mailPassword",mailPassword);
|
||||
detailMap.put("mailFolder",mailFolder);
|
||||
detailMap.put("remindUser",remindUser);
|
||||
detailMap.put("whiteSender",whiteSender);
|
||||
|
||||
int secCategory = -1;
|
||||
if(!"".equals(docCategory)){
|
||||
secCategory = Util.getIntValue(docCategory.substring(docCategory.lastIndexOf(",")),0);
|
||||
}
|
||||
|
||||
detailMap.put("secCategory",secCategory);
|
||||
|
||||
List<Map<Integer,Integer>> fieldList = new ArrayList<>();
|
||||
if(rs_d.executeQuery(selectDetailData,mainId)){
|
||||
while(rs_d.next()){
|
||||
//邮件字段
|
||||
int mailField = Util.getIntValue(rs_d.getString("mailField"),0);
|
||||
//流程字段
|
||||
int billField = Util.getIntValue(rs_d.getString("billField"),0);
|
||||
|
||||
Map<Integer,Integer> fieldMap = new HashMap<>();
|
||||
fieldMap.put(mailField,billField);
|
||||
|
||||
fieldList.add(fieldMap);
|
||||
}
|
||||
}
|
||||
|
||||
detailMap.put("fieldList",fieldList);
|
||||
|
||||
configList.add(detailMap);
|
||||
}
|
||||
}
|
||||
|
||||
return configList;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.dao;
|
||||
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.Util;
|
||||
import weaver.xiao.commons.config.entity.DocImageFile;
|
||||
import weaver.xiao.commons.config.entity.FieldMessage;
|
||||
import weaver.xiao.commons.config.entity.MappingDetail;
|
||||
import weaver.xiao.commons.config.entity.RequestMappingConfig;
|
||||
import weaver.xiao.commons.config.enumtype.DataSourceEnum;
|
||||
import weaver.xiao.commons.exception.ValueDealException;
|
||||
import weaver.xiao.commons.utils.SqlUtil;
|
||||
import weaver.zwl.common.ToolUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2021/12/29 9:46
|
||||
*/
|
||||
|
||||
public class ConfigMappingCMD {
|
||||
|
||||
private final ToolUtil toolUtil = new ToolUtil();
|
||||
private final String configTableName = "uf_request_config";
|
||||
private final SqlUtil sqlUtil = new SqlUtil();
|
||||
|
||||
public RequestMappingConfig selectByUniqueCode(String uniqueCode) {
|
||||
toolUtil.writeDebuggerLog("=======================查询配置列表=======================");
|
||||
RequestMappingConfig requestMappingConfig = new RequestMappingConfig();
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String querySql = "select id,workflow,requestUrl,dataSource,uniqueCode from " + configTableName + " where uniqueCode = ?";
|
||||
toolUtil.writeDebuggerLog("执行查询的sql query mainRequestMappingConfig list sql new>>>>" + querySql + " uniqueCode >>" + uniqueCode);
|
||||
recordSet.executeQuery(querySql, uniqueCode);
|
||||
if (recordSet.next()) {
|
||||
int mainId = Util.getIntValue(recordSet.getString("id"));
|
||||
requestMappingConfig = sqlUtil.recordSetToEntityByEntity(recordSet, RequestMappingConfig.class);
|
||||
this.setDetailMapping(mainId, requestMappingConfig);
|
||||
}
|
||||
return requestMappingConfig;
|
||||
}
|
||||
|
||||
private void setDetailMapping(int mainId, RequestMappingConfig requestMappingConfig) {
|
||||
// 查询明细1的信息
|
||||
RecordSet detail1RecordSet = new RecordSet();
|
||||
String dataSource = requestMappingConfig.getDataSource();
|
||||
if (Objects.isNull(dataSource) || "".equals(dataSource)) {
|
||||
dataSource = "0";
|
||||
}
|
||||
DataSourceEnum anEnum = DataSourceEnum.getEnum(dataSource);
|
||||
String queryDetail1Sql = "";
|
||||
switch (anEnum) {
|
||||
case CUS_TABLE:
|
||||
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext," +
|
||||
" from " + configTableName + "_dt1 config ";
|
||||
break;
|
||||
case WORKFLOW:
|
||||
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,valueContext," +
|
||||
" fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " +
|
||||
" from " + configTableName + "_dt1 config " +
|
||||
" left join workflow_field_table_view fv on config.workflowField = fv.id " +
|
||||
" where mainid = ? ";
|
||||
break;
|
||||
case MODEL:
|
||||
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext," +
|
||||
" fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " +
|
||||
" from " + configTableName + "_dt1 config " +
|
||||
" left join workflow_field_table_view fv on config.modelField = fv.id " +
|
||||
" where mainid = ? ";
|
||||
break;
|
||||
default:
|
||||
throw new ValueDealException("不支持的数据来源");
|
||||
}
|
||||
toolUtil.writeDebuggerLog("执行查询的明细1sql query detail1Sql >>>>" + queryDetail1Sql + " mainId:" + mainId);
|
||||
detail1RecordSet.executeQuery(queryDetail1Sql, mainId);
|
||||
List<MappingDetail> mappingDetails = new ArrayList<>();
|
||||
while (detail1RecordSet.next()) {
|
||||
MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail1RecordSet, MappingDetail.class);
|
||||
String getValueType = mappingDetail.getGetValueType();
|
||||
// 设置流程字段相关信息
|
||||
// if("0".equals(getValueType) || "4".equals(getValueType)){
|
||||
FieldMessage fieldMessage = sqlUtil.recordSetToEntityByEntity(detail1RecordSet, FieldMessage.class);
|
||||
mappingDetail.setFieldMassage(fieldMessage);
|
||||
// }
|
||||
mappingDetails.add(mappingDetail);
|
||||
}
|
||||
// 查询明细2的信息
|
||||
RecordSet detail2RecordSet = new RecordSet();
|
||||
String queryDetail2Sql = "select paramName,belongTo,childType,dataSource,detailId from uf_request_config_dt2 where mainid = ?";
|
||||
toolUtil.writeDebuggerLog("执行查询的明细sql query detail2Sql >>>>" + queryDetail2Sql + " mainId:" + mainId);
|
||||
detail2RecordSet.executeQuery(queryDetail2Sql, mainId);
|
||||
while (detail2RecordSet.next()) {
|
||||
MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail2RecordSet, MappingDetail.class);
|
||||
mappingDetail.setParamType("6");// 设置参数类型为List
|
||||
mappingDetails.add(mappingDetail);
|
||||
}
|
||||
// 查询明细3的信息
|
||||
RecordSet detail3RecordSet = new RecordSet();
|
||||
String queryDetail3Sql = "select paramName,belongTo from uf_request_config_dt3 where mainid = ?";
|
||||
toolUtil.writeDebuggerLog("执行查询的明细sql query detail3Sql >>>>" + queryDetail3Sql + " mainId:" + mainId);
|
||||
detail3RecordSet.executeQuery(queryDetail3Sql, mainId);
|
||||
while (detail3RecordSet.next()) {
|
||||
MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail3RecordSet, MappingDetail.class);
|
||||
mappingDetail.setParamType("5");// 设置参数类型为Object
|
||||
mappingDetails.add(mappingDetail);
|
||||
}
|
||||
requestMappingConfig.setConfigDetail(mappingDetails);
|
||||
// //查询明细4的信息
|
||||
// RecordSet detail4RecordSet = new RecordSet();
|
||||
// List<ResponseMapping> responseMappingList = new ArrayList<>();
|
||||
// String queryDetail4Sql = "select responseFieldName,workflowField,mainOrDetail,detailTableId,workflowFieldName from uf_request_config_dt4 where mainid = ?";
|
||||
// toolUtil.writeDebuggerLog("执行查询的明细sql query detail4Sql >>>>"+queryDetail4Sql+" mainId:"+mainId);
|
||||
// detail4RecordSet.executeQuery(queryDetail4Sql,mainId);
|
||||
// while (detail4RecordSet.next()){
|
||||
// ResponseMapping responseMapping = sqlUtil.recordSetToEntityByEntity(detail4RecordSet, ResponseMapping.class);
|
||||
// responseMappingList.add(responseMapping);
|
||||
// }
|
||||
// requestMappingConfig.setResponseMappingList(responseMappingList);
|
||||
requestMappingConfig.setConfigDetail(mappingDetails);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <h2>查询附件信息</h2>
|
||||
*
|
||||
* @param docIds 文档id
|
||||
* @return 附件信息
|
||||
* @author YouHong.ai
|
||||
*/
|
||||
public List<DocImageFile> selectDocImageFileList(String docIds) {
|
||||
String sql = "select docfile.IMAGEFILEID,docfile.IMAGEFILENAME,docfile.DOCID,docfile.ID, " +
|
||||
" imf.FILESIZE " +
|
||||
"from docimagefile docfile " +
|
||||
"left join imagefile imf on imf.IMAGEFILEID = docfile.IMAGEFILEID " +
|
||||
"where docid in (" + docIds + ")";
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(sql);
|
||||
List<DocImageFile> docImageFileList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String IMAGEFILEID = rs.getString("IMAGEFILEID");
|
||||
String IMAGEFILENAME = rs.getString("IMAGEFILENAME");
|
||||
String DOCID = rs.getString("DOCID");
|
||||
String ID = rs.getString("ID");
|
||||
String fileSize = rs.getString("FILESIZE");
|
||||
DocImageFile docImageFile = new DocImageFile();
|
||||
docImageFile.setImageFileId(Util.getIntValue(IMAGEFILEID));
|
||||
docImageFile.setImageFileName(IMAGEFILENAME);
|
||||
docImageFile.setDocId(Util.getIntValue(DOCID));
|
||||
docImageFile.setId(Util.getIntValue(ID));
|
||||
docImageFile.setFileSize(Util.getIntValue(fileSize) / 1024L);
|
||||
docImageFileList.add(docImageFile);
|
||||
}
|
||||
if (docImageFileList.isEmpty()) {
|
||||
throw new NullPointerException("附件字段不存在值!请检查数据表或配置表数据类型是否正确!");
|
||||
}
|
||||
return docImageFileList;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <h1>附件信息</h1>
|
||||
*
|
||||
* <p>create: 2022-11-21 10:55</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class DocImageFile {
|
||||
/**
|
||||
* 文件id
|
||||
*/
|
||||
private Integer imageFileId;
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String imageFileName;
|
||||
/**
|
||||
* docId
|
||||
*/
|
||||
private Integer docId;
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private Long fileSize;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import weaver.xiao.commons.utils.annotation.SqlFieldMapping;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2021/12/31 10:15
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class FieldMessage {
|
||||
|
||||
@SqlFieldMapping("fieldId")
|
||||
private String fieldId;
|
||||
|
||||
@SqlFieldMapping("fieldName")
|
||||
private String fieldName;
|
||||
|
||||
@SqlFieldMapping("indexDesc")
|
||||
private String indexDesc;
|
||||
|
||||
@SqlFieldMapping("tableName")
|
||||
private String tableName;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <h1>list分割暂存类</h1>
|
||||
*
|
||||
* <p>create: 2022-08-05 11:25</p>
|
||||
*
|
||||
* @author aiyh EBU7-dev-1
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ListMapIndexValue {
|
||||
private String key;
|
||||
private Object value;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import weaver.xiao.commons.config.entity.FieldMessage;
|
||||
import weaver.xiao.commons.utils.annotation.SqlFieldMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2021/12/28 17:45
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class MappingDetail {
|
||||
|
||||
@SqlFieldMapping("paramName")
|
||||
private String paramName;
|
||||
|
||||
@SqlFieldMapping("paramType")
|
||||
private String paramType;
|
||||
|
||||
@SqlFieldMapping("getValueType")
|
||||
private String getValueType;
|
||||
|
||||
@SqlFieldMapping("childType")
|
||||
private String childType;
|
||||
|
||||
@SqlFieldMapping("dataSource")
|
||||
private String dataSource;
|
||||
|
||||
@SqlFieldMapping("detailId")
|
||||
private String detailId;
|
||||
|
||||
@SqlFieldMapping("belongTo")
|
||||
private String belongTo;
|
||||
|
||||
@SqlFieldMapping("workflowField")
|
||||
private String workflowField;
|
||||
|
||||
@SqlFieldMapping("valueContext")
|
||||
private String valueContext;
|
||||
|
||||
private List<MappingDetail> childList;
|
||||
|
||||
private FieldMessage fieldMassage;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* <p>create: 2022-11-21 11:12</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString
|
||||
public class MultipartFile {
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
String fileName;
|
||||
/**
|
||||
* 上传文件的key
|
||||
*/
|
||||
String fileKey;
|
||||
/**
|
||||
* 文件流信息
|
||||
*/
|
||||
InputStream stream;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
Long fileSize;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import weaver.xiao.commons.config.entity.MappingDetail;
|
||||
import weaver.xiao.commons.config.entity.ResponseMapping;
|
||||
import weaver.xiao.commons.utils.annotation.SqlFieldMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2021/12/28 17:43
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class RequestMappingConfig {
|
||||
|
||||
@SqlFieldMapping("workflow")
|
||||
private String workflow;
|
||||
|
||||
@SqlFieldMapping("requestUrl")
|
||||
private String requestUrl;
|
||||
|
||||
@SqlFieldMapping("uniqueCode")
|
||||
private String uniqueCode;
|
||||
|
||||
@SqlFieldMapping("dataSource")
|
||||
private String dataSource;
|
||||
|
||||
@SqlFieldMapping("modelId")
|
||||
private String modelId;
|
||||
|
||||
@SqlFieldMapping("tableName")
|
||||
private String tableName;
|
||||
|
||||
@SqlFieldMapping("urlDesc")
|
||||
private String urlDesc;
|
||||
|
||||
private List<MappingDetail> configDetail;
|
||||
|
||||
private List<ResponseMapping> responseMappingList;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2022/4/12 22:28
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ResponseMapping {
|
||||
private String responseFieldName;
|
||||
private String workflowField;
|
||||
private String mainOrDetail;
|
||||
private String detailTableId;
|
||||
private String workflowFieldName;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.enumtype;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2022/6/14 12:26
|
||||
*/
|
||||
|
||||
public enum DataSourceEnum {
|
||||
|
||||
WORKFLOW("0"),
|
||||
MODEL("1"),
|
||||
CUS_TABLE("2");
|
||||
|
||||
private static final Map<String, DataSourceEnum> LOOK_UP = new HashMap<>(8);
|
||||
|
||||
static {
|
||||
for (DataSourceEnum dataSource : EnumSet.allOf(DataSourceEnum.class)){
|
||||
LOOK_UP.put(dataSource.value,dataSource);
|
||||
}
|
||||
}
|
||||
public final String value;
|
||||
|
||||
DataSourceEnum(String value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static DataSourceEnum getEnum(String value){
|
||||
return LOOK_UP.get(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.enumtype;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2022/6/14 13:13
|
||||
*/
|
||||
|
||||
public enum GetValueTypeEnum {
|
||||
|
||||
WORKFLOW_FIELD("0"),
|
||||
DEFAULT_VALUE("1"),
|
||||
CURRENT_TIME("3"),
|
||||
CUS_SQL("4"),
|
||||
REQUEST_ID("5"),
|
||||
MAIN_DATA_ID("6"),
|
||||
RANDOM("7"),
|
||||
ATTACHMENT("8"),
|
||||
|
||||
CUS_INTERFACE("9"),
|
||||
|
||||
CUS_FIELD("10");
|
||||
|
||||
private static final Map<String, GetValueTypeEnum> LOOK_UP = new HashMap<>(8);
|
||||
|
||||
static {
|
||||
for (GetValueTypeEnum getValueTypeEnum : EnumSet.allOf(GetValueTypeEnum.class)) {
|
||||
LOOK_UP.put(getValueTypeEnum.value, getValueTypeEnum);
|
||||
}
|
||||
}
|
||||
|
||||
public final String value;
|
||||
|
||||
GetValueTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static GetValueTypeEnum getEnum(String value) {
|
||||
return LOOK_UP.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.enumtype;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author XiaoBokang
|
||||
* @create 2022/6/14 12:56
|
||||
*/
|
||||
|
||||
public enum ParamTypeEnum {
|
||||
|
||||
STRING("0"),
|
||||
INT("1"),
|
||||
DOUBLE("2"),
|
||||
DATE("3"),
|
||||
DATE_TIME("4"),
|
||||
OBJECT("5"),
|
||||
LIST("6"),
|
||||
CUS_DATE_STR("7"),
|
||||
TIME_STAMP("8"),
|
||||
DATE_VAL("9"),
|
||||
Boolean("10");
|
||||
|
||||
|
||||
private static final Map<String, ParamTypeEnum> LOOK_UP = new HashMap<>(8);
|
||||
|
||||
static {
|
||||
for (ParamTypeEnum paramTypeEnum : EnumSet.allOf(ParamTypeEnum.class)){
|
||||
LOOK_UP.put(paramTypeEnum.value,paramTypeEnum);
|
||||
}
|
||||
}
|
||||
public final String value;
|
||||
|
||||
ParamTypeEnum(String value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ParamTypeEnum getEnum(String value){
|
||||
return LOOK_UP.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.interfacies;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.xiao.commons.utils.LogUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>自定义获取参数值</h1>
|
||||
*
|
||||
* @author EBU7-dev-1 aiyh
|
||||
* <p>create: 2022-07-25 14:18</p>
|
||||
*/
|
||||
|
||||
public interface CusInterfaceGetValue {
|
||||
|
||||
final String START_LEFT = "{";
|
||||
final String VAR_START_STR = "#{";
|
||||
final String MAIN = "main.";
|
||||
final String DETAIL = "detail.";
|
||||
final String END_STR = "}";
|
||||
|
||||
final String SQL_START = "#sql{";
|
||||
|
||||
final Logger log = LogUtil.getLogger();
|
||||
|
||||
/**
|
||||
* 获取参数值
|
||||
*
|
||||
* @param mainMap 主表数据
|
||||
* @param detailMap 明细表数据
|
||||
* @param currentValue 当前字段值
|
||||
* @param pathParam 路径参数
|
||||
* @return 最终返回参数
|
||||
*/
|
||||
Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap, String currentValue,
|
||||
Map<String, String> pathParam);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package weaver.chaoyang.he.xiao.commons.config.interfacies;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>自定义数组数据来源</h1>
|
||||
*
|
||||
* <p>create: 2022-08-15 15:38</p>
|
||||
*
|
||||
* @author aiyh EBU7-dev-1
|
||||
*/
|
||||
|
||||
public interface CusInterfaceListValue {
|
||||
|
||||
/**
|
||||
* <h2>自定义数组数据来源</h2>
|
||||
*
|
||||
* @param pathParam 路径参数
|
||||
* @param mainMap 主表数据
|
||||
* @param mainTable 主表表明
|
||||
* @return 数组
|
||||
*/
|
||||
List<Object> execute(Map<String, String> pathParam, Map<String, Object> mainMap, String mainTable);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue