package com.goafanti.demand.controller; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.goafanti.admin.service.AftFileService; import com.goafanti.common.bo.Result; import com.goafanti.common.constant.ErrorConstants; import com.goafanti.common.controller.CertifyApiController; import com.goafanti.common.enums.AttachmentType; import com.goafanti.common.enums.DeleteStatus; import com.goafanti.common.enums.DemandAuditStatus; import com.goafanti.common.model.AftFile; import com.goafanti.common.model.Demand; import com.goafanti.common.model.DemandFollow; import com.goafanti.common.model.DemandFollowDetail; import com.goafanti.common.model.DemandPublish; import com.goafanti.common.utils.StringUtils; import com.goafanti.demand.service.DemandFollowService; import com.goafanti.demand.service.DemandOrderService; import com.goafanti.demand.service.DemandPublishPageService; import com.goafanti.demand.service.DemandPublishService; import com.goafanti.demand.service.DemandService; import com.goafanti.user.service.UserService; @RestController @RequestMapping(value = "/api/admin/demand") public class AdminDemandApiController extends CertifyApiController { @Resource private DemandService demandService; @Resource private UserService userService; @Resource private AftFileService aftFileService; @Resource private DemandOrderService demandOrderService; @Resource DemandPublishService demandPublishService; @Resource DemandFollowService demandFollowService; /** * 科技需求匹配科技成果 */ @RequestMapping(value = "/matchAchievement", method = RequestMethod.POST) public Result matchAchievement(String id) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "成果ID")); return res; } Demand d = demandService.selectByPrimaryKey(id); if (null == d|| !DeleteStatus.UNDELETE.getCode().equals(d.getDeletedSign()) || !DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())) { res.getError().add(buildError("", "当前状态无法匹配!")); return res; } res.setData(demandService.updateMatchAchievement(d)); return res; } /** * 成果需求匹配列表 */ @RequestMapping(value = "/achievementDemand", method = RequestMethod.GET) public Result achievementDemand(String id) { Result res = new Result(); res.setData(demandService.selectAchievementDemandListByDemandId(id)); 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.DEMAND_TEMPLATE) { String fileName = ""; AftFile af = aftFileService.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.DEMAND_TEMPLATE.getDesc() + suffix; downloadFile(response, fileName, path); } } else { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示")); } return res; } /** * 个人用户--需求列表 */ @RequestMapping(value = "/userList", method = RequestMethod.GET) public Result userList(String pageNo, String pageSize) { Result res = new Result(); //res.setData(null); TODO return res; } /** * 组织用户--需求列表(个人组织合并) */ @RequestMapping(value = "/orgList", method = RequestMethod.GET) public Result orgList(String pageNo, String pageSize) { Result res = new Result(); //res.setData(null); TODO return res; } /** * 个人需求详情 */ @RequestMapping(value = "/userDemandDetail", method = RequestMethod.GET) public Result userDemandDetail(String id) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID")); return res; } res.setData(demandService.selectUserDemandDetail(id)); return res; } /** * 组织用户详情(个人组织合并) */ @RequestMapping(value = "/orgDemandDetail", method = RequestMethod.GET) public Result orgDemandDetail(String id,Integer dataCategory) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID")); return res; } if(dataCategory==0){ res.setData(demandService.selectUserDemandDetail(id)); return res; }else if(dataCategory==1){ res.setData(demandService.selectOrgDemandDetail(id)); return res; } return res; } /** * 需求管理--获取个人用户下拉 */ @RequestMapping(value = "/userNames", method = RequestMethod.GET) public Result getUserNames() { Result res = new Result(); res.setData(userService.selectDemandUserNames()); return res; } /** * 需求管理--获取组织用户下拉 */ @RequestMapping(value = "/unitNames", method = RequestMethod.GET) public Result getUnitNames() { Result res = new Result(); res.setData(userService.selectDemandUnitNames()); return res; } /** * 需求资料--图片上传 */ @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST) public Result uploadPicture(HttpServletRequest req, String sign, String uid) { Result res = new Result(); if (StringUtils.isBlank(uid)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID")); return res; } AttachmentType attachmentType = AttachmentType.getField(sign); if (attachmentType == AttachmentType.DEMAND_PICTURE|| attachmentType == AttachmentType.DEMAND_COVER_PICTURE) { res.setData(handleFiles(res, "/demand/", false, req, sign, uid)); } else { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示")); } return res; } /** * 需求资料--文本文件上传 */ @RequestMapping(value = "/uploadTextFile", method = RequestMethod.POST) public Result uploadTextFile(HttpServletRequest req, String sign, String uid) { Result res = new Result(); if (StringUtils.isBlank(uid)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户ID", "用户ID")); return res; } AttachmentType attachmentType = AttachmentType.getField(sign); if (attachmentType == AttachmentType.DEMAND_TEXT_FILE) { res.setData(handleFiles(res, "/demand/", false, req, sign, uid)); } 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; } Demand d = demandService.selectByPrimaryKey(id); if (null == d) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID")); return res; } d.setReleaseStatus(releaseStatus); res.setData(demandService.updateReleaseStatus(d)); return res; } /** * 下载需求文件--文本文件 */ @RequestMapping(value = "/download", method = RequestMethod.GET) public Result download(HttpServletResponse response, String id) { Result res = new Result(); if (StringUtils.isEmpty(id)) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID")); return res; } Demand d = demandService.selectByPrimaryKey(id); if (null == d) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID")); return res; } downloadUnPrivateFile(response, d.getTextFileDownloadFileName(), d.getTextFileUrl()); return res; } /** * 我的需求列表 */ @RequestMapping(value = "/myList", method = RequestMethod.GET) public Result myList(String pageNo, String pageSize) { Result res = new Result(); // res.setData(null) todo; return res; } /** * 需求发布 */ @RequestMapping(value = "/addDemandPublish", method = RequestMethod.POST) private Result addDemandPublish(DemandPublish d) { Result res = new Result(); if (StringUtils.isBlank(d.getDemandId())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求", "需求")); return res; } res.setData(demandPublishService.insertDemandPublish(d)); return res; } /** * 撤销发布 */ @RequestMapping(value = "/deletePublish", method = RequestMethod.GET) private Result deletePublish(String id) { Result res = new Result(); res.setData(demandPublishService.deletePublish(id)); return res; } /** * 修改发布 */ @RequestMapping(value = "/updatePublish", method = RequestMethod.GET) private Result updatePublish(DemandPublish d) { Result res = new Result(); res.setData(demandPublishService.updatePublish(d)); 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 employerName) { Result res = new Result(); if (null==pageNo) { pageNo=1; } if (null==pageSize) { pageSize=10; } res.setData(demandPublishService.listPublish( name, publishPlatform, publishClient, publishPage, ifTop, pageNo, pageSize,employerName)); return res; } /** * 获取需求页面位置 */ @RequestMapping(value="/getPublishPage",method = RequestMethod.GET) private Result getPublishPage(){ Result res=new Result(); return res.data(DemandPublishPageService.getBranchInformation()); } /** * 新增匹配跟进保存 */ @RequestMapping(value = "/addDemandFollow", method = RequestMethod.POST) private Result addDemandFollow(DemandFollow d) { Result res = new Result(); if (StringUtils.isBlank(d.getDemandId())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求", "需求")); return res; } if (StringUtils.isBlank(d.getContactMobile())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到联系人电话", "联系人电话")); return res; } if (StringUtils.isBlank(d.getContacts())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到联系人", "联系人")); return res; } if (StringUtils.isBlank(d.getOrganization())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到机构", "机构")); return res; } res.data(demandFollowService.insertDemandFollow(d)); return res; } /** * 修改匹配跟进 */ @RequestMapping(value = "/updateDemandFollow", method = RequestMethod.POST) private Result DemandFollow(DemandFollow d) { Result res = new Result(); if (StringUtils.isBlank(d.getId())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求匹配", "匹配跟进")); return res; } res.setData(demandFollowService.updateDemandFollow(d)); return res; } /** * 新增跟进情况 */ @RequestMapping(value = "/addDemandFollowDetail", method = RequestMethod.POST) private Result addDemandFollowDetail(DemandFollowDetail d,String createTimeFormattedDate) { Result res = new Result(); if (StringUtils.isBlank(d.getDemandFollowId())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求匹配跟进", "需求匹配跟进")); return res; } if (StringUtils.isBlank(d.getRemarks())) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到跟进情况", "跟进情况")); return res; } if (null==d.getResult()) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到跟进结果", "跟进结果")); return res; } if (StringUtils.isBlank(createTimeFormattedDate)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到跟进时间", "跟进时间")); return res; } res.data(demandFollowService.insertDemandFollowDetail(d,createTimeFormattedDate)); return res; } /** * 跟进列表 */ @RequestMapping(value = "/listDemandFollow", method = RequestMethod.GET) private Result listDemandFollow(String id,Integer pNo,Integer pSize) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求匹配跟进", "需求匹配跟进")); return res; } res.data(demandFollowService.selectDemandFollow( id, pNo, pSize)); return res; } /** * 删除跟进 */ @RequestMapping(value = "/deleteDemandFollow", method = RequestMethod.GET) private Result deleteDemandFollow(String id) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求匹配跟进", "需求匹配跟进")); return res; } res.data(demandFollowService.deleteDemandFollow( id)); return res; } /** * 跟进情况列表 */ @RequestMapping(value = "/listDemandFollowDetail", method = RequestMethod.GET) private Result listDemandFollowDetail(String id,Integer pNo, Integer pSize) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求跟进", "需求跟进")); return res; } res.data(demandFollowService.selectDemandFollowDetail( id,pNo, pSize)); return res; } /** * 匹配跟进 */ @RequestMapping(value = "/DemandFollowDetails", method = RequestMethod.GET) private Result DemandFollowDetails(String id) { Result res = new Result(); if (StringUtils.isBlank(id)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求跟进", "需求跟进")); return res; } res.data(demandService.DemandFollowDetails(id)); return res; } }