|
|
@@ -6,9 +6,9 @@ import com.huyi.service.base.entity.*;
|
|
|
import com.huyi.service.base.service.*;
|
|
|
import com.huyi.service.financeRecord.service.FinanceRecordService;
|
|
|
import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
|
|
|
-import com.sun.xml.internal.bind.v2.TODO;
|
|
|
import com.tianhu.common.core.constant.SalaryConstants;
|
|
|
import com.tianhu.common.core.domain.R;
|
|
|
+import com.tianhu.common.core.utils.AmtUtil;
|
|
|
import com.tianhu.common.core.utils.CommonUtil;
|
|
|
import com.tianhu.common.core.utils.DateUtils;
|
|
|
import com.tianhu.common.core.utils.IdUtils;
|
|
|
@@ -21,17 +21,23 @@ import com.tianhu.common.security.service.TokenService;
|
|
|
import com.tianhu.system.api.domain.SysUser;
|
|
|
import com.tianhu.system.api.model.LoginUser;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cglib.beans.BeanMap;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -44,15 +50,12 @@ import java.util.Map;
|
|
|
@RestController
|
|
|
@RequestMapping("/financeRecord")
|
|
|
public class FinanceRecordController extends BaseController {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(FinanceRecordController.class);
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
@Autowired
|
|
|
private FinanceRecordService financeRecordService;
|
|
|
@Autowired
|
|
|
- private IZcFinanceInfService zcFinanceInfService;
|
|
|
- @Autowired
|
|
|
- private IZcFinanceProComRelService iZcFinanceProComRelService;
|
|
|
- @Autowired
|
|
|
private IZcFinanceProductService iZcFinanceProductService;
|
|
|
@Autowired
|
|
|
private IPayAccInfService iPayAccInfService;
|
|
|
@@ -62,12 +65,35 @@ public class FinanceRecordController extends BaseController {
|
|
|
private IZcBillInfService iZcBillInfService;
|
|
|
@Autowired
|
|
|
private IZcFinanceRecordService iZcFinanceRecordService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
+ //发票服务
|
|
|
+ @Autowired
|
|
|
+ private IZcInvoiceInfService invoiceInfService;
|
|
|
+ //文件服务类
|
|
|
+ @Autowired
|
|
|
+ private IPubFileInfService fileInfService;
|
|
|
+ //收付款和文件的关系表服务类
|
|
|
+ @Autowired
|
|
|
+ private IZcBillFileRelService billFileRelService;
|
|
|
+ //收付款与发票关系表
|
|
|
+ @Autowired
|
|
|
+ private IZcBillInvoiceRelService billInvoiceRelService;
|
|
|
+ @Autowired
|
|
|
+ private IZcChargeInfService iZcChargeInfService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserCompanyRelService iSysUserCompanyRelService;
|
|
|
+ @Autowired
|
|
|
+ private IZcFinanceInfService iZcFinanceInfService;
|
|
|
/**
|
|
|
* 查询融资管理列表
|
|
|
*/
|
|
|
@PreAuthorize(hasPermi = "finance:record:list")
|
|
|
@GetMapping("/list")
|
|
|
- public R list(@RequestParam (required = false) String zfrStatus, QueryRequest request) {
|
|
|
+ public R list(@RequestParam (required = false) String zfrTypes,
|
|
|
+ @RequestParam (required = false) String zfrQuery,
|
|
|
+ @RequestParam (required = false) String zfrValue,
|
|
|
+ @RequestParam (required = false) String zfrStatus,QueryRequest request) {
|
|
|
//查询当前操作员
|
|
|
LoginUser userInfo = tokenService.getLoginUser();
|
|
|
SysUser use = userInfo.getSysUser();
|
|
|
@@ -78,11 +104,50 @@ public class FinanceRecordController extends BaseController {
|
|
|
map.put("companyId", companyId);
|
|
|
}
|
|
|
map.put("zfrStatus",zfrStatus);
|
|
|
+ //00:我签收的 01:我开立的
|
|
|
+ if ("00".equals(zfrTypes)){
|
|
|
+ map.put("zfiSupplierId",zfrTypes);
|
|
|
+ }else if ("01".equals(zfrTypes)){
|
|
|
+ map.put("zfiCoreId",zfrTypes);
|
|
|
+ }
|
|
|
+ //00:按开立企业名称查询 01:按接收方企业名称查询 02:按授信额度查询 03:按融资利率查询
|
|
|
+ if ("00".equals(zfrQuery)) {
|
|
|
+ map.put("coreScyName", zfrValue);
|
|
|
+ }else if ("01".equals(zfrQuery)){
|
|
|
+ map.put("supplierScyName", zfrValue);
|
|
|
+ }else if ("02".equals(zfrQuery)){
|
|
|
+ map.put("zfpcrAmount", zfrValue);
|
|
|
+ }else if ("03".equals(zfrQuery)){
|
|
|
+ map.put("zfrRate", zfrValue);
|
|
|
+ }
|
|
|
IPage<Map> list = financeRecordService.selectFinanceRecordList(map, request);
|
|
|
return R.ok(list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 融资管理信息详情
|
|
|
+ * @param zfrId 融资id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "credit:line:query")
|
|
|
+ @GetMapping(value = "/{zfrId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("zfrId") String zfrId)
|
|
|
+ {
|
|
|
+ ZcFinanceRecord zcFinanceRecord = iZcFinanceRecordService.getById(zfrId);
|
|
|
+ Map map = new HashMap();
|
|
|
+ if (zcFinanceRecord != null) {
|
|
|
+ com.huyi.service.base.entity.SysUser user = iSysUserService.getById(zcFinanceRecord.getCreateBy());
|
|
|
+ BeanMap beanMap = BeanMap.create(zcFinanceRecord);
|
|
|
+ for (Object key : beanMap.keySet()) {
|
|
|
+ map.put(key + "", beanMap.get(key));
|
|
|
+ }
|
|
|
+ //创建人
|
|
|
+ map.put("createUser", user.getNickName());
|
|
|
+ }
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 新增融资管理
|
|
|
* @param map
|
|
|
* @return
|
|
|
@@ -98,6 +163,21 @@ public class FinanceRecordController extends BaseController {
|
|
|
LoginUser userInfo = tokenService.getLoginUser();
|
|
|
SysUser user = userInfo.getSysUser();
|
|
|
String userId = user.getUserId() + "";
|
|
|
+ String companyId = user.getCompanyId();
|
|
|
+ //查询当前用户是否是经办人
|
|
|
+ LambdaQueryWrapper<SysUserCompanyRel> companyRelWrapper = new LambdaQueryWrapper<>();
|
|
|
+ companyRelWrapper.eq(SysUserCompanyRel::getSucrUserId,userId);
|
|
|
+ companyRelWrapper.eq(SysUserCompanyRel::getSucrCompanyId,companyId);
|
|
|
+ List<SysUserCompanyRel> list = iSysUserCompanyRelService.findSysUserCompanyRels(companyRelWrapper);
|
|
|
+ if (list.size() > 0){
|
|
|
+ //是否经办人 0:不是, 1:是
|
|
|
+ String handler = list.get(0).getSucrHandler();
|
|
|
+ if (!"1".equals(handler)){
|
|
|
+ throw new Exception("此操作需经办人权限,请确认您是否是经办人");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new Exception("此操作需经办人权限,请确认您是否是经办人");
|
|
|
+ }
|
|
|
//融信id
|
|
|
String zfrFinanceId = CommonUtil.objToString(map.get("zfrFinanceId"));
|
|
|
//融资金额
|
|
|
@@ -106,6 +186,7 @@ public class FinanceRecordController extends BaseController {
|
|
|
String zfrCollectionAccount = CommonUtil.objToString(map.get("zfrCollectionAccount"));
|
|
|
//融资利率
|
|
|
String zfrRate = CommonUtil.objToString(map.get("zfrRate"));
|
|
|
+ String zfpcrChargeRate = CommonUtil.objToString(map.get("zfpcrChargeRate"));
|
|
|
//融资放款方式(0:平台电子记账簿 1:供应商指定账户 2:供应商线下面签)
|
|
|
String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
|
|
|
//融资产品
|
|
|
@@ -154,7 +235,7 @@ public class FinanceRecordController extends BaseController {
|
|
|
zfrCollectionAccount = accInfList.get(0).getPaiAccno();
|
|
|
}
|
|
|
}
|
|
|
- //执行新增
|
|
|
+ /*---------------新增融资表----------*/
|
|
|
ZcFinanceRecord zcFinanceRecord = new ZcFinanceRecord();
|
|
|
//主键
|
|
|
String zfrId = IdUtils.fastSimpleUUID();
|
|
|
@@ -184,11 +265,104 @@ public class FinanceRecordController extends BaseController {
|
|
|
zcFinanceRecord.setCreateBy(userId);
|
|
|
//创建时间
|
|
|
zcFinanceRecord.setCreateTime(createTime);
|
|
|
+ /*-------------新增费用表--------*/
|
|
|
+ ZcChargeInf zcChargeInf = new ZcChargeInf();
|
|
|
+ //主键
|
|
|
+ zcChargeInf.setZciId(IdUtils.fastSimpleUUID());
|
|
|
+ //融资id
|
|
|
+ zcChargeInf.setZciFinanceId(zfrId);
|
|
|
+ //手续费
|
|
|
+ String zciAmount = AmtUtil.divide(zfpcrChargeRate,"100",4);
|
|
|
+ zciAmount = AmtUtil.subtract(zfrAmount,zciAmount,2);
|
|
|
+ zcChargeInf.setZciAmount(zciAmount);
|
|
|
+ //创建人
|
|
|
+ zcChargeInf.setCreateBy(userId);
|
|
|
+ //创建时间
|
|
|
+ zcChargeInf.setCreateTime(DateUtils.getNowDate());
|
|
|
+ /*----------修改融信表状态---------------*/
|
|
|
+ ZcFinanceInf zcFinanceInf = new ZcFinanceInf();
|
|
|
+ //融信id
|
|
|
+ zcFinanceInf.setZfiId(zfrFinanceId);
|
|
|
+ //融信状态(00:待确权 01:待签收 02:已生效 03:已失效 04:融资中 05:已融资 06:平台退回)
|
|
|
+ zcFinanceInf.setZfiStatus("04");
|
|
|
+ //修改人
|
|
|
+ zcFinanceInf.setUpdateBy(userId);
|
|
|
+ //修改时间
|
|
|
+ zcFinanceInf.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ iZcFinanceInfService.updateZcFinanceInf(zcFinanceInf);
|
|
|
+ iZcChargeInfService.createZcChargeInf(zcChargeInf);
|
|
|
iZcFinanceRecordService.createZcFinanceRecord(zcFinanceRecord);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 放款登记
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "finance:record:edit")
|
|
|
+ @Log(title = "融资管理", businessType = BusinessType.UPDATE)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult update(@RequestBody Map<String,Object> map)throws Exception
|
|
|
+ {
|
|
|
+ //主键
|
|
|
+ String zfrId = CommonUtil.objToString(map.get("zfrId"));
|
|
|
+ //获取此操作员
|
|
|
+ LoginUser userInfo = tokenService.getLoginUser();
|
|
|
+ SysUser user = userInfo.getSysUser();
|
|
|
+ String userId = user.getUserId() + "";
|
|
|
+ //放款金额
|
|
|
+ String zfrLoanAmount = CommonUtil.objToString(map.get("zfrLoanAmount"));
|
|
|
+ //融资金额
|
|
|
+ String zfrAmount = CommonUtil.objToString(map.get("zfrAmount"));
|
|
|
+ //融信id
|
|
|
+ String zfrFinanceId = CommonUtil.objToString(map.get("zfrFinanceId"));
|
|
|
+ //授信额度
|
|
|
+ if(CommonUtil.isNotEmpty(zfrLoanAmount)) {
|
|
|
+ if(AmtUtil.isMoney(zfrLoanAmount) == false) {
|
|
|
+ throw new Exception("请输入正确的放款金额");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new Exception("放款金额不能为空");
|
|
|
+ }
|
|
|
+ int count = CommonUtil.compare(zfrLoanAmount,zfrAmount);
|
|
|
+ if (count == 1){
|
|
|
+ throw new Exception("实际放款金额不能大于融资金额");
|
|
|
+ }
|
|
|
+ //图片
|
|
|
+ String zfrLoanFile = "";
|
|
|
+ List<Map<String, String>> url = (List<Map<String, String>>) map.get("zfrLoanFile");
|
|
|
+ if (url.size() > 0){
|
|
|
+ zfrLoanFile = String.valueOf(url.get(0).get("uid"));
|
|
|
+ }
|
|
|
+ //-----------------执行修改融资表
|
|
|
+ ZcFinanceRecord zcFinanceRecord = new ZcFinanceRecord();
|
|
|
+ //主键
|
|
|
+ zcFinanceRecord.setZfrId(zfrId);
|
|
|
+ //放款金额
|
|
|
+ zcFinanceRecord.setZfrLoanAmount(zfrLoanAmount);
|
|
|
+ //附件
|
|
|
+ zcFinanceRecord.setZfrLoanFile(zfrLoanFile);
|
|
|
+ //融资状态(00:融资中 01:已放款 02:融资失败 03:已结算)
|
|
|
+ zcFinanceRecord.setZfrStatus("01");
|
|
|
+ /*----------修改融信表状态---------------*/
|
|
|
+ ZcFinanceInf zcFinanceInf = new ZcFinanceInf();
|
|
|
+ //融信id
|
|
|
+ zcFinanceInf.setZfiId(zfrFinanceId);
|
|
|
+ //融信状态(00:待确权 01:待签收 02:已生效 03:已失效 04:融资中 05:已融资 06:平台退回)
|
|
|
+ zcFinanceInf.setZfiStatus("05");
|
|
|
+ //修改人
|
|
|
+ zcFinanceInf.setUpdateBy(userId);
|
|
|
+ //修改时间
|
|
|
+ zcFinanceInf.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ iZcFinanceInfService.updateZcFinanceInf(zcFinanceInf);
|
|
|
+ iZcFinanceRecordService.updateZcFinanceRecord(zcFinanceRecord);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询往来账款
|
|
|
* @param zfiId 融信id
|
|
|
* @return
|
|
|
@@ -216,5 +390,314 @@ public class FinanceRecordController extends BaseController {
|
|
|
return AjaxResult.success(list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出附件
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PreAuthorize(hasPermi = "finance:record:export")
|
|
|
+ @Log(title = "融资管理", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/export/{zfrFinanceId}")
|
|
|
+ public AjaxResult export(HttpServletResponse response,@PathVariable String zfrFinanceId ) throws Exception {
|
|
|
+ List<Map<String, String>> list = new ArrayList<>();
|
|
|
+ //查询往来账款
|
|
|
+ LambdaQueryWrapper<ZcFinanceBillRel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(ZcFinanceBillRel::getZfbrFinanceId,zfrFinanceId);
|
|
|
+ List<ZcFinanceBillRel> billRelList = iZcFinanceBillRelService.findZcFinanceBillRels(queryWrapper);
|
|
|
+ List<String> billIdList = new ArrayList<>();
|
|
|
+ //查询往来账款
|
|
|
+ if (billRelList.size() > 0){
|
|
|
+ //提取所有的
|
|
|
+ billIdList = CommonUtil.getIdFromList(billRelList,"zfbrBillId");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<ZcBillInf> billInfWrapper = new LambdaQueryWrapper<>();
|
|
|
+ billInfWrapper.in(ZcBillInf::getZbiId,billIdList);
|
|
|
+ List<ZcBillInf> billInfList = iZcBillInfService.findZcBillInfs(billInfWrapper);
|
|
|
+ //发票文件
|
|
|
+ List<PubFileInf> invoiceFileList = new ArrayList<>();
|
|
|
+ //收付款的合同类型的文件
|
|
|
+ List<PubFileInf> contractFileList = new ArrayList<>();
|
|
|
+ //收付款的其他文件
|
|
|
+ List<PubFileInf> otherFileList = new ArrayList<>();
|
|
|
+ //提取收付款编号
|
|
|
+ List<String> zbiIdList = CommonUtil.getIdFromList(billInfList,"zbiId");
|
|
|
+ //发票与收付款相关
|
|
|
+ LambdaQueryWrapper<ZcBillInvoiceRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.in(ZcBillInvoiceRel::getZbirBillId,zbiIdList);
|
|
|
+ List<ZcBillInvoiceRel> relList = billInvoiceRelService.findZcBillInvoiceRels(lambdaQueryWrapper);
|
|
|
+ //有关联的发票
|
|
|
+ if(relList.size() > 0 ){
|
|
|
+ List<String> invoiceIdList = CommonUtil.getIdFromList(relList,"zbirInvoiceId");
|
|
|
+ //查询发票
|
|
|
+ LambdaQueryWrapper<ZcInvoiceInf> invoiceInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ invoiceInfLambdaQueryWrapper.in(ZcInvoiceInf::getZiiId,invoiceIdList);
|
|
|
+ invoiceInfLambdaQueryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
|
|
|
+ List<ZcInvoiceInf> invoiceInfList = invoiceInfService.findZcInvoiceInfs(invoiceInfLambdaQueryWrapper);
|
|
|
+ //发票信息不为空
|
|
|
+ if(invoiceInfList.size() > 0){
|
|
|
+ //提取出文件信息
|
|
|
+ List<String> fileIdList = CommonUtil.getIdFromList(invoiceInfList,"ziiFile");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,fileIdList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ //查询文件
|
|
|
+ invoiceFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询文件关系表
|
|
|
+ LambdaQueryWrapper<ZcBillFileRel> billFileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ billFileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
|
|
|
+ billFileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"0");
|
|
|
+ List<ZcBillFileRel> billFileRelList = billFileRelService.findZcBillFileRels(billFileRelLambdaQueryWrapper);
|
|
|
+ //不为空
|
|
|
+ if(billFileRelList.size() > 0){
|
|
|
+ //提取文件编号
|
|
|
+ List<String> idList = CommonUtil.getIdFromList(billFileRelList,"zbfrFileId");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ contractFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
+ //查询文件关系表
|
|
|
+ LambdaQueryWrapper<ZcBillFileRel> fileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
|
|
|
+ fileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"2");
|
|
|
+ List<ZcBillFileRel> relFileList = billFileRelService.findZcBillFileRels(fileRelLambdaQueryWrapper);
|
|
|
+ //不为空
|
|
|
+ if(relFileList.size() > 0){
|
|
|
+ //提取文件编号
|
|
|
+ List<String> idList = CommonUtil.getIdFromList(relFileList,"zbfrFileId");
|
|
|
+ LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
|
|
|
+ fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
|
|
|
+ otherFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
|
|
|
+ }
|
|
|
+ String directory = "E:\\home\\" ;
|
|
|
+// String directory = configService.selectConfigByKey("hr_resume_export");
|
|
|
+
|
|
|
+ for (int i = 0; i < otherFileList.size(); i++) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ //文件路径
|
|
|
+ String pfiFileUrl = otherFileList.get(i).getPfiFileUrl();
|
|
|
+ //文件名称
|
|
|
+ String pfiFileName = otherFileList.get(i).getPfiFileName();
|
|
|
+ map.put("pfiFileUrl",pfiFileUrl);
|
|
|
+ map.put("pfiFileName",pfiFileName);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ for (int j = 0; j < contractFileList.size(); j++) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ //文件路径
|
|
|
+ String pfiFileUrl = contractFileList.get(j).getPfiFileUrl();
|
|
|
+ //文件名称
|
|
|
+ String pfiFileName = contractFileList.get(j).getPfiFileName();
|
|
|
+ map.put("pfiFileUrl",pfiFileUrl);
|
|
|
+ map.put("pfiFileName",pfiFileName);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ for (int k = 0; k < invoiceFileList.size(); k++) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ //文件路径
|
|
|
+ String pfiFileUrl = invoiceFileList.get(k).getPfiFileUrl();
|
|
|
+ //文件名称
|
|
|
+ String pfiFileName = invoiceFileList.get(k).getPfiFileName();
|
|
|
+ map.put("pfiFileUrl",pfiFileUrl);
|
|
|
+ map.put("pfiFileName",pfiFileName);
|
|
|
+ list.add(map);
|
|
|
+
|
|
|
+ }
|
|
|
+ for (int l = 0; l < list.size(); l++) {
|
|
|
+ String files = list.get(l).get("pfiFileUrl");
|
|
|
+ String names = list.get(l).get("pfiFileName");
|
|
|
+ downloadFile(files, directory+ names);
|
|
|
+ }
|
|
|
+ /** 压缩方法 */
|
|
|
+ FileOutputStream fos1= new FileOutputStream(new File("E:/" + "rzgl"+DateUtils.dateTimeNow()+ ".zip"));
|
|
|
+ toZip("E:\\home",fos1 ,true);
|
|
|
+ File zipFile = new File("E:/" + "rzgl"+DateUtils.dateTimeNow()+ ".zip");
|
|
|
+ if(zipFile.exists()) {
|
|
|
+ down(response, "rzgl" + DateUtils.dateTimeNow() + ".zip", "E:/");
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void down(HttpServletResponse response, String fileName, String path) {
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
+ byte[] buff = new byte[1024];
|
|
|
+ //创建缓冲输入流
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+
|
|
|
+ //这个路径为待下载文件的路径
|
|
|
+ bis = new BufferedInputStream(new FileInputStream(new File(path + fileName )));
|
|
|
+ int read = bis.read(buff);
|
|
|
+
|
|
|
+ //通过while循环写入到指定了的文件夹中
|
|
|
+ while (read != -1) {
|
|
|
+ outputStream.write(buff, 0, buff.length);
|
|
|
+ outputStream.flush();
|
|
|
+ read = bis.read(buff);
|
|
|
+ }
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 下载失败
|
|
|
+ } finally {
|
|
|
+ if (bis != null) {
|
|
|
+ try {
|
|
|
+ bis.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载远程文件并保存到本地
|
|
|
+ * @param remoteFilePath 远程文件路径
|
|
|
+ * @param localFilePath 本地文件路径(带文件名)
|
|
|
+ */
|
|
|
+ public static String downloadFile(String remoteFilePath, String localFilePath)
|
|
|
+ {
|
|
|
+ URL urlfile = null;
|
|
|
+ HttpURLConnection httpUrl = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
+
|
|
|
+ File path = new File("E:\\home\\");
|
|
|
+ //判断文件是否存在
|
|
|
+ if(!path.exists()){
|
|
|
+ path.mkdirs();
|
|
|
+ }
|
|
|
+ File f = new File( localFilePath );
|
|
|
+ try
|
|
|
+ {
|
|
|
+ urlfile = new URL(remoteFilePath);
|
|
|
+ httpUrl = (HttpURLConnection)urlfile.openConnection();
|
|
|
+ httpUrl.connect();
|
|
|
+ bis = new BufferedInputStream(httpUrl.getInputStream());
|
|
|
+ bos = new BufferedOutputStream(new FileOutputStream(f));
|
|
|
+ int len = 2048;
|
|
|
+ byte[] b = new byte[len];
|
|
|
+ while ((len = bis.read(b)) != -1)
|
|
|
+ {
|
|
|
+ bos.write(b, 0, len);
|
|
|
+ }
|
|
|
+ bos.flush();
|
|
|
+ bis.close();
|
|
|
+ httpUrl.disconnect();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bis.close();
|
|
|
+ bos.close();
|
|
|
+ }
|
|
|
+ catch (IOException e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return f.getAbsolutePath();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 压缩成ZIP 方法 * @param srcDir 压缩文件夹路径
|
|
|
+ * @param out 压缩文件输出流
|
|
|
+ * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
|
|
|
+ * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
|
|
|
+ * @throws RuntimeException 压缩失败会抛出运行时异常
|
|
|
+ */
|
|
|
+ public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure) throws RuntimeException{
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ ZipOutputStream zos = null ;
|
|
|
+ try {
|
|
|
+ zos = new ZipOutputStream(out);
|
|
|
+ File sourceFile = new File(srcDir);
|
|
|
+ compress(sourceFile,zos,sourceFile.getName(),KeepDirStructure);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println("压缩完成,耗时:" + (end - start) +" ms");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("zip error from ZipUtils",e);
|
|
|
+ }finally{
|
|
|
+ if(zos != null){
|
|
|
+ try {
|
|
|
+ zos.flush();
|
|
|
+ zos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 递归压缩方法
|
|
|
+ * @param sourceFile 源文件
|
|
|
+ * @param zos zip输出流
|
|
|
+ * @param name 压缩后的名称
|
|
|
+ * @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
|
|
|
+ * false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private static void compress(File sourceFile, ZipOutputStream zos, String name,
|
|
|
+ boolean KeepDirStructure) throws Exception{
|
|
|
+ byte[] buf = new byte[2 * 1024];
|
|
|
+ if(sourceFile.isFile()){
|
|
|
+ // 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
|
|
|
+ zos.putNextEntry(new ZipEntry(name));
|
|
|
+ // copy文件到zip输出流中
|
|
|
+ int len;
|
|
|
+ FileInputStream in = new FileInputStream(sourceFile);
|
|
|
+ while ((len = in.read(buf)) != -1){
|
|
|
+ zos.write(buf, 0, len);
|
|
|
+ }
|
|
|
+ // Complete the entry
|
|
|
+ zos.closeEntry();
|
|
|
+ in.close();
|
|
|
+ } else {
|
|
|
+ //是文件夹
|
|
|
+ File[] listFiles = sourceFile.listFiles();
|
|
|
+ if(listFiles == null || listFiles.length == 0){
|
|
|
+ // 需要保留原来的文件结构时,需要对空文件夹进行处理
|
|
|
+ if(KeepDirStructure){
|
|
|
+ // 空文件夹的处理
|
|
|
+ zos.putNextEntry(new ZipEntry(name + "/"));
|
|
|
+ // 没有文件,不需要文件的copy
|
|
|
+ zos.closeEntry();
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ for (File file : listFiles) {
|
|
|
+ // 判断是否需要保留原来的文件结构
|
|
|
+ if (KeepDirStructure) {
|
|
|
+ // 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
|
|
|
+ // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
|
|
|
+ compress(file, zos, name + "/" + file.getName(),KeepDirStructure);
|
|
|
+ } else {
|
|
|
+ compress(file, zos, file.getName(),KeepDirStructure);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|