package com.goafanti.achievement.controller;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.goafanti.achievement.bo.AchievementImportBo;
import com.goafanti.achievement.bo.InputAchievement;
import com.goafanti.achievement.service.AchievementPublishPageService;
import com.goafanti.achievement.service.AchievementPublishService;
import com.goafanti.achievement.service.AchievementService;
import com.goafanti.admin.service.AttachmentService;
import com.goafanti.common.bo.Result;
import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.constant.ErrorConstants;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.dao.AdminMapper;
import com.goafanti.common.enums.AchievementAuditStatus;
import com.goafanti.common.enums.AchievementFields;
import com.goafanti.common.enums.AchievementImportFields;
import com.goafanti.common.enums.AttachmentType;
import com.goafanti.common.enums.DeleteStatus;
import com.goafanti.common.model.Achievement;
import com.goafanti.common.model.AchievementPublish;
import com.goafanti.common.model.Attachment;
import com.goafanti.common.service.BranchInformationService;
import com.goafanti.common.utils.LoggerUtils;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.user.service.UserService;
@RestController
@RequestMapping(value = "/api/admin/achievement")
public class AdminAchievementApiController extends CertifyApiController {
    @Resource
    private AchievementService		achievementService;
    @Resource
    private UserService				userService;
    @Resource
    private AttachmentService			attachmentService;
    @Resource
    private AdminMapper adminMapper;
    @Resource
    AchievementPublishService	achievementPublishService;
    @Resource
    BranchInformationService	branchInformationService;
    
    /**
     * 个人成果列表
     */
    @RequestMapping(value = "/userList", method = RequestMethod.GET)
    private Result userList(Integer ownerType,String username, String ownerName, String ownerId, Integer auditStatus,
            Integer serialNumber, String name, String keyword, Integer category, Integer status,
            String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate, Integer releaseStatus, String pageNo,
            String pageSize,Integer boutique,Integer hot) {
        Result res = new Result();
        Integer pNo = 1;
        Integer pSize = 10;
        if (StringUtils.isNumeric(pageSize)) {
            pSize = Integer.parseInt(pageSize);
        }
        if (StringUtils.isNumeric(pageNo)) {
            pNo = Integer.parseInt(pageNo);
        }
       res.setData(achievementService.listUserOwnerAchievement(ownerType,username, ownerName, ownerId, auditStatus, serialNumber, name,
                keyword, category, status, releaseDateStartDate, releaseDateEndDate,createDateStartDate,createDateEndDate, releaseStatus, pNo, pSize,boutique,hot));
       return res;
    }
    /**
     * 组织用户成果列表(个人组织合并)
     */
    @RequestMapping(value = "/orgList", method = RequestMethod.GET)
    private Result orgList(Integer ownerType,String unitName, String ownerName, String ownerId, Integer auditStatus, Integer serialNumber, String name,
            String keyword, Integer category, Integer status, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate,
            Integer releaseStatus,String internationalFlag, String pageNo, String pageSize,Integer boutique,Integer hot,String recordPerson) {
        Result res = new Result();
        Integer pNo = 1;
        Integer pSize = 10;
        if (StringUtils.isNumeric(pageSize)) {
            pSize = Integer.parseInt(pageSize);
        }
        if (StringUtils.isNumeric(pageNo)) {
            pNo = Integer.parseInt(pageNo);
        }
        
        Object o = achievementService.listOrgOwnerAchievement(ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name,
                keyword, category, status, releaseDateStartDate, releaseDateEndDate, createDateStartDate,  createDateEndDate, releaseStatus,internationalFlag, pNo, pSize,boutique,hot, recordPerson);
        
        res.setData(o);
        
        
        return res;
    }
    /**
     * 个人成果所有人列表
     */
    @RequestMapping(value = "/userOwner", method = RequestMethod.GET)
    public Result getAchievementUserOwner(String name) {
        Result res = new Result();
        if (StringUtils.isBlank(name)) {
            return res;
        }
        res.setData(userService.selectAchievementUserOwner(name));
        return res;
    }
    /**
     * 组织成果所有人列表
     */
    @RequestMapping(value = "/orgOwner", method = RequestMethod.GET)
    public Result getAchievementOrgOwner(String name) {
        Result res = new Result();
        if (StringUtils.isBlank(name)) {
            return res;
        }
        res.setData(userService.selectAchievementOrgOwner(name));
        return res;
    }
    /**
     * 个人成果详情详情
     */
    @RequestMapping(value = "/userDetail", method = RequestMethod.GET)
    private Result userDetail(String id) {
        Result res = new Result();
        if (StringUtils.isBlank(id)) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
            return res;
        }
        res.setData(achievementService.selectUserOwnerDetail(id));
        return res;
    }
    /**
     * 组织用户成果详情详情(个人组织合并)
     */
    @RequestMapping(value = "/orgDetail", method = RequestMethod.GET)
    private Result orgDetail(String id,int ownerType) {
        Result res = new Result();
        if (StringUtils.isBlank(id)) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
            return res;
        }
        if(ownerType==0){
        	res.setData(achievementService.selectUserOwnerDetail(id));
        }else if(ownerType==1){
        	res.setData(achievementService.selectOrgOwnerDetail(id));
        }       
        return res;
    }
    /**
     * 新增成果
     */
    @RequestMapping(value = "/apply", method = RequestMethod.POST)
    private Result apply(@Valid InputAchievement ia, BindingResult bindingResult,
            @RequestParam(name = "keywords[]", required = false) String[] keywords,String coverImg,Integer hot) {
        Result res = new Result();
        if (bindingResult.hasErrors()) {
            res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
                    AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
            return res;
        }
        if (StringUtils.isBlank(ia.getOwnerId()) && StringUtils.isBlank(ia.getOwnerName())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果所有人", "成果所有人"));
            return res;
        }
        res = disposeInputAchievement(res, ia, keywords);
        if (!res.getError().isEmpty()) {
            return res;
        }
        Achievement a = new Achievement();
        BeanUtils.copyProperties(ia, a);
        achievementService.saveAchievement(a, keywords);
       return res;
    }
    /**
     * 修改成果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@Valid InputAchievement ia, BindingResult bindingResult, Integer switchSign,
            @RequestParam(name = "keywords[]", required = false) String[] keywords,String coverImg,Integer hot) {
        Result res = new Result();
        if (bindingResult.hasErrors()) {
            res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
                    AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
            return res;
        }
       /* if (null == switchSign) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到开关标记", "开关标记"));
            return res;
        }
        if (!AchievementSwitchSign.CLOSE.getCode().equals(switchSign)
                && !AchievementSwitchSign.OPEN.getCode().equals(switchSign)) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "开关标记"));
            return res;
        }*/
        if (StringUtils.isBlank(ia.getId())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
            return res;
        }
        if (StringUtils.isBlank(ia.getOwnerId()) && StringUtils.isBlank(ia.getOwnerName())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果所有人", "成果所有人"));
            return res;
        }
        if (!AchievementAuditStatus.CREATE.getCode().equals(ia.getAuditStatus())
                && !AchievementAuditStatus.SUBMIT.getCode().equals(ia.getAuditStatus())
                && !AchievementAuditStatus.UNAUDITED.getCode().equals(ia.getAuditStatus())) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核！"));
            return res;
        }
        res = disposeInputAchievement(res, ia, keywords);
        if (!res.getError().isEmpty()) {
            return res;
        }
        Achievement a = new Achievement();
        BeanUtils.copyProperties(ia, a);
        achievementService.updateAchievement(a, keywords, switchSign);
       return res;
    }
    /**
     * 科技成果匹配科技需求
     */
    @RequestMapping(value = "/matchDemand", method = RequestMethod.POST)
    public Result matchDemand(String id) {
        Result res = new Result();
        if (StringUtils.isBlank(id)) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
            return res;
        }
        Achievement a = achievementService.selectByPrimaryKey(id);
        if (null == a || !AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
                || !DeleteStatus.UNDELETE.getCode().equals(a.getDeletedSign())
                ) {
            res.getError().add(buildError("", "当前状态无法匹配！"));
            return res;
        }
        res.setData(achievementService.updateMatchDemand(a));
        return res;
    }
    /**
     * 批量导入科技成果
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/importAchievement", method = RequestMethod.POST)
    public Result importAchievement(@RequestParam(name = "data", required = false) String d) {
        Result res = new Result();
        List<AchievementImportBo> data = JSON.parseArray(d, AchievementImportBo.class);
        if (data == null || data.isEmpty()) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据"));
            return res;
        }
        if (data.size() > AFTConstants.IMPORTMAXLENTH) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据量"));
            return res;
        }
        res = disposeImportAchievement(res, data);
        if (!res.getError().isEmpty()) {
            return res;
        }
        data = (List<AchievementImportBo>) res.getData();
        achievementService.insertImport(data);
        return res;
    }
    /**
     * 成果需求匹配列表
     */
    @RequestMapping(value = "/achievementDemand", method = RequestMethod.GET)
    public Result achievementDemand(String id) {
        Result res = new Result();
        res.setData(achievementService.selectAchievementDemandListByAchievementId(id));
        return res;
    }
    /**
     * 上传技术成果批量导入Excel模板
     * 
     * @param req
     * @return
     */
    @RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST)
    public Result uploadPatentTemplate(HttpServletRequest req, String sign) {
        Result res = new Result();
        String fileName = "";
        List<MultipartFile> files = getFiles(req);
        MultipartFile mf = files.get(0);
        String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
        if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
            AttachmentType attachmentType = AttachmentType.getField(sign);
            if (attachmentType == AttachmentType.ACHIEVEMENT_TEMPLATE) {
                fileName = sign + suffix;
            } else {
                res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
                return res;
            }
            String name = handleFile(res, req, fileName, files, mf);
            res.setData(name);
            if (!StringUtils.isBlank(name) && null == attachmentService.selectAftFileBySign(sign)) {
            	Attachment f = new Attachment();
                f.setId(UUID.randomUUID().toString());
                f.setFileName(AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc());
                f.setUid(TokenManager.getAdminId());
                f.setComment(AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc());
                f.setSign(sign);
                f.setFilePath("/admin/" + fileName);
                f.setDeleletedSign(DeleteStatus.UNDELETE.getCode());
                attachmentService.insert(f);
            }
        } else {
            res.getError().add(buildError(ErrorConstants.FILE_PATTERN_ERROR, "文件格式错误，请重新上传！"));
        }
        return res;
    }
    /**
     * 下载技术成果批量导入Excel模板
     * 
     * @param response
     * @return
     */
    @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
    public Result downloadTemplateFile(HttpServletResponse response, String sign) {
        Result res = new Result();
        AttachmentType attachmentType = AttachmentType.getField(sign);
        if (attachmentType == AttachmentType.ACHIEVEMENT_TEMPLATE) {
            String fileName = "";
            Attachment af = attachmentService.selectAftFileBySign(sign);
            if (null == af) {
                res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件！"));
            } else {
                String path = af.getFilePath();
                String suffix = path.substring(path.lastIndexOf("."));
                fileName = AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc() + suffix;
                downloadFile(response, fileName, path);
            }
        } else {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
        }
        return res;
    }
    /**
     * 成果撤消发布(下架)
     */
    @RequestMapping(value = "/offShelf", method = RequestMethod.POST)
    public Result offShelf(String id,Integer releaseStatus) {
        Result res = new Result();
        if (StringUtils.isBlank(id)) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
            return res;
        }
        Achievement a = achievementService.selectByPrimaryKey(id);
        if (null == a) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
            return res;
        }
        a.setReleaseStatus(releaseStatus);
        res.setData(achievementService.updateReleaseStatus(a));
        return res;
    }
    /**
     * 下载文本文件
     */
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public Result download(HttpServletResponse response, String id, String sign) {
        Result res = new Result();
        if (StringUtils.isEmpty(id)) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技成果ID"));
            return res;
        }
        Achievement a = achievementService.selectByPrimaryKey(id);
        if (null == a) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "科技成果ID"));
            return res;
        }
        AttachmentType attachmentType = AttachmentType.getField(sign);
        if (attachmentType == AttachmentType.ACHIEVEMENT_MATURITY_TEXT_FILE) {
            downloadUnPrivateFile(response, a.getMaturityTextFileDownloadFileName(), a.getMaturityTextFileUrl());
        } else if (attachmentType == AttachmentType.ACHIEVEMENT_TECH_PLAN) {
            downloadUnPrivateFile(response, a.getTechPlanDownloadFileName(), a.getTechPlanUrl());
        } else if (attachmentType == AttachmentType.ACHIEVEMENT_BUSINESS_PLAN) {
            downloadUnPrivateFile(response, a.getBusinessPlanDownloadFileName(), a.getBusinessPlanUrl());
        } else {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
        }
        return res;
    }
    /**
     * 文本文件上传
     */
    @RequestMapping(value = "/uploadTextFile", method = RequestMethod.POST)
    public Result uploadTextFile(HttpServletRequest req, String sign) {
        Result res = new Result();
        AttachmentType attachmentType = AttachmentType.getField(sign);
        if (attachmentType == AttachmentType.ACHIEVEMENT_MATURITY_TEXT_FILE
                || attachmentType == AttachmentType.ACHIEVEMENT_TECH_PLAN
                || attachmentType == AttachmentType.ACHIEVEMENT_BUSINESS_PLAN) {
            res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
        } else {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
        }
        return res;
    }
    /**
     * 图片上传
     */
    @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
    public Result uploadPicture(HttpServletRequest req, String sign) {
        Result res = new Result();
        AttachmentType attachmentType = AttachmentType.getField(sign);
        if (attachmentType == AttachmentType.ACHIEVEMENT_TECHNICAL_PICTURE
                || attachmentType == AttachmentType.ACHIEVEMENT_MATURITY_PICTURE
                || attachmentType == AttachmentType.ACHIEVEMENT_COVER_PICTURE) {
            res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
        } else {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
        }
        return res;
    }
    /**
     * 删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    private Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
        Result res = new Result();
        if (ids == null || ids.length != 1) {
            res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
        }
        return res;
    }
    private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
        if (StringUtils.isBlank(ia.getName())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
            return res;
        }
        if (null == ia.getCategory()) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
            return res;
        }
        if (StringUtils.isBlank(ia.getKeyword())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
            return res;
        }
        if (null == keywords || keywords.length < 1) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
            return res;
        }
        if (null == ia.getOwnerType()) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到所有人类型", "成果类别"));
            return res;
        }
        if (null == ia.getCooperationMode()) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合作方式", "合作方式"));
            return res;
        }
        for (int i = 0; i < keywords.length; i++) {
            if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
                res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
                return res;
            }
        }
        return res;
    }
    private String handleFile(Result res, HttpServletRequest req, String fileName, List<MultipartFile> files,
            MultipartFile mf) {
        if (!files.isEmpty()) {
            try {
                mf.transferTo(toAdminPrivateFile(fileName));
                LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
            } catch (IllegalStateException | IOException e) {
                LoggerUtils.error(getClass(), "文件上传失败", e);
                res.getError().add(buildError("", "文件上传失败!"));
                return "";
            }
        } else {
            res.getError().add(buildError("", "文件上传失败!"));
            return "";
        }
        return fileName;
    }
    private Result disposeImportAchievement(Result res, List<AchievementImportBo> data) {
        Field[] field = AchievementImportBo.class.getDeclaredFields();
        for (AchievementImportBo bo : data) {
            for (Field f : field) {
                f.setAccessible(true);
                try {
                    if (!f.getName().equals("keywords") && (f.get(bo) == null || "".equals(f.get(bo)))) {
                        res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "",
                                AchievementImportFields.getFieldDesc(f.getName())));
                        return res;
                    }
                } catch (IllegalArgumentException | IllegalAccessException e) {
                }
            }
            if (bo.getDataCategory().toString().length() > 1) {
                res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
                        AchievementImportFields.DATACATEGORY.getDesc()));
                return res;
            }
            if (bo.getName().length() > 31) {
                res.getError()
                        .add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.NAME.getDesc()));
                return res;
            }
            if (bo.getCategory().toString().length() > 1) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.CATEGORY.getDesc()));
                return res;
            }
            if (bo.getOwnerName().length() > 31) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERNAME.getDesc()));
                return res;
            }
            if (bo.getOwnerType().toString().length() > 1) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERTYPE.getDesc()));
                return res;
            }
            if (bo.getOwnerIdNumber().length() > 35) {
                res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
                        AchievementImportFields.OWNERIDNUMBER.getDesc()));
                return res;
            }
            if (bo.getOwnerMobile().length() > 11) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
                return res;
            }
            if (bo.getOwnerEmail().length() > 254) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.OWNERMOBILE.getDesc()));
                return res;
            }
            if (bo.getOwnerPostalAddress().length() > 254) {
                res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
                        AchievementImportFields.OWNERPOSTALADDRESS.getDesc()));
                return res;
            }
            if (bo.getCooperationMode().toString().length() > 1) {
                res.getError().add(buildError(ErrorConstants.PARAM_SIZE_ERROR, "",
                        AchievementImportFields.COOPERATIONMODE.getDesc()));
                return res;
            }
            if (bo.getKeyword().length() > 44) {
                res.getError().add(
                        buildError(ErrorConstants.PARAM_SIZE_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
                return res;
            }
            String[] keywords = bo.getKeyword().trim().split(",|，");
            if (null == keywords || keywords.length < 1) {
                res.getError()
                        .add(buildError(ErrorConstants.PARAM_ERROR, "", AchievementImportFields.KEYWORD.getDesc()));
                return res;
            }
            List<String> list = new ArrayList<>();
            for (String s : keywords) {
                if (!StringUtils.isBlank(s)) {
                    list.add(s);
                }
            }
            bo.setKeywords(list);
        }
        res.setData(data);
        return res;
    }
    /**
     * 我的成果列表
     */
    @RequestMapping(value = "/myList", method = RequestMethod.GET)
    private Result myList(Integer ownerType,String unitName, String ownerName, String ownerId, Integer auditStatus, Integer serialNumber, String name,
            String keyword, Integer category, Integer status, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate,
            Integer releaseStatus,String internationalFlag, String pageNo, String pageSize,Integer boutique,Integer hot) {
        Result res = new Result();
        Integer pNo = 1;
        Integer pSize = 10;
        if (StringUtils.isNumeric(pageSize)) {
            pSize = Integer.parseInt(pageSize);
        }
        if (StringUtils.isNumeric(pageNo)) {
            pNo = Integer.parseInt(pageNo);
        }
        String techBrokerId=TokenManager.getAdminId();
        Object o = achievementService.listMyAchievement(techBrokerId,ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name,
                keyword, category, status, releaseDateStartDate, releaseDateEndDate, createDateStartDate,  createDateEndDate, releaseStatus,internationalFlag, pNo, pSize,boutique,hot);
        res.setData(o);     
        return res;
    }
    
    /**
     * 科技成果管理列表
     */
    @RequestMapping(value = "/manageList", method = RequestMethod.GET)
    private Result manageList(Integer ownerType,String unitName, String ownerName, String ownerId, Integer auditStatus, Integer serialNumber, String name,
            String keyword, Integer category, Integer status, String releaseDateStartDate, String releaseDateEndDate,String createDateStartDate, String createDateEndDate,
            Integer releaseStatus,String internationalFlag, String pageNo, String pageSize,Integer boutique,Integer hot,String recordPerson) {
        Result res = new Result();
        Integer pNo = 1;
        Integer pSize = 10;
        if (StringUtils.isNumeric(pageSize)) {
            pSize = Integer.parseInt(pageSize);
        }
        if (StringUtils.isNumeric(pageNo)) {
            pNo = Integer.parseInt(pageNo);
        }
        String techBrokerId=TokenManager.getAdminId();
        Object o = achievementService.listManageAchievement(techBrokerId,ownerType,unitName, ownerName, ownerId, auditStatus, serialNumber, name,
                keyword, category, status, releaseDateStartDate, releaseDateEndDate, createDateStartDate,  createDateEndDate, releaseStatus,internationalFlag, pNo, pSize,boutique,hot,recordPerson);
        res.setData(o);     
        return res;
    }
    /**
     * 成果发布
     */
    @RequestMapping(value = "/addAchievementPublish", method = RequestMethod.POST)
    private Result addAchievementPublish(AchievementPublish a) {
    	Result res = new Result();
    	if (StringUtils.isBlank(a.getAchievementId())) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果", "成果"));
            return res;
        }
    	
        res.setData(achievementPublishService.insertachievementPublish(a));     
        return res;
    }
    /**
     * 撤销发布
     */
    @RequestMapping(value = "/deletePublish", method = RequestMethod.GET)
    private Result deletePublish(String id) {
        Result res = new Result();
        res.setData(achievementPublishService.deletePublish(id));     
        return res;
    }
    /**
     * 修改发布
     */
    @RequestMapping(value = "/updatePublish", method = RequestMethod.GET)
    private Result updatePublish(AchievementPublish a) {
        Result res = new Result();
        res.setData(achievementPublishService.updatePublish(a));     
        return res;
    }
    
    /**
     * 发布列表
     */
    @RequestMapping(value = "/listPublish", method = RequestMethod.GET)
    private Result listPublish(String name,String publishPlatform,Integer publishClient,String publishPage,
    		Integer ifTop, Integer pageNo, Integer pageSize,String ownerName) {
        Result res = new Result();
        if (null==pageNo) {
			pageNo=1;
		}
        if (null==pageSize) {
			pageSize=10;
		}
        res.setData(achievementPublishService.listPublish( name, publishPlatform, publishClient, publishPage,
        		 ifTop,  pageNo,  pageSize,ownerName));     
        return res;
    }
    /**
     * 获取分公司信息
     */
    @RequestMapping(value="/getBranchInformation",method = RequestMethod.GET)
    private Result getBranchInformation(){
    	Result res=new Result();
    	return res.data(branchInformationService.getBranchInformation());
    }
    /**
     * 获取成果页面位置
     */
    @RequestMapping(value="/getPublishPage",method = RequestMethod.GET)
    private Result getPublishPage(){
    	Result res=new Result();
    	return res.data(AchievementPublishPageService.getBranchInformation());
    }
	/**
	 * 客户知识产权列表（成果） 
	 * @return
	 */
    @RequestMapping(value="/listUserAchievement",method = RequestMethod.GET)
    private Result listUserAchievement(String uid,Integer pageNo, Integer pageSize){
    	Result res=new Result();
    	if (StringUtils.isBlank(uid)) {
            res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
            return res;
        }
    	return res.data(achievementService.listUserAchievement(uid,pageNo,pageSize));
    }
    
}