|
|
@@ -0,0 +1,729 @@
|
|
|
+package com.jpsoft.employment.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.employment.config.OSSConfig;
|
|
|
+import com.jpsoft.employment.modules.base.entity.DepartmentInfo;
|
|
|
+import com.jpsoft.employment.modules.base.entity.TemplateOption;
|
|
|
+import com.jpsoft.employment.modules.base.service.DepartmentInfoService;
|
|
|
+import com.jpsoft.employment.modules.base.service.TemplateInfoService;
|
|
|
+import com.jpsoft.employment.modules.base.service.TemplateOptionService;
|
|
|
+import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.employment.modules.base.entity.FundIncomeInfo;
|
|
|
+import com.jpsoft.employment.modules.base.service.FundIncomeInfoService;
|
|
|
+import com.jpsoft.employment.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.employment.modules.common.utils.POIUtils;
|
|
|
+import com.jpsoft.employment.modules.common.utils.PojoUtils;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/fundIncomeInfo")
|
|
|
+public class FundIncomeInfoController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FundIncomeInfoService fundIncomeInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TemplateOptionService templateOptionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DepartmentInfoService departmentInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<FundIncomeInfo> create() {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ FundIncomeInfo fundIncomeInfo = new FundIncomeInfo();
|
|
|
+
|
|
|
+ msgResult.setData(fundIncomeInfo);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ public MessageResult<FundIncomeInfo> add(@RequestBody FundIncomeInfo fundIncomeInfo, @RequestAttribute String subject) {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Date now = new Date();
|
|
|
+ fundIncomeInfo.setId(UUID.randomUUID().toString());
|
|
|
+ fundIncomeInfo.setDelFlag(false);
|
|
|
+ fundIncomeInfo.setCreateBy(subject);
|
|
|
+ fundIncomeInfo.setCreateTime(now);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(fundIncomeInfo.getEndDateStr())) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ fundIncomeInfo.setEndDate(sdf.parse(fundIncomeInfo.getEndDateStr()));
|
|
|
+ }
|
|
|
+
|
|
|
+ fundIncomeInfo.setYear(now);
|
|
|
+
|
|
|
+ int affectCount = fundIncomeInfoService.insert(fundIncomeInfo);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(fundIncomeInfo);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<FundIncomeInfo> edit(@PathVariable("id") String id) {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ FundIncomeInfo fundIncomeInfo = fundIncomeInfoService.get(id);
|
|
|
+
|
|
|
+ if (fundIncomeInfo != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (fundIncomeInfo.getEndDate() != null) {
|
|
|
+ fundIncomeInfo.setEndDateStr(sdf.format(fundIncomeInfo.getEndDate()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(fundIncomeInfo.getIncomeType())) {
|
|
|
+ String type = fundIncomeInfo.getIncomeType();
|
|
|
+ switch (type) {
|
|
|
+ case "1":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按月");
|
|
|
+ case "2":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按年");
|
|
|
+ case "3":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按季");
|
|
|
+ case "4":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按学期");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(fundIncomeInfo);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新用户")
|
|
|
+ @PostMapping("update")
|
|
|
+ public MessageResult<FundIncomeInfo> update(@RequestBody FundIncomeInfo fundIncomeInfo, @RequestAttribute String subject) {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ fundIncomeInfo.setUpdateBy(subject);
|
|
|
+ fundIncomeInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(fundIncomeInfo.getEndDateStr())) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ fundIncomeInfo.setEndDate(sdf.parse(fundIncomeInfo.getEndDateStr()));
|
|
|
+ }
|
|
|
+
|
|
|
+ int affectCount = fundIncomeInfoService.update(fundIncomeInfo);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(fundIncomeInfo);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除用户")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ public MessageResult<FundIncomeInfo> delete(@PathVariable("id") String id, @RequestAttribute String subject) {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ FundIncomeInfo fundIncomeInfo = fundIncomeInfoService.get(id);
|
|
|
+ fundIncomeInfo.setDelFlag(true);
|
|
|
+ fundIncomeInfo.setUpdateBy(subject);
|
|
|
+ fundIncomeInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = fundIncomeInfoService.update(fundIncomeInfo);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库删除失败");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "批量删除")
|
|
|
+ @PostMapping("batchDelete")
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ for (String id : idList) {
|
|
|
+ FundIncomeInfo fundIncomeInfo = fundIncomeInfoService.get(id);
|
|
|
+ fundIncomeInfo.setDelFlag(true);
|
|
|
+ fundIncomeInfo.setUpdateBy(subject);
|
|
|
+ fundIncomeInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += fundIncomeInfoService.update(fundIncomeInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "生成数据")
|
|
|
+ @PostMapping("generateData")
|
|
|
+ public MessageResult<FundIncomeInfo> generateData(
|
|
|
+ String templateId,String year,
|
|
|
+ @RequestAttribute String subject) {
|
|
|
+ MessageResult<FundIncomeInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ int affectCount = fundIncomeInfoService.generateData(templateId, year,subject);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库删除失败");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "列表")
|
|
|
+ @RequestMapping(value = "pageList", method = RequestMethod.POST)
|
|
|
+ public MessageResult<Object> pageList(
|
|
|
+ String yearMonth, String name,
|
|
|
+ @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "20000") int pageSize,
|
|
|
+ @RequestParam(value = "exportFlag", defaultValue = "false") Boolean exportFlag,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ String subject = (String) request.getAttribute("subject");
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+
|
|
|
+ MessageResult<Object> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("index_", "asc"));
|
|
|
+
|
|
|
+ String curMonth = "";
|
|
|
+ String startDate = "";
|
|
|
+ String endDate = "";
|
|
|
+ if (StringUtils.isNotEmpty(yearMonth)) {
|
|
|
+ startDate = yearMonth + "-01";
|
|
|
+ endDate = yearMonth + "-31";
|
|
|
+
|
|
|
+ searchParams.put("startDate", startDate);
|
|
|
+ searchParams.put("endDate", endDate);
|
|
|
+
|
|
|
+ curMonth = endDate;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name", name);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Page<FundIncomeInfo> page = fundIncomeInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
|
|
|
+
|
|
|
+ SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (FundIncomeInfo fundIncomeInfo : page) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", fundIncomeInfo.getId());
|
|
|
+ map.put("name", fundIncomeInfo.getName());
|
|
|
+ map.put("serialNumber", fundIncomeInfo.getSerialNumber());
|
|
|
+ map.put("isSum", fundIncomeInfo.getIsSum());
|
|
|
+ BigDecimal budgetRevenue = fundIncomeInfo.getBudgetRevenue();
|
|
|
+ if(fundIncomeInfo.getIsSum()!=null) {
|
|
|
+ if (fundIncomeInfo.getIsSum()) {
|
|
|
+ String serialNumber = fundIncomeInfo.getSerialNumber();
|
|
|
+ BigDecimal sumBudget = fundIncomeInfoService.sumBudgetRevenue(serialNumber + ".%", startDate, endDate);
|
|
|
+ budgetRevenue = sumBudget;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("budgetRevenue", budgetRevenue);
|
|
|
+ map.put("accountName", fundIncomeInfo.getAccountName());
|
|
|
+ map.put("curMonthReceived", fundIncomeInfo.getCurMonthReceived());
|
|
|
+ //map.put("actualTotalRevenue", fundIncomeInfo.getActualTotalRevenue());
|
|
|
+ map.put("accumulatedArrears", fundIncomeInfo.getAccumulatedArrears());
|
|
|
+
|
|
|
+ String endDateStr = "";
|
|
|
+ String incomeTypeN = "";
|
|
|
+ String yearMonthStr = "";
|
|
|
+ String updateTime = "";
|
|
|
+ String createTime = "";
|
|
|
+ String year = "";
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getYear() != null) {
|
|
|
+ year = sdf3.format(fundIncomeInfo.getYear());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getCreateTime() != null) {
|
|
|
+ createTime = sdf3.format(fundIncomeInfo.getCreateTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getUpdateTime() != null) {
|
|
|
+ updateTime = sdf3.format(fundIncomeInfo.getUpdateTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getEndDate() != null) {
|
|
|
+ fundIncomeInfo.setEndDateStr(sdf.format(fundIncomeInfo.getEndDate()));
|
|
|
+ endDateStr = sdf.format(fundIncomeInfo.getEndDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getEndDate() != null) {
|
|
|
+ fundIncomeInfo.setEndDateStr(sdf.format(fundIncomeInfo.getEndDate()));
|
|
|
+ endDateStr = sdf.format(fundIncomeInfo.getEndDate());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(fundIncomeInfo.getIncomeType())) {
|
|
|
+ String type = fundIncomeInfo.getIncomeType();
|
|
|
+ switch (type) {
|
|
|
+ case "1":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按月");
|
|
|
+ incomeTypeN = "按月";
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按年");
|
|
|
+ incomeTypeN = "按年";
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按季");
|
|
|
+ incomeTypeN = "按季";
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ fundIncomeInfo.setIncomeTypeN("按学期");
|
|
|
+ incomeTypeN = "按学期";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("endDateStr", endDateStr);
|
|
|
+ map.put("endDate", endDateStr);
|
|
|
+ map.put("incomeTypeN", incomeTypeN);
|
|
|
+
|
|
|
+ if (fundIncomeInfo.getYear() != null) {
|
|
|
+ yearMonthStr = sdf2.format(fundIncomeInfo.getYear());
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("yearMonthStr", yearMonthStr);
|
|
|
+ map.put("yearMonth", yearMonthStr);
|
|
|
+
|
|
|
+ map.put("createTime", createTime);
|
|
|
+ map.put("updateTime", updateTime);
|
|
|
+ map.put("incomeTimeRange", fundIncomeInfo.getIncomeTimeRange());
|
|
|
+
|
|
|
+ map.put("attachment", fundIncomeInfo.getAttachment());
|
|
|
+
|
|
|
+ String incomeDepartment="";
|
|
|
+ if(StringUtils.isNotEmpty(fundIncomeInfo.getIncomeDepartment())){
|
|
|
+ String[] incomeDepartmentArr = fundIncomeInfo.getIncomeDepartment().split(",");
|
|
|
+ for (String departId:incomeDepartmentArr) {
|
|
|
+ DepartmentInfo departmentInfo = departmentInfoService.get(departId);
|
|
|
+ if(departmentInfo!=null){
|
|
|
+ incomeDepartment+=departmentInfo.getName()+",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(incomeDepartment)){
|
|
|
+ incomeDepartment = incomeDepartment.substring(0,incomeDepartment.lastIndexOf(","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("incomeDepartment", incomeDepartment);
|
|
|
+ map.put("accountingName", fundIncomeInfo.getAccountingName());
|
|
|
+ map.put("bak", fundIncomeInfo.getBak());
|
|
|
+ map.put("year", year);
|
|
|
+
|
|
|
+ BigDecimal total = fundIncomeInfoService.sumBySerialNumber(fundIncomeInfo.getSerialNumber(), curMonth);
|
|
|
+
|
|
|
+ map.put("total", total);
|
|
|
+
|
|
|
+ BigDecimal accumulatedArrears = fundIncomeInfo.getBudgetRevenue();
|
|
|
+ if (total != null) {
|
|
|
+ accumulatedArrears = accumulatedArrears.subtract(total);
|
|
|
+ }
|
|
|
+
|
|
|
+ //累计欠费
|
|
|
+ map.put("accumulatedArrears", accumulatedArrears);
|
|
|
+
|
|
|
+ //实际总收入
|
|
|
+ map.put("actualTotalRevenue", total);
|
|
|
+
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exportFlag) {
|
|
|
+ String filePath = exportXls(mapList);
|
|
|
+ msgResult.setData(filePath);
|
|
|
+ } else {
|
|
|
+ Map<String, Object> dataMap = PojoUtils.pageWrapper(page);
|
|
|
+ dataMap.put("data", mapList);
|
|
|
+ msgResult.setData(dataMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //导出
|
|
|
+ private String exportXls(List<Map> mapList) {
|
|
|
+ String downloadUrl = "";
|
|
|
+
|
|
|
+ Workbook workbook = new HSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet();
|
|
|
+
|
|
|
+ //表头
|
|
|
+ Row rowTitle = sheet.createRow(0);
|
|
|
+
|
|
|
+ String[] titles = new String[]{"序号", "项目名称", "预算收入", "账户名称", "本月到账资金", "实际总收入", "累计欠费",
|
|
|
+ "收入时间区间", "收入类型", "终止日", "收入实现部门", "会计主体名称", "备注", "所属年份"};
|
|
|
+
|
|
|
+ for (int i = 0; i < titles.length; i++) {
|
|
|
+ Cell cell = rowTitle.createCell(i);
|
|
|
+ cell.setCellValue(titles[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < mapList.size(); i++) {
|
|
|
+ Map<String, Object> map = mapList.get(i);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+
|
|
|
+ int colIndex = 0;
|
|
|
+ //row.createCell(colIndex++).setCellValue(i + 1);
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("serialNumber"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("name"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("budgetRevenue"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("accountName"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("curMonthReceived"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("actualTotalRevenue"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("accumulatedArrears"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("incomeTimeRange"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("incomeTypeN"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("endDateStr"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("incomeDepartment"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("accountingName"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("bak"), ""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.employment.modules.common.utils.StringUtils.strValue(map.get("year"), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ try {
|
|
|
+ workbook.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ downloadUrl = OSSUtil.upload(ossConfig, "FundIncomeList", "预算收入列表.xls", input);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return downloadUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入数据")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "uploadFile", value = "上传文件", required = true, paramType = "form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject) {
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 5;
|
|
|
+
|
|
|
+ int count = sheet1.getLastRowNum();
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ for (int rowIndex = 1; rowIndex <= count; rowIndex++) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ String serialNumber = poiUtils.getCellValue(sheetIndex, rowIndex, 0).toString().replace(" ", "");
|
|
|
+
|
|
|
+ String name = poiUtils.getCellValue(sheetIndex, rowIndex, 1).toString().replace(" ", "");
|
|
|
+
|
|
|
+ String year = poiUtils.getCellValue(sheetIndex, rowIndex, 2).toString().replace(" ", "");
|
|
|
+ String budgetRevenue = poiUtils.getCellValue(sheetIndex, rowIndex, 3).toString().replace(" ", "");
|
|
|
+ String accountName = poiUtils.getCellValue(sheetIndex, rowIndex, 4).toString().replace(" ", "");
|
|
|
+ String curMonthReceived = poiUtils.getCellValue(sheetIndex, rowIndex, 5).toString().replace(" ", "");
|
|
|
+ String actualTotalRevenue = poiUtils.getCellValue(sheetIndex, rowIndex, 6).toString().replace(" ", "");
|
|
|
+ String accumulatedArrears = poiUtils.getCellValue(sheetIndex, rowIndex, 7).toString().replace(" ", "");
|
|
|
+ String incomeTimeRange = poiUtils.getCellValue(sheetIndex, rowIndex, 8).toString().replace(" ", "");
|
|
|
+ String incomeType = poiUtils.getCellValue(sheetIndex, rowIndex, 9).toString().replace(" ", "");
|
|
|
+ String endDate = poiUtils.getCellValue(sheetIndex, rowIndex, 10).toString().replace(" ", "");
|
|
|
+ String incomeDepartment = poiUtils.getCellValue(sheetIndex, rowIndex, 11).toString().replace(" ", "");
|
|
|
+ String accountingName = poiUtils.getCellValue(sheetIndex, rowIndex, 12).toString().replace(" ", "");
|
|
|
+ String bak = poiUtils.getCellValue(sheetIndex, rowIndex, 13).toString().replace(" ", "");
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(serialNumber)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写用序号!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写项目名称!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(year)) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未填写所属年份!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户身份
|
|
|
+ FundIncomeInfo fundIncomeInfo = new FundIncomeInfo();
|
|
|
+ fundIncomeInfo.setId(UUID.randomUUID().toString());
|
|
|
+ fundIncomeInfo.setSerialNumber(serialNumber);
|
|
|
+ fundIncomeInfo.setName(name);
|
|
|
+ if (StringUtils.isNotEmpty(budgetRevenue)) {
|
|
|
+ fundIncomeInfo.setBudgetRevenue(new BigDecimal(budgetRevenue));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(curMonthReceived)) {
|
|
|
+ fundIncomeInfo.setBudgetRevenue(new BigDecimal(curMonthReceived));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(actualTotalRevenue)) {
|
|
|
+ fundIncomeInfo.setBudgetRevenue(new BigDecimal(actualTotalRevenue));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(accumulatedArrears)) {
|
|
|
+ fundIncomeInfo.setBudgetRevenue(new BigDecimal(accumulatedArrears));
|
|
|
+ }
|
|
|
+
|
|
|
+ fundIncomeInfo.setAccountName(accountName);
|
|
|
+ fundIncomeInfo.setIncomeTimeRange(incomeTimeRange);
|
|
|
+
|
|
|
+ String incomeTypeNum = "";
|
|
|
+ if (StringUtils.isNotEmpty(incomeType)) {
|
|
|
+ switch (incomeType) {
|
|
|
+ case "按月":
|
|
|
+ incomeTypeNum = "1";
|
|
|
+ break;
|
|
|
+ case "按年":
|
|
|
+ incomeTypeNum = "2";
|
|
|
+ break;
|
|
|
+ case "按季":
|
|
|
+ incomeTypeNum = "3";
|
|
|
+ break;
|
|
|
+ case "按学期":
|
|
|
+ incomeTypeNum = "4";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fundIncomeInfo.setIncomeType(incomeTypeNum);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(endDate)) {
|
|
|
+ String s = dateFormate(endDate);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ fundIncomeInfo.setEndDate(sdf.parse(s));
|
|
|
+ }
|
|
|
+
|
|
|
+ fundIncomeInfo.setIncomeDepartment(incomeDepartment);
|
|
|
+ fundIncomeInfo.setAccountingName(accountingName);
|
|
|
+ fundIncomeInfo.setBak(bak);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(year)) {
|
|
|
+ String s = dateFormate(year + "-01");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ fundIncomeInfo.setYear(sdf.parse(s));
|
|
|
+ }
|
|
|
+
|
|
|
+ fundIncomeInfo.setCreateBy(subject);
|
|
|
+ fundIncomeInfo.setCreateTime(now);
|
|
|
+ fundIncomeInfo.setDelFlag(false);
|
|
|
+
|
|
|
+ //保存新数据
|
|
|
+ fundIncomeInfoService.insert(fundIncomeInfo);
|
|
|
+ affectCount++;
|
|
|
+ } catch (Exception innerEx) {
|
|
|
+ logger.error(innerEx.getMessage(), innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount > 0) {
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(sheetIndex, validateColIndex, 1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig, "import", "error.xls", input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String dateFormate(String str) {
|
|
|
+ //String s="45292.0"; //举例日期为2024-01-01 / 45292.0
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date date;
|
|
|
+ boolean b;
|
|
|
+ try {
|
|
|
+ Double.parseDouble(str);
|
|
|
+ b = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ b = false;
|
|
|
+ }
|
|
|
+ String format = "";
|
|
|
+ //如果是double 则HSSF工具类处理
|
|
|
+ if (b) {
|
|
|
+ date = HSSFDateUtil.getJavaDate(new Double(String.valueOf(str)));
|
|
|
+ format = dateFormat.format(date);
|
|
|
+ System.out.println(date.getTime() / 1000);
|
|
|
+ System.out.println(format);
|
|
|
+ }
|
|
|
+ //如果是日期字符串则直接获取想要的属性
|
|
|
+ else {
|
|
|
+ //如果是错误的日期比如2024-01-51 建议用封装的Util类先校验一下日期
|
|
|
+ try {
|
|
|
+ Date parse = dateFormat.parse(str);
|
|
|
+ format = dateFormat.format(parse);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return format;
|
|
|
+ }
|
|
|
+}
|