Просмотр исходного кода

[商店账单][修改][生成催缴单]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
0d8e87ec9e
9 измененных файлов: 457 добавлений и 200 удалений
  1. +1
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/WxBillAllVo.java
  2. +134
    -6
      mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java
  3. +21
    -191
      mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java
  4. +48
    -3
      mallinkService/src/main/java/com/iformall/utils/DownFileUtil.java
  5. +154
    -0
      mallinkService/src/main/java/com/iformall/utils/PriceUtil.java
  6. +87
    -0
      mallinkService/src/main/java/com/iformall/utils/WordUtil.java
  7. Двоичные данные
      mallinkService/src/main/resources/contract-word-template/bill_owe.docx
  8. Двоичные данные
      mallinkService/src/main/resources/contract-word-template/owe_bill.docx
  9. +12
    -0
      mallinkService/src/main/resources/mapper/WxBillAllMapper.xml

+ 1
- 0
mallinkService/src/main/java/com/iformall/domain/vo/WxBillAllVo.java Просмотреть файл

@@ -63,6 +63,7 @@ public class WxBillAllVo {

private String shopInfo;

private String name;

public String getReceivePayStr() {
if(getReceivePay()!=null) {


+ 134
- 6
mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java Просмотреть файл

@@ -7,15 +7,15 @@ import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.po.msg.MailMsg;
import com.iformall.domain.vo.OweMerchantVo;
import com.iformall.domain.vo.WaitMerchantVo;
import com.iformall.domain.vo.WxBillAll;
import com.iformall.domain.vo.WxBillAllVo;
import com.iformall.domain.vo.*;
import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;
import com.iformall.mq.MqBaseProducer;
import com.iformall.service.*;
import com.iformall.utils.DateUtils;
import com.iformall.utils.PriceUtil;
import com.iformall.utils.WordUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
@@ -98,6 +98,15 @@ public class WxBillAllServiceImpl implements WxBillAllService {
@Autowired
WxMallMapper wxMallMapper;

@Autowired
WxMerchantMapper wxMerchantMapper;

@Autowired
private String fmUploadDir;

@Autowired
private WxPayAccountBillMapper wxPayAccountBillMapper;

@Override
public Map<String, Object> listAsPage(WxBillAll record, Integer pageIndex, Integer pageSize) {
//更新各账单状态
@@ -587,8 +596,127 @@ public class WxBillAllServiceImpl implements WxBillAllService {
public void exportOweBill(WxBillAll wxBillAll, HttpServletRequest request, HttpServletResponse response) {
//商场名称
WxMall wxMall = wxMallMapper.getByTenantId(wxBillAll.getTenantId());
//账单总数
List<Map<String, Object>> data = wxBillAllMapper.getOweBillAsPage(wxBillAll);
//映射结果
Map<String, Object> result = new HashMap<>();
result.put("mall", wxMall.getName());

//付款方式
WxPayAccountBill wxPayAccountBill = new WxPayAccountBill();
wxPayAccountBill.setTenantId(wxBillAll.getTenantId());
wxPayAccountBill = wxPayAccountBillMapper.selectOne(wxPayAccountBill);
if (wxPayAccountBill == null) {
result.put("accountNumber", wxPayAccountBill.getBankCardId());
result.put("accountName", wxPayAccountBill.getBankAccountName());
} else {
result.put("accountNumber", " ");
result.put("accountName", " ");
}

//账单时间段
result.put("starttime", wxBillAll.getStarttime());
result.put("endtime", wxBillAll.getEndtime().substring(0, 10));

//编号
String number = "JF" + DateUtils.getSystemTime("yyyyMMddHHmmss");
result.put("number", number);
//数据
List<WxBillAllVo> list = wxBillAllMapper.list(wxBillAll);
if (!list.isEmpty()) {
//租金总额
Long rentSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.RENT.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//物业总额
Long propertySum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.PROPERTY.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//押金总额
Long depositSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.RENT_DEPOSIT.getCode()) ||
b.getBillTypeValue().equals(EnumBillTypeParam.PROPERTY_DEPOSIT.getCode()) || b.getBillTypeValue().equals(EnumBillTypeParam.ATHER_DEPOSIT.getCode()))
.collect(Collectors.summingLong(b -> b.getOwe()));
//水费
Long waterSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.WATER.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//电费
Long powerSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.POWER.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//空调费
Long airConditioningSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.AIR_CONDITIONING.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//其他费用
Long otherSum = list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.ROUTINE.getCode())).collect(Collectors.summingLong(b -> b.getOwe()));
//押金明细
StringBuffer depositDetail = new StringBuffer();
list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.RENT_DEPOSIT.getCode()) ||
b.getBillTypeValue().equals(EnumBillTypeParam.PROPERTY_DEPOSIT.getCode()) || b.getBillTypeValue().equals(EnumBillTypeParam.ATHER_DEPOSIT.getCode()))
.forEach(b -> {
BigDecimal owe = new BigDecimal(b.getOwe()).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
depositDetail.append(b.getName()).append(":[").append(owe.toPlainString()).append("] ");
});

//其他费用明细
StringBuffer otherDetail = new StringBuffer();
list.parallelStream().filter(b -> b.getBillTypeValue().equals(EnumBillTypeParam.ROUTINE.getCode()))
.forEach(b -> {
BigDecimal owe = new BigDecimal(b.getOwe()).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
otherDetail.append(b.getName()).append(":[").append(owe.toPlainString()).append("] ");
});
//总计
Long summarySum = rentSum + propertySum + depositSum + waterSum + powerSum + airConditioningSum + otherSum;
BigDecimal rent = new BigDecimal(rentSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal property = new BigDecimal(propertySum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal deposit = new BigDecimal(depositSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal water = new BigDecimal(waterSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal power = new BigDecimal(powerSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal airConditioning = new BigDecimal(airConditioningSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal other = new BigDecimal(otherSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
BigDecimal summary = new BigDecimal(summarySum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
String summaryUpper = PriceUtil.number2CNMontrayUnit(summary);

result.put("rent", rent.toPlainString());
result.put("property", property.toPlainString());
result.put("deposit", deposit.toPlainString());
result.put("water", water.toPlainString());
result.put("power", power.toPlainString());
result.put("airConditioning", airConditioning.toPlainString());
result.put("other", other.toPlainString());
result.put("summary", summary.toPlainString());
result.put("summaryUpper", summaryUpper);

result.put("depositDetail", StringUtils.isNotEmpty(depositDetail.toString()) ? depositDetail.toString() : " ");
result.put("otherDetail", StringUtils.isNotEmpty(otherDetail.toString()) ? otherDetail.toString() : " ");

WxMerchantVo wxMerchantVo = new WxMerchantVo();
wxMerchantVo.setId(wxBillAll.getMerchantId());
List<WxMerchantVo> listCVo = wxMerchantMapper.findListCVo(wxMerchantVo);
wxMerchantVo = listCVo.get(0);
result.put("merchant", wxMerchantVo.getMerchantName());
WxShopVo wxShopVo = wxMerchantVo.getShopVoList().parallelStream().filter(s -> StringUtils.isNotEmpty(s.getLinkPhone())).findAny().orElse(null);
if (wxShopVo != null) {
result.put("linkPerson", wxShopVo.getLinkPerson());
result.put("linkPhone", wxShopVo.getLinkPhone());
} else {
result.put("linkPerson", " ");
result.put("linkPhone", " ");
}

} else {
result.put("merchant", " ");
result.put("rent", " ");
result.put("property", " ");
result.put("deposit", " ");
result.put("water", " ");
result.put("power", " ");
result.put("airConditioning", " ");
result.put("other", " ");
result.put("summary", " ");
result.put("summaryUpper", " ");

result.put("depositDetail", " ");
result.put("otherDetail", " ");
}

String createtime = DateUtils.getSystemTime("yyyy-MM-dd");
result.put("createtime", createtime);

String templatePath = "contract-word-template/bill_owe.docx";
String filepath = fmUploadDir;
String filename = UUID.randomUUID() + ".docx";
String exportFileName = "催缴单.docx";
WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response);

}



+ 21
- 191
mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java Просмотреть файл

@@ -1,6 +1,5 @@
package com.iformall.service.impl;

import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
@@ -14,14 +13,12 @@ import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;
import com.iformall.service.*;
import com.iformall.utils.Constant;
import com.iformall.utils.DataUtil;
import com.iformall.utils.DateUtils;
import me.chanjar.weixin.common.util.DataUtils;
import com.iformall.utils.DownFileUtil;
import com.iformall.utils.PriceUtil;
import com.iformall.utils.WordUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.shiro.SecurityUtils;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
@@ -31,19 +28,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.*;

/**
@@ -1172,8 +1166,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
try {
String exportFileName = wxRentContract.getFilename();
downLoadFromUrl(wxRentContract.getFilepath(), filename, filepath);
downFile(destPath, wxRentContract.getFilename(), exportFileName, response, request);
DownFileUtil.downLoadFromUrl(wxRentContract.getFilepath(), filename, filepath);
DownFileUtil.downFile(destPath, exportFileName, response, request);
org.apache.commons.io.FileUtils.forceDelete(dest);
} catch (IOException e) {
logger.info("创建本地文件失败" + e.getMessage());
@@ -1325,74 +1319,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
}

public static void downLoadFromUrl(String urlStr, String fileName, String savePath) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);

//文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
File file = new File(saveDir + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if (fos != null) {
fos.close();
}
if (inputStream != null) {
inputStream.close();
}


System.out.println("info:" + url + " download success");

}

public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}

public void downFile(String filePath, String filename, String exportFileName, HttpServletResponse response,
HttpServletRequest req) {
try {
response.reset();
response.setContentType("bin");
String agent = req.getHeader("user-agent");
if (agent.contains("Firefox")) {
response.setHeader("Content-disposition", "attachment; filename=" + new String(exportFileName.getBytes("GB2312"), "ISO-8859-1"));
} else {
response.setHeader("Content-disposition", "attachment; filename=" + java.net.URLEncoder.encode(exportFileName, "UTF-8"));
}
// 循环取出流中的数据
byte[] b = new byte[1024];
int len;
InputStream inStream = new FileInputStream(filePath);
while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (Exception e) {
logger.info("下载合同失败" + e.getMessage());
e.printStackTrace();
}
}

@Override
public void exportContract(HttpServletRequest request, HttpServletResponse response, String tenantId, Long id) {
String contracType = "0";
@@ -1417,7 +1343,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
String filepath = fmUploadDir;
String filename = UUID.randomUUID() + ".docx";
String exportFileName = result.get("merchantName").toString() + "合同.docx";
exportWord(templatePath, filepath, filename, exportFileName, result, request, response);
WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response);
}

@Override
@@ -1617,15 +1543,15 @@ public class WxRentContractServiceImpl implements WxRentContractService {
.divide(new BigDecimal(100))
.setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("unitPriceRent", unitPrice);
result.put("priceRentUpper", digitUppercase(priceRent));
result.put("unitPriceRentUpper", digitUppercase(unitPrice));
result.put("priceRentUpper", PriceUtil.digitUppercase(priceRent));
result.put("unitPriceRentUpper", PriceUtil.digitUppercase(unitPrice));
//租赁保证金
int cashDepositMonthRent = 3;
double cashDepositRent = new BigDecimal(wxRentContract.getPrice()).multiply(new BigDecimal(cashDepositMonthRent))
.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("cashDepositMonthRent", cashDepositMonthRent);
result.put("cashDepositRent", cashDepositRent);
result.put("cashDepositRentUpper", digitUppercase(cashDepositRent));
result.put("cashDepositRentUpper", PriceUtil.digitUppercase(cashDepositRent));
result.put("type", wxRentContract.getType());
int extralease = lease % 12;
int extracount = extralease > 0 ? 1 : 0;
@@ -1638,10 +1564,10 @@ public class WxRentContractServiceImpl implements WxRentContractService {
double revenue = new BigDecimal(wxRentContract.getRevenue())
.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("revenue", revenue);
result.put("revenueUpper", digitUppercase(revenue));
result.put("revenueUpper", PriceUtil.digitUppercase(revenue));
} else {
result.put("revenue", 0);
result.put("revenueUpper", digitUppercase(0));
result.put("revenueUpper", PriceUtil.digitUppercase(0));
}
if (!wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) {
areaWay(wxRentContract, result, lease, extralease, extracount, paycount, index, count, rentPrice);
@@ -1672,8 +1598,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
.divide(new BigDecimal(wxRentContract.getRentArea()), 2, RoundingMode.HALF_EVEN)
.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("unitPriceProperty", unitPriceProperty);
result.put("pricePropertyUpper", digitUppercase(priceProperty));
result.put("unitPricePropertyUpper", digitUppercase(unitPriceProperty));
result.put("pricePropertyUpper", PriceUtil.digitUppercase(priceProperty));
result.put("unitPricePropertyUpper", PriceUtil.digitUppercase(unitPriceProperty));
//首期物业费
Calendar instance = Calendar.getInstance();
instance.setTime(wxRentContract.getRentalStartDate());
@@ -1699,7 +1625,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
.multiply(new BigDecimal(receivePeriodProperty))
.setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("pricePropertyFirst", pricePropertyFirst);
result.put("pricePropertyFirstUpper", digitUppercase(pricePropertyFirst));
result.put("pricePropertyFirstUpper", PriceUtil.digitUppercase(pricePropertyFirst));


//物业保证金
@@ -1708,7 +1634,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
.divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
result.put("cashDepositMonthProperty", cashDepositMonthProperty);
result.put("cashDepositProperty", cashDepositProperty);
result.put("cashDepositPropertyUpper", digitUppercase(cashDepositProperty));
result.put("cashDepositPropertyUpper", PriceUtil.digitUppercase(cashDepositProperty));


} else {
@@ -1887,13 +1813,13 @@ public class WxRentContractServiceImpl implements WxRentContractService {

if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) {
rentPrice = new BigDecimal(priceArrs[i]).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
result.put("priceRentUpper" + i, digitUppercase(rentPrice.doubleValue()));
result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue()));
result.put("priceRent" + i, rentPrice.doubleValue());
result.put("adjustRatio" + i, adjustRatioList.get(i));
} else {
rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(i)))
.add(rentPrice).setScale(2, RoundingMode.HALF_EVEN);
result.put("priceRentUpper" + i, digitUppercase(rentPrice.doubleValue()));
result.put("priceRentUpper" + i, PriceUtil.digitUppercase(rentPrice.doubleValue()));
result.put("priceRent" + i, rentPrice.doubleValue());
result.put("adjustRatio" + i, adjustRatioList.get(i));
}
@@ -1926,12 +1852,12 @@ public class WxRentContractServiceImpl implements WxRentContractService {

if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) {
rentPrice = new BigDecimal(priceArrs[count]).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN);
result.put("priceRentUpper" + count, digitUppercase(rentPrice.doubleValue()));
result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue()));
result.put("priceRent" + count, rentPrice.doubleValue());
} else {
rentPrice = rentPrice.multiply(new BigDecimal(adjustRatioList.get(count)))
.add(rentPrice).setScale(2, RoundingMode.HALF_EVEN);
result.put("priceRentUpper" + count, digitUppercase(rentPrice.doubleValue()));
result.put("priceRentUpper" + count, PriceUtil.digitUppercase(rentPrice.doubleValue()));
result.put("priceRent" + count, rentPrice.doubleValue());
}

@@ -1954,102 +1880,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
}

/**
* 导出word
* <p>第一步生成替换后的word文件,只支持docx</p>
* <p>第二步下载生成的文件</p>
* <p>第三步删除生成的临时文件</p>
* 模版变量中变量格式:{{foo}}
*
* @param templatePath word模板地址
* @param temDir 生成临时文件存放地址
* @param fileName 文件名
* @param params 替换的参数
* @param request HttpServletRequest
* @param response HttpServletResponse
*/
public void exportWord(String templatePath, String temDir, String fileName, String exportFileName, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
Assert.notNull(templatePath, "模板路径不能为空");
Assert.notNull(temDir, "临时文件路径不能为空");
Assert.notNull(exportFileName, "导出文件名不能为空");
Assert.isTrue(exportFileName.endsWith(".docx"), "word导出请使用docx格式");
if (!temDir.endsWith("/")) {
temDir = temDir + File.separator;
}
File dir = new File(temDir);
if (!dir.exists()) {
dir.mkdirs();
}
try {
// String userAgent = request.getHeader("user-agent").toLowerCase();
// if (userAgent.contains("msie") || userAgent.contains("like gecko")) {
// exportFileName = URLEncoder.encode(exportFileName, "UTF-8");
// } else {
// exportFileName = new String(exportFileName.getBytes("utf-8"), "ISO-8859-1");
// }


XWPFDocument doc = WordExportUtil.exportWord07(templatePath, params);
String tmpPath = temDir + fileName;
FileOutputStream fos = new FileOutputStream(tmpPath);
doc.write(fos);
// 设置强制下载不打开
response.setContentType("application/force-download");
// 设置文件名
response.addHeader("Content-Disposition", "attachment;fileName=" + exportFileName);
String userAgent = request.getHeader("user-agent");
if (userAgent.contains("Firefox")) {
response.setHeader("Content-disposition",
"attachment; filename="
+ new String(exportFileName.getBytes("GB2312"),
"ISO-8859-1"));
} else {
response
.setHeader("Content-disposition",
"attachment; filename="
+ java.net.URLEncoder.encode(exportFileName,
"UTF-8"));
}
OutputStream out = response.getOutputStream();
doc.write(out);
out.close();
FileUtils.forceDelete(new File(tmpPath));
} catch (Exception e) {
e.printStackTrace();
}

}

/**
* 数字金额大写转换,思想先写个完整的然后将如零拾替换成零 要用到正则表达式
*/
public static String digitUppercase(double n) {
String fraction[] = {"角", "分"};
String digit[] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
String unit[][] = {{"圆", "万", "亿"}, {"", "拾", "佰", "仟"}};

String head = n < 0 ? "负" : "";
n = Math.abs(n);

String s = "";
for (int i = 0; i < fraction.length; i++) {
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
}
if (s.length() < 1) {
s = "整";
}
int integerPart = (int) Math.floor(n);

for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
String p = "";
for (int j = 0; j < unit[1].length && n > 0; j++) {
p = digit[integerPart % 10] + unit[1][j] + p;
integerPart = integerPart / 10;
}
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
}
return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
}

@Override
public void updateApplyStatus(WxRentContract wxRentContract) {


+ 48
- 3
mallinkService/src/main/java/com/iformall/utils/DownFileUtil.java Просмотреть файл

@@ -2,9 +2,9 @@ package com.iformall.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
* @author luozukai
@@ -37,4 +37,49 @@ public class DownFileUtil {
response.getOutputStream().write(b, 0, len);
inStream.close();
}

public static void downLoadFromUrl(String urlStr, String fileName, String savePath) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);

//文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
File file = new File(saveDir + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if (fos != null) {
fos.close();
}
if (inputStream != null) {
inputStream.close();
}


System.out.println("info:" + url + " download success");

}

public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}

}

+ 154
- 0
mallinkService/src/main/java/com/iformall/utils/PriceUtil.java Просмотреть файл

@@ -0,0 +1,154 @@
package com.iformall.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

public class PriceUtil {

private static final Logger logger = LoggerFactory.getLogger(PriceUtil.class);

/**
* 数字金额大写转换,思想先写个完整的然后将如零拾替换成零 要用到正则表达式
*/
public static String digitUppercase(double n) {
String fraction[] = {"角", "分"};
String digit[] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
String unit[][] = {{"圆", "万", "亿"}, {"", "拾", "佰", "仟"}};

String head = n < 0 ? "负" : "";
n = Math.abs(n);

String s = "";
for (int i = 0; i < fraction.length; i++) {
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
}
if (s.length() < 1) {
s = "整";
}
int integerPart = (int) Math.floor(n);

for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
String p = "";
for (int j = 0; j < unit[1].length && n > 0; j++) {
p = digit[integerPart % 10] + unit[1][j] + p;
integerPart = integerPart / 10;
}
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
}
return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
}


/**
* 汉语中数字大写
*/
private static final String[] CN_UPPER_NUMBER = {"零", "壹", "贰", "叁", "肆",
"伍", "陆", "柒", "捌", "玖"};
/**
* 汉语中货币单位大写,这样的设计类似于占位符
*/
private static final String[] CN_UPPER_MONETRAY_UNIT = {"分", "角", "元",
"拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾",
"佰", "仟"};
/**
* 特殊字符:整
*/
private static final String CN_FULL = "整";
/**
* 特殊字符:负
*/
private static final String CN_NEGATIVE = "负";
/**
* 金额的精度,默认值为2
*/
private static final int MONEY_PRECISION = 2;
/**
* 特殊字符:零元整
*/
private static final String CN_ZEOR_FULL = "零元" + CN_FULL;

/**
* 把输入的金额转换为汉语中人民币的大写
*
* @param numberOfMoney 输入的金额
* @return 对应的汉语大写
*/
public static String number2CNMontrayUnit(BigDecimal numberOfMoney) {
StringBuffer sb = new StringBuffer();
// -1, 0, or 1 as the value of this BigDecimal is negative, zero, or
// positive.
int signum = numberOfMoney.signum();
// 零元整的情况
if (signum == 0) {
return CN_ZEOR_FULL;
}
//这里会进行金额的四舍五入
long number = numberOfMoney.movePointRight(MONEY_PRECISION)
.setScale(0, 4).abs().longValue();
// 得到小数点后两位值
long scale = number % 100;
int numUnit = 0;
int numIndex = 0;
boolean getZero = false;
// 判断最后两位数,一共有四中情况:00 = 0, 01 = 1, 10, 11
if (!(scale > 0)) {
numIndex = 2;
number = number / 100;
getZero = true;
}
if ((scale > 0) && (!(scale % 10 > 0))) {
numIndex = 1;
number = number / 10;
getZero = true;
}
int zeroSize = 0;
while (true) {
if (number <= 0) {
break;
}
// 每次获取到最后一个数
numUnit = (int) (number % 10);
if (numUnit > 0) {
if ((numIndex == 9) && (zeroSize >= 3)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[6]);
}
if ((numIndex == 13) && (zeroSize >= 3)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[10]);
}
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
sb.insert(0, CN_UPPER_NUMBER[numUnit]);
getZero = false;
zeroSize = 0;
} else {
++zeroSize;
if (!(getZero)) {
sb.insert(0, CN_UPPER_NUMBER[numUnit]);
}
if (numIndex == 2) {
if (number > 0) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
}
} else if (((numIndex - 2) % 4 == 0) && (number % 1000 > 0)) {
sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
}
getZero = true;
}
// 让number每次都去掉最后一个数
number = number / 10;
++numIndex;
}
// 如果signum == -1,则说明输入的数字为负数,就在最前面追加特殊字符:负
if (signum == -1) {
sb.insert(0, CN_NEGATIVE);
}
// 输入的数字小数点后两位为"00"的情况,则要在最后追加特殊字符:整
if (!(scale > 0)) {
sb.append(CN_FULL);
}
return sb.toString();
}


}

+ 87
- 0
mallinkService/src/main/java/com/iformall/utils/WordUtil.java Просмотреть файл

@@ -0,0 +1,87 @@
package com.iformall.utils;

import cn.afterturn.easypoi.word.WordExportUtil;
import org.apache.commons.io.FileUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Map;

public class WordUtil {

private static final Logger logger = LoggerFactory.getLogger(WordUtil.class);

/**
* 导出word
* <p>第一步生成替换后的word文件,只支持docx</p>
* <p>第二步下载生成的文件</p>
* <p>第三步删除生成的临时文件</p>
* 模版变量中变量格式:{{foo}}
*
* @param templatePath word模板地址
* @param temDir 生成临时文件存放地址
* @param fileName 文件名
* @param params 替换的参数
* @param request HttpServletRequest
* @param response HttpServletResponse
*/
public static void exportWord(String templatePath, String temDir, String fileName, String exportFileName, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
Assert.notNull(templatePath, "模板路径不能为空");
Assert.notNull(temDir, "临时文件路径不能为空");
Assert.notNull(exportFileName, "导出文件名不能为空");
Assert.isTrue(exportFileName.endsWith(".docx"), "word导出请使用docx格式");
if (!temDir.endsWith("/")) {
temDir = temDir + File.separator;
}
File dir = new File(temDir);
if (!dir.exists()) {
dir.mkdirs();
}
try {
// String userAgent = request.getHeader("user-agent").toLowerCase();
// if (userAgent.contains("msie") || userAgent.contains("like gecko")) {
// exportFileName = URLEncoder.encode(exportFileName, "UTF-8");
// } else {
// exportFileName = new String(exportFileName.getBytes("utf-8"), "ISO-8859-1");
// }


XWPFDocument doc = WordExportUtil.exportWord07(templatePath, params);
String tmpPath = temDir + fileName;
FileOutputStream fos = new FileOutputStream(tmpPath);
doc.write(fos);
// 设置强制下载不打开
response.setContentType("application/force-download");
// 设置文件名
response.addHeader("Content-Disposition", "attachment;fileName=" + exportFileName);
String userAgent = request.getHeader("user-agent");
if (userAgent.contains("Firefox")) {
response.setHeader("Content-disposition",
"attachment; filename="
+ new String(exportFileName.getBytes("GB2312"),
"ISO-8859-1"));
} else {
response
.setHeader("Content-disposition",
"attachment; filename="
+ java.net.URLEncoder.encode(exportFileName,
"UTF-8"));
}
OutputStream out = response.getOutputStream();
doc.write(out);
out.close();
FileUtils.forceDelete(new File(tmpPath));
} catch (Exception e) {
e.printStackTrace();
}

}

}

Двоичные данные
mallinkService/src/main/resources/contract-word-template/bill_owe.docx Просмотреть файл


Двоичные данные
mallinkService/src/main/resources/contract-word-template/owe_bill.docx Просмотреть файл


+ 12
- 0
mallinkService/src/main/resources/mapper/WxBillAllMapper.xml Просмотреть файл

@@ -32,6 +32,9 @@
<result column="managerPhone" jdbcType="VARCHAR" property="managerPhone"/>
<result column="shopInfo" jdbcType="VARCHAR" property="shopInfo"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
</resultMap>


@@ -103,6 +106,15 @@
<if test=" null != starttime and null!= endtime ">
and bill.receive_date between #{starttime} and #{endtime}
</if>
<if test=" null != merchantId and ''!=merchantId">
and bill.merchant_id=#{merchantId}
</if>
<if test=" null != statusList ">
and bill.`status` in
<foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
#{status}
</foreach>
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
<if test=" null == sortColumns"> order by bill.id desc,bill.merchant_id,bill.status,bill.receive_date desc </if>



Загрузка…
Отмена
Сохранить