Merge branch 'master' of bdgit.educoder.net:mwxbgi697/softegg

master
zhanglinhao 1 year ago
commit 383a9111cd

@ -0,0 +1,20 @@
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
#app {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 20px;
}
</style>

@ -0,0 +1,16 @@
<template>
<div>
<label for="user-input"></label>
<input type="text" id="user-input" v-model="userInput" placeholder="请输入">
</div>
</template>
<script>
export default {
data() {
return {
userInput: '', //
};
},
};
</script>

@ -0,0 +1,67 @@
<template>
<div class="footer-nav">
<div class="button-with-icon" @click="gotohome()">
<el-icon><House /></el-icon>
<span>首页</span>
</div>
<div class="button-with-icon" @click="gotomessage()()">
<el-icon><ChatDotSquare /></el-icon>
<span>消息</span>
</div>
<div class="button-with-icon" @click="gotomine()">
<el-icon><User /></el-icon>
<span>我的</span>
</div>
</div>
</template>
<script>
export default {
name: 'Home',
methods: {
gotohome() {
this.$router.push('/home');
},
gotomessage() {
this.$router.push('/message');
},
gotomine() {
this.$router.push('/mine');
},
gotoSearchPage() {
this.$router.push('/searchPage');
},
gotoAddDemandPage() {
this.$router.push('/addDemandPage');
},
}
}
</script>
<style>
.footer-nav {
/* 定义底部导航的样式 */
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-around;
padding: 10px;
background-color: #f5f5f5; /* 示例背景色 */
}
.button-with-icon {
/* 定义按钮的样式 */
flex: 1;
border: none;
padding: 10px;
background-color: #d5d5d5;
color: #333;
cursor: pointer;
}
.button-with-icon:hover {
background-color: #aaaaaa;
}
</style>

@ -0,0 +1,27 @@
<template>
<div>
<el-carousel :interval="4000" arrow="always">
<el-carousel-item v-for="(item, index) in imagePaths" :key="index">
<img :src="item" alt = "描述图像的文本">
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const imagePaths = ref([
'https://dimg04.c-ctrip.com/images/0102p12000828jmogCF2E_C_1600_1200.jpg',
'https://pic.kuaizhan.com/g3/b7/18/7a16-bad5-4d28-b5aa-571710c674cb36',
'https://img.shetu66.com/2023/07/11/1689058469100908.png'
]);
return {
imagePaths
};
}
};
</script>

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
/>
</svg>
</template>

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
<path
d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
/>
</svg>
</template>

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
<path
d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
/>
</svg>
</template>

@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
/>
</svg>
</template>

@ -0,0 +1,19 @@
<!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
aria-hidden="true"
role="img"
class="iconify iconify--mdi"
width="24"
height="24"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
>
<path
d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
fill="currentColor"
></path>
</svg>
</template>

@ -0,0 +1,70 @@
<template>
<el-button plain class="addServe-button" @click="isGuide()">
我是导游
</el-button>
<el-dialog
v-model="dialogVisible"
width="500"
>
<span>您还不是导游是否申请平台导游资格</span>
<template #footer>
<div class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="gotoRegisterGuide">
申请
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import axios from 'axios';
const router = useRouter();
const dialogVisible = ref(false)
const gotoRegisterGuide = () => {
router.push('/registerGuide')
}
const isGuide = () => {
axios.get(`http://192.168.243.35:9000/users/isGuide?phone=${sessionStorage.getItem('phone')}`)
.then(response => {
if (response.data == true){
router.push('/addServe')
}
else{
dialogVisible.value = true;
}
})
.catch(error => {
console.error('Error fetching user:', error);
});
}
</script>
<style>
.addServe-button {
/* 定义返回按钮的样式 */
position: fixed; /* 使按钮位置固定 */
top: 10px;
right: 10px;
margin: 0;
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #ccc;
color: #333;
cursor: pointer;
}
.addServe-button:hover {
background-color: #aaaaaa;
}
</style>

@ -0,0 +1,6 @@
export type AreaList = {
code: string;
level: number;
name: string;
areaList: AreaList[];
};

@ -0,0 +1,18 @@
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import VueDatePicker from '@vuepic/vue-datepicker';
import '@vuepic/vue-datepicker/dist/main.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(ElementPlus);
app.use(router);
app.component('VueDatePicker', VueDatePicker);
app.mount('#app');

@ -0,0 +1,19 @@
package com.softegg.freetogo.Demand.Dao;
import com.softegg.freetogo.Demand.bean.Demands;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* @description:Jpa
* @author:wuyifan
* @date:2024/5/10 19:50
*/
public interface DemandsRepository extends JpaRepository<Demands, Integer> {
List<Demands> findByPhone(String phone);
List<Demands> findByCity(String city);
List<Demands> findByProvince(String province);
}

@ -0,0 +1,53 @@
package com.softegg.freetogo.Demand.bean;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
/**
* @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 did;
@Column
private String phone;//游客手机号码
@Column(name = "tourist_gender")
private boolean touristGender;//游客性别 ture:male, false:female
@Column
private String nickname;//发布需求的游客昵称信息
@Column(name = "create_time")
private String createTime;//需求发布时间
@Column(name = "departure_date")
private String departureDate;//游客需求起始日期
@Column(name = "end_date")
private String endDate;//游客需求结束日期
@Column(name = "sum_day")
private String sumDay;//游客旅游总天数
@Column
private String province;//发布需求的目的省份
@Column
private String city;//发布需求的目的城市
@Column
private String message;//需求备注内容
@Column
private Integer status;//游客需求状态 0未匹配 1请求匹配 2已完成匹配 3已完成所有服务
@Column
private Integer guideServiceId;//游客需求最终匹配到的导游服务id
@ElementCollection
@Column(name = "guide_service_id_list")
private List<Integer> guideServiceIdList;//游客需求申请匹配到的导游服务id
}

@ -0,0 +1,107 @@
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.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @description:Demand
* @author:wuyifan
* @date:2024/5/10 11:40
*/
@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/demands")
public class DemandsController {
@Autowired
private DemandsService demandsService;
@GetMapping("findAllRandom")
public List<Demands> findAllRandom() {
List<Demands> dlist = demandsService.findAll();
Collections.shuffle(dlist);
return dlist;
}
@GetMapping("add")
public String add(String phone,
boolean tGender,
String nkn,
String ct,
String dDate,
String eDate,
String sDay,
String province,
String city,
String message,
Integer status,
Integer guideServiceId,
List<Integer> guideServiceIdList) {
Demands demand = new Demands();
setDemands(phone, tGender, nkn, ct, dDate, eDate, sDay, province, city, message, status, demand, guideServiceId, guideServiceIdList);
demandsService.add(demand);
return "添加成功";
}
@PostMapping("delbyid")
public int delById(@RequestBody Map<String, Object> map) {
int did = Integer.parseInt(map.get("did").toString());
demandsService.deleteById(did);
return 1;
}
@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 province,
String city,
String message,
Integer status,
Integer guideServiceId,
List<Integer> guideServiceIdList) {
Demands demand = demandsService.getDemandById(id);
setDemands(phone, tGender, nkn, ct, dDate, eDate, sDay, province, city, message, status, demand, guideServiceId, guideServiceIdList);
demandsService.update(demand);
return "更新成功";
}
@GetMapping("getByPhone")
public List<Demands> getByPhone(String phone) {
System.out.println("根据手机号获取游客需求信息:" + phone);
return demandsService.getDemandsByPhone(phone);
}
private void setDemands(String phone, boolean tGender, String nkn, String ct, String dDate, String eDate, String sDay, String province, String city, String message, Integer status, Demands demand,Integer guideServiceId,List<Integer> guideServiceIdList) {
demand.setPhone(phone);
demand.setTouristGender(tGender);
demand.setNickname(nkn);
demand.setCreateTime(ct);
demand.setDepartureDate(dDate);
demand.setEndDate(eDate);
demand.setSumDay(sDay);
demand.setProvince(province);
demand.setCity(city);
demand.setMessage(message);
demand.setStatus(status);
demand.setGuideServiceId(guideServiceId);
demand.setGuideServiceIdList(guideServiceIdList);
}
}

@ -0,0 +1,28 @@
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);//更新需求信息
List<Demands> getDemandsByPhone(String phone);//根据手机号获得对应游客用户的服务
List<Demands> getDemandsByCity(String city);//根据手机号获得对应游客用户的服务
List<Demands> getDemandsByProvince(String province);//根据手机号获得对应游客用户的服务
}

@ -0,0 +1,124 @@
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.Iterator;
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 did) {
DemandsRepository.deleteById(did);
System.out.println("删除成功对应did:");
}
/**
* @description:
* @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: phone
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/15 20:18
*/
public List<Demands> getDemandsByPhone(String phone) {
List<Demands> demandsList = DemandsRepository.findByPhone(phone);
Iterator<Demands> iterator = demandsList.iterator();
while (iterator.hasNext()) {
Demands demand = iterator.next();
if (demand.getStatus() == 4) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
return demandsList;
}
/**
* @description:
* @param: city
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/15 20:18
*/
public List<Demands> getDemandsByCity(String city) {
return DemandsRepository.findByCity(city);
}
/**
* @description:
* @param: city
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/15 20:18
*/
public List<Demands> getDemandsByProvince(String province) {
return DemandsRepository.findByProvince(province);
}
}

@ -0,0 +1,140 @@
package com.softegg.freetogo.DemandMatch.controller;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import com.softegg.freetogo.DemandMatch.service.DemandMatchService;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author:wuyifan
* @date:2024/6/4 14:47
*/
@RestController
@RequestMapping("/DemandMatch")
public class DemandMatchController {
@Autowired
DemandMatchService demandMatchService;
@Autowired
UsersService usersService;
@Autowired
GuideServiceService guideServiceService;
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/4 14:48
*/
@GetMapping("register")
public List<GuideService> GuideMatch(int did) {
System.out.println("接收的did:"+did);
return demandMatchService.guideMatchAccount(did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/4 14:48
*/
@GetMapping("specific")
public List<GuideService> specific(int did, int gid) {
System.out.println("接收的did:"+did);
return demandMatchService.guideMatchAccount(did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("match")
public int Match(@RequestBody Map<String, Object> map) {
int did = (int) map.get("did");
System.out.println("接收的did:"+did);
int gid = (int) map.get("gid");
System.out.println("接收的did:"+did);
return demandMatchService.match(did, gid);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@GetMapping("confirmedPage")
public List<GuideService> confirmedpage(int did) {
System.out.println("接收的did:"+did);
return demandMatchService.confirmedPage(did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("confirmed")
public int confirmed(@RequestBody Map<String, Object> map) {
int did = Integer.parseInt(map.get("did").toString());
System.out.println("接收的did:"+did);
int gid = Integer.parseInt(map.get("gid").toString());
System.out.println("接收的did:"+gid);
return demandMatchService.confirmed(did, gid);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("refuse")
public int refuse(@RequestBody Map<String, Object> map) {
int did = (int) map.get("did");
System.out.println("接收的did:"+did);
return demandMatchService.refuse(did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("finish")
public int finish(@RequestBody Map<String, Object> map) {
int did = (int) map.get("did");
System.out.println("接收的did:"+did);
return demandMatchService.finish(did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("delete")
public int delete(@RequestBody Map<String, Object> map) {
int did = (int) map.get("did");
System.out.println("接收的did:"+did);
return demandMatchService.delete(did);
}
}

@ -0,0 +1,26 @@
package com.softegg.freetogo.DemandMatch.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.bean.GuideService;
import java.util.List;
public interface DemandMatchService {
List<GuideService> guideMatchAccount(int did);
int match(int did, int gid);
int confirmed(int did, int gid);
List<GuideService> confirmedPage(int did);
int refuse(int did);
int finish(int did);
int delete(int did);
double timeScore(int gsum, String gddate, String gedate, int dsum, String dddate, String dedate);
double messageScore(String gmessage, String dmessage);
}

@ -0,0 +1,421 @@
package com.softegg.freetogo.DemandMatch.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.Demand.service.DemandsService;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.User.service.UsersService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.format.DateTimeFormatter;
import java.util.*;
import static java.lang.Math.abs;
import java.time.LocalDate;
/**
* description:
* @author:wuyifan
* date:2024/5/28 19:51
*/
@Component
public class DemandMatchServiceImpl implements DemandMatchService{
@Autowired
DemandsService demandsService;
@Autowired
UsersService usersService;
@Autowired
GuideServiceService guideServiceService;
/**
* @description:
* @param: city
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public List<GuideService> guideMatchAccount(int did){
Demands demand = demandsService.getDemandById(did);
int demandSumDay = Integer.parseInt(demand.getSumDay());
String demandDepartureDate = demand.getDepartureDate();
String demandEndDate = demand.getEndDate();
String demandMessage = demand.getMessage();
List<GuideService> guideServiceList = guideServiceService.getGuideServiceByCity(demand.getCity());
Iterator<GuideService> iterator = guideServiceList.iterator();
while (iterator.hasNext()) {
GuideService guideService = iterator.next();
if (guideService.getStatus() > 1) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
int length = guideServiceList.size();
double[] sumScores = new double[length];
int i = 0;
for (GuideService guideService : guideServiceList) {
double sumScore = 0;
int guideServiceSumDay = Integer.parseInt(guideService.getSumDay());
String guideServiceDepartureDate = guideService.getDepartureDate();
String guideServiceEndDate = guideService.getEndDate();
String guideServiceMessage = guideService.getMessage();
double timeScore = timeScore(guideServiceSumDay, guideServiceDepartureDate, guideServiceEndDate, demandSumDay, demandDepartureDate, demandEndDate);
double messageScore = messageScore(guideServiceMessage, demandMessage);
sumScore += timeScore + messageScore;
sumScores[i] = sumScore;
i++;
}
// 创建一个包含索引和值的列表
List<Map.Entry<Double, GuideService>> list = new ArrayList<>();
for (int j = 0; j < sumScores.length; j++) {
list.add(new AbstractMap.SimpleEntry<>(sumScores[j], guideServiceList.get(j)));
}
// 根据sumScores的元素大小对 list 进行排序
list.sort(new Comparator<Map.Entry<Double, GuideService>>() {
@Override
public int compare(Map.Entry<Double, GuideService> o1, Map.Entry<Double, GuideService> o2) {
return o2.getKey().compareTo(o1.getKey());
}
});
List<GuideService> newgList = new ArrayList<>();
for (Map.Entry<Double, GuideService> entry : list) {
newgList.add(entry.getValue());
}
return newgList;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int match(int did, int gid){
Demands demand = demandsService.getDemandById(did);
GuideService guideService = guideServiceService.getGuideServiceById(gid);
// List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
// if (guideServiceIdList == null) {
// guideServiceIdList = new ArrayList<>();
// }
// guideServiceIdList.add(gid);
// demand.setGuideServiceIdList(guideServiceIdList);
List<Integer> demandIdList = guideService.getDemandIdList();
if (demandIdList == null) {
demandIdList = new ArrayList<>();
}
if(!demandIdList.contains(did)) {
demandIdList.add(did);
}
guideService.setStatus(1);
guideService.setDemandIdList(demandIdList);
demandsService.update(demand);
guideServiceService.update(guideService);
System.out.println(guideService.getDemandIdList());
return 1006;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int confirmed(int did, int gid){
Demands demand = demandsService.getDemandById(did);
GuideService guideService = guideServiceService.getGuideServiceById(gid);
demand.setStatus(2);
demand.setGuideServiceId(gid);
guideService.setStatus(2);
guideService.setDemandId(did);
demandsService.update(demand);
guideServiceService.update(guideService);
return 1007;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public List<GuideService> confirmedPage(int did){
Demands demand = demandsService.getDemandById(did);
List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
List<GuideService> guideServiceList = new ArrayList<>();
for(int number : guideServiceIdList) {
GuideService guideService = guideServiceService.getGuideServiceById(number);
guideServiceList.add(guideService);
}
return guideServiceList;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int refuse(int did){
Demands demand = demandsService.getDemandById(did);
int gid = demand.getGuideServiceId();
GuideService guideService = guideServiceService.getGuideServiceById(gid);
List<Integer> demandIdList = guideService.getDemandIdList();
if (demandIdList == null) {
guideService.setStatus(0);
}else {
guideService.setStatus(1);
}
List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
if(guideServiceIdList == null){
demand.setStatus(0);
}else {
demand.setStatus(1);
}
demand.setGuideServiceId(null);
guideService.setDemandId(null);
demandsService.update(demand);
guideServiceService.update(guideService);
return 1;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int finish(int did){
Demands demand = demandsService.getDemandById(did);
int gid = demand.getGuideServiceId();
GuideService guideService = guideServiceService.getGuideServiceById(gid);
demand.setStatus(3);
demand.setGuideServiceIdList(null);
guideService.setStatus(3);
guideService.setDemandIdList(null);
demandsService.update(demand);
guideServiceService.update(guideService);
return 1;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int delete(int did){
Demands demand = demandsService.getDemandById(did);
demand.setStatus(4);
demandsService.update(demand);
return 1;
}
public static boolean isRangeWithinRange(LocalDate startDate1, LocalDate endDate1, LocalDate startDate2, LocalDate endDate2) {
// 第一个范围的起始日期必须在第二个范围内或与其起始日期相同
return !startDate1.isBefore(startDate2) && !endDate1.isAfter(endDate2);
}
/**
* @description:
* @param: gsumdsumddateedate
* @return: float
* @author: wuyifan
* @date: 2024/5/28 20:35
*/
@Override
public double timeScore(int gsum, String gddate, String gedate, int dsum, String dddate, String dedate){
double score = 0;
int difference = gsum - dsum;
if (abs(difference) < 15 ){
score += 10 / (float)(abs(difference) + 1);
}
// 使用DateTimeFormatter将字符串转换为LocalDate对象
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate1 = LocalDate.parse(dddate, formatter);
LocalDate endDate1 = LocalDate.parse(dedate, formatter);
LocalDate startDate2 = LocalDate.parse(gddate, formatter);
LocalDate endDate2 = LocalDate.parse(gedate, formatter);
// 判断第一个范围是否在第二个范围内
boolean isRange1WithinRange2 = isRangeWithinRange(startDate1, endDate1, startDate2, endDate2);
if (isRange1WithinRange2){
score += 100;
}
return score;
}
/**
* @description: Jaccard
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:35
*/
public static double jaccardSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Set<Character> set1 = new HashSet<>();
Set<Character> set2 = new HashSet<>();
for (char c : s1.toCharArray()) {
set1.add(c);
}
for (char c : s2.toCharArray()) {
set2.add(c);
}
Set<Character> intersection = new HashSet<>(set1);
intersection.retainAll(set2);
Set<Character> union = new HashSet<>(set1);
union.addAll(set2);
return (double) intersection.size() / union.size();
}
/**
* @description:
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:35
*/
private static Map<Character, Integer> getCharacterFrequency(String s) {
Map<Character, Integer> frequencyMap = new HashMap<>();
for (char c : s.toCharArray()) {
frequencyMap.put(c, frequencyMap.getOrDefault(c, 0) + 1);
}
return frequencyMap;
}
public static double cosineSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Map<Character, Integer> freq1 = getCharacterFrequency(s1);
Map<Character, Integer> freq2 = getCharacterFrequency(s2);
double dotProduct = 0.0;
double mag1 = 0.0;
double mag2 = 0.0;
for (char c : freq1.keySet()) {
if (freq2.containsKey(c)) {
dotProduct += freq1.get(c) * freq2.get(c);
}
mag1 += Math.pow(freq1.get(c), 2);
}
for (char c : freq2.keySet()) {
mag2 += Math.pow(freq2.get(c), 2);
}
mag1 = Math.sqrt(mag1);
mag2 = Math.sqrt(mag2);
return dotProduct / (mag1 * mag2);
}
/**
* @description: Dice
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:25
*/
public static double diceCoefficient(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
int intersection = 0;
for (int i = 0; i < s1.length() - 1; i++) {
String bigram = s1.substring(i, i + 2);
if (s2.contains(bigram)) {
intersection++;
}
}
int union = s1.length() + s2.length() - intersection;
return (double) (2 * intersection) / union;
}
/**
* @description: N-gram
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:22
*/
private static Set<String> generateNGrams(String s, int n) {
if (s == null || s.length() < n || n <= 0) {
throw new IllegalArgumentException("Invalid input string or n-gram size");
}
if (s.isEmpty()) {
return new HashSet<>(); // 返回空集合
}
Set<String> nGrams = new HashSet<>();
for (int i = 0; i <= s.length() - n; i++) {
nGrams.add(s.substring(i, i + n));
}
return nGrams;
}
public static double bigramSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Set<String> bigrams1 = generateNGrams(s1, 2);
Set<String> bigrams2 = generateNGrams(s2, 2);
Set<String> commonBigrams = new HashSet<>(bigrams1);
commonBigrams.retainAll(bigrams2);
Set<String> allBigrams = new HashSet<>(bigrams1);
allBigrams.addAll(bigrams2);
return (double) commonBigrams.size() / allBigrams.size();
}
/**
* @description:
* @param: gmessagedmessage
* @return: float
* @author: wuyifan
* @date: 2024/5/28 20:35
*/
@Override
public double messageScore(String gmessage, String dmessage){
double score = 0;
double similarity1 = jaccardSimilarity(gmessage, dmessage);
double similarity2 = cosineSimilarity(gmessage, dmessage);
double similarity3 = diceCoefficient(gmessage, dmessage);
double similarity4 = bigramSimilarity(gmessage, dmessage);
score = similarity1 + similarity2 + similarity3 + similarity4;
return score;
}
}

@ -0,0 +1,119 @@
package com.softegg.freetogo.GuideMatch.controller;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import com.softegg.freetogo.GuideMatch.service.GuideMatchService;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author:wuyifan
* @date:2024/5/30 10:47
*/
@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/GuideMatch")
public class GuideMatchController {
@Autowired
GuideMatchService guideMatchService;
@Autowired
UsersService usersService;
@Autowired
GuideServiceService guideServiceService;
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/5/30 20:48
*/
@GetMapping("register")
public List<Demands> GuideMatch(int gid) {
System.out.println("需匹配的gid:" + gid);
return guideMatchService.guideMatchAccount(gid);
}
/**
* @description:
* @param: map
* @return: java.lang.int
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("match")
public int Match(@RequestBody Map<String, Object> map) {
int gid = Integer.parseInt(map.get("gid").toString());
System.out.println("接收的gid:"+gid);
int did = Integer.parseInt(map.get("did").toString());
System.out.println("接收的did:"+did);
return guideMatchService.match(gid, did);
}
/**
* @description:
* @param: gid
* @return: java.lang.Demands
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@GetMapping("confirmedPage")
public List<Demands> confirmedpage(int gid) {
System.out.println("接收的gid:"+gid);
return guideMatchService.confirmedPage(gid);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("confirmed")
public int confirmed(@RequestBody Map<String, Object> map) {
int gid = Integer.parseInt(map.get("gid").toString());
System.out.println("接收的did:"+gid);
int did = Integer.parseInt(map.get("did").toString());
System.out.println("接收的did:"+did);
return guideMatchService.confirmed(gid, did);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("refuse")
public int refuse(@RequestBody Map<String, Object> map) {
int gid = (int) map.get("gid");
System.out.println("接收的gid:"+gid);
return guideMatchService.refuse(gid);
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/11 1012
*/
@PostMapping("delete")
public int delete(@RequestBody Map<String, Object> map) {
int gid = (int) map.get("gid");
System.out.println("接收的gid:"+gid);
return guideMatchService.delete(gid);
}
}

@ -0,0 +1,31 @@
package com.softegg.freetogo.GuideMatch.service;
import com.softegg.freetogo.Demand.bean.Demands;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @description:
* @author:wuyifan
* @date:2024/5/28 19:45
*/
@Service
public interface GuideMatchService {
List<Demands> guideMatchAccount(int gid);
int match(int gid, int did);
List<Demands> confirmedPage(int gid);
int confirmed(int did, int gid);
int refuse(int gid);
int delete(int gid);
double timeScore(int gsum, String gddate, String gedate, int dsum, String dddate, String dedate);
double messageScore(String gmessage, String dmessage);
}

@ -0,0 +1,397 @@
package com.softegg.freetogo.GuideMatch.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.Demand.service.DemandsService;
import com.softegg.freetogo.User.service.UsersService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import static java.lang.Math.abs;
/**
* description:
* @author:wuyifan
* date:2024/5/28 19:51
*/
@Component
public class GuideMatchServiceImpl implements GuideMatchService {
@Autowired
DemandsService demandsService;
@Autowired
UsersService usersService;
@Autowired
GuideServiceService guideServiceService;
/**
* @description:
* @param: city
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public List<Demands> guideMatchAccount(int gid){
GuideService guideService = guideServiceService.getGuideServiceById(gid);
int guideServiceSumDay = Integer.parseInt(guideService.getSumDay());
String guideServiceDepartureDate = guideService.getDepartureDate();
String guideServiceEndDate = guideService.getEndDate();
String guideServiceMessage = guideService.getMessage();
List<Demands> dlist = demandsService.getDemandsByCity(guideService.getCity());
Iterator<Demands> iterator = dlist.iterator();
while (iterator.hasNext()) {
Demands demand = iterator.next();
if (demand.getStatus() > 1) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
int length = dlist.size();
double[] sumScores = new double[length];
int i = 0;
for (Demands demands : dlist) {
double sumScore = 0;
int demandsSumDay = Integer.parseInt(demands.getSumDay());
String demandsDepartureDate = demands.getDepartureDate();
String demandsEndDate = demands.getEndDate();
String demandsMessage = demands.getMessage();
double timeScore = timeScore(guideServiceSumDay,guideServiceDepartureDate,guideServiceEndDate,demandsSumDay,demandsDepartureDate,demandsEndDate);
double messageScore = messageScore(guideServiceMessage, demandsMessage);
sumScore += timeScore + messageScore;
sumScores[i] = sumScore;
i++;
}
// 创建一个包含索引和值的列表
List<Map.Entry<Double, Demands>> list = new ArrayList<>();
for (int j = 0; j < sumScores.length; j++) {
list.add(new AbstractMap.SimpleEntry<>(sumScores[j], dlist.get(j)));
}
// 根据sumScores的元素大小对 list 进行排序
list.sort(new Comparator<Map.Entry<Double, Demands>>() {
@Override
public int compare(Map.Entry<Double, Demands> o1, Map.Entry<Double, Demands> o2) {
return o2.getKey().compareTo(o1.getKey());
}
});
List<Demands> newdList = new ArrayList<>();
for (Map.Entry<Double, Demands> entry : list) {
newdList.add(entry.getValue());
}
return newdList;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int match(int gid, int did){
Demands demand = demandsService.getDemandById(did);
GuideService guideService = guideServiceService.getGuideServiceById(gid);
demand.setStatus(1);
List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
if (guideServiceIdList == null) {
guideServiceIdList = new ArrayList<>();
}
if(!guideServiceIdList.contains(gid)){
guideServiceIdList.add(gid);
}
demand.setGuideServiceIdList(guideServiceIdList);
// List<Integer> demandIdList = guideService.getDemandIdList();
// if (demandIdList == null) {
// demandIdList = new ArrayList<>();
// }
// demandIdList.add(did);
// guideService.setDemandIdList(demandIdList);
demandsService.update(demand);
guideServiceService.update(guideService);
System.out.println(demand.getGuideServiceIdList());
return 1006;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public List<Demands> confirmedPage(int gid){
GuideService guideService = guideServiceService.getGuideServiceById(gid);
List<Integer> demandIdList = guideService.getDemandIdList();
List<Demands> demandsList = new ArrayList<>();
for(int number : demandIdList) {
Demands demand = demandsService.getDemandById(number);
demandsList.add(demand);
}
return demandsList;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int confirmed(int gid, int did){
Demands demand = demandsService.getDemandById(did);
GuideService guideService = guideServiceService.getGuideServiceById(gid);
demand.setStatus(2);
demand.setGuideServiceId(gid);
guideService.setStatus(2);
guideService.setDemandId(did);
demandsService.update(demand);
guideServiceService.update(guideService);
return 1007;
}
/**
* @description:
* @param: did,gid
* @return: int
* author: wuyifan
* @date: 2024/5/28 19:52
*/
@Override
public int refuse(int gid){
GuideService guideService = guideServiceService.getGuideServiceById(gid);
int did = guideService.getDemandId();
Demands demand = demandsService.getDemandById(gid);
List<Integer> demandIdList = guideService.getDemandIdList();
if (demandIdList == null) {
guideService.setStatus(0);
}else {
guideService.setStatus(1);
}
List<Integer> guideServiceIdList = demand.getGuideServiceIdList();
if(guideServiceIdList == null){
demand.setStatus(0);
}else {
demand.setStatus(1);
}
guideService.setDemandId(null);
demand.setGuideServiceId(null);
demandsService.update(demand);
guideServiceService.update(guideService);
return 1;
}
@Override
public int delete(int gid){
GuideService guideService = guideServiceService.getGuideServiceById(gid);
guideService.setStatus(4);
guideServiceService.update(guideService);
return 1;
}
public static boolean isRangeWithinRange(LocalDate startDate1, LocalDate endDate1, LocalDate startDate2, LocalDate endDate2) {
return !startDate1.isBefore(startDate2) && !endDate1.isAfter(endDate2);
}
/**
* @description:
* @param: gsumdsumddateedate
* @return: float
* @author: wuyifan
* @date: 2024/5/28 20:35
*/
@Override
public double timeScore(int gsum, String gddate, String gedate, int dsum, String dddate, String dedate){
double score = 0;
int difference = gsum - dsum;
if (abs(difference) < 15 ){
score += 10 / (float)(abs(difference) + 1);
}
// 使用DateTimeFormatter将字符串转换为LocalDate对象
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate1 = LocalDate.parse(dddate, formatter);
LocalDate endDate1 = LocalDate.parse(dedate, formatter);
System.out.println(startDate1);
System.out.println(endDate1);
LocalDate startDate2 = LocalDate.parse(gddate, formatter);
LocalDate endDate2 = LocalDate.parse(gedate, formatter);
System.out.println(startDate2);
System.out.println(endDate2);
// 判断第一个范围是否在第二个范围内
boolean isRange1WithinRange2 = isRangeWithinRange(startDate1, endDate1, startDate2, endDate2);
if (isRange1WithinRange2){
score += 100;
}
return score;
}
/**
* @description: Jaccard
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:35
*/
public static double jaccardSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Set<Character> set1 = new HashSet<>();
Set<Character> set2 = new HashSet<>();
for (char c : s1.toCharArray()) {
set1.add(c);
}
for (char c : s2.toCharArray()) {
set2.add(c);
}
Set<Character> intersection = new HashSet<>(set1);
intersection.retainAll(set2);
Set<Character> union = new HashSet<>(set1);
union.addAll(set2);
return (double) intersection.size() / union.size();
}
/**
* @description:
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:35
*/
private static Map<Character, Integer> getCharacterFrequency(String s) {
Map<Character, Integer> frequencyMap = new HashMap<>();
for (char c : s.toCharArray()) {
frequencyMap.put(c, frequencyMap.getOrDefault(c, 0) + 1);
}
return frequencyMap;
}
public static double cosineSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Map<Character, Integer> freq1 = getCharacterFrequency(s1);
Map<Character, Integer> freq2 = getCharacterFrequency(s2);
double dotProduct = 0.0;
double mag1 = 0.0;
double mag2 = 0.0;
for (char c : freq1.keySet()) {
if (freq2.containsKey(c)) {
dotProduct += freq1.get(c) * freq2.get(c);
}
mag1 += Math.pow(freq1.get(c), 2);
}
for (char c : freq2.keySet()) {
mag2 += Math.pow(freq2.get(c), 2);
}
mag1 = Math.sqrt(mag1);
mag2 = Math.sqrt(mag2);
return dotProduct / (mag1 * mag2);
}
/**
* @description: Dice
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:25
*/
public static double diceCoefficient(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
int intersection = 0;
for (int i = 0; i < s1.length() - 1; i++) {
String bigram = s1.substring(i, i + 2);
if (s2.contains(bigram)) {
intersection++;
}
}
int union = s1.length() + s2.length() - intersection;
return (double) (2 * intersection) / union;
}
/**
* @description: N-gram
* @param: String
* @return: float
* @author: wuyifan
* @date: 2024/5/30 20:22
*/
private static Set<String> generateNGrams(String s, int n) {
if (s == null || s.length() < n || n <= 0) {
throw new IllegalArgumentException("Invalid input string or n-gram size");
}
if (s.isEmpty()) {
return new HashSet<>(); // 返回空集合
}
Set<String> nGrams = new HashSet<>();
for (int i = 0; i <= s.length() - n; i++) {
nGrams.add(s.substring(i, i + n));
}
return nGrams;
}
public static double bigramSimilarity(String s1, String s2) {
if (s1 == null || s2 == null || s1.isEmpty() || s2.isEmpty()) {
return 0.0; // 如果任何一个字符串为空直接返回0
}
Set<String> bigrams1 = generateNGrams(s1, 2);
Set<String> bigrams2 = generateNGrams(s2, 2);
Set<String> commonBigrams = new HashSet<>(bigrams1);
commonBigrams.retainAll(bigrams2);
Set<String> allBigrams = new HashSet<>(bigrams1);
allBigrams.addAll(bigrams2);
return (double) commonBigrams.size() / allBigrams.size();
}
/**
* @description:
* @param: gmessagedmessage
* @return: float
* @author: wuyifan
* @date: 2024/5/28 20:35
*/
@Override
public double messageScore(String gmessage, String dmessage){
double score = 0;
double similarity1 = jaccardSimilarity(gmessage, dmessage);
double similarity2 = cosineSimilarity(gmessage, dmessage);
double similarity3 = diceCoefficient(gmessage, dmessage);
double similarity4 = bigramSimilarity(gmessage, dmessage);
score = similarity1 + similarity2 + similarity3 + similarity4;
return score;
}
}

@ -0,0 +1,20 @@
package com.softegg.freetogo.GuideService.Dao;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.bean.GuideService;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* @description:Jpa
* @author:wuyifan
* @date:2024/5/13 9:17
*/
public interface GuideServiceRepository extends JpaRepository<GuideService, Integer> {
List<GuideService> findByPhone(String phone);
List<GuideService> findByCity(String city);
List<GuideService> findByProvince(String province);
}

@ -0,0 +1,53 @@
package com.softegg.freetogo.GuideService.bean;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
/**
* @description:guideService
* @author:wuyifan
* @date:2024/5/13 9:14
*/
@Entity
@Table(name = "guideService")
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class GuideService {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer gid;
@Column
private String phone;//导游手机号码
@Column(name = "guide_gender")
private boolean guideGender;//导游性别 ture:male, false:female
@Column
private String nickname;//发布需求的导游昵称信息
@Column(name = "create_time")
private String createTime;//服务发布时间
@Column(name = "departure_date")
private String departureDate;//导游服务起始日期
@Column(name = "end_date")
private String endDate;//导游服务结束日期
@Column(name = "sum_day")
private String sumDay;//导游服务总天数
@Column
private String province;//导游服务的目的省份
@Column
private String city;//导游服务的目的城市
@Column
private String message;//导游服务备注内容
@Column
private Integer status;//导游服务状态 0未匹配 1请求匹配 2已完成匹配 3已完成所有服务
@Column
private Integer demandId;//导游服务最终匹配到的游客需求id
@ElementCollection
@Column
private List<Integer> demandIdList;//游客需求申请匹配到的导游服务id
}

@ -0,0 +1,103 @@
package com.softegg.freetogo.GuideService.controller;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:Guide
* @author:wuyifan
* @date:2024/5/13 9:26
*/
@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/guideService")
public class GuideServiceController {
@Autowired
private GuideServiceService guideServiceService;
@GetMapping("findAll")
public List<GuideService> findAll() {
return guideServiceService.findAll();
}
@GetMapping("add")
public String add(String phone,
boolean gGender,
String nkn,
String ct,
String dDate,
String eDate,
String sDay,
String procvince,
String city,
String message,
Integer status,
Integer demandId,
List<Integer> demandIdList) {
GuideService guideService = new GuideService();
setDemands(phone, gGender, nkn, ct, dDate, eDate, sDay, procvince, city, message, status, guideService, demandId, demandIdList);
guideServiceService.add(guideService);
return "添加成功";
}
@PostMapping("delbyid")
public String delById(@RequestBody Map<String, Object> map) {
int gid = (int) map.get("gid");
guideServiceService.deleteById(gid);
return "1";
}
@GetMapping("findbyid")
public GuideService getUserById(int gid) {
return guideServiceService.getGuideServiceById(gid);
}
@GetMapping("getByPhone")
public List<GuideService> getByPhone(String phone) {
System.out.println("根据手机号获取游客需求信息:" + phone);
return guideServiceService.getGuideServiceByPhone(phone);
}
@GetMapping("update")
public String update(int id,
String phone,
boolean gGender,
String nkn,
String ct,
String dDate,
String eDate,
String sDay,
String province,
String city,
String message,
Integer status,
Integer demandId,
List<Integer> demandIdList) {
GuideService guideService = guideServiceService.getGuideServiceById(id);
setDemands(phone, gGender, nkn, ct, dDate, eDate, sDay, province, city, message, status, guideService, demandId, demandIdList);
guideServiceService.update(guideService);
return "更新成功";
}
private void setDemands(String phone, boolean gGender, String nkn, String ct, String dDate, String eDate, String sDay, String province, String city, String message, Integer status, GuideService guideservice, Integer demandId, List<Integer> demandIdList) {
guideservice.setPhone(phone);
guideservice.setGuideGender(gGender);
guideservice.setNickname(nkn);
guideservice.setCreateTime(ct);
guideservice.setDepartureDate(dDate);
guideservice.setEndDate(eDate);
guideservice.setSumDay(sDay);
guideservice.setProvince(province);
guideservice.setCity(city);
guideservice.setMessage(message);
guideservice.setStatus(status);
guideservice.setDemandId(demandId);
guideservice.setDemandIdList(demandIdList);
}
}

@ -0,0 +1,28 @@
package com.softegg.freetogo.GuideService.service;
import com.softegg.freetogo.GuideService.bean.GuideService;
import java.util.List;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 2059
*/
public interface GuideServiceService {
List<GuideService> findAll();//查找所有需求
void add(GuideService guideService);//以demand为用户入库
void deleteById(int id);//删除对应id需求
GuideService getGuideServiceById(int id);//获得对应id需求
void update(GuideService guideService);//更新需求信息
List<GuideService> getGuideServiceByPhone(String phone);//获得对应手机号的导游用户的所有服务
List<GuideService> getGuideServiceByCity(String city);//根据所选城市获得导游服务列表
List<GuideService> getGuideServiceByProvince(String province);//根据所选城市获得导游服务列表
}

@ -0,0 +1,128 @@
package com.softegg.freetogo.GuideService.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.GuideService.Dao.GuideServiceRepository;
import com.softegg.freetogo.GuideService.bean.GuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Iterator;
import java.util.List;
/**
* @description:
* @author:wuyifan
* @date:2024/5/13 9:19
*/
@Component
public class GuideServiceServiceImpl implements GuideServiceService {
@Autowired
private GuideServiceRepository GuideServiceRepository;
@Autowired
private GuideServiceRepository guideServiceRepository;
/**
* @description:
* @param: null
* @return: java.util.List<com.softegg.freetogo.GuideService.Bean.GuideService>
* @author: wuyifan
* @date: 2024/5/13 9:21
*/
public List<GuideService> findAll() {
System.out.println("查询成功");
return GuideServiceRepository.findAll();
}
/**
* @description: guideService
* @param: guideService
* @return: void
* @author: wuyifan
* @date: 2024/5/13 922
*/
public void add(GuideService guideService) {
GuideServiceRepository.save(guideService);
System.out.println("添加成功");
}
/**
* @description: id
* @param: id
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/10 20:02
*/
public GuideService getGuideServiceById(int id) {
return GuideServiceRepository.findById(id).orElse(null);
}
/**
* @description: gid
* @param: id
* @return: void
* @author: zhanglinhao
* @date: 2024/5/9 22:53
*/
public void deleteById(int gid) {
guideServiceRepository.deleteById(gid);
System.out.println("删除成功:" + gid);
}
/**
* @description:
* @param: guideService
* @return: void
* @author: wuyifan
* @date: 2024/5/10 20:05
*/
public void update(GuideService guideService) {
GuideServiceRepository.save(guideService);
System.out.println("服务更新成功");
}
/**
* @description:
* @param: phone
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/16 15:18
*/
public List<GuideService> getGuideServiceByPhone(String phone) {
List<GuideService> guideServiceList = GuideServiceRepository.findByPhone(phone);
Iterator<GuideService> iterator = guideServiceList.iterator();
while (iterator.hasNext()) {
GuideService guideService = iterator.next();
if (guideService.getStatus() == 4) {
iterator.remove(); // 使用迭代器的 remove 方法
}
}
return guideServiceList;
}
/**
* @description:
* @param: city
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/16 15:30
*/
public List<GuideService> getGuideServiceByCity(String city) {
return GuideServiceRepository.findByCity(city);
}
/**
* @description:
* @param: city
* @return: com.softegg.freetogo.GuideService.Bean.GuideService
* @author: wuyifan
* @date: 2024/5/16 15:30
*/
public List<GuideService> getGuideServiceByProvince(String province) {
return GuideServiceRepository.findByProvince(province);
}
}

@ -0,0 +1,4 @@
package com.softegg.freetogo.HeatMap.controller;
public class HeatMapController {
}

@ -0,0 +1,11 @@
package com.softegg.freetogo.HeatMap.service;
public interface HeatMapService {
int[] provinceDemandsHeatMap();//获得每个省份的游客需求数目
int[] cityDemandsHeatMap(String province);//获得目标省份的游客需求数目
int[] provinceGuideServiceHeatMap();
int[] cityGuideServiceHeatMap(String province);
}

@ -0,0 +1,192 @@
package com.softegg.freetogo.HeatMap.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.Demand.service.DemandsService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import com.softegg.freetogo.GuideService.bean.GuideService;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* description:
* @author:wuyifan
* date:2024/6/6 10:51
*/
@Component
public class HeatMapServiceImpl implements HeatMapService {
@Autowired
DemandsService demandsService;
@Autowired
GuideServiceService guideServiceService;
public static void main(String[] args) {
List<String> provinceList = new ArrayList<>();
JSONParser parser = new JSONParser();
try {
// 读取 JSON 文件内容并解析为 JSONObject
Object obj = parser.parse(new FileReader("C:/Users/WYF/Desktop/软件体系结构/FreeToGo/src/main/java/com/softegg/freetogo/HeatMap/service/area.json")); // 直接使用文件名表示相对路径
JSONObject jsonObject = (JSONObject) obj;
for (Object province : jsonObject.keySet()) {
provinceList.add(province.toString());
}
System.out.println("所有省份列表:");
for (String province : provinceList) {
System.out.println(province);
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
/**
* @description: List
* @param: null
* @return: List<String>
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
public List<String> getAllProvinces() {
List<String> provinceList = new ArrayList<>();
JSONParser parser = new JSONParser();
try {
// 读取 JSON 文件内容并解析为 JSONObject
Object obj = parser.parse(new FileReader("C:/Users/WYF/Desktop/软件体系结构/FreeToGo/src/main/java/com/softegg/freetogo/HeatMap/service/area.json"));
JSONObject jsonObject = (JSONObject) obj;
// 遍历每个省份
for (Object province : jsonObject.keySet()) {
// 将省份添加到列表中
provinceList.add(province.toString());
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
return provinceList;
}
/**
* @description: List
* @param: String
* @return: List<String>
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
public List<String> getCitiesInProvince(String province) {
List<String> cityList = new ArrayList<>();
JSONParser parser = new JSONParser();
try {
// 读取 JSON 文件内容并解析为 JSONObject
Object obj = parser.parse(new FileReader("C:/Users/WYF/Desktop/软件体系结构/FreeToGo/src/main/java/com/softegg/freetogo/HeatMap/service/area.json"));
JSONObject jsonObject = (JSONObject) obj;
// 获取湖南省的城市信息
JSONObject hunanCities = (JSONObject) jsonObject.get(province);
// 遍历每个城市并将城市名称添加到列表中
for (Object city : hunanCities.keySet()) {
cityList.add(city.toString());
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
return cityList;
}
/**
* @description:
* @param: null
* @return: int[]
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
@Override
public int[] provinceDemandsHeatMap(){
List<String> provinceList = getAllProvinces();
int[] sum = new int[provinceList.size()];
int i = 0;
for (String province : provinceList) {
List<Demands> demandsList = demandsService.getDemandsByProvince(province);
sum[i] = demandsList.size();
i++;
}
return sum;
}
/**
* @description:
* @param: String
* @return: int[]
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
@Override
public int[] cityDemandsHeatMap(String province){
List<String> cityList = getCitiesInProvince(province);
int[] sum = new int[cityList.size()];
int i = 0;
for (String city : cityList) {
List<Demands> demandsList = demandsService.getDemandsByCity(city);
sum[i] = demandsList.size();
i++;
}
return sum;
}
/**
* @description:
* @param: null
* @return: int[]
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
@Override
public int[] provinceGuideServiceHeatMap(){
List<String> provinceList = getAllProvinces();
int[] sum = new int[provinceList.size()];
int i = 0;
for (String province : provinceList) {
List<GuideService> guideServiceList = guideServiceService.getGuideServiceByProvince(province);
sum[i] = guideServiceList.size();
i++;
}
return sum;
}
/**
* @description:
* @param: String
* @return: int[]
* @author: wuyifan
* @date: 2024/6/6 15:48
*/
@Override
public int[] cityGuideServiceHeatMap(String province){
List<String> cityList = getCitiesInProvince(province);
int[] sum = new int[cityList.size()];
int i = 0;
for (String city : cityList) {
List<GuideService> guideServiceList = guideServiceService.getGuideServiceByCity(city);
sum[i] = guideServiceList.size();
i++;
}
return sum;
}
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,72 @@
package com.softegg.freetogo.SendDemand.controller;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.Demand.service.DemandsService;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.SendDemand.service.SendDemandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 23:09
*/
@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/SendDemand")
public class SendDemandController {
@Autowired
SendDemandService sendDemandService;
@Autowired
DemandsService demandsService;
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/5/10 22:45
*/
@PostMapping("register")
public String SendDemand(@RequestBody Map<String, Object> map) {
return switch (sendDemandService.sendnewDemandAccount(map.get("city").toString(), map.get("phone").toString(), map.get("time").toString(), (String) map.get("remark"))) {
case 1005 -> "1";//需求发送成功
default -> "0";
};
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/5/16 11:01
*/
@GetMapping("sendAllDemands")
public List<Demands> sendAllDemand(String phone) {
System.out.println("收到目标用户手机号:" + phone);
List<Demands> dlist = demandsService.getDemandsByPhone(phone);
System.out.println(dlist);
return dlist;
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/4 16:12
*/
@GetMapping("demand")
public Demands demand(int did) {
System.out.println("需求did:"+did);
return demandsService.getDemandById(did);
}
}

@ -0,0 +1,13 @@
package com.softegg.freetogo.SendDemand.service;
import org.springframework.stereotype.Service;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 23:31
*/
@Service
public interface SendDemandService {
int sendnewDemandAccount(String city, String phone, String date, String message);
}

@ -0,0 +1,70 @@
package com.softegg.freetogo.SendDemand.service;
import com.softegg.freetogo.Demand.bean.Demands;
import com.softegg.freetogo.Demand.service.DemandsService;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
/**
* @description:
* @author:wuyifan
* @date:2024/5/10 23:10
*/
@Component
public class SendDemandServiceImpl implements SendDemandService {
@Autowired
DemandsService demandsService;
@Autowired
UsersService usersService;
/**
* @description:
* @param: city
* @return: int
* @author: wuyifan
* @date: 2024/5/10 23:25
*/
@Override
public int sendnewDemandAccount(String city, String phone, String date, String message) {
LocalDateTime currentDateTime = LocalDateTime.now();
//对获取的date信息进行处理
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = currentDateTime.format(formatter1);
date = date.replace("[", "");
date = date.replace("]", "");
String[] parts = date.split(",");
String dDate = parts[0];
String eDate = parts[1];
//获取整个导游服务的总天数
eDate = eDate.trim();
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(dDate, formatter2);
LocalDate endDate = LocalDate.parse(eDate, formatter2);
String departureTime = startDate.format(formatter2);
String endTime = endDate.format(formatter2);
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1;
//根据收到的消息,初始化游客需求内容
Demands demand = new Demands();
Users user = usersService.getUserByPhone(phone);
demand.setPhone(phone);
demand.setCity(city);
demand.setTouristGender(user.isGender());
demand.setNickname(user.getNickname());
demand.setCreateTime(formattedDateTime);
demand.setDepartureDate(departureTime);
demand.setEndDate(endTime);
demand.setSumDay(String.valueOf(daysBetween));
demand.setMessage(message);
demand.setStatus(0);
demandsService.add(demand);
return 1005;//添加游客需求成功
}
}

@ -0,0 +1,76 @@
package com.softegg.freetogo.SendGuideService.controller;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import com.softegg.freetogo.SendGuideService.service.SendGuideServiceService;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author:wuyifan
* @date:2024/5/13 10:47
*/
@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/SendGuideService")
public class SendGuideServiceController {
@Autowired
SendGuideServiceService sendGuideServiceService;
@Autowired
UsersService usersService;
@Autowired
GuideServiceService guideServiceService;
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/5/13 10:48
*/
@PostMapping("register")
public int SendDemand(@RequestBody Map<String, Object> map) {
String phone = map.get("phone").toString();
Users user = usersService.getUserByPhone(phone);
if (user.isMembertype()) {
return switch (sendGuideServiceService.sendnewGuideServiceAccount(map.get("city").toString(), map.get("phone").toString(), map.get("time").toString(), (String) map.get("remark"))) {
case 1005 -> 1;//服务发送成功
default -> 0;
};
} else {
return 2;//用户非导游
}
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/5/16 11:01
*/
@GetMapping("sendAllGuideService")
public List<GuideService> sendAllGuideService(String phone) {
List<GuideService> glist = guideServiceService.getGuideServiceByPhone(phone);
return glist;
}
/**
* @description:
* @param: map
* @return: java.lang.String
* @author: wuyifan
* @date: 2024/6/4 16:10
*/
@GetMapping("GuideService")
public GuideService GuideService(int gid) {
return guideServiceService.getGuideServiceById(gid);
}
}

@ -0,0 +1,14 @@
package com.softegg.freetogo.SendGuideService.service;
import org.springframework.stereotype.Service;
/**
* @description:
* @author:wuyifan
* @date:2024/5/13 11:11
*/
@Service
public interface SendGuideServiceService {
int sendnewGuideServiceAccount(String city, String phone, String date, String message);
}

@ -0,0 +1,76 @@
package com.softegg.freetogo.SendGuideService.service;
import com.softegg.freetogo.GuideService.bean.GuideService;
import com.softegg.freetogo.GuideService.service.GuideServiceService;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
/**
* @description:
* @author:wuyifan
* @date:2024/5/13 10:53
*/
@Component
public class SendGuideServiceServiceImpl implements SendGuideServiceService {
@Autowired
GuideServiceService guideServiceService;
@Autowired
UsersService usersService;
/**
* @description:
* @param: city
* @return: int
* @author: wuyifan
* @date: 2024/5/10 23:25
*/
@Override
public int sendnewGuideServiceAccount(String city, String phone, String date, String message) {
LocalDateTime currentDateTime = LocalDateTime.now();
//对获取的date信息进行处理
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = currentDateTime.format(formatter1);
date = date.replace("[", "");
date = date.replace("]", "");
String[] parts = date.split(",");
String dDate = parts[0];
String eDate = parts[1];
//获取整个导游服务的总天数
System.out.println(dDate);
System.out.println(eDate);
dDate = dDate.trim();
eDate = eDate.trim();
dDate = dDate.substring(0, 10);
eDate = eDate.substring(0, 10);
System.out.println(dDate);
System.out.println(eDate);
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(dDate, formatter2);
LocalDate endDate = LocalDate.parse(eDate, formatter2);
String departureTime = startDate.format(formatter2);
String endTime = endDate.format(formatter2);
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1;
//根据收到的消息,初始化导游服务内容
GuideService guideService = new GuideService();
Users user = usersService.getUserByPhone(phone);
guideService.setPhone(phone);
guideService.setCity(city);
guideService.setGuideGender(user.isGender());
guideService.setNickname(user.getNickname());
guideService.setCreateTime(formattedDateTime);
guideService.setDepartureDate(departureTime);
guideService.setEndDate(endTime);
guideService.setSumDay(String.valueOf(daysBetween));
guideService.setMessage(message);
guideService.setStatus(0);
guideServiceService.add(guideService);
return 1006;//添加导游服务成功
}
}
Loading…
Cancel
Save