Merge pull request '后端代码新增' (#9) from wuyifan_branch into develop

wuyifan_branch
mwxbgi697 1 year ago
commit 1676bb1968

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

@ -0,0 +1,13 @@
package com.softegg.freetogo.Demand.Dao;
import com.softegg.freetogo.Demand.bean.Demands;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @description:Jpa
* @author:wuyifan
* @date:2024/5/10 19:50
*/
public interface DemandsRepository extends JpaRepository<Demands, Integer> {
}

@ -0,0 +1,47 @@
package com.softegg.freetogo.Demand.bean;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* @description:demand
* @author:wuyifan
* @date:2024/5/10 11:36
*/
@Entity
@Table(name="demands")
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Demands {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer uid;
@Column
private String phone;//游客手机号码
@Column
private boolean touristGender;//游客性别 ture:male, false:female
@Column
private String nickname;//发布需求的游客昵称信息
@Column
private String createTime;//需求发布时间
@Column
private String departureDate;//游客需求起始日期
@Column
private String endDate;//游客需求结束日期
@Column
private String sumDay;//游客旅游总天数
@Column
private String city;//发布需求的目的城市
@Column
private String message;//需求备注内容
// @Column
// private boolean guideGender;//希望导游性别
// @Column
// private int status;
}

@ -0,0 +1,85 @@
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<Demands> 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);
}
}

@ -0,0 +1,23 @@
package com.softegg.freetogo.Demand.service;
import com.softegg.freetogo.Demand.bean.Demands;
import java.util.List;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 2059
*/
public interface DemandsService {
List<Demands> findAll();//查找所有需求
void add(Demands demand);//以demand为用户入库
void deleteById(int id);//删除对应id需求
Demands getDemandById(int id);//获得对应id需求
void update(Demands demand);//更新需求信息
}

@ -0,0 +1,92 @@
package com.softegg.freetogo.Demand.service;
import com.softegg.freetogo.Demand.Dao.DemandsRepository;
import com.softegg.freetogo.Demand.bean.Demands;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 19:50
*/
@Component
public class DemandsServiceImpl implements DemandsService {
@Autowired
private DemandsRepository DemandsRepository;
/**
* @description:
* @param: null
* @return: java.util.List<com.softegg.freetogo.Demand.Bean.Demands>
* @author: wuyifan
* @date: 2024/5/10 19:53
*/
public List<Demands> findAll() {
System.out.println("查询成功");
return DemandsRepository.findAll();
}
/**
* @description: demand
* @param: demand
* @return: void
* @author: wuyifan
* @date: 2024/5/10 19:55
*/
public void add(Demands demand) {
DemandsRepository.save(demand);
System.out.println("添加成功");
}
/**
* @description: id
* @param: id
* @return: void
* @author: wuyifan
* @date: 2024/5/10 19:59
*/
public void deleteById(int id) {
DemandsRepository.deleteById(id);
System.out.println("删除成功");
}
/**
* @description: id
* @param: id
* @return: com.softegg.freetogo.Demand.Bean.Demands
* @author: wuyifan
* @date: 2024/5/10 20:02
*/
public Demands getDemandById(int id) {
return DemandsRepository.findById(id).orElse(null);
}
/**
* @description:
* @param: demand
* @return: void
* @author: wuyifan
* @date: 2024/5/10 20:05
*/
public void update(Demands demand) {
DemandsRepository.save(demand);
System.out.println("更新成功");
}
// /**
// * @description: 判断相同需求是否已经入库
// * @param: id
// * @return: boolean
// * @author: wuyifan
// * @date: 2024/5/10 20:05
// */
// public boolean isRegister(int id) {
// Demands demand = DemandsRepository.findById(id);
// System.out.println(demand);
// return users != null;
// }
}
Loading…
Cancel
Save