| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- package com.goafanti.admin.controller;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- 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.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.enums.DemandReleaseStatus;
- import com.goafanti.common.model.Demand;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.demand.bo.InputDemand;
- import com.goafanti.demand.service.DemandService;
- @RestController
- @RequestMapping(value = "/api/admin/demand")
- public class AdminDemandApiController extends CertifyApiController {
- @Resource
- private DemandService demandService;
-
-
- /**
- * 需求资料--图片上传
- */
- @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) {
- 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 = "/userList", method = RequestMethod.GET)
- public Result userList(String province, Integer serialNumber, String name, String keyword, Integer infoSources,
- Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
- Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,
- String pageNo, String pageSize) {
- 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(demandService.selectUserDemandManageList(province, serialNumber, name, keyword, infoSources,
- demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
- releaseDateStartDate, releaseDateEndDate, pNo, pSize));
- return res;
- }
- /**
- * 个人用户新增需求
- */
- @RequestMapping(value = "/userApply", 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);
- demandService.saveUserDemandByManager(d, validityPeriodFormattedDate);
- return res;
- }
-
- /**
- * 修改个人用户需求
- */
- @RequestMapping(value = "/userUpdate", 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);
- res.setData(demandService.updateUserDemandByManager(d, validityPeriodFormattedDate));
- return res;
- }
- /**
- * 组织用户--需求列表
- */
- @RequestMapping(value = "/orgList", method = RequestMethod.GET)
- public Result orgList(String province, Integer serialNumber, String name, String keyword, Integer infoSources,
- Integer demandType, String validityPeriodStartDate, String validityPeriodEndDate, String username,
- Integer status, Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate,
- String pageNo, String pageSize) {
- 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(demandService.selectOrgDemandManageList(province, serialNumber, name, keyword, infoSources,
- demandType, validityPeriodStartDate, validityPeriodEndDate, username, status, releaseStatus,
- releaseDateStartDate, releaseDateEndDate, pNo, pSize));
- 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())){
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "数据类型"));
- return res;
- }
- if (StringUtils.isBlank(demand.getEmployerId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到雇主ID", "雇主ID"));
- 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;
- }
- if (!DemandReleaseStatus.RELEASED.getCode().equals(demand.getReleaseStatus())
- && !DemandReleaseStatus.UNRELEASE.getCode().equals(demand.getReleaseStatus())) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "是否发布"));
- return res;
- }
- return res;
- }
- }
|