| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- package com.goafanti.demand.controller;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- 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 com.goafanti.admin.service.AftFileService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.constant.PageConstants;
- import com.goafanti.common.controller.CertifyApiController;
- import com.goafanti.common.enums.AttachmentType;
- import com.goafanti.common.enums.DemandAuditStatus;
- import com.goafanti.common.enums.DemandDataCategory;
- import com.goafanti.common.enums.DemandFields;
- import com.goafanti.common.enums.DemandOrderStatus;
- import com.goafanti.common.model.AftFile;
- import com.goafanti.common.model.Demand;
- import com.goafanti.common.model.DemandOrder;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.demand.bo.InputDemand;
- import com.goafanti.demand.service.DemandOrderService;
- import com.goafanti.demand.service.DemandService;
- @RestController
- @RequestMapping(value = "/api/user/demand")
- public class UserDemandApiController extends CertifyApiController {
- @Resource
- private DemandService demandService;
- @Resource
- private AftFileService aftFileService;
- @Resource
- private DemandOrderService demandOrderService;
- /**
- * 下载技术需求批量导入Excel模板
- */
- @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 = "/list", method = RequestMethod.GET)
- public Result list(String name,String startDate,String endDate,Integer pageNo, Integer pageSize) {
- Result res = new Result();
- res.setData(demandService.listMyDemand(name, startDate, endDate, pageNo, pageSize));
- return res;
- }
- /**
- * 新增需求
- */
- @RequestMapping(value = "/apply", method = RequestMethod.POST)
- public Result userApply(@Valid InputDemand demand, BindingResult bindingResult,
- @RequestParam(name = "keywords[]", required = false) String[] keywords,
- @RequestParam(value = "publishPages[]", required = false)String[] publishPages,
- String validityPeriodFormattedDate) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- res = disposeDemand(res, demand, keywords,publishPages);
- if (!res.getError().isEmpty()) {
- return res;
- }
- Demand d = new Demand();
- BeanUtils.copyProperties(demand, d);
- d.setEmployerId(TokenManager.getUserId());
- List<String> webPages = new ArrayList<String>();
- List<String> appPages = new ArrayList<String>();
- PageConstants.putDemand(publishPages, webPages, appPages);
- if(webPages.size()==0 && appPages.size() == 0){
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "页面参数错误"));
- return res;
- }
- demandService.saveDemand(d, validityPeriodFormattedDate, keywords,webPages, appPages);
- return res;
- }
- @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
- public Result demandDetail(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.selectDemandDetail(id));
- return res;
- }
-
-
- /**
- * 组织用户详情
- */
- @RequestMapping(value = "/orgDemandDetail", method = RequestMethod.GET)
- public Result orgDemandDetail(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.selectOrgDemandDetail(id));
- 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 = "/updateDemand", method = RequestMethod.POST)
- public Result updateDemand(@Valid InputDemand demand, BindingResult bindingResult,
- @RequestParam(name = "keywords[]", required = false) String[] keywords,
- @RequestParam(value = "publishPages[]", required = false) String[] publishPages,
- String validityPeriodFormattedDate) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- if (StringUtils.isBlank(demand.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
- return res;
- }
- if (!DemandAuditStatus.CREATE.getCode().equals(demand.getAuditStatus())
- && !DemandAuditStatus.UNAUDITED.getCode().equals(demand.getAuditStatus())
- && !DemandAuditStatus.REVOKE.getCode().equals(demand.getAuditStatus())) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核!"));
- return res;
- }
- //demand.setAuditStatus(DemandAuditStatus.INAUDIT.getCode()); 两步操作,先保存后提交
- res = disposeDemand(res, demand, keywords,publishPages);
- if (!res.getError().isEmpty()) {
- return res;
- }
- List<String> webPages = new ArrayList<String>();
- List<String> appPages = new ArrayList<String>();
- PageConstants.putDemand(publishPages, webPages, appPages);
- if(webPages.size()==0 && appPages.size() == 0){
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "页面参数错误"));
- return res;
- }
- Demand d = new Demand();
- BeanUtils.copyProperties(demand, d);
- d.setEmployerId(TokenManager.getUserId());
- res.setData(demandService.updateUserDemand(d, validityPeriodFormattedDate, keywords, webPages,appPages));
- return res;
- }
-
- @RequestMapping(value = "/publishDemand", method = RequestMethod.POST)
- public Result publishDemand(String id,Integer auditStatus){
- Result res = new Result();
- if (StringUtils.isBlank(id)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "需求ID"));
- return res;
- }
- if (null == auditStatus) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "需求状态错误", "需求状态"));
- return res;
- }
- if (DemandAuditStatus.CREATE.getCode() != auditStatus
- && DemandAuditStatus.UNAUDITED.getCode() != auditStatus
- && DemandAuditStatus.REVOKE.getCode() != auditStatus) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "当前状态无法提交审核!"));
- return res;
- }
- Demand d = new Demand();
- d.setId(id);
- d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
- demandService.updateByPrimaryKeySelective(d);
- return res;
- }
-
- /**
- * 需求撤消发布(下架)
- */
- @RequestMapping(value = "/offShelf", method = RequestMethod.POST)
- public Result offShelf(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) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "需求ID"));
- return res;
- }
- res.setData(demandService.updateReleaseStatus(d));
- return res;
- }
- /**
- * 删除需求(个人&团体)
- */
- @RequestMapping(value = "/delete", method = RequestMethod.POST)
- public 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, "", ""));
- } else {
- List<DemandOrder> list = demandOrderService.selectDemandOrderByDemandId(ids[0]);
- for (DemandOrder order : list){
- if (!DemandOrderStatus.CREATE.getCode().equals(order.getStatus())){
- res.getError().add(buildError("", "当前科技需求有订单,无法删除!"));
- return res;
- }
- }
- res.setData(demandService.deleteByPrimaryKey(Arrays.asList(ids)));
- }
- 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.DEMAND_PICTURE) {
- res.setData(handleFiles(res, "/demand/", false, req, sign, TokenManager.getUserId()));
- } 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.DEMAND_TEXT_FILE) {
- res.setData(handleFiles(res, "/demand/", false, req, sign, TokenManager.getUserId()));
- } else {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
- }
- 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;
- }
- private Result disposeDemand(Result res, InputDemand demand, String[] keywords,String[] publishPages) {
- if (StringUtils.isBlank(demand.getName())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
- return res;
- }
- if (!DemandDataCategory.USERDEMAND.getCode().equals(demand.getDataCategory())
- && !DemandDataCategory.ORGDEMAND.getCode().equals(demand.getDataCategory())) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "数据类型"));
- return res;
- }
- /*if (StringUtils.isBlank(demand.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 == demand.getIndustryCategoryA()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
- return res;
- }
- if (null == demand.getDemandType()) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
- return res;
- }
- if (StringUtils.isBlank(demand.getProblemDes())) {
- 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;
- }
- }
|