/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */

package com.qunzhixinxi.hnqz.admin.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
import com.qunzhixinxi.hnqz.admin.api.entity.SysFile;
import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
import com.qunzhixinxi.hnqz.admin.entity.AuditEntity;
import com.qunzhixinxi.hnqz.admin.entity.WmDaAgent;
import com.qunzhixinxi.hnqz.admin.entity.WmDaDistribution;
import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEnt;
import com.qunzhixinxi.hnqz.admin.entity.WmDaHospital;
import com.qunzhixinxi.hnqz.admin.entity.WmReport;
import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
import com.qunzhixinxi.hnqz.admin.entity.WmTask;
import com.qunzhixinxi.hnqz.admin.entity.WmTaskContent;
import com.qunzhixinxi.hnqz.admin.entity.WmTaskRule;
import com.qunzhixinxi.hnqz.admin.entity.WmTaskType;
import com.qunzhixinxi.hnqz.admin.entity.XlsPackageInfo;
import com.qunzhixinxi.hnqz.admin.entity.XlsTask;
import com.qunzhixinxi.hnqz.admin.entity.dto.CommonEvidenceDTO;
import com.qunzhixinxi.hnqz.admin.entity.model.excel.CommonTaskExcelModel;
import com.qunzhixinxi.hnqz.admin.mapper.WmTaskMapper;
import com.qunzhixinxi.hnqz.admin.service.ReportExportService;
import com.qunzhixinxi.hnqz.admin.service.SysDeptService;
import com.qunzhixinxi.hnqz.admin.service.SysFileService;
import com.qunzhixinxi.hnqz.admin.service.SysUserService;
import com.qunzhixinxi.hnqz.admin.service.WmDaAgentService;
import com.qunzhixinxi.hnqz.admin.service.WmDaDistributionService;
import com.qunzhixinxi.hnqz.admin.service.WmDaDrugEntService;
import com.qunzhixinxi.hnqz.admin.service.WmDaHospitalService;
import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
import com.qunzhixinxi.hnqz.admin.service.WmTaskContentService;
import com.qunzhixinxi.hnqz.admin.service.WmTaskRuleService;
import com.qunzhixinxi.hnqz.admin.service.WmTaskService;
import com.qunzhixinxi.hnqz.admin.service.WmTaskTypeService;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 任务表
 *
 * @author gaoyanng
 * @date 2020-06-25 23:35:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wmtask")
@Api(value = "wmtask", tags = "任务表管理")
@Slf4j
public class WmTaskController {

	private final WmTaskService wmTaskService;

	private final WmTaskMapper wmTaskMapper;

	private final WmScorePackageService wmScorePackageService;

	private final SysDeptService sysDeptService;

	private final SysUserService sysUserService;

	private final WmDaDrugEntService wmDaDrugEntService;

	private final WmTaskTypeService wmTaskTypeService;

	private final WmTaskRuleService wmTaskRuleService;

	private final WmDaAgentService wmDaAgentService;

	private final WmDaHospitalService wmDaHospitalService;

	private final WmDaDistributionService wmDaDistributionService;

	private final WmTaskContentService wmTaskContentService;

	private final ReportExportService reportExportService;

	private final SysFileService sysFileService;

	/**
	 * 分页查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/pageSum")
	public R pageSum(Page page, WmTask wmTask) {
		WmScorePackage wmScorePackage = wmScorePackageService.getById(wmTask.getScorePackageId());
		wmScorePackage.setRelationScoreId(wmScorePackage.getId());
		List<WmScorePackage> wmScorePackageList = wmScorePackageService.selectLists(wmScorePackage);
		List<WmTask> list = new ArrayList<>();
		if (wmScorePackageList.size() > 0) {
			WmTask wmTask3 = new WmTask();
			wmTask3.setScorePackageId(wmScorePackage.getId());
			List<WmTask> wmTaskList3 = wmTaskMapper.selectListByIds(wmTask3);
			list.addAll(wmTaskList3);
			List<String> ids2 = wmScorePackageList.stream().map(p -> p.getId()).collect(Collectors.toList());
			for (String id : ids2) {
				WmScorePackage wmScorePackage1 = new WmScorePackage();
				wmScorePackage1.setRelationScoreId(id);
				List<WmScorePackage> wmScorePackageList1 = wmScorePackageService.selectLists(wmScorePackage1);
				WmTask wmTask1 = new WmTask();
				wmTask1.setScorePackageId(id);
				List<WmTask> wmTaskList = wmTaskMapper.selectListByIds(wmTask1);
				List<String> ids3 = wmTaskList.stream().map(p -> p.getId()).collect(Collectors.toList());
				List<String> ids4 = wmScorePackageList1.stream().map(p -> p.getId()).collect(Collectors.toList());
				if (wmScorePackageList1.size() > 0) {
					for (String id1 : ids4) {
						WmTask wmTask2 = new WmTask();
						wmTask2.setScorePackageId(id1);
						List<WmTask> wmTaskList1 = wmTaskMapper.selectListByIds(wmTask2);
						List<String> ids5 = wmTaskList1.stream().map(p -> p.getId()).collect(Collectors.toList());
						for (String id2 : ids5) {
							WmTask wmTaskList2 = wmTaskMapper.selectByRealFlag(Integer.parseInt(id2));
							list.add(wmTaskList2);
						}
					}
				}
				for (String id1 : ids3) {
					WmTask wmTaskList1 = wmTaskMapper.selectByRealFlag(Integer.parseInt(id1));
					list.add(wmTaskList1);
				}
			}
		} else {
			WmTask wmTask1 = new WmTask();
			wmTask1.setScorePackageId(wmScorePackage.getId());
			List<WmTask> wmTaskList1 = wmTaskMapper.selectListByIds(wmTask1);
			list.addAll(wmTaskList1);
		}
		//每页数据条数
		Page<WmTask> page1 = new Page<>();
		int current = new Long(page.getCurrent()).intValue();
		int size = new Long(page.getSize()).intValue();

		int count = list.size();
		List<WmTask> pageList = new ArrayList<>();
		//计算当前页第一条数据的下标
		int currId = current > 1 ? (current - 1) * size : 0;
		for (int i = 0; i < size && i < count - currId; i++) {
			pageList.add(list.get(currId + i));
		}
		page1.setSize(size);
		page1.setCurrent(current);
		page1.setTotal(count);
		//计算分页总页数
		page1.setPages(count % 10 == 0 ? count / 10 : count / 10 + 1);
		page1.setRecords(pageList);
//			pageAnswer.setRecords(list);
//		}
		return R.ok(page1);
	}


	/**
	 * 分页查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_view')" )
	public R getWmTaskPage(Page page, WmTask wmTask) {
		OrderItem orderItem = new OrderItem();
		orderItem.setColumn("create_time");
		orderItem.setAsc(false);
		page.addOrder(orderItem);
		if (page.getSize() > 500) {
			page.setSize(-1);

		}

		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");
		LambdaQueryWrapper<WmTask> lambdaQueryWrapper = Wrappers.lambdaQuery();
		lambdaQueryWrapper.orderByDesc(WmTask::getCreateTime);

		if (SecurityUtils.getRoles().contains(3)) {
			lambdaQueryWrapper.isNotNull(WmTask::getScorePackageDrugId);
			lambdaQueryWrapper.eq(WmTask::getSubmitStatus, "1");
		}

		if (null != wmTask.getScorePackageDrugId()) {
			if (SecurityUtils.getRoles().contains(3) || SecurityUtils.getRoles().contains(2)) {
				lambdaQueryWrapper.eq(WmTask::getScorePackageDrugId, wmTask.getScorePackageDrugId());
			} else {
				QueryWrapper wrappers = Wrappers.query().like(true, "score_id", wmTask.getScorePackageDrugId());
				List<WmScorePackage> wmScorePackageList = wmScorePackageService.list(wrappers);
				if (wmScorePackageList.size() > 0) {
					List<String> stringList = new ArrayList<>();
					for (WmScorePackage wms : wmScorePackageList) {
						stringList.add(wms.getId());
					}

					if (stringList.size() == 0) {
						stringList.add("-1");
					}

					lambdaQueryWrapper.and(Wrapper -> Wrapper.in(WmTask::getScorePackageId, stringList).or().in(
							WmTask::getScorePackageDrugId, stringList
					));

				}
			}
		}

		if (null != wmTask.getTaskUserId()) {
			LambdaQueryWrapper<SysUser> lambdaQueryWrapperUser = Wrappers.lambdaQuery();
			lambdaQueryWrapperUser.like(SysUser::getRealname, wmTask.getTaskUserId());
			List<SysUser> list = sysUserService.list(lambdaQueryWrapperUser);
			if (list.size() > 0) {
				List<String> listUser = new ArrayList<>();
				for (SysUser sysUser : list) {
					listUser.add(sysUser.getUserId() + "");
				}

				if (listUser.size() == 0) {
					listUser.add("-1");
				}

				lambdaQueryWrapper.in(WmTask::getTaskUserId, listUser);

			}
		}


		if (!SecurityUtils.getRoles().contains(1) && !SecurityUtils.getRoles().contains(2)) {
			lambdaQueryWrapper.eq(WmTask::getDrugEntId, SecurityUtils.getUser().getDrugEntId());

		}

		if (null != wmTask.getTaskTypeId()) {
			lambdaQueryWrapper.eq(WmTask::getTaskTypeId, wmTask.getTaskTypeId());
		}

		if (null != wmTask.getSubmitStatus()) {
			lambdaQueryWrapper.eq(WmTask::getSubmitStatus, wmTask.getSubmitStatus());
		}

		if (null != wmTask.getPlatAuditStatus()) {
			lambdaQueryWrapper.eq(WmTask::getPlatAuditStatus, wmTask.getPlatAuditStatus());
		}

		if (null != wmTask.getDeptId()) {
			lambdaQueryWrapper.eq(WmTask::getDeptId, wmTask.getDeptId());
		}

		if (null != wmTask.getTaskStatus()) {
			lambdaQueryWrapper.eq(WmTask::getTaskStatus, wmTask.getTaskStatus());
		}

		if (null != wmTask.getCreateTime()) {
			lambdaQueryWrapper.ge(WmTask::getLookintoDate, wmTask.getCreateTime());
		}

		if (null != wmTask.getUpdateTime()) {
			lambdaQueryWrapper.le(WmTask::getLookintoDate, wmTask.getUpdateTime());
		}


		Page pageAnswer = wmTaskService.listTaskPage(page, lambdaQueryWrapper);
		if (null != wmTask.getScorePackageId()) {
			List<WmTask> wmTaskList = pageAnswer.getRecords();
			List<WmTask> wmTaskListNew = new ArrayList<>();
			WmScorePackage wmScorePackage = wmScorePackageService.getById(wmTask.getScorePackageId());

			if (wmScorePackage.getScore() > 0) {
				Integer taskScore = 0;
				for (WmTask wmT : wmTaskList) {
					if (taskScore < wmScorePackage.getScore()) {
						taskScore += wmT.getScore();
						wmTaskListNew.add(wmT);
					}
				}
			}
			pageAnswer.setRecords(wmTaskListNew);
		}
		return R.ok(pageAnswer);
	}


	/**
	 * 分页查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/pageAudit")
	public R pageAudit(Page page, WmTask wmTask, String endDate, String startDate) {

		LocalDateTime _startDate = null;
		LocalDateTime _endDate = null;
		if (StringUtils.isNotEmpty(startDate)) {
			_startDate = LocalDateTime.of(LocalDate.parse(startDate), LocalTime.MIN);
		}
		if (StringUtils.isNotEmpty(endDate)) {
			_endDate = LocalDateTime.of(LocalDate.parse(endDate), LocalTime.MAX);
		}
		IPage<WmTask> iPage = wmTaskService.listInfoAudit(page, wmTask, _startDate, _endDate);
		return R.ok(iPage);
	}


	/**
	 * 分页查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/pageYq")
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_view')" )
	public R getWmTaskPageYq(Page page, WmTask wmTask) {
		OrderItem orderItem = new OrderItem();
		orderItem.setColumn("create_time");
		orderItem.setAsc(false);
		page.addOrder(orderItem);


		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");
		QueryWrapper queryWrapper = Wrappers.query();
		if (SecurityUtils.getRoles().contains(1) || SecurityUtils.getRoles().contains(2)) {

		} else {
			queryWrapper.eq(true, "drug_ent_id", SecurityUtils.getUser().getDrugEntId());
			queryWrapper.isNotNull("score_package_drug_id");
		}

		if (null != wmTask.getScorePackageId()) {
			QueryWrapper queryWrapper1 = Wrappers.query();
			List<WmScorePackage> wmScorePackageList = wmScorePackageService.list(queryWrapper1.like(true, "score_id", wmTask
					.getScorePackageId()));
			if (wmScorePackageList.size() > 0) {
				List<String> stringList = new ArrayList<>();
				stringList.add("100000000");
				for (WmScorePackage wmScorePackage : wmScorePackageList) {
					stringList.add(wmScorePackage.getId());
				}
				queryWrapper.in("score_package_id", stringList);
			}
		}
		queryWrapper.orderByDesc("create_time");

		return R.ok(wmTaskService.page(page, queryWrapper));
	}


	/**
	 * 通过id查询任务表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_view')" )
	public R getById(@PathVariable("id") Integer id) {
		return R.ok(wmTaskService.getById(id));
	}

	/**
	 * 新增任务表
	 *
	 * @param wmTask 任务表
	 * @return R
	 */
	@ApiOperation(value = "新增任务表", notes = "新增任务表")
	@SysLog("新增任务表")
	@PostMapping
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_add')" )
	public R save(@RequestBody WmTask wmTask) {

		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");


		if (null != SecurityUtils.getUser().getDeptId()) {
			wmTask.setDeptId(SecurityUtils.getUser().getDeptId() + "");
		}

		if (null != SecurityUtils.getUser().getDrugEntId()) {
			wmTask.setDrugEntId(SecurityUtils.getUser().getDrugEntId() + "");
		}

		if (null != SecurityUtils.getUser().getId()) {
			wmTask.setTaskUserId(SecurityUtils.getUser().getId() + "");
		}

		if (SecurityUtils.getRoles().contains(5)) {
			wmTask.setTaskUserType("5");
		}

		wmTask.setCreateTime(LocalDateTime.now());

		if (SecurityUtils.getRoles().contains(6)) {
			wmTask.setTaskUserType("6");
		}

		return R.ok(wmTaskService.save(wmTask));
	}

	/**
	 * 修改任务表
	 *
	 * @param wmTask 任务表
	 * @return R
	 */
	@ApiOperation(value = "修改任务表", notes = "修改任务表")
	@SysLog("修改任务表")
	@PutMapping
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_edit')" )
	public R updateById(@RequestBody WmTask wmTask) {
		wmTask.setUpdateUser(SecurityUtils.getUser().getId() + "");
		wmTask.setUpdateTime(LocalDateTime.now());
		return R.ok(wmTaskService.updateById(wmTask));
	}

	/**
	 * 通过id删除任务表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除任务表", notes = "通过id删除任务表")
	@SysLog("通过id删除任务表")
	@DeleteMapping("/{id}")
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_del')" )
	public R removeById(@PathVariable Integer id) {
		return R.ok(wmTaskService.removeById(id));
	}


	/**
	 * 获取药企列表
	 *
	 * @return 角色列表
	 */
	@GetMapping("/list")
	public R listWmScorePackage(WmTask wmTask) {
		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");
		return R.ok(wmTaskService.list(Wrappers.query(wmTask)));
	}


	/**
	 * 提交任务
	 *
	 * @return 角色列表
	 */
	@PostMapping("/submitTask")
	public R submitTask(String ids, String type, String packageId) {
		if (null == ids) {
			return R.failed("任务ID不能为空");
		}
		List<String> idlist = new ArrayList<>();
		String[] idArray = ids.split(",");
		for (int i = 0; i < idArray.length; i++) {
			if (null != idArray[i] && !"".equals(idArray[i].trim())) {
				idlist.add(idArray[i]);
			}
		}

		List<WmTask> list = wmTaskService.list(Wrappers.<WmTask>lambdaQuery().in(WmTask::getId, idlist));
		if (list.size() > 0) {
			for (WmTask wm :
					list) {
				if ("1".equals(type)) {
					wm.setTaskStatus("2");
					wm.setSubmitStatus("1");
				} else if ("2".equals(type)) {
					wm.setTaskStatus("3");
				} else if ("3".equals(type)) {
					wm.setTaskStatus("4");
				}
				wm.setScorePackageDrugId(packageId);
			}
		}

		wmTaskService.saveOrUpdateBatch(list, list.size());

		WmScorePackage wmScorePackage = wmScorePackageService.getById(packageId);
		if (null != wmScorePackage) {
			WmTask wmTask = new WmTask();
			wmTask.setScorePackageDrugId(packageId);
			List<WmTask> wmTaskList = wmTaskService.list(Wrappers.query(wmTask));
			int score = 0;
			for (WmTask wmt : wmTaskList) {
				score += wmt.getScore();
			}
			System.out.println("score:" + score);
			System.out.println("wmScorePackage.getScore():" + wmScorePackage.getScore());

			if (score >= wmScorePackage.getScore()) {
				wmScorePackage.setPackageFinishStatus("1");
				wmScorePackage.setPackageFinishTime(LocalDateTime.now());
				wmScorePackageService.updateById(wmScorePackage);
			}
		}

		return R.ok();
	}


	/**
	 * 计算待提交积分
	 *
	 * @return 角色列表
	 */
	@GetMapping("/getTotalScore")
	public R getTotalScore(WmTask wmTask) {
		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");
		wmTask.setTaskStatus("1");

		List<WmTask> wmTaskList = wmTaskService.listTask(Wrappers.query(wmTask));
		Map<String, Object> map = new HashMap<>();
		int count = wmTaskList.size();
		int countScore = 0;
		for (WmTask wmT :
				wmTaskList) {
			countScore += wmT.getScore();
		}
		map.put("totalCount", count);
		map.put("countScore", countScore);

		return R.ok(map);
	}


	/**
	 * 获取药企列表
	 *
	 * @return 角色列表
	 */
	@GetMapping("/wmTaskList")
	public R wmTaskList(WmTask wmTask) {
		WmTask wmDaDrugEnt = new WmTask();
		wmDaDrugEnt.setDelFlag("0");
		wmDaDrugEnt.setEnableFlag("0");
		return R.ok(wmTaskService.list(Wrappers.query(wmDaDrugEnt)));
	}


	/**
	 * 获取药企列表
	 *
	 * @return 角色列表  --audit==taskStatus 3代表审核通过
	 */
	@PostMapping("/auditList")
	public R listWmScorePackage(@RequestBody AuditEntity auditEntity) {
		if (null == auditEntity.getIds()) {
			R.failed("至少选择一条数据");
		}

		String[] args = auditEntity.getIds().split(",");

		if (auditEntity.getIds().split(",").length > 0) {

			List<String> list = new ArrayList<>();
			for (String str : args) {
				list.add(str);
			}
			List<WmTask> wmTasks = wmTaskService.listByIds(list);

			for (WmTask wmTask : wmTasks) {
				wmTask.setTaskStatus(auditEntity.getAudit());
				//wmTask.setPlatAuditStatus("1");
//				if("15".equals(wmTask.getTaskTypeId()))
//				{
//					wmDaHospitalService.saveOrUpdateHospitalByTask(wmTask);
//				}
//
//				if("16".equals(wmTask.getTaskTypeId()))
//				{
//					wmDaHospitalService.saveOrUpdateHospitalByTask(wmTask);
//				}

			}
//			wmTaskService.saveOrUpdateBatch(wmTasks);
			if (wmTasks.size() > 500) {
				int size = 500;
				int total = wmTasks.size() % size == 0 ? wmTasks.size() / size : wmTasks.size() / size + 1;
//				System.out.println(total);
				for (int i = 0; i < total; i++) {
					int start = size * i;
					int end = Math.min(size * (i + 1), wmTasks.size());
					List<WmTask> nlist = wmTasks.subList(start, end);
//					System.out.println(nlist);
					wmTaskService.updateBatchById(nlist);
				}

			} else {
				wmTaskService.updateBatchById(wmTasks);
			}

		}

		WmScorePackage wmScorePackage = wmScorePackageService.getById(auditEntity.getScorePackageDrugId());
		if (null != wmScorePackage) {
			if ("1".equals(wmScorePackage.getPackageFinishStatus())) {
				wmScorePackage.setPackageAuditStatus("1");
			}
		}

		return R.ok(wmScorePackageService.updateById(wmScorePackage));
	}

	@GetMapping("/exportTask")
	public void e1(Page page, WmTask wmTask, HttpServletResponse response) throws IOException {
		page.setSize(1000);
		page.setCurrent(1);
		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");
		String packageId = wmTask.getScorePackageId();
		if (null == packageId) {
			packageId = wmTask.getScorePackageDrugId();
		}
		List<XlsTask> xlsTaskList = new ArrayList<>();

		wmTask.setScorePackageId(null);
		wmTask.setScorePackageDrugId(null);
		if (SecurityUtils.getRoles().contains(1) || SecurityUtils.getRoles().contains(2)) {

		} else {
			wmTask.setDrugEntId(SecurityUtils.getUser().getDrugEntId());
		}

		SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
		if (sysDept.getLevel() == 1) {
			wmTask.setScorePackageDrugId(packageId);
		}

		if (sysDept.getLevel() == 2) {
			wmTask.setScorePackageDrugId(packageId);
		}

		if (sysDept.getLevel() == 3) {
			wmTask.setScorePackageDrugId(packageId);
		}

		if (sysDept.getLevel() == 4) {
			wmTask.setScorePackageId(packageId);
		}

		Integer taskCountAll = 0;
		Integer taskSumAll = 0;

		String taskTypeName1 = "";
		Integer taskCount1 = 0;
		Integer taskSum1 = 0;

		String taskTypeName2 = "";
		Integer taskCount2 = 0;
		Integer taskSum2 = 0;

		String taskTypeName3 = "";
		Integer taskCount3 = 0;
		Integer taskSum3 = 0;

		String taskTypeName4 = "";
		Integer taskCount4 = 0;
		Integer taskSum4 = 0;
		Page pageAnswer = wmTaskService.listTaskPage(page, Wrappers.query(wmTask).orderByDesc("create_time"));
		WmScorePackage wmScorePackage = null;
		List<XlsPackageInfo> xlsPackageInfoList = new ArrayList<>();
		if (null != packageId) {
			List<WmTask> wmTaskList = pageAnswer.getRecords();
			List<WmTask> wmTaskListNew = new ArrayList<>();
			wmScorePackage = wmScorePackageService.getById(packageId);

			if (wmScorePackage.getScore() > 0) {
				Integer taskScore = 0;

				//判断当前积分包已有任务积分
				WmTask wmTask1 = new WmTask();
				wmTask1.setDelFlag("0");
				wmTask1.setEnableFlag("0");
				if (sysDept.getLevel() == 4) {
					wmTask1.setScorePackageId(packageId);
				} else {
					wmTask1.setScorePackageDrugId(packageId);
				}
				wmTask1.setTaskStatus(wmTask.getTaskStatus());
				List<WmTask> list = wmTaskService.list(Wrappers.query(wmTask1));

				if (list.size() > 0) {
					for (WmTask wmt : list) {
						if (taskScore >= wmScorePackage.getScore()) {
							taskScore = wmScorePackage.getScore();
						} else {
							taskScore += wmt.getScore();
						}

						wmTaskListNew.add(wmt);

					}
				}

//				for (WmTask wmT:wmTaskList) {
//					if(taskScore<=wmScorePackage.getScore())
//					{
//						taskScore+=wmT.getScore();
//						wmTaskListNew.add(wmT);
//					}else{
//						break;
//					}
//				}
			}

			DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
			taskTypeName1 = "会议举办";
			taskTypeName2 = "客户拜访";
			taskTypeName3 = "文章分享";
			taskTypeName4 = "客户拜访";

			for (WmTask wmT : wmTaskListNew) {
				taskSumAll += wmT.getScore();
				Integer taskType = Integer.parseInt(wmT.getTaskTypeId());
				if (taskType >= 1 && taskType <= 4) {
					taskCount1 = taskCount1 + 1;
					taskSum1 += wmT.getScore();
				} else if (taskType >= 5 && taskType <= 6) {
					taskCount2 = taskCount2 + 1;
					taskSum2 += wmT.getScore();
				} else if (taskType >= 7 && taskType <= 11) {
					taskCount3 = taskCount3 + 1;
					taskSum3 += wmT.getScore();
				} else if (taskType >= 12 && taskType <= 17) {
					taskCount4 = taskCount4 + 1;
					taskSum4 += wmT.getScore();
				}


				XlsTask xlsTask = new XlsTask();
				xlsTask.setCreateTime(dtf2.format(wmT.getCreateTime()));

				xlsTask.setDeptName(sysDept.getName());

				WmDaDrugEnt wmDaDrugEnt = wmDaDrugEntService.getById(wmT.getDrugEntId());
				xlsTask.setDrugEntName(wmDaDrugEnt.getEntname());

				xlsTask.setScore(wmT.getScore());

				SysUser sysUser = sysUserService.getById(wmT.getTaskUserId());
				xlsTask.setUsername(sysUser.getRealname());

				WmTaskType wmTaskType = wmTaskTypeService.getById(wmT.getTaskTypeId());
				xlsTask.setTaskType(wmTaskType.getTaskTypeName());

				xlsTaskList.add(xlsTask);
				System.out.println("xlsTaskList:" + xlsTaskList.size());
			}
		}

		//String basePath="/Users/gaoyang/Desktop/xlst";
		String basePath = "";
		String templateFileName = "/drugEnt.xlsx";

		String fileName = basePath + "/" + System.currentTimeMillis() + ".xlsx";
		ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(basePath + templateFileName).build();
		WriteSheet writeSheet = EasyExcel.writerSheet().build();
		// 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
		// forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
		// 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
		// 如果数据量大 list不是最后一行 参照下一个

		FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
		excelWriter.fill(xlsTaskList, fillConfig, writeSheet);
		excelWriter.fill(xlsPackageInfoList, fillConfig, writeSheet);
		Map<String, Object> map = new HashMap<String, Object>();
		if (xlsTaskList.size() > 0) {
			map.put("drugent", xlsTaskList.get(0).getDrugEntName());
		}
		map.put("scoreId", wmScorePackage.getScoreId());
		map.put("taskCountAll", xlsTaskList.size());
		map.put("taskSumAll", taskSumAll);


		map.put("taskTypeName1", taskTypeName1);
		map.put("taskCount1", taskCount1);
		map.put("taskSum1", taskSum1);

		map.put("taskTypeName2", taskTypeName2);
		map.put("taskCount2", taskCount2);
		map.put("taskSum2", taskSum2);

		map.put("taskTypeName3", taskTypeName3);
		map.put("taskCount3", taskCount3);
		map.put("taskSum3", taskSum3);

		map.put("taskTypeName4", taskTypeName4);
		map.put("taskCount4", taskCount4);
		map.put("taskSum4", taskSum4);

		WmTaskRule wmTaskRule = wmTaskRuleService.getById(wmScorePackage.getTaskRuleId());
		String entDate = wmTaskRule.getRuleMonth() + "-31";
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			format.parse(entDate);
		} catch (Exception ex) {
			entDate = wmTaskRule.getRuleMonth() + "-30";
		}
		map.put("date", wmTaskRule.getRuleMonth() + "-01 至 " + entDate);

		WmDaAgent wmDaAgent = wmDaAgentService.getById(wmScorePackage.getLevel1Id());
		if (null != wmDaAgent) {
			map.put("ent", wmDaAgent.getGsmc());
		} else {
			map.put("ent", "");
		}
		excelWriter.fill(map, writeSheet);
		excelWriter.finish();


		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");

		// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
		String fileName1 = null;
		try {
			fileName1 = URLEncoder.encode("测试", "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		File f = ResourceUtils.getFile(fileName);


		InputStream bis = new BufferedInputStream(new FileInputStream(f));
		//假如以中文名下载的话，设置下载文件名称
		String filename = "导入模板.xls";
		//转码，免得文件名中文乱码
		filename = URLEncoder.encode(filename, "UTF-8");
		//设置文件下载头
		response.addHeader("Content-Disposition", "attachment;filename=" + filename);
		//1.设置文件ContentType类型，这样设置，会自动判断下载文件类型
		response.setContentType("application/vnd.ms-excel");
		BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
		int len = 0;
		while ((len = bis.read()) != -1) {
			out.write(len);
			out.flush();
		}
		out.close();
	}


	@GetMapping("/exportTaskInfo")
	public void exportTaskInfo(Page page, WmTask wmTask, HttpServletResponse response) throws IOException {


	}

	/**
	 * 获取药企列表
	 *
	 * @return 角色列表
	 */
	@GetMapping("/getHTaskInfo")
	public R getHTaskInfo(String taskId) {
		WmTask wmDaDrugEnt = new WmTask();
		wmDaDrugEnt.setDelFlag("0");
		wmDaDrugEnt.setEnableFlag("0");

		Map<String, Object> map = new HashMap<>();

		WmTask wmTask = wmTaskService.getById(taskId);
		if (null != wmTask) {
			WmTaskContent wmTaskContent = wmTaskContentService.getById(wmTask.getTaskContentId());
			map.put("content", wmTaskContent);
			if (null != wmTaskContent) {
				WmDaHospital wmDaHospital = new WmDaHospital();
				wmDaHospital.setDelFlag("0");
				wmDaHospital.setDelFlag("0");
				wmDaHospital.setYymc(wmTaskContent.getTemp3());

				List<WmDaHospital> list = wmDaHospitalService.list(Wrappers.query(wmDaHospital));
				if (list.size() == 1) {
					map.put("hospital", list.get(0));

				}
			}

		}
		return R.ok(map);
	}


	/**
	 * 获取药企列表
	 *
	 * @return 角色列表
	 */
	@GetMapping("/getATaskInfo")
	public R getATaskInfo(String taskId) {
		WmTask wmDaDrugEnt = new WmTask();
		wmDaDrugEnt.setDelFlag("0");
		wmDaDrugEnt.setEnableFlag("0");

		Map<String, Object> map = new HashMap<>();

		WmTask wmTask = wmTaskService.getById(taskId);
		if (null != wmTask) {
			WmTaskContent wmTaskContent = wmTaskContentService.getById(wmTask.getTaskContentId());
			map.put("content", wmTaskContent);
			if (null != wmTaskContent) {
				WmDaDistribution wmDaHospital = new WmDaDistribution();
				wmDaHospital.setDelFlag(0);
				wmDaHospital.setDelFlag(0);
				wmDaHospital.setShyshxydm(wmTaskContent.getTemp6());

				List<WmDaDistribution> list = wmDaDistributionService.list(Wrappers.query(wmDaHospital));
				if (list.size() == 1) {
					map.put("hospital", list.get(0));

				}
			}

		}
		return R.ok(map);
	}


	/**
	 * 分页查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/pageExtList")
	//@PreAuthorize("@pms.hasPermission('admin_wmtask_view')" )
	public R pageExtList(Page page, WmTask wmTask) {
		OrderItem orderItem = new OrderItem();
		orderItem.setColumn("create_time");
		orderItem.setAsc(false);
		page.addOrder(orderItem);

		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");

		List<String> stringList = new ArrayList<>();
		if (null != wmTask.getDrugEntId() && !"".equals(wmTask.getDrugEntId())) {
			stringList.add(wmTask.getDrugEntId());
		} else {
			SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
			if (null != sysDept) {
				String levelId = "";
				if (sysDept.getLevel() == 3) {
					levelId = sysDept.getLevel2Id() + "";
				} else {
					levelId = sysDept.getLevel3Id() + "";
				}
				WmDaAgent wmDaAgent = wmDaAgentService.getById(levelId);

				if (null != wmDaAgent && null != wmDaAgent.getExtDrugEnt() && !"".equals(wmDaAgent.getExtDrugEnt())) {
					String extDrugEnt = wmDaAgent.getExtDrugEnt();
					String ext[] = extDrugEnt.split(",");
					for (String args : ext) {
						if (!(sysDept.getLevel1Id() + "").equals(args)) {
							stringList.add(args);
						}
					}
				}
			}
		}
		if (stringList.size() == 0) {
			stringList.add("-1");
		}
		wmTask.setExtIds(stringList);
		wmTask.setDrugEntId(SecurityUtils.getUser().getDrugEntId());
		IPage<WmTask> pageAnswer = wmTaskService.listTaskByExt(page, wmTask);
		return R.ok(pageAnswer);
	}

	/**
	 * 获取任务列表
	 *
	 * @return 任务列表
	 */
	@GetMapping("/selectList")
	public R selectList(Page page, WmScorePackage wmScorePackage) {
		return wmTaskService.selectList(page, wmScorePackage);
	}

	/**
	 * 获取已完成积分值及所做任务数量
	 */
	@GetMapping("/selectScore")
	public R select1(WmTask wmTask) {
		return wmTaskService.selectZbCount(wmTask);
	}

	/**
	 * 获取已完成积分值及所做任务数量
	 */
	@GetMapping("/selectReport")
	public R select(WmTask wmTask) {
		return wmTaskService.selectByWmTask(wmTask);
	}

	/**
	 * 获取积分包所关联的任务
	 */
	@GetMapping("/selectByWmTaskId")
	public R selectByWmTaskId(WmTask wmTask) {
		return wmTaskService.selectByWmTaskId(wmTask);
	}

	/**
	 * 获取已完成积分值及所做任务数量
	 */
	@GetMapping("/saveAndUpdateWmTask")
	public R saveAndUpdateWmTask(WmTask wmTask, WmReport wmReport) {
		return wmTaskService.saveAndUpdateWmTask(wmTask, wmReport);
	}

	/**
	 * 获取已完成积分值及所做任务数量--生成报告并提交审核
	 */
	@GetMapping("/saveAndUpdateWmReport")
	public R saveAndUpdateWmReport(WmTask wmTask, WmReport wmReport) {
		return wmTaskService.saveAndUpdateWmReport(wmTask, wmReport);
	}

	/**
	 * 分派积分--查看
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "分派积分--查看", notes = "分派积分--查看")
	@GetMapping("/getWmTaskList")
	public R getWmTaskList(Page page, WmTask wmTask) {
		if (page.getSize() > 500) {
			page.setSize(-1);
		}
		if (StringUtils.isEmpty(wmTask.getScorePackageId())) {
			return R.failed("缺少参数：积分包id");
		}

		return wmTaskService.getWmTaskList(page, wmTask);
	}

	/**
	 * 任务审核
	 *
	 * @param wmTask
	 * @return
	 */
	@ApiOperation(value = "任务审核", notes = "任务审核")
	@SysLog("任务审核")
	@PostMapping("/approvalTask")
	public R approvalTask(@RequestBody WmTask wmTask) {
		if (StringUtils.isEmpty(wmTask.getId())) {
			R.failed("任务id不能为空");
		}
		return wmTaskService.approvalTask(wmTask);
	}

	/**
	 * 新增举证--结算包举证
	 *
	 * @param wmTask 任务表
	 * @return R
	 */
	@ApiOperation(value = "新增举证", notes = "新增举证")
	@SysLog("新增举证")
	@PostMapping("/saveTaskSettle")
	public R saveTaskSettle(@RequestBody WmTask wmTask) {

		return wmTaskService.saveTaskSettle(wmTask);
	}

	/**
	 * 患者教育-处方上传（WmTask的子对象WmTaskContent的字段含义：temp1-接单人id，temp2-医生姓名，temp3-患者姓名，temp4-处方单编号，
	 * temp5-开具处方时间，temp6-患教服务费，temp7-诊断，temp8-剂型，temp9-审方药师，temp10-发货方，temp11-药品，temp12-用法用量，
	 * temp13-补充说明）
	 *
	 * @param wmTask 任务表
	 * @return R
	 */
	@ApiOperation(value = "患者教育-处方上传", notes = "患者教育-处方上传")
	@SysLog("患者教育-处方上传")
	@PostMapping("/saveTaskPrescription")
	public R saveTaskPrescription(@RequestBody WmTask wmTask) {
		// 校验
		WmTaskContent taskContent = wmTask.getWmTaskContent();
		if (taskContent == null || StringUtils.isAnyBlank(wmTask.getScorePackageId(),
				taskContent.getTemp2(), taskContent.getTemp3(), taskContent.getTemp4(), taskContent.getTemp5(),
				taskContent.getTemp6(), taskContent.getTemp7(), taskContent.getTemp8(), taskContent.getTemp9(),
				taskContent.getTemp10(), taskContent.getTemp11())) {
			return R.failed("必填参数为空");
		}
		return wmTaskService.saveTaskPrescription(wmTask);
	}

	/**
	 * 保存举证--结算包举证
	 *
	 * @param wmTask 任务表
	 * @return R
	 */
	@ApiOperation(value = "保存举证", notes = "保存举证")
	@SysLog("保存举证")
	@PostMapping("/updateTaskSettle")
	public R updateTaskSettle(@RequestBody WmTask wmTask) {

		return wmTaskService.updateTaskSettle(wmTask);
	}


	/**
	 * 举证上传-列表查询
	 *
	 * @param page   分页对象
	 * @param wmTask 任务表
	 * @return
	 */
	@ApiOperation(value = "举证上传-列表查询", notes = "举证上传-列表查询")
	@GetMapping("/selectSettleTask")
	public R selectSettleTask(Page page, WmTask wmTask) {

		return R.ok(wmTaskService.selectSettleTask(page, wmTask));
	}

	/**
	 * 任务中心--导出汇总或详情
	 *
	 * @param wmScorePackage
	 * @return
	 * @throws IOException
	 */
	@GetMapping("/exportNba")
	public R exportNba(WmScorePackage wmScorePackage) throws IOException {
		wmScorePackage = wmScorePackageService.getById(wmScorePackage.getId());
		List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
		//更新任务表审批意见
		WmTask wmTask = new WmTask();
		wmTask.setDelFlag("0");
		wmTask.setEnableFlag("0");

		if (null == taskList || taskList.size() <= 0) {
			return R.failed("未查询到该报告关联的审批通过的任务");
		}
		String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining(","));
		wmTask.setScorePackageId(wmScorePackage.getId());
		wmTask.setId(ids);

		return reportExportService.exportNba(wmTask, wmScorePackage);//报告汇总


	}

	/**
	 * 结算包--获取任务详情
	 *
	 * @param taskId
	 * @return
	 * @throws IOException
	 */
	@Inner(false)
	@GetMapping("/getTaskInfo")
	public R getTaskInfo(String taskId) {
		return wmTaskService.getTaskInfo(taskId);
	}

	/**
	 * 查询调查信息审核数据
	 *
	 * @param taskId 任务id
	 * @return
	 */
	@GetMapping("/survey-task-info/{taskId}")
	public R<?> getSurveyTaskInfo(@PathVariable("taskId") String taskId) {
		return wmTaskService.getSurveryTaskInfo(taskId);
	}

	/**
	 * 患者教育-处方列表
	 *
	 * @param scorePackageId 积分包id
	 * @param prescriptionNo 处方单编号
	 * @return 处方列表
	 */
	@ApiOperation(value = "患者教育-处方列表", notes = "患者教育-处方列表")
	@GetMapping("/listTaskPrescription")
	public R listTaskPrescription(Page page, String scorePackageId, @RequestParam(value = "temp3", required = false) String prescriptionNo) {
		if (StringUtils.isBlank(scorePackageId)) {
			return R.failed("积分包id不能为空");
		}
		IPage<WmTaskContent> taskContentIPage = wmTaskService.listTaskPrescription(page, scorePackageId, prescriptionNo);
		return R.ok(taskContentIPage);
	}

	/**
	 * 患者教育-处方删除
	 *
	 * @param id WmTask的id
	 * @return
	 */
	@ApiOperation(value = "患者教育-处方删除", notes = "患者教育-处方删除")
	@PostMapping("/deleteTaskPrescription/{id}")
	public R deleteTaskPrescription(@PathVariable Integer id) {
		if (id == null) {
			return R.failed("id不能为空");
		}
		wmTaskService.deleteTaskPrescription(id);
		return R.ok();
	}


	/**
	 * 批量上传证据链
	 *
	 * 如果当前积分包名称为{@code null},
	 * 则表示只接受当前积分包的证据链，不允许多包上传。
	 * 否则不做限制
	 *
	 * @param dataList    excel表数据
	 * @param packageName 当前积分包名称
	 * @return 上传结果
	 */
	@PostMapping(value = "/task-batch-import")
	public R taskBatch(@RequestExcel List<CommonTaskExcelModel> dataList,
					   @RequestParam(value = "fileId") Integer fileId,
					   @RequestParam(value = "packageName", required = false) String packageName) {

		// 参数校验
		if (CollectionUtils.isEmpty(dataList)) {
			log.error("空报表，不能上传");
			return R.failed("空报表，不能上传");
		}

		SysFile byId = sysFileService.getById(fileId);
		if (byId == null){
			log.error("无法获取上传文件");
			return R.failed("无法获取上传文件");
		}

		// 封装为DTO，map：key：积分包名称，val：证据链内容
		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		Map<String, List<CommonEvidenceDTO>> DTOMap = new HashMap<>();
		dataList.forEach(excelModel -> {
			CommonEvidenceDTO evidenceDTO = new CommonEvidenceDTO();
			evidenceDTO.setId(excelModel.getId().trim());
			evidenceDTO.setRealName(excelModel.getRealName().trim());
			evidenceDTO.setUsername(excelModel.getUsername().trim());
			evidenceDTO.setTargetUsername(excelModel.getTargetUsername().trim());
			String spn = packageName.trim();
			evidenceDTO.setScorePackageName(spn);
			evidenceDTO.setLogs(excelModel.getLogs().trim());
			evidenceDTO.setAuditor(excelModel.getAuditor().trim());
			evidenceDTO.setSubjectNum(excelModel.getSubjectNum().trim());
			evidenceDTO.setWorkstation(excelModel.getWorkstation());
			evidenceDTO.setVisitStage(excelModel.getVisitStage());
			evidenceDTO.setUploadTime(LocalDate.parse(excelModel.getUploadTime(), df));
			evidenceDTO.setAuditStatus(excelModel.getAuditStatus());
			evidenceDTO.setPassingTime(LocalDate.parse(excelModel.getPassingTime(), df));
			evidenceDTO.setComment(StringUtils.isEmpty(excelModel.getComment()) ? null : excelModel.getComment()
					.trim());
			evidenceDTO.setInvoiceCategory(excelModel.getInvoiceCategory());
			evidenceDTO.setAmount(new BigDecimal(excelModel.getAmount()).setScale(2, RoundingMode.HALF_EVEN));
			evidenceDTO.setFile(byId);

			// 封装结果
			List<CommonEvidenceDTO> commonEvidenceDTOList;
			if (DTOMap.containsKey(spn)) {
				commonEvidenceDTOList = DTOMap.get(spn);
			} else {
				commonEvidenceDTOList = new ArrayList<>();
				DTOMap.put(spn, commonEvidenceDTOList);
			}
			commonEvidenceDTOList.add(evidenceDTO);
		});

		// 实际业务处理
		Map<String, String> errorMap = wmTaskService.taskBatchImport(DTOMap, packageName);

		// 返回上传结果
		Map<String, Object> result = new HashMap<>(3);
		if (errorMap.size() == 0) {
			result.put("code", "SUCCESS");
			result.put("message", "上传成功");
			result.put("data", null);
			return R.ok(result);
		} else {
			log.error("上传数据错误，{}", JSONUtil.toJsonStr(errorMap));
			result.put("code", "FAILURE");
			result.put("message", "上传数据错误");
			result.put("data", errorMap);
			return R.failed(result);

		}
	}

}
