package com.pj.tb_goods_transit;

import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.pj.api.client.admin.AdminInterface;
import com.pj.api.dto.GoodsTransitDto;
import com.pj.api.dto.MessageDto;
import com.pj.common.core.exception.ServiceException;
import com.pj.current.dto.APPLoginUserInfo;
import com.pj.current.satoken.StpAPPUserUtil;
import com.pj.enummj.*;
import com.pj.retry.SmsRetryService;
import com.pj.tb_enterprise.TbEnterprise;
import com.pj.tb_enterprise.TbEnterpriseMapper;
import com.pj.tb_goods.TbGoods;
import com.pj.tb_goods.TbGoodsMapper;
import com.pj.tb_goods_cart.TbGoodsCart;
import com.pj.tb_goods_cart.TbGoodsCartMapper;
import com.pj.tb_goods_cart.TbGoodsCartService;
import com.pj.tb_goods_transit.param.JudgeTransitParam;
import com.pj.tb_goods_transit.param.PurchaseLevelOneGoodsTransitParam;
import com.pj.tb_goods_transit.param.TransactionGoodsParam;
import com.pj.tb_order.MethodOrderService;
import com.pj.tb_order.TbOrder;
import com.pj.tb_order.TbOrderMapper;
import com.pj.tb_order.TbOrderService;
import com.pj.tb_people.TbPeople;
import com.pj.tb_people.TbPeopleMapper;
import com.pj.tb_trade_area.TbTradeArea;
import com.pj.tb_trade_area.TbTradeAreaMapper;
import com.pj.utils.so.SoMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.swing.filechooser.FileSystemView;

import static com.pj.api.consts.FeignFactory.adminInterface;

/**
 * Service: tb_goods_transit -- 审核商户在APP端发布的商品
 * @author qzy
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbGoodsTransitService extends ServiceImpl<TbGoodsTransitMapper, TbGoodsTransit> implements IService<TbGoodsTransit>{

	/** 底层 Mapper 对象 */
	@Autowired
	TbGoodsTransitMapper tbGoodsTransitMapper;
	/** 方法抽取,代码优化 */
	@Autowired
	private MethodGoodsTransitService methodGoodsTransitService;
	/** 监管产品mapper */
	@Autowired
	private TbGoodsMapper tbGoodsMapper;
	@Autowired
	private TbOrderService tbOrderService;
	@Autowired
	private TbOrderMapper tbOrderMapper;
	/** 互市区mapper */
	@Autowired
	private TbTradeAreaMapper tbTradeAreaMapper;
	/** 锁 */
	private Lock lock = new ReentrantLock();

	//边民的授信额度
	//todo: @Value("${quota}")
	 public static final Double QUOTA = 8000.0;

	/** 增 */
	void add(TbGoodsTransit t){
		//获取当前登录人
		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
		if(appLoginInfo == null || appLoginInfo.getLoginId() == null)
			throw new RuntimeException("账户登录信息已失效!请重新登录");
		t.setAuditStatus(AuditStatus.AUDIT_STATUS_ON.getCode());
		t.setCreateBy(String.valueOf(appLoginInfo.getLoginId()));
		t.setCreateName(appLoginInfo.getLoginName());
		t.setCreateTime(new Date());
		t.setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode());
		save(t);
	}

	/** 删 */
	void delete(Long id){
		//防止接单时被外籍商户删除上架的商品
		TbGoodsTransit goodsTransit = tbGoodsTransitMapper.selectById(id);
		if(goodsTransit == null)throw new SecurityException("商品信息异常!");
		//判断商品状态
		if(goodsTransit.getIsOrders().equals(IsOrders.IS_ORDERS_ONE.getCode()))
			throw new ServiceException("您的商品[ " + goodsTransit.getGoodsName() + " ] 已被下单,请先处理下单请求再来进行删除。");
		removeById(id);
	}

	/** 改 */
	void update(TbGoodsTransit t){
		updateById(t);

	}

	/** 查 */
	TbGoodsTransit getById(Long id){
		return super.getById(id);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	List<TbGoodsTransit> getList(SoMap so) {
		return tbGoodsTransitMapper.getList(so);
	}

	/** 查集合 - 根据自己的互市区ID查询对应互市区的商品 */
	List<TbGoodsTransit> getAppList(SoMap so) {
		//获取app登录用户
		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
		if (appLoginInfo == null) throw new RuntimeException("当前登陆用户信息已失效!");
		//添加互市区条件
		so.put("tradeAreaId",appLoginInfo.getTradeAreaId()); // 根据边民的所在互市区匹配其能查看的商品
		so.put("merchantId", appLoginInfo.getFk()); // 外键
		so.put("isOrders",IsOrders.IS_ORDERS_ZERO.getCode()); // 未被下单
		so.set("auditStatus",AuditStatus.AUDIT_STATUS_ON.getCode()); // 审核通过
		so.put("deleteStatus", DeleteStatus.DELETE_STATUS_ON.getCode()); // 未被逻辑删除
		return tbGoodsTransitMapper.getList(so);
	}

	/** 查看一级市场在销/上架商品 */
	List<TbGoodsTransit> getTransitList(SoMap so,String goodsType){
		//设置可展示的状态
		if(goodsType != null){
			so.put("goodsType", goodsType);
		}
		//获取在销商品列表,根据日期进行降序排序
		List<TbGoodsTransit> goodsTransitList = tbGoodsTransitMapper.getList(so);
		return goodsTransitList;
	}

	/** 审核在销商品,可批量 */
	String judgeTransit(JudgeTransitParam judgeTransitParam){
		//获取审核id
		List<String> ids = judgeTransitParam.getIds();
		if(ids.size() == 0)return "没有需要审核的数据。";
		//检查登录
		StpUtil.checkLogin();
		//获取审核状态
		Integer judgeStatus = judgeTransitParam.getJudgeStatus();
		//添加审核计数器
		int count = 0;
		//开始审核
		for (String item : ids) {
			TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectById(item);
			//判断对象值和该对象是否已经审核过了
			if(tbGoodsTransit == null || tbGoodsTransit.getAuditStatus() != 0){
				continue;
			}
			//设置审核状态
			tbGoodsTransit.setAuditStatus(judgeStatus);
			//设置审核内容
			tbGoodsTransit.setRemark(judgeTransitParam.getRemark());
			//设置基本参数
			tbGoodsTransit.setAuditTime(new Date());
			//保存结果
			int i = tbGoodsTransitMapper.updateById(tbGoodsTransit);
			if(i == 1)count += 1;
		}
		return "已完成 " + count + "条 数据审核!";
	}

	/** app端 - 添加需要交易的商品 */
	public boolean transactionGoods(TransactionGoodsParam transactionGoodsParam){
		//判断商品的净重毛重
		Double netWeight = transactionGoodsParam.getNetWeight();
		Double grossWeight = transactionGoodsParam.getGrossWeight();
		if(netWeight > grossWeight){
			throw new RuntimeException("净重超过了毛重,请检查输入。");
		}
		//获取当前登录人
		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
		if(appLoginInfo == null || appLoginInfo.getLoginId() == null)
			throw new RuntimeException("账户登录信息已失效!请重新登录");
		//取出申报商品ID
		Long id = transactionGoodsParam.getId();
		//查询监管产品
		TbGoods tbGoods = tbGoodsMapper.selectById(id);
		if(tbGoods == null)throw new RuntimeException("该产品暂未录入监管列表!");
		//查询互市区
		TbTradeArea tbTradeArea = tbTradeAreaMapper.selectById(transactionGoodsParam.getTradeAreaId());
		if(tbTradeArea == null)throw new RuntimeException("互市区不存在!");
		//执行保存
		TbGoodsTransit tbGoodsTransit = new TbGoodsTransit();
		BeanUtils.copyProperties(transactionGoodsParam,tbGoodsTransit);
		//获取并保存当前商品基本信息
		tbGoodsTransit.setTradeAreaName(tbTradeArea.getName());  // 交易地区(互市区)
		tbGoodsTransit.setGoodsName(tbGoods.getName());  // 商品名称
		tbGoodsTransit.setDescription(tbGoods.getRemark());  // 商品描述
		tbGoodsTransit.setPlaceOrigin(tbGoods.getSource()); // 商品产地
		tbGoodsTransit.setGoodsUnits(tbGoods.getUnit());  // 商品单位
		tbGoodsTransit.setGoodsType(tbGoods.getTypeNames()); // 商品类型名称
		tbGoodsTransit.setGoodsImg(tbGoods.getAvatar());  // 商品图片
		tbGoodsTransit.setGoodsId(tbGoods.getId());//保存监管商品表id
		tbGoodsTransit.setShopId(transactionGoodsParam.getShopId());  // 商铺ID
		tbGoodsTransit.setShopName(transactionGoodsParam.getShopName()); // 商铺名称
		tbGoodsTransit.setSellOut(SellOut.SELL_OUT_ZERO.getCode());//默认商品未售罄
		//商户编号
		tbGoodsTransit.setMerchantId(appLoginInfo.getFk() + ""); // appUser表的外键
		//商户名称
		tbGoodsTransit.setMerchantName(appLoginInfo.getLoginName());  // appUser表昵称

		//保存海关商品表的主键到商品审核表上 todo:原计划是保存[海关申报单号],临时修改成保存海关商品表的主键
		tbGoodsTransit.setDeclareOdd(String.valueOf(tbGoods.getId()));
		//设置默认信息
		tbGoodsTransit.setAuditStatus(AuditStatus.AUDIT_STATUS_ON.getCode());//默认已过审
		tbGoodsTransit.setIsOrders(IsOrders.IS_ORDERS_ZERO.getCode());//默认未被下单
		tbGoodsTransit.setEnterpriseConfirm(ConfirmStatus.CONFIRM_STATUS_ZERO.getCode());//商铺确认情况[0=待确认,1=已确认,2=拒绝]
		//设置基本信息
		tbGoodsTransit.setCreateTime(new Date());
		tbGoodsTransit.setCreateBy(appLoginInfo.getLoginId() + "");
		tbGoodsTransit.setCreateName(appLoginInfo.getLoginName());
		tbGoodsTransit.setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode());
		//执行保存
		int insert = tbGoodsTransitMapper.insert(tbGoodsTransit);
		return insert == 1;
	}

	/** app端 - 商户自行选择上架/下架商品 */
	boolean UpOrDownGoods(Long goodsTransitId , Integer goodsStatus){
		//获取当前登陆人
		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
		if(appLoginInfo == null || appLoginInfo.getLoginId() == null)
			throw new RuntimeException("当前登陆人不存在!");
		//查询当前需要执行上架/下架的商品
		TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectById(goodsTransitId);
		if(tbGoodsTransit == null || tbGoodsTransit.getId() == null)
			throw new RuntimeException("该商品状态异常或不存在!");
		//设置商品状态
		tbGoodsTransit.setGoodsStatus
				(goodsStatus == null || goodsStatus.toString().equals("")?
						tbGoodsTransit.getGoodsStatus() : goodsStatus);
		//设置基本属性
		tbGoodsTransit.setUpdateTime(new Date());
		tbGoodsTransit.setUpdateBy(appLoginInfo.getLoginId().toString());
		tbGoodsTransit.setUpdateName(appLoginInfo.getLoginName());
		//执行保存
		int updateById = tbGoodsTransitMapper.updateById(tbGoodsTransit);
		return updateById == 1;
	}

	/**
	 * 一级市场边民的购买操作
	 * 采购一级市场的商品，
	 * 包括加入购物车、购买、支付（暂时不做），
	 * 下单后会向组内边民发送短信，
	 * 通知其登录APP进行交易确认。
	 */
	public boolean purchaseLevelOntGoodsTransit(PurchaseLevelOneGoodsTransitParam purchaseLevelOntGoodsTransitParam) throws Exception {
		//获取当前登陆人
		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
		if(appLoginInfo == null || appLoginInfo.getLoginId() == null)
			throw new RuntimeException("当前登陆用户信息已失效!");
		//获取商品ID
		String goodsTransitId = purchaseLevelOntGoodsTransitParam.getGoodsTransitId();
		//查询商品
		TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectById(goodsTransitId);
		if(tbGoodsTransit == null || tbGoodsTransit.getId() == null)
			throw new RuntimeException("当前商品信息已失效!");
		if(tbGoodsTransit.getGoodsStatus().equals(GoodsStatus.GOODS_STATUS_OFF.getCode()))
			throw new ServiceException("该商品已下架,无法进行购买!");
		if(tbGoodsTransit.getSellOut().equals(SellOut.SELL_OUT_ONE.getCode()))
			throw new ServiceException("该商品已售罄!");
		//计算价格
		BigDecimal b = new BigDecimal(tbGoodsTransit.getPrice() * purchaseLevelOntGoodsTransitParam.getNumber());
		Double totalPrice = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
		//判断物价是否大于8000
		if(totalPrice > QUOTA)
			throw new ServiceException("您当前购物已大于授信额度,请检查购买信息。");
		//查询当天是否已存在该订单
		LocalDate today = LocalDate.now();
		LocalDateTime startTime = LocalDateTime.of(today, LocalTime.MIN);
		LocalDateTime endTime = LocalDateTime.of(today, LocalTime.MAX);
		List<TbOrder> tbOrderList = tbOrderMapper.selectList(
				new LambdaQueryWrapper<TbOrder>()
						.eq(TbOrder::getCreateBy, appLoginInfo.getLoginId())
						.between(TbOrder::getCreateTime,startTime,endTime)
						.eq(TbOrder::getDeleteStatus,DeleteStatus.DELETE_STATUS_ON.getCode()));
		if(tbOrderList.size() != 0)throw new RuntimeException("当天已下订单,暂时无法继续下单!");
		//检查是否属于海关允许销售商品
		Long goodsId = tbGoodsTransit.getGoodsId();
		TbGoods tbGoods = tbGoodsMapper.selectById(goodsId);
		if(tbGoods == null)throw new RuntimeException("当前商品海关已不允许销售!");
		//查询该商品库存是否有库存
		if(tbGoodsTransit.getStock() == 0.0)throw new ServiceException("当前商品已售罄!");
		//判断数量是否足够
		if(purchaseLevelOntGoodsTransitParam.getNumber() > tbGoodsTransit.getStock())
			throw new ServiceException("购买数量已超上限!");
		try{
			//上锁
			lock.lock();
			// todo: 调用银行接口发送指令,把当前边民下单所使用的额度(totalPrice)发送给银行,我们只需要做发送指令操作,不需要做银行额度是否满足判断
			//执行购买
			//商品库存
			tbGoodsTransit.setStock(tbGoodsTransit.getStock() - purchaseLevelOntGoodsTransitParam.getNumber());
			//如果商品的数量已售罄
			if(new BigDecimal(tbGoodsTransit.getStock()).compareTo(new BigDecimal(0.0)) < 0)
				throw new ServiceException("购买异常!");
			if(new BigDecimal(tbGoodsTransit.getStock()).compareTo(new BigDecimal(0.0)) == 0)
				tbGoodsTransit.setSellOut(SellOut.SELL_OUT_ONE.getCode());
			//保存结果
			int updateById = tbGoodsTransitMapper.updateById(tbGoodsTransit);
			if(updateById == 1){
				//生成小订单
				tbGoodsTransit.setPrice(totalPrice);
				TbOrder tbOrder = methodGoodsTransitService.setTbOrderProperties(tbGoodsTransit, appLoginInfo);
				boolean save = tbOrderService.save(tbOrder);
				if(save){
					//todo: 将交易成功信息推送给航通
					//发送message给商家和买家
					MessageDto dto = new MessageDto();
					dto.setUrl("/pages/market/one/merchant/order/list");
					dto.setUserId(Long.valueOf(tbGoodsTransit.getCreateBy()));
					dto.setContents("你的商品 <<" + tbGoodsTransit.getGoodsName() + ">> " +
							"已出售"+ purchaseLevelOntGoodsTransitParam.getNumber() +
							tbGoodsTransit.getGoodsUnits() + "还剩 "+ tbGoodsTransit.getStock() +
							tbGoodsTransit.getGoodsUnits() +",请前往查看。");
					//执行message发送
					adminInterface.messageSave(dto);
					//执行发送买家
					dto.setUrl("/pages/market/one/merchant/order/list");
					dto.setUserId(appLoginInfo.getLoginId());
					dto.setContents("购买商品 <<" + tbGoodsTransit.getGoodsName() + ">>成功!");
					adminInterface.messageSave(dto);
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}finally {
			//解锁
			lock.unlock();
		}

		throw new RuntimeException("订单预创建异常!");
	}

	/**
	 * 导入
	 * @param file excel文件
	 * @return
	 * @throws IOException
	 */
	public String importData(MultipartFile file) throws IOException {
		System.out.println("\n开始执行文件上传....\n");

		//判空
		if(file.isEmpty()) return "文件为空,无法执行上传...";
		//获取文件上传数据
		HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
		//获取第一页sheet
		HSSFSheet sheet = wb.getSheetAt(0);
		//定义计数器
		int count = 0;
		//定义行对象
		HSSFRow row = null;
		//解析数据封装到集合
		count = methodGoodsTransitService.importMethod(row, sheet, count);
		wb.close();
		System.out.println("\n文件上传完成,共上传 " + count + "条 " + "数据...\n");
		return "上传完成,共上传"  + count + "条"  + "数据。";
	}

	/**
	 * 导出 excel文件
	 * @param keyword
	 * @return
	 */
	public String outportExcel(String keyword,String filepath) throws IOException {
		System.out.println("\n开始执行文件导出....\n");
		//导出的文件的路径
		if(filepath == null || filepath.trim().equals("")){
			// 获取当前用户的桌面路径
			FileSystemView fileSystemView = FileSystemView.getFileSystemView();
			filepath = fileSystemView.getHomeDirectory().getPath();
		}
		filepath = filepath + "\\商家商品审核数据表_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ".xlsx";
		//根据需求查询数据
		List<TbGoodsTransit> selectedList = tbGoodsTransitMapper.selectList(new LambdaQueryWrapper<TbGoodsTransit>().eq(StringUtils.isNoneBlank(keyword), TbGoodsTransit::getMerchantName, keyword));
		if(selectedList.size() == 0)return "没有可导出的数据。";
		//建立excel对象封装数据
		HSSFWorkbook workbook = new HSSFWorkbook();
		//创建excel表格右下角的sheet页名称
		HSSFSheet sheet = workbook.createSheet("1");
		//创建表头
		HSSFRow row = sheet.createRow(0);
		row.createCell(0).setCellValue("序号");
		row.createCell(1).setCellValue("商户编号");
		row.createCell(2).setCellValue("商户名称");
		row.createCell(3).setCellValue("商品类型");
		row.createCell(4).setCellValue("商品名称");
		row.createCell(5).setCellValue("商品单位");
		row.createCell(6).setCellValue("净重");
		row.createCell(7).setCellValue("毛重");
		row.createCell(8).setCellValue("商品价格");
		row.createCell(9).setCellValue("海关申报单号");
		row.createCell(10).setCellValue("产地(国家)");
		row.createCell(11).setCellValue("商品描述");
		row.createCell(12).setCellValue("库存数量");
		row.createCell(13).setCellValue("商品状态");
		row.createCell(14).setCellValue("审核状态");
		row.createCell(15).setCellValue("审核时间");
		row.createCell(16).setCellValue("审核意见");
		row.createCell(17).setCellValue("创建时间");
		row.createCell(18).setCellValue("创建人编号");
		row.createCell(19).setCellValue("创建人名称");
		row.createCell(20).setCellValue("更新时间");
		row.createCell(21).setCellValue("更新人编号");
		row.createCell(22).setCellValue("更新人名称");
		row.createCell(23).setCellValue("删除状态");

		//定义计数器
		int count = 0;
		//遍历集合
		for (int i = 0; i < selectedList.size(); i++) {
			HSSFRow sheetRow = sheet.createRow(sheet.getLastRowNum() + 1);
			sheetRow.createCell(0).setCellValue(i + 1);
			sheetRow.createCell(1).setCellValue((selectedList.get(i).getMerchantId() + "").equals("null")? "": selectedList.get(i).getMerchantId() + "");
			sheetRow.createCell(2).setCellValue((selectedList.get(i).getMerchantName() + "").equals("null")? "": selectedList.get(i).getMerchantName() + "");
			sheetRow.createCell(3).setCellValue((selectedList.get(i).getGoodsType() + "").equals("null")? "": selectedList.get(i).getGoodsType() + "");
			sheetRow.createCell(4).setCellValue((selectedList.get(i).getGoodsName() + "").equals("null")? "": selectedList.get(i).getGoodsName() + "");
			sheetRow.createCell(5).setCellValue((selectedList.get(i).getGoodsUnits() + "").equals("null")? "": selectedList.get(i).getGoodsUnits() + "");
			sheetRow.createCell(5).setCellValue((selectedList.get(i).getNetWeight() + "").equals("null")? "": selectedList.get(i).getNetWeight() + "");
			sheetRow.createCell(5).setCellValue((selectedList.get(i).getGrossWeight() + "").equals("null")? "": selectedList.get(i).getGrossWeight() + "");
			sheetRow.createCell(6).setCellValue((selectedList.get(i).getPrice() + "").equals("null")? "": selectedList.get(i).getPrice() + "");
			sheetRow.createCell(6).setCellValue((selectedList.get(i).getDeclareOdd() + "").equals("null")? "": selectedList.get(i).getDeclareOdd() + "");
			sheetRow.createCell(7).setCellValue((selectedList.get(i).getPlaceOrigin() + "").equals("null")? "": selectedList.get(i).getPlaceOrigin() + "");
			sheetRow.createCell(8).setCellValue((selectedList.get(i).getDescription() + "" ).equals("null")? "": selectedList.get(i).getDescription() + "");
			sheetRow.createCell(9).setCellValue((selectedList.get(i).getStock() + "").equals("null")? "": selectedList.get(i).getStock() + "");
			sheetRow.createCell(10).setCellValue((selectedList.get(i).getGoodsStatus() + "").equals("null")? "": selectedList.get(i).getGoodsStatus() + "");
			sheetRow.createCell(11).setCellValue((selectedList.get(i).getAuditStatus() + "").equals("null")? "": selectedList.get(i).getAuditStatus() + "");
			sheetRow.createCell(12).setCellValue((selectedList.get(i).getAuditTime() + "").equals("null")? "": selectedList.get(i).getAuditTime() + "");
			sheetRow.createCell(13).setCellValue((selectedList.get(i).getRemark() + "").equals("null")? "": selectedList.get(i).getRemark() + "");
			//公共字段
			sheetRow.createCell(22).setCellValue((selectedList.get(i).getCreateTime() + "").equals("null")? "": selectedList.get(i).getCreateTime() + "");
			sheetRow.createCell(23).setCellValue((selectedList.get(i).getCreateBy() + "").equals("null")? "": selectedList.get(i).getCreateBy() + "");
			sheetRow.createCell(24).setCellValue((selectedList.get(i).getCreateName() + "").equals("null")? "": selectedList.get(i).getCreateName() + "");
			sheetRow.createCell(25).setCellValue((selectedList.get(i).getUpdateTime() + "").equals("null")? "": selectedList.get(i).getUpdateTime() + "");
			sheetRow.createCell(26).setCellValue((selectedList.get(i).getUpdateBy() + "").equals("null")? "": selectedList.get(i).getUpdateBy() + "");
			sheetRow.createCell(27).setCellValue((selectedList.get(i).getUpdateName() + "").equals("null")? "": selectedList.get(i).getUpdateName() + "");
			sheetRow.createCell(28).setCellValue((selectedList.get(i).getDeleteStatus() + "").equals("null")? "": selectedList.get(i).getDeleteStatus() + "");
			count += 1;
		}
		//建立输出流，输出文件
		FileOutputStream fos = new FileOutputStream(filepath);

		workbook.write(fos);
		fos.flush();
		//关闭输出流
		fos.close();
		workbook.close();
		System.out.println("\n数据导出完成!共导出 " + count + " 条数据。");
		return "数据导出完成!共导出 " + count + " 条数据。";
	}

	/** 远程调用: 根据ID查询过审商品表(tb_goods_transit) */
	GoodsTransitDto getGoodsTransitById(Long goodsTransitId,Long enterpriseId){
		TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectOne(new LambdaQueryWrapper<TbGoodsTransit>().eq(TbGoodsTransit::getId, goodsTransitId).eq(TbGoodsTransit::getMerchantId, enterpriseId));
		GoodsTransitDto goodsTransitDto = new GoodsTransitDto();
		BeanUtils.copyProperties(tbGoodsTransit,goodsTransitDto);
		return goodsTransitDto;
	}

}
