Browse Source

客户端需求管理-新增、修改、删除、文件上传下载

Antiloveg 8 years ago
parent
commit
a7f73b3209

+ 2 - 8
src/main/java/com/goafanti/admin/controller/AdminDemandApiController.java

@@ -20,7 +20,6 @@ import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.DemandDataCategory;
 import com.goafanti.common.enums.DemandFields;
-import com.goafanti.common.enums.DemandReleaseStatus;
 import com.goafanti.common.model.Demand;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.demand.bo.InputDemand;
@@ -153,7 +152,7 @@ public class AdminDemandApiController extends CertifyApiController {
 
 		Demand d = new Demand();
 		BeanUtils.copyProperties(demand, d);
-		demandService.saveUserDemandByManager(d, validityPeriodFormattedDate);
+		demandService.saveUserDemand(d, validityPeriodFormattedDate);
 		return res;
 	}
 
@@ -182,7 +181,7 @@ public class AdminDemandApiController extends CertifyApiController {
 
 		Demand d = new Demand();
 		BeanUtils.copyProperties(demand, d);
-		res.setData(demandService.updateUserDemandByManager(d, validityPeriodFormattedDate));
+		res.setData(demandService.updateUserDemand(d, validityPeriodFormattedDate));
 		return res;
 	}
 
@@ -315,11 +314,6 @@ public class AdminDemandApiController extends CertifyApiController {
 			return res;
 		}
 
-		if (!DemandReleaseStatus.RELEASED.getCode().equals(demand.getReleaseStatus())
-				&& !DemandReleaseStatus.UNRELEASE.getCode().equals(demand.getReleaseStatus())) {
-			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "是否发布"));
-			return res;
-		}
 		return res;
 	}
 }

+ 189 - 1
src/main/java/com/goafanti/demand/controller/DemandApiController.java

@@ -1,18 +1,34 @@
 package com.goafanti.demand.controller;
 
+import java.util.Arrays;
+
 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.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.DemandDataCategory;
+import com.goafanti.common.enums.DemandFields;
+import com.goafanti.common.model.Demand;
 import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.shiro.token.TokenManager;
+import com.goafanti.demand.bo.InputDemand;
 import com.goafanti.demand.service.DemandService;
 
 @RestController
 @RequestMapping(value = "/api/user/demand")
-public class DemandApiController {
+public class DemandApiController extends CertifyApiController{
 	@Resource
 	private DemandService demandService;
 	
@@ -39,5 +55,177 @@ public class DemandApiController {
 				releaseDateEndDate, pNo, pSize));
 		return res;
 	}
+	
+	/**
+	 * 新增需求
+	 */
+	@RequestMapping(value = "/apply", method = RequestMethod.POST)
+	public Result userApply(@Valid InputDemand demand, BindingResult bindingResult,
+			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);
+		if (!res.getError().isEmpty()) {
+			return res;
+		}
+
+		Demand d = new Demand();
+		BeanUtils.copyProperties(demand, d);
+		d.setEmployerId(TokenManager.getUserId());
+		demandService.saveUserDemand(d, validityPeriodFormattedDate);
+		return res;
+	}
+
+	/**
+	 * 修改需求
+	 */
+	@RequestMapping(value = "/update", method = RequestMethod.POST)
+	public Result updateUser(@Valid InputDemand demand, BindingResult bindingResult,
+			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;
+		}
+
+		res = disposeDemand(res, demand);
+		if (!res.getError().isEmpty()) {
+			return res;
+		}
+
+		Demand d = new Demand();
+		BeanUtils.copyProperties(demand, d);
+		d.setEmployerId(TokenManager.getUserId());
+		res.setData(demandService.updateUserDemand(d, validityPeriodFormattedDate));
+		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 {
+			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) {
+		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 == demand.getInfoSources()) {
+			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;
+		}
+
+		if (null == demand.getReleaseStatus()) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到是否发布", "是否发布"));
+			return res;
+		}
+
+		return res;
+	}
 
 }

+ 2 - 2
src/main/java/com/goafanti/demand/service/DemandService.java

@@ -20,9 +20,9 @@ public interface DemandService {
 			String validityPeriodEndDate, String username, Integer status, Integer releaseStatus, String releaseDateStartDate,
 			String releaseDateEndDate, Integer pNo, Integer pSize);
 
-	void saveUserDemandByManager(Demand d, String validityPeriodFormattedDate);
+	void saveUserDemand(Demand d, String validityPeriodFormattedDate);
 
-	int updateUserDemandByManager(Demand d, String validityPeriodFormattedDate);
+	int updateUserDemand(Demand d, String validityPeriodFormattedDate);
 
 	DemandManageDetailBo selectUserDemandDetail(String id);
 

+ 2 - 2
src/main/java/com/goafanti/demand/service/impl/DemandServiceImpl.java

@@ -258,7 +258,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 	}
 
 	@Override
-	public void saveUserDemandByManager(Demand d, String validityPeriodFormattedDate) {
+	public void saveUserDemand(Demand d, String validityPeriodFormattedDate) {
 		Date validityPeriod = null;
 		if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
 			try {
@@ -285,7 +285,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 	}
 
 	@Override
-	public int updateUserDemandByManager(Demand d, String validityPeriodFormattedDate) {
+	public int updateUserDemand(Demand d, String validityPeriodFormattedDate) {
 
 		Date validityPeriod = null;
 		if (!StringUtils.isBlank(validityPeriodFormattedDate)) {