package com.unis.base.app.service.impl;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.unis.base.app.feign.MyuserFeign;
import com.unis.base.app.service.SinkpointRecordsService;
import com.unis.base.client.OiltankFeign;
import com.unis.base.client.SinkpointFeign;
import com.unis.base.client.SinkpointRecordsFeign;
import com.unis.base.client.WarehouseFeign;
import com.unis.base.common.constant.FilingConstant;
import com.unis.base.common.vo.*;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.LsBeanUtils;
import com.unis.common.utils.ResponseWrapper;
import com.unis.flowable.client.FlowAbleClient;
import com.unis.flowable.common.vo.FlowAbleCompleteVO;
import com.unis.flowable.common.vo.StartNewTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

/** 
 * @ClassName: SinkpointServiceImpl
 * @Description: 库点信息 service实现类
 * @author WangZL
 * @date 2019年9月6日 上午11:18:54  
 */
@Service
public class SinkpointRecordsServiceImpl implements SinkpointRecordsService {

	@Autowired
	private SinkpointRecordsFeign sinkpointRecordsFeign;

	@Autowired
	private MyuserFeign myuserFeign;

	@Autowired
	private FlowAbleClient flowAbleClient;

	@Autowired
	private SinkpointFeign sinkpointFeign;

    @Autowired
    private WarehouseFeign warehouseFeign;

    @Autowired
    private OiltankFeign oiltankFeign;

	private static final Integer SAVE = 0; //操作状态：保存
	private static final Integer SUBMIT = 1;//操作状态：提交

	private static final String PROCESS_KEY = "SLQYJCXXBA";
	private static final String STATUS_KEY = "status";

    private static final Integer WAREHOUSE = 1; //仓房
    private static final Integer OILTANk = 2;//油罐

	/**
	 * 分页查询列表
	 * @param sinkpointRecordsQueryVO
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@Override
	public ResponseWrapper getSinkpointRecordsPage(SinkpointRecordsQueryVO sinkpointRecordsQueryVO, Integer pageNum, Integer pageSize) {
		ResponseWrapper responseWrapper = null;
		//获取待办列表
		responseWrapper = flowAbleClient.getUserTaskNoPage(CurrentUtil.getUserId());
		//responseWrapper = flowAbleClient.getUserTaskNoPage("userId");
		//便利拼接我的待办，
		String liucheng = ",";
		if(responseWrapper.getInfoCode() != 200) {
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "获取失败", null);
		}
		List<LinkedHashMap> data = (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:data) {
			String lcid = (String) linkedHashMap.get("procInsId");//获取审批列表数组
			liucheng += lcid +",";
		}
		responseWrapper = sinkpointRecordsFeign.getSinkpointRecordsPage(sinkpointRecordsQueryVO, pageNum, pageSize);

		if(responseWrapper.getInfoCode() != 200) {
			return responseWrapper;
		}
		LinkedHashMap pageDate = (LinkedHashMap) responseWrapper.getData();
		List<LinkedHashMap> pageList  = (List<LinkedHashMap>) pageDate.get("list");
		for(LinkedHashMap linkedHashMap: pageList) {
			String lcid = (String) linkedHashMap.get("lcId");
			if(lcid == null) {
				linkedHashMap.put("sfxssh", 0);//改回0
				continue;
			}
			if(liucheng.contains(","+lcid+",")) {//包含，显示审核按钮
				linkedHashMap.put("sfxssh", 1);
			} else {
				linkedHashMap.put("sfxssh", 0);//改回0
			}
		}
		return responseWrapper;
	}

	/**
	 * 根据状态新增
	 * @param sinkpointRecordsVO
	 * @return
	 */
	@Override
	public ResponseWrapper insertSinkpointRecords(SinkpointRecordsVO sinkpointRecordsVO, Integer type) {

		String zzqUsers = "";
		ResponseWrapper responseWrapper = null;
		responseWrapper = myuserFeign.getUserByRole(new String[] {"R0000085"});//获取库区主任角色
		if(responseWrapper.getInfoCode()!=200) {
			return ResponseWrapper.error("获取库区主任信息失败");
		}
		//获取自治区用户信息
		List<LinkedHashMap> datas =  (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:datas) {
			zzqUsers += (String) linkedHashMap.get("userCode");//获取审批列表数组
		}

		StartNewTaskVO startNewTaskVO = null;//初始化流程对象
		FlowAbleCompleteVO completeVO = null;
		if (type == SAVE){
			//当保存时，备案状态为待提交
			sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_SUBMIT.getValue());
		} else if (type == SUBMIT) {
			//当提交时，备案状态为待库区主任审批
			sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_SUBMIT.getValue());

			startNewTaskVO = new StartNewTaskVO();
			startNewTaskVO.setProcessKey(PROCESS_KEY);
			startNewTaskVO.setStatusKey(STATUS_KEY);
			startNewTaskVO.setStatus("1");//标识盟市提交
			startNewTaskVO.setUserId(CurrentUtil.getUserId());

			//审批对象拼接
			completeVO = new FlowAbleCompleteVO();
			completeVO.setStatusKey(STATUS_KEY);//状态标识
			completeVO.setUserId(CurrentUtil.getUserId());//当前用户审批
			completeVO.setMessage("提交");//审批意见
			completeVO.setAssignee(zzqUsers);
			completeVO.setStatus("1");//表示提交审核
		}

		sinkpointRecordsVO.setStatus(1);
		sinkpointRecordsVO.setCreator(CurrentUtil.getUserName());
		sinkpointRecordsVO.setCreatorCode(CurrentUtil.getUserId());
		sinkpointRecordsVO.setCreateDate(new Date());

		ResponseWrapper infoResponse = sinkpointRecordsFeign.insert(sinkpointRecordsVO);
		if (infoResponse.getInfoCode() == 200) {
			String kdbabh = infoResponse.getData().toString();

			if (startNewTaskVO != null){
				startNewTaskVO.setId(kdbabh);
				responseWrapper = flowAbleClient.start(startNewTaskVO);//启动流程
				//启动成功进行流程与数据进行绑定
				if(responseWrapper.getInfoCode() == 200) {
					LinkedHashMap data =  (LinkedHashMap) responseWrapper.getData();
					String lcId =  (String) data.get("processId");//获取到流程id
					sinkpointRecordsVO.setLcId(lcId);
					sinkpointRecordsVO.setKdbabh(kdbabh);
					sinkpointRecordsFeign.update(sinkpointRecordsVO);

					completeVO.setProcessId(lcId);
					responseWrapper = flowAbleClient.complete(completeVO);//进行第一次上报
					if(responseWrapper.getInfoCode() == 200) {//标识上报到自治区成功
						sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_KQZR_APPROVAL.getValue());//结果为待库区主任审批
						return  sinkpointRecordsFeign.update(sinkpointRecordsVO);
					}
				}else {
					return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"启动流程失败",null);
				}
			}
		}
		return ResponseWrapper.success(HttpStatus.OK.value(), "操作成功",null);
	}

	/**
	 * 查看详情
	 * @param kdbabh
	 * @return
	 */
	@Override
	public ResponseWrapper getSinkpointRecordsInfoById(String kdbabh) {
		ResponseWrapper responseWrapper = null;
		responseWrapper = sinkpointRecordsFeign.getSinkpointRecordsInfoById(kdbabh);


		if(responseWrapper.getInfoCode() != 200) {
			return responseWrapper;
		}

		//对象Mapper
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.setSerializationInclusion(Include.ALWAYS);
		objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(responseWrapper.getData(), SinkpointRecordsVO.class);

		LinkedHashMap zfryzzsq = (LinkedHashMap) responseWrapper.getData();
		String lcid = sinkpointRecordsVO.getLcId();
		if (lcid == null) {
			return responseWrapper;
		}

		//根据流程id获取审批历史
		ResponseWrapper processHis = flowAbleClient.findByProcessInfo(lcid);
		if(processHis.getInfoCode()!=200) {
			return processHis;
		}
		List<LinkedHashMap> linkedHashMaps = (List<LinkedHashMap>) processHis.getData();
		for(LinkedHashMap linkedHashMap : linkedHashMaps) {
			String assigneeName = (String) zfryzzsq.get("assigneeName");//获取审批用户id
			//根据id从用户中心获取用户信息
			//linkedHashMap.put("assigneeName", "肖礼兵");
		}
		zfryzzsq.put("processHis", processHis.getData());//添加审批历史信息

		return responseWrapper;
	}

	/**
	 * 提交
	 * @param kdbabh
	 * @return
	 */
	@Override
	public ResponseWrapper sinkpointRecordsRelay(String kdbabh) {

		String zzqUsers = "";
		ResponseWrapper responseWrapper = null;
		responseWrapper = myuserFeign.getUserByRole(new String[] {"R0000085"});//获取库区主任角色
		if(responseWrapper.getInfoCode()!=200) {
			return ResponseWrapper.error("获取库区主任信息失败");
		}
		//获取自治区用户信息
		List<LinkedHashMap> datas =  (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:datas) {
			zzqUsers += (String) linkedHashMap.get("userCode");//获取审批列表数组
		}

		StartNewTaskVO startNewTaskVO = null;
		FlowAbleCompleteVO completeVO = null;

		startNewTaskVO = new StartNewTaskVO();
		startNewTaskVO.setProcessKey(PROCESS_KEY);
		startNewTaskVO.setStatusKey(STATUS_KEY);
		startNewTaskVO.setStatus("1");
		startNewTaskVO.setUserId(CurrentUtil.getUserId());
		startNewTaskVO.setId(kdbabh);

		//审批对象拼接
		completeVO = new FlowAbleCompleteVO();
		completeVO.setStatusKey(STATUS_KEY);//状态标识
		completeVO.setUserId(CurrentUtil.getUserId());//当前用户审批
		completeVO.setMessage("提交");//审批意见
		completeVO.setAssignee(zzqUsers);
		completeVO.setStatus("1");//表示提交审核

		ResponseWrapper rw = sinkpointRecordsFeign.getSinkpointRecordsInfoById(kdbabh);
		if(rw.getInfoCode() == 200) {
			//对象Mapper
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setSerializationInclusion(Include.ALWAYS);
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
			SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(rw.getData(), SinkpointRecordsVO.class);



			responseWrapper = flowAbleClient.start(startNewTaskVO);//启动流程
			//启动成功进行流程与数据进行绑定
			if(responseWrapper.getInfoCode() == 200) {//标识启动成功
				LinkedHashMap data =  (LinkedHashMap) responseWrapper.getData();
				String lcId =  (String) data.get("processId");//获取到流程id
				sinkpointRecordsVO.setLcId(lcId);
				sinkpointRecordsFeign.update(sinkpointRecordsVO);
				//进行第一次审批
				completeVO.setProcessId(lcId);
				responseWrapper = flowAbleClient.complete(completeVO);//进行第一次转发

				if(responseWrapper.getInfoCode() == 200) {//标识上报到库区主任成功
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_KQZR_APPROVAL.getValue());//带库区主任审批
					return  sinkpointRecordsFeign.update(sinkpointRecordsVO);
				} else {//失败标识审核失败进行库点记录保存可再次提交
					return  ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"库点提交失败，请稍后！",null);
				}
			}else {
				return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"启动流程失败",null);
			}
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"库点提交失败",null);
	}

	/**
	 * 库区主任审批
	 * @param examineStampVO
	 * @return
	 */
	@Override
	public ResponseWrapper sinkpointRecordsDirectorExamine(ExamineStampVO examineStampVO) {

		String zzqUsers = "";
		ResponseWrapper responseWrapper = null;
		responseWrapper = myuserFeign.getUserByRole(new String[] {"R0000085"});//待区粮办盖章
		if(responseWrapper.getInfoCode()!=200) {
			return ResponseWrapper.error("获取库区主任信息失败");
		}
		//获取自治区用户信息
		List<LinkedHashMap> datas =  (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:datas) {
			zzqUsers += (String) linkedHashMap.get("userCode");//获取审批列表数组
		}

		ResponseWrapper rw = sinkpointRecordsFeign.getSinkpointRecordsInfoById(examineStampVO.getId());
		if(rw.getInfoCode() == 200 && rw.getData() != null) {
			//对象Mapper
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setSerializationInclusion(Include.ALWAYS);
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
			SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(rw.getData(), SinkpointRecordsVO.class);

			FlowAbleCompleteVO completeVO = new FlowAbleCompleteVO();
			completeVO.setProcessId(sinkpointRecordsVO.getLcId());
			completeVO.setStatusKey(STATUS_KEY);
            Integer status = examineStampVO.getStatus();
			if(status == 0) {
				completeVO.setStatus("2");//驳回状态为2
			}else if(status == 1) {
				completeVO.setStatus("1");//通过状态为1
			}
			completeVO.setAssignee(zzqUsers);
			completeVO.setMessage(examineStampVO.getMessage());
			completeVO.setUserId(CurrentUtil.getUserId());
			ResponseWrapper flowResponse = flowAbleClient.complete(completeVO);
			if(flowResponse.getInfoCode() == 200) {
				if(status == 0) {
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_KQZR_NO_STAMP.getValue());
				}else if(status == 1) {//通过传给区粮办审批
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_KQZR_YSE_STAMP.getValue());
				}
				sinkpointRecordsVO.setRefreshTime(new Date());
				sinkpointRecordsVO.setRefresher(CurrentUtil.getUserName());
				sinkpointRecordsVO.setRefresherCode(CurrentUtil.getUserId());
				sinkpointRecordsFeign.update(sinkpointRecordsVO);

				return ResponseWrapper.success(HttpStatus.OK.value(), "库区主任审批成功",null);
			}else {
				return flowResponse;
			}
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"库区主任审批失败",null);
	}

	/**
	 * 库区主任盖章
	 * @param examineStampVO
	 * @return
	 */
	@Override
	public ResponseWrapper sinkpointRecordsDirectorStamp(ExamineStampVO examineStampVO) {
		String zzqUsers = "";
		ResponseWrapper responseWrapper = null;
		responseWrapper = myuserFeign.getUserByRole(new String[] {"R0000086"});//待区粮办审批
		if(responseWrapper.getInfoCode()!=200) {
			return ResponseWrapper.error("获取区粮办信息失败");
		}
		//获取自治区用户信息
		List<LinkedHashMap> datas =  (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:datas) {
			zzqUsers += (String) linkedHashMap.get("userCode");//获取审批列表数组
		}

		ResponseWrapper rw = sinkpointRecordsFeign.getSinkpointRecordsInfoById(examineStampVO.getId());
		if(rw.getInfoCode() == 200 && rw.getData() != null) {
			//对象Mapper
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setSerializationInclusion(Include.ALWAYS);
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
			SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(rw.getData(), SinkpointRecordsVO.class);

			FlowAbleCompleteVO completeVO = new FlowAbleCompleteVO();
			completeVO.setProcessId(sinkpointRecordsVO.getLcId());
			completeVO.setStatusKey(STATUS_KEY);
			Integer status = examineStampVO.getStatus();
			if(status == 0) {
				completeVO.setStatus("2");//驳回状态为2
			}else if(status == 1) {
				completeVO.setStatus("1");//通过状态为1
			}
			completeVO.setAssignee(zzqUsers);
			completeVO.setMessage(examineStampVO.getMessage());
			completeVO.setUserId(CurrentUtil.getUserId());
			ResponseWrapper flowResponse = flowAbleClient.complete(completeVO);
			if(flowResponse.getInfoCode() == 200) {
				if(status == 0) {
					sinkpointRecordsVO.setSfba(FilingConstant.REJECTED.getValue());
				}else if(status == 1) {//通过传给区粮办审批
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_QLB_APPROVAL.getValue());
				}
				sinkpointRecordsVO.setRefreshTime(new Date());
				sinkpointRecordsVO.setRefresher(CurrentUtil.getUserName());
				sinkpointRecordsVO.setRefresherCode(CurrentUtil.getUserId());
				sinkpointRecordsFeign.update(sinkpointRecordsVO);

				return ResponseWrapper.success(HttpStatus.OK.value(), "库区主任盖章成功",null);
			}else {
				return flowResponse;
			}
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"库区主任盖章失败",null);
	}

	/**
	 * 区粮办审批
	 * @param examineStampVO
	 * @return
	 */
	@Override
	public ResponseWrapper sinkpointRecordsDistrictExamine(ExamineStampVO examineStampVO) {

		String zzqUsers = "";
		ResponseWrapper responseWrapper = null;
		responseWrapper = myuserFeign.getUserByRole(new String[] {"R0000086"});//待区粮办审批
		if(responseWrapper.getInfoCode()!=200) {
			return ResponseWrapper.error("获取库区粮办失败");
		}
		//获取自治区用户信息
		List<LinkedHashMap> datas =  (List<LinkedHashMap>) responseWrapper.getData();
		for(LinkedHashMap linkedHashMap:datas) {
			zzqUsers += (String) linkedHashMap.get("userCode");//获取审批列表数组
		}

		ResponseWrapper rw = sinkpointRecordsFeign.getSinkpointRecordsInfoById(examineStampVO.getId());
		if(rw.getInfoCode() == 200 && rw.getData() != null) {
			//对象Mapper
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setSerializationInclusion(Include.ALWAYS);
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
			SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(rw.getData(), SinkpointRecordsVO.class);

			FlowAbleCompleteVO completeVO = new FlowAbleCompleteVO();
			completeVO.setProcessId(sinkpointRecordsVO.getLcId());
			completeVO.setStatusKey(STATUS_KEY);
			Integer status = examineStampVO.getStatus();
			if(status == 0) {
				completeVO.setStatus("2");//驳回状态为2
			}else if(status == 1) {
				completeVO.setStatus("1");//通过状态为1
			}
			completeVO.setAssignee(zzqUsers);
			completeVO.setMessage(examineStampVO.getMessage());
			completeVO.setUserId(CurrentUtil.getUserId());
			ResponseWrapper flowResponse = flowAbleClient.complete(completeVO);
			if(flowResponse.getInfoCode() == 200) {
				if(status == 0) {
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_QLB_NO_STAMP.getValue());
				}else if(status == 1) {//通过区粮办通过盖章
					sinkpointRecordsVO.setSfba(FilingConstant.TO_BE_QLB_YSE_STAMP.getValue());
				}
				sinkpointRecordsVO.setRefreshTime(new Date());
				sinkpointRecordsVO.setRefresher(CurrentUtil.getUserName());
				sinkpointRecordsVO.setRefresherCode(CurrentUtil.getUserId());
				sinkpointRecordsFeign.update(sinkpointRecordsVO);

				return ResponseWrapper.success(HttpStatus.OK.value(), "区粮办审批成功",null);
			}else {
				return flowResponse;
			}
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"区粮办审批失败",null);
	}

	/**
	 * 区粮办盖章
	 * @param examineStampVO
	 * @return
	 */
	@Override
	public ResponseWrapper sinkpointRecordsDistrictStamp(ExamineStampVO examineStampVO) {

		ResponseWrapper rw = sinkpointRecordsFeign.getSinkpointRecordsInfoById(examineStampVO.getId());
		if(rw.getInfoCode() == 200 && rw.getData() != null) {
			//对象Mapper
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setSerializationInclusion(Include.ALWAYS);
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
			SinkpointRecordsVO sinkpointRecordsVO = objectMapper.convertValue(rw.getData(), SinkpointRecordsVO.class);

			FlowAbleCompleteVO completeVO = new FlowAbleCompleteVO();
			completeVO.setProcessId(sinkpointRecordsVO.getLcId());
			completeVO.setStatusKey(STATUS_KEY);
			Integer status = examineStampVO.getStatus();
			if(status == 0) {
				completeVO.setStatus("2");//驳回状态为2
			}else if(status == 1) {
				completeVO.setStatus("1");//通过状态为1
			}
			completeVO.setMessage(examineStampVO.getMessage());
			completeVO.setUserId(CurrentUtil.getUserId());
			ResponseWrapper flowResponse = flowAbleClient.complete(completeVO);
			if(flowResponse.getInfoCode() == 200) {
				if(status == 0) {
					sinkpointRecordsVO.setSfba(FilingConstant.REJECTED.getValue());
				}else if(status == 1) {//通过已备案
					sinkpointRecordsVO.setSfba(FilingConstant.FILING.getValue());
				}
				sinkpointRecordsVO.setRefreshTime(new Date());
				sinkpointRecordsVO.setRefresher(CurrentUtil.getUserName());
				sinkpointRecordsVO.setRefresherCode(CurrentUtil.getUserId());
                ResponseWrapper sinkpointRecordsUpdate = sinkpointRecordsFeign.update(sinkpointRecordsVO);
                if (sinkpointRecordsUpdate.getInfoCode() == 200){
                    Integer sfba = FilingConstant.FILING.getValue();
                    if (sinkpointRecordsVO.getSfba().equals(sfba)){
                        //更新主表数据
                        DKdxxsjyVO dKdxxsjyVO = new DKdxxsjyVO();
                        LsBeanUtils.copyAllProperties(sinkpointRecordsVO,dKdxxsjyVO);
                        ResponseWrapper sinkpointUpdate = sinkpointFeign.update(dKdxxsjyVO);
                        if (sinkpointUpdate.getInfoCode() != 200){
                            return sinkpointUpdate;
                        }
                        //更新仓（罐）信息备案
                        if(WAREHOUSE.equals(sinkpointRecordsVO.getBhcgzt())){
                            DCfxxsjyVO dCfxxsjyVO = new DCfxxsjyVO();
                            dCfxxsjyVO.setSfba(sfba);
                            dCfxxsjyVO.setCfbh(sinkpointRecordsVO.getCgbh());
                            ResponseWrapper warehouseUpdate = warehouseFeign.update(dCfxxsjyVO);
                            if (warehouseUpdate.getInfoCode() != 200){
                                return warehouseUpdate;
                            }
                        } else if (OILTANk.equals(sinkpointRecordsVO.getBhcgzt())){
                            OiltankVO oiltankVO = new OiltankVO();
                            oiltankVO.setSfba(sfba);
                            oiltankVO.setYgbh(sinkpointRecordsVO.getCgbh());
                            ResponseWrapper oiltankUpdate = oiltankFeign.update(oiltankVO);
                            if (oiltankUpdate.getInfoCode() != 200){
                                return oiltankUpdate;
                            }
                        }
                    }
                }
				return ResponseWrapper.success(HttpStatus.OK.value(), "区粮办盖章成功",null);
			}else {
				return flowResponse;
			}
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"区粮办盖章失败",null);
	}


}
