Survey/src/main/java/com/example/survey/controller/RespondentController.java
2021-02-01 20:19:55 +08:00

61 lines
2.0 KiB
Java

package com.example.survey.controller;
import com.example.survey.entity.Respondent;
import com.example.survey.service.RespondentService;
import com.example.survey.dto.RespondentDto;
import com.example.survey.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Pope
*/
@RestController
@RequestMapping("/respondent")
public class RespondentController {
@Autowired
private RespondentService respondentService;
@PostMapping("/respondent")
public ResultVo addRespondent(@RequestBody Respondent respondent) {
ResultVo resultVo = new ResultVo();
boolean result = respondentService.addRespondent(respondent);
if (result) {
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("创建成功");
} else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("创建失败");
}
resultVo.setData(result);
return resultVo;
}
@GetMapping("/respondent")
public ResultVo countRespondent(@RequestParam(value = "investigatorPhone") String investigatorPhone,
@RequestParam(value = "currentPage") int currentPage,
@RequestParam(value = "pageSize", defaultValue = "30") int pageSize) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
Map<String, Object> resultMap = new HashMap<>(16, 0.75F);
List<RespondentDto> voList = respondentService.listRespondentPageByInvestigatorPhone(investigatorPhone, currentPage, pageSize);
resultMap.put("totalCount", voList.size());
resultMap.put("currentPage", currentPage);
resultMap.put("pageSize", pageSize);
resultMap.put("data", voList);
resultVo.setData(resultMap);
return resultVo;
}
}