支出合同导入接口
This commit is contained in:
+2
@@ -30,6 +30,7 @@ import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecgframework.poi.excel.def.MapExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
|
||||
@@ -496,6 +497,7 @@ public class PayIncomeContractController extends JeroController<PayIncomeContrac
|
||||
filedsList.add(new ExcelExportEntity("已收金额", "amountReceived"));
|
||||
filedsList.add(new ExcelExportEntity("未收金额", "outstandingAmount"));
|
||||
filedsList.add(new ExcelExportEntity("账款状态", "accountStatus"));
|
||||
filedsList.add(new ExcelExportEntity("合同约定付款次数", "contractPaymentTimes"));
|
||||
filedsList.add(new ExcelExportEntity("是否打包", "pack"));
|
||||
filedsList.add(new ExcelExportEntity("打包年份", "packYear"));
|
||||
int count = mapCount.get("count");
|
||||
|
||||
+251
-4
@@ -1,14 +1,19 @@
|
||||
package com.jero.contract.controller;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -22,8 +27,6 @@ import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.company.entity.PayCompanyManagement;
|
||||
import com.jero.contract.common.PayIncomeContractCommon;
|
||||
import com.jero.contract.entity.*;
|
||||
import com.jero.contract.service.IPaySpendingContractInstallmentService;
|
||||
import com.jero.contract.service.IPaySpendingContractService;
|
||||
@@ -31,13 +34,18 @@ import com.jero.contract.vo.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.jeecgframework.poi.excel.def.MapExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
|
||||
import org.jeecgframework.poi.excel.view.JeecgMapExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -323,8 +331,247 @@ public class PaySpendingContractController extends JeroController<PaySpendingCon
|
||||
*/
|
||||
@PostMapping(value = "/importExcel")
|
||||
@ApiOperation(value="支出合同-通过excel导入数据", notes="支出合同-通过excel导入数据")
|
||||
@Transactional
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, PaySpendingContract.class);
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
List<Map<Integer, String>> list = read(file);
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
List<String> listSpendingContract = Arrays.asList("合同编号","合同名称","签订单位名称","签订单位联系人","是否开口","负责人",
|
||||
"部门名称","签订合同总金额","税率","未税金额","合同签订日期","合同终止日期","合同约定主要时点",
|
||||
"应收金额","已收金额","未收金额","账款状态","合同约定付款次数","是否打包","打包年份");
|
||||
List<String> listSpendingContractInstallment = Arrays.asList("阶段","期应收","期应收时间","期实收","期实收时间");
|
||||
// 校验表头
|
||||
Map<Integer, String> map = list.get(1);
|
||||
if(!Objects.isNull(map)){
|
||||
int count = map.size();
|
||||
// 合同信息字段为20个,分期信息为5个
|
||||
if(count < 20){
|
||||
throw new JeroBootException("excel表头错误!");
|
||||
}else {
|
||||
listSpendingContract.forEach(p->{
|
||||
if(!Objects.equals(map.get(listSpendingContract.indexOf(p)),p)){
|
||||
throw new JeroBootException("excel表头错误!");
|
||||
}
|
||||
});
|
||||
int count1 = count - 20;
|
||||
if(count1 != 0){
|
||||
Pattern p = Pattern.compile("[0-9]*");
|
||||
Matcher m = p.matcher(String.valueOf(count1 / 5));
|
||||
if (!m.matches()){
|
||||
throw new JeroBootException("excel表头错误!");
|
||||
}
|
||||
int count2 = count1/5;
|
||||
for (int i = 1; i <= count2; i++) {
|
||||
int finalI = i;
|
||||
listSpendingContractInstallment.forEach(item->{
|
||||
int n = listSpendingContractInstallment.indexOf(item) + 1;
|
||||
if(Objects.equals((n + 1) + item,map.get(20 + finalI * n))){
|
||||
throw new JeroBootException("excel表头错误!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, String> mapOpening = sysBaseAPI.queryDictItemsMapByCode("yn");
|
||||
Map<String, String> mapAccountStatus = sysBaseAPI.queryDictItemsMapByCode("revenue_contract_account_status");
|
||||
Map<String, String> mapPack = sysBaseAPI.queryDictItemsMapByCode("yn");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
list.forEach(sub->{
|
||||
int count = sub.size();
|
||||
int n = list.indexOf(sub);
|
||||
if(n < 2){
|
||||
return;
|
||||
}
|
||||
|
||||
if(count < 20){
|
||||
sb.append("第").append(n + 1).append("行,excel数据错误!");
|
||||
}else {
|
||||
PaySpendingContract paySpendingContract = setPaySpendingContract(sub,mapOpening,mapAccountStatus,mapPack,n,sb);
|
||||
paySpendingContractService.save(paySpendingContract);
|
||||
int count1 = count - 20;
|
||||
if(count > 0){
|
||||
Pattern p = Pattern.compile("[0-9]*");
|
||||
Matcher m = p.matcher(String.valueOf(count1 / 5));
|
||||
if (!m.matches()){
|
||||
throw new JeroBootException("excel数据错误!");
|
||||
}
|
||||
int count2 = count1/5;
|
||||
List<PaySpendingContractInstallment> listPaySpendingContractInstallment = new ArrayList<>();
|
||||
for (int i = 0; i < count2; i++) {
|
||||
PaySpendingContractInstallment paySpendingContractInstallment = new PaySpendingContractInstallment();
|
||||
paySpendingContractInstallment.setContractId(paySpendingContract.getId());
|
||||
paySpendingContractInstallment.setPhaseName(sub.get(20 + (i * 5) + 0));
|
||||
paySpendingContractInstallment.setAccountsReceivableAmount(Integer.parseInt(sub.get(20 + (i * 5) + 1)));
|
||||
paySpendingContractInstallment.setAccountsReceivableTime(DateUtils.str2Date(sub.get(20 + (i * 5) + 2),new SimpleDateFormat("yyyy-MM-dd")));
|
||||
paySpendingContractInstallment.setPaidAmount(Integer.parseInt(sub.get(20 + (i * 5) + 3)));
|
||||
paySpendingContractInstallment.setPaidTime(DateUtils.str2Date(sub.get(20 + (i * 5) + 4),new SimpleDateFormat("yyyy-MM-dd")));
|
||||
listPaySpendingContractInstallment.add(paySpendingContractInstallment);
|
||||
}
|
||||
paySpendingContractInstallmentService.saveBatch(listPaySpendingContractInstallment);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return Result.OK("文件导入成功!");
|
||||
}
|
||||
|
||||
private PaySpendingContract setPaySpendingContract(Map<Integer,String> map,Map<String, String> mapOpening,
|
||||
Map<String, String> mapAccountStatus,Map<String, String> mapPack,
|
||||
int n,StringBuilder sb){
|
||||
PaySpendingContract paySpendingContract = new PaySpendingContract();
|
||||
paySpendingContract.setContractNum(map.get(0));
|
||||
paySpendingContract.setContractName(map.get(1));
|
||||
paySpendingContract.setSignedCompanyTemporaryName(map.get(2));
|
||||
paySpendingContract.setSignedContactsTemporaryName(map.get(3));
|
||||
AtomicBoolean opening = new AtomicBoolean(false);
|
||||
mapOpening.forEach((k,v)->{
|
||||
if(Objects.equals(map.get(4),v)){
|
||||
opening.set(true);
|
||||
paySpendingContract.setOpening(Integer.parseInt(k));
|
||||
}
|
||||
});
|
||||
if(!opening.get()){
|
||||
sb.append("第").append(n + 1).append("行,是否开口错误!");
|
||||
}
|
||||
paySpendingContract.setPrincipalName(map.get(5));
|
||||
paySpendingContract.setDepartmentName(map.get(6));
|
||||
paySpendingContract.setContractAmount(map.get(7));
|
||||
paySpendingContract.setRate(map.get(8));
|
||||
paySpendingContract.setNoTaxAmount(map.get(9));
|
||||
paySpendingContract.setContractDate(DateUtils.str2Date(map.get(10),new SimpleDateFormat("yyyy-MM-dd")));
|
||||
paySpendingContract.setTerminationDate(DateUtils.str2Date(map.get(10),new SimpleDateFormat("yyyy-MM-dd")));
|
||||
paySpendingContract.setContractTimePoints(map.get(12));
|
||||
paySpendingContract.setAccountsReceivableAmount(map.get(13));
|
||||
paySpendingContract.setAmountReceived(map.get(14));
|
||||
paySpendingContract.setOutstandingAmount(map.get(15));
|
||||
AtomicBoolean accountStatus = new AtomicBoolean(false);
|
||||
mapAccountStatus.forEach((k,v)->{
|
||||
if(Objects.equals(map.get(16),v)){
|
||||
accountStatus.set(true);
|
||||
paySpendingContract.setAccountStatus(Integer.parseInt(k));
|
||||
}
|
||||
});
|
||||
if(!accountStatus.get()){
|
||||
sb.append("第").append(n + 1).append("行,账款状态错误!");
|
||||
}
|
||||
paySpendingContract.setContractPaymentTimes(map.get(17));
|
||||
AtomicBoolean pack = new AtomicBoolean(false);
|
||||
mapPack.forEach((k,v)->{
|
||||
if(Objects.equals(map.get(18),v)){
|
||||
pack.set(true);
|
||||
paySpendingContract.setPack(Integer.parseInt(k));
|
||||
}
|
||||
});
|
||||
if(!pack.get()){
|
||||
sb.append("第").append(n + 1).append("行,是否打包错误!");
|
||||
}
|
||||
paySpendingContract.setPackYear(map.get(19));
|
||||
return paySpendingContract;
|
||||
}
|
||||
|
||||
/** 导入excel表格,返回的List<Map<Integer, String>>数据结构.
|
||||
* @param
|
||||
* @return 返回list集合
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<Map<Integer, String>> read(MultipartFile file) {
|
||||
//最终返回数据
|
||||
List<Map<Integer, String>> list = new ArrayList<>();
|
||||
try{
|
||||
Workbook workbook = null;
|
||||
InputStream is = file.getInputStream();
|
||||
String name = file.getOriginalFilename().toLowerCase();
|
||||
// 创建excel操作对象
|
||||
if (name.contains(".xlsx") || name.contains(".xls")) {
|
||||
workbook = WorkbookFactory.create(is);
|
||||
}
|
||||
//得到一个工作表
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
//获得数据的总行数
|
||||
int totalRowNum = sheet.getLastRowNum();
|
||||
|
||||
//获得总列数
|
||||
int cellLength = sheet.getRow(0).getPhysicalNumberOfCells();
|
||||
Map<Integer, String> map = null;
|
||||
//获得所有数据
|
||||
//从第x行开始获取
|
||||
for(int x = 0 ; x <= totalRowNum ; x++){
|
||||
map = new HashMap<>();
|
||||
//获得第i行对象
|
||||
Row row = sheet.getRow(x);
|
||||
//如果一行里的所有单元格都为空则不放进list里面
|
||||
int a = 0;
|
||||
for(int y=0;y<cellLength;y++){
|
||||
if (!(row==null)) {
|
||||
Cell cell = row.getCell(y);
|
||||
if (cell == null) {
|
||||
map.put(y, "");
|
||||
} else {
|
||||
map.put(y,getXCellVal(cell));
|
||||
}
|
||||
if (map.get(y) == null || "".equals(map.get(y))) {
|
||||
a++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(a!=cellLength && row!=null){
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cell
|
||||
* @return String
|
||||
* 获取单元格中的值
|
||||
*/
|
||||
|
||||
private String getXCellVal(Cell cell) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
DecimalFormat df = new DecimalFormat("0.0000");
|
||||
String val = "";
|
||||
switch (cell.getCellType()) {
|
||||
case XSSFCell.CELL_TYPE_NUMERIC:
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
val = fmt.format(cell.getDateCellValue()); //日期型
|
||||
} else {
|
||||
val = df.format(cell.getNumericCellValue()); //数字型
|
||||
// 去掉多余的0,如最后一位是.则去掉
|
||||
val = val.replaceAll("0+?$", "").replaceAll("[.]$","");
|
||||
}
|
||||
break;
|
||||
case XSSFCell.CELL_TYPE_STRING: //文本类型
|
||||
val = cell.getStringCellValue();
|
||||
break;
|
||||
case XSSFCell.CELL_TYPE_BOOLEAN: //布尔型
|
||||
val = String.valueOf(cell.getBooleanCellValue());
|
||||
break;
|
||||
case XSSFCell.CELL_TYPE_BLANK: //空白
|
||||
val = cell.getStringCellValue();
|
||||
break;
|
||||
case XSSFCell.CELL_TYPE_ERROR: //错误
|
||||
val = "";
|
||||
break;
|
||||
case XSSFCell.CELL_TYPE_FORMULA: //公式
|
||||
try {
|
||||
val = String.valueOf(cell.getStringCellValue());
|
||||
} catch (IllegalStateException e) {
|
||||
val = String.valueOf(cell.getNumericCellValue());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
val = cell.getRichStringCellValue() == null ? null : cell.getRichStringCellValue().toString();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -14,6 +14,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
@@ -42,11 +43,13 @@ public class PayIncomeContractInstallment implements Serializable {
|
||||
/**阶段*/
|
||||
@Excel(name = "阶段", width = 15)
|
||||
@ApiModelProperty(value = "阶段")
|
||||
@NotEmpty(message = "阶段不能为空")
|
||||
@Size(max = 50, message = "阶段长度不能大于50个字符")
|
||||
private java.lang.String phaseName;
|
||||
/**应收金额*/
|
||||
@Excel(name = "应收金额", width = 15)
|
||||
@ApiModelProperty(value = "应收金额")
|
||||
@NotEmpty(message = "应收金额不能为空")
|
||||
@Max(value = 999999999,message = "应收金额格式错误")
|
||||
private java.lang.Integer accountsReceivableAmount;
|
||||
/**应收时间*/
|
||||
|
||||
+1
-1
@@ -130,5 +130,5 @@ public interface IPayIncomeContractService extends IService<PayIncomeContract> {
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
void checkContractNum(String contractNum);
|
||||
PayIncomeContract checkContractNum(String contractNum);
|
||||
}
|
||||
|
||||
+5
-4
@@ -608,16 +608,17 @@ public class PayIncomeContractServiceImpl extends ServiceImpl<PayIncomeContractM
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkContractNum(String contractNum) {
|
||||
public PayIncomeContract checkContractNum(String contractNum) {
|
||||
if(StringUtils.isBlank(contractNum)){
|
||||
throw new JeroBootException("合同编号不能为空!");
|
||||
return null;
|
||||
}else{
|
||||
LambdaQueryWrapper<PayIncomeContract> query = new LambdaQueryWrapper<>();
|
||||
query.eq(PayIncomeContract::getContractNum,contractNum);
|
||||
List<PayIncomeContract> payIncomeContract = payIncomeContractService.list(query);
|
||||
if(CollectionUtils.isEmpty(payIncomeContract)){
|
||||
throw new JeroBootException("合同编号不存在!");
|
||||
if(!CollectionUtils.isEmpty(payIncomeContract)){
|
||||
return payIncomeContract.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-4
@@ -7,6 +7,8 @@ import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.service.ProjectDetailService;
|
||||
import com.jero.contract.entity.PayIncomeContract;
|
||||
import com.jero.contract.entity.PayIncomeContractAssociated;
|
||||
import com.jero.contract.service.IPayIncomeContractAssociatedService;
|
||||
import com.jero.contract.service.IPayIncomeContractService;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
@@ -55,6 +57,8 @@ public class PayCommonProjectServiceImpl extends ServiceImpl<PayCommonProjectMap
|
||||
private IPayContactsManagementTemporaryService payContactsManagementTemporaryService;
|
||||
@Autowired
|
||||
private IPayIncomeContractService payIncomeContractService;
|
||||
@Autowired
|
||||
private IPayIncomeContractAssociatedService payIncomeContractAssociatedService;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -77,16 +81,25 @@ public class PayCommonProjectServiceImpl extends ServiceImpl<PayCommonProjectMap
|
||||
log.info("普通项目管理-添加异常",e);
|
||||
throw new JeroBootException("来款项目已存在!");
|
||||
}
|
||||
// 来款方式为合同,校验合同编号
|
||||
if(Objects.equals(payCommonProject.getChargeWay(),PayProjectCommon.CHARGE_WAY2)){
|
||||
payIncomeContractService.checkContractNum(payCommonProject.getContractNum());
|
||||
}
|
||||
|
||||
setPayCommonProject(payCommonProject);
|
||||
payCommonProject.setPack(PayProjectCommon.PACKAGING0);
|
||||
payCommonProject.setInAccount(PayProjectCommon.IN_ACCOUNT0);
|
||||
payCommonProject.setMakeInvoice(PayProjectCommon.MAKE_INVOICE0);
|
||||
payCommonProject.setMail(PayProjectCommon.MAIL0);
|
||||
payCommonProjectService.save(payCommonProject);
|
||||
// 来款方式为合同,校验合同编号
|
||||
if(Objects.equals(payCommonProject.getChargeWay(),PayProjectCommon.CHARGE_WAY2)){
|
||||
PayIncomeContract payIncomeContract = payIncomeContractService.checkContractNum(payCommonProject.getContractNum());
|
||||
if(!Objects.isNull(payIncomeContract) && Objects.equals(payIncomeContract.getSignedCompanyId(),payCommonProject.getChargeCompanyId())){
|
||||
PayIncomeContractAssociated payIncomeContractAssociated = new PayIncomeContractAssociated();
|
||||
payIncomeContractAssociated.setProjectId(payCommonProject.getId());
|
||||
payIncomeContractAssociated.setContractId(payIncomeContract.getId());
|
||||
payIncomeContractAssociated.setProjectType(Integer.parseInt(PayProjectCommon.PROJECT_TYPE1));
|
||||
payIncomeContractAssociatedService.save(payIncomeContractAssociated);
|
||||
// todo 缺少添加打包功能
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user