| @@ -1,10 +1,8 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxPropertyContract; | |||||
| import com.iformall.domain.vo.WxBillAll; | import com.iformall.domain.vo.WxBillAll; | ||||
| import com.iformall.service.WxBillAllService; | import com.iformall.service.WxBillAllService; | ||||
| import com.iformall.service.WxPropertyContractService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -15,6 +13,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -42,5 +42,12 @@ public class WxBillAllController extends BaseController | |||||
| Map<String, Object> result = wxBillAllService.listAsPage(wxBillAll, pageNum, pageSize); | Map<String, Object> result = wxBillAllService.listAsPage(wxBillAll, pageNum, pageSize); | ||||
| return new ResultData(result); | return new ResultData(result); | ||||
| } | } | ||||
| @GetMapping("exportBill") | |||||
| public void exportBill(@ModelAttribute WxBillAll wxBillAll,HttpServletRequest request, HttpServletResponse response){ | |||||
| wxBillAll.setTenantId(getTenantId()); | |||||
| wxBillAllService.exportBill(request,response,wxBillAll); | |||||
| } | |||||
| } | } | ||||
| @@ -3,6 +3,8 @@ package com.iformall.service; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.vo.WxBillAll; | import com.iformall.domain.vo.WxBillAll; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -19,4 +21,6 @@ public interface WxBillAllService { | |||||
| void updateBill(Map<String,Object> bill); | void updateBill(Map<String,Object> bill); | ||||
| void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll); | |||||
| } | } | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.service.impl; | package com.iformall.service.impl; | ||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| @@ -13,12 +14,24 @@ import com.iformall.enums.EnumBillTypeParam; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.Constant; | |||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import org.apache.commons.io.FileUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.poi.ss.usermodel.Cell; | |||||
| import org.apache.poi.ss.usermodel.Row; | |||||
| import org.apache.poi.xssf.usermodel.XSSFSheet; | |||||
| import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.*; | |||||
| import java.math.BigDecimal; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.*; | import java.util.*; | ||||
| /** | /** | ||||
| @@ -81,8 +94,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| //分页-页数、条数 | //分页-页数、条数 | ||||
| PageHelper.startPage(pageIndex, pageSize); | PageHelper.startPage(pageIndex, pageSize); | ||||
| //查询 | //查询 | ||||
| List<Map<String, Object>> rentContractData = wxBillAllMapper.list(record); | |||||
| PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(rentContractData); | |||||
| List<Map<String, Object>> billList = wxBillAllMapper.list(record); | |||||
| PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(billList); | |||||
| //返回值 | //返回值 | ||||
| Map<String, Object> result = new HashMap<>(); | Map<String, Object> result = new HashMap<>(); | ||||
| result.put("billInfo", billInfo); | result.put("billInfo", billInfo); | ||||
| @@ -189,6 +202,121 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| } | } | ||||
| } | } | ||||
| @Override | |||||
| public void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll) { | |||||
| //得到当前月 | |||||
| String month = DateUtils.getSystemTime("yyyy-MM"); | |||||
| //设置查询参数-当前月 | |||||
| wxBillAll.setMonth(month); | |||||
| //查询 | |||||
| List<Map<String, Object>> billList = wxBillAllMapper.list(wxBillAll); | |||||
| XSSFWorkbook workbook; | |||||
| String filepath = Constant.fileDirectory; | |||||
| File savefile = new File(filepath); | |||||
| if (!savefile.exists()) { | |||||
| savefile.mkdirs(); | |||||
| } | |||||
| String filename = UUID.randomUUID() + ".xlsx"; | |||||
| filepath = filepath + filename; | |||||
| try { | |||||
| File file = new File(filepath); | |||||
| workbook = new XSSFWorkbook(); | |||||
| XSSFSheet sheet = workbook.createSheet("账单"); | |||||
| Row row = sheet.createRow(0); | |||||
| Cell shopNumberCell = row.createCell(0); | |||||
| Cell merchantNameCell = row.createCell(1); | |||||
| Cell billNameCell = row.createCell(2); | |||||
| Cell needPayCell = row.createCell(3); | |||||
| Cell receivePayCell = row.createCell(4); | |||||
| Cell oweCell = row.createCell(5); | |||||
| Cell receiveDateCell = row.createCell(6); | |||||
| Cell expiredDayCell = row.createCell(7); | |||||
| Cell statusCell = row.createCell(8); | |||||
| shopNumberCell.setCellValue("商铺号"); | |||||
| merchantNameCell.setCellValue("商户名称"); | |||||
| billNameCell.setCellValue("费用类型"); | |||||
| needPayCell.setCellValue("实际应收金额(元)"); | |||||
| receivePayCell.setCellValue("实收金额(元)"); | |||||
| oweCell.setCellValue("欠缴金额(元)"); | |||||
| receiveDateCell.setCellValue("缴款截止日期"); | |||||
| expiredDayCell.setCellValue("过期时间"); | |||||
| statusCell.setCellValue("账单状态"); | |||||
| for (int i = 0,size=billList.size(); i < size; i++) { | |||||
| row = sheet.createRow(i + 1); | |||||
| shopNumberCell = row.createCell(0); | |||||
| merchantNameCell = row.createCell(1); | |||||
| billNameCell = row.createCell(2); | |||||
| needPayCell = row.createCell(3); | |||||
| receivePayCell = row.createCell(4); | |||||
| oweCell = row.createCell(5); | |||||
| receiveDateCell = row.createCell(6); | |||||
| expiredDayCell = row.createCell(7); | |||||
| statusCell = row.createCell(8); | |||||
| Map<String, Object> billMap = billList.get(i); | |||||
| logger.info(billMap.toString()); | |||||
| shopNumberCell.setCellValue(billMap.get("shopNumber").toString()); | |||||
| merchantNameCell.setCellValue(billMap.get("merchantName").toString()); | |||||
| billNameCell.setCellValue(billMap.get("name").toString()); | |||||
| BigDecimal needPay = new BigDecimal(billMap.get("needPay").toString()).divide(new BigDecimal(100)); | |||||
| needPayCell.setCellValue(needPay.toString()); | |||||
| BigDecimal receivePay = new BigDecimal(billMap.get("receivePay").toString()).divide(new BigDecimal(100)); | |||||
| receivePayCell.setCellValue(receivePay.toString()); | |||||
| BigDecimal owe = new BigDecimal(billMap.get("owe").toString()).divide(new BigDecimal(100)); | |||||
| oweCell.setCellValue(owe.toString()); | |||||
| String receiveDate = DateUtils.date2String((Date) billMap.get("receiveDate"), "yyyy-MM-dd"); | |||||
| receiveDateCell.setCellValue(receiveDate); | |||||
| expiredDayCell.setCellValue(billMap.get("expiredDay").toString()); | |||||
| statusCell.setCellValue(EnumBillDailyStatus.getEnum((Integer) billMap.get("status")).getMessage()); | |||||
| } | |||||
| FileOutputStream fileOut = new FileOutputStream(file); | |||||
| workbook.write(fileOut); | |||||
| fileOut.close(); | |||||
| workbook.close(); | |||||
| downFile(filepath, filename, response, request); | |||||
| FileUtils.forceDelete(file); | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| public void downFile(String filePath, String filename, HttpServletResponse response, | |||||
| HttpServletRequest req) throws IOException { | |||||
| try { | |||||
| response.reset(); | |||||
| response.setContentType("bin"); | |||||
| String agent = req.getHeader("user-agent"); | |||||
| if (agent.contains("Firefox")) { | |||||
| response.setHeader("Content-disposition", | |||||
| "attachment; filename=" | |||||
| + new String(filename.getBytes("GB2312"), | |||||
| "ISO-8859-1")); | |||||
| } else { | |||||
| response | |||||
| .setHeader("Content-disposition", | |||||
| "attachment; filename=" | |||||
| + java.net.URLEncoder.encode(filename, | |||||
| "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) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| private int updateBillOther(Map<String, Object> bill) { | private int updateBillOther(Map<String, Object> bill) { | ||||
| logger.info("updateBillOther params:"+bill.toString()); | logger.info("updateBillOther params:"+bill.toString()); | ||||
| Object id = bill.get("id"); | Object id = bill.get("id"); | ||||
| @@ -14,11 +14,11 @@ | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_property_deposit | select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_property_deposit | ||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type, '' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=1 | |||||
| select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=1 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=2 | |||||
| select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=2 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_other | |||||
| select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_other | |||||
| ) bill | ) bill | ||||
| left join wx_merchant m on bill.merchant_id=m.id | left join wx_merchant m on bill.merchant_id=m.id | ||||
| left join wx_shop s on bill.shop_id=s.id | left join wx_shop s on bill.shop_id=s.id | ||||
| @@ -46,11 +46,11 @@ | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_property_deposit | select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_property_deposit | ||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type, '' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=1 | |||||
| select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=1 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=2 | |||||
| select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=2 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_other | |||||
| select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_other | |||||
| ) bill | ) bill | ||||
| where bill.tenant_id=#{tenantId} and bill.status=#{status} | where bill.tenant_id=#{tenantId} and bill.status=#{status} | ||||
| <if test=" null != starttime and null!= endtime "> | <if test=" null != starttime and null!= endtime "> | ||||
| @@ -73,11 +73,11 @@ | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_property_deposit | select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_property_deposit | ||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type, '' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=1 | |||||
| select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=1 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=2 | |||||
| select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_daily where type=2 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_other | |||||
| select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status from wx_bill_other | |||||
| ) bill | ) bill | ||||
| where bill.tenant_id=#{tenantId} and bill.status=#{status} | where bill.tenant_id=#{tenantId} and bill.status=#{status} | ||||
| <if test=" null != starttime and null!= endtime "> | <if test=" null != starttime and null!= endtime "> | ||||
| @@ -103,11 +103,11 @@ | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime from wx_bill_property_deposit | select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime from wx_bill_property_deposit | ||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type, '' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=1 | |||||
| select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type, 0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=1 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=2 | |||||
| select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_daily where type=2 | |||||
| union | union | ||||
| select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,'' need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_other | |||||
| select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime from wx_bill_other | |||||
| ) bill | ) bill | ||||
| left join wx_merchant m on bill.merchant_id=m.id | left join wx_merchant m on bill.merchant_id=m.id | ||||
| left join wx_shop s on bill.shop_id=s.id | left join wx_shop s on bill.shop_id=s.id | ||||