cashbill.java 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. package restcontroller.sale.cashbill;
  2. import beans.clear.ClearData;
  3. import beans.data.BatchDeleteErr;
  4. import beans.datacontrllog.DataContrlLog;
  5. import beans.datateam.DataTeam;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.sun.xml.internal.xsom.impl.Ref;
  9. import common.Controller;
  10. import common.YosException;
  11. import common.annotation.API;
  12. import common.annotation.CACHEING;
  13. import common.annotation.CACHEING_CLEAN;
  14. import common.annotation.cm;
  15. import common.data.*;
  16. import common.data.Row;
  17. import org.apache.commons.lang.StringUtils;
  18. import org.apache.poi.ss.usermodel.*;
  19. import org.apache.poi.xssf.usermodel.*;
  20. import restcontroller.R;
  21. import restcontroller.system.attachment.Attachment;
  22. import java.math.BigDecimal;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.HashMap;
  27. import java.util.Map;
  28. import static restcontroller.webmanage.saletool.orderclue.orderclue.isBigDecimal;
  29. public class cashbill extends Controller {
  30. public cashbill(JSONObject arg0) throws YosException {
  31. super(arg0);
  32. // TODO Auto-generated constructor stub
  33. }
  34. /**
  35. * 下载凭证导入单模板
  36. *
  37. * @return
  38. */
  39. @API(title = "下载凭证导入单模板", apiversion = R.ID20230506162603.v1.class)
  40. public String downloadCashbillExcel() throws YosException {
  41. ExcelFactory excelFactory = new ExcelFactory("ImportTemplateForCashbill");
  42. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  43. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  44. CellStyle style = xssfFWorkbook.createCellStyle();
  45. // 设置为文本格式,防止身份证号变成科学计数法
  46. DataFormat format = xssfFWorkbook.createDataFormat();
  47. style.setDataFormat(format.getFormat("@"));
  48. // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
  49. sheet.setDefaultColumnStyle(0, style);
  50. sheet.setDefaultColumnStyle(1, style);
  51. sheet.setDefaultColumnStyle(2, style);
  52. if(content.getString("type").equals("收入")){
  53. IncomeExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  54. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  55. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  56. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createBodyCellStyle(xssfFWorkbook);
  57. XSSFCellStyle titleCellStyle4 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  58. IncomeExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  59. xssfFWorkbook);// 写入标题
  60. }else if(content.getString("type").equals("支出")){
  61. PayExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  62. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  63. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  64. XSSFCellStyle titleCellStyle3 = PayExportExcel.createBodyCellStyle(xssfFWorkbook);
  65. XSSFCellStyle titleCellStyle4 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  66. PayExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  67. xssfFWorkbook);// 写入标题
  68. }else{
  69. return getErrReturnObject().setErrMsg("凭证类型不匹配,无法下载导入文件").toString();
  70. }
  71. Rows aa = uploadExcelToObs(excelFactory);
  72. String url = "";
  73. if (!aa.isEmpty()) {
  74. url = aa.get(0).getString("url");
  75. }
  76. return getSucReturnObject().setData(url).toString();
  77. }
  78. /**
  79. * 导入凭证
  80. *
  81. * @return
  82. */
  83. @API(title = "导入凭证", apiversion = R.ID20230506162703.v1.class)
  84. @CACHEING_CLEAN(apiClass = cashbill.class)
  85. public String uploadCashbillByExcel() throws YosException {
  86. ExcelFactory e;
  87. try {
  88. // 华为云
  89. //e = getPostExcelFactory(content.getLong("attachmentid"));
  90. // 本地
  91. e = getPostExcelFactory();
  92. // Rows keyRow = dbConnect.runSqlQuery("select fagentnum,faddress from tagents
  93. // where 1=2");
  94. // Rows row1 = e.getSheetRows(1, keyRow, 1);
  95. ArrayList<String> keys = new ArrayList<>();
  96. ArrayList<String> sqllist = new ArrayList<>();
  97. keys.add("agentnum");
  98. keys.add("accountname");
  99. keys.add("amount");
  100. keys.add("type");
  101. keys.add("typemx");
  102. keys.add("remarks");
  103. Rows accountclassRows = dbConnect.runSqlQuery("select sa_accountclassid,accountname from sa_accountclass where siteid='"+siteid+"' and isused=1");
  104. RowsMap accountclassRowsMap = accountclassRows.toRowsMap("accountname");
  105. Rows agentRows = dbConnect.runSqlQuery("select agentnum,sys_enterpriseid from sa_agents where siteid='"+siteid+"'");
  106. RowsMap agentRowsMap = agentRows.toRowsMap("agentnum");
  107. if (!(content.getString("type") + "凭证导入")
  108. .equals(((String) getCellFormatValue(e.getSheet(0).getRow(0).getCell(0))).replace(" ", ""))) {
  109. return getErrReturnObject().setErrMsg("导入失败,不符合" + content.getString("type") + "凭证导入要求").toString();
  110. }
  111. Rows rows = e.getSheetRows(0, keys, 3);
  112. int a = 1;
  113. int i = 0;
  114. // String msg = "";
  115. boolean iserr = false;
  116. Rows rowserr = new Rows();
  117. Rows rowssuc = new Rows();
  118. for (Row row : rows) {
  119. String msg = "";
  120. if (StringUtils.isEmpty(row.getString("agentnum"))) {
  121. iserr = true;
  122. msg =msg + "【经销商编码为空】";
  123. }
  124. if (StringUtils.isEmpty(row.getString("accountname"))) {
  125. iserr = true;
  126. msg = msg +"【账户名称为空】";
  127. }
  128. if (!isBigDecimal(row.getString("amount"))) {
  129. iserr = true;
  130. msg = msg + "【金额错误:" + row.getString("amount") + "】";
  131. }
  132. if (StringUtils.isEmpty(row.getString("type"))) {
  133. iserr = true;
  134. msg = msg +"【分类为空】";
  135. }
  136. if(!agentRowsMap.containsKey(row.getString("agentnum"))){
  137. msg = msg +"【该经销商编码找不到匹配的经销商】";
  138. }else{
  139. if(agentRowsMap.get(row.getString("agentnum")).isEmpty()){
  140. msg = msg +"【该经销商编码找不到匹配的经销商】";
  141. }
  142. }
  143. if(!accountclassRowsMap.containsKey(row.getString("accountname"))){
  144. msg = msg +"【该账户名称找不到匹配的账户】";
  145. }else{
  146. if(accountclassRowsMap.get(row.getString("accountname")).isEmpty()){
  147. msg = msg +"【该账户名称找不到匹配的账户】";
  148. }
  149. }
  150. if (iserr) {
  151. row.put("msg", "错误信息:" + msg);
  152. rowserr.add(row);
  153. } else {
  154. rowssuc.add(row);
  155. }
  156. // if (!msg.equals("111")) {
  157. // XSSFWorkbook xssfFWorkbook = e.getXssfWorkbook();
  158. // XSSFCellStyle cellStyle = xssfFWorkbook.createCellStyle();
  159. //
  160. // XSSFFont font = xssfFWorkbook.createFont();
  161. //
  162. // font.setColor((short) 0xa);
  163. // font.setFontHeightInPoints((short) 8);
  164. // font.setBold(true);
  165. // cellStyle.setFont(font);
  166. // datarow.createCell(8).setCellValue("错误信息:" + msg);
  167. // datarow.getCell(8).setCellStyle(cellStyle);
  168. //
  169. // }
  170. }
  171. long[] sa_cashbillid = createTableID("sa_cashbill",
  172. rowssuc.size());
  173. if (!rowssuc.isEmpty()) {
  174. for (Row row : rowssuc) {
  175. SQLFactory sqlFactoryupload = new SQLFactory(this, "收支凭证新增");
  176. sqlFactoryupload.addParameter("sa_cashbillid", sa_cashbillid[i]);
  177. sqlFactoryupload.addParameter("billno", createBillCode("cashbill"));
  178. if(agentRowsMap.containsKey(row.getString("agentnum"))){
  179. sqlFactoryupload.addParameter("sys_enterpriseid", agentRowsMap.get(row.getString("agentnum")).get(0).getLong("sys_enterpriseid"));
  180. }else {
  181. continue;
  182. }
  183. if(accountclassRowsMap.containsKey(row.getString("accountname"))){
  184. sqlFactoryupload.addParameter("sa_accountclassid", accountclassRowsMap.get(row.getString("accountname")).get(0).getLong("sa_accountclassid"));
  185. }else {
  186. continue;
  187. }
  188. if(content.getString("type").equals("收入")){
  189. sqlFactoryupload.addParameter("type", 1);
  190. }else{
  191. sqlFactoryupload.addParameter("type", 0);
  192. }
  193. sqlFactoryupload.addParameter("siteid", siteid);
  194. sqlFactoryupload.addParameter("remarks", row.getString("remarks"));
  195. sqlFactoryupload.addParameter("amount", row.getString("amount"));
  196. sqlFactoryupload.addParameter("subclass", row.getString("typemx"));
  197. sqlFactoryupload.addParameter("class", row.getString("type"));
  198. sqlFactoryupload.addParameter("userid", userid);
  199. sqlFactoryupload.addParameter("username", username);
  200. sqlFactoryupload.addParameter("ownertable", "");
  201. sqlFactoryupload.addParameter("ownerid", 0);
  202. sqlFactoryupload.addParameter("source", "");
  203. sqlFactoryupload.addParameter("sourcenote", "");
  204. sqllist.add(sqlFactoryupload.getSQL());
  205. i++;
  206. }
  207. }
  208. if (iserr) {
  209. ExcelFactory excelFactory = new ExcelFactory("sa_cashbillerr");
  210. HashMap<String, String> map = new HashMap<String, String>();
  211. map.put("agentnum", "经销商编码");
  212. map.put("accountname", "账户名称");
  213. map.put("amount", "金额");
  214. map.put("type", "分类");
  215. map.put("typemx", "分类明细");
  216. map.put("remarks", "备注");
  217. map.put("msg", "错误信息");
  218. ArrayList<String> colNameList = new ArrayList<String>();
  219. HashMap<String, Class> keytypemap = new HashMap<String, Class>();
  220. colNameList.add("agentnum");
  221. colNameList.add("accountname");
  222. colNameList.add("amount");
  223. colNameList.add("type");
  224. colNameList.add("typemx");
  225. colNameList.add("remarks");
  226. colNameList.add("msg");
  227. keytypemap.put("agentnum", String.class);
  228. keytypemap.put("accountname", String.class);
  229. keytypemap.put("amount", String.class);
  230. keytypemap.put("type", String.class);
  231. keytypemap.put("typemx", String.class);
  232. keytypemap.put("remarks", String.class);
  233. keytypemap.put("msg", String.class);
  234. rowserr.setFieldList(colNameList);
  235. rowserr.setFieldTypeMap(keytypemap);
  236. if(content.getString("type").equals("收入")){
  237. addSheetIncome(excelFactory, "Sheet1", rowserr, map);
  238. }else {
  239. addSheetPay(excelFactory, "Sheet1", rowserr, map);
  240. }
  241. Rows aa = uploadExcelToObs(excelFactory);
  242. String url = "";
  243. if (!aa.isEmpty()) {
  244. url = aa.get(0).getString("url");
  245. }
  246. return getSucReturnObject().setData(url).toString();
  247. }
  248. } catch (Exception e1) {
  249. // TODO Auto-generated catch block
  250. e1.printStackTrace();
  251. return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
  252. }
  253. return getSucReturnObject().toString();
  254. }
  255. @API(title = "收支凭证新建更新", apiversion = R.ID20221009102803.v1.class)
  256. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  257. public String insertormodify_creditbill() throws YosException {
  258. Long sa_cashbillid = content.getLong("sa_cashbillid");
  259. Long type = content.getLong("type"); //收支类型(1:收;0:支)
  260. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  261. Long sa_accountclassid = content.getLong("sa_accountclassid");
  262. String billcode = createBillCode("cashbill");
  263. String subclass = content.getString("subclass");
  264. String class1 = content.getString("class");
  265. //String billcode = "123456789";
  266. BigDecimal amount = content.getBigDecimal("amount");
  267. String remarks = content.getString("remarks");
  268. // String source = content.getString("source");
  269. // String sourcenote = content.getString("sourcenote");
  270. ArrayList<String> sqlList = new ArrayList<>();
  271. if (sa_cashbillid <= 0 || dbConnect
  272. .runSqlQuery("select sa_cashbillid from sa_cashbill where sa_cashbillid="
  273. + sa_cashbillid)
  274. .isEmpty()) {
  275. sa_cashbillid = createTableID("sa_cashbill");
  276. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证新增");
  277. sqlFactory.addParameter("billno", billcode);
  278. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  279. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  280. sqlFactory.addParameter("type", type);
  281. sqlFactory.addParameter("siteid", siteid);
  282. sqlFactory.addParameter("remarks", remarks);
  283. sqlFactory.addParameter("amount", amount);
  284. sqlFactory.addParameter("subclass", subclass);
  285. sqlFactory.addParameter("class", class1);
  286. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  287. sqlFactory.addParameter("userid", userid);
  288. sqlFactory.addParameter("username", username);
  289. sqlFactory.addParameter("ownertable", "");
  290. sqlFactory.addParameter("ownerid", 0);
  291. sqlFactory.addParameter("source", "");
  292. sqlFactory.addParameter("sourcenote", "");
  293. content.put("sa_cashbillid", sa_cashbillid);
  294. sqlList.add(sqlFactory.getSQL());
  295. } else {
  296. Rows rowscount = dbConnect.runSqlQuery(
  297. "select status from sa_cashbill where sa_cashbillid=" + sa_cashbillid);
  298. if (rowscount.isEmpty()) {
  299. return getErrReturnObject().setErrMsg("此收支凭证不存在").toString();
  300. } else {
  301. if (!rowscount.get(0).getString("status").equals("新建")) {
  302. return getErrReturnObject().setErrMsg("非新建状态的收支凭证无法更新").toString();
  303. }
  304. }
  305. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证更新");
  306. sqlFactory.addParameter("siteid", siteid);
  307. sqlFactory.addParameter("remarks", remarks);
  308. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  309. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  310. sqlFactory.addParameter("amount", amount);
  311. sqlFactory.addParameter("subclass", subclass);
  312. sqlFactory.addParameter("class", class1);
  313. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  314. sqlFactory.addParameter("userid", userid);
  315. sqlFactory.addParameter("username", username);
  316. sqlFactory.addParameter("source", "");
  317. sqlFactory.addParameter("sourcenote", "");
  318. sqlList.add(sqlFactory.getSQL());
  319. }
  320. dbConnect.runSqlUpdate(sqlList);
  321. return queryCashbillMain();
  322. }
  323. // @API(title = "合作企业档案列表",apiversion = R.ID20221008164103.v1.class)
  324. // @CACHEING
  325. // public String queryEnterpriseList() throws YosException {
  326. //
  327. // /*
  328. // * 过滤条件设置
  329. // */
  330. // String where = " 1=1 ";
  331. // if (content.containsKey("where")) {
  332. // JSONObject whereObject = content.getJSONObject("where");
  333. // if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  334. // where = where + " and(t1.enterprisename like'%" + whereObject.getString("condition")
  335. // + "%' or t1.phonenumber like '%" + whereObject.getString("condition") + "%')";
  336. // }
  337. // }
  338. // SQLFactory sqlFactory = new SQLFactory(this, "合作企业档案列表查询", pageSize, pageNumber, pageSorting);
  339. // sqlFactory.addParameter_SQL("where", where);
  340. // sqlFactory.addParameter("siteid", siteid);
  341. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  342. // return getSucReturnObject().setData(rows).toString();
  343. // }
  344. //
  345. // @API(title = "营销账户类别列表",apiversion = R.ID20221008164203.v1.class)
  346. // @CACHEING
  347. // public String queryAccountclassList() throws YosException {
  348. // long sys_enterpriseid=content.getLong("sys_enterpriseid");
  349. //
  350. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户类别列表查询");
  351. // sqlFactory.addParameter("siteid", siteid);
  352. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  353. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  354. // return getSucReturnObject().setData(rows).toString();
  355. // }
  356. @API(title = "收入凭证列表", apiversion = R.ID20221009102903.v1.class)
  357. @CACHEING
  358. public String queryIncomeCashbillList() throws YosException {
  359. /*
  360. * 过滤条件设置
  361. */
  362. String where = " 1=1 and t1.type=1 ";
  363. if (content.containsKey("where")) {
  364. JSONObject whereObject = content.getJSONObject("where");
  365. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  366. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  367. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  368. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  369. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  370. + " or t1.remarks like '%" + whereObject.getString("condition") + "%'"
  371. + ")";
  372. }
  373. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  374. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  375. }
  376. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  377. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  378. }
  379. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  380. where = where + " and t1.createdate >='" + whereObject.getString("begindate") + "'";
  381. }
  382. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  383. where = where + " and t1.createdate <='" + whereObject.getString("enddate") + "'";
  384. }
  385. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  386. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  387. }
  388. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  389. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  390. }
  391. }
  392. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证列表查询", pageSize, pageNumber, pageSorting);
  393. sqlFactory.addParameter_SQL("where", where);
  394. sqlFactory.addParameter("siteid", siteid);
  395. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  396. ArrayList sa_cashbillids = rows.toArrayList("sa_cashbillid", new ArrayList<>());
  397. sa_cashbillids.add(0L);
  398. String sql = "select t1.sa_cashbillid,t2.billno from sa_cashbill t1 inner join sa_cashbill t2 on t1.siteid=t2.siteid and t1.ownerid=t2.sa_cashbillid and t1.ownertable='sa_cashbill' where t1.siteid='" + siteid + "' and t1.ownerid in " + sa_cashbillids;
  399. sql = sql.replace("[", "(").replace("]", ")");
  400. RowsMap offsettingRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("sa_cashbillid");
  401. for (Row row : rows) {
  402. if (row.getString("ownertable").equals("sa_cashbill") && offsettingRowsMap.containsKey(row.getString("sa_cashbillid"))) {
  403. row.put("offsettingbillno", offsettingRowsMap.get(row.getString("sa_cashbillid")).get(0).getString("billno"));
  404. }
  405. row.put("amount", row.getBigDecimal("amount"));
  406. }
  407. return getSucReturnObject().setData(rows).toString();
  408. }
  409. @API(title = "支出收入凭证列表", apiversion = R.ID20221010102903.v1.class)
  410. @CACHEING
  411. public String queryPayCashbillList() throws YosException {
  412. /*
  413. * 过滤条件设置
  414. */
  415. String where = " 1=1 and t1.type=0 ";
  416. if (content.containsKey("where")) {
  417. JSONObject whereObject = content.getJSONObject("where");
  418. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  419. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  420. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  421. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  422. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  423. + ")";
  424. }
  425. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  426. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  427. }
  428. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  429. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  430. }
  431. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  432. where = where + " and t1.createdate >='" + whereObject.getString("begindate") + "'";
  433. }
  434. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  435. where = where + " and t1.createdate <='" + whereObject.getString("enddate") + "'";
  436. }
  437. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  438. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  439. }
  440. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  441. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  442. }
  443. }
  444. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证列表查询", pageSize, pageNumber, pageSorting);
  445. sqlFactory.addParameter_SQL("where", where);
  446. sqlFactory.addParameter("siteid", siteid);
  447. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  448. for (Row row : rows) {
  449. row.put("amount", row.getBigDecimal("amount"));
  450. }
  451. return getSucReturnObject().setData(rows).toString();
  452. }
  453. @API(title = "收支凭证详情", apiversion = R.ID20221009103003.v1.class)
  454. public String queryCashbillMain() throws YosException {
  455. Long sa_cashbillid = content.getLong("sa_cashbillid");
  456. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  457. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  458. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  459. if (rows.size() > 0) {
  460. Rows offsetting = dbConnect.runSqlQuery("select billno from sa_cashbill where siteid='" + siteid + "' and '" + rows.get(0).getString("ownertable") + "'='sa_cashbill' and sa_cashbillid=" + rows.get(0).getLong("ownerid"));
  461. if (offsetting.isNotEmpty()) {
  462. rows.get(0).put("offsettingbillno", offsetting.get(0).getString("billno"));
  463. }
  464. rows.get(0).put("amount", rows.get(0).getBigDecimal("amount"));
  465. }
  466. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  467. }
  468. /**
  469. * 收支凭证审核
  470. *
  471. * @return
  472. */
  473. @API(title = "收支凭证审核", apiversion = R.ID20221009103103.v1.class)
  474. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class, R.ID20230111103403.v1.class})
  475. public String release() throws YosException {
  476. long sa_cashbillid = content.getLong("sa_cashbillid");
  477. String[] s = {"sa_cashbillid"};
  478. for (String s1 : s) {
  479. if (!content.containsKey(s1))
  480. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  481. }
  482. //List<String> list = sa_creditbillids.toJavaList(String.class);
  483. //String[] stringArray = list.toArray(new String[0]);
  484. //SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  485. //sqlFactoryquery.addParameter("siteid", siteid);
  486. //sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  487. Rows rows = dbConnect.runSqlQuery("select sa_cashbillid,sys_enterpriseid,sa_accountclassid,status,billno,amount,type,ownerid from sa_cashbill where sa_cashbillid ='" + sa_cashbillid + "' and siteid='" + siteid + "'");
  488. for (Row row : rows) {
  489. if (row.getString("status").equals("审核")) {
  490. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证已审核,无法再次审核")
  491. .toString();
  492. }
  493. if (!row.getString("status").equals("新建")) {
  494. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证为非新建状态,无法审核")
  495. .toString();
  496. }
  497. }
  498. ArrayList<String> sqlList = new ArrayList<>();
  499. BigDecimal balance = BigDecimal.ZERO; //当前账户余额
  500. if (!rows.isEmpty()) {
  501. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  502. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  503. long type = rows.get(0).getLong("type");
  504. Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  505. if (type == 1) {
  506. Rows offsettingRows = dbConnect.runSqlQuery("select amount from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + rows.get(0).getLong("ownerid"));
  507. if (offsettingRows.isNotEmpty()) {
  508. sqlList.add("update sa_cashbill set writeoffamount=writeoffamount+" + offsettingRows.get(0).getBigDecimal("amount").abs() + " where siteid='" + siteid + "' and sa_cashbillid=" + rows.get(0).getLong("ownerid"));
  509. }
  510. if (rowsaccountbalance.isEmpty()) {
  511. balance = rows.get(0).getBigDecimal("amount");
  512. SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  513. sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  514. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  515. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  516. sqlFactory.addParameter("siteid", siteid);
  517. sqlFactory.addParameter("balance", rows.get(0).getBigDecimal("amount"));
  518. sqlFactory.addParameter("userid", userid);
  519. sqlFactory.addParameter("username", username);
  520. sqlList.add(sqlFactory.getSQL());
  521. } else {
  522. balance = rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  523. sqlList.add("update sa_accountbalance set balance='" + rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance")) + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  524. }
  525. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "收入凭证审核成功").getSQL());
  526. } else {
  527. if (rowsaccountbalance.isEmpty()) {
  528. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  529. // sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  530. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  531. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  532. // sqlFactory.addParameter("siteid", siteid);
  533. // sqlFactory.addParameter("balance", -rows.get(0).getLong("amount"));
  534. // sqlFactory.addParameter("userid", userid);
  535. // sqlFactory.addParameter("username", username);
  536. // sqlList.add(sqlFactory.getSQL());
  537. return getErrReturnObject().setErrMsg("该营销账户不存在,支出凭证无法审核")
  538. .toString();
  539. } else {
  540. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  541. if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1) {
  542. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,支出凭证无法审核")
  543. .toString();
  544. }
  545. BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(rows.get(0).getBigDecimal("amount"));
  546. balance = newbalance;
  547. sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  548. }
  549. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "支出凭证审核成功").getSQL());
  550. }
  551. }
  552. SQLFactory sqlFactoryupdate = new SQLFactory(this, "收支凭证审核");
  553. sqlFactoryupdate.addParameter("siteid", siteid);
  554. sqlFactoryupdate.addParameter("sa_cashbillid", sa_cashbillid);
  555. sqlFactoryupdate.addParameter("balance", balance);
  556. sqlFactoryupdate.addParameter("checkby", username);
  557. sqlList.add(sqlFactoryupdate.getSQL());
  558. dbConnect.runSqlUpdate(sqlList);
  559. return getSucReturnObject().toString();
  560. }
  561. @API(title = "删除", apiversion = R.ID20221009103203.v1.class)
  562. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  563. public String delete() throws YosException {
  564. JSONArray sa_cashbillids = content.getJSONArray("sa_cashbillids");
  565. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_cashbillids.size());
  566. for (Object o : sa_cashbillids) {
  567. long sa_cashbillid = Long.parseLong(o.toString());
  568. Rows RowsStatus = dbConnect.runSqlQuery("select sa_cashbillid,status from sa_cashbill where siteid='"
  569. + siteid + "' and sa_cashbillid='" + sa_cashbillid + "'");
  570. if (RowsStatus.isNotEmpty()) {
  571. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  572. batchDeleteErr.addErr(sa_cashbillid, "非新建状态的凭证无法删除");
  573. continue;
  574. }
  575. }
  576. ArrayList<String> list = new ArrayList<>();
  577. SQLFactory deletesql = new SQLFactory("sql:delete from sa_cashbill where siteid='" + siteid
  578. + "' and sa_cashbillid=" + sa_cashbillid);
  579. list.add(deletesql.getSQL());
  580. dbConnect.runSqlUpdate(list);
  581. }
  582. ClearData.clearCashbill(this);
  583. return batchDeleteErr.getReturnObject().toString();
  584. }
  585. @API(title = "审核状态的收支凭证详情列表", apiversion = R.ID20221022161304.v1.class)
  586. @CACHEING
  587. public String query_cashnill_audit() throws YosException {
  588. /*
  589. 过滤条件
  590. */
  591. StringBuffer where = new StringBuffer(" 1=1 ");
  592. Long sa_accountclassid = content.getLong("sa_accountclassid");
  593. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  594. if (content.containsKey("where")) {
  595. JSONObject whereObject = content.getJSONObject("where");
  596. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  597. where.append(" and (t1.billno like '%").append(whereObject.getString("condition")).append("%'");
  598. where.append(" or t3.enterprisename like '%").append(whereObject.getString("condition")).append("%'");
  599. where.append(" or t1.remarks like '%").append(whereObject.getString("condition")).append("%'");
  600. where.append(" or t1.source like '%").append(whereObject.getString("condition")).append("%')");
  601. }
  602. if (whereObject.containsKey("minAmount") && whereObject.getBigDecimal("minAmount").compareTo(new BigDecimal("0")) == 1) {
  603. BigDecimal minAmount = whereObject.getBigDecimal("minAmount");
  604. if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  605. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  606. where.append(" and t1.amount between ").append(minAmount).append(" and ").append(maxAmount);
  607. } else {
  608. where.append(" and t1.amount > ").append(minAmount);
  609. }
  610. } else if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  611. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  612. where.append(" and t1.amount < ").append(maxAmount);
  613. }
  614. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  615. where.append(" and t1.type = ").append(whereObject.getLong("type"));
  616. }
  617. }
  618. SQLFactory sqlFactory = new SQLFactory(this, "审核状态的收支凭证详情列表", pageSize, pageNumber, pageSorting);
  619. sqlFactory.addParameter_SQL("where", where);
  620. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  621. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  622. sqlFactory.addParameter("siteid", siteid);
  623. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  624. return getSucReturnObject().setData(rows).toString();
  625. }
  626. @API(title = "资金流水账列表查询", apiversion = R.ID20230111103403.v1.class)
  627. @CACHEING
  628. public String query_cashBill() throws YosException {
  629. /*
  630. 过滤条件
  631. */
  632. Long sa_accountclassid = content.getLong("sa_accountclassid");
  633. if (content.containsKey("sys_enterpriseid")) {
  634. sys_enterpriseid = content.getLong("sys_enterpriseid");
  635. }
  636. Map<String, Rows> map = new HashMap<String, Rows>();
  637. /**
  638. * 过滤条件设置
  639. */
  640. String where = " 1=1 ";
  641. if (content.containsKey("where")) {
  642. JSONObject whereObject = content.getJSONObject("where");
  643. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  644. where = where + " and (t1.billno like '%" + whereObject.getString("condition") + "%') ";
  645. }
  646. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  647. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') >=DATE_FORMAT('"+whereObject.getString("begindate")+"','%Y-%m-%d')";
  648. }
  649. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  650. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') <=DATE_FORMAT('"+whereObject.getString("enddate")+"','%Y-%m-%d')";
  651. }
  652. }
  653. /**
  654. * SQL资金流水账查询参数设置并查询
  655. */
  656. SQLFactory factory = new SQLFactory(this, "资金流水账查询", pageSize, pageNumber, pageSorting);
  657. factory.addParameter("sys_enterpriseid", sys_enterpriseid);
  658. factory.addParameter("sa_accountclassid", sa_accountclassid);
  659. factory.addParameter("siteid", siteid);
  660. factory.addParameter_SQL("where", where);
  661. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  662. /**
  663. * SQL资金流水账汇总信息查询参数设置并查询
  664. */
  665. SQLFactory factoryhz = new SQLFactory(this, "资金流水账查询汇总");
  666. factoryhz.addParameter("sys_enterpriseid", sys_enterpriseid);
  667. factoryhz.addParameter("sa_accountclassid", sa_accountclassid);
  668. factoryhz.addParameter("siteid", siteid);
  669. factoryhz.addParameter_SQL("where", where);
  670. Rows rowszh = dbConnect.runSqlQuery(factoryhz.getSQL());
  671. if(!rows.isEmpty()){
  672. rows.get(0).put("total",rowszh);
  673. }
  674. return getSucReturnObject().setData(rows).toString();
  675. }
  676. @API(title = "核销单关联查询", apiversion = R.ID20230224185904.v1.class)
  677. @CACHEING
  678. public String querywriteoffamount() throws YosException {
  679. Long sa_cashbillid = content.getLong("sa_cashbillid");
  680. SQLFactory sqlFactory = new SQLFactory(this, "核销单关联查询", pageSize, pageNumber, pageSorting);
  681. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  682. sqlFactory.addParameter("siteid", siteid);
  683. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  684. return getSucReturnObject().setData(rows).toString();
  685. }
  686. @API(title = "收入凭证对冲生成", apiversion = R.ID20230306102904.v1.class)
  687. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  688. public String cashbilloffsetting() throws YosException {
  689. Long sa_cashbillid = content.getLong("sa_cashbillid");
  690. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  691. sqlFactory.addParameter("siteid", siteid);
  692. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  693. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  694. if (rows.isEmpty()) {
  695. return getErrReturnObject().setErrMsg("无效收入凭证").toString();
  696. }
  697. if (rows.get(0).getLong("type") == 0) {
  698. return getErrReturnObject().setErrMsg("支出凭证不能生成对冲").toString();
  699. }
  700. if (!rows.get(0).getString("status").equals("审核")) {
  701. return getErrReturnObject().setErrMsg("非审核状态不能生成对冲").toString();
  702. }
  703. if (rows.get(0).getBigDecimal("unwriteoffamount").compareTo(new BigDecimal(0)) < 1) {
  704. return getErrReturnObject().setErrMsg("未核销金额必须大于0").toString();
  705. }
  706. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and sa_cashbillid=" + sa_cashbillid).isNotEmpty()) {
  707. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  708. }
  709. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + sa_cashbillid).isNotEmpty()) {
  710. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  711. }
  712. Long offsettingCashbillid = createTableID("sa_cashbill");
  713. sqlFactory = new SQLFactory(this, "收支凭证新增");
  714. sqlFactory.addParameter("siteid", siteid);
  715. sqlFactory.addParameter("userid", userid);
  716. sqlFactory.addParameter("username", username);
  717. sqlFactory.addParameter("sa_cashbillid", offsettingCashbillid);
  718. sqlFactory.addParameter("billno", createBillCode("cashbill"));
  719. sqlFactory.addParameter("sys_enterpriseid", rows.get(0).getLong("sys_enterpriseid"));
  720. sqlFactory.addParameter("sa_accountclassid", rows.get(0).getLong("sa_accountclassid"));
  721. sqlFactory.addParameter("type", rows.get(0).getLong("type"));
  722. sqlFactory.addParameter("remarks", "凭证对冲");
  723. sqlFactory.addParameter("amount", rows.get(0).getBigDecimal("unwriteoffamount").negate());
  724. sqlFactory.addParameter("source", rows.get(0).getString("amount"));
  725. sqlFactory.addParameter("sourcenote", rows.get(0).getString("sourcenote"));
  726. sqlFactory.addParameter("subclass", rows.get(0).getString("subclass"));
  727. sqlFactory.addParameter("class", rows.get(0).getString("class"));
  728. sqlFactory.addParameter("ownertable", "sa_cashbill");
  729. sqlFactory.addParameter("ownerid", sa_cashbillid);
  730. dbConnect.runSqlUpdate(sqlFactory.getSQL());
  731. content.put("sa_cashbillid", offsettingCashbillid);
  732. return queryCashbillMain();
  733. }
  734. public Object getCellFormatValue(Cell cell) {
  735. Object cellValue = null;
  736. if (cell != null) {
  737. // 判断cell类型
  738. CellType cellType = cell.getCellType();
  739. switch (cellType) {
  740. case NUMERIC: {
  741. if (DateUtil.isCellDateFormatted(cell)) {
  742. short num = cell.getCellStyle().getDataFormat();
  743. String format = "YYYY-mm-dd";
  744. SimpleDateFormat df = new SimpleDateFormat(format);
  745. cellValue = df.format(cell.getDateCellValue());
  746. } else {
  747. cell.setCellType(CellType.STRING); // 将数值型cell设置为string型
  748. cellValue = cell.getStringCellValue();
  749. }
  750. break;
  751. }
  752. case FORMULA: {
  753. // 判断cell是否为日期格式
  754. if (DateUtil.isCellDateFormatted(cell)) {
  755. // 转换为日期格式YYYY-mm-dd
  756. cellValue = cell.getDateCellValue();
  757. } else {
  758. // 数字
  759. cellValue = String.valueOf(cell.getNumericCellValue());
  760. }
  761. break;
  762. }
  763. case STRING: {
  764. cellValue = cell.getRichStringCellValue().getString();
  765. break;
  766. }
  767. default:
  768. cellValue = cell.getRichStringCellValue().getString();
  769. break;
  770. }
  771. } else {
  772. cellValue = "";
  773. }
  774. return cellValue;
  775. }
  776. public XSSFSheet addSheetIncome(ExcelFactory excelFactory, String sheetname, Rows datarows,
  777. HashMap<String, String> titlemap) {
  778. ArrayList<String> keylist = datarows.getFieldList();
  779. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  780. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  781. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  782. XSSFFont font = xssfFWorkbook.createFont();
  783. font.setColor((short) 0xa);
  784. font.setFontHeightInPoints((short) 12);
  785. font.setBold(true);
  786. xssfCellStyle1.setFont(font);
  787. IncomeExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  788. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  789. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  790. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  791. IncomeExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  792. for (int n = 0; n < datarows.size(); n++) {
  793. Row row = datarows.get(n);
  794. XSSFRow datarow = sheet.createRow(n + 3);
  795. for (int i1 = 0; i1 < keylist.size(); i1++) {
  796. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  797. if (fieldclazztype == Integer.class) {
  798. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)).intValue());
  799. } else if (fieldclazztype == Long.class) {
  800. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  801. } else if (fieldclazztype == Float.class) {
  802. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  803. } else if (fieldclazztype == Double.class) {
  804. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  805. } else {
  806. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  807. }
  808. if (i1 == 6) {
  809. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  810. }
  811. }
  812. }
  813. return sheet;
  814. }
  815. public XSSFSheet addSheetPay(ExcelFactory excelFactory, String sheetname, Rows datarows,
  816. HashMap<String, String> titlemap) {
  817. ArrayList<String> keylist = datarows.getFieldList();
  818. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  819. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  820. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  821. XSSFFont font = xssfFWorkbook.createFont();
  822. font.setColor((short) 0xa);
  823. font.setFontHeightInPoints((short) 12);
  824. font.setBold(true);
  825. xssfCellStyle1.setFont(font);
  826. PayExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  827. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  828. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  829. XSSFCellStyle titleCellStyle3 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  830. PayExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  831. for (int n = 0; n < datarows.size(); n++) {
  832. Row row = datarows.get(n);
  833. XSSFRow datarow = sheet.createRow(n + 3);
  834. for (int i1 = 0; i1 < keylist.size(); i1++) {
  835. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  836. if (fieldclazztype == Integer.class) {
  837. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)).intValue());
  838. } else if (fieldclazztype == Long.class) {
  839. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  840. } else if (fieldclazztype == Float.class) {
  841. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  842. } else if (fieldclazztype == Double.class) {
  843. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  844. } else {
  845. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  846. }
  847. if (i1 == 6) {
  848. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  849. }
  850. }
  851. }
  852. return sheet;
  853. }
  854. }