package com.prolog.cs.base.gsp.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageHelper;
import com.prolog.cs.base.gsp.dao.DxiGspDestroyRequestRecordMapper;
import com.prolog.cs.base.gsp.dao.GspUnqualifiedDestroyDMapper;
import com.prolog.cs.base.gsp.dao.GspUnqualifiedDestroyMapper;
import com.prolog.cs.base.gsp.dao.GspUnqualifiedLossDMapper;
import com.prolog.cs.base.gsp.enums.GspUnqualifiedStatus;
import com.prolog.cs.base.gsp.model.DxiGspDestroyRequestRecord;
import com.prolog.cs.base.gsp.model.GspUnqualifiedDestroy;
import com.prolog.cs.base.gsp.model.GspUnqualifiedDestroyD;
import com.prolog.cs.base.gsp.model.GspUnqualifiedLossD;
import com.prolog.cs.base.gsp.resource.ChainClient;
import com.prolog.cs.base.gsp.resource.InventoryClient;
import com.prolog.cs.base.gsp.resource.ItemClient;
import com.prolog.cs.base.gsp.resource.WarehouseClient;
import com.prolog.cs.base.gsp.service.GspUnqualifiedDestroyService;
import com.prolog.cs.base.gsp.service.GspUnqualifiedLossService;
import com.prolog.cs.base.gsp.vo.GspUnqualifiedDestroyDVO;
import com.prolog.cs.base.gsp.vo.GspUnqualifiedLossDVO;
import com.prolog.cs.basic.chain.model.cargo.BaseCargoOwnerMst;
import com.prolog.cs.basic.item.model.BaseMtlItemHealth;
import com.prolog.cs.basic.item.model.BaseMtlItemMst;
import com.prolog.cs.basic.warehouse.model.BaseWmsWarehouseMst;
import com.prolog.cs.basic.warehouse.model.vo.WarehouseLocatorBasicInfo;
import com.prolog.framework.authority.core.dto.UserDTO;
import com.prolog.framework.authority.user.UserTemplate;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.framework.core.exception.ParameterException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.framework.utils.*;
import com.prolog.upcloud.base.inventory.vo.BatchNumberListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class GspUnqualifiedDestroyServiceImpl implements GspUnqualifiedDestroyService {

	@Autowired
	private GspUnqualifiedDestroyMapper mapper;

	@Autowired
	private GspUnqualifiedDestroyDMapper dMapper;

    @Autowired
    private GspUnqualifiedLossDMapper gspUnqualifiedLossDMapper;
    
	@Autowired
	private UserTemplate userTemplate;

	@Autowired
	private ItemClient itemClient;

	@Autowired
	private WarehouseClient warehouseClient;

	@Autowired
	private ChainClient chainClient;
	
	@Autowired
	private DxiGspDestroyRequestRecordMapper dxiGspDestroyRequestRecordMapper;
	
	@Autowired
	private GspUnqualifiedLossService gspUnqualifiedLossService;

	// 添加库存服务 feignClient - by Huanglh 2022-03-01
	@Autowired
	private InventoryClient inventoryClient;
	
	@Override
	public Page<GspUnqualifiedDestroyDVO> listPagePick(String warehouseId, String cargoOwnerId, String lossCode, String itemId, Integer pageSize, Integer pageNum) {
		UserDTO userDTO = userTemplate.getUserDTO();
		String enterpriseId = userDTO.getEnterpriseId();
		PageHelper.startPage(pageNum, pageSize);

		GspUnqualifiedLossD gspUnqualifiedLossD=new GspUnqualifiedLossD();
		gspUnqualifiedLossD.setCargoOwnerId(cargoOwnerId);
		gspUnqualifiedLossD.setItemId(itemId);
		gspUnqualifiedLossD.setLossCode(lossCode);
		gspUnqualifiedLossD.setEnterpriseId(enterpriseId);
		gspUnqualifiedLossD.setWarehouseId(warehouseId);
		List<GspUnqualifiedLossD> list = gspUnqualifiedLossDMapper.listPagePick(gspUnqualifiedLossD);
		if (CollUtil.isEmpty(list)){
			return new Page<>();
		}
		//转换并组装
		List<GspUnqualifiedDestroyDVO> listRet=new ArrayList<>();
		for(GspUnqualifiedLossDVO lossD : gspUnqualifiedLossService.spellGspUnqualifiedLossDVOS(list)){
			GspUnqualifiedDestroyDVO gspUnqualifiedDestroyDVO=new GspUnqualifiedDestroyDVO();
			BeanUtils.copyProperties(lossD, gspUnqualifiedDestroyDVO);
            gspUnqualifiedDestroyDVO.setRefBillId(lossD.getLossId());
			gspUnqualifiedDestroyDVO.setRefBillCode(lossD.getCode());
            gspUnqualifiedDestroyDVO.setRefLineId(lossD.getId());
            String destroyQty = (new BigDecimal(lossD.getLossQty())).subtract(new BigDecimal(lossD.getDestroyingQty())).toString();
			gspUnqualifiedDestroyDVO.setDestroyQty(destroyQty);
			listRet.add(gspUnqualifiedDestroyDVO);
		}
		return PageUtils.getPage(listRet);
	}

	@Override
	@Transactional
	public void add(GspUnqualifiedDestroy dto) {
		String warehouseId = dto.getWarehouseId();
		if (StringUtils.isEmpty(warehouseId))
			throw new ParameterException("仓库不能为空");
		if (dto.getGspUnqualifiedDestroyDList()==null || dto.getGspUnqualifiedDestroyDList().size()==0)
			throw new ParameterException("请选择商品");
		// 必填字段校验
		if (StringUtils.isEmpty(dto.getDestroyReason())) {
			throw new ParameterException("销毁原因不能为空！");
		}
		if (StringUtils.isEmpty(dto.getTransportor())) {
			throw new ParameterException("运输人员不能为空！");
		}
		if (StringUtils.isEmpty(dto.getDestroySite())) {
			throw new ParameterException("销毁地点不能为空！");
		}
		if (StringUtils.isEmpty(dto.getDestroyMode())) {
			throw new ParameterException("销毁方式不能为空！");
		}

		//请求仓库信息
		BaseWmsWarehouseMst wmsWarehouseMst=null;
		RestMessage<BaseWmsWarehouseMst> itemResultWarehouse = warehouseClient.warehouse(warehouseId);
		if (itemResultWarehouse.isSuccess() && itemResultWarehouse.getData() != null) {
			wmsWarehouseMst=itemResultWarehouse.getData();
		}
		if(wmsWarehouseMst==null){
			throw new ParameterException("仓库不能为空");
		}
		UserDTO userDTO = userTemplate.getUserDTO();
		String userId = userDTO.getId();
		String userName = userDTO.getNickname();
		String enterpriseId = userDTO.getEnterpriseId();
		Date date = new Date();
		String id = String.valueOf(SnowFlakeUtils.getId());
		dto.setId(id);
		String code = "XHD"+id.substring(id.length() - 8);
		dto.setCode(code);
		dto.setCreator(userId);
		dto.setCreatorName(userName);
		dto.setGmtCreate(date);
		dto.setModifier(userId);
		dto.setModifierName(userName);
		dto.setGmtModified(date);
		dto.setEnterpriseId(enterpriseId);
		// 销毁没有ERP审批，状态需要直接设置为 ERP_AUDIT_YES
		dto.setStatus(GspUnqualifiedStatus.OUT_AUDIT_YES.getStatus());
		dto.setDcId(wmsWarehouseMst.getDcId());
		mapper.save(dto);
		// 不合格品信息
		List<GspUnqualifiedDestroyD> dList = dto.getGspUnqualifiedDestroyDList();
		
		for (int i = 0; i < dList.size(); i++) {
			GspUnqualifiedDestroyD dModel=dList.get(i);
			String lossQty = dModel.getLossQty();
			String destroyQty = dModel.getDestroyQty();
			if((StringUtils.isBlank(lossQty) || StringUtils.isBlank(destroyQty)) ||
					(new BigDecimal(lossQty)).compareTo(new BigDecimal(destroyQty))<0){
				throw new BizException("销毁数量不能大于报损数量：第"+(i+1)+"行");
			}
			String sonId = String.valueOf(SnowFlakeUtils.getId());
			dModel.setId(sonId);
			dModel.setDestroyId(id);
			dModel.setDestroyCode(code);
			dModel.setRefBillId(dModel.getRefBillId());
			dModel.setRefLineId(dModel.getRefLineId());
			dModel.setDcId(wmsWarehouseMst.getDcId());
			dModel.setWarehouseId(warehouseId);
			dModel.setEnterpriseId(enterpriseId);
			dModel.setCode(String.valueOf(SnowFlakeUtils.getId()));
			if(StringUtils.isBlank(destroyQty)){
                dModel.setDestroyQty(dModel.getUnqualifiedQty());
            }
			dModel.setCreator(userId);
			dModel.setCreatorName(userName);
			dModel.setGmtCreate(date);
			dModel.setModifier(userId);
			dModel.setModifierName(userName);
			dModel.setGmtModified(date);
			dMapper.save(dModel);
			gspUnqualifiedLossDMapper.updateDestroyingQty(dModel.getRefLineId(), new BigDecimal(destroyQty));
		}
	}

	@Override
	@Transactional
	public void delIds(List<String> pkIdList) {
		// TODO
		pkIdList.stream().forEach(p ->
			this.mapper.deleteById(p,GspUnqualifiedDestroy.class));
	}

	@Override
	public List<GspUnqualifiedDestroyDVO> findDetailByMstId(String mstId){
		if(StringUtils.isBlank(mstId)){
			return new ArrayList<>();
		}
		Criteria crt = Criteria.forClass(GspUnqualifiedDestroyD.class);
		Restriction r1 = Restrictions.eq("destroyId",mstId);
		crt.setOrder(Order.newInstance().asc("gmtCreate"));
		crt.setRestriction(Restrictions.and(r1));
		List<GspUnqualifiedDestroyD> list = dMapper.findByCriteria(crt);
		return spellGspUnqualifiedDestroyDVOS(list);
	}

	//转换并组装
	private List<GspUnqualifiedDestroyDVO> spellGspUnqualifiedDestroyDVOS(List<GspUnqualifiedDestroyD> list) {
		List<GspUnqualifiedDestroyDVO> listRet=new ArrayList<>();
		String[] itemIds = list.stream().map(GspUnqualifiedDestroyD::getItemId).distinct().toArray(String[]::new);
		//请求商品信息
		RestMessage<List<BaseMtlItemMst>> itemResult = itemClient.getListByIds(itemIds);
		// 获取批次数组，查询库存服务批次信息 - by Huanglh 2022-03-01
		String[] batchIds = list.stream().map(GspUnqualifiedDestroyD::getBatchId).distinct().toArray(String[]::new);
		RestMessage<List<BatchNumberListVO>> batchNumberResult = inventoryClient.getBatchNumberBasicInfo(batchIds);
		Map<String, BatchNumberListVO> batchNumberMap = new HashMap<>();
		if (batchNumberResult.isSuccess() && CollectionUtil.isNotEmpty(batchNumberResult.getData())) {
			batchNumberMap = batchNumberResult.getData().stream().collect(
			Collectors.toMap(BatchNumberListVO::getBatchId, entity -> entity));
		}

		//查询货位信息，得到库别 库区
		String[] locatorIdList = list.stream().map(GspUnqualifiedDestroyD::getLocatorId).toArray(String[]::new);
		RestMessage<List<WarehouseLocatorBasicInfo>> locationBasicInfos = warehouseClient.getLocationBasicInfos(locatorIdList);
		if (!locationBasicInfos.isSuccess() || locationBasicInfos.getData() == null) {
			throw new BizException("查询货位关联信息失败!请重试或联系管理员!");
		}
		List<WarehouseLocatorBasicInfo>  warehouselocators = locationBasicInfos.getData();

		for(GspUnqualifiedDestroyD gspUnqualifiedDestroyD:list){
			GspUnqualifiedDestroyDVO gspUnqualifiedDestroyDVO=new GspUnqualifiedDestroyDVO();
			BeanUtils.copyProperties(gspUnqualifiedDestroyD, gspUnqualifiedDestroyDVO);
			if (itemResult.isSuccess() && itemResult.getData() != null) {
				BaseMtlItemMst itemBaseInfoVO = itemResult.getData().stream().filter(item -> item.getItemId().
						equals(gspUnqualifiedDestroyD.getItemId())).findFirst().orElse(null);
				if (itemBaseInfoVO != null) {
					BeanUtils.copyProperties(itemBaseInfoVO, gspUnqualifiedDestroyDVO);
					gspUnqualifiedDestroyDVO.setCountryOriginName(itemBaseInfoVO.getCountryOriginId());
					gspUnqualifiedDestroyDVO.setManufacturerName(itemBaseInfoVO.getManufacturerId());
					gspUnqualifiedDestroyDVO.setCaseConversionRate(itemBaseInfoVO.getCaseConversionRate());
					BaseMtlItemHealth baseMtlItemHealth = itemBaseInfoVO.getBaseMtlItemHealth();
					if(baseMtlItemHealth!=null){
						gspUnqualifiedDestroyDVO.setItemHealthSuperviseFlag(baseMtlItemHealth.getItemHealthSuperviseflag()==0?"否":"是");
						gspUnqualifiedDestroyDVO.setItemHealthListedLicensor(baseMtlItemHealth.getItemHealthListedLicensor());
						gspUnqualifiedDestroyDVO.setItemHealthCategory(baseMtlItemHealth.getItemHealthCategoryName());
						gspUnqualifiedDestroyDVO.setItemHealthApprovalNbr(baseMtlItemHealth.getItemHealthApprovalNbr());
						gspUnqualifiedDestroyDVO.setItemHealthRegisterNbr(baseMtlItemHealth.getItemHealthRegisterNbr());
					}
				}
			}
			// 将 生产日期，有效期 填入到 VO - by Huanglh 2022-03-01
			if (batchNumberMap.containsKey(gspUnqualifiedDestroyD.getBatchId())) {
				BatchNumberListVO batchNumberVO = batchNumberMap.get(gspUnqualifiedDestroyD.getBatchId());
				gspUnqualifiedDestroyDVO.setBatchProductionDateShow(batchNumberVO.getBatchProductionDateShow());
				gspUnqualifiedDestroyDVO.setBatchExpiredDateShow(batchNumberVO.getBatchExpiredDateShow());
			}

			//库区库别
			for (WarehouseLocatorBasicInfo warehouselocator :warehouselocators) {
				if(warehouselocator.getWarehouseLocatorId().equals(gspUnqualifiedDestroyDVO.getLocatorId())){
					gspUnqualifiedDestroyDVO.setWarehouseAreaName(warehouselocator.getWarehouseAreaName());
					gspUnqualifiedDestroyDVO.setWarehouseAreaCategoryName(warehouselocator.getWarehouseAreaCategoryName());
				}
			}

			listRet.add(gspUnqualifiedDestroyDVO);
		}
		return listRet;
	}

	@Override
	public Page<GspUnqualifiedDestroy> listPage(String warehouseId, String cargoOwnerId, String status, Integer pageSize, Integer pageNum) {
		UserDTO userDTO = userTemplate.getUserDTO();
		String enterpriseId = userDTO.getEnterpriseId();
		PageHelper.startPage(pageNum, pageSize);

		Criteria crt = Criteria.forClass(GspUnqualifiedDestroy.class);
		Restriction r1 = Restrictions.eq("enterpriseId",enterpriseId);
		Restriction r2 = Restrictions.eq("warehouseId",warehouseId);
		Restriction r3 = Restrictions.eq("status",status);
		Restriction r4 = StringUtils.isEmpty(cargoOwnerId)?null:Restrictions.eq("cargoOwnerId", cargoOwnerId);
		crt.setOrder(Order.newInstance().desc("gmtCreate"));
		crt.setRestriction(Restrictions.and(r1,r2,r3,r4));
		List<GspUnqualifiedDestroy> list = mapper.findByCriteria(crt);
		if(list==null || list.size()==0){
			return PageUtils.getPage(list);
		}
		//请求仓库信息
		String warehouseName=null;
		RestMessage<BaseWmsWarehouseMst> itemResultWarehouse = warehouseClient.warehouse(warehouseId);
		if (itemResultWarehouse.isSuccess() && itemResultWarehouse.getData() != null) {
			warehouseName=itemResultWarehouse.getData().getWarehouseName();
		}
		//组合id
		String[] locatorIds = list.stream().map(GspUnqualifiedDestroy::getCargoOwnerId).distinct().toArray(String[]::new);
		//请求货位信息
		RestMessage<Map<String, BaseCargoOwnerMst>> locatorResult = chainClient.getCargoOwnerMstByIds(locatorIds);
		if(locatorResult==null || locatorResult.getData()==null){
			throw new BizException("货主数据异常");
		}
		for(GspUnqualifiedDestroy gspUnqualifiedLoss:list){
			gspUnqualifiedLoss.setWarehouseName(warehouseName);
			if (locatorResult.getData().get(gspUnqualifiedLoss.getCargoOwnerId())!=null) {
				gspUnqualifiedLoss.setCargoOwnerName(locatorResult.getData().get(gspUnqualifiedLoss.getCargoOwnerId()).getCargoOwnerName());
			}
		}
		return PageUtils.getPage(list);
	}
	
	@Override
	public void batchUpdate(List<GspUnqualifiedDestroy> list, String status) throws Exception {
		UserDTO userDTO = userTemplate.getUserDTO();
		String userId = userDTO.getId();
		String userName = userDTO.getNickname();
		Date auditDate = new Date();
		for (GspUnqualifiedDestroy gspUnqualifiedDestroyDTO : list) {
			gspUnqualifiedDestroyDTO.setModifier(userId);
			gspUnqualifiedDestroyDTO.setModifierName(userName);
			gspUnqualifiedDestroyDTO.setGmtModified(auditDate);
			if(!StringUtils.isEmpty(status)){
				gspUnqualifiedDestroyDTO.setStatus(status);
				if("20".equals(status) || "30".equals(status)){
					gspUnqualifiedDestroyDTO.setAuditDate(auditDate);
				}
			}
			oneAudit(gspUnqualifiedDestroyDTO,status,auditDate);
		}
	}

	@Override
	@Transactional
	public void oneAudit(GspUnqualifiedDestroy gspUnqualifiedDestroyDTO, String status, Date auditDate) throws Exception {
		this.mapper.updateWithValidate(gspUnqualifiedDestroyDTO, p -> ObjectUtils.isNotNull(p) && ObjectUtils.isNotNull(p.getValue()));
		Criteria crt = Criteria.forClass(GspUnqualifiedDestroyD.class);
		crt.setRestriction(Restrictions.eq("destroyId", gspUnqualifiedDestroyDTO.getId()));
		dMapper.updateMapByCriteria(MapUtils.put("status", status).put("gmtModified", auditDate).getMap(), crt);
		Criteria crtD = Criteria.forClass(GspUnqualifiedDestroyD.class);
		Restriction r1 = Restrictions.eq("destroyId",gspUnqualifiedDestroyDTO.getId());
		crtD.setRestriction(Restrictions.and(r1));
		List<GspUnqualifiedDestroyD> dList = dMapper.findByCriteria(crtD);
		if("30".equals(status)){
			for (int i = 0; i < dList.size(); i++) {
				GspUnqualifiedDestroyD gspUnqualifiedDestroyD = dList.get(i);
				if(!StringUtils.isBlank(gspUnqualifiedDestroyD.getDestroyQty())){
					BigDecimal destroyQty =new BigDecimal(gspUnqualifiedDestroyD.getDestroyQty());
					gspUnqualifiedLossDMapper.updateDestroyedQty(gspUnqualifiedDestroyD.getRefLineId(), destroyQty);
				}
			}
		}else if("40".equals(status)){
			gspUnqualifiedDestroyDTO.setGspUnqualifiedDestroyDList(dList);
			saveDxi(gspUnqualifiedDestroyDTO);
		}
	}

	@Override
	public GspUnqualifiedDestroy getById(String mstId) {
		if (StringUtils.isEmpty(mstId))
			throw new ParameterException("id不能为空");
		return mapper.findById(mstId, GspUnqualifiedDestroy.class);
	}

    private void saveDxi(GspUnqualifiedDestroy model){
		BaseWmsWarehouseMst wmsWarehouseMst=null;
		List<GspUnqualifiedDestroyDVO> voList = spellGspUnqualifiedDestroyDVOS(model.getGspUnqualifiedDestroyDList());
		for (int i = 0; i < voList.size(); i++) {
			GspUnqualifiedDestroyDVO dModel=voList.get(i);
			if(i==0){
				RestMessage<BaseWmsWarehouseMst> itemResultWarehouse = warehouseClient.warehouse(dModel.getWarehouseId());
				if (itemResultWarehouse.isSuccess() && itemResultWarehouse.getData() != null) {
					wmsWarehouseMst=itemResultWarehouse.getData();
				}
			}
			DxiGspDestroyRequestRecord owsModel=new DxiGspDestroyRequestRecord();
			owsModel.setLineid(dModel.getId());//对接单据行号
			owsModel.setSeqno(Integer.toString(i+1));//对接单据行号
			owsModel.setBillid(model.getId());//单据ID
			owsModel.setBillno(model.getCode());//销毁单号
			owsModel.setBranchid(model.getWarehouseId());//申请仓库ID
			if(wmsWarehouseMst!=null){
				owsModel.setBranchcode(wmsWarehouseMst.getWarehouseCode());//申请仓库编码
			}
			owsModel.setBranchname(model.getWarehouseName());//申请仓库名称
			owsModel.setConsignorid(model.getCargoOwnerId());//货主ID
			//owsModel.setConsignorcode();//货主编码
			owsModel.setConsignorname(model.getCargoOwnerName());//货主名称
			owsModel.setRefBilltype("N/A");//单据来源类型 todo
			owsModel.setDefectsItemType("N/A");//销毁商品类别 todo
			owsModel.setItemid(dModel.getItemId());//商品ID
			owsModel.setItemcode(dModel.getItemCode());//商品编码
			owsModel.setItemname(dModel.getItemName());//商品名称
//            owsModel.setItemSpecs();//商品规格
//            owsModel.setManufacturer();//生产厂家
//            owsModel.setParerntItemid();//父商品ID
//            owsModel.setCategoryId();//商品类别ID--商品大类表ID
//            owsModel.setTypeCode();//商品大类编码
//            owsModel.setTypeName();//商品大类名称
			owsModel.setLotNo(dModel.getLotNum());//批号
			owsModel.setBatchNo(dModel.getBatchId());//批次号
//            owsModel.setPdateFrom();//生产日期
//            owsModel.setValidUntil();//有效期至
//            owsModel.setPaperNo();//备案凭证号
//            owsModel.setApprovalNumber();//批准文号
//            owsModel.setProductionPlace();//产地
//            owsModel.setBarcode();//商品条码
//            owsModel.setPackSize();//包装数量
//            owsModel.setPackUnits();//包装单位
			owsModel.setDefectsReason(dModel.getUnqualifiedReason());//不合格原因
			owsModel.setDestroyQty(dModel.getDestroyQty());//销毁数量
			//owsModel.setDestroyReason(dModel.getd);//销毁原因
			owsModel.setDestroySite(model.getDestroySite());//销毁地点
			owsModel.setDestroyMode(model.getDestroyMode());//销毁方式
			owsModel.setTransportFacility(model.getTransportTool());//运输工具
			owsModel.setTransportPerson(model.getTransportor());//运输人员
			owsModel.setDestroySiteCond(model.getDestroySituation());//销毁后现场情况
			owsModel.setDestroyExecutor(model.getDestroyExecutor());//销毁执行人
			owsModel.setDestroySupervisor(model.getDestroySupervisor());//销毁监督人
			owsModel.setDapartmentStaff(model.getNmpaOfficer());//监管部门人员
			owsModel.setBillDate(model.getGmtCreate());//发起申请日期
			owsModel.setStatus("已销毁");//状态
			owsModel.setRemark(model.getRemark());//备注
			owsModel.setClosedReason(model.getNmpaOfficer());//作废原因
			//		owsModel.setAttrStr1();//字符扩展属性1
			//		owsModel.setAttrStr2();//字符扩展属性2
			//		owsModel.setAttrStr3();//字符扩展属性3
			//		owsModel.setAttrStr4();//字符扩展属性4
			//		owsModel.setAttrStr5();//字符扩展属性5
			//		owsModel.setAttrStr6();//字符扩展属性6
			//		owsModel.setAttrStr7();//字符扩展属性7
			//		owsModel.setAttrStr8();//字符扩展属性8
			//		owsModel.setAttrStr9();//字符扩展属性9
			//		owsModel.setAttrStr10();//字符扩展属性10
			//		owsModel.setAttrSum1();//数字扩展属性1
			//		owsModel.setAttrNum2();//数字扩展属性2
			//		owsModel.setAttrNum3();//数字扩展属性3
			//		owsModel.setAttrNum4();//数字扩展属性4
			//		owsModel.setAttrNum5();//数字扩展属性5
			//		owsModel.setAttrDte1();//日期属性扩展1
			//		owsModel.setAttrDte2();//日期属性扩展2
			//		owsModel.setAttrDte3();//日期属性扩展3
			//		owsModel.setAttrDte4();//日期属性扩展4
			//		owsModel.setAttrDte5();//日期属性扩展5
			owsModel.setCreateby(model.getCreatorName());//录入员
			owsModel.setCreatedate(model.getGmtCreate());//录入时间
			owsModel.setLastmodifyby(model.getModifierName());//修改人
			owsModel.setLastmodifydate(model.getGmtModified());//修改时间
			owsModel.setEnterpriseid(model.getEnterpriseId());//企业ID
			owsModel.setEnterprisename(userTemplate.getUserDTO().getEnterpriseName());//企业名称
//			owsModel.setBilldate(model.getGmtCreate());
			dxiGspDestroyRequestRecordMapper.save(owsModel);
		}
    }
}