浏览代码

批量导入费用报销数据修改

yurk 2 年之前
父节点
当前提交
b465684184

+ 61 - 28
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ExpenseSheetServiceImpl.java

@@ -6,14 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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.ExpenseSheetService;
 import com.management.platform.util.ExcelUtil;
@@ -39,6 +34,7 @@ import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -61,6 +57,10 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
     private ExpenseItemMapper expenseItemMapper;
     @Resource
     private ProjectMapper projectMapper;
+    @Resource
+    private SysFunctionMapper sysFunctionMapper;
+    @Resource
+    private ExpenseTypeMapper expenseTypeMapper;
     @Override
     public HttpRespMsg add(ExpenseSheet sheet, String items, String userId) {
         HttpRespMsg msg = new HttpRespMsg();
@@ -200,7 +200,6 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("token"));
         //然后处理文件
-//        List<MultipartFile> multipartFiles = JSONArray.parseArray(files, MultipartFile.class);
         for (MultipartFile multipartFile : files) {
             String fileName = multipartFile.getOriginalFilename();
             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<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);
                 if (firstRow == null) {
@@ -247,6 +247,11 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                     throw new Exception("费用类型不能为空");
                 }
                 ExpenseSheet expenseSheet = new ExpenseSheet();
+                if(functionList.size()>0){
+                    expenseSheet.setStatus(0);
+                }else {
+                    expenseSheet.setStatus(1);
+                }
                 //处理编号
                 DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
                 String format = yyyyMMdd.format(LocalDate.now());
@@ -293,6 +298,7 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                 //计算总费用
                 BigDecimal bigDecimal = new BigDecimal(0);
                 List<ExpenseItem> expenseItemList = new ArrayList<>();
+                int i=0;
                 for (int rowIndex = 5; rowIndex <= rowNum; rowIndex++) {
                     XSSFRow row = sheet.getRow(rowIndex);
                     if (row == null) {
@@ -320,8 +326,13 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                     if (invoiceNoCell != null) invoiceNoCell.setCellType(CellType.STRING);
                     if (taxPercentCell != null) taxPercentCell.setCellType(CellType.NUMERIC);
                     if (remarkCell != null) remarkCell.setCellType(CellType.STRING);
+                    //项目为空 直接跳过
                     if(codeCell==null){
-                        throw  new Exception("项目编号/项目名称不能为空");
+                        continue;
+                    }
+                    if(happenDateCell==null){
+                        msg.setError("费用日期不能为空");
+                        return msg;
                     }
                     ExpenseItem expenseItem = new ExpenseItem();
                     Optional<Project> project = projectList.stream().filter(pro ->(StringUtils.isEmpty(pro.getProjectCode())?"":pro.getProjectCode()).equals(codeCell.getStringCellValue())
@@ -335,26 +346,48 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
                     LocalDate happenDate = Instant.ofEpochMilli(happenDateCell.getDateCellValue().getTime())
                             .atZone(ZoneId.systemDefault()).toLocalDate();
                     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;
+                        }
+                    }
+                    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());
                     }
-                    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(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);
+                    i++;
                 }
+                expenseSheet.setTicketNum(i);
                 expenseSheet.setTotalAmount(bigDecimal.doubleValue());
                 expenseSheetMapper.updateById(expenseSheet);
                 expenseItemService.saveBatch(expenseItemList);