|
@@ -6,13 +6,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.constant.Constant;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.vo.ContractPageVO;
|
|
|
+import com.management.platform.entity.vo.ContractVo;
|
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
|
import com.management.platform.mapper.*;
|
|
|
-import com.management.platform.service.ContractService;
|
|
|
-import com.management.platform.service.ExcelExportService;
|
|
|
-import com.management.platform.service.SysDictService;
|
|
|
+import com.management.platform.service.*;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
@@ -86,9 +86,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
private ContractPayCustomizedMapper contractPayCustomizedMapper;
|
|
|
@Resource
|
|
|
private SysDictService sysDictService;
|
|
|
+ @Resource
|
|
|
+ private DepartmentService departmentService;
|
|
|
+ @Resource
|
|
|
+ private ContractPaymentService contractPaymentService;
|
|
|
|
|
|
@Resource
|
|
|
private CompanyDingdingMapper companyDingdingMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysFunctionService sysFunctionService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -110,15 +118,18 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
String typeName, Integer status, String startDate, String endDate,
|
|
|
String paymentStartDate, String paymentEndDate, Integer secTypeId,String customerOrg,Integer finishStatus) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("token");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部合同");
|
|
|
+ boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门合同数据");
|
|
|
try {
|
|
|
- String token = request.getHeader("token");
|
|
|
- User user = userMapper.selectById(token);
|
|
|
+
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
- List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
|
|
|
+ /*List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
|
|
|
if(functionContractList.size() <= 0){
|
|
|
httpRespMsg.setError(MessageUtils.message("access.viewError"));
|
|
|
return httpRespMsg;
|
|
|
- }
|
|
|
+ }*/
|
|
|
List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
|
|
|
if (types.size() == 0){
|
|
|
//String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
|
|
@@ -134,22 +145,35 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
if (pageIndex!=null){
|
|
|
pageStart = (pageIndex -1) * pageSize;
|
|
|
}
|
|
|
-// if (StringUtils.isNotBlank(number)){
|
|
|
-// number = "%" + number + "%";
|
|
|
-// }
|
|
|
-// if (StringUtils.isNotBlank(name)){
|
|
|
-// name = "%" + name + "%";
|
|
|
-// }
|
|
|
- List<Contract> contracts = contractMapper.selectContract(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
|
|
|
- Long totalCnt = contractMapper.selectContractCnt(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
|
|
|
+ List<Contract> contracts = new ArrayList<>();
|
|
|
+ Long totalCnt=0L;
|
|
|
+
|
|
|
+ int type=0;
|
|
|
+ Integer dept=user.getDepartmentId();
|
|
|
+ String userId=user.getId();
|
|
|
+ if (isAll){
|
|
|
+ type=1;//查看全部
|
|
|
+ }else if (isNotAll) {
|
|
|
+ type=2;//查看对应部门
|
|
|
+ }else {
|
|
|
+ type=3;//查看个人
|
|
|
+ }
|
|
|
+ contracts = contractMapper.selectContractWithType(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
|
|
|
+ totalCnt = contractMapper.selectContractCntWithType(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
|
|
|
+
|
|
|
+
|
|
|
+ //首先获取所有合同的Id
|
|
|
+ List<Integer> contractCollect = contracts.stream().map(Contract::getId).collect(Collectors.toList());
|
|
|
+ contractCollect.add(-1);
|
|
|
+ List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().in("contract_id", contractCollect));
|
|
|
for (Contract contract : contracts) {
|
|
|
if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
contract.setCreatorName(contract.getCreatorWxCorpId());
|
|
|
}
|
|
|
+ //已开票金额
|
|
|
+ BigDecimal decimal = contractPaymentList.stream().filter(c -> c.getContractId().equals(contract.getId()) && c.getIsBilled() == 1).map(ContractPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ contract.setInvoicedAmount(decimal);
|
|
|
}
|
|
|
- //首先获取所有合同的Id
|
|
|
- List<Integer> contractCollect = contracts.stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
- contractCollect.add(-1);
|
|
|
//查询所有合同的所有附件
|
|
|
List<ContractDocument> fileList = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().in("contract_id", contractCollect).eq("is_deleted",0));
|
|
|
//获取所有附件的上传者id
|
|
@@ -200,6 +224,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
contractPageVO.setPlate3(contract.getPlate3());
|
|
|
contractPageVO.setPlate4(contract.getPlate4());
|
|
|
contractPageVO.setPlate5(contract.getPlate5());
|
|
|
+ contractPageVO.setInvoicedAmount(contract.getInvoicedAmount());
|
|
|
+ contractPageVO.setDepartmentId(contract.getDepartmentId());
|
|
|
+ contractPageVO.setDepartmentName(contract.getDepartmentName());
|
|
|
if (contract.getStatus().equals(2)){
|
|
|
for (Map<String, Object> contractLog : contractLogs) {
|
|
|
if (contractLog.get("contractId").toString().equals(contract.getId().toString())){
|
|
@@ -276,6 +303,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
// headList.add("创建时间");
|
|
|
// headList.add("备注");
|
|
|
headList.add(MessageUtils.message("entry.contractNo"));
|
|
|
+ headList.add("部门");
|
|
|
headList.add(MessageUtils.message("contract.name"));
|
|
|
headList.add(MessageUtils.message("Contract.startDate"));
|
|
|
headList.add(MessageUtils.message("Contract.endDate"));
|
|
@@ -290,6 +318,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
for (ContractPageVO contract : data) {
|
|
|
ArrayList<String> item = new ArrayList<>();
|
|
|
item.add(contract.getNumber()==null?"":contract.getNumber());
|
|
|
+ item.add(StringUtils.isEmpty(contract.getDepartmentName())?"":contract.getDepartmentName());
|
|
|
item.add(null == contract.getName()?"":contract.getName());
|
|
|
item.add(contract.getStartDate()==null?"":contract.getStartDate()+"");
|
|
|
item.add(contract.getEndDate()==null?"":contract.getEndDate()+"");
|
|
@@ -338,6 +367,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public HttpRespMsg addContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
@@ -398,7 +428,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
for (ContractPayment contractPayment:contractPaymentList) {
|
|
|
contractPayment.setContractId(contract.getId());
|
|
|
contractPaymentMapper.insert(contractPayment);
|
|
|
- if (contractPayment.getIsPayed()) {
|
|
|
+ if (contractPayment.getIsPayed()!=null&&contractPayment.getIsPayed()) {
|
|
|
bg = bg.add(contractPayment.getAmount());
|
|
|
}
|
|
|
}
|
|
@@ -435,11 +465,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
public HttpRespMsg editContract(HttpServletRequest request, Contract contract, ContractCustom custom, String paymentListStr) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
|
- List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
|
|
|
+ /*List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
|
|
|
if(functionContractList.size() <= 0){
|
|
|
httpRespMsg.setError(MessageUtils.message("access.operationError"));
|
|
|
return httpRespMsg;
|
|
|
- }
|
|
|
+ }*/
|
|
|
try {
|
|
|
if (contract.getId() == null) {
|
|
|
httpRespMsg.setError(MessageUtils.message("name.idNullError"));
|
|
@@ -1546,6 +1576,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
try {
|
|
|
String token = request.getHeader("token");
|
|
|
User user = userMapper.selectById(token);
|
|
|
+ boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部合同");
|
|
|
+ boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门合同数据");
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部合同");
|
|
|
// CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, user.getCompanyId()));
|
|
@@ -1555,10 +1587,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
// companyUserMap = companyUserList.stream().collect(Collectors.toMap(User::getId, t -> t));
|
|
|
// }
|
|
|
|
|
|
- if(functionContractList.size() <= 0){
|
|
|
- httpRespMsg.setError(MessageUtils.message("access.viewError"));
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
|
|
|
if (types.size() == 0){
|
|
|
//String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
|
|
@@ -1574,14 +1602,18 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
if (pageIndex!=null){
|
|
|
pageStart = (pageIndex -1) * pageSize;
|
|
|
}
|
|
|
-// if (StringUtils.isNotBlank(number)){
|
|
|
-// number = "%" + number + "%";
|
|
|
-// }
|
|
|
-// if (StringUtils.isNotBlank(name)){
|
|
|
-// name = "%" + name + "%";
|
|
|
-// }
|
|
|
- List<Contract> contracts = contractMapper.selectContractByPin(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
|
|
|
- Long totalCnt = contractMapper.selectContractCnt(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus);
|
|
|
+ int type=0;
|
|
|
+ Integer dept=user.getDepartmentId();
|
|
|
+ String userId=user.getId();
|
|
|
+ if (isAll){
|
|
|
+ type=1;//查看全部
|
|
|
+ }else if (isNotAll) {
|
|
|
+ type=2;//查看对应部门
|
|
|
+ }else {
|
|
|
+ type=3;//查看个人
|
|
|
+ }
|
|
|
+ List<Contract> contracts = contractMapper.selectContractByPinWithType(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
|
|
|
+ Long totalCnt = contractMapper.selectContractContByPinWithType(user.getCompanyId(), number, name, typeName, status, startDate, endDate, paymentStartDate, paymentEndDate, secTypeId,customerOrg,finishStatus,type,dept,userId);
|
|
|
for (Contract contract : contracts) {
|
|
|
if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
contract.setCreatorName(contract.getCreatorWxCorpId());
|
|
@@ -1721,6 +1753,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
public HttpRespMsg getContractDetail(HttpServletRequest request, Integer id) {
|
|
|
HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
Contract contract = contractMapper.selectById(id);
|
|
|
+ if(contract.getDepartmentId()!=null){
|
|
|
+ contract.setDepartmentName(departmentService.getById(contract.getDepartmentId()).getDepartmentName());
|
|
|
+ }
|
|
|
if (contract.getTypeId()!=null){
|
|
|
SysDict dict = sysDictService.getById(contract.getTypeId());
|
|
|
if (dict!=null){
|
|
@@ -1736,6 +1771,10 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
contract.setNextPaymentAmount(contractPayment.getAmount());
|
|
|
}
|
|
|
}
|
|
|
+ List<ContractPayment> contractPaymentList = contractPaymentMapper.selectList(new QueryWrapper<ContractPayment>().eq("is_billed", 1).eq("contract_id",contract.getId()));
|
|
|
+ //已开票金额
|
|
|
+ BigDecimal decimal = contractPaymentList.stream().map(ContractPayment::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ contract.setInvoicedAmount(decimal);
|
|
|
List<ContractCustom> selectedList = contractCustomMapper.selectList(new QueryWrapper<ContractCustom>().eq("contract_id", contract.getId()));
|
|
|
if (selectedList != null && !selectedList.isEmpty()) {
|
|
|
contract.setCustomData(selectedList.get(0));
|
|
@@ -1748,4 +1787,399 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
|
|
|
return respMsg;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importContractNew(HttpServletRequest request, MultipartFile multipartFile) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ List<SysRichFunction> functionContractList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "导入合同");
|
|
|
+ if(functionContractList.size() <= 0){
|
|
|
+ msg.setError(MessageUtils.message("access.operationError"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ //然后处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ if (rowNum == 0) {
|
|
|
+ msg.setError(MessageUtils.message("Contract.dataNull"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ List<Contract> contractList = contractMapper.selectList(new QueryWrapper<Contract>().eq("company_id", companyId));
|
|
|
+ List<SysDict> sysDictList = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ContractType").orderByAsc(SysDict::getSeq));
|
|
|
+ List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+
|
|
|
+ int dataIndex = 1;
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
+
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+
|
|
|
+ for (int i = 0; i < 17; i++) {
|
|
|
+ if (row.getCell(i) != null) {
|
|
|
+ if (i ==2 || i == 11|| i == 15|| i == 16) {
|
|
|
+ //日期类型的
|
|
|
+ row.getCell(i).setCellType(CellType.NUMERIC);
|
|
|
+ } else {
|
|
|
+ row.getCell(i).setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (row!=null){
|
|
|
+ if (row.getCell(0)==null||row.getCell(1)==null||StringUtils.isEmpty(row.getCell(0).getStringCellValue())||StringUtils.isEmpty(row.getCell(1).getStringCellValue())){
|
|
|
+ msg.setError("请填写合同编号或合同名称");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ String number = row.getCell(0).getStringCellValue();
|
|
|
+ String name = row.getCell(1).getStringCellValue();
|
|
|
+ if (map.containsKey(number)){
|
|
|
+ if (!map.get(number).equals(name)){
|
|
|
+ msg.setError("文档中存在合同编号相同但是合同名称不同的数据");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(number,name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ContractVo> contractVos = new ArrayList<>();
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
+
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ for (int i = 0; i < 17; i++) {
|
|
|
+ if (row.getCell(i) != null) {
|
|
|
+ if (i ==2 || i == 11|| i == 15|| i == 16) {
|
|
|
+ //日期类型的
|
|
|
+ row.getCell(i).setCellType(CellType.NUMERIC);
|
|
|
+ } else {
|
|
|
+ row.getCell(i).setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (row!=null){
|
|
|
+ String number = row.getCell(0).getStringCellValue();
|
|
|
+ String name = row.getCell(1).getStringCellValue();
|
|
|
+ double contractAmount = row.getCell(2)==null?0:row.getCell(2).getNumericCellValue();
|
|
|
+ String contractTypeName =row.getCell(3)==null?"": row.getCell(3).getStringCellValue();
|
|
|
+ LocalDate startDate = null;
|
|
|
+ LocalDate endDate = null;
|
|
|
+ if(row.getCell(4) != null && row.getCell(4).getCellTypeEnum() != CellType.BLANK){
|
|
|
+ if(!StringUtils.isEmpty(row.getCell(4).getStringCellValue())){
|
|
|
+ try {
|
|
|
+ int count = Integer.parseInt(row.getCell(4).getStringCellValue());
|
|
|
+ // Excel中的日期序列号的基准日期是1900年1月1日
|
|
|
+ LocalDate baseDate = LocalDate.of(1900, 1, 1);
|
|
|
+ LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
|
|
|
+ startDate = date;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
|
|
|
+ msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(row.getCell(5) != null && row.getCell(5).getCellTypeEnum() != CellType.BLANK){
|
|
|
+ if(!StringUtils.isEmpty(row.getCell(5).getStringCellValue())){
|
|
|
+ try {
|
|
|
+ int count = Integer.parseInt(row.getCell(5).getStringCellValue());
|
|
|
+ // Excel中的日期序列号的基准日期是1900年1月1日
|
|
|
+ LocalDate baseDate = LocalDate.of(1900, 1, 1);
|
|
|
+ LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
|
|
|
+ endDate = date;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
|
|
|
+ msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String dept =row.getCell(6)==null?"": row.getCell(6).getStringCellValue();
|
|
|
+ String design =row.getCell(7)==null?"": row.getCell(7).getStringCellValue();
|
|
|
+ String remarks =row.getCell(8)==null?"": row.getCell(8).getStringCellValue();
|
|
|
+ String isReturn = row.getCell(9)==null?"": row.getCell(9).getStringCellValue();
|
|
|
+ LocalDate returnDate = null;
|
|
|
+ if(row.getCell(10) != null && row.getCell(10).getCellTypeEnum() != CellType.BLANK){
|
|
|
+ if(!StringUtils.isEmpty(row.getCell(10).getStringCellValue())){
|
|
|
+ try {
|
|
|
+ int count = Integer.parseInt(row.getCell(10).getStringCellValue());
|
|
|
+ // Excel中的日期序列号的基准日期是1900年1月1日
|
|
|
+ LocalDate baseDate = LocalDate.of(1900, 1, 1);
|
|
|
+ LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
|
|
|
+ returnDate = date;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
|
|
|
+ msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double returnAmount = row.getCell(11)==null?0:row.getCell(11).getNumericCellValue();
|
|
|
+ String isBilled =row.getCell(12)==null?"": row.getCell(12).getStringCellValue();
|
|
|
+
|
|
|
+ LocalDate billDate = null;
|
|
|
+ if(row.getCell(13) != null && row.getCell(13).getCellTypeEnum() != CellType.BLANK){
|
|
|
+ if(!StringUtils.isEmpty(row.getCell(13).getStringCellValue())){
|
|
|
+ try {
|
|
|
+ int count = Integer.parseInt(row.getCell(13).getStringCellValue());
|
|
|
+ // Excel中的日期序列号的基准日期是1900年1月1日
|
|
|
+ LocalDate baseDate = LocalDate.of(1900, 1, 1);
|
|
|
+ LocalDate date = baseDate.plusDays(count - 2); // Excel的基准日期是1900年1月0日,所以需要减去2天
|
|
|
+ billDate = date;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
|
|
|
+ msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String billType =row.getCell(14)==null?"": row.getCell(14).getStringCellValue();
|
|
|
+ double taxRate = row.getCell(15)==null?0:row.getCell(15).getNumericCellValue();
|
|
|
+ double taxAmount = row.getCell(16)==null?0:row.getCell(16).getNumericCellValue();
|
|
|
+
|
|
|
+ ContractVo contractVo = new ContractVo();
|
|
|
+ contractVo.setNumber(number)
|
|
|
+ .setName(name)
|
|
|
+ .setContractAmount(contractAmount)
|
|
|
+ .setContractType(contractTypeName)
|
|
|
+ .setStartDate(startDate)
|
|
|
+ .setEndDate(endDate)
|
|
|
+ .setDepartmentName(dept)
|
|
|
+ .setDesign(design)
|
|
|
+ .setRemark(remarks)
|
|
|
+ .setIsreturn(isReturn)
|
|
|
+ .setReturnDate(returnDate)
|
|
|
+ .setReturnMoney(returnAmount)
|
|
|
+ .setIsBill(isBilled)
|
|
|
+ .setBillDate(billDate)
|
|
|
+ .setBillType(billType)
|
|
|
+ .setTax(taxAmount)
|
|
|
+ .setTaxRate(taxRate);
|
|
|
+ contractVos.add(contractVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Set<Map.Entry<String, String>> entries = map.entrySet();
|
|
|
+ for (Map.Entry<String, String> entry : entries) {
|
|
|
+ List<ContractVo> voList = contractVos.stream().filter(c -> c.getNumber().equals(entry.getKey())).collect(Collectors.toList());
|
|
|
+ if (voList.size() > 1) {
|
|
|
+ ContractVo contractVo = voList.get(0);
|
|
|
+ Contract contract = new Contract();
|
|
|
+ long count = contractList.stream().filter(c -> c.getNumber().equals(contractVo.getNumber())).count();
|
|
|
+ if (count >0) {
|
|
|
+ msg.setError("合同编号:"+contractVo.getNumber()+"已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ contract.setNumber(contractVo.getNumber())
|
|
|
+ .setName(contractVo.getName())
|
|
|
+ .setAmounts(BigDecimal.valueOf(contractVo.getContractAmount()))
|
|
|
+ .setStartDate(contractVo.getStartDate())
|
|
|
+ .setEndDate(contractVo.getEndDate())
|
|
|
+ .setPlate1(contractVo.getDesign())
|
|
|
+ .setRemarks(contractVo.getRemark())
|
|
|
+ .setCompanyId(user.getCompanyId())
|
|
|
+ .setCreatorId(user.getId())
|
|
|
+ .setIndate(LocalDate.now());
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getContractType())){
|
|
|
+ Optional<SysDict> first = sysDictList.stream().filter(s -> s.getName().equals(contractVo.getContractType())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ contract.setTypeId(first.get().getId());
|
|
|
+ }else {
|
|
|
+ msg.setError("合同不已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getDepartmentName())){
|
|
|
+ Optional<Department> first = departmentList.stream().filter(d -> d.getDepartmentName().equals(contractVo.getDepartmentName())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ contract.setDepartmentId(first.get().getDepartmentId());
|
|
|
+ }else {
|
|
|
+ msg.setError("部门名称不已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ contractMapper.insert(contract);
|
|
|
+
|
|
|
+ ArrayList<ContractPayment> paymentArrayList = new ArrayList<>();
|
|
|
+ for (ContractVo vo : voList) {
|
|
|
+ ContractPayment payment = new ContractPayment();
|
|
|
+ if (StringUtils.isNotEmpty(vo.getIsreturn())){
|
|
|
+ if (vo.getIsreturn().equals("是")){
|
|
|
+ payment.setIsPayed(true);
|
|
|
+ }else {
|
|
|
+ payment.setIsPayed(false);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ payment.setIsPayed(false);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(vo.getIsBill())){
|
|
|
+ if (vo.getIsBill().equals("是")){
|
|
|
+ payment.setIsBilled(1);
|
|
|
+ }else {
|
|
|
+ payment.setIsBilled(0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ payment.setIsBilled(0);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(vo.getBillType())){
|
|
|
+ if (vo.getBillType().equals("专票")){
|
|
|
+ payment.setInvoiceType(0);
|
|
|
+ }else if (vo.getBillType().equals("普票")){
|
|
|
+ payment.setInvoiceType(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ payment.setContractId(contract.getId())
|
|
|
+ .setPayDate(vo.getReturnDate())
|
|
|
+ .setAmount(BigDecimal.valueOf(vo.getReturnMoney()))
|
|
|
+ .setBillDate(vo.getBillDate())
|
|
|
+ .setTaxAmount(BigDecimal.valueOf(vo.getTax()))
|
|
|
+ .setTaxRate(BigDecimal.valueOf(vo.getTaxRate()));
|
|
|
+
|
|
|
+ paymentArrayList.add(payment);
|
|
|
+ BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
|
|
|
+ if(vo.getIsreturn().equals("是")) {
|
|
|
+ contract.setPayment(paymented.add(BigDecimal.valueOf(vo.getReturnMoney())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ contractPaymentService.saveBatch(paymentArrayList);
|
|
|
+ contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ContractVo contractVo = voList.get(0);
|
|
|
+ Contract contract = new Contract();
|
|
|
+ long count = contractList.stream().filter(c -> c.getNumber()!=null&&c.getNumber().equals(contractVo.getNumber())).count();
|
|
|
+ if (count >0) {
|
|
|
+ msg.setError("合同编号:"+contractVo.getNumber()+"已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ contract.setNumber(contractVo.getNumber())
|
|
|
+ .setName(contractVo.getName())
|
|
|
+ .setAmounts(BigDecimal.valueOf(contractVo.getContractAmount()))
|
|
|
+ .setStartDate(contractVo.getStartDate())
|
|
|
+ .setEndDate(contractVo.getEndDate())
|
|
|
+ .setPlate1(contractVo.getDesign())
|
|
|
+ .setRemarks(contractVo.getRemark())
|
|
|
+ .setCompanyId(user.getCompanyId())
|
|
|
+ .setCreatorId(user.getId())
|
|
|
+ .setIndate(LocalDate.now());
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getContractType())){
|
|
|
+ Optional<SysDict> first = sysDictList.stream().filter(s -> s.getName().equals(contractVo.getContractType())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ contract.setTypeId(first.get().getId());
|
|
|
+ }else {
|
|
|
+ msg.setError("合同不已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getDepartmentName())){
|
|
|
+ Optional<Department> first = departmentList.stream().filter(d -> d.getDepartmentName().equals(contractVo.getDepartmentName())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ contract.setDepartmentId(first.get().getDepartmentId());
|
|
|
+ }else {
|
|
|
+ msg.setError("部门名称不已存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ contractMapper.insert(contract);
|
|
|
+
|
|
|
+ ContractPayment payment = new ContractPayment();
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getIsreturn())){
|
|
|
+ if (contractVo.getIsreturn().equals("是")){
|
|
|
+ payment.setIsPayed(true);
|
|
|
+ }else {
|
|
|
+ payment.setIsPayed(false);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ payment.setIsPayed(false);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getIsBill())){
|
|
|
+ if (contractVo.getIsBill().equals("是")){
|
|
|
+ payment.setIsBilled(1);
|
|
|
+ }else {
|
|
|
+ payment.setIsBilled(0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ payment.setIsBilled(0);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(contractVo.getBillType())){
|
|
|
+ if (contractVo.getBillType().equals("专票")){
|
|
|
+ payment.setInvoiceType(0);
|
|
|
+ }else if (contractVo.getBillType().equals("普票")){
|
|
|
+ payment.setInvoiceType(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ payment.setContractId(contract.getId())
|
|
|
+ .setPayDate(contractVo.getReturnDate())
|
|
|
+ .setAmount(BigDecimal.valueOf(contractVo.getReturnMoney()))
|
|
|
+ .setBillDate(contractVo.getBillDate())
|
|
|
+ .setTaxAmount(BigDecimal.valueOf(contractVo.getTax()))
|
|
|
+ .setTaxRate(BigDecimal.valueOf(contractVo.getTaxRate()));
|
|
|
+ contractPaymentService.save(payment);
|
|
|
+
|
|
|
+ BigDecimal paymented = contract.getPayment() == null ? BigDecimal.ZERO : contract.getPayment();
|
|
|
+ if(contractVo.getIsreturn().equals("是")) {
|
|
|
+ contract.setPayment(paymented.add(BigDecimal.valueOf(contractVo.getReturnMoney())));
|
|
|
+ }
|
|
|
+ contractMapper.update(null,new UpdateWrapper<Contract>().set("payment",contract.getPayment()).eq("id",contract.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件处理出错");
|
|
|
+ msg.setError(MessageUtils.message("file.error"));
|
|
|
+ return msg;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
+ msg.setError(MessageUtils.message("file.dataFormatError"));
|
|
|
+ return msg;
|
|
|
+ }catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
+ return msg;
|
|
|
+ }catch (EncryptedDocumentException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件加密状态,需要先解除加密状态再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.encryption"));
|
|
|
+ return msg;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("发生其他错误:"+e.getMessage());
|
|
|
+ msg.setError(MessageUtils.message("other.errorByParameter",e.getMessage()));
|
|
|
+ return msg;
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|