package com.softegg.freetogo.Demand.controller; import com.softegg.freetogo.Demand.bean.Demands; import com.softegg.freetogo.Demand.service.DemandsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * @description:Demand控制类,用于前后端交互 * @author:wuyifan * @date:2024/5/10 11:40 */ @RestController //@CrossOrigin(origins = "*") @RequestMapping("/demands") public class DemandsController { @Autowired private DemandsService demandsService; @GetMapping("findAll") public List findAll() { return demandsService.findAll(); } @GetMapping("add") public String add(String phone, boolean tGender, String nkn, String ct, String dDate, String eDate, String sDay, String city, String message) { Demands demand = new Demands(); setDemands(phone, tGender, nkn, ct, dDate, eDate, sDay, city, message, demand); demandsService.add(demand); return "添加成功"; } @GetMapping("delbyid") public String delById(int id) { demandsService.deleteById(id); return "删除成功"; } @GetMapping("findbyid") public Demands getUserById(int id) { return demandsService.getDemandById(id); } @GetMapping("update") public String update(int id, String phone, boolean tGender, String nkn, String ct, String dDate, String eDate, String sDay, String city, String message) { Demands demand = demandsService.getDemandById(id); setDemands(phone, tGender, nkn, ct, dDate, eDate, sDay, city, message, demand); demandsService.update(demand); return "更新成功"; } private void setDemands(String phone, boolean tGender, String nkn, String ct, String dDate, String eDate, String sDay, String city, String message, Demands demand) { demand.setPhone(phone); demand.setTouristGender(tGender); demand.setNickname(nkn); demand.setCreateTime(ct); demand.setDepartureDate(dDate); demand.setEndDate(eDate); demand.setSumDay(sDay); demand.setCity(city); demand.setMessage(message); // demand.setGuideGender(gGender); } }