package org.jeecg.modules.demo.ggzycontentdistribution.controller;

import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.gcproject.entity.GcProject;
import org.jeecg.modules.demo.gcproject.entity.GcProjectVo;
import org.jeecg.modules.demo.gcproject.service.IGcProjectService;
import org.jeecg.modules.demo.ggzyannouncementtype.entity.GgzyAnnouncementType;
import org.jeecg.modules.demo.ggzyannouncementtype.service.IGgzyAnnouncementTypeService;
import org.jeecg.modules.demo.ggzycontentdistribution.entity.GgzyContentDistribution;
import org.jeecg.modules.demo.ggzycontentdistribution.entity.GgzyContentDistributionVo;
import org.jeecg.modules.demo.ggzycontentdistribution.service.IGgzyContentDistributionService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.demo.ggzycontentdistribution.service.IGgzyContentDistributionVoService;
import org.jeecg.modules.demo.ggzyindustrytype.entity.GgzyIndustryType;
import org.jeecg.modules.demo.ggzyindustrytype.service.IGgzyIndustryTypeService;
import org.jeecg.modules.demo.ggzyqxqcodemapping.entity.GgzyQxqCodeMapping;
import org.jeecg.modules.demo.ggzyqxqcodemapping.service.IGgzyQxqCodeMappingService;
import org.jeecg.modules.demo.ggzyregionalcodemapping.entity.GgzyRegionalCodeMapping;
import org.jeecg.modules.demo.ggzyregionalcodemapping.service.IGgzyRegionalCodeMappingService;
import org.jeecg.modules.elasticsearch.entity.TenderDetailsVo;
import org.jeecg.modules.elasticsearch.service.impl.TenderDetailsVoServiceImpl;
import org.jeecg.modules.elasticsearch.utils.TenderDetailsVoUtils;
import org.jeecg.modules.utils.RandomStrUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: 公共资源内容发布
 * @Author: jeecg-boot
 * @Date:   2024-01-08
 * @Version: V1.0
 */
@Api(tags="公共资源内容发布")
@RestController
@RequestMapping("/ggzycontentdistribution/ggzyContentDistribution")
@Slf4j
public class GgzyContentDistributionController extends JeecgController<GgzyContentDistribution, IGgzyContentDistributionService> {
	@Autowired
	private IGgzyContentDistributionService ggzyContentDistributionService;

	@Autowired
	private IGgzyContentDistributionVoService ggzyContentDistributionVoService;

	 @Autowired
	 private IGcProjectService gcProjectService;

	 @Autowired
	 private IGgzyAnnouncementTypeService iGgzyAnnouncementTypeService;

	 @Autowired
	 private IGgzyQxqCodeMappingService iGgzyQxqCodeMappingService;

	 @Autowired
	 private IGgzyRegionalCodeMappingService iGgzyRegionalCodeMappingService;

	 @Autowired
	 private TenderDetailsVoServiceImpl tenderDetailsVoService;

	 @Autowired
	 private IGgzyIndustryTypeService iGgzyIndustryTypeService;
	/**
	 * 分页列表查询
	 *
	 * @param ggzyContentDistributionVo
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "公共资源内容发布-分页列表查询")
	@ApiOperation(value="公共资源内容发布-分页列表查询", notes="公共资源内容发布-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<GgzyContentDistributionVo>> queryPageList(GgzyContentDistributionVo ggzyContentDistributionVo,
																  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																  HttpServletRequest req) {
		QueryWrapper<GgzyContentDistributionVo> queryWrapper = QueryGenerator.initQueryWrapper(ggzyContentDistributionVo, req.getParameterMap());
		Page<GgzyContentDistributionVo> page = new Page<GgzyContentDistributionVo>(pageNo, pageSize);
		IPage<GgzyContentDistributionVo> pageList = ggzyContentDistributionVoService.page(page, queryWrapper);
		return Result.OK(pageList);
	}


	 @GetMapping(value = "/getSourceDataKey")
	 public Result<String> getSourceDataKey(){
		 String randomNumberNew = null;
		 try {
			 for (int i = 0; i < 10; i++) {
				 String randomNumber = RandomStrUtil.getRandomNumber(20);
				 QueryWrapper<GgzyContentDistributionVo> queryWrapper = new QueryWrapper<GgzyContentDistributionVo>();
				 queryWrapper.eq("source_data_key",randomNumber);
				 long count = ggzyContentDistributionVoService.count(queryWrapper);
				 if(count <= 0){
					 randomNumberNew = randomNumber;
					 break;
				 }
			 }
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 if(ObjectUtils.isEmpty(randomNumberNew)){
			 return Result.ok("有重复内容请重新生成");
		 }
		 return Result.ok(randomNumberNew);
	 }


	 @GetMapping(value = "/getProjectCode")
	 public Result<String> getProjectCode(){
		 String randomNumberNew = null;
		 try {
			 for (int i = 0; i < 10; i++) {
				 String randomNumber = RandomStrUtil.getRandomNumberCrossBar(15);
				 QueryWrapper<GgzyContentDistributionVo> queryWrapper = new QueryWrapper<GgzyContentDistributionVo>();
				 queryWrapper.eq("project_code",randomNumber);
				 long count = ggzyContentDistributionVoService.count(queryWrapper);
				 if(count <= 0){
					 randomNumberNew = randomNumber;
					 break;
				 }
			 }
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 if(ObjectUtils.isEmpty(randomNumberNew)){
			 return Result.ok("有重复内容请重新生成");
		 }
		 return Result.ok(randomNumberNew);
	 }

	/**
	 *   添加
	 *
	 * @param ggzyContentDistribution
	 * @return
	 */
	@AutoLog(value = "公共资源内容发布-添加")
	@ApiOperation(value="公共资源内容发布-添加", notes="公共资源内容发布-添加")
	@RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody GgzyContentDistribution ggzyContentDistribution) {
		String projectCode = ggzyContentDistribution.getProjectCode();
		if(!ObjectUtils.isEmpty(projectCode) && projectCode != ""){
			GcProject gcProject = getGcProject(projectCode);
			if(!ObjectUtils.isEmpty(gcProject)){
				String regionCode = gcProject.getRegionCode();
				if(!ObjectUtils.isEmpty(regionCode) && regionCode != ""){
					ggzyContentDistribution.setRegionCode(regionCode);
					GgzyQxqCodeMapping ggzyQxqCodeMapping = getGgzyQxqCodeMapping(regionCode);
					if(!ObjectUtils.isEmpty(ggzyQxqCodeMapping)){
						String name = ggzyQxqCodeMapping.getName();
						if(!ObjectUtils.isEmpty(name)){
							ggzyContentDistribution.setRegionName(name);
						}
					}
				}
				String platformCode = gcProject.getPlatformCode();
				if(!ObjectUtils.isEmpty(platformCode) && platformCode != ""){
					ggzyContentDistribution.setPlatformCode(platformCode);
					GgzyRegionalCodeMapping ggzyRegionalCodeMapping = getGgzyRegionalCodeMapping(platformCode);
					if(!ObjectUtils.isEmpty(ggzyRegionalCodeMapping)){
						String name = ggzyRegionalCodeMapping.getName();
						if(!ObjectUtils.isEmpty(name)){
							ggzyContentDistribution.setPlatformName(name);
						}
					}
				}
				String projectName = gcProject.getProjectName();
				if(!ObjectUtils.isEmpty(projectName)){
					ggzyContentDistribution.setProjectName(projectName);
				}
				String industriesTypeCode = gcProject.getIndustriesType();
				if(!ObjectUtils.isEmpty(industriesTypeCode)){
					ggzyContentDistribution.setIndustriesTypeCode(industriesTypeCode);

					GgzyIndustryType ggzyIndustryType = getGgzyIndustryType(industriesTypeCode);
					if(!ObjectUtils.isEmpty(ggzyIndustryType)){
						String industriesTypeName = ggzyIndustryType.getIndustriesTypeName();
						ggzyContentDistribution.setIndustriesTypeName(industriesTypeName);
					}
				}

			}
		}
		String regionCode = ggzyContentDistribution.getRegionCode();
		if(!ObjectUtils.isEmpty(regionCode) && regionCode != ""){
			GgzyQxqCodeMapping ggzyQxqCodeMapping = getGgzyQxqCodeMapping(regionCode);
			if(!ObjectUtils.isEmpty(ggzyQxqCodeMapping)){
				String name = ggzyQxqCodeMapping.getName();
				if(!ObjectUtils.isEmpty(name)){
					ggzyContentDistribution.setRegionName(name);
				}
			}
		}
		String platformCode = ggzyContentDistribution.getPlatformCode();
		if(!ObjectUtils.isEmpty(platformCode) && platformCode != ""){
			GgzyRegionalCodeMapping ggzyRegionalCodeMapping = getGgzyRegionalCodeMapping(platformCode);
			if(!ObjectUtils.isEmpty(ggzyRegionalCodeMapping)){
				String name = ggzyRegionalCodeMapping.getName();
				if(!ObjectUtils.isEmpty(name)){
					ggzyContentDistribution.setPlatformName(name);
				}
			}
		}
		String noticeTypeCodeId = ggzyContentDistribution.getNoticeTypeCodeId();
		if(!ObjectUtils.isEmpty(noticeTypeCodeId) && noticeTypeCodeId != ""){
			GgzyAnnouncementType ggzyAnnouncementTypeById = getGgzyAnnouncementTypeById(noticeTypeCodeId);
			if(!ObjectUtils.isEmpty(ggzyAnnouncementTypeById)){
				String noticeTypeCode = ggzyAnnouncementTypeById.getNoticeTypeCode();
				if(!ObjectUtils.isEmpty(noticeTypeCode)){
					ggzyContentDistribution.setNoticeTypeCode(noticeTypeCode);
				}
				String noticeTypeName = ggzyAnnouncementTypeById.getNoticeTypeName();
				if(!ObjectUtils.isEmpty(noticeTypeName)){
					ggzyContentDistribution.setNoticeTypeName(noticeTypeName);
				}
				String transactionTypeCode = ggzyAnnouncementTypeById.getTransactionTypeCode();
				if(!ObjectUtils.isEmpty(transactionTypeCode)){
					ggzyContentDistribution.setTransactionTypeCode(transactionTypeCode);
				}
				String transactionTypeName = ggzyAnnouncementTypeById.getTransactionTypeName();
				if(!ObjectUtils.isEmpty(transactionTypeName)){
					ggzyContentDistribution.setTransactionTypeName(transactionTypeName);
				}
			}
		}
		String industriesTypeCode = ggzyContentDistribution.getIndustriesTypeCode();
		if(!ObjectUtils.isEmpty(industriesTypeCode)){
			GgzyIndustryType ggzyIndustryType = getGgzyIndustryType(industriesTypeCode);
			if(!ObjectUtils.isEmpty(ggzyIndustryType)){
				String industriesTypeName = ggzyIndustryType.getIndustriesTypeName();
				ggzyContentDistribution.setIndustriesTypeName(industriesTypeName);
			}
		}
		ggzyContentDistribution.setIsSynchronous("1");
		ggzyContentDistributionService.saveOrUpdate(ggzyContentDistribution);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param ggzyContentDistribution
	 * @return
	 */
	@AutoLog(value = "公共资源内容发布-编辑")
	@ApiOperation(value="公共资源内容发布-编辑", notes="公共资源内容发布-编辑")
	@RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody GgzyContentDistribution ggzyContentDistribution) {
        String projectCode = ggzyContentDistribution.getProjectCode();
        if(!ObjectUtils.isEmpty(projectCode) && projectCode != ""){
            GcProject gcProject = getGcProject(projectCode);
            if(!ObjectUtils.isEmpty(gcProject)){
                String regionCode = gcProject.getRegionCode();
                if(!ObjectUtils.isEmpty(regionCode) && regionCode != ""){
					ggzyContentDistribution.setRegionCode(regionCode);
                    GgzyQxqCodeMapping ggzyQxqCodeMapping = getGgzyQxqCodeMapping(regionCode);
                    if(!ObjectUtils.isEmpty(ggzyQxqCodeMapping)){
                        String name = ggzyQxqCodeMapping.getName();
                        if(!ObjectUtils.isEmpty(name)){
                            ggzyContentDistribution.setRegionName(name);
                        }
                    }
                }
                String platformCode = gcProject.getPlatformCode();
                if(!ObjectUtils.isEmpty(platformCode) && platformCode != ""){
					ggzyContentDistribution.setPlatformCode(platformCode);
                    GgzyRegionalCodeMapping ggzyRegionalCodeMapping = getGgzyRegionalCodeMapping(platformCode);
                    if(!ObjectUtils.isEmpty(ggzyRegionalCodeMapping)){
                        String name = ggzyRegionalCodeMapping.getName();
                        if(!ObjectUtils.isEmpty(name)){
                            ggzyContentDistribution.setPlatformName(name);
                        }
                    }
                }
                String projectName = gcProject.getProjectName();
                if(!ObjectUtils.isEmpty(projectName)){
                    ggzyContentDistribution.setProjectName(projectName);
                }
				String industriesTypeCode = gcProject.getIndustriesType();
				if(!ObjectUtils.isEmpty(industriesTypeCode)){
					ggzyContentDistribution.setIndustriesTypeCode(industriesTypeCode);

					GgzyIndustryType ggzyIndustryType = getGgzyIndustryType(industriesTypeCode);
					if(!ObjectUtils.isEmpty(ggzyIndustryType)){
						String industriesTypeName = ggzyIndustryType.getIndustriesTypeName();
						ggzyContentDistribution.setIndustriesTypeName(industriesTypeName);
					}
				}

			}
        }
        String regionCode = ggzyContentDistribution.getRegionCode();
        if(!ObjectUtils.isEmpty(regionCode) && regionCode != ""){
            GgzyQxqCodeMapping ggzyQxqCodeMapping = getGgzyQxqCodeMapping(regionCode);
            if(!ObjectUtils.isEmpty(ggzyQxqCodeMapping)){
                String name = ggzyQxqCodeMapping.getName();
                if(!ObjectUtils.isEmpty(name)){
                    ggzyContentDistribution.setRegionName(name);
                }
            }
        }
        String platformCode = ggzyContentDistribution.getPlatformCode();
        if(!ObjectUtils.isEmpty(platformCode) && platformCode != ""){
            GgzyRegionalCodeMapping ggzyRegionalCodeMapping = getGgzyRegionalCodeMapping(platformCode);
            if(!ObjectUtils.isEmpty(ggzyRegionalCodeMapping)){
                String name = ggzyRegionalCodeMapping.getName();
                if(!ObjectUtils.isEmpty(name)){
                    ggzyContentDistribution.setPlatformName(name);
                }
            }
        }
        String noticeTypeCodeId = ggzyContentDistribution.getNoticeTypeCodeId();
        if(!ObjectUtils.isEmpty(noticeTypeCodeId) && noticeTypeCodeId != ""){
            GgzyAnnouncementType ggzyAnnouncementTypeById = getGgzyAnnouncementTypeById(noticeTypeCodeId);
            if(!ObjectUtils.isEmpty(ggzyAnnouncementTypeById)){
                String noticeTypeCode = ggzyAnnouncementTypeById.getNoticeTypeCode();
                if(!ObjectUtils.isEmpty(noticeTypeCode)){
                    ggzyContentDistribution.setNoticeTypeCode(noticeTypeCode);
                }
                String noticeTypeName = ggzyAnnouncementTypeById.getNoticeTypeName();
                if(!ObjectUtils.isEmpty(noticeTypeName)){
                    ggzyContentDistribution.setNoticeTypeName(noticeTypeName);
                }
                String transactionTypeCode = ggzyAnnouncementTypeById.getTransactionTypeCode();
                if(!ObjectUtils.isEmpty(transactionTypeCode)){
                    ggzyContentDistribution.setTransactionTypeCode(transactionTypeCode);
                }
                String transactionTypeName = ggzyAnnouncementTypeById.getTransactionTypeName();
                if(!ObjectUtils.isEmpty(transactionTypeName)){
                    ggzyContentDistribution.setTransactionTypeName(transactionTypeName);
                }
            }
        }
		String industriesTypeCode = ggzyContentDistribution.getIndustriesTypeCode();
		if(!ObjectUtils.isEmpty(industriesTypeCode)){
			GgzyIndustryType ggzyIndustryType = getGgzyIndustryType(industriesTypeCode);
			if(!ObjectUtils.isEmpty(ggzyIndustryType)){
				String industriesTypeName = ggzyIndustryType.getIndustriesTypeName();
				ggzyContentDistribution.setIndustriesTypeName(industriesTypeName);
			}
		}
		ggzyContentDistributionService.saveOrUpdate(ggzyContentDistribution);
		return Result.OK("编辑成功!");
	}

	private GgzyAnnouncementType getGgzyAnnouncementTypeById(String id){
		GgzyAnnouncementType byId = iGgzyAnnouncementTypeService.getById(id);
		return byId;
	}

	 private GgzyQxqCodeMapping getGgzyQxqCodeMapping(String codePram){
		 QueryWrapper<GgzyQxqCodeMapping> queryWrapper = new QueryWrapper<GgzyQxqCodeMapping>();
		 Page<GgzyQxqCodeMapping> page = new Page<GgzyQxqCodeMapping>(1, 1);
		 queryWrapper.eq("code_pram",codePram);
		 IPage<GgzyQxqCodeMapping> pageList = iGgzyQxqCodeMappingService.page(page, queryWrapper);
		 if(!ObjectUtils.isEmpty(pageList)){
			 List<GgzyQxqCodeMapping> records = pageList.getRecords();
			 if(!ObjectUtils.isEmpty(records)){
				 int size = records.size();
				 if(size >= 1){
					 GgzyQxqCodeMapping codeMapping = records.get(0);
					 if(!ObjectUtils.isEmpty(codeMapping)){
						 return codeMapping;
					 }
				 }
			 }
		 }
		 return null;
	 }

	private GgzyRegionalCodeMapping getGgzyRegionalCodeMapping(String platformCode){
		QueryWrapper<GgzyRegionalCodeMapping> queryWrapper = new QueryWrapper<GgzyRegionalCodeMapping>();
		Page<GgzyRegionalCodeMapping> page = new Page<GgzyRegionalCodeMapping>(1, 1);
		queryWrapper.eq("platform_code",platformCode);
		IPage<GgzyRegionalCodeMapping> pageList = iGgzyRegionalCodeMappingService.page(page, queryWrapper);
		if(!ObjectUtils.isEmpty(pageList)){
			List<GgzyRegionalCodeMapping> records = pageList.getRecords();
			if(!ObjectUtils.isEmpty(records)){
				int size = records.size();
				if(size >= 1){
					GgzyRegionalCodeMapping codeMapping = records.get(0);
					if(!ObjectUtils.isEmpty(codeMapping)){
						return codeMapping;
					}
				}
			}
		}
		return null;
	}

	private GcProject getGcProject(String projectCode){
		QueryWrapper<GcProject> queryWrapper = new QueryWrapper<GcProject>();
		Page<GcProject> page = new Page<GcProject>(1, 1);
		queryWrapper.eq("project_code",projectCode);
		IPage<GcProject> pageList = gcProjectService.page(page, queryWrapper);
		if(!ObjectUtils.isEmpty(pageList)){
			List<GcProject> records = pageList.getRecords();
			if(!ObjectUtils.isEmpty(records)){
				int size = records.size();
				if(size >= 1){
					GcProject gcProject = records.get(0);
					return gcProject;
				}
			}
		}
		return null;
	}


	private GgzyIndustryType getGgzyIndustryType(String industryTypeCode){
		QueryWrapper<GgzyIndustryType> queryWrapper = new QueryWrapper<GgzyIndustryType>();
		Page<GgzyIndustryType> page = new Page<GgzyIndustryType>(1, 1);
		queryWrapper.eq("industries_type_code",industryTypeCode);
		IPage<GgzyIndustryType> pageList = iGgzyIndustryTypeService.page(page, queryWrapper);
		if(!ObjectUtils.isEmpty(pageList)){
			List<GgzyIndustryType> records = pageList.getRecords();
			if(!ObjectUtils.isEmpty(records)){
				int size = records.size();
				if(size >= 1){
					GgzyIndustryType ggzyIndustryType = records.get(0);
					return ggzyIndustryType;
				}
			}
		}
		return null;
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "公共资源内容发布-通过id删除")
	@ApiOperation(value="公共资源内容发布-通过id删除", notes="公共资源内容发布-通过id删除")
	@RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		ggzyContentDistributionService.removeById(id);
		GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(id);
		if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
			List<GgzyContentDistribution> ggzyContentDistributions = new ArrayList<GgzyContentDistribution>();
			ggzyContentDistributions.add(ggzyContentDistribution);
			revokeOneVo(ggzyContentDistributions);
		}
		return Result.OK("删除成功!");
	}

	/*
	发布
	* */
	 @DeleteMapping(value = "/releaseOne")
	 public Result<String> releaseOne(@RequestParam(name="id",required=true) String id) {
		 GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(id);
		 if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
			 List<GgzyContentDistribution> ggzyContentDistributions = new ArrayList<GgzyContentDistribution>();
			 ggzyContentDistributions.add(ggzyContentDistribution);
			 boolean b = releaseOneVo(ggzyContentDistributions);
			 if(b){
				 ggzyContentDistribution.setIsSynchronous("2");
				 ggzyContentDistributionService.updateById(ggzyContentDistribution);
			 }
		 }
		 return Result.OK("发布成功!");
	 }
	 /*
     撤销
     * */
	 @DeleteMapping(value = "/revokeOne")
	 public Result<String> revokeOne(@RequestParam(name="id",required=true) String id) {
		 GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(id);
		 if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
			 List<GgzyContentDistribution> ggzyContentDistributions = new ArrayList<GgzyContentDistribution>();
			 ggzyContentDistributions.add(ggzyContentDistribution);
			 boolean b = revokeOneVo(ggzyContentDistributions);
			 if(b){
				 ggzyContentDistribution.setIsSynchronous("3");
				 ggzyContentDistributionService.updateById(ggzyContentDistribution);
			 }
		 }

		 return Result.OK("撤销成功!");
	 }

	 //发布
	 public boolean releaseOneVo(List<GgzyContentDistribution> ggzyContentDistributions) {
		 List<TenderDetailsVo> tenderDetailsVoList = new ArrayList<TenderDetailsVo>();
		 Boolean aBoolean = false;
		 for (GgzyContentDistribution ggzyContentDistribution : ggzyContentDistributions) {
			 if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
				 TenderDetailsVo tenderDetailsVo = getTenderDetailsVo(ggzyContentDistribution);
				 if(!ObjectUtils.isEmpty(tenderDetailsVo)){
					 tenderDetailsVoList.add(tenderDetailsVo);
				 }
			 }

		 }
		 if(tenderDetailsVoList.size() > 0){
			 try {
				 aBoolean = tenderDetailsVoService.releasTenderDetailsVo(tenderDetailsVoList);
			 }catch (Exception e){
				e.printStackTrace();
			 }
		 }
		 return aBoolean;
	 }

	 //撤销
	 public boolean revokeOneVo(List<GgzyContentDistribution> ggzyContentDistributions) {
		 List<TenderDetailsVo> tenderDetailsVoList = new ArrayList<TenderDetailsVo>();
		 Boolean aBoolean = false;
		 if(!ObjectUtils.isEmpty(ggzyContentDistributions)){
			 if(ggzyContentDistributions.size() > 0){
				 for (GgzyContentDistribution ggzyContentDistribution : ggzyContentDistributions) {
					 if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
						 TenderDetailsVo tenderDetailsVo = getTenderDetailsVo(ggzyContentDistribution);
						 if(!ObjectUtils.isEmpty(tenderDetailsVo)){
							 tenderDetailsVoList.add(tenderDetailsVo);
						 }
					 }
				 }
				 if(tenderDetailsVoList.size() > 0){
					 try {
						 aBoolean = tenderDetailsVoService.revokeTenderDetailsVo(tenderDetailsVoList);
					 }catch (Exception e){
						 e.printStackTrace();
					 }
				 }
			 }
		 }
		 return aBoolean;
	 }

	 private TenderDetailsVo getTenderDetailsVo(GgzyContentDistribution ggzyContentDistribution) {
		 TenderDetailsVo tenderDetailsVo = null;
		 if(!ObjectUtils.isEmpty(ggzyContentDistribution)){
			 tenderDetailsVo = new TenderDetailsVo();
			 String sourceDataKey = ggzyContentDistribution.getSourceDataKey();
			 if(!ObjectUtils.isEmpty(sourceDataKey)){
				 tenderDetailsVo.setSourceDataKey(sourceDataKey);
			 }
			 String projectCode = ggzyContentDistribution.getProjectCode();
			 if(!ObjectUtils.isEmpty(sourceDataKey)){
				 tenderDetailsVo.setProjectCode(projectCode);
			 }
			 String projectName = ggzyContentDistribution.getProjectName();
			 if(!ObjectUtils.isEmpty(projectName)){
				 tenderDetailsVo.setProjectName(projectName);
			 }
			 String tenderProjectCode = ggzyContentDistribution.getTenderProjectCode();
			 if(!ObjectUtils.isEmpty(tenderProjectCode)){
				 tenderDetailsVo.setTenderProjectCode(tenderProjectCode);
			 }
			 String noticeName = ggzyContentDistribution.getNoticeName();
			 if(!ObjectUtils.isEmpty(noticeName)){
				 tenderDetailsVo.setNoticeName(noticeName);
			 }
			 String noticeContent = ggzyContentDistribution.getNoticeContent();
			 if(!ObjectUtils.isEmpty(noticeContent)){
				 tenderDetailsVo.setNoticeContent(noticeContent);
			 }
			 Date noticeSendTime = ggzyContentDistribution.getNoticeSendTime();
			 if(!ObjectUtils.isEmpty(noticeSendTime)){
				 String noticeSendTimeStr = DateUtils.formatDate(noticeSendTime, "yyyy-MM-dd HH:mm:ss");
				 tenderDetailsVo.setNoticeSendTime(noticeSendTimeStr);
			 }
			 String noticeNature = ggzyContentDistribution.getNoticeNature();
			 if(!ObjectUtils.isEmpty(noticeNature)){
				 tenderDetailsVo.setNoticeNature(noticeNature);
			 }
			 String noticeNatureName = ggzyContentDistribution.getNoticeNatureName();
			 if(!ObjectUtils.isEmpty(noticeNatureName)){
				 tenderDetailsVo.setNoticeNatureName(noticeNatureName);
			 }
			 String regionCode = ggzyContentDistribution.getRegionCode();
			 if(!ObjectUtils.isEmpty(regionCode)){
				 tenderDetailsVo.setRegionCode(regionCode);
			 }
			 String regionName = ggzyContentDistribution.getRegionName();
			 if(!ObjectUtils.isEmpty(regionName)){
				 tenderDetailsVo.setRegionName(regionName);
			 }
			 String industriesTypeCode = ggzyContentDistribution.getIndustriesTypeCode();
			 if(!ObjectUtils.isEmpty(industriesTypeCode)){
				 tenderDetailsVo.setIndustriesTypeCode(industriesTypeCode);
			 }
			 String industriesTypeName = ggzyContentDistribution.getIndustriesTypeName();
			 if(!ObjectUtils.isEmpty(industriesTypeName)){
				 tenderDetailsVo.setIndustriesTypeName(industriesTypeName);
			 }
			 String platformCode = ggzyContentDistribution.getPlatformCode();
			 if(!ObjectUtils.isEmpty(platformCode)){
				 tenderDetailsVo.setPlatformCode(platformCode);
			 }
			 String platformName = ggzyContentDistribution.getPlatformName();
			 if(!ObjectUtils.isEmpty(platformName)){
				 tenderDetailsVo.setPlatformName(platformName);
			 }
			 String noticeTypeCode = ggzyContentDistribution.getNoticeTypeCode();
			 if(!ObjectUtils.isEmpty(noticeTypeCode)){
				 tenderDetailsVo.setNoticeTypeCode(noticeTypeCode);
			 }
			 String noticeTypeName = ggzyContentDistribution.getNoticeTypeName();
			 if(!ObjectUtils.isEmpty(noticeTypeName)){
				 tenderDetailsVo.setNoticeTypeName(noticeTypeName);
			 }
			 String transactionTypeCode = ggzyContentDistribution.getTransactionTypeCode();
			 if(!ObjectUtils.isEmpty(transactionTypeCode)){
				 tenderDetailsVo.setTransactionTypeCode(transactionTypeCode);
			 }
			 String transactionTypeName = ggzyContentDistribution.getTransactionTypeName();
			 if(!ObjectUtils.isEmpty(transactionTypeName)){
				 tenderDetailsVo.setTransactionTypeName(transactionTypeName);
			 }
			 String bulletinTypeCode = ggzyContentDistribution.getBulletinTypeCode();
			 if(!ObjectUtils.isEmpty(bulletinTypeCode)){
				 tenderDetailsVo.setBulletinTypeCode(bulletinTypeCode);
			 }
			 String bulletinTypeName = ggzyContentDistribution.getBulletinTypeName();
			 if(!ObjectUtils.isEmpty(bulletinTypeName)){
				 tenderDetailsVo.setBulletinTypeName(bulletinTypeName);
			 }
			 String bulletinDuty = ggzyContentDistribution.getBulletinDuty();
			 if(!ObjectUtils.isEmpty(bulletinDuty)){
				 tenderDetailsVo.setBulletinDuty(bulletinDuty);
			 }
			 String dataSourceCode = ggzyContentDistribution.getDataSourceCode();
			 if(!ObjectUtils.isEmpty(dataSourceCode)){
				 tenderDetailsVo.setDataSourceCode(dataSourceCode);
			 }
			 String dataSourceName = ggzyContentDistribution.getDataSourceName();
			 if(!ObjectUtils.isEmpty(dataSourceName)){
				 tenderDetailsVo.setDataSourceName(dataSourceName);
			 }
			 String noticeBidNum = ggzyContentDistribution.getNoticeBidNum();
			 if(!ObjectUtils.isEmpty(noticeBidNum)){
				 tenderDetailsVo.setNoticeBidNum(noticeBidNum);
			 }
			 if(!ObjectUtils.isEmpty(projectCode)){
				 tenderDetailsVo.setBidSectionCodes(projectCode);
			 }
			 try{
				 String projectCodeArr[] = {projectCode};
				 tenderDetailsVo.setBidSectionCodesArr(projectCodeArr);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
			 Date docGetStartTime = ggzyContentDistribution.getDocGetStartTime();
			 if(!ObjectUtils.isEmpty(docGetStartTime)){
				 String docGetStartTimeStr = DateUtils.formatDate(docGetStartTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(docGetStartTimeStr)){
					 tenderDetailsVo.setDocGetStartTime(docGetStartTimeStr);
				 }
			 }
			 Date docGetEndTime = ggzyContentDistribution.getDocGetEndTime();
			 if(!ObjectUtils.isEmpty(docGetEndTime)){
				 String docGetEndTimeStr = DateUtils.formatDate(docGetEndTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(docGetEndTimeStr)){
					 tenderDetailsVo.setDocGetEndTime(docGetEndTimeStr);
				 }
			 }
			 Date bidDocReferEndTime = ggzyContentDistribution.getBidDocReferEndTime();
			 if(!ObjectUtils.isEmpty(bidDocReferEndTime)){
				 String bidDocReferEndTimeStr = DateUtils.formatDate(bidDocReferEndTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(bidDocReferEndTimeStr)){
					 tenderDetailsVo.setBidDocReferEndTime(bidDocReferEndTimeStr);
				 }
			 }
			 Date bidOpenTime = ggzyContentDistribution.getBidOpenTime();
			 if(!ObjectUtils.isEmpty(bidOpenTime)){
				 String bidOpenTimeStr = DateUtils.formatDate(bidOpenTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(bidOpenTimeStr)){
					 tenderDetailsVo.setBidOpenTime(bidOpenTimeStr);
				 }
			 }
			 Integer validPeriod = ggzyContentDistribution.getValidPeriod();
			 if(!ObjectUtils.isEmpty(validPeriod)){
				 tenderDetailsVo.setValidPeriod(String.valueOf(validPeriod));
			 }
			 Date clarifyTime = ggzyContentDistribution.getClarifyTime();
			 if(!ObjectUtils.isEmpty(clarifyTime)){
				 String clarifyTimeStr = DateUtils.formatDate(clarifyTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(clarifyTimeStr)){
					 tenderDetailsVo.setClarifyTime(clarifyTimeStr);
				 }
			 }
			 Date submitTime = ggzyContentDistribution.getSubmitTime();
			 if(!ObjectUtils.isEmpty(submitTime)){
				 String submitTimeStr = DateUtils.formatDate(submitTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(submitTimeStr)){
					 tenderDetailsVo.setSubmitTime(submitTimeStr);
				 }
			 }
			 String bidOpeningAddress = ggzyContentDistribution.getBidOpeningAddress();
			 if(!ObjectUtils.isEmpty(bidOpeningAddress)){
				 tenderDetailsVo.setBidOpeningAddress(bidOpeningAddress);
			 }
			 Date bidOpeningTime = ggzyContentDistribution.getBidOpeningTime();
			 if(!ObjectUtils.isEmpty(bidOpeningTime)){
				 String bidOpeningTimeStr = DateUtils.formatDate(bidOpeningTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(bidOpeningTimeStr)){
					 tenderDetailsVo.setBidOpeningTime(bidOpeningTimeStr);
				 }
			 }
			 Date bidFinishTime = ggzyContentDistribution.getBidFinishTime();
			 if(!ObjectUtils.isEmpty(bidFinishTime)){
				 String bidFinishTimeStr = DateUtils.formatDate(bidFinishTime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(bidFinishTimeStr)){
					 tenderDetailsVo.setBidFinishTime(bidFinishTimeStr);
				 }
			 }
			 String file = ggzyContentDistribution.getFile();
			 if(!ObjectUtils.isEmpty(file)){
				 tenderDetailsVo.setFile(file);
			 }
			 tenderDetailsVo.setDocstatus("10");
			 Date docpubtime = ggzyContentDistribution.getDocpubtime();
			 if(!ObjectUtils.isEmpty(docpubtime)){
				 String docpubtimeStr = DateUtils.formatDate(docpubtime, "yyyy-MM-dd HH:mm:ss");
				 if(!ObjectUtils.isEmpty(docpubtimeStr)){
					 tenderDetailsVo.setDocpubtime(docpubtimeStr);
				 }
			 }
		 }
		 tenderDetailsVo = TenderDetailsVoUtils.isNull(tenderDetailsVo);
		 return tenderDetailsVo;
	 }
	 /**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "公共资源内容发布-批量删除")
	@ApiOperation(value="公共资源内容发布-批量删除", notes="公共资源内容发布-批量删除")
	@RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.ggzyContentDistributionService.removeByIds(Arrays.asList(ids.split(",")));
		List<String> stringList = Arrays.asList(ids.split(","));
		List<GgzyContentDistribution> ggzyContentDistributionList = new ArrayList<GgzyContentDistribution>();
		for (String sid : stringList) {
			GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(sid);
			ggzyContentDistributionList.add(ggzyContentDistribution);
		}
		boolean flag = revokeOneVo(ggzyContentDistributionList);
		if(flag){
			for (GgzyContentDistribution ggzyContentDistribution : ggzyContentDistributionList) {
				ggzyContentDistribution.setIsSynchronous("3");
				ggzyContentDistributionService.updateById(ggzyContentDistribution);
			}
			return Result.OK("批量删除成功!");
		}
		return Result.error("批量删除失败!");
	}

	 @DeleteMapping(value = "/releaseBatch")
	 public Result<String> releaseBatch(@RequestParam(name="ids",required=true) String ids) {
		 List<String> stringList = Arrays.asList(ids.split(","));
		 List<GgzyContentDistribution> ggzyContentDistributionList = new ArrayList<GgzyContentDistribution>();
		 for (String sid : stringList) {
			 GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(sid);
			 ggzyContentDistributionList.add(ggzyContentDistribution);

		 }
		 boolean b = releaseOneVo(ggzyContentDistributionList);
		 if(b){
			 for (GgzyContentDistribution ggzyContentDistribution : ggzyContentDistributionList) {
				 ggzyContentDistribution.setIsSynchronous("2");
				 ggzyContentDistributionService.updateById(ggzyContentDistribution);
			 }
		 }

		 return Result.OK("批量发布成功!");
	 }
	 @DeleteMapping(value = "/revokeBatch")
	 public Result<String> revokeBatch(@RequestParam(name="ids",required=true) String ids) {
		 List<String> stringList = Arrays.asList(ids.split(","));
		 List<GgzyContentDistribution> ggzyContentDistributionList = new ArrayList<GgzyContentDistribution>();
		 for (String sid : stringList) {
			 GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(sid);
			 ggzyContentDistributionList.add(ggzyContentDistribution);

		 }
		 boolean b = revokeOneVo(ggzyContentDistributionList);
		 if(b){
			 for (GgzyContentDistribution ggzyContentDistribution : ggzyContentDistributionList) {
				 ggzyContentDistribution.setIsSynchronous("3");
				 ggzyContentDistributionService.updateById(ggzyContentDistribution);
			 }
		 }

		 return Result.OK("批量撤销成功!");
	 }
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "公共资源内容发布-通过id查询")
	@ApiOperation(value="公共资源内容发布-通过id查询", notes="公共资源内容发布-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<GgzyContentDistribution> queryById(@RequestParam(name="id",required=true) String id) {
		GgzyContentDistribution ggzyContentDistribution = ggzyContentDistributionService.getById(id);
		if(ggzyContentDistribution==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(ggzyContentDistribution);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param ggzyContentDistribution
    */
    @RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, GgzyContentDistribution ggzyContentDistribution) {
        return super.exportXls(request, ggzyContentDistribution, GgzyContentDistribution.class, "公共资源内容发布");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("ggzycontentdistribution:ggzy_content_distribution:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, GgzyContentDistribution.class);
    }

}
