package cn.com.countrygarden.bi.main.service.wcx.impl;

import cn.com.countrygarden.bi.main.constant.wcx.enumeration.WcxAuditRoleEnum;
import cn.com.countrygarden.bi.main.constant.wcx.enumeration.WcxSysRoleEnum;
import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dao.twerp.hm.TbSysUserMapper;
import cn.com.countrygarden.bi.main.dao.wcx.*;
import cn.com.countrygarden.bi.main.dto.wcx.WcxInnovationDto;
import cn.com.countrygarden.bi.main.dto.wcx.WcxWeeklyStatisticsDTO;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.sys.UserRoles;
import cn.com.countrygarden.bi.main.model.twerp.ErpCommunity;
import cn.com.countrygarden.bi.main.model.wcx.WcxFile;
import cn.com.countrygarden.bi.main.model.wcx.WcxWeeklyStatistics;
import cn.com.countrygarden.bi.main.model.wcx.WcxWeeklyStatisticsRegion;
import cn.com.countrygarden.bi.main.model.wcx.WcxWeeklyStatisticsRegionProject;
import cn.com.countrygarden.bi.main.service.wcx.WcxInnovationService;
import cn.com.countrygarden.bi.main.service.wcx.WcxRegionProjectService;
import cn.com.countrygarden.bi.main.service.wcx.WcxService;
import cn.com.countrygarden.bi.main.util.PageUtil;
import cn.com.countrygarden.bi.main.util.erp.StringUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageRowBounds;
import com.vdurmont.emoji.EmojiParser;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2018/6/23.
 */
@Service
public class WcxInnovationServiceImpl implements WcxInnovationService {
    @Autowired
    private WcxInnovationMapper wcxInnovationMapper;
    //    @Autowired
//    private WcxFileMapper wcxFileMapper;
    @Autowired
    private WcxRegionProjectMapper wcxRegionProjectMapper;
    @Autowired
    private WcxThumbMapper wcxThumbMapper;
    @Autowired
    private WcxReviewMapper wcxReviewMapper;
    @Autowired
    private WcxContentMapper wcxContentMapper;
    @Autowired
    private WcxInnovationOtherMapper wcxInnovationOtherMapper;
    @Autowired
    private TbSysUserMapper tbSysUserMapper;
    @Autowired
    private WcxRegionProjectService wcxRegionProjectService;
    @Autowired
    private WcxInnovationService wcxInnovationService;
    @Autowired
    private WcxService wcxService;
    @Autowired
    private WcxWeeklyStatisticsMapper wcxWeeklyStatisticsMapper;

    @Autowired
    private WcxWeeklyStatisticsRegionMapper weeklyStatisticsRegionMapper;

    @Autowired
    private WcxWeeklyStatisticsRegionProjectMapper weeklyStatisticsRegionProjectMapper;

    @Override
    public PageData selectPageList(WcxInnovationDto dto) throws UnsupportedEncodingException {

         if(StringUtil.isBlank(dto.getInnovationTitle()) && StringUtil.isBlank(dto.getEmployeeName())
                 && StringUtil.isBlank(dto.getStartDateStr()) && StringUtil.isBlank(dto.getEndDateStr()) && StringUtil.isBlank(dto.getRoleType())
         && StringUtil.isBlank(dto.getRegionName()) && StringUtil.isBlank(dto.getProjectName()) && StringUtil.isBlank(dto.getBaseline()) && StringUtil.isBlank(dto.getClassification())
         && dto.getIsRecomm()==null && dto.getIsTop()==null && dto.getIsExcellent()==null){

             dto.setIsMoren(1);
             SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
             SimpleDateFormat sfda = new SimpleDateFormat("yyyy-MM-dd");
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(new Date());
             calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
             String shangTime=sf.format(calendar.getTime())+"-01";
             String xianTime=sfda.format(new Date());

             dto.setStartDateStr(shangTime+" 00:00:00");
             dto.setEndDateStr(xianTime+" 23:59:59");
         }

        List<WcxInnovationDto> dataNofen = wcxInnovationMapper.selectPageDataNofen(dto);

        //List <String> idList=new ArrayList<>();
        int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(), dto.getPageSize());
        dto.setPageOffset(pageOffset);
        dto.setExamineStatus("1");
        List<WcxInnovationDto> data = wcxInnovationMapper.selectPageData(dto);

        //List <String> idList=wcxInnovationMapper.selectIdList(dto);
        List <String> idList=new ArrayList<>();
        // 设置领导点赞数
        if (data != null && !data.isEmpty()) {
            for (WcxInnovationDto datum : data) {
                String innovationId = datum.getInnovationId();
                //int leadThumbNumber = wcxThumbMapper.getLeadThumbNumberByInnId(innovationId);
                // 大领导点赞数
                Integer bigLeadThumbNumber = wcxThumbMapper.findBigLeadThumbNumber(innovationId);
                datum.setLeaderThumbNumber(bigLeadThumbNumber == null ? 0 : bigLeadThumbNumber);
                if(StringUtil.isNotBlank(datum.getInnovationContent())){
                    String result= EmojiParser.parseToUnicode(datum.getInnovationContent());
                    datum.setInnovationContent(result);
                }
                if(StringUtil.isNotBlank(datum.getInnovationTitle())){
                    String resultTitle= EmojiParser.parseToUnicode(datum.getInnovationTitle());
                    datum.setInnovationTitle(resultTitle);
                }
            }

        }
        if (dataNofen != null && !dataNofen.isEmpty()) {
            for (int i = 0; i < dataNofen.size(); i++) {
                idList.add(dataNofen.get(i).getInnovationId());
            }
            data.get(0).setInnovationIdList(idList);
        }



        Long total = wcxInnovationMapper.selectPageCount(dto);

        PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
        pageRowBounds.setTotal(total);
        pageRowBounds.setCount(true);
        if(CollectionUtils.isNotEmpty(data)){
            data.get(0).setRoleCodeAdmin(dto.getRoleCodeAdmin());
        }
        PageData pageData = new PageData(data, pageRowBounds);
        return pageData;
    }

    @Override
    public WcxInnovationDto selectWcxInnovationDto(WcxInnovationDto condition) {
        WcxInnovationDto wcxInnDto = null;
        wcxInnDto = wcxInnovationMapper.selectOneDto(condition);
        if(wcxInnDto==null){
            wcxInnDto=wcxInnovationMapper.selectgetOne(condition);
        }
        int leadThumbNumber = wcxThumbMapper.getLeadThumbNumberByInnId(condition.getInnovationId());
        wcxInnDto.setLeaderThumbNumber(leadThumbNumber);
         if(StringUtil.isNotBlank(wcxInnDto.getInnovationTitle())){
             String resultTitle= EmojiParser.parseToUnicode(wcxInnDto.getInnovationTitle());
             wcxInnDto.setInnovationTitle(resultTitle);
         }
         if(StringUtil.isNotBlank(wcxInnDto.getInnovationContent())){
             String result= EmojiParser.parseToUnicode(wcxInnDto.getInnovationContent());
             wcxInnDto.setInnovationContent(result);
         }
        return wcxInnDto;
    }

    @Override
    public WcxInnovationDto selectWcxInnovationDto(String innoId) {
        WcxInnovationDto param = new WcxInnovationDto();
        param.setInnovationId(innoId);
        WcxInnovationDto innoDto = this.selectWcxInnovationDto(param);
        return innoDto;
    }

    @Override
    @Transactional
    public void delete(String innovationId) {
        // 判断是否有评论
        String haveReview = wcxInnovationMapper.haveReview(innovationId);
        if (StringUtils.hasText(haveReview)) {
            throw new ServiceException("创新下包含评论不能删除,请先删除评论");
        }
        // 相关点赞全部删除
        wcxThumbMapper.deleteByInnovationId(innovationId);
        // 删除内容
        wcxContentMapper.deleteByInnovationId(innovationId);
        // 图片状态全部置为0
        wcxInnovationMapper.deleteByPrimateKey(innovationId);
    }

    private WcxFile wcxFileConstructor(String fileId, String fileType, String fileUrl, String innovationId, String status, Date createDate) {
        WcxFile wcxFile = new WcxFile();
        wcxFile.setFileId(fileId);
        wcxFile.setFileType(fileType);
        wcxFile.setFileUrl(fileUrl);
        wcxFile.setInnovationId(innovationId);
        wcxFile.setStatus(status);
        wcxFile.setCreateDate(createDate);
        return wcxFile;
    }

    public List<WcxInnovationDto> selectSimplePageData(String innovationTitle) {
        WcxInnovationDto param = new WcxInnovationDto();
        param.setPageOffset(0);
        param.setPageSize(10);
        param.setInnovationTitle(innovationTitle);
        List<WcxInnovationDto> innoSimpleDtos = wcxInnovationMapper.findSimplePageData(param);
        return innoSimpleDtos;
    }

    @Override
    public WcxInnovationDto select(String innovationId) {
        WcxInnovationDto param = new WcxInnovationDto();
        param.setInnovationId(innovationId);
        WcxInnovationDto result = wcxInnovationMapper.selectOneDto(param);
        return result;
    }

    /**
     * 获取用户可操作的对应基线
     *
     * @param userRoles
     * @return 管理员权限 返回null;
     * 区域权限 返回 0
     * 部分权限 返回对应基线码(1,2,3....)
     */
    public String getBaseline(List<UserRoles> userRoles) {
        List<String> baselineCodes = new ArrayList<>();
        for (UserRoles userRole : userRoles) {
            String roleCode = userRole.getRoleCode();
            String baselineCode = WcxSysRoleEnum.getBaselineCode(roleCode);
            if (baselineCode != null) {
                baselineCodes.add(baselineCode);
            }
        }

        if (baselineCodes.isEmpty()) {
            throw new ServiceException("该用户没有权限查询信息");
        }

        String baseline = null;
        if (baselineCodes.contains("Z")) {
            // 表示具有所有权限
            baseline = null;
        } else {
            // 日志 如果一个人含有多个角色
            baseline = baselineCodes.get(0);
        }
        return baseline;
    }

    @Override
    public List<WcxInnovationDto> selectInnoList(WcxInnovationDto param) {

        List<WcxInnovationDto> data=null;
        param.setOrderByThumbNumber(null);
        if(StringUtil.isBlank(param.getInnovationTitle()) && StringUtil.isBlank(param.getEmployeeName())
                && StringUtil.isBlank(param.getStartDateStr()) && StringUtil.isBlank(param.getEndDateStr()) && StringUtil.isBlank(param.getRoleType())
                && StringUtil.isBlank(param.getRegionName()) && StringUtil.isBlank(param.getProjectName()) && StringUtil.isBlank(param.getBaseline()) && StringUtil.isBlank(param.getClassification())
                && param.getIsRecomm()==null && param.getIsTop()==null && param.getIsExcellent()==null){

            param.setIsMoren(1);
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
            SimpleDateFormat sfda = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
            String shangTime=sf.format(calendar.getTime())+"-01";
            String xianTime=sfda.format(new Date());

            param.setStartDateStr(shangTime+" 00:00:00");
            param.setEndDateStr(xianTime+" 23:59:59");

        }
        if(StringUtil.isBlank(param.getExamineStatus())){
            param.setExamineStatus("0");
        }
        if(param.getExamineStatus().equals("1")){
            data = wcxInnovationMapper.selectPageData(param);
        }else {
            data = wcxInnovationMapper.selectPageDataNot(param);
        }
        // 设置领导点赞数
        if (data != null && !data.isEmpty()) {
            for (WcxInnovationDto datum : data) {
                String innovationId = datum.getInnovationId();
                int leadThumbNumber = wcxThumbMapper.getLeadThumbNumberByInnId(innovationId);
                datum.setLeaderThumbNumber(leadThumbNumber);
            }
        }
        return data;
    }

    @Override
    public int examine(WcxInnovationDto wcxInnovationDto) {
        return wcxInnovationMapper.examine(wcxInnovationDto);
    }
    @Override
    public int examineStatus(String innovationId) {
        int examineStatus=wcxInnovationMapper.examineStatus(innovationId);
        return examineStatus;
    }

    @Override
    public int addExamine(String innovationId, String baseline) {
        String roleCode= WcxAuditRoleEnum.getRoleCode(baseline);
        //查询数据的信息
        WcxInnovationDto result = wcxInnovationService.select(innovationId);
        //获取用户编码list
        List<String> userCodeList=wcxInnovationMapper.getUserCode(roleCode);
        String test = result.getRegionName();
        String region=test.substring(0,3);
        List<String>userName=wcxRegionProjectService.selectErpRegionNameByIn(userCodeList,region);
        String name=String.join(",", userName);
        try {
            wcxInnovationMapper.updateExamine(name,innovationId);
        }catch (Exception e){
            throw e;
        }
        return 0;
    }

    /**
     * 更新创新表id对应的基础业务线
     *
     * @param innovationId
     * @param baseline
     * @return
     */
    @Override
    public void updateBaseLineById(String innovationId, String baseline) {
        if (wcxInnovationMapper.findById(innovationId) == 0) {
            throw new ServiceException("创新id不存在");
        }
        wcxInnovationMapper.updateBaseLineById(innovationId, baseline);
    }

    /**
     * 分页查询审核页面数据
     * @param dto
     * @return
     */
    @Override
    public PageData selectPageListForAudit(WcxInnovationDto dto) {
        if(StringUtil.isBlank(dto.getInnovationTitle()) && StringUtil.isBlank(dto.getEmployeeName())
                && StringUtil.isBlank(dto.getStartDateStr()) && StringUtil.isBlank(dto.getEndDateStr()) && StringUtil.isBlank(dto.getRoleType())
                && StringUtil.isBlank(dto.getRegionName()) && StringUtil.isBlank(dto.getProjectName()) && StringUtil.isBlank(dto.getBaseline()) && StringUtil.isBlank(dto.getClassification())
                && dto.getIsRecomm()==null && dto.getIsTop()==null && dto.getIsExcellent()==null){

            dto.setIsMoren(1);
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
            SimpleDateFormat sfda = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
            String shangTime=sf.format(calendar.getTime())+"-01";
            String xianTime=sfda.format(new Date());

            dto.setStartDateStr(shangTime+" 00:00:00");
            dto.setEndDateStr(xianTime+" 23:59:59");
        }

        //List<WcxInnovationDto> dataNofen = wcxInnovationMapper.selectPageDataNofen(dto);


        List<WcxInnovationDto> dataNofenShenhe = wcxInnovationMapper.selectPageDataNofenShenhe(dto);

        int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(), dto.getPageSize());
        dto.setPageOffset(pageOffset);


        List<WcxInnovationDto> data = wcxInnovationMapper.selectPageData(dto);

        //List <String> idList=wcxInnovationMapper.selectIdListAudit(dto);
        //List <String> idListzhe=wcxInnovationMapper.selectIdList(dto);
        List <String> idList=new ArrayList<>();
        List <String> idListzhe=new ArrayList<>();
        for (int i = 0; i <data.size() ; i++) {
            String result= EmojiParser.parseToUnicode(data.get(i).getInnovationTitle());
            data.get(i).setInnovationTitle(result);
        }
        if(CollectionUtils.isNotEmpty(data)){
     /*       for (int i = 0; i <dataNofen.size() ; i++) {
                idListzhe.add(dataNofen.get(i).getInnovationId());
            }
            data.get(0).setInnovationIdList(idListzhe);*/


            for (int i = 0; i <dataNofenShenhe.size() ; i++) {
                idList.add(dataNofenShenhe.get(i).getInnovationId());
            }
            data.get(0).setInnovationIdListshenhe(idList);
        }

    /*    if(CollectionUtils.isNotEmpty(data)){
            data.get(0).setInnovationIdListshenhe(idList);
            data.get(0).setInnovationIdList(idListzhe);
        }*/
        Long total = wcxInnovationMapper.selectPageCount(dto);
        PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
        pageRowBounds.setTotal(total);
        pageRowBounds.setCount(true);
        PageData pageData = new PageData(data, pageRowBounds);
        return pageData;
    }
    @Override
    public List<Map<String, String>> getErpOrgList() {
        List<Map<String, String>> resultList = new ArrayList<>();
        List<ErpCommunity> erpCommunityList = tbSysUserMapper.getErpOrgList();
        if (erpCommunityList != null && erpCommunityList.size() > 0) {
            for (ErpCommunity erpCommunity : erpCommunityList) {
                Map<String, String> tempMap = new HashMap<>();
                tempMap.put("organName", erpCommunity.getOrganName());
                resultList.add(tempMap);
            }
        }
        return resultList;
    }

    @Override
    public Result addTop(String innovationId,Integer isTop,String sysUserCode) {
        try {
            WcxInnovationDto wcxIonDto=new WcxInnovationDto();
            wcxIonDto.setInnovationId(innovationId);
            if(isTop.equals(1)){
                wcxIonDto.setUpdateTime(new Date());
            }else {
                wcxIonDto.setUpdateTime(null);
            }
            wcxIonDto.setIsTop(isTop);
            wcxInnovationMapper.updateTop(wcxIonDto);
        }catch (Exception e){
            throw new ServiceException("置顶失败");
        }
        return Response.response();
    }

    @Override
    public Result addRecomm(String innovationId, Integer isRecomm, String sysUserCode) {
        try {
            WcxInnovationDto wcxIonDto=new WcxInnovationDto();
            wcxIonDto.setInnovationId(innovationId);
            if(isRecomm.equals(1)){
                wcxIonDto.setRecommTime(new Date());
            }else {
                wcxIonDto.setRecommTime(null);
            }
            wcxIonDto.setIsRecomm(isRecomm);
            wcxInnovationMapper.updateRecomm(wcxIonDto);
        }catch (Exception e){
            throw new ServiceException("推荐失败");
        }
        return Response.response();
    }

    @Override
    public Result addExcellent(String innovationId, Integer isExcellent, String sysUserCode) {
        WcxInnovationDto wcxIonDto=new WcxInnovationDto();
        wcxIonDto.setInnovationId(innovationId);
        wcxIonDto.setIsExcellent(isExcellent);
        wcxInnovationMapper.addExcellent(wcxIonDto);
        return Response.response();
    }

    @Override
    public WcxInnovationDto getInnovationShenhe(WcxInnovationDto condition) {

        WcxInnovationDto wcxInnDto = null;
        wcxInnDto = wcxInnovationMapper.selectOneDto(condition);
        if(wcxInnDto==null){
            wcxInnDto=wcxInnovationMapper.selectgetOne(condition);
        }
        int leadThumbNumber = wcxThumbMapper.getLeadThumbNumberByInnId(condition.getInnovationId());
        wcxInnDto.setLeaderThumbNumber(leadThumbNumber);
        if(StringUtil.isNotBlank(wcxInnDto.getInnovationTitle())){
            String resultTitle= EmojiParser.parseToUnicode(wcxInnDto.getInnovationTitle());
            wcxInnDto.setInnovationTitle(resultTitle);
        }
        if(StringUtil.isNotBlank(wcxInnDto.getInnovationContent())){
            String result= EmojiParser.parseToUnicode(wcxInnDto.getInnovationContent());
            wcxInnDto.setInnovationContent(result);
        }
        return wcxInnDto;
    }

    String zhouUrl="https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend?access_token=";


    @Override
    public void tongjizhou() throws ParseException, IOException {
//startTime  endTime
// visit_uv 访问人数   visit_uv_new  新用户数
        //{"visit_uv":9,"stay_time_uv":573.3333,"stay_time_session":55.4839,
        // "ref_date":"20180625-20180701",
        // "visit_depth":2.3978,"session_cnt":93,"visit_pv":423,"visit_uv_new":9}

     /*   SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;
        int offset1 = 1 - dayOfWeek;
        int offset2 = 7 - dayOfWeek;
        calendar1.add(Calendar.DATE, offset1 - 7);
        calendar2.add(Calendar.DATE, offset2 - 7);
        String lastBeginDate = sdf.format(calendar1.getTime());
        String lastEndDate = sdf.format(calendar2.getTime());
        System.out.println(lastBeginDate + "," + lastEndDate);

        String lastBeginDate2 = sdf2.format(calendar1.getTime());
        String lastEndDate2 = sdf2.format(calendar2.getTime());

        String[] startyuenian=lastBeginDate2.split("/");

        Map<String,Object> wxSessionMap = wcxService.getWxAccessToken();
        if(null == wxSessionMap){
           throw new ServiceException("调用返回值为空");
        }
        if(wxSessionMap.containsKey("errcode")){
            throw new ServiceException("调用返回值为空");
        }
        String accessToken = (String)wxSessionMap.get("access_token");

        String urlzh=zhouUrl+accessToken;
        String zhoushuju=wcxService.postUr(urlzh,lastBeginDate,lastEndDate);

        JSONObject object = JSONObject.parseObject(zhoushuju);
        String jsoerr=object.getString("errcode");
        if(StringUtil.isNotBlank(jsoerr)){
            throw new ServiceException("未知异常errcode");
        }

        JSONArray jsonlist=object.getJSONArray("list");
        WcxWeeklyStatistics weeklyStatistics=new WcxWeeklyStatistics();
        WcxWeeklyStatisticsRegion weeklyStatisticsRegion=new WcxWeeklyStatisticsRegion();
        WcxWeeklyStatisticsRegionProject weeklyStatisticsRegionProject=new WcxWeeklyStatisticsRegionProject();
        weeklyStatistics.setWekindex(1);
        weeklyStatisticsRegion.setWekindex(1);
        weeklyStatisticsRegionProject.setWekindex(1);
        weeklyStatistics.setDateRange(lastBeginDate2+"-"+lastEndDate2);
        weeklyStatisticsRegion.setDateRange(lastBeginDate2+"-"+lastEndDate2);
        weeklyStatisticsRegionProject.setDateRange(lastBeginDate2+"-"+lastEndDate2);

        Date date = sdf2.parse(lastBeginDate2);
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);

        Integer zhou=calendar.get(Calendar.WEEK_OF_YEAR);

        if(zhou<10&&zhou>0){
            weeklyStatistics.setWeek(startyuenian[0]+"年第"+"0"+zhou+"周");
            weeklyStatisticsRegion.setWeek(startyuenian[0]+"年第"+"0"+zhou+"周");
            weeklyStatisticsRegionProject.setWeek(startyuenian[0]+"年第"+"0"+zhou+"周");
        }else {
            weeklyStatistics.setWeek(startyuenian[0]+"年第"+zhou+"周");
            weeklyStatisticsRegion.setWeek(startyuenian[0]+"年第"+zhou+"周");
            weeklyStatisticsRegionProject.setWeek(startyuenian[0]+"年第"+zhou+"周");
        }

        if(jsonlist!=null){
            if(jsonlist.size()!=0){
                for (int j = 0; j < jsonlist.size(); j++) {
                    JSONObject jObject3=jsonlist.getJSONObject(j);
                    weeklyStatistics.setInnovationNum(0);
                    weeklyStatistics.setInnovationNumChain("0");
                    weeklyStatistics.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                    weeklyStatistics.setUserNumChain("0");
                    weeklyStatistics.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                    weeklyStatistics.setNewUserChain("0");

                    weeklyStatisticsRegion.setInnovationNum(0);
                    weeklyStatisticsRegion.setInnovationNumChain("0");
                    weeklyStatisticsRegion.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                    weeklyStatisticsRegion.setUserNumChain("0");
                    weeklyStatisticsRegion.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                    weeklyStatisticsRegion.setNewUserChain("0");


                    weeklyStatisticsRegionProject.setInnovationNum(0);
                    weeklyStatisticsRegionProject.setInnovationNumChain("0");
                    weeklyStatisticsRegionProject.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                    weeklyStatisticsRegionProject.setUserNumChain("0");
                    weeklyStatisticsRegionProject.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                    weeklyStatisticsRegionProject.setNewUserChain("0");
                }
            }else {
                weeklyStatistics.setInnovationNum(0);
                weeklyStatistics.setInnovationNumChain("0");
                weeklyStatistics.setUserNum(0);
                weeklyStatistics.setUserNumChain("0");
                weeklyStatistics.setNewUserNum(0);
                weeklyStatistics.setNewUserChain("0");

                weeklyStatisticsRegion.setInnovationNum(0);
                weeklyStatisticsRegion.setInnovationNumChain("0");
                weeklyStatisticsRegion.setUserNum(0);
                weeklyStatisticsRegion.setUserNumChain("0");
                weeklyStatisticsRegion.setNewUserNum(0);
                weeklyStatisticsRegion.setNewUserChain("0");

                weeklyStatisticsRegionProject.setInnovationNum(0);
                weeklyStatisticsRegionProject.setInnovationNumChain("0");
                weeklyStatisticsRegionProject.setUserNum(0);
                weeklyStatisticsRegionProject.setUserNumChain("0");
                weeklyStatisticsRegionProject.setNewUserNum(0);
                weeklyStatisticsRegionProject.setNewUserChain("0");
            }
            wcxWeeklyStatisticsMapper.insert(weeklyStatistics);
            weeklyStatisticsRegionMapper.insert(weeklyStatisticsRegion);
            weeklyStatisticsRegionProjectMapper.insert(weeklyStatisticsRegionProject);
        }


        List<WcxWeeklyStatistics> innovationNumZhouTongji= wcxWeeklyStatisticsMapper.innovationNumZhouTongji();
        for (int c = 0; c <innovationNumZhouTongji.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(innovationNumZhouTongji.get(c).getWeek());
            weics.setInnovationNum(innovationNumZhouTongji.get(c).getInnovationNum());
            weics.setInnovationNumChain(innovationNumZhouTongji.get(c).getInnovationNumChain());
            wcxWeeklyStatisticsMapper.updateWeek(weics);
        }

        List<WcxWeeklyStatisticsRegion> innovationNumZhouTongjiRegion=weeklyStatisticsRegionMapper.innovationNumZhouTongjiRegion();

        for (int i = 0; i <innovationNumZhouTongjiRegion.size() ; i++) {
            WcxWeeklyStatisticsRegion weeklyStion=new WcxWeeklyStatisticsRegion();
            weeklyStion.setWeek(innovationNumZhouTongjiRegion.get(i).getWeek());
            weeklyStion.setOrgCode(innovationNumZhouTongjiRegion.get(i).getOrgCode());
            weeklyStion.setOrgName(innovationNumZhouTongjiRegion.get(i).getOrgName());
            weeklyStion.setInnovationNum(innovationNumZhouTongjiRegion.get(i).getInnovationNum());
            weeklyStion.setInnovationNumChain(innovationNumZhouTongjiRegion.get(i).getInnovationNumChain());
            weeklyStatisticsRegionMapper.updateWeekRegion(weeklyStion);
        }

        List<WcxWeeklyStatisticsRegionProject> innovationNumZhouTongjiRegionProject=weeklyStatisticsRegionProjectMapper.innovationNumZhouTongjiRegionProject();

        for (int i = 0; i <innovationNumZhouTongjiRegionProject.size() ; i++) {
            WcxWeeklyStatisticsRegionProject weeklyStRegiProj=new WcxWeeklyStatisticsRegionProject();
            weeklyStRegiProj.setWeek(innovationNumZhouTongjiRegionProject.get(i).getWeek());
            weeklyStRegiProj.setOrgCode(innovationNumZhouTongjiRegionProject.get(i).getOrgCode());
            weeklyStRegiProj.setOrgName(innovationNumZhouTongjiRegionProject.get(i).getOrgName());
            weeklyStRegiProj.setCommCode(innovationNumZhouTongjiRegionProject.get(i).getCommCode());
            weeklyStRegiProj.setCommName(innovationNumZhouTongjiRegionProject.get(i).getCommName());
            weeklyStRegiProj.setInnovationNum(innovationNumZhouTongjiRegionProject.get(i).getInnovationNum());
            weeklyStRegiProj.setInnovationNumChain(innovationNumZhouTongjiRegionProject.get(i).getInnovationNumChain());
            weeklyStatisticsRegionProjectMapper.updateWeekRegionProject(weeklyStRegiProj);
        }


        List<WcxWeeklyStatistics> StatisticsNumZhouTongji= wcxWeeklyStatisticsMapper.StatisticsNumZhouTongji(1);

        for (int c = 0; c <StatisticsNumZhouTongji.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(StatisticsNumZhouTongji.get(c).getWeek());
            weics.setUserNumChain(StatisticsNumZhouTongji.get(c).getUserNumChain());
            weics.setNewUserChain(StatisticsNumZhouTongji.get(c).getNewUserChain());
            wcxWeeklyStatisticsMapper.updateWeeChain(weics);
        }*/



        Integer[] nian={2018,2019,2020,2021};

        for (int z = 0; z < nian.length; z++) {
            Map<String,Object> wxSessionMap = wcxService.getWxAccessToken();
            if(null == wxSessionMap){
                throw new ServiceException("调用返回值为空");
            }
            if(wxSessionMap.containsKey("errcode")){
                throw new ServiceException("调用返回值为空");
            }
            String accessToken = (String)wxSessionMap.get("access_token");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            Map<String, Map<String, String>> getYearWeekMapyue=getYearWeekMap(nian[z]);
            for (int i = 1; i <=getYearWeekMapyue.size() ; i++) {
                Map<String, String> map=getYearWeekMapyue.get(String.valueOf(i));
                String[] startyuenian=map.get("startTime").split("/");
                String[] endyuenian=map.get("endTime").split("/");
                String startyuenianStr=startyuenian[0]+startyuenian[1]+startyuenian[2];
                String endyuenianStr=endyuenian[0]+endyuenian[1]+endyuenian[2];


                String urlzh=zhouUrl+accessToken;
                String zhoushuju=wcxService.postUr(urlzh,startyuenianStr,endyuenianStr);

                JSONObject object = JSONObject.parseObject(zhoushuju);
                String jsoerr=object.getString("errcode");
                if(StringUtil.isNotBlank(jsoerr)){
                    continue;
                }
                JSONArray jsonlist=object.getJSONArray("list");
                WcxWeeklyStatistics weeklyStatistics=new WcxWeeklyStatistics();
                WcxWeeklyStatisticsRegion weeklyStatisticsRegion=new WcxWeeklyStatisticsRegion();
                WcxWeeklyStatisticsRegionProject weeklyStatisticsRegionProject=new WcxWeeklyStatisticsRegionProject();
                weeklyStatistics.setWekindex(1);
                weeklyStatisticsRegion.setWekindex(1);
                weeklyStatisticsRegionProject.setWekindex(1);
                weeklyStatistics.setDateRange(map.get("startTime")+"-"+map.get("endTime"));
                weeklyStatisticsRegion.setDateRange(map.get("startTime")+"-"+map.get("endTime"));
                weeklyStatisticsRegionProject.setDateRange(map.get("startTime")+"-"+map.get("endTime"));
                if(i<10&&i>0){
                    weeklyStatistics.setWeek(nian[z]+"年第"+"0"+i+"周");
                    weeklyStatisticsRegion.setWeek(nian[z]+"年第"+"0"+i+"周");
                    weeklyStatisticsRegionProject.setWeek(nian[z]+"年第"+"0"+i+"周");
                }else {
                    weeklyStatistics.setWeek(nian[z]+"年第"+i+"周");
                    weeklyStatisticsRegion.setWeek(nian[z]+"年第"+i+"周");
                    weeklyStatisticsRegionProject.setWeek(nian[z]+"年第"+i+"周");
                }

                if(jsonlist!=null){
                    if(jsonlist.size()!=0){
                        for (int j = 0; j < jsonlist.size(); j++) {
                            JSONObject jObject3=jsonlist.getJSONObject(j);
                            weeklyStatistics.setInnovationNum(0);
                            weeklyStatistics.setInnovationNumChain("0");
                            weeklyStatistics.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                            weeklyStatistics.setUserNumChain("0");
                            weeklyStatistics.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                            weeklyStatistics.setNewUserChain("0");

                            weeklyStatisticsRegion.setInnovationNum(0);
                            weeklyStatisticsRegion.setInnovationNumChain("0");
                            weeklyStatisticsRegion.setUserNum(0);
                            weeklyStatisticsRegion.setUserNumChain("0");
                            weeklyStatisticsRegion.setNewUserNum(0);
                            weeklyStatisticsRegion.setNewUserChain("0");


                            weeklyStatisticsRegionProject.setInnovationNum(0);
                            weeklyStatisticsRegionProject.setInnovationNumChain("0");
                            weeklyStatisticsRegionProject.setUserNum(0);
                            weeklyStatisticsRegionProject.setUserNumChain("0");
                            weeklyStatisticsRegionProject.setNewUserNum(0);
                            weeklyStatisticsRegionProject.setNewUserChain("0");
                        }
                    }else {
                        weeklyStatistics.setInnovationNum(0);
                        weeklyStatistics.setInnovationNumChain("0");
                        weeklyStatistics.setUserNum(0);
                        weeklyStatistics.setUserNumChain("0");
                        weeklyStatistics.setNewUserNum(0);
                        weeklyStatistics.setNewUserChain("0");

                        weeklyStatisticsRegion.setInnovationNum(0);
                        weeklyStatisticsRegion.setInnovationNumChain("0");
                        weeklyStatisticsRegion.setUserNum(0);
                        weeklyStatisticsRegion.setUserNumChain("0");
                        weeklyStatisticsRegion.setNewUserNum(0);
                        weeklyStatisticsRegion.setNewUserChain("0");

                        weeklyStatisticsRegionProject.setInnovationNum(0);
                        weeklyStatisticsRegionProject.setInnovationNumChain("0");
                        weeklyStatisticsRegionProject.setUserNum(0);
                        weeklyStatisticsRegionProject.setUserNumChain("0");
                        weeklyStatisticsRegionProject.setNewUserNum(0);
                        weeklyStatisticsRegionProject.setNewUserChain("0");
                    }
                    wcxWeeklyStatisticsMapper.insert(weeklyStatistics);
                    weeklyStatisticsRegionMapper.insert(weeklyStatisticsRegion);
                    weeklyStatisticsRegionProjectMapper.insert(weeklyStatisticsRegionProject);
                }
            }

            List<WcxWeeklyStatistics> innovationNumZhouTongji= wcxWeeklyStatisticsMapper.innovationNumZhouTongji();
            for (int c = 0; c <innovationNumZhouTongji.size() ; c++) {
                WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
                weics.setWeek(innovationNumZhouTongji.get(c).getWeek());
                weics.setInnovationNum(innovationNumZhouTongji.get(c).getInnovationNum());
                weics.setInnovationNumChain(innovationNumZhouTongji.get(c).getInnovationNumChain());
                wcxWeeklyStatisticsMapper.updateWeek(weics);
            }

            List<WcxWeeklyStatisticsRegion> innovationNumZhouTongjiRegion=weeklyStatisticsRegionMapper.innovationNumZhouTongjiRegion();

            for (int i = 0; i <innovationNumZhouTongjiRegion.size() ; i++) {
                WcxWeeklyStatisticsRegion weeklyStion=new WcxWeeklyStatisticsRegion();
                weeklyStion.setWeek(innovationNumZhouTongjiRegion.get(i).getWeek());
                weeklyStion.setOrgCode(innovationNumZhouTongjiRegion.get(i).getOrgCode());
                weeklyStion.setOrgName(innovationNumZhouTongjiRegion.get(i).getOrgName());
                weeklyStion.setInnovationNum(innovationNumZhouTongjiRegion.get(i).getInnovationNum());
                weeklyStion.setInnovationNumChain(innovationNumZhouTongjiRegion.get(i).getInnovationNumChain());
                weeklyStatisticsRegionMapper.updateWeekRegion(weeklyStion);
            }

            List<WcxWeeklyStatisticsRegionProject> innovationNumZhouTongjiRegionProject=weeklyStatisticsRegionProjectMapper.innovationNumZhouTongjiRegionProject();

            for (int i = 0; i <innovationNumZhouTongjiRegionProject.size() ; i++) {
                WcxWeeklyStatisticsRegionProject weeklyStRegiProj=new WcxWeeklyStatisticsRegionProject();
                weeklyStRegiProj.setWeek(innovationNumZhouTongjiRegionProject.get(i).getWeek());
                weeklyStRegiProj.setOrgCode(innovationNumZhouTongjiRegionProject.get(i).getOrgCode());
                weeklyStRegiProj.setOrgName(innovationNumZhouTongjiRegionProject.get(i).getOrgName());
                weeklyStRegiProj.setCommCode(innovationNumZhouTongjiRegionProject.get(i).getCommCode());
                weeklyStRegiProj.setCommName(innovationNumZhouTongjiRegionProject.get(i).getCommName());
                weeklyStRegiProj.setInnovationNum(innovationNumZhouTongjiRegionProject.get(i).getInnovationNum());
                weeklyStRegiProj.setInnovationNumChain(innovationNumZhouTongjiRegionProject.get(i).getInnovationNumChain());
                weeklyStatisticsRegionProjectMapper.updateWeekRegionProject(weeklyStRegiProj);
            }


            List<WcxWeeklyStatistics> StatisticsNumZhouTongji= wcxWeeklyStatisticsMapper.StatisticsNumZhouTongjican(1);

            for (int c = 0; c <StatisticsNumZhouTongji.size() ; c++) {
                WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
                weics.setWeek(StatisticsNumZhouTongji.get(c).getWeek());
                weics.setUserNumChain(StatisticsNumZhouTongji.get(c).getUserNumChain());
                weics.setNewUserChain(StatisticsNumZhouTongji.get(c).getNewUserChain());
                wcxWeeklyStatisticsMapper.updateWeeChain(weics);
            }

        }


    }

    @Override
    public void tongjiyue() throws IOException {
/*        {monthEnd=2018/01/31, monthStart=2018/01/01}
        {monthEnd=2018/02/28, monthStart=2018/02/01}
        {monthEnd=2018/03/31, monthStart=2018/03/01}*/
        String yueUrl="https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=";

        Integer[] nian={2018,2019,2020,2021};

        for (int z = 0; z < nian.length; z++) {
            Map<String,Object> wxSessionMap = wcxService.getWxAccessToken();
            if(null == wxSessionMap){
                throw new ServiceException("调用返回值为空");
            }
            if(wxSessionMap.containsKey("errcode")){
                throw new ServiceException("调用返回值为空");
            }
            String accessToken = (String)wxSessionMap.get("access_token");
            Map<String, Map<String, String>> getYearWeekMapyue=getMonthWeekMap(nian[z]);
            for (int i = 1; i <=getYearWeekMapyue.size() ; i++) {
                Map<String, String> map=getYearWeekMapyue.get(String.valueOf(i));
                String[] startyue=map.get("monthStart").split("/");
                String[] endyue=map.get("monthEnd").split("/");

                String startyueStr=startyue[0]+startyue[1]+startyue[2];
                String endyueStr=endyue[0]+endyue[1]+endyue[2];

                String urlzh=yueUrl+accessToken;
                String zhoushuju=wcxService.postUr(urlzh,startyueStr,endyueStr);

                JSONObject object = JSONObject.parseObject(zhoushuju);
                String jsoerr=object.getString("errcode");
                if(StringUtil.isNotBlank(jsoerr)){
                    continue;
                }
                JSONArray jsonlist=object.getJSONArray("list");

                WcxWeeklyStatistics weeklyStatistics=new WcxWeeklyStatistics();
                WcxWeeklyStatisticsRegion weeklyStatisticsRegion=new WcxWeeklyStatisticsRegion();
                WcxWeeklyStatisticsRegionProject weeklyStatisticsRegionProject=new WcxWeeklyStatisticsRegionProject();
                weeklyStatistics.setWekindex(2);
                weeklyStatisticsRegion.setWekindex(2);
                weeklyStatisticsRegionProject.setWekindex(2);
                weeklyStatistics.setDateRange(map.get("monthStart")+"-"+map.get("monthEnd"));
                weeklyStatisticsRegion.setDateRange(map.get("monthStart")+"-"+map.get("monthEnd"));
                weeklyStatisticsRegionProject.setDateRange(map.get("monthStart")+"-"+map.get("monthEnd"));
                if(i<10&&i>0){
                    weeklyStatistics.setWeek(nian[z]+"年第"+"0"+i+"月");
                    weeklyStatisticsRegion.setWeek(nian[z]+"年第"+"0"+i+"月");
                    weeklyStatisticsRegionProject.setWeek(nian[z]+"年第"+"0"+i+"月");
                }else {
                    weeklyStatistics.setWeek(nian[z]+"年第"+i+"月");
                    weeklyStatisticsRegion.setWeek(nian[z]+"年第"+i+"月");
                    weeklyStatisticsRegionProject.setWeek(nian[z]+"年第"+i+"月");
                }

                if(jsonlist!=null){
                    if(jsonlist.size()!=0){
                        for (int j = 0; j < jsonlist.size(); j++) {
                            JSONObject jObject3=jsonlist.getJSONObject(j);
                            weeklyStatistics.setInnovationNum(0);
                            weeklyStatistics.setInnovationNumChain("0");
                            weeklyStatistics.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                            weeklyStatistics.setUserNumChain("0");
                            weeklyStatistics.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                            weeklyStatistics.setNewUserChain("0");

                            weeklyStatisticsRegion.setInnovationNum(0);
                            weeklyStatisticsRegion.setInnovationNumChain("0");
                            weeklyStatisticsRegion.setUserNum(0);
                            weeklyStatisticsRegion.setUserNumChain("0");
                            weeklyStatisticsRegion.setNewUserNum(0);
                            weeklyStatisticsRegion.setNewUserChain("0");


                            weeklyStatisticsRegionProject.setInnovationNum(0);
                            weeklyStatisticsRegionProject.setInnovationNumChain("0");
                            weeklyStatisticsRegionProject.setUserNum(0);
                            weeklyStatisticsRegionProject.setUserNumChain("0");
                            weeklyStatisticsRegionProject.setNewUserNum(0);
                            weeklyStatisticsRegionProject.setNewUserChain("0");
                        }
                    }else {
                        weeklyStatistics.setInnovationNum(0);
                        weeklyStatistics.setInnovationNumChain("0");
                        weeklyStatistics.setUserNum(0);
                        weeklyStatistics.setUserNumChain("0");
                        weeklyStatistics.setNewUserNum(0);
                        weeklyStatistics.setNewUserChain("0");

                        weeklyStatisticsRegion.setInnovationNum(0);
                        weeklyStatisticsRegion.setInnovationNumChain("0");
                        weeklyStatisticsRegion.setUserNum(0);
                        weeklyStatisticsRegion.setUserNumChain("0");
                        weeklyStatisticsRegion.setNewUserNum(0);
                        weeklyStatisticsRegion.setNewUserChain("0");

                        weeklyStatisticsRegionProject.setInnovationNum(0);
                        weeklyStatisticsRegionProject.setInnovationNumChain("0");
                        weeklyStatisticsRegionProject.setUserNum(0);
                        weeklyStatisticsRegionProject.setUserNumChain("0");
                        weeklyStatisticsRegionProject.setNewUserNum(0);
                        weeklyStatisticsRegionProject.setNewUserChain("0");
                    }
                    wcxWeeklyStatisticsMapper.insert(weeklyStatistics);
                    weeklyStatisticsRegionMapper.insert(weeklyStatisticsRegion);
                    weeklyStatisticsRegionProjectMapper.insert(weeklyStatisticsRegionProject);
                }
            }

            List<WcxWeeklyStatistics> innovationNumYueTongji= wcxWeeklyStatisticsMapper.innovationNumYueTongji();
            for (int c = 0; c <innovationNumYueTongji.size() ; c++) {
                WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
                weics.setWeek(innovationNumYueTongji.get(c).getWeek());
                weics.setInnovationNum(innovationNumYueTongji.get(c).getInnovationNum());
                weics.setInnovationNumChain(innovationNumYueTongji.get(c).getInnovationNumChain());
                wcxWeeklyStatisticsMapper.updateWeek(weics);
            }

            List<WcxWeeklyStatisticsRegion> innovationNumYueTongjiRegion=weeklyStatisticsRegionMapper.innovationNumYueTongjiRegion();

            for (int i = 0; i <innovationNumYueTongjiRegion.size() ; i++) {
                WcxWeeklyStatisticsRegion weeklyStion=new WcxWeeklyStatisticsRegion();
                weeklyStion.setWeek(innovationNumYueTongjiRegion.get(i).getWeek());
                weeklyStion.setOrgCode(innovationNumYueTongjiRegion.get(i).getOrgCode());
                weeklyStion.setOrgName(innovationNumYueTongjiRegion.get(i).getOrgName());
                weeklyStion.setInnovationNum(innovationNumYueTongjiRegion.get(i).getInnovationNum());
                weeklyStion.setInnovationNumChain(innovationNumYueTongjiRegion.get(i).getInnovationNumChain());
                weeklyStatisticsRegionMapper.updateWeekRegion(weeklyStion);
            }


            List<WcxWeeklyStatisticsRegionProject> innovationNumYueTongjiRegionProject=weeklyStatisticsRegionProjectMapper.innovationNumYueTongjiRegionProject();

            for (int i = 0; i <innovationNumYueTongjiRegionProject.size() ; i++) {
                WcxWeeklyStatisticsRegionProject weeklyStRegiProj=new WcxWeeklyStatisticsRegionProject();
                weeklyStRegiProj.setWeek(innovationNumYueTongjiRegionProject.get(i).getWeek());
                weeklyStRegiProj.setOrgCode(innovationNumYueTongjiRegionProject.get(i).getOrgCode());
                weeklyStRegiProj.setOrgName(innovationNumYueTongjiRegionProject.get(i).getOrgName());
                weeklyStRegiProj.setCommCode(innovationNumYueTongjiRegionProject.get(i).getCommCode());
                weeklyStRegiProj.setCommName(innovationNumYueTongjiRegionProject.get(i).getCommName());
                weeklyStRegiProj.setInnovationNum(innovationNumYueTongjiRegionProject.get(i).getInnovationNum());
                weeklyStRegiProj.setInnovationNumChain(innovationNumYueTongjiRegionProject.get(i).getInnovationNumChain());
                weeklyStatisticsRegionProjectMapper.updateWeekRegionProject(weeklyStRegiProj);
            }



            List<WcxWeeklyStatistics> StatisticsNumZhouTongji= wcxWeeklyStatisticsMapper.StatisticsNumZhouTongjican(2);

            for (int c = 0; c <StatisticsNumZhouTongji.size() ; c++) {
                WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
                weics.setWeek(StatisticsNumZhouTongji.get(c).getWeek());
                weics.setUserNumChain(StatisticsNumZhouTongji.get(c).getUserNumChain());
                weics.setNewUserChain(StatisticsNumZhouTongji.get(c).getNewUserChain());
                wcxWeeklyStatisticsMapper.updateWeeChain(weics);
            }
        }


    }

    @Override
    public void tongjiri() throws ParseException, IOException {
       // [2018-01-01, 2018-01-02, 2018-01-03, 2018-01-04,
       /* String riUrl="https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=";

        List<String> getYearDate=getYearDate(dateStart,dateEnd);
        for (int i = 0; i <getYearDate.size() ; i++) {
            String[] startnian=getYearDate.get(i).split("-");
            String yeas=startnian[0];
            System.out.println("第"+(i+1)+"日"+getYearDate.get(i));
            String startyueStr=getYearDate.get(i);
            String endyueStr=getYearDate.get(i);
            String urlzh=riUrl+accessToken;
            String zhoushuju=wcxService.postUr(urlzh,startyueStr,endyueStr);

            JSONObject object = JSONObject.parseObject(zhoushuju);
            String jsoerr=object.getString("errcode");
            if(StringUtil.isNotBlank(jsoerr)){
                continue;
            }
            JSONArray jsonlist=object.getJSONArray("list");

            WcxWeeklyStatistics weeklyStatistics=new WcxWeeklyStatistics();
            WcxWeeklyStatisticsRegion weeklyStatisticsRegion=new WcxWeeklyStatisticsRegion();
            WcxWeeklyStatisticsRegionProject weeklyStatisticsRegionProject=new WcxWeeklyStatisticsRegionProject();
            weeklyStatistics.setWekindex(3);
            weeklyStatisticsRegion.setWekindex(3);
            weeklyStatisticsRegionProject.setWekindex(3);

            weeklyStatistics.setDateRange(getYearDate.get(i));
            weeklyStatisticsRegion.setDateRange(getYearDate.get(i));
            weeklyStatisticsRegionProject.setDateRange(getYearDate.get(i));

            weeklyStatistics.setWeek(getYearDate.get(i));
            weeklyStatisticsRegion.setWeek(getYearDate.get(i));
            weeklyStatisticsRegionProject.setWeek(getYearDate.get(i));
            if(jsonlist!=null){
                if(jsonlist.size()!=0){
                    for (int j = 0; j < jsonlist.size(); j++) {
                        JSONObject jObject3=jsonlist.getJSONObject(j);
                        weeklyStatistics.setInnovationNum(0);
                        weeklyStatistics.setInnovationNumChain("0");
                        weeklyStatistics.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                        weeklyStatistics.setUserNumChain("0");
                        weeklyStatistics.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                        weeklyStatistics.setNewUserChain("0");


                        weeklyStatisticsRegion.setInnovationNum(0);
                        weeklyStatisticsRegion.setInnovationNumChain("0");
                        weeklyStatisticsRegion.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                        weeklyStatisticsRegion.setUserNumChain("0");
                        weeklyStatisticsRegion.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                        weeklyStatisticsRegion.setNewUserChain("0");

                        weeklyStatisticsRegionProject.setInnovationNum(0);
                        weeklyStatisticsRegionProject.setInnovationNumChain("0");
                        weeklyStatisticsRegionProject.setUserNum(Integer.valueOf(jObject3.getString("visit_uv")));
                        weeklyStatisticsRegionProject.setUserNumChain("0");
                        weeklyStatisticsRegionProject.setNewUserNum(Integer.valueOf(jObject3.getString("visit_uv_new")));
                        weeklyStatisticsRegionProject.setNewUserChain("0");
                    }
                }else {
                    weeklyStatistics.setInnovationNum(0);
                    weeklyStatistics.setInnovationNumChain("0");
                    weeklyStatistics.setUserNum(0);
                    weeklyStatistics.setUserNumChain("0");
                    weeklyStatistics.setNewUserNum(0);
                    weeklyStatistics.setNewUserChain("0");

                    weeklyStatisticsRegion.setInnovationNum(0);
                    weeklyStatisticsRegion.setInnovationNumChain("0");
                    weeklyStatisticsRegion.setUserNum(0);
                    weeklyStatisticsRegion.setUserNumChain("0");
                    weeklyStatisticsRegion.setNewUserNum(0);
                    weeklyStatisticsRegion.setNewUserChain("0");

                    weeklyStatisticsRegionProject.setInnovationNum(0);
                    weeklyStatisticsRegionProject.setInnovationNumChain("0");
                    weeklyStatisticsRegionProject.setUserNum(0);
                    weeklyStatisticsRegionProject.setUserNumChain("0");
                    weeklyStatisticsRegionProject.setNewUserNum(0);
                    weeklyStatisticsRegionProject.setNewUserChain("0");
                }
                wcxWeeklyStatisticsMapper.insert(weeklyStatistics);
                weeklyStatisticsRegionMapper.insert(weeklyStatisticsRegion);
                weeklyStatisticsRegionProjectMapper.insert(weeklyStatisticsRegionProject);
            }
        }

        List<WcxWeeklyStatistics> innovationNumDateTongji= wcxWeeklyStatisticsMapper.innovationNumDateTongji();
        for (int c = 0; c <innovationNumDateTongji.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(innovationNumDateTongji.get(c).getWeek());
            weics.setInnovationNum(innovationNumDateTongji.get(c).getInnovationNum());
            weics.setInnovationNumChain(innovationNumDateTongji.get(c).getInnovationNumChain());
            wcxWeeklyStatisticsMapper.updateWeek(weics);
        }


        List<WcxWeeklyStatisticsRegion> innovationNumRiTongjiRegion=weeklyStatisticsRegionMapper.innovationNumRiTongjiRegion();

        for (int i = 0; i <innovationNumRiTongjiRegion.size() ; i++) {
            WcxWeeklyStatisticsRegion weeklyStion=new WcxWeeklyStatisticsRegion();
            weeklyStion.setWeek(innovationNumRiTongjiRegion.get(i).getWeek());
            weeklyStion.setOrgCode(innovationNumRiTongjiRegion.get(i).getOrgCode());
            weeklyStion.setOrgName(innovationNumRiTongjiRegion.get(i).getOrgName());
            weeklyStion.setInnovationNum(innovationNumRiTongjiRegion.get(i).getInnovationNum());
            weeklyStion.setInnovationNumChain(innovationNumRiTongjiRegion.get(i).getInnovationNumChain());
            weeklyStatisticsRegionMapper.updateWeekRegion(weeklyStion);
        }



        List<WcxWeeklyStatisticsRegionProject> innovationNumRiTongjiRegionProject=weeklyStatisticsRegionProjectMapper.innovationNumRiTongjiRegionProject();

        for (int i = 0; i <innovationNumRiTongjiRegionProject.size() ; i++) {
            WcxWeeklyStatisticsRegionProject weeklyStRegiProj=new WcxWeeklyStatisticsRegionProject();
            weeklyStRegiProj.setWeek(innovationNumRiTongjiRegionProject.get(i).getWeek());
            weeklyStRegiProj.setOrgCode(innovationNumRiTongjiRegionProject.get(i).getOrgCode());
            weeklyStRegiProj.setOrgName(innovationNumRiTongjiRegionProject.get(i).getOrgName());
            weeklyStRegiProj.setCommCode(innovationNumRiTongjiRegionProject.get(i).getCommCode());
            weeklyStRegiProj.setCommName(innovationNumRiTongjiRegionProject.get(i).getCommName());
            weeklyStRegiProj.setInnovationNum(innovationNumRiTongjiRegionProject.get(i).getInnovationNum());
            weeklyStRegiProj.setInnovationNumChain(innovationNumRiTongjiRegionProject.get(i).getInnovationNumChain());
            weeklyStatisticsRegionProjectMapper.updateWeekRegionProject(weeklyStRegiProj);
        }


        List<WcxWeeklyStatistics> StatisticsNumZhouTongji= wcxWeeklyStatisticsMapper.StatisticsNumZhouTongji(3);

        for (int c = 0; c <StatisticsNumZhouTongji.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(StatisticsNumZhouTongji.get(c).getWeek());
            weics.setUserNumChain(StatisticsNumZhouTongji.get(c).getUserNumChain());
            weics.setNewUserChain(StatisticsNumZhouTongji.get(c).getNewUserChain());
            wcxWeeklyStatisticsMapper.updateWeeChain(weics);
        }*/


       /*        {monthEnd=2018/01/31, monthStart=2018/01/01}
        {monthEnd=2018/02/28, monthStart=2018/02/01}
        {monthEnd=2018/03/31, monthStart=2018/03/01}*/

        /*List<WcxWeeklyStatistics> innovationNumDateTongji1= wcxWeeklyStatisticsMapper.innovationNumDateTongji();
        for (int c = 0; c <innovationNumDateTongji1.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(innovationNumDateTongji1.get(c).getWeek());
            weics.setInnovationNum(innovationNumDateTongji1.get(c).getInnovationNum());
            if(c==0){
                weics.setInnovationNumChain("0");
            }else {
                System.out.println((Double.valueOf(innovationNumDateTongji1.get(c).getInnovationNum())-Double.valueOf(innovationNumDateTongji1.get(c-1).getInnovationNum()))/Double.valueOf(innovationNumDateTongji1.get(c-1).getInnovationNum())*100);
                //DecimalFormat df = new DecimalFormat("#.00");
                //Double sumdo=Double.valueOf(String.valueOf((innovationNumDateTongji.get(c).getInnovationNum()-innovationNumDateTongji.get(c-1).getInnovationNum())/innovationNumDateTongji.get(c-1).getInnovationNum()*100));
                weics.setInnovationNumChain("0");
            }

            wcxWeeklyStatisticsMapper.updateWeek(weics);
        }*/


        String yueUrl="https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=";


        Integer[] nian={2018,2019,2020};

        for (int z = 0; z <nian.length ; z++) {
            Integer userNumsum=0;
            Integer newUserNumsum=0;
            WcxWeeklyStatistics weeklyStatistics=new WcxWeeklyStatistics();
            weeklyStatistics.setWekindex(3);

            weeklyStatistics.setDateRange(String.valueOf(nian[z]));

            weeklyStatistics.setWeek(String.valueOf(nian[z]));

           Map<String,Object> wxSessionMap = wcxService.getWxAccessToken();
            if(null == wxSessionMap){
                throw new ServiceException("调用返回值为空");
            }
            if(wxSessionMap.containsKey("errcode")){
                throw new ServiceException("调用返回值为空");
            }
            String accessToken = (String)wxSessionMap.get("access_token");
            Map<String, Map<String, String>> getYearWeekMapyue=getMonthWeekMap(nian[z]);
            for (int i = 1; i <=getYearWeekMapyue.size() ; i++) {
                Map<String, String> map=getYearWeekMapyue.get(String.valueOf(i));
                String[] startyue=map.get("monthStart").split("/");
                String[] endyue=map.get("monthEnd").split("/");

                String startyueStr=startyue[0]+startyue[1]+startyue[2];
                String endyueStr=endyue[0]+endyue[1]+endyue[2];

                String urlzh=yueUrl+accessToken;
               String zhoushuju=wcxService.postUr(urlzh,startyueStr,endyueStr);

                JSONObject object = JSONObject.parseObject(zhoushuju);
                String jsoerr=object.getString("errcode");
                if(StringUtil.isNotBlank(jsoerr)){
                    continue;
                }
                JSONArray jsonlist=object.getJSONArray("list");

                if(jsonlist!=null){
                    if(jsonlist.size()!=0){
                        for (int j = 0; j < jsonlist.size(); j++) {
                            JSONObject jObject3=jsonlist.getJSONObject(j);
                            userNumsum+=Integer.valueOf(jObject3.getString("visit_uv"));
                            newUserNumsum+=Integer.valueOf(jObject3.getString("visit_uv_new"));
                        }

                    }
                }
            }

            weeklyStatistics.setInnovationNum(0);
            weeklyStatistics.setInnovationNumChain("0");
            weeklyStatistics.setUserNum(userNumsum);
            weeklyStatistics.setUserNumChain("0");
            weeklyStatistics.setNewUserNum(newUserNumsum);
            weeklyStatistics.setNewUserChain("0");


            wcxWeeklyStatisticsMapper.insert(weeklyStatistics);
            //weeklyStatisticsRegionMapper.insert(weeklyStatisticsRegion);
            //weeklyStatisticsRegionProjectMapper.insert(weeklyStatisticsRegionProject);
//（本期新增-上期新增）/上期新增*100
            List<WcxWeeklyStatistics> innovationNumDateTongji= wcxWeeklyStatisticsMapper.innovationNumDateTongji();
            for (int c = 0; c <innovationNumDateTongji.size() ; c++) {
                WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
                weics.setWeek(innovationNumDateTongji.get(c).getWeek());
                weics.setInnovationNum(innovationNumDateTongji.get(c).getInnovationNum());
                if(c==0){
                    weics.setInnovationNumChain("0");
                }else {
                    //(Double.valueOf(innovationNumDateTongji1.get(c).getInnovationNum())-Double.valueOf(innovationNumDateTongji1.get(c-1).getInnovationNum()))/Double.valueOf(innovationNumDateTongji1.get(c-1).getInnovationNum())*100
                    DecimalFormat df = new DecimalFormat("#.00");
                    Double sumdo=(Double.valueOf(innovationNumDateTongji.get(c).getInnovationNum())-Double.valueOf(innovationNumDateTongji.get(c-1).getInnovationNum()))/Double.valueOf(innovationNumDateTongji.get(c-1).getInnovationNum())*100;
                    weics.setInnovationNumChain(df.format(sumdo));
                }

                wcxWeeklyStatisticsMapper.updateWeek(weics);
            }


            List<WcxWeeklyStatisticsRegion> innovationNumRiTongjiRegion=weeklyStatisticsRegionMapper.innovationNumRiTongjiRegion();

            for (int i = 0; i <innovationNumRiTongjiRegion.size() ; i++) {
                WcxWeeklyStatisticsRegion weeklyStion=new WcxWeeklyStatisticsRegion();
                weeklyStion.setWekindex(3);
                weeklyStion.setWeek(String.valueOf(nian[z]));
                weeklyStion.setDateRange(String.valueOf(nian[z]));
                weeklyStion.setInnovationNum(innovationNumRiTongjiRegion.get(i).getInnovationNum());
                weeklyStion.setInnovationNumChain(innovationNumRiTongjiRegion.get(i).getInnovationNumChain());
                weeklyStion.setUserNum(0);
                weeklyStion.setUserNumChain("0");
                weeklyStion.setNewUserNum(0);
                weeklyStion.setNewUserChain("0");
                weeklyStion.setOrgCode(innovationNumRiTongjiRegion.get(i).getOrgCode());
                weeklyStion.setOrgName(innovationNumRiTongjiRegion.get(i).getOrgName());
                weeklyStion.setInnovationNum(innovationNumRiTongjiRegion.get(i).getInnovationNum());
                weeklyStion.setInnovationNumChain(innovationNumRiTongjiRegion.get(i).getInnovationNumChain());
                // weeklyStatisticsRegionMapper.updateWeekRegion(weeklyStion);
                weeklyStatisticsRegionMapper.insert(weeklyStion);
            }



            List<WcxWeeklyStatisticsRegionProject> innovationNumRiTongjiRegionProject=weeklyStatisticsRegionProjectMapper.innovationNumRiTongjiRegionProject();

            for (int i = 0; i <innovationNumRiTongjiRegionProject.size() ; i++) {
                WcxWeeklyStatisticsRegionProject weeklyStRegiProj=new WcxWeeklyStatisticsRegionProject();
                weeklyStRegiProj.setWekindex(3);
                weeklyStRegiProj.setInnovationNum(innovationNumRiTongjiRegionProject.get(i).getInnovationNum());
                weeklyStRegiProj.setInnovationNumChain(innovationNumRiTongjiRegionProject.get(i).getInnovationNumChain());
                weeklyStRegiProj.setUserNum(0);
                weeklyStRegiProj.setUserNumChain("0");
                weeklyStRegiProj.setNewUserNum(0);
                weeklyStRegiProj.setNewUserChain("0");
                weeklyStRegiProj.setWeek(String.valueOf(nian[z]));
                weeklyStRegiProj.setDateRange(String.valueOf(nian[z]));
                weeklyStRegiProj.setWeek(innovationNumRiTongjiRegionProject.get(i).getWeek());
                weeklyStRegiProj.setOrgCode(innovationNumRiTongjiRegionProject.get(i).getOrgCode());
                weeklyStRegiProj.setOrgName(innovationNumRiTongjiRegionProject.get(i).getOrgName());
                weeklyStRegiProj.setCommCode(innovationNumRiTongjiRegionProject.get(i).getCommCode());
                weeklyStRegiProj.setCommName(innovationNumRiTongjiRegionProject.get(i).getCommName());
                weeklyStRegiProj.setInnovationNum(innovationNumRiTongjiRegionProject.get(i).getInnovationNum());
                weeklyStRegiProj.setInnovationNumChain(innovationNumRiTongjiRegionProject.get(i).getInnovationNumChain());
                //weeklyStatisticsRegionProjectMapper.updateWeekRegionProject(weeklyStRegiProj);
                weeklyStatisticsRegionProjectMapper.insert(weeklyStRegiProj);
            }
        }

        List<WcxWeeklyStatistics> StatisticsNumZhouTongji= wcxWeeklyStatisticsMapper.StatisticsNumZhouTongji();

        for (int c = 0; c <StatisticsNumZhouTongji.size() ; c++) {
            WcxWeeklyStatistics weics=new WcxWeeklyStatistics();
            weics.setWeek(StatisticsNumZhouTongji.get(c).getWeek());
            if(c==0){
                weics.setUserNumChain("0");
                weics.setNewUserChain("0");
            }else {
                DecimalFormat df = new DecimalFormat("#.00");
                Double sumdoun=(Double.valueOf(StatisticsNumZhouTongji.get(c).getUserNum())-Double.valueOf(StatisticsNumZhouTongji.get(c-1).getUserNum()))/Double.valueOf(StatisticsNumZhouTongji.get(c-1).getUserNum())*100;

                Double sumdonun=(Double.valueOf(StatisticsNumZhouTongji.get(c).getNewUserNum())-Double.valueOf(StatisticsNumZhouTongji.get(c-1).getNewUserNum()))/Double.valueOf(StatisticsNumZhouTongji.get(c-1).getNewUserNum())*100;

                weics.setUserNumChain(df.format(sumdoun));
                weics.setNewUserChain(df.format(sumdonun));
            }

            wcxWeeklyStatisticsMapper.updateWeeChain(weics);
        }

    }

    @Override
    public PageData getWcxWeekly(WcxWeeklyStatisticsDTO weeklyStatisticsDTO, HttpServletRequest request) {
        int pageOffset = PageUtil.getPageOffset(weeklyStatisticsDTO.getPageIndex(), weeklyStatisticsDTO.getPageSize());
         weeklyStatisticsDTO.setPageOffset(pageOffset);

         if(StringUtil.isNotBlank(weeklyStatisticsDTO.getWeek())){
             String[] timeStr=weeklyStatisticsDTO.getWeek().split(",");
             weeklyStatisticsDTO.setWeekList( Arrays.asList(timeStr));
         }
             if(StringUtil.isNotBlank(weeklyStatisticsDTO.getOrgName())){
                 List<WcxWeeklyStatisticsDTO> statisquyu=weeklyStatisticsRegionMapper.selectstatisquyu(weeklyStatisticsDTO);
                 Long total=weeklyStatisticsRegionMapper.selectstatisquyuCount(weeklyStatisticsDTO);

                 PageRowBounds pageRowBounds = new PageRowBounds(weeklyStatisticsDTO.getPageIndex(), weeklyStatisticsDTO.getPageSize());
                 pageRowBounds.setTotal(total);
                 pageRowBounds.setCount(true);
                 PageData pageData = new PageData(statisquyu, pageRowBounds);
                 return pageData;
             }else if(StringUtil.isNotBlank(weeklyStatisticsDTO.getOrgName()) && StringUtil.isNotBlank(weeklyStatisticsDTO.getCommName())){
                List<WcxWeeklyStatisticsDTO> statisquyuxiangmu=weeklyStatisticsRegionProjectMapper.selectstatisquyuxiangmu(weeklyStatisticsDTO);

                 Long total=weeklyStatisticsRegionProjectMapper.selectstatisquyuxiangmuCount(weeklyStatisticsDTO);

                 PageRowBounds pageRowBounds = new PageRowBounds(weeklyStatisticsDTO.getPageIndex(), weeklyStatisticsDTO.getPageSize());
                 pageRowBounds.setTotal(total);
                 pageRowBounds.setCount(true);
                 PageData pageData = new PageData(statisquyuxiangmu, pageRowBounds);
                 return pageData;
             }else {
                 List<WcxWeeklyStatisticsDTO> statistime=wcxWeeklyStatisticsMapper.statistime(weeklyStatisticsDTO);
                 Long total=wcxWeeklyStatisticsMapper.statistimeCount(weeklyStatisticsDTO);
                 PageRowBounds pageRowBounds = new PageRowBounds(weeklyStatisticsDTO.getPageIndex(), weeklyStatisticsDTO.getPageSize());
                 pageRowBounds.setTotal(total);
                 pageRowBounds.setCount(true);
                 PageData pageData = new PageData(statistime, pageRowBounds);
                 return pageData;
             }
    }


    public static List<String> getYearDate(String dateStart,String dateEnd) throws ParseException {
    /*   String dateStart="2018-01-01";
       String dateEnd="2018-12-31";*/
        SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd");
         long startTime = date.parse(dateStart).getTime();//start
          long endTime = date.parse(dateEnd).getTime();//end
          long day=1000*60*60*24;
        List<String> list=new LinkedList<>();
         for(long i=startTime;i<=endTime;i+=day) {
             //System.out.println(date.format(new Date(i)));
             list.add(date.format(new Date(i)));
         }
         return list;
     }


    /**
     * 获取某年所有周的时间跨度
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getYearWeekMap(int year) {
        int weeks = getYearWeekConut(year);
        Map<String, Map<String, String>> yearWeekMap = new HashMap<String, Map<String, String>>();
        for (int i =1;i<=weeks;i++){
            Map<String, String> timeMap = getWeekRangeMap(year,i);
            yearWeekMap.put(i+"",timeMap);
        }
        return yearWeekMap;
    }

    /**
     * 获取某年所有月的时间跨度
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getMonthWeekMap(int year) {
        Map<String, Map<String, String>> monthWeekMap = new HashMap<String, Map<String, String>>();
        for (int i = 1; i <=12 ; i++) {
            Map<String, String> map=new HashMap<>();
           String getMonthStart=getMonthStart(year,i);
            String getMonthEnd=getMonthEnd(year,i);
            map.put("monthStart",getMonthStart);
            map.put("monthEnd",getMonthEnd);
            monthWeekMap.put(i+"",map);
        }
        return monthWeekMap;
    }

    //获取某年有多少周
    public static int getYearWeekConut(int year) {
        int week = 52;
        try {
            /*Calendar calendar = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            calendar.setFirstDayOfWeek(Calendar.MONDAY);//设置星期一为一周开始的第一天
            calendar.set(year, Calendar.DECEMBER, 31, 23, 59, 59);
            week = calendar.get(Calendar.WEEK_OF_YEAR);*/
            Map<String, String> timeMap = getWeekRangeMap(year, 53);
            if (!org.springframework.util.CollectionUtils.isEmpty(timeMap)) {
                String startTime = timeMap.get("startTime");
                if (startTime.substring(0, 4).equals(year + "")) { //判断年度是否相符，如果相符说明有53个周。
                    week = 53;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return week;
    }

    //获取某年某周的时间跨度
    public static Map<String, String> getWeekRangeMap(int year, int week) {
        Map<String, String> timeMap = new HashMap<String, String>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.setFirstDayOfWeek(Calendar.MONDAY);//设置星期一为一周开始的第一天
        calendar.setMinimalDaysInFirstWeek(4);//可以不用设置
        int weekYear = calendar.get(Calendar.YEAR);//获得当前的年
        calendar.setWeekDate(weekYear, week, 2);//获得指定年的第几周的开始日期
        Date time = calendar.getTime();
        String startTime = new SimpleDateFormat("yyyy/MM/dd").format(time);
        timeMap.put("startTime", startTime);
        calendar.setWeekDate(weekYear, week, 1);//获得指定年的第几周的结束日期
        time = calendar.getTime();
        String endTime = new SimpleDateFormat("yyyy/MM/dd").format(time);
        timeMap.put("endTime", endTime);
        return timeMap;
    }

    /**
     * 获取某年某月开始日期
     * @return String
     * **/
    public static String getMonthStart(int year,int month){
        Calendar cal=Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month-1);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        Date time=cal.getTime();
        return new SimpleDateFormat("yyyy/MM/dd").format(time);
    }

    /**
     * 获取某年某月最后一天
     * @return String
     * **/
    public static String getMonthEnd(int year,int month){
        Calendar cal=Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month-1);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        Date time=cal.getTime();
        return new SimpleDateFormat("yyyy/MM/dd").format(time);
    }

    /**
     * 获取昨天
     * @return String
     * */
    public static String getYestoday(){
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,-1);
        Date time=cal.getTime();
        return new SimpleDateFormat("yyyy-MM-dd").format(time);
    }



    /** 0:撤回 **//*
    private static final String STATUS_CANCEL = "0";
    *//** 1:未屏蔽 **//*
    private static final String STATUS_SHOW = "1";
    *//** 2:已屏蔽 **//*
    private static final String STATUS_HIDE = "2";

    @Override
    public PageData selectPageList(WcxInnovationOtherDto dto) {
        int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(), dto.getPageSize());
        dto.setPageOffset(pageOffset);

        List<WcxInnovationOtherDto> data = wcxInnovationOtherMapper.selectPageData(dto);
        Long total = wcxInnovationOtherMapper.selectPageCount(dto);

        PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
        pageRowBounds.setTotal(total);
        pageRowBounds.setCount(true);

        PageData pageData = new PageData(data, pageRowBounds);
        return pageData;
    }

    @Override
    @Transactional
    public void cancelReport(String reviewOtherId) {
        WcxInnovationOtherDto innoOther = wcxInnovationOtherMapper.findFirstByPrimaryKey(reviewOtherId);
        wcxInnovationOtherMapper.updateStatus(reviewOtherId, WcxConstant.DELETE_YES, WcxConstant.STATUS_DISABLE);

        WcxInnovationDto dto = wcxInnovationMapper.findFirstDto(innoOther.getInnoId());
        if (dto == null) {
            WcxInnovation model = new WcxInnovation();
            model.setInnovationId(innoOther.getInnoId());
            model.setInnovationTitle(innoOther.getInnoTitle());
            model.setInnovationContentId(innoOther.getInnoContentId());
            model.setInnovationSimpleContent(innoOther.getInnoSimpleContent());
            model.setInnovationType(innoOther.getInnoType());
            model.setBaseline(innoOther.getInnoBaseline());
            model.setClassification(innoOther.getInnoClassification());
            model.setTeamContent(innoOther.getInnoTeamContent());
            model.setProjectName(innoOther.getInnoProjectName());
            model.setRegionName(innoOther.getInnoRegionName());
            model.setTopEndDate(innoOther.getInnoTopEndDate());
            model.setUserId(innoOther.getInnoUserId());
            model.setStatus(innoOther.getStatus());
            model.setCreateDate(innoOther.getCreateDate());
            wcxInnovationMapper.insertOne(model);
        }
    }

    @Override
    @Transactional
    public void hideReport(String innoOtherId, String sysUserCode, String sysUserName) {
        wcxInnovationOtherMapper.updateStatus(innoOtherId, WcxConstant.DELETE_NO, STATUS_HIDE);
        wcxInnovationOtherMapper.updateAudit(innoOtherId, sysUserCode, sysUserName);
        WcxInnovationOtherDto innoOther = wcxInnovationOtherMapper.findFirstByPrimaryKey(innoOtherId);
        wcxInnovationMapper.deleteByPrimateKey(innoOther.getInnoId());
    }*/
}
