|
@@ -6,14 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.management.platform.entity.ExpenseItem;
|
|
|
|
-import com.management.platform.entity.ExpenseSheet;
|
|
|
|
-import com.management.platform.entity.Project;
|
|
|
|
-import com.management.platform.entity.User;
|
|
|
|
-import com.management.platform.mapper.ExpenseItemMapper;
|
|
|
|
-import com.management.platform.mapper.ExpenseSheetMapper;
|
|
|
|
-import com.management.platform.mapper.ProjectMapper;
|
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
|
|
|
+import com.management.platform.entity.*;
|
|
|
|
+import com.management.platform.entity.vo.SysRichFunction;
|
|
|
|
+import com.management.platform.mapper.*;
|
|
import com.management.platform.service.ExpenseItemService;
|
|
import com.management.platform.service.ExpenseItemService;
|
|
import com.management.platform.service.ExpenseSheetService;
|
|
import com.management.platform.service.ExpenseSheetService;
|
|
import com.management.platform.util.ExcelUtil;
|
|
import com.management.platform.util.ExcelUtil;
|
|
@@ -39,6 +34,7 @@ import java.time.LocalDate;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -61,6 +57,10 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
private ExpenseItemMapper expenseItemMapper;
|
|
private ExpenseItemMapper expenseItemMapper;
|
|
@Resource
|
|
@Resource
|
|
private ProjectMapper projectMapper;
|
|
private ProjectMapper projectMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysFunctionMapper sysFunctionMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private ExpenseTypeMapper expenseTypeMapper;
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg add(ExpenseSheet sheet, String items, String userId) {
|
|
public HttpRespMsg add(ExpenseSheet sheet, String items, String userId) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -200,7 +200,6 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
//然后处理文件
|
|
//然后处理文件
|
|
-// List<MultipartFile> multipartFiles = JSONArray.parseArray(files, MultipartFile.class);
|
|
|
|
for (MultipartFile multipartFile : files) {
|
|
for (MultipartFile multipartFile : files) {
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
@@ -223,7 +222,8 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
//获取全部人员
|
|
//获取全部人员
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", user.getCompanyId()));
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", user.getCompanyId()));
|
|
- System.out.println(projectList);
|
|
|
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "费用审核");
|
|
|
|
+ List<ExpenseType> expenseTypeList = expenseTypeMapper.selectList(null);
|
|
//由于第一行需要指明报销人列对应的标题
|
|
//由于第一行需要指明报销人列对应的标题
|
|
XSSFRow firstRow = sheet.getRow(2);
|
|
XSSFRow firstRow = sheet.getRow(2);
|
|
if (firstRow == null) {
|
|
if (firstRow == null) {
|
|
@@ -246,7 +246,15 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
if (expenseTypeCell == null) {
|
|
if (expenseTypeCell == null) {
|
|
throw new Exception("费用类型不能为空");
|
|
throw new Exception("费用类型不能为空");
|
|
}
|
|
}
|
|
|
|
+ if (reportDateCell == null) {
|
|
|
|
+ throw new Exception("填报日期不能为空");
|
|
|
|
+ }
|
|
ExpenseSheet expenseSheet = new ExpenseSheet();
|
|
ExpenseSheet expenseSheet = new ExpenseSheet();
|
|
|
|
+ if(functionList.size()>0){
|
|
|
|
+ expenseSheet.setStatus(0);
|
|
|
|
+ }else {
|
|
|
|
+ expenseSheet.setStatus(1);
|
|
|
|
+ }
|
|
//处理编号
|
|
//处理编号
|
|
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
String format = yyyyMMdd.format(LocalDate.now());
|
|
String format = yyyyMMdd.format(LocalDate.now());
|
|
@@ -293,6 +301,7 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
//计算总费用
|
|
//计算总费用
|
|
BigDecimal bigDecimal = new BigDecimal(0);
|
|
BigDecimal bigDecimal = new BigDecimal(0);
|
|
List<ExpenseItem> expenseItemList = new ArrayList<>();
|
|
List<ExpenseItem> expenseItemList = new ArrayList<>();
|
|
|
|
+ int i=0;
|
|
for (int rowIndex = 5; rowIndex <= rowNum; rowIndex++) {
|
|
for (int rowIndex = 5; rowIndex <= rowNum; rowIndex++) {
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
if (row == null) {
|
|
if (row == null) {
|
|
@@ -320,38 +329,69 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
if (invoiceNoCell != null) invoiceNoCell.setCellType(CellType.STRING);
|
|
if (invoiceNoCell != null) invoiceNoCell.setCellType(CellType.STRING);
|
|
if (taxPercentCell != null) taxPercentCell.setCellType(CellType.NUMERIC);
|
|
if (taxPercentCell != null) taxPercentCell.setCellType(CellType.NUMERIC);
|
|
if (remarkCell != null) remarkCell.setCellType(CellType.STRING);
|
|
if (remarkCell != null) remarkCell.setCellType(CellType.STRING);
|
|
|
|
+ //项目为空 直接跳过
|
|
|
|
+ if(codeCell==null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if(happenDateCell.toString().trim().equals("")||happenDateCell==null){
|
|
|
|
+ msg.setError("费用日期不能为空");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
ExpenseItem expenseItem = new ExpenseItem();
|
|
ExpenseItem expenseItem = new ExpenseItem();
|
|
|
|
+ System.out.println(codeCell.getStringCellValue());
|
|
Optional<Project> project = projectList.stream().filter(pro ->(StringUtils.isEmpty(pro.getProjectCode())?"":pro.getProjectCode()).equals(codeCell.getStringCellValue())
|
|
Optional<Project> project = projectList.stream().filter(pro ->(StringUtils.isEmpty(pro.getProjectCode())?"":pro.getProjectCode()).equals(codeCell.getStringCellValue())
|
|
|| (StringUtils.isEmpty(pro.getProjectName())?"":pro.getProjectName()).equals(codeCell.getStringCellValue())).findFirst();
|
|
|| (StringUtils.isEmpty(pro.getProjectName())?"":pro.getProjectName()).equals(codeCell.getStringCellValue())).findFirst();
|
|
if (project.isPresent()) {
|
|
if (project.isPresent()) {
|
|
expenseItem.setProjectId(project.get().getId());
|
|
expenseItem.setProjectId(project.get().getId());
|
|
} else {
|
|
} else {
|
|
- throw new Exception("项目编号为[" + codeCell.getStringCellValue() + "]的项目不存在");
|
|
|
|
|
|
+ throw new Exception("项目编号/项目名称为[" + codeCell.getStringCellValue() + "]的项目不存在");
|
|
}
|
|
}
|
|
expenseItem.setExpenseId(expenseSheet.getId());
|
|
expenseItem.setExpenseId(expenseSheet.getId());
|
|
LocalDate happenDate = Instant.ofEpochMilli(happenDateCell.getDateCellValue().getTime())
|
|
LocalDate happenDate = Instant.ofEpochMilli(happenDateCell.getDateCellValue().getTime())
|
|
.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
expenseItem.setHappenDate(String.valueOf(happenDate));
|
|
expenseItem.setHappenDate(String.valueOf(happenDate));
|
|
- switch (invoiceTypeCell.getStringCellValue()) {
|
|
|
|
- case "增值税专用发票":
|
|
|
|
- expenseItem.setInvoiceType(0);
|
|
|
|
- break;
|
|
|
|
- case "增值税普通发票":
|
|
|
|
- expenseItem.setInvoiceType(1);
|
|
|
|
- break;
|
|
|
|
|
|
+ if(invoiceTypeCell!=null){
|
|
|
|
+ switch (invoiceTypeCell.getStringCellValue()) {
|
|
|
|
+ case "增值税专用发票":
|
|
|
|
+ expenseItem.setInvoiceType(0);
|
|
|
|
+ break;
|
|
|
|
+ case "增值税普通发票":
|
|
|
|
+ expenseItem.setInvoiceType(1);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- expenseItem.setInvoiceNo(invoiceNoCell.getStringCellValue());
|
|
|
|
- expenseItem.setAmount(amountCell.getNumericCellValue());
|
|
|
|
- expenseItem.setRemark(remarkCell.getStringCellValue());
|
|
|
|
- //计算税额
|
|
|
|
- BigDecimal bd = new BigDecimal(amountCell.getNumericCellValue());
|
|
|
|
- //原始金额
|
|
|
|
- BigDecimal divide = bd.divide(BigDecimal.valueOf((1 + taxPercentCell.getNumericCellValue())),2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
- BigDecimal subtract = bd.subtract(divide);
|
|
|
|
- expenseItem.setTaxValue(subtract.doubleValue());
|
|
|
|
- bigDecimal.add(BigDecimal.valueOf(amountCell.getNumericCellValue()));
|
|
|
|
|
|
+ if(subExpenseTypeCell!=null){
|
|
|
|
+ List<String> stringList = expenseTypeList.stream().filter(et -> et.getMainType().equals(expenseSheet.getType())).map(et -> et.getTypeName()).collect(Collectors.toList());
|
|
|
|
+ if(!stringList.contains(subExpenseTypeCell.getStringCellValue())){
|
|
|
|
+ msg.setError("当前费用类型["+expenseTypeCell.getStringCellValue()+"]中不存在["+subExpenseTypeCell.getStringCellValue()+"]类型");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ expenseItem.setExpenseType(subExpenseTypeCell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ if(invoiceNoCell!=null){
|
|
|
|
+ expenseItem.setInvoiceNo(invoiceNoCell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ if(amountCell!=null){
|
|
|
|
+ expenseItem.setAmount(amountCell.getNumericCellValue());
|
|
|
|
+ //计算税额
|
|
|
|
+ BigDecimal bd = new BigDecimal(amountCell.getNumericCellValue());
|
|
|
|
+ //原始金额
|
|
|
|
+ BigDecimal divide = bd.divide(BigDecimal.valueOf((1 + taxPercentCell.getNumericCellValue())),2,BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ BigDecimal subtract = bd.subtract(divide);
|
|
|
|
+ bigDecimal=bigDecimal.add(BigDecimal.valueOf(amountCell.getNumericCellValue()));
|
|
|
|
+ expenseItem.setTaxValue(subtract.doubleValue());
|
|
|
|
+ }
|
|
|
|
+ if(remarkCell!=null){
|
|
|
|
+ expenseItem.setRemark(remarkCell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ if(taxPercentCell!=null){
|
|
|
|
+ expenseItem.setTaxPercent(taxPercentCell.getNumericCellValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
expenseItemList.add(expenseItem);
|
|
expenseItemList.add(expenseItem);
|
|
|
|
+ i++;
|
|
}
|
|
}
|
|
|
|
+ expenseSheet.setTicketNum(i);
|
|
expenseSheet.setTotalAmount(bigDecimal.doubleValue());
|
|
expenseSheet.setTotalAmount(bigDecimal.doubleValue());
|
|
expenseSheetMapper.updateById(expenseSheet);
|
|
expenseSheetMapper.updateById(expenseSheet);
|
|
expenseItemService.saveBatch(expenseItemList);
|
|
expenseItemService.saveBatch(expenseItemList);
|