批量导入
parent
5afdee12bb
commit
2a9ddc35fa
|
@ -5,6 +5,8 @@ import cn.palmte.work.model.*;
|
|||
import cn.palmte.work.pojo.ActHisTask;
|
||||
import cn.palmte.work.service.*;
|
||||
import cn.palmte.work.utils.*;
|
||||
import cn.palmte.work.utils.excel.ExcelLogs;
|
||||
import cn.palmte.work.utils.excel.ExcelUtil;
|
||||
import cn.palmte.work.utils.excel.ExportExcelUtils;
|
||||
import cn.palmte.work.utils.excel.ExportUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -13,6 +15,9 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import org.activiti.engine.HistoryService;
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.apache.poi.EncryptedDocumentException;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -22,6 +27,7 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.jfunc.common.db.bean.Page;
|
||||
import top.jfunc.common.utils.CollectionUtil;
|
||||
|
||||
|
@ -1017,6 +1023,27 @@ public class ProjectController extends BaseController {
|
|||
exportUtils.write(response.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据导入
|
||||
*/
|
||||
@RequestMapping(value = "/batchIncomeImport")
|
||||
@ResponseBody
|
||||
public String batchIncomeImport(MultipartFile file, Integer id) {
|
||||
try {
|
||||
ExcelLogs logs = new ExcelLogs();
|
||||
Collection<Map> maps = ExcelUtil.importExcel(Map.class, file.getInputStream(),
|
||||
"yyyy/MM/dd HH:mm:ss", logs, 0);
|
||||
synchronized (this) {
|
||||
return JSON.toJSONString(projectBudgetService.checkIncome(maps, id));
|
||||
}
|
||||
} catch (OfficeXmlFileException | EncryptedDocumentException | InvalidFormatException e) {
|
||||
logger.error("", e);
|
||||
return JSON.toJSONString(ResponseMsg.buildFailedMsg("格式错误,请上传excel 2003/2007格式文件"));
|
||||
} catch (Exception e) {
|
||||
return JSON.toJSONString(ResponseMsg.buildFailedMsg("导入数据失败,请联系管理员"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支出模板下载
|
||||
|
@ -1029,4 +1056,25 @@ public class ProjectController extends BaseController {
|
|||
ExportUtils exportUtils = new ExportUtils(headers);
|
||||
exportUtils.write(response.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据导入
|
||||
*/
|
||||
@RequestMapping(value = "/batchCostImport")
|
||||
@ResponseBody
|
||||
public String batchCostImport(MultipartFile file, Integer id) {
|
||||
try {
|
||||
ExcelLogs logs = new ExcelLogs();
|
||||
Collection<Map> maps = ExcelUtil.importExcel(Map.class, file.getInputStream(),
|
||||
"yyyy/MM/dd HH:mm:ss", logs, 0);
|
||||
synchronized (this) {
|
||||
return JSON.toJSONString(projectBudgetService.checkCost(maps, id));
|
||||
}
|
||||
} catch (OfficeXmlFileException | EncryptedDocumentException | InvalidFormatException e) {
|
||||
logger.error("", e);
|
||||
return JSON.toJSONString(ResponseMsg.buildFailedMsg("格式错误,请上传excel 2003/2007格式文件"));
|
||||
} catch (Exception e) {
|
||||
return JSON.toJSONString(ResponseMsg.buildFailedMsg("导入数据失败,请联系管理员"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package cn.palmte.work.model;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProcurementTypeRepository extends JpaRepository<ProcurementType,Integer> {
|
||||
List<ProcurementType> findAllByEnabledEqualsAndIsDeletedEquals(int enable,int deleted);
|
||||
|
||||
@Query(value = "select * from procurement_type where name = ?1 and enabled = 1 and is_deleted = 0 limit 1", nativeQuery = true)
|
||||
ProcurementType findByName(String category);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ package cn.palmte.work.service;
|
|||
|
||||
import cn.palmte.work.bean.*;
|
||||
import cn.palmte.work.model.*;
|
||||
import cn.palmte.work.utils.DateKit;
|
||||
import cn.palmte.work.utils.StrKit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -9,8 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import top.jfunc.common.utils.CollectionUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +22,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@Service
|
||||
public class ProjectBudgetService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectBudgetService.class);
|
||||
@Autowired
|
||||
private ProjectBudgetIncomeRepository projectBudgetIncomeRepository;
|
||||
@Autowired
|
||||
|
@ -55,6 +59,8 @@ public class ProjectBudgetService {
|
|||
private ProjectRepository projectRepository;
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
@Autowired
|
||||
private ProcurementTypeRepository procurementTypeRepository;
|
||||
|
||||
@Value("#{'${fourcal.fixedprojectmanagedetails}'.split('\\|')}")
|
||||
private String[] fixedProjectManageDetails;
|
||||
|
@ -942,4 +948,153 @@ public class ProjectBudgetService {
|
|||
//资金计划明细
|
||||
clearBudgetPlanDetail(p);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseMsg checkIncome(Collection<Map> excelMap, Integer id) {
|
||||
int successCount = 0;
|
||||
int errorCount = 0;
|
||||
List<String> errorList = new ArrayList<>();
|
||||
List<ProjectBudgetIncomeDetailTemp> incomeDetailTempList = new ArrayList<>();
|
||||
for (Map m : excelMap) {
|
||||
try {
|
||||
saveIncomeTemp(m, id, incomeDetailTempList);
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
errorCount++;
|
||||
if (!e.getMessage().isEmpty()) {
|
||||
errorList.add(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
projectBudgetIncomeDetailTempRepository.save(incomeDetailTempList);
|
||||
final ResponseMsg msg = ResponseMsg.buildSuccessMsg(String.format("成功:%d, 失败:%d", successCount, errorCount));
|
||||
msg.setData(errorList);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void saveIncomeTemp(Map m, Integer id, List<ProjectBudgetIncomeDetailTemp> incomeDetailTempList) {
|
||||
ProjectBudgetIncomeDetailTemp temp = new ProjectBudgetIncomeDetailTemp();
|
||||
String key;
|
||||
Object o1;
|
||||
temp.setProjectId(id);
|
||||
key = "类别";
|
||||
o1 = m.get(key);
|
||||
String type = (String) o1;
|
||||
if ("设备类".equals(type)) {
|
||||
temp.setType(1);
|
||||
} else if ("工程类".equals(type)) {
|
||||
temp.setType(2);
|
||||
} else if ("服务类".equals(type)) {
|
||||
temp.setType(3);
|
||||
}
|
||||
key = "名称";
|
||||
o1 = m.get(key);
|
||||
temp.setName((String) o1);
|
||||
key = "单位";
|
||||
o1 = m.get(key);
|
||||
temp.setUnit((String) o1);
|
||||
key = "数量";
|
||||
o1 = m.get(key);
|
||||
temp.setAmount(Integer.parseInt((String) o1));
|
||||
key = "单价";
|
||||
o1 = m.get(key);
|
||||
temp.setPrice(new BigDecimal((String) o1));
|
||||
key = "税率(%)";
|
||||
o1 = m.get(key);
|
||||
temp.setTaxRate(new BigDecimal((String) o1));
|
||||
incomeDetailTempList.add(temp);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseMsg checkCost(Collection<Map> excelMap, Integer id) {
|
||||
int successCount = 0;
|
||||
int errorCount = 0;
|
||||
List<String> errorList = new ArrayList<>();
|
||||
List<ProjectBudgetCostDetailTemp> costDetailTempList = new ArrayList<>();
|
||||
for (Map m : excelMap) {
|
||||
try {
|
||||
saveCostTemp(m, id, costDetailTempList);
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
errorCount++;
|
||||
if (!e.getMessage().isEmpty()) {
|
||||
errorList.add(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
projectBudgetCostDetailTempRepository.save(costDetailTempList);
|
||||
final ResponseMsg msg = ResponseMsg.buildSuccessMsg(String.format("成功:%d, 失败:%d", successCount, errorCount));
|
||||
msg.setData(errorList);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void saveCostTemp(Map m, Integer id, List<ProjectBudgetCostDetailTemp> costDetailTempList) {
|
||||
ProjectBudgetCostDetailTemp temp = new ProjectBudgetCostDetailTemp();
|
||||
String key;
|
||||
Object o1;
|
||||
temp.setProjectId(id);
|
||||
key = "大类";
|
||||
o1 = m.get(key);
|
||||
String type = (String) o1;
|
||||
if ("设备".equals(type)) {
|
||||
temp.setType(1);
|
||||
} else if ("施工".equals(type)) {
|
||||
temp.setType(2);
|
||||
} else if ("服务".equals(type)) {
|
||||
temp.setType(3);
|
||||
} else if ("其他".equals(type)) {
|
||||
temp.setType(4);
|
||||
}
|
||||
key = "类别";
|
||||
o1 = m.get(key);
|
||||
String category = (String) o1;
|
||||
ProcurementType procurementType = procurementTypeRepository.findByName(category);
|
||||
if (procurementType != null && procurementType.getType() == temp.getType()) {
|
||||
temp.setCategory(procurementType.getId());
|
||||
}
|
||||
key = "名称";
|
||||
o1 = m.get(key);
|
||||
temp.setName((String) o1);
|
||||
key = "单位";
|
||||
o1 = m.get(key);
|
||||
temp.setUnit((String) o1);
|
||||
key = "数量";
|
||||
o1 = m.get(key);
|
||||
temp.setAmount(Integer.parseInt((String) o1));
|
||||
key = "单价";
|
||||
o1 = m.get(key);
|
||||
temp.setPrice(new BigDecimal((String) o1));
|
||||
key = "税率(%)";
|
||||
o1 = m.get(key);
|
||||
temp.setTaxRate(new BigDecimal((String) o1));
|
||||
key = "签约方";
|
||||
o1 = m.get(key);
|
||||
temp.setContractParty((String) o1);
|
||||
key = "是否垫资";
|
||||
o1 = m.get(key);
|
||||
String isUnderwritten = (String) o1;
|
||||
if ("是".equals(isUnderwritten)) {
|
||||
temp.setIsUnderwritten(1);
|
||||
} else if ("否".equals(isUnderwritten)) {
|
||||
temp.setIsUnderwritten(2);
|
||||
} else {
|
||||
temp.setIsUnderwritten(0);
|
||||
}
|
||||
key = "预估垫资金额(元)";
|
||||
o1 = m.get(key);
|
||||
temp.setUnderwrittenAmount(new BigDecimal((String) o1));
|
||||
key = "支出时间";
|
||||
o1 = m.get(key);
|
||||
temp.setPayTime(DateKit.getDate((String) o1, DateKit.DATE_FORMAT));
|
||||
key = "支出金额(元)";
|
||||
o1 = m.get(key);
|
||||
temp.setPayAmount(new BigDecimal((String) o1));
|
||||
key = "付款方式";
|
||||
o1 = m.get(key);
|
||||
temp.setPayWay((String) o1);
|
||||
key = "备注";
|
||||
o1 = m.get(key);
|
||||
temp.setRemark((String) o1);
|
||||
costDetailTempList.add(temp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -631,7 +631,7 @@
|
|||
<span class="am-icon-archive"></span>
|
||||
批量导入
|
||||
</button>
|
||||
<input id="doc-form-file" type="file" name="file" onChange="ajaxUploadFile('doc-form-file','${base}/project/batchIncomeImport')">
|
||||
<input id="doc-form-file" type="file" name="file" onChange="ajaxUploadFile('doc-form-file','${base}/project/batchIncomeImport?id=' + ${project.id})">
|
||||
</div>
|
||||
|
||||
<button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/project/incomeTemplate'">
|
||||
|
@ -1375,7 +1375,8 @@
|
|||
<script type="text/javascript" src="../common/jQuery-File-Upload/js/jquery.fileupload.js"></script>
|
||||
<script src="../common/jQuery-File-Upload/js/jquery.fileupload-process.js"></script>
|
||||
<script src="../common/jQuery-File-Upload/js/jquery.fileupload-validate.js"></script>
|
||||
<script>
|
||||
<script type="text/javascript" src="../common/js/jquery.ajaxfileupload.js"></script>
|
||||
<script>
|
||||
var changeCheck = function () {
|
||||
var underwrittenMode = $("#underwrittenMode").val();
|
||||
if (underwrittenMode == 1) {
|
||||
|
|
Loading…
Reference in New Issue