package com.jeeplus.assess.assessSignatureDaily.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.assess.assessSignatureDaily.domain.*;
import com.jeeplus.assess.assessSignatureDaily.mapper.AssessSignatureDailyOfficeWorkMapper;
import com.jeeplus.assess.assessSignatureDaily.service.dto.AssessSignatureDailyOfficeWorkDTO;
import com.jeeplus.assess.utils.Global;
import com.jeeplus.assess.utils.SignaturePostUtil;
import com.jeeplus.assess.workContract.mapper.WorkContractInfoMapper;
import com.jeeplus.common.TokenProvider;
import com.jeeplus.core.query.QueryWrapperGenerator;

import com.jeeplus.flowable.feign.IFlowableApi;
import com.jeeplus.sys.domain.WorkAttachmentInfo;
import com.jeeplus.sys.feign.IUserApi;
import com.jeeplus.sys.feign.IWorkAttachmentApi;
import com.jeeplus.sys.service.dto.UserDTO;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;

@Service
@Transactional
public class AssessSignatureDailyOfficeWorkService {

    private static final byte[] SYN_BYTE = new byte[0];
    private static final String HTTPTOP = Global.getConfig("signature_http_top");

    /**
     * 公司圆章-横
     */
    private static final String COMPANYROUNDSEALID = Global.getConfig("company_round_seal_id");
    //日常签章申请流程id
    private static final String DAILYOFFICEWORK = Global.getConfig("signature_daily_office_work");

    @Resource
    private AssessSignatureDailyOfficeWorkMapper signatureDailyOfficeWorkMapper;

    @Resource
    private WorkContractInfoMapper mapper;

    @Resource
    private IFlowableApi flowTaskService;



    /**
     * 列表查询
     * @param page
     * @param dto
     * @return
     */
    public IPage<AssessSignatureDailyOfficeWorkDTO> list(Page<AssessSignatureDailyOfficeWorkDTO> page, AssessSignatureDailyOfficeWorkDTO dto) throws Exception {
        QueryWrapper<AssessSignatureDailyOfficeWorkDTO> queryWrapper = QueryWrapperGenerator.buildQueryCondition(dto, AssessSignatureDailyOfficeWorkDTO.class);
        /**
         * a表是reimbursementInfo
         * b表是reimbursementDetailInfo
         * c表是sysUser
         */
        queryWrapper.eq("a.del_flag", 0);

        // 创建时间
        if (dto.getDates() != null) {
            queryWrapper.between("a.create_time", dto.getDates()[0], dto.getDates()[1]);
        }
        // 创建人
        if (StringUtils.isNotEmpty(dto.getCreateById())) {
            queryWrapper.apply("(a.create_by_id",dto.getCreateById()).or().like("c.name",dto.getCreateById());
        }

        // 状态
        if (StringUtils.isNotEmpty(dto.getStatus())) {
            queryWrapper.eq("a.status", dto.getStatus());
        }
        // 部门
        if (StringUtils.isNotEmpty(dto.getOfficeId())) {
            queryWrapper.eq("so.id", dto.getOfficeId());
        }

        // 签章类型
        if (StringUtils.isNotBlank(dto.getSignatureType())) {
            queryWrapper.eq("a.signature_type", dto.getSignatureType());
        }

        // 签章描述
        if (StringUtils.isNotEmpty(dto.getSignatureName())) {
            queryWrapper.like("a.signature_name", dto.getSignatureName());
        }


        IPage<AssessSignatureDailyOfficeWorkDTO> list = signatureDailyOfficeWorkMapper.findList(page, queryWrapper);

        return list;
    }

    /**
     * 用于导出数据
     * @param page
     * @param dto
     * @return
     * @throws Exception
     */
    public IPage<AssessSignatureDailyOfficeWorkDTO> list2(Page<AssessSignatureDailyOfficeWorkDTO> page, AssessSignatureDailyOfficeWorkDTO dto) throws Exception {
        QueryWrapper<AssessSignatureDailyOfficeWorkDTO> queryWrapper = QueryWrapperGenerator.buildQueryCondition(dto, AssessSignatureDailyOfficeWorkDTO.class);
        /**
         * a表是reimbursementInfo
         * b表是reimbursementDetailInfo
         * c表是sysUser
         */
        queryWrapper.eq("a.del_flag", 0);

        // 创建时间
        if (dto.getDates() != null) {
            queryWrapper.between("a.create_time", dto.getDates()[0], dto.getDates()[1]);
        }
        // 创建人
        if (StringUtils.isNotEmpty(dto.getCreateById())) {
            queryWrapper.apply("(a.create_by_id",dto.getCreateById());
        }

        // 状态
        if (StringUtils.isNotEmpty(dto.getStatus())) {
            queryWrapper.eq("a.status", dto.getStatus());
        }
        // 部门
        if (StringUtils.isNotEmpty(dto.getOfficeId())) {
            queryWrapper.eq("so.id", dto.getOfficeId());
        }

        // 签章类型
        if (StringUtils.isNotBlank(dto.getSignatureType())) {
            queryWrapper.eq("a.signature_type", dto.getSignatureType());
        }

        // 签章描述
        if (StringUtils.isNotEmpty(dto.getSignatureName())) {
            queryWrapper.like("a.signature_name", dto.getSignatureName());
        }


        IPage<AssessSignatureDailyOfficeWorkDTO> list = signatureDailyOfficeWorkMapper.findList2(page, queryWrapper);

        return list;
    }

    /*8
    根据id查询数据
     */
    public AssessSignatureDailyOfficeWorkDTO findById(String id) {
        AssessSignatureDailyOfficeWorkDTO dto = new AssessSignatureDailyOfficeWorkDTO();
        AssessSignatureDailyOfficeWorkDTO dailyOfficeWorkDTO=signatureDailyOfficeWorkMapper.findById(id);
        if (ObjectUtil.isNotEmpty(dailyOfficeWorkDTO)){
            BeanUtils.copyProperties(dailyOfficeWorkDTO, dto);
            //查询附件信息
            List<WorkAttachmentInfo> fileList = signatureDailyOfficeWorkMapper.findFiles(id,"signatureDaily");

            if (CollectionUtils.isNotEmpty(fileList)) {
                for (WorkAttachmentInfo i : fileList) {
                    i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
                }
            }
            dto.setFiles(fileList);
            //查询已签章附件
            List<WorkAttachmentInfo> fileList1 = signatureDailyOfficeWorkMapper.findFiles(id,"signatured_daily");

            if (CollectionUtils.isNotEmpty(fileList1)) {
                for (WorkAttachmentInfo i : fileList1) {
                    i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
                }
            }
            dto.setSignatureFiles(fileList1);
        }
        return dto;
    }

    /**
     * 新增或修改
     * @param dto
     * @return
     */
    public AssessSignatureDailyOfficeWork save(AssessSignatureDailyOfficeWorkDTO dto) throws Exception {
        UserDTO userDTO = SpringUtil.getBean(IUserApi.class).getByToken(TokenProvider.getCurrentToken());
        if (StringUtils.isNotBlank(dto.getId())){
            return update(dto,userDTO);
        }
        return add(dto,userDTO);
    }

    private AssessSignatureDailyOfficeWork update(AssessSignatureDailyOfficeWorkDTO dto, UserDTO userDTO) {
        // 修改基础信息
        AssessSignatureDailyOfficeWork signatureDailyOfficeWork = new AssessSignatureDailyOfficeWork();
        BeanUtils.copyProperties(dto, signatureDailyOfficeWork);
        signatureDailyOfficeWork.setUpdateById(userDTO.getId());
        signatureDailyOfficeWork.setUpdateTime(new Date());
        signatureDailyOfficeWorkMapper.updateById(signatureDailyOfficeWork);
        // 修改附件信息列表
        if (CollectionUtils.isNotEmpty(dto.getFiles())) {
            updateFiles(dto.getFiles(), userDTO, dto.getId(),"signatureDaily");
        }

        //生成签章信息
        if (StringUtils.isNotBlank(dto.getStatus())&&dto.getStatus().equals("2")){
            this.getManualSignatureUrl(dto.getId());
        }
        return signatureDailyOfficeWork;
    }

    private AssessSignatureDailyOfficeWork add(AssessSignatureDailyOfficeWorkDTO dto, UserDTO userDTO) throws Exception {
        // 生成id
        String id = UUID.randomUUID().toString().replace("-", "");
        // 生成编号
        String no = SpringUtil.getBean ( IWorkAttachmentApi.class ).genSerialNum(userDTO.getCompanyDTO().getId(), dto.BIZ_CODE, TokenProvider.getCurrentToken());
        //保存信息
        AssessSignatureDailyOfficeWork signatureDailyOfficeWork = new AssessSignatureDailyOfficeWork();
        BeanUtils.copyProperties(dto, signatureDailyOfficeWork);
        signatureDailyOfficeWork.setId(id);
        signatureDailyOfficeWork.setNumber(no);
        signatureDailyOfficeWork.setCreateById(userDTO.getId());
        signatureDailyOfficeWork.setCreateTime(new Date());
        signatureDailyOfficeWork.setUpdateById(userDTO.getId());
        signatureDailyOfficeWork.setUpdateTime(new Date());
        signatureDailyOfficeWork.setDelFlag(0);
        signatureDailyOfficeWorkMapper.insert(signatureDailyOfficeWork);

        // 保存附件列表信息
        if (CollectionUtils.isNotEmpty(dto.getFiles())) {
            saveFiles(dto.getFiles(), userDTO, id);
        }
        //生成签章流程
        if ("2".equals(dto.getStatus())){
            this.getManualSignatureUrl(id);
        }
        return signatureDailyOfficeWork;
    }

    /**
     * 保存附件信息
     * @param list 待保存的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id) {
        int j = 1;
        for (WorkAttachmentInfo dto : list) {
            WorkAttachmentInfo i = new WorkAttachmentInfo();
            //包含了url、size、name
            i.setId(UUID.randomUUID().toString().replace("-", ""));
//            i.getCreateBy().setId(userDTO.getId());
            i.setCreateTime(new Date());
//            i.getUpdateBy().setId(userDTO.getId());
            i.setUpdateTime(new Date());
            i.setDelFlag(0);
            i.setUrl(dto.getUrl());
            //文件类型处理
            String fileName = dto.getName();
            List<String> strings = Arrays.asList(fileName.split("\\."));
            // 检查文件名是否有后缀
            if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
                // 获取最后一个部分作为文件类型
                i.setType(strings.get(strings.size() - 1));
            } else {
                // 如果没有后缀或文件名无效，设置一个默认类型或空
                i.setType("");
            }
            i.setAttachmentId(id);
            i.setAttachmentName(dto.getName());
            i.setAttachmentFlag("signatureDaily");
            i.setFileSize(dto.getSize());
            i.setSort(j);
//            ossServiceMapper.insertWorkAttachment(i, userDTO);
            Map<String,String> map = new HashMap<>();
            String workAttachment = JSON.toJSONString((i));
            String userDTOInfo = JSON.toJSONString((userDTO));
            map.put("workAttachment",workAttachment);
            map.put("userDTO",userDTOInfo);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
            j++;
        }
    }

    /**
     * 修改附件信息
     * @param list 待修改的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id, String attachmentFlag) {
        int j = 1;
        String names = new String();
        //表中存在，但是传过来不存在，说明已删除，表中数据也要删除
        for (WorkAttachmentInfo dto : list) {
            names = names + "," +dto.getUrl();
        }
        //查询保存的附件信息
        List<WorkAttachmentInfo> infoList = mapper.findListByIdAndAttachmentFlag(id,attachmentFlag);
        if (org.flowable.editor.language.json.converter.util.CollectionUtils.isNotEmpty(infoList)) {
            for (WorkAttachmentInfo i : infoList) {
                if (!names.contains(i.getUrl())) {
//                    ossServiceMapper.deleteById(i.getId());
                    SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteById(i.getId());
                }
            }
        }
        //保存信息
        for (WorkAttachmentInfo dto : list) {
            //判断是否存在
            Integer isExit = mapper.findIsExit(id, dto.getName());
            if (isExit == 0) {
                WorkAttachmentInfo i = new WorkAttachmentInfo();
                //包含了url、size、name
                i.setId(UUID.randomUUID().toString().replace("-", ""));
//                i.getCreateBy().setId(userDTO.getId());
                i.setCreateTime(new Date());
//                i.getUpdateBy().setId(userDTO.getId());
                i.setUpdateTime(new Date());
                i.setDelFlag(0);
                i.setUrl(dto.getUrl());
                //文件类型处理
                String fileName = dto.getName();
                List<String> strings = Arrays.asList(fileName.split("\\."));
                // 检查文件名是否有后缀
                if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
                    // 获取最后一个部分作为文件类型
                    i.setType(strings.get(strings.size() - 1));
                } else {
                    // 如果没有后缀或文件名无效，设置一个默认类型或空
                    i.setType("");
                }
                i.setAttachmentId(id);
                i.setAttachmentName(dto.getName());
                i.setAttachmentFlag(attachmentFlag);
                i.setFileSize(dto.getSize());
                i.setSort(j);
                Map<String,String> map = new HashMap<>();
                String workAttachment = JSON.toJSONString((i));
                String userDTOInfo = JSON.toJSONString((userDTO));
                map.put("workAttachment",workAttachment);
                map.put("userDTO",userDTOInfo);
                SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
//                ossServiceMapper.insertWorkAttachment(i, userDTO);
                j++;
            }
        }
    }


    /*8
    删除
     */
    public String remove(String id) {
        signatureDailyOfficeWorkMapper.deleteById(id);
        SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteByAttachmentId(id);
        return "操作成功";
    }

    /**
     * 根据id修改装填
     * @param dto
     */
    public void updateStatusById(AssessSignatureDailyOfficeWorkDTO dto) {
        signatureDailyOfficeWorkMapper.updateStatusById(dto.getStatus(),dto.getId());
        //如果是撤销或者是驳回,则需要对签章流程进行恢复
        if ("3".equals(dto.getStatus())||"4".equals(dto.getStatus())){
            AssessSignatureDailyOfficeWork dailyOfficeWorkDTO = new AssessSignatureDailyOfficeWork();
            dailyOfficeWorkDTO.setSignatureContractId("");
            dailyOfficeWorkDTO.setSignatureDocumentId("");
            dailyOfficeWorkDTO.setSignatureFlag(0);
            dailyOfficeWorkDTO.setSignatureUrlFlag(0);
            dailyOfficeWorkDTO.setSignatureUrl("");
            dailyOfficeWorkDTO.setSignatureFileName("");
            dailyOfficeWorkDTO.setSignatureUploadDate(null);
            dailyOfficeWorkDTO.setId(dto.getId());
            signatureDailyOfficeWorkMapper.updateById(dailyOfficeWorkDTO);
        }
    }

    /**
     * 根据documentId查询签章信息
     * @param documentId
     * @return
     */
    public AssessSignatureDailyOfficeWorkDTO getByDocumentId(String documentId) {
        AssessSignatureDailyOfficeWorkDTO dailyOfficeWork = signatureDailyOfficeWorkMapper.getByDocumentId(documentId);
        return dailyOfficeWork;
    }
    //根据contractId查询对应的报告信息
    public AssessSignatureDailyOfficeWorkDTO getByContractId(String contractId) {
        AssessSignatureDailyOfficeWorkDTO dailyOfficeWork = signatureDailyOfficeWorkMapper.getByContractId(contractId);
        return dailyOfficeWork;
    }

    /**
     * 根据报告签章id查询签章审核节点信息
     * @param
     * @return
     */
    public Map<String,Object> getAuditNodeById(String id){
        Map<String,Object> map = new HashMap<>();
        //查询流程id
        AssessSignatureDailyOfficeWorkDTO workDTO = signatureDailyOfficeWorkMapper.findById(id);
        if(StringUtils.isNotBlank(workDTO.getProcInsId())){
            //根据流程id查询流程当前节点信息
            String currentTask = flowTaskService.getCurrentTaskName(workDTO.getProcInsId());
            if(StringUtils.isNotEmpty(currentTask)){
                map.put("success", true);
                map.put("message", "获取签章流程成功");
                map.put("signatureType", currentTask);
            }else{
                map.put("success", false);
                map.put("message", "获取签章流程失败");
                map.put("signatureType", "");
            }
        }else{
            map.put("success", false);
            map.put("message", "获取签章流程失败");
            map.put("signatureType", "");
        }

        return map;
    }

    /**
     * 根据签章节点获取签章状态数据信息
     * @param id
     * @return
     */
    public Map<String,Object> getSignatureTypeById(String id){
        Map<String,Object> map = new HashMap<>();
        AssessSignatureDailyOfficeWorkDTO officeWorkDTO = signatureDailyOfficeWorkMapper.findById(id);
        if(null != officeWorkDTO){
            map.put("success", true);
            map.put("message", "获取签章完成情况成功");
            map.put("signatureType", officeWorkDTO.getSignatureFlag());
        }else{
            map.put("success", false);
            map.put("message", "获取签章完成情况失败");
            map.put("signatureType", "0");
        }
        return map;
    }

    /**
     * 创建签章流程
     * @param dailyOfficeWorkId
     * @return
     */
    public HashMap<String, Object> getManualSignatureUrl( String dailyOfficeWorkId) {
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("contractUrl","");
        map.put("success",false);
        //下载文件位置
        String deleteFile = null;
        try {
            //根据项目id查询是否已经提交过了报告签章
            AssessSignatureDailyOfficeWorkDTO dailyOfficeWork = this.findById(dailyOfficeWorkId);
            if(null == dailyOfficeWork){
                map.put("str","查询不到该签章申请信息");
                map.put("success",false);
                return map;
            }
            if(null!= dailyOfficeWork.getSignatureFlag() && 1 == dailyOfficeWork.getSignatureFlag()){
                map.put("str","该盖章申请已完成");
                map.put("success",false);
                return map;
            }

            List<WorkAttachmentInfo> infoList = mapper.findListByIdAndAttachmentFlag(dailyOfficeWorkId,"signatureDaily");


            //创建一个用于存放签章文件documentId的集合
            List<String> documentList = com.google.common.collect.Lists.newArrayList();
            if(infoList.size()>0) {
                String aliyunUrl = "http://cdn.gangwaninfo.com";
                String aliDownloadUrl = "http://oss.gangwaninfo.com";
                for (WorkAttachmentInfo workattachment : infoList) {
                    if (StringUtils.isBlank(workattachment.getUrl())) {
                        map.put("str", "签章文件存储路径为空，无法进行签章操作，请驳回后重新上传盖章文件");
                        map.put("success", false);
                    } else {
                        if (StringUtils.isBlank(workattachment.getUrl())) {
                            map.put("str", "签章文件存储路径为空，无法进行签章操作，请驳回后重新上传盖章文件");
                            map.put("success", false);
                        } else {
                            //下载签章申请文件
                            String path = null;
                            if (System.getProperty("os.name").toLowerCase().contains("win")) {
                                path = "D:/attachment-file/";
                            } else {
                                path = "/attachment-file/";
                            }
                            String file = aliyunUrl+workattachment.getUrl();
                            file = file.replace("amp;", "");
                            String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
                            String cons = "";
                            if (file.contains(aliyunUrl)) {
                                cons = aliyunUrl;
                            } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
                                cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
                            } else {
                                cons = aliDownloadUrl;
                            }
                            String ossKey = file.split(cons + "/")[1];
                            SpringUtil.getBean ( IWorkAttachmentApi.class ).downByStreamSaveLocal(ossKey,fileName,path+fileName);
                            //将下载下来的文件转换为file文件
                            File srcFile = new File(path + fileName);
                            deleteFile = path + fileName;

                            //截取文件后缀名
                            String substring = srcFile.getName().substring(srcFile.getName().lastIndexOf(".") + 1, srcFile.getName().length());
                            if (!"doc".equals(substring.toLowerCase()) && !"docx".equals(substring.toLowerCase()) && !"pdf".equals(substring.toLowerCase())) {
                                map.put("str", "请上传doc、docx或者pdf的文件进行签章操作");
                                map.put("success", false);
                            } else {

                                //获取真签单的documentId
                                HashMap hashMap = new SignaturePostUtil().getDocument(srcFile);
                                String code = hashMap.get("code").toString();

                                if ("0".equals(code)) {
                                    String documentId = "";
                                    String result = hashMap.get("result").toString();
                                    HashMap documentIdMap = JSON.parseObject(result, HashMap.class);
                                    documentId = documentIdMap.get("documentId").toString();
                                    if ("".equals(documentId)) {
                                        map.put("str", "签章文件创建失败，签章文件存在问题");
                                        map.put("success", false);
                                    } else {
                                        documentList.add(documentId);
                                    }
                                } else {
                                    String message = hashMap.get("message").toString();
                                    map.put("str", message);
                                    map.put("success", false);
                                }
                            }
                        }
                    }
                }
            }

            //根据项目id 和 documentId生成合同id
            HashMap contractIdHashMap = this.getManualSignatureContractId(documentList,dailyOfficeWork);
            String contractIdCode = contractIdHashMap.get("code").toString();
            String contractId = "";
            if("0".equals(contractIdCode)){
                contractId = contractIdHashMap.get("contractId").toString();
                if("".equals(contractId)){
                    map.put("str","签章文件创建失败");
                    map.put("success",false);
                    return map;
                }
            }else{
                map.put("str",contractIdHashMap.get("message").toString());
            }


            String documents = String.join(",", documentList);
            //修改报告信息中对应的签章contractId
            dailyOfficeWork.setSignatureDocumentId(documents);
            dailyOfficeWork.setSignatureContractId(contractId);
            //修改签章对应信息文件
            signatureDailyOfficeWorkMapper.updateSignatureInfo(dailyOfficeWork);

            map.put("success",true);
            return map;

            //获取contractUrl路径
            /*String contractUrl = this.getSignatureContractUrl(contractId);
            if("".equals(contractUrl)){
                map.put("str","签章文件创建失败");
                map.put("success",false);
                return map;
            }else{

                String documents = String.join(",", documentList);
                //修改报告信息中对应的签章contractId
                dailyOfficeWork.setSignatureDocumentId(documents);
                dailyOfficeWork.setSignatureContractId(contractId);
                //修改签章对应信息文件
                dao.updateSignatureInfo(dailyOfficeWork);

                map.put("contractUrl",contractUrl);
                map.put("success",true);
                return map;
            }*/
        } catch (Exception e) {
            e.getMessage();
        } finally {
            if(StringUtils.isNotBlank(deleteFile)){
                //根据路径创建文件对象
                File file = new File(deleteFile);
                //路径是个文件且不为空时删除文件
                if(file.isFile()&&file.exists()){
                    file.delete();
                }
            }
        }


        return map;
    }

    /**
     * 根据项目id 和 documentId生成合同id（手动签生成签署合同）
     * @param documentList
     * @return
     */
    public HashMap getManualSignatureContractId(List<String> documentList,AssessSignatureDailyOfficeWorkDTO dailyOfficeWork){
        HashMap hashMap = new HashMap();
        //创建签署方信息
        List<Action> actions = Lists.newArrayList();
        Set<String> serialIdSet = new HashSet<>();

        Action companyAction = new Action();
        companyAction.setType("CORPORATE");
        companyAction.setName("公司印章");
        companyAction.setSerialNo("1");
        //公司圆章-竖
        serialIdSet.add(COMPANYROUNDSEALID);
        //添加盖章位置
        List<Location> locations = Lists.newArrayList();
        for (String documentId: documentList) {
            Location location = new Location();
            location.setSealId(COMPANYROUNDSEALID);
            location.setDocumentId(documentId);
            location.setPage("0");
            location.setRectType("SEAL_CORPORATE");
            location.setKeywordIndex(-1);
            location.setOffsetX("0.5264");
            location.setOffsetY("0.6787");
            locations.add(location);
        }

        List<String> serialIdList = new ArrayList<String>(serialIdSet);
        companyAction.setSealIds("[" + String.join(",", serialIdList) + "]");
        companyAction.setAutoSign("false");
        companyAction.setLocations(locations);
        actions.add(companyAction);


        //创建签署方信息表
        List<SignatorieInfo> signatories = Lists.newArrayList();
        SignatorieInfo signatorieInfo1 = new SignatorieInfo();
        signatorieInfo1.setSerialNo("1");
        signatorieInfo1.setTenantName("江苏兴光项目管理有限公司");
        signatorieInfo1.setTenantType("COMPANY");
        signatorieInfo1.setActions(actions);
        signatories.add(signatorieInfo1);
        SignatureContract signatureContract = new SignatureContract();
        signatureContract.setDocuments(documentList);
        //签章申请用印流程id
        signatureContract.setCategoryId(DAILYOFFICEWORK);

        signatureContract.setSend(true);
        signatureContract.setSignatories(signatories);
        signatureContract.setSn("");
        if(null != dailyOfficeWork && StringUtils.isNotBlank(dailyOfficeWork.getNumber())){
            signatureContract.setSubject(dailyOfficeWork.getNumber() + "。" + dailyOfficeWork.getSignatureName());//添加项目名称
        }else if(null != dailyOfficeWork && StringUtils.isNotBlank(dailyOfficeWork.getSignatureName())){
            signatureContract.setSubject(dailyOfficeWork.getSignatureName());//添加项目名称
        }
        JSONObject json = JSONObject.fromObject(signatureContract);
        String contractIdMapStr = SignaturePostUtil.sendPostApplicationJson(HTTPTOP + "/contract/createbycategory", json.toString());
        hashMap = JSON.parseObject(contractIdMapStr, HashMap.class);

        return hashMap;
    }

}
