yulongyan_citu před 1 rokem
rodič
revize
32c21301dc

+ 14 - 11
Dockerfile

@@ -1,20 +1,23 @@
-# 使用官方Python基础镜像
-FROM python:3.7-slim
+# 第一阶段:从国内镜像源拉取基础镜像
+FROM docker.m.daocloud.io/library/python:3.7 AS base
+
+# 第二阶段:实际构建
+FROM base
 
 # 设置工作目录
-WORKDIR /usr/src/app
+WORKDIR /opt/mendunr
 
-# 将项目的依赖文件复制到工作目录
-COPY /opt/mendunr_project/requirements.txt ./
+# 设置pip的最大工作线程数
+ENV PIP_MAX_WORKERS=1
 
-# 安装依赖
-RUN pip install --no-cache-dir -r requirements.txt
+# 将项目的依赖文件复制到工作目录
+COPY requirements.txt .
 
-# 将Python脚本复制到容器中
-COPY /opt/mendunr_project ./
+# 升级pip并安装依赖,使用阿里云的镜像源
+RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
 
-# 暴露应用的端口
-EXPOSE 3333
+# 将项目代码复制到工作目录
+COPY . .
 
 # 运行Python应用
 CMD ["python", "app.py"]

+ 29 - 62
configs/nacos_config.py

@@ -1,56 +1,3 @@
-# import json
-# import threading
-#
-# from flask import Flask
-# from  nacos import NacosClient
-#
-# app = Flask(__name__)
-#
-# class nacos:
-#     def __init__(self,address,namespace,username,password,data_id,group):
-#         self.SERVER_ADDRESSES = address
-#         self.NAMESPACE = namespace
-#         self.USERNAME = username
-#         self.PASSWORD = password
-#         self.client = NacosClient(server_addresses=self.SERVER_ADDRESSES, namespace=self.NAMESPACE)
-#         self.data_id = data_id
-#         self.group = group
-#     def load_config(self):
-#         """从Nacos加载配置并更新应用状态"""
-#         config_data = self.client.get_config(data_id=self.data_id, group=self.group)
-#         app.config['CONFIG_DATA'] = config_data
-#         print(config_data)
-#         return json.loads(config_data)
-#
-#     def on_config_change(self,cfg):
-#         """当Nacos中的配置发生变化时,更新应用配置中的配置数据"""
-#         config_data = json.loads(cfg['content'])  # Parse the JSON string to a dictionary
-#         app.config['CONFIG_DATA'] = config_data
-#         return config_data
-#
-#     def watch_config_changes(self):
-#         try:
-#             self.client.add_config_watcher(data_id='python-mendunr', group='DEFAULT_GROUP', cb=self.on_config_change)
-#             self.client.add_naming_instance(service_name='python-mendunr',
-#                                        ip='192.168.3.175',
-#                                        port=3333,
-#                                        group_name='DEFAULT_GROUP',
-#                                        ephemeral=False)
-#         except Exception as e:
-#             raise e
-#
-#
-#     # def start_background_tasks(self):
-#     #     """启动后台任务线程来监控配置变化"""
-#     #     t = threading.Thread(target=self.watch_config_changes)
-#     #     t.daemon = True
-#     #     t.start()
-#     #     # self.watch_config_changes()
-#
-# nacos_single = nacos(address="192.168.3.80:8848",namespace = "dev",username = 'nacos',
-#                      password ='nacos',data_id = 'python-mendunr',group = 'DEFAULT_GROUP')
-# nacos_single.watch_config_changes()
-# configs = nacos_single.load_config()
 
 import json
 from flask import Flask, request
@@ -58,17 +5,37 @@ from nacos import NacosClient
 
 app = Flask(__name__)
 
+config_json = {
+    "local": {
+        "address": "192.168.3.80:8848",
+        "namespace": "dev",
+        "username": "nacos",
+        "password": "nacos",
+        "data_id": "python-mendunr",
+        "group": "DEFAULT_GROUP"
+    },
+    "production": {
+        "address": "localhost:8848",
+        "namespace": "dev",
+        "username": "nacos",
+        "password": "nacos",
+        "data_id": "python-mendunr",
+        "group": "DEFAULT_GROUP"
+    }
+}
+
 
 class NacosConfig:
-    def __init__(self, address, namespace, username, password, data_id, group):
-        self.SERVER_ADDRESSES = address
-        self.NAMESPACE = namespace
-        self.USERNAME = username
-        self.PASSWORD = password
+    def __init__(self, environment='local'):
+        env_config = config_json[environment]
+        self.SERVER_ADDRESSES = env_config['address']
+        self.NAMESPACE = env_config['namespace']
+        self.USERNAME = env_config['username']
+        self.PASSWORD = env_config['password']
+        self.data_id = env_config['data_id']
+        self.group = env_config['group']
         self.client = NacosClient(server_addresses=self.SERVER_ADDRESSES, namespace=self.NAMESPACE,
                                   username=self.USERNAME, password=self.PASSWORD)
-        self.data_id = data_id
-        self.group = group
         self.config_data = None
 
     def load_config(self):
@@ -84,8 +51,8 @@ class NacosConfig:
         return self.config_data
 
 
-nacos_config = NacosConfig(address="192.168.3.80:8848", namespace="dev", username='nacos', password='nacos',
-                           data_id='python-mendunr', group='DEFAULT_GROUP')
+# 使用配置文件中的生产环境配置 (本地是local,提交代码是production)!!
+nacos_config = NacosConfig(environment='production')
 configs = nacos_config.get_config()
 
 

+ 1 - 1
functions/operate_graph.py

@@ -92,7 +92,7 @@ def delete_old_jobs(dataList):
         current_app.logger.error(f'delete_old_jobs error: {e}')
 
 # 企业
-def operate_enterprise(operate,dataList):
+def operate_enterprise(operate, dataList):
     try:
         if operate == 'sync_all':
             sync_all_enterprise(dataList)

+ 5 - 3
functions/similarity_judge.py

@@ -123,7 +123,8 @@ def home_job(uniqueid,start,end):
             """
             result = connect_graph.run(query,Id = uniqueid).evaluate()
             if result:
-                return result
+                need_list = default_job()
+                return result + need_list[:10-len(result)]
             else:
                 return default_job()
         else:
@@ -200,14 +201,15 @@ def home_person(uniqueid,start,end):
             WITH j, jl, sl
             MATCH (s:seeker)-[:connection]->(sl)
             // 7. 返回 seeker 的 id 和总数
-            WITH j, s.uniqueId AS seekerId
+            WITH j, toString(s.uniqueId) AS seekerId
             //WITH count(DISTINCT seekerId) AS total, collect(DISTINCT seekerId) AS seekerIds
             with collect(DISTINCT seekerId) AS seekerIds
             RETURN seekerIds[{start}..{end}] AS seekerIds
             """
             result = connect_graph.run(query,Id = uniqueid).evaluate()
             if result:
-                return result
+                need_list = default_job()
+                return result + need_list[:10 - len(result)]
             else:
                 return default_person()
         else:

+ 26 - 1
interfaces/rocketmq.py

@@ -3,11 +3,36 @@ from configs.result import success
 from functions.label_number import job_label, enterprise_label, seeker_label
 from functions.operate_graph import operate_job, operate_enterprise, operate_seeker
 import logging
-from functions.similarity_judge import similar_job, similar_seeker, draw_graph, home_job, home_person
+from functions.similarity_judge import similar_job, similar_seeker, draw_graph, home_job, home_person, draw_person_graph
 from functions.solve_graph import llm_client
+from configs.connections import connect_graph
 logger = logging.getLogger(__name__)
 rocket = Blueprint('rocket', __name__)
 
+@rocket.route('/delete/data', methods=['POST'])
+def delete_data():
+    try:
+        receiver = request.get_json()
+        type = receiver.get('type')  # job, enterprise, person
+
+        if type == 'job':
+            connect_graph.run('match (n:job) detach delete n')
+            connect_graph.run('match (n:jobLabel) detach delete n')
+        elif type == 'enterprise':
+            connect_graph.run('match (n:enterprise) detach delete n')
+            connect_graph.run('match (n:enterpriseLabel) detach delete n')
+        elif type == 'person':
+            connect_graph.run('match (n:seeker) detach delete n')
+            connect_graph.run('match (n:seekerLabel) detach delete n')
+        else:
+            current_app.logger.error('delete_data Invalid type')
+            return jsonify(success(True, "success"))  # 返回成功响应
+
+    except Exception as e:
+        current_app.logger.error(f'delete_data error: {e}')
+        return jsonify(success(True, "success"))
+
+
 
 @rocket.route('/receive/data', methods=['POST'])
 def receive_data():