Commit 0388261e by kangxiaoshan

合同导出

parent 7dbba580
......@@ -60,6 +60,9 @@ public class ContractController {
putdata(this, ContractStatusEnum.MONEY_BACK_NONE);
putdata(this, ContractStatusEnum.MONEY_BACK_FIRST);
putdata(this, ContractStatusEnum.DELETE);
putdata(this, ContractStatusEnum.FIRST_SIGNING);
putdata(this, ContractStatusEnum.RENEWAL);
putdata(this, ContractStatusEnum.SUPPLEMENTARY_AGREEMENT);
}};
......@@ -92,45 +95,63 @@ public class ContractController {
@RequestMapping(value = "export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_EX)
public ResponseEntity<byte[]> export(@CurrentAccount User loginAccount, @PathVariable String platform, @RequestParam String startDate
public void export(@CurrentAccount User loginAccount, @PathVariable String platform, @RequestParam String startDate
, @RequestParam String endDate, HttpServletRequest request, HttpServletResponse response) {
List<Contract> contractList = service.findAll(loginAccount, startDate, endDate, platform, null);
byte[] content = new byte[0];
// byte[] content = new byte[0];
StringBuilder sb = new StringBuilder();
sb.append("时间,合同编号,客户账号,签约方,销售,开始日期,结束日期,套餐类型,合同金额,收款金额,合同状态\r\n");
//时间 合同编号 客户账号 我方签约主体 签约方 行业分类 销售 开始日期 结束日期 套餐类型 合同金额 签约类型 合同状态 关联合同
sb.append("录入时间,合同编号,客户账号,我方签约主体,签约方,行业分类,销售,开始日期,结束日期,套餐类型,合同金额,签约类型,合同状态,关联合同\r\n");
if (ValidateUtil.isValid(contractList)) {
for (Contract c : contractList) {
sb.append(c.getDs()).append(",").append(c.getContractCode()).append(",").append(c.getEmail()).append(",").append(c.getCustomerBody()).append(",").append(c.getSaleName()).append(",")
.append(c.getStartDate()).append(",").append(c.getEndDate()).append(",").append(c.getPriceLevelName()).append(",").append(c.getMoney()).append(",").append(c.getPayMoney()).append(",")
.append(CONTRACT_STATUS.get(c.getStatus())).append("\r\n");
sb.append(c.getDs()).append(",").
append(c.getContractCode()).append(",")
.append(c.getEmail()).append(",")
.append(c.getMyBodyName()).append(",")
.append(c.getCustomerBody()).append(",")
.append(c.getTradeName()).append(",")
.append(c.getSaleName()).append(",")
.append(c.getStartDate()).append(",")
.append(c.getEndDate()).append(",")
.append(c.getPriceLevelName()).append(",")
.append(c.getMoney()).append(",")
.append(c.getPayMoney()).append(",")
.append(CONTRACT_STATUS.get(c.getContractType())).append(",")
.append(CONTRACT_STATUS.get(c.getStatus())).append(",")
.append(c.getRelationCode()).append(",")
.append("\r\n");
}
}
InputStream in = new ByteArrayInputStream(sb.toString().getBytes());
try {
content = IOUtils.toByteArray(in);
} catch (IOException e) {
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
response.setHeader("filename", "contract.csv");
response.setHeader("content-disposition", "attachment; filename=contract.csv");
response.setHeader("Content-Type", "text/csv");
response.setContentType("APPLICATION/OCTET-STREAM");
String fileName = "合同管理(" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ").csv";
this.exportWrite(fileName, sb.toString(), "合同管理", response);
// InputStream in = new ByteArrayInputStream(sb.toString().getBytes());
// try {
// content = IOUtils.toByteArray(in);
// } catch (IOException e) {
// e.printStackTrace();
// }
// HttpHeaders headers = new HttpHeaders();
// response.setHeader("filename", "contract.csv");
// response.setHeader("content-disposition", "attachment; filename=contract.csv");
// response.setHeader("Content-Type", "text/csv");
// response.setContentType("APPLICATION/OCTET-STREAM");
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出合同", startDate, endDate, request, platform);
userlog.start();
//返回文件字符串
return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
// return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
}
@RequestMapping(value = "pay/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.COLLECTBILLLIST_EX)
public ResponseEntity<byte[]> exportPay(@CurrentAccount User loginAccount, @RequestParam String startDate, @RequestParam String endDate,
HttpServletRequest request, HttpServletResponse response, @PathVariable String platform,
String moneyType, String packageTypeSearch, String money_ids) {
public void exportPay(@CurrentAccount User loginAccount, @RequestParam String startDate, @RequestParam String endDate,
HttpServletRequest request, HttpServletResponse response, @PathVariable String platform,
String moneyType, String packageTypeSearch, String money_ids) {
List<ContractMoney> moneyList = service.findPayAll(loginAccount, startDate, endDate, platform, moneyType, packageTypeSearch, money_ids);
Map<String, String> map = new HashMap<>();
map.put("pay", "收款");
......@@ -168,23 +189,27 @@ public class ContractController {
titlebuffer.append("汇总, - , - , - , - , - , - ,").append(parseSum).append(" , - \r\n");
titlebuffer.append(sb);
InputStream in = new ByteArrayInputStream(titlebuffer.toString().getBytes());
try {
content = IOUtils.toByteArray(in);
} catch (IOException e) {
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
response.setHeader("filename", "contract_pay.csv");
response.setHeader("content-disposition", "attachment; filename=contract_pay.csv");
// response.setHeader("Content-Type", "application/octet-stream;charset=UTF-8");
response.setHeader("Content-Type", "text/csv");
response.setContentType("APPLICATION/OCTET-STREAM");
String fileName = "收款开票(" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ").csv";
this.exportWrite(fileName, sb.toString(), "收款开票", response);
// InputStream in = new ByteArrayInputStream(titlebuffer.toString().getBytes());
// try {
// content = IOUtils.toByteArray(in);
// } catch (IOException e) {
// e.printStackTrace();
// }
// HttpHeaders headers = new HttpHeaders();
// response.setHeader("filename", "contract_pay.csv");
// response.setHeader("content-disposition", "attachment; filename=contract_pay.csv");
// // response.setHeader("Content-Type", "application/octet-stream;charset=UTF-8");
// response.setHeader("Content-Type", "text/csv");
// response.setContentType("APPLICATION/OCTET-STREAM");
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.CUSTOMER.getKey(), platform, "导出收款开票", startDate, endDate, request, platform);
userlog.start();
//返回文件字符串
return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
// return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
}
@RequestMapping(value = "findone", method = RequestMethod.GET)
......@@ -463,10 +488,38 @@ public class ContractController {
}
}
OutputStream os = null;
String fileName = "分摊收入报表(" + new DateTime(startDate).toString("yyyyMMdd")
+ "_" + new DateTime(endDate).toString("yyyyMMdd") + ").csv";
this.exportWrite(fileName, sb.toString(), "分摊收入报表", response);
// OutputStream os = null;
// try {
// fileName = URLEncoder.encode(fileName, "UTF-8");
// response.setHeader("filename", fileName);
// response.setHeader("content-disposition", "attachment; filename=" + fileName);
// response.setHeader("Content-Type", "text/csv");
// response.setContentType("APPLICATION/OCTET-STREAM");
// response.setCharacterEncoding("UTF-8");
// os = response.getOutputStream();
// os.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
// os.write(sb.toString().getBytes("UTF-8"));
// os.flush();
// } catch (Exception e) {
// logger.error("导出分摊收入报错", e);
// } finally {
// if (os != null) {
// try {
// os.close();
// } catch (IOException e) {
// logger.error("导出分摊收入关闭流报错", e);
// }
// }
// }
}
private void exportWrite(String fileName, String text, String exportName, HttpServletResponse response) {
OutputStream os = null;
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setHeader("filename", fileName);
......@@ -474,18 +527,18 @@ public class ContractController {
response.setHeader("Content-Type", "text/csv");
response.setContentType("APPLICATION/OCTET-STREAM");
response.setCharacterEncoding("UTF-8");
os = response.getOutputStream();
os = response.getOutputStream();
os.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
os.write(sb.toString().getBytes("UTF-8"));
os.write(text.getBytes("UTF-8"));
os.flush();
} catch (Exception e) {
logger.error("导出分摊收入报错", e);
logger.error(exportName + "报错", e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error("导出分摊收入关闭流报错", e);
logger.error(exportName + "导出,关闭流报错", e);
}
}
......
......@@ -27,7 +27,6 @@ public interface ContractMoneyRepository extends JpaRepository<ContractMoney, Lo
// @Query(value = "select a.id,b.customer_body company,a.contract_code,u.name create_name,a.create_account,a.create_time,a.ds,a.email,a.modify_account,a.modify_time,a.money,a.platform,a.type,a.user,a.del_flag,b.sale salse,b.price_level from contract_money a left join contract b on a.contract_code = b.contract_code left join user u on a.create_account = u.id where a.ds >= ?1 and a.ds <= ?2 and a.platform = ?3 order by a.ds desc",nativeQuery = true)
// List<ContractMoney> findByDsAllContract(String startDate, String endDate, String platfrom);
// @Query(value = "select a.id,b.customer_body company,a.contract_code,u.name create_name,a.create_account,a.create_time,a.ds,a.email,a.modify_account,a.modify_time,a.money,a.platform,a.type,a.user,a.del_flag,b.sale salse,b.price_level from contract_money a left join contract b on a.contract_code = b.contract_code left join user u on a.create_account = u.id where a.ds >= ?1 and a.ds <= ?2 and a.platform = ?3 and a.type = ?4 and b.price_level = ?5 order by a.ds desc",nativeQuery = true)
// List<ContractMoney> findByDsAllContractAll(String startDate, String endDate, String platfrom, String moneyType, String packageTypeSearch);
//
......
......@@ -6,17 +6,21 @@ package dic;
*/
public enum ContractStatusEnum {
WAIT("wait","未执行"),
WAIT("wait", "未执行"),
EXECUTING("executing", "执行中"),
END("end", "已结束"),
MONEY_BACK_ALL("backall","已回款"),
MONEY_BACK_FIRST("backfirst","先回款待录入"),
MONEY_BACK_NONE("backnone","未回款"),
MONEY_BACK_PART("backpart","部分回款"),
MONEY_BACK_ALL("backall", "已回款"),
MONEY_BACK_FIRST("backfirst", "先回款待录入"),
MONEY_BACK_NONE("backnone", "未回款"),
MONEY_BACK_PART("backpart", "部分回款"),
CANCEL("cancel", "作废"),
DELETE("del", "已删除");
DELETE("del", "已删除"),
FIRST_SIGNING("0", "首次签约"),
RENEWAL("1", "续约"),
SUPPLEMENTARY_AGREEMENT("2", "补充协议"),
BLANK("", "");
private String key;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment