同步操作将从 TDTXYZHH/HarmonyOS应用开发项目集合 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
@[toc](HarmonyOS应用开发--社区型APP文化乡道[V2.1.0版][API V6])
APP客户端具备:
【1】APP客户端: 采用JAVA UI开发模式,使用单个MainAbility,该MainAbility包含14个AbilitySlice。 其中,在MainAbilitySlice中采用的上、中、下三段式页面结构。上、中可以使用XML动态装载技术,根据下部的TabLiist导航tab不同,去装载不同的上、中子布局。 在APP客户端中,只涉及用户个人注册信息的存储,使用鸿蒙API给出的基于XML的轻量偏好型键值对数据库去存储。 【2】服务器端: 采用python django 3.2,使用MVT模式中的V,在views.py中直接导入pymysql模块,直接拼接字符串,去执行SQL语句即可,总共设计了24个网络接口,在后续章节给出。 数据库方面,采用Mysql 8,特别的,需要使用其json数据存储类型。
【用户指令处理】
(1)登录指令
(2)注册指令
(3)销毁指令
(4)全站动态请求指令
(5)全站项目请求指令
(6)全站文章请求指令
(7)全站领域请求指令
(8)内容阅读指令
(9)点赞指令
(10)取消点赞指令
(11)收藏指令
(12)取消收藏指令
(13)评论指令
(14)关注指令
(15) 取消关注指令
(16)用户内容发布指令
(17)用户内容删除指令
(18)请求用户消息列表指令
(19)请求用户内容列表指令
(20)请求内容评论列表指令
(21)请求用户关注数量、粉丝数量、阅读数量指令
(22)搜索用户指令
(23)请求关注列表指令
(24)请求粉丝列表指令
(1)用户(用户账号,密码,邮箱,年龄,性别),
主码:用户账号;
(2)点赞(点赞编号,点赞时间,内容编号,用户账号),
主码:点赞编号,外码:内容编号、用户账号;
(3)领域(领域编号、领域名称),主码:领域编号。
(4)用户内容(内容编号,内容类别,发表日期,内容详情,阅读量,用户账号,领域编号),
主码:内容编号,外码:用户账号、领域编号;
(5)评论(评论编号,评论详情,评论时间,内容编号,用户账号),
主码:评论编号,外码:内容编号、用户账号;
(6)收藏(收藏编号,收藏时间,内容编号,用户账号),
主码:收藏编号,外码:内容编号、用户账号。
在MySql 8环境中,设计数据库表如下:
APP客户端:登录流程图
服务器端:登录流程图
APP客户端:内容发布流程图
服务器端:关注指令处理
package com.tdtxdcxm.ruralcommunity.appruntime;
import com.tdtxdcxm.ruralcommunity.ResourceTable;
import com.tdtxdcxm.ruralcommunity.items.LCArryListContentItem;
import com.tdtxdcxm.ruralcommunity.items.LCArryListNormalItem;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForContent;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForNormal;
import com.tdtxdcxm.ruralcommunity.providers.PSProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.webengine.WebView;
import java.util.ArrayList;
public class DataCenterControl {
//这里是数据指挥中心,程序内软数据总线
private DataCenterControl(){}
public static String messageNoticeUrlString = "https://www.gitee.com/";//消息——通知所加载的html网页地址
public static String serverIpWithPort = "http:127.0.0.1:8000/";//服务器地址,写上自己服务器的公网IP+端口号
public static WebView webView = null;
public static String userName = "";
public static String age = "";
public static String gender = "";
public static String followsum = "";
public static String fanssum = "";
public static String readvalue = "";
public static final String[] fields = {"艺","衣","食","住","行","学","文"};
//首页-中间区域-pageslider每一页的子布局数据源列表
public static final ArrayList<DirectionalLayout> firstcenter_pageslist = new ArrayList<>();
//领域-中间区域-pageslider每一页的子布局数据源列表
public static final ArrayList<DirectionalLayout> secondcenter_pageslist = new ArrayList<>();
//消息-中间区域-pageslider每一页的子布局数据源列表
public static final ArrayList<DirectionalLayout> fourthcenter_pageslist = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> worlddt_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> worldxm_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> worldwz_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> art_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> clothe_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> food_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> house_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> traffic_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> study_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> culture_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> messageagree_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> messagediscuss_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> messagecollect_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> follow_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> fans_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> discuss_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListNormalItem> people_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> userdt_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> userxm_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> userwz_listcontainer_list = new ArrayList<>();
public static final ArrayList<LCArryListContentItem> usercollect_listcontainer_list = new ArrayList<>();
public static LCProviderForContent worldDtListContainerProvider = null;
public static LCProviderForContent worldXmListContainerProvider = null;
public static LCProviderForContent worldWzListContainerProvider = null;
public static LCProviderForContent artListContainerProvider = null;
public static LCProviderForContent clotheListContainerProvider = null;
public static LCProviderForContent foodListContainerProvider = null;
public static LCProviderForContent houseListContainerProvider = null;
public static LCProviderForContent trafficListContainerProvider = null;
public static LCProviderForContent studyListContainerProvider = null;
public static LCProviderForContent cultureListContainerProvider = null;
public static LCProviderForNormal messageAgreeListContainerProvider = null;
public static LCProviderForNormal messageDiscussListContainerProvider = null;
public static LCProviderForNormal messageCollectListContainerProvider = null;
public static LCProviderForNormal followAndFanaListListContainerProvider = null;
public static LCProviderForNormal discussListContainerProvider = null;
public static LCProviderForNormal peopleListContainerProvider = null;
public static LCProviderForContent userDtListContainerProvider = null;
public static LCProviderForContent userXmListContainerProvider = null;
public static LCProviderForContent userWzListContainerProvider = null;
public static LCProviderForContent userCollectListContainerProvider = null;
public static PSProvider firstcenter_pgSliderProvider = null;
public static PSProvider secondcenter_pgSliderProvider = null;
public static PSProvider fourthcenter_pgSliderProvider = null;
public static void addDataToPagesList(AbilitySlice abilitySlice,int n,int typeN){
switch (typeN) {
case 0:
firstcenter_pageslist.clear();
for (int i = 0; i < n; i++) {
DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter
.getInstance(abilitySlice.getContext())
.parse(ResourceTable.Layout_pageslider_item_listcontainer,null,false);
firstcenter_pageslist.add(directionalLayout);
}
break;
case 1:
secondcenter_pageslist.clear();
for (int i = 0; i < n; i++) {
DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter
.getInstance(abilitySlice.getContext())
.parse(ResourceTable.Layout_pageslider_item_listcontainer,null,false);
secondcenter_pageslist.add(directionalLayout);
}
break;
case 2:
break;
case 3:
fourthcenter_pageslist.clear();
for (int i = 0; i < n; i++) {
if(i == 0){
DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter
.getInstance(abilitySlice.getContext())
.parse(ResourceTable.Layout_pageslider_item_webview,null,false);
fourthcenter_pageslist.add(directionalLayout);
continue;
}
DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter
.getInstance(abilitySlice.getContext())
.parse(ResourceTable.Layout_pageslider_item_listcontainer,null,false);
fourthcenter_pageslist.add(directionalLayout);
}
break;
default:
break;
}
}
}
package com.tdtxdcxm.ruralcommunity.myutils;
import com.tdtxdcxm.ruralcommunity.appruntime.DataCenterControl;
import com.tdtxdcxm.ruralcommunity.appruntime.UserConfigInfo;
import com.tdtxdcxm.ruralcommunity.httpmanagers.ThreadPoolUtil;
import com.tdtxdcxm.ruralcommunity.items.LCArryListContentItem;
import com.tdtxdcxm.ruralcommunity.items.LCArryListNormalItem;
import com.tdtxdcxm.ruralcommunity.providers.LCProviderForContent;
import com.tdtxdcxm.ruralcommunity.slice.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;
import ohos.net.NetHandle;
import ohos.net.NetManager;
import ohos.net.NetStatusCallback;
import ohos.utils.zson.ZSONObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class MyTools {
private MyTools(){}
/*<****************http构造表单上传注册数据区域*****************/
public static void UpDataRegeisterInfo(AbilitySlice slice, String[][] userinfo, Text reg_tstext, TextField reg_usernametfd, TextField reg_passwordtfd, TextField reg_email, RadioContainer reg_dll2_1_radiocontainer,TextField reg_nl){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "register/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0;i < userinfo.length;i++){
if(i == 0){
stringBuilder.append(userinfo[0][0]);
stringBuilder.append("=");
stringBuilder.append(userinfo[0][1]);
continue;
}
stringBuilder.append("&");
stringBuilder.append(userinfo[i][0]);
stringBuilder.append("=");
stringBuilder.append(userinfo[i][1]);
}
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
try {
InputStream inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = new String(outputStream.toByteArray());
if(result.equals("OK")){
DataCenterControl.userName = userinfo[0][1];
DataCenterControl.gender = userinfo[3][1];
DataCenterControl.age = userinfo[4][1];
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
reg_tstext.setText("注册成功");
reg_usernametfd.setText("");
reg_passwordtfd.setText("");
reg_email.setText("");
reg_dll2_1_radiocontainer.cancelMarks();
reg_nl.setText("");
UserConfigInfo.pushData(slice.getContext(),userinfo);//将注册数据写入本地数据库
RegisterSlice.toanotherslice = true;
}
});
slice.present(new MainAbilitySlice(),new Intent());
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
reg_tstext.setText("注册失败");
}
});
}
}
} catch (IOException e) {} finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http构造表单上传注册数据区域***************>*/
/*<****************http构造表单上传注登录数据区域*****************/
public static void UpDataLoginInfo(AbilitySlice slice,String[] userinfo,String[][] userinfodown,Text log_tstext,TextField log_usernametfd,TextField log_passwordtfd){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "login/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username");
stringBuilder.append("=");
stringBuilder.append(userinfo[0]);
stringBuilder.append("&");
stringBuilder.append("password");
stringBuilder.append("=");
stringBuilder.append(userinfo[1]);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
try {
InputStream inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = new String(outputStream.toByteArray());
String[] userinfos = result.split(",");
if(userinfos[0].equals("OK")){
userinfodown[0][0] = "username";
userinfodown[0][1] = userinfos[1];
userinfodown[1][0] = "password";
userinfodown[1][1] = userinfos[2];
userinfodown[2][0] = "email";
userinfodown[2][1] = userinfos[3];
userinfodown[3][0] = "gender";
userinfodown[3][1] = userinfos[4];
userinfodown[4][0] = "age";
userinfodown[4][1] = userinfos[5];
UserConfigInfo.pushData(slice.getContext(),userinfodown);
DataCenterControl.userName = userinfo[0];
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
log_tstext.setText("登录成功");
log_usernametfd.setText("");
log_passwordtfd.setText("");
DataCenterControl.age = userinfos[5];
DataCenterControl.gender = userinfos[4];
LoginSlice.toanotherslice = true;
}
});
slice.present(new MainAbilitySlice(),new Intent());
}
else{
if(userinfos[0].equals("NOT")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
log_tstext.setText("远程验证:账号未注册!");
}
});
}
if(userinfos[0].equals("NO")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
log_tstext.setText("远程验证:密码错误!");
}
});
}
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http构造表单上传登录数据区域***************>*/
/*<****************http构造表单上传销毁指令数据区域*****************/
public static void UpDataDestoryInfo(AbilitySlice slice,String username){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "destory/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username");
stringBuilder.append("=");
stringBuilder.append(username);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.equals("OK")){
//销毁成功
UserConfigInfo.deleteUserInfo(slice.getContext(),DataCenterControl.userName);
DataCenterControl.userName = "";
((MainAbilitySlice)slice).toanotherslice = true;
slice.present(new StartPage(),new Intent());
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("销毁失败", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http构造表单上传销毁指令数据区域***************>*/
/*<****************http搜索用户数据区域*****************/
public static void UpDataSearchUserInfo(AbilitySlice slice, String username,String objectname){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "searchuser/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(username);
stringBuilder.append("&objectname=");
stringBuilder.append(objectname);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.startsWith("OK")){
//搜索成功
String finalResult = result;
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
DataCenterControl.people_listcontainer_list.clear();
DataCenterControl.people_listcontainer_list.add(new LCArryListNormalItem(finalResult.substring(3)));
if(DataCenterControl.peopleListContainerProvider != null){
DataCenterControl.peopleListContainerProvider.notifyDataChanged();
}
}
});
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("搜索为空!", slice.getContext());
}
});
}
}
} catch (IOException e) {} finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http搜索用户数据区域***************>*/
/*<****************http请求全站内容列表数据区域*****************/
public static void DownDataWorldListInfo(AbilitySlice slice,String type,String field){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = null;
switch(type){
case "worlddt":
urlString = DataCenterControl.serverIpWithPort + "worlddt/";
break;
case "worldxm":
urlString = DataCenterControl.serverIpWithPort + "worldxm/";
break;
case "worldwz":
urlString = DataCenterControl.serverIpWithPort + "worldwz/";
break;
case "worldfield":
urlString = DataCenterControl.serverIpWithPort + "worldfield/";
break;
default:
urlString = DataCenterControl.serverIpWithPort + "index/";
break;
}
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("field_id=");
switch (field){
case "art":
stringBuilder.append("1");
break;
case "clothe":
stringBuilder.append("2");
break;
case "food":
stringBuilder.append("3");
break;
case "house":
stringBuilder.append("4");
break;
case "traffic":
stringBuilder.append("5");
break;
case "study":
stringBuilder.append("6");
break;
case "culture":
stringBuilder.append("7");
break;
default:
stringBuilder.append("0");
break;
}
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.indexOf("sum") != -1){
//请求全站动态成功
String finalResult = result;
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "worlddt":
ZSONObject zsonobject_dt = ZSONObject.stringToZSON(finalResult);
int sum_dt = Integer.parseInt(zsonobject_dt.getString("sum"));
DataCenterControl.worlddt_listcontainer_list.clear();
for(int i = 0;i < sum_dt;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_dt.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.worlddt_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.worldDtListContainerProvider != null){
DataCenterControl.worldDtListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("全站动态下载成功!", slice.getContext());
break;
case "worldxm":
ZSONObject zsonobject_xm = ZSONObject.stringToZSON(finalResult);
int sum_xm = Integer.parseInt(zsonobject_xm.getString("sum"));
DataCenterControl.worldxm_listcontainer_list.clear();
for(int i = 0;i < sum_xm;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_xm.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.worldxm_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.worldXmListContainerProvider != null){
DataCenterControl.worldXmListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("全站项目下载成功!", slice.getContext());
break;
case "worldwz":
ZSONObject zsonobject_wz = ZSONObject.stringToZSON(finalResult);
int sum_wz = Integer.parseInt(zsonobject_wz.getString("sum"));
DataCenterControl.worldwz_listcontainer_list.clear();
for(int i = 0;i < sum_wz;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_wz.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.worldwz_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.worldWzListContainerProvider != null){
DataCenterControl.worldWzListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("全站文章下载成功!", slice.getContext());
break;
case "worldfield":
switch (field){
case "art":
ZSONObject zsonobject_art = ZSONObject.stringToZSON(finalResult);
int sum_art = Integer.parseInt(zsonobject_art.getString("sum"));
DataCenterControl.art_listcontainer_list.clear();
for(int i = 0;i < sum_art;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_art.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.art_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.art_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.artListContainerProvider != null){
DataCenterControl.artListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[艺]下载成功!", slice.getContext());
break;
case "clothe":
ZSONObject zsonobject_clothe = ZSONObject.stringToZSON(finalResult);
int sum_clothe = Integer.parseInt(zsonobject_clothe.getString("sum"));
DataCenterControl.clothe_listcontainer_list.clear();
for(int i = 0;i < sum_clothe;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_clothe.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.clothe_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.clothe_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.clotheListContainerProvider != null){
DataCenterControl.clotheListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[衣]下载成功!", slice.getContext());
break;
case "food":
ZSONObject zsonobject_food = ZSONObject.stringToZSON(finalResult);
int sum_food = Integer.parseInt(zsonobject_food.getString("sum"));
DataCenterControl.food_listcontainer_list.clear();
for(int i = 0;i < sum_food;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_food.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.food_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.food_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.foodListContainerProvider != null){
DataCenterControl.foodListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[食]下载成功!", slice.getContext());
break;
case "house":
ZSONObject zsonobject_house = ZSONObject.stringToZSON(finalResult);
int sum_house = Integer.parseInt(zsonobject_house.getString("sum"));
DataCenterControl.house_listcontainer_list.clear();
for(int i = 0;i < sum_house;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_house.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.house_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.house_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.houseListContainerProvider != null){
DataCenterControl.houseListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[住]下载成功!", slice.getContext());
break;
case "traffic":
ZSONObject zsonobject_traffic = ZSONObject.stringToZSON(finalResult);
int sum_traffic = Integer.parseInt(zsonobject_traffic.getString("sum"));
DataCenterControl.traffic_listcontainer_list.clear();
for(int i = 0;i < sum_traffic;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_traffic.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.traffic_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.traffic_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.trafficListContainerProvider != null){
DataCenterControl.trafficListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[行]下载成功!", slice.getContext());
break;
case "study":
ZSONObject zsonobject_study = ZSONObject.stringToZSON(finalResult);
int sum_study = Integer.parseInt(zsonobject_study.getString("sum"));
DataCenterControl.study_listcontainer_list.clear();
for(int i = 0;i < sum_study;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_study.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.study_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.study_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.studyListContainerProvider != null){
DataCenterControl.studyListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[学]下载成功!", slice.getContext());
break;
case "culture":
ZSONObject zsonobject_culture = ZSONObject.stringToZSON(finalResult);
int sum_culture = Integer.parseInt(zsonobject_culture.getString("sum"));
DataCenterControl.culture_listcontainer_list.clear();
for(int i = 0;i < sum_culture;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_culture.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.culture_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.culture_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.cultureListContainerProvider != null){
DataCenterControl.cultureListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("[文]下载成功!", slice.getContext());
break;
default:
break;
}
break;
default:
MyTools.toastShow("全站未知下载成功!", slice.getContext());
break;
}
}
});
}
else if(result.equals("NULL")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("全站内容为空!", slice.getContext());
}
});
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "worlddt":
MyTools.toastShow("全站动态下载失败!", slice.getContext());
break;
case "worldxm":
MyTools.toastShow("全站项目下载失败!", slice.getContext());
break;
case "worldwz":
MyTools.toastShow("全站文章下载失败!", slice.getContext());
break;
default:
MyTools.toastShow("全站未知下载失败!", slice.getContext());
break;
}
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http请求全站内容列表数据区域***************>*/
/*<****************http请求用户点赞、评论、收藏消息数据区域*****************/
public static void DownDataMessageListInfo(AbilitySlice slice,String type){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "message/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&messagetype=");
switch(type){
case "messageagree":
stringBuilder.append("AGREE");
break;
case "messagediscuss":
stringBuilder.append("DISCUSS");
break;
case "messagecollect":
stringBuilder.append("COLLECT");
break;
default:
break;
}
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.indexOf("sum") != -1){
String finalResult = result;
switch (type) {
case "messageagree":
ZSONObject zsonobject_agree = ZSONObject.stringToZSON(finalResult);
int sum_agree = Integer.parseInt(zsonobject_agree.getString("sum"));
DataCenterControl.messageagree_listcontainer_list.clear();
for(int i = 0;i < sum_agree;i++){
String info = zsonobject_agree.getString(String.valueOf(i));
DataCenterControl.messageagree_listcontainer_list.add(new LCArryListNormalItem(info));
}
break;
case "messagediscuss":
ZSONObject zsonobject_discuss = ZSONObject.stringToZSON(finalResult);
int sum_discuss = Integer.parseInt(zsonobject_discuss.getString("sum"));
DataCenterControl.messagediscuss_listcontainer_list.clear();
for(int i = 0;i < sum_discuss;i++){
String info = zsonobject_discuss.getString(String.valueOf(i));
DataCenterControl.messagediscuss_listcontainer_list.add(new LCArryListNormalItem(info));
}
break;
case "messagecollect":
ZSONObject zsonobject_collect = ZSONObject.stringToZSON(finalResult);
int sum_collect = Integer.parseInt(zsonobject_collect.getString("sum"));
DataCenterControl.messagecollect_listcontainer_list.clear();
for(int i = 0;i < sum_collect;i++){
String info = zsonobject_collect.getString(String.valueOf(i));
DataCenterControl.messagecollect_listcontainer_list.add(new LCArryListNormalItem(info));
}
break;
default:
break;
}
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "messageagree":
if(DataCenterControl.messageAgreeListContainerProvider != null){
DataCenterControl.messageAgreeListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户点赞消息下载成功!", slice.getContext());
break;
case "messagediscuss":
if(DataCenterControl.messageDiscussListContainerProvider != null){
DataCenterControl.messageDiscussListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户评论消息下载成功!", slice.getContext());
break;
case "messagecollect":
if(DataCenterControl.messageCollectListContainerProvider != null){
DataCenterControl.messageCollectListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户收藏消息下载成功!", slice.getContext());
break;
default:
MyTools.toastShow("全站未知下载成功!",slice.getContext());
break;
}
}
});
}
else if(result.equals("NULL")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "messageagree":
DataCenterControl.messageagree_listcontainer_list.clear();
if(DataCenterControl.messageAgreeListContainerProvider != null){
DataCenterControl.messageAgreeListContainerProvider.notifyDataChanged();
}
break;
case "messagediscuss":
DataCenterControl.messagediscuss_listcontainer_list.clear();
if(DataCenterControl.messageDiscussListContainerProvider != null){
DataCenterControl.messageDiscussListContainerProvider.notifyDataChanged();
}
break;
case "messagecollect":
DataCenterControl.messagecollect_listcontainer_list.clear();
if(DataCenterControl.messageCollectListContainerProvider != null){
DataCenterControl.messageCollectListContainerProvider.notifyDataChanged();
}
break;
}
MyTools.toastShow("用户消息为空!", slice.getContext());
}
});
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "messageagree":
MyTools.toastShow("用户点赞消息下载失败!", slice.getContext());
break;
case "messagediscuss":
MyTools.toastShow("用户评论消息下载失败!", slice.getContext());
break;
case "messagecollect":
MyTools.toastShow("用户收藏下载失败!", slice.getContext());
break;
default:
MyTools.toastShow("用户未知消息下载失败!", slice.getContext());
break;
}
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http请求用户点赞、评论、收藏消息数据区域***************>*/
/*<****************http发送关注或取消关注指令区域*****************/
public static void UpDataFollowInfo(AbilitySlice slice, Component component, String user_id, int i, String operation){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = "";
if(operation.equals("关注")){
urlString = DataCenterControl.serverIpWithPort + "follow/?";
}
if(operation.equals("取消关注")){
urlString = DataCenterControl.serverIpWithPort + "unfollow/?";
}
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&user_id=");
stringBuilder.append(user_id);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
String[] tosettext = {"","",""};
if(result.equals("OK")){
if(operation.equals("关注")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
//i是-1是代表是搜索用户结果列表的中操作,i是-2是代表内容详情页中的操作
if(i == -1){
DataCenterControl.people_listcontainer_list.get(0).setContent(user_id+"[已关注]");
DataCenterControl.peopleListContainerProvider.notifyDataChanged();
}
else if(i == -2){
((Text)component).setText("已关注");
}
MyTools.toastShow("已关注",slice.getContext());
}
});
}
if(operation.equals("取消关注")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
//i是-1是代表是搜索用户结果列表的中操作,i是-2是代表内容详情页中的操作,其余i是大于等于0是代表用户关注列表中的操作
if(i == -1){
DataCenterControl.people_listcontainer_list.remove(0);
DataCenterControl.peopleListContainerProvider.notifyDataChanged();
}
else if(i == -2){
((Text)component).setText("关注");
}
else{
DataCenterControl.follow_listcontainer_list.remove(i);
DataCenterControl.followAndFanaListListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("已取消关注",slice.getContext());
}
});
}
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http发送关注或取消关注指令区域***************>*/
/*<****************http请求关注数目、粉丝数目、阅读数目数据区域*****************/
public static void DownDataFollowFansReadvalueInfo(AbilitySlice slice,String username,Text[] followfansread){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "count/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username");
stringBuilder.append("=");
stringBuilder.append(username);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.startsWith("OK")){
String[] numbers = result.substring(3).split(",");
if(followfansread != null){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
followfansread[0].setText(numbers[0]);
followfansread[1].setText(numbers[1]);
followfansread[2].setText(numbers[2]);
}
});
}
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("计数请求失败", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http请求关注数目、粉丝数目、阅读数目数据区域***************>*/
/*<****************http下载用户关注和粉丝列表据区域*****************/
public static void DownDataFollowAndFanslistInfo(AbilitySlice slice,String username,String type){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = null;
switch (type) {
case "followlist":
urlString = DataCenterControl.serverIpWithPort + "followlist/?";
break;
case "fanslist":
urlString = DataCenterControl.serverIpWithPort + "fanslist/?";
break;
default:
urlString = DataCenterControl.serverIpWithPort + "inedx/?";
break;
}
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(username);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.indexOf("sum") != -1){
//搜索成功
String finalResult = result;
switch (type){
case "followlist":
DataCenterControl.follow_listcontainer_list.clear();
ZSONObject zsonobject_follow = ZSONObject.stringToZSON(finalResult);
int sum_follow = Integer.parseInt(zsonobject_follow.getString("sum"));
for(int i = 0;i < sum_follow;i++){
String info = zsonobject_follow.getString(String.valueOf(i));
DataCenterControl.follow_listcontainer_list.add(new LCArryListNormalItem(info));
}
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
if(DataCenterControl.followAndFanaListListContainerProvider != null){
DataCenterControl.followAndFanaListListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("关注列表下载成功!", slice.getContext());
}
});
break;
case "fanslist":
DataCenterControl.fans_listcontainer_list.clear();
ZSONObject zsonobject_fans = ZSONObject.stringToZSON(finalResult);
int sum_fans = Integer.parseInt(zsonobject_fans.getString("sum"));
for(int i = 0;i < sum_fans;i++){
String info = zsonobject_fans.getString(String.valueOf(i));
DataCenterControl.fans_listcontainer_list.add(new LCArryListNormalItem(info));
}
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
if(DataCenterControl.followAndFanaListListContainerProvider != null){
DataCenterControl.followAndFanaListListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("粉丝列表下载成功!", slice.getContext());
}
});
break;
default:
break;
}
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("好友为空!", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http下载用户关注和粉丝列表据区域***************>*/
/*<****************http请求用户内容列表与收藏列表数据区域*****************/
public static void DownDataUserContentListInfo(AbilitySlice slice,String type){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "usercontentlist/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&type=");
switch(type){
case "dtlist":
stringBuilder.append("dtlist");
break;
case "xmlist":
stringBuilder.append("xmlist");
break;
case "wzlist":
stringBuilder.append("wzlist");
break;
case "collectlist":
stringBuilder.append("collectlist");
break;
default:
break;
}
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.indexOf("sum") != -1){
//请求全站动态成功
String finalResult = result;
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "dtlist":
ZSONObject zsonobject_dt = ZSONObject.stringToZSON(finalResult);
int sum_dt = Integer.parseInt(zsonobject_dt.getString("sum"));
DataCenterControl.userdt_listcontainer_list.clear();
for(int i = 0;i < sum_dt;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_dt.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.userdt_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.userDtListContainerProvider != null){
DataCenterControl.userDtListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户动态下载成功!", slice.getContext());
break;
case "xmlist":
ZSONObject zsonobject_xm = ZSONObject.stringToZSON(finalResult);
int sum_xm = Integer.parseInt(zsonobject_xm.getString("sum"));
DataCenterControl.userxm_listcontainer_list.clear();
for(int i = 0;i < sum_xm;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_xm.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.userxm_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.userXmListContainerProvider != null){
DataCenterControl.userXmListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户项目下载成功!", slice.getContext());
break;
case "wzlist":
ZSONObject zsonobject_wz = ZSONObject.stringToZSON(finalResult);
int sum_wz = Integer.parseInt(zsonobject_wz.getString("sum"));
DataCenterControl.userwz_listcontainer_list.clear();
for(int i = 0;i < sum_wz;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_wz.getString(String.valueOf(i)));
int detail_len = t.getString("DETAIL").length();
DataCenterControl.userwz_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(DataCenterControl.userWzListContainerProvider != null){
DataCenterControl.userWzListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户文章下载成功!", slice.getContext());
break;
case "collectlist":
ZSONObject zsonobject_collect = ZSONObject.stringToZSON(finalResult);
int sum_collect = Integer.parseInt(zsonobject_collect.getString("sum"));
DataCenterControl.usercollect_listcontainer_list.clear();
for(int i = 0;i < sum_collect;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_collect.getString(String.valueOf(i)));
String field = t.getString("TYPE");
int detail_len = t.getString("DETAIL").length();
if(field.equals("动态") || field.equals("文章")){
DataCenterControl.usercollect_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL").substring(12,detail_len - 1 - 1).replace("\\n","\n")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
if(field.equals("项目")){
DataCenterControl.usercollect_listcontainer_list.add(
new LCArryListContentItem(t.getString("CONTENT_ID")
,t.getString("TYPE")
,t.getString("DATE")
,t.getString("READVALUE")
,t.getString("DETAIL")
,t.getString("USER_ID")
,DataCenterControl.fields[Integer.parseInt(t.getString("FIELD_ID")) - 1]
)
);
}
}
if(DataCenterControl.userCollectListContainerProvider != null){
DataCenterControl.userCollectListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("用户收藏下载成功!", slice.getContext());
break;
default:
MyTools.toastShow("用户未知下载成功!", slice.getContext());
break;
}
}
});
}
else if(result.equals("NULL")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch(type){
case "dtlist":
DataCenterControl.userdt_listcontainer_list.clear();
if(DataCenterControl.userDtListContainerProvider != null){
DataCenterControl.userDtListContainerProvider.notifyDataChanged();
}
break;
case "xmlist":
DataCenterControl.userxm_listcontainer_list.clear();
if(DataCenterControl.userXmListContainerProvider != null){
DataCenterControl.userXmListContainerProvider.notifyDataChanged();
}
break;
case "wzlist":
DataCenterControl.userwz_listcontainer_list.clear();
if(DataCenterControl.userWzListContainerProvider != null){
DataCenterControl.userWzListContainerProvider.notifyDataChanged();
}
break;
case "collectlist":
DataCenterControl.usercollect_listcontainer_list.clear();
if(DataCenterControl.userCollectListContainerProvider != null){
DataCenterControl.userCollectListContainerProvider.notifyDataChanged();
}
break;
}
MyTools.toastShow("用户内容为空!", slice.getContext());
}
});
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
switch (type) {
case "dtlist":
MyTools.toastShow("用户动态下载失败!", slice.getContext());
break;
case "xmlist":
MyTools.toastShow("用户项目下载失败!", slice.getContext());
break;
case "wzlist":
MyTools.toastShow("用户文章下载失败!", slice.getContext());
break;
case "collectlist":
MyTools.toastShow("用户收藏下载失败!", slice.getContext());
break;
default:
MyTools.toastShow("用户未知下载失败!", slice.getContext());
break;
}
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http请求用户内容列表与收藏列表数据区域***************>*/
/*<****************http删除用户内容数据区域*****************/
public static void UpDataDeleteUserContentInfo(AbilitySlice slice,String type, String contentid, ArrayList<LCArryListContentItem> list, LCProviderForContent lcProviderForContent, int list_i){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "deleteusercontent/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&contentid=");
stringBuilder.append(contentid);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.equals("OK")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
list.remove(list_i);
lcProviderForContent.notifyDataChanged();
MyTools.toastShow("删除成功!", slice.getContext());
}
});
}
else if(result.equals("NO")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("删除失败!刷可刷新加载!", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http删除用户内容数据区域***************>*/
/*<****************http发送点击阅读指令区域*****************/
public static void UpDataWorldListReadInfo(AbilitySlice slice,String content_id,String user_id,Button detail_authorbut,Button detail_topddl_agreebut,Button detail_topddl_collectbut){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "read/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&content_id=");
stringBuilder.append(content_id);
stringBuilder.append("&user_id=");
stringBuilder.append(user_id);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
String[] tosettext = {"","",""};
if(result.startsWith("ok:")){
result = result.substring(3);
if(result.charAt(0) == '0'){
tosettext[0] = "关注";
}
else{
tosettext[0] = "已关注";
}
if(result.charAt(1) == '0'){
tosettext[1] = "点赞";
}
else{
tosettext[1] = "已点赞";
}
if(result.charAt(2) == '0'){
tosettext[2] = "收藏";
}
else{
tosettext[2] = "已收藏";
}
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
detail_authorbut.setText(tosettext[0]);
detail_topddl_agreebut.setText(tosettext[1]);
detail_topddl_collectbut.setText(tosettext[2]);
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http发送点击阅读指令区域***************>*/
/*<****************http请求内容评论数据区域*****************/
public static void DownDataContentDiscussListInfo(AbilitySlice slice, String contentid){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "pulldiscuss/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("contentid=");
stringBuilder.append(contentid);
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.indexOf("sum") != -1){
String finalResult = result;
ZSONObject zsonobject_dt = ZSONObject.stringToZSON(finalResult);
int sum_dt = Integer.parseInt(zsonobject_dt.getString("sum"));
DataCenterControl.discuss_listcontainer_list.clear();
for(int i = 0;i < sum_dt;i++){
ZSONObject t = ZSONObject.stringToZSON(zsonobject_dt.getString(String.valueOf(i)));
DataCenterControl.discuss_listcontainer_list.add(new LCArryListNormalItem(t.getString("detail")));
}
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
if(DataCenterControl.discussListContainerProvider != null){
DataCenterControl.discussListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("内容评论下载成功!", slice.getContext());
}
});
}
else if(result.equals("NULL")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
DataCenterControl.discuss_listcontainer_list.clear();
if(DataCenterControl.discussListContainerProvider != null){
DataCenterControl.discussListContainerProvider.notifyDataChanged();
}
MyTools.toastShow("评论为空!", slice.getContext());
}
});
}
else{
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("该内容评论下载失败!", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http请求内容评论数据区域***************>*/
/*<****************http发布评论数据区域*****************/
public static void UpDataContentDiscussInfo(AbilitySlice slice,String contentid,String detail,TextField discuss_writetfd){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = DataCenterControl.serverIpWithPort + "pushdiscuss/?";
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&contentid=");
stringBuilder.append(contentid);
stringBuilder.append("&detail=");
stringBuilder.append(detail);
stringBuilder.append("&time=");
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
stringBuilder.append(formatter.format(date));
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
if(result.equals("OK")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
discuss_writetfd.clearFocus();
discuss_writetfd.setText("");
MyTools.toastShow("评论成功!", slice.getContext());
}
});
}
else if(result.equals("NO")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
MyTools.toastShow("评论失败!!", slice.getContext());
}
});
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http发布评论数据区域***************>*/
/*<****************http发送点赞或收藏指令区域*****************/
public static void UpDataAgreeAndCollectInfo(AbilitySlice slice,String content_id,String operation,Button button){
NetManager main_toplistnetmanger = NetManager.getInstance(slice.getContext());
if (!main_toplistnetmanger.hasDefaultNet()) {return;}
ThreadPoolUtil.submit(() -> {
NetHandle thenetHandle = main_toplistnetmanger.getDefaultNet();
NetStatusCallback netStatusCallback = new NetStatusCallback() {};
HttpURLConnection httpURLConnection = null;
String urlString = "";
if(operation.equals("点赞")){
urlString = DataCenterControl.serverIpWithPort + "agree/?";
}
if(operation.equals("收藏")){
urlString = DataCenterControl.serverIpWithPort + "collect/?";
}
if(operation.equals("取消点赞")){
urlString = DataCenterControl.serverIpWithPort + "unagree/?";
}
if(operation.equals("取消收藏")){
urlString = DataCenterControl.serverIpWithPort + "uncollect/?";
}
try {
URL url = new URL(urlString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
URLConnection urlConnection = thenetHandle.openConnection(url, java.net.Proxy.NO_PROXY);
if (urlConnection instanceof HttpURLConnection) {
httpURLConnection = (HttpURLConnection) urlConnection;
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("username=");
stringBuilder.append(DataCenterControl.userName);
stringBuilder.append("&contentid=");
stringBuilder.append(content_id);
stringBuilder.append("&time=");
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
stringBuilder.append(formatter.format(date));
byte[] b = stringBuilder.toString().getBytes();
httpURLConnection.getOutputStream().write(b);
try {
httpURLConnection.connect();
} catch (IOException e) {}
outputStream.flush();
InputStream inputStream = null;
try {
inputStream = urlConnection.getInputStream();
byte[] cache = new byte[2 * 1024];
int len = inputStream.read(cache);
while (len != -1) {
outputStream.write(cache, 0, len);
len = inputStream.read(cache);
}
} catch (IOException e) {}
String result = "";
result = outputStream.toString();
String[] tosettext = {"","",""};
if(result.equals("OK")){
if(operation.equals("点赞")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
button.setText("已点赞");
}
});
}
if(operation.equals("收藏")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
button.setText("已收藏");
}
});
}
if(operation.equals("取消点赞")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
button.setText("点赞");
}
});
}
if(operation.equals("取消收藏")){
slice.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
button.setText("收藏");
}
});
}
}
}
} catch (IOException e) {}
finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
});
}
/******************http发送点赞或收藏指令区域***************>*/
public static void toastShow(String info, Context context){
ToastDialog toastDialog = new ToastDialog(context);
toastDialog.setText(info);
toastDialog.setTransparent(true);
toastDialog.setDuration(50);
toastDialog.setAlignment(LayoutAlignment.CENTER);
toastDialog.show();
}
public static void commonDialogRemoveShow(String title, String content, Component component,int itemid, AbilitySlice slice,String operation){
CommonDialog commonDialog = new CommonDialog(slice.getContext());
commonDialog.setTitleText(title);
commonDialog.setContentText(content);
commonDialog.setSize(630,400);
commonDialog.setButton(1, "确认", new IDialog.ClickedListener() {
@Override
public void onClick(IDialog iDialog, int i) {
if(operation.equals("destory")){
MyTools.UpDataDestoryInfo(slice,DataCenterControl.userName);
}
if(operation.equals("follow")){
Text text = (Text) ((DirectionalLayout)component).getComponentAt(0);
String s = text.getText();
if(s.substring(0,s.length() - 4).equals(DataCenterControl.userName)){
MyTools.toastShow("无法关注自己!",slice.getContext());
commonDialog.destroy();
return;
}
MyTools.UpDataFollowInfo(slice,component,s.substring(0,s.length() - 4),itemid,"关注");
}
if(operation.equals("unfollow")){
Text text = (Text) ((DirectionalLayout)component).getComponentAt(0);
String s = text.getText();
MyTools.UpDataFollowInfo(slice,component,s.substring(0,s.length() - 5),itemid,"取消关注");
}
commonDialog.destroy();
}
});
commonDialog.setButton(2, "取消", new IDialog.ClickedListener() {
@Override
public void onClick(IDialog iDialog, int i) {
commonDialog.destroy();
}
});
commonDialog.show();
}
public static void selectImage(AbilitySlice abilitySlice, int requestCode){
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withAction("android.intent.action.GET_CONTENT")
.withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
.build();
intent.setOperation(operation);
intent.setType("image/*");
abilitySlice.startAbilityForResult(intent,requestCode);
}
}
import pymysql
#编写创建各表的SQL语句
#1.创建USERS表
USERS = '''
CREATE TABLE IF NOT EXISTS USERS
(
USER_ID VARCHAR(32) NOT NULL,
PASSWORD CHAR(8) NOT NULL,
EMAIL VARCHAR(100) NOT NULL,
AGE TINYINT NOT NULL,
GENDER ENUM('男','女') NOT NULL DEFAULT '男',
PRIMARY KEY(USER_ID)
)
'''
#2.创建FIELD表
FIELD = '''
CREATE TABLE IF NOT EXISTS FIELD
(
FIELD_ID VARCHAR(1) NOT NULL,
NAME ENUM('艺','衣','食','住','行','学','文') NOT NULL DEFAULT '艺',
PRIMARY KEY(FIELD_ID)
)
'''
#3.创建USER_CONTENTS表
USER_CONTENTS = '''
CREATE TABLE IF NOT EXISTS USER_CONTENTS
(
CONTENT_ID INT NOT NULL AUTO_INCREMENT,
TYPE ENUM('动态','项目','文章') NOT NULL,
DATE DATETIME NOT NULL,
READVALUE INT NOT NULL,
DETAIL JSON NOT NULL,
USER_ID VARCHAR(32) NOT NULL,
FIELD_ID VARCHAR(1) NOT NULL,
PRIMARY KEY(CONTENT_ID),
FOREIGN KEY(USER_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(FIELD_ID) REFERENCES FIELD(FIELD_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
'''
#4.创建AGREE表
AGREE = '''
CREATE TABLE IF NOT EXISTS AGREE
(
AGREE_ID INT NOT NULL AUTO_INCREMENT,
TIME DATETIME NOT NULL,
CONTENT_ID INT NOT NULL,
USER_ID VARCHAR(32) NOT NULL,
PRIMARY KEY(AGREE_ID),
FOREIGN KEY(CONTENT_ID) REFERENCES USER_CONTENTS(CONTENT_ID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(USER_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
'''
#5.创建DISCUSS表
DISCUSS = '''
CREATE TABLE IF NOT EXISTS DISCUSS
(
DISCUSS_ID INT NOT NULL AUTO_INCREMENT,
TIME DATETIME NOT NULL,
DETAIL VARCHAR(300) NOT NULL,
CONTENT_ID INT NOT NULL,
USER_ID VARCHAR(32) NOT NULL,
PRIMARY KEY(DISCUSS_ID),
FOREIGN KEY(CONTENT_ID) REFERENCES USER_CONTENTS(CONTENT_ID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(USER_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
'''
#6.创建COLLECT表
COLLECT = '''
CREATE TABLE IF NOT EXISTS COLLECT
(
COLLECT_ID INT NOT NULL AUTO_INCREMENT,
TIME DATETIME NOT NULL,
CONTENT_ID INT NOT NULL,
USER_ID VARCHAR(32) NOT NULL,
PRIMARY KEY(COLLECT_ID),
FOREIGN KEY(CONTENT_ID) REFERENCES USER_CONTENTS(CONTENT_ID) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(USER_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
'''
#a.打开数据库连接
database = pymysql.connect(host='localhost'
,user='root'
,password='000000'
,port=3306
)
print("已经连接到Mysql!")
#b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
cur.execute('CREATE DATABASE IF NOT EXISTS WHXD')
cur.close()
print("已经创建WHXD数据库,并关闭连接!")
#a.打开数据库连接
database = pymysql.connect(host='localhost'
,user='root'
,password='000000'
,port=3306
,database='WHXD')
print("已经连接到WHXD数据库!")
#b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
#c.使用execute()方法执行SQL语句
cur.execute(USERS)
cur.execute(FIELD)
cur.execute(USER_CONTENTS)
cur.execute(AGREE)
cur.execute(DISCUSS)
cur.execute(COLLECT)
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('1','艺')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('2','衣')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('3','食')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('4','住')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('5','行')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('6','学')
'''
cur.execute(sql)
database.commit()
sql = '''
INSERT INTO FIELD (FIELD_ID,NAME) VALUES ('7','文')
'''
cur.execute(sql)
database.commit()
#d.关闭数据库连接
database.close()
print("已经创建各表并插入领域数据,并关闭WHXD数据库连接!")
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import json
import pymysql
# Create your views here.
# request第一个参数必不可少,将浏览器请求的对象传过来
@csrf_exempt
def register(request):
USERNAME = ''
PASSORD = ''
EMAIL = ''
AGE = ''
GENDER = ''
canregister = True
# 1.注册指令处理
if request.method == 'POST':
print("注册信息:")
print("username:", request.POST.get('username'))
print("password:", request.POST.get('password'))
print("email:", request.POST.get('email'))
print("gender:", request.POST.get('gender'))
print("age:", request.POST.get('age'))
USERNAME = request.POST.get('username')
PASSORD = request.POST.get('password')
EMAIL = request.POST.get('email')
AGE = request.POST.get('age')
GENDER = request.POST.get('gender')
elif request.method == 'GET':
print("注册信息:")
print("username:", request.GET.get('username'))
print("password:", request.GET.get('password'))
print("email:", request.GET.get('email'))
print("gender:", request.GET.get('gender'))
print("age:", request.GET.get('age'))
USERNAME = request.GET.get('username')
PASSORD = request.GET.get('password')
EMAIL = request.GET.get('email')
AGE = request.GET.get('age')
GENDER = request.GET.get('gender')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[注册]已经连接到WHXD数据库!")
sql = "SELECT USER_ID FROM USERS WHERE USER_ID='%s'" % USERNAME # 查询该用户名是否存在
print(sql)
# c.使用execute()方法执行SQL语句
cur.execute(sql)
result = cur.fetchall()
if len(result) == 0:
# 该用户名不存在——可以注册
sql = "INSERT INTO USERS VALUES('%s','%s','%s',%s,'%s')" % (USERNAME, PASSORD, EMAIL, AGE, GENDER)
print(sql)
cur.execute(sql)
database.commit()
# 给该新注册用户创建一个关注表
sql = '''
CREATE TABLE IF NOT EXISTS %s_FOLLOW
(
ID INT NOT NULL AUTO_INCREMENT,
FOLLOW_ID VARCHAR(32) NOT NULL,
PRIMARY KEY(ID),
FOREIGN KEY(FOLLOW_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
''' % (USERNAME.upper())
print(sql)
cur.execute(sql)
# 给该新注册用户创建一个粉丝表
sql = '''
CREATE TABLE IF NOT EXISTS %s_FANS
(
ID INT NOT NULL AUTO_INCREMENT,
FANS_ID VARCHAR(32) NOT NULL,
PRIMARY KEY(ID),
FOREIGN KEY(FANS_ID) REFERENCES USERS(USER_ID) ON DELETE CASCADE ON UPDATE CASCADE
)
''' % (USERNAME.upper())
print(sql)
cur.execute(sql)
print("已经成功注册该用户!")
else:
# 该用户名存在——不能注册
print("该账户已经存在!")
canregister = False
# d.关闭数据库连接
database.close()
print("[注册]已经关闭WHXD数据库连接!")
if canregister == True:
return HttpResponse("OK")
else:
return HttpResponse("NO")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def login(request):
USERNAME = ''
PASSORD = ''
# 2.登录指令处理
if request.method == 'POST':
print("登陆信息:")
print("username:", request.POST.get('username'))
print("password:", request.POST.get('password'))
USERNAME = request.POST.get('username')
PASSORD = request.POST.get('password')
elif request.method == 'GET':
print("登陆信息:")
print("username:", request.GET.get('username'))
print("password:", request.GET.get('password'))
USERNAME = request.GET.get('username')
PASSORD = request.GET.get('password')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[登录]已经连接到WHXD数据库!")
sql = "SELECT USER_ID,PASSWORD,EMAIL,GENDER,AGE FROM USERS WHERE USER_ID='%s'" % USERNAME # 查询该用户名是否存在
print(sql)
# c.使用execute()方法执行SQL语句
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[登录]已经关闭WHXD数据库连接!")
if len(result) == 0:
print("账户不存在,请注册!")
return HttpResponse("NOT")
else:
if PASSORD == result[0][1]:
print("密码正确,登录成功!")
backinfo = 'OK' \
+ ',' + str(result[0][0]) \
+ ',' + str(result[0][1]) \
+ ',' + str(result[0][2]) \
+ ',' + str(result[0][4]) \
+ ',' + str(result[0][3])
return HttpResponse(backinfo)
else:
print("密码错误,登录失败!")
return HttpResponse("NO")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def destory(request):
USERNAME = ''
# 3.销毁指令处理
if request.method == 'POST':
print("被销毁账号:")
print("username:", request.POST.get('username'))
USERNAME = request.POST.get('username')
elif request.method == 'GET':
print("被销毁账号:")
print("username:", request.GET.get('username'))
USERNAME = request.GET.get('username')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[销毁]已经连接到WHXD数据库!")
sql = '''
DELETE FROM USERS WHERE USER_ID='%s'
'''%USERNAME
print(sql)
# c.使用execute()方法执行SQL语句
cur.execute(sql)
database.commit()
print("1.已经删除该用户信息!")
'''
# 将关注列表中所有用户的粉丝列表中删除自己,
sql = "
SELECT FOLLOW_ID FROM %s_FOLLOW
" % USERNAME
cur.execute(sql)
result = cur.fetchall()
result_len = len(result)
if result_len != 0:
for i in range(0, result_len):
tsql = "
DELETE FORM %s_FANS WHERE FANS_ID='%s'
" % (request[i][0], USERNAME)
print(tsql)
cur.execute(tsql)
database.commit()
print("2.已取消所有的关注!")
'''
sql = '''DROP TABLE IF EXISTS %s_FOLLOW''' % USERNAME
cur.execute(sql)
sql = '''DROP TABLE IF EXISTS %s_FANS''' % USERNAME
cur.execute(sql)
print("3.已经删除该用户关注和粉丝表!")
# d.关闭数据库连接
database.close()
print("[销毁]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def read(request):
USERNAME = ''
CONTENT_ID = ''
USER_ID = ''
isfollow = '0'
isagree = '0'
iscollect = '0'
# 阅读详情指令
if request.method == 'POST':
print("[指令]阅读详情")
USERNAME = request.POST.get('username')
CONTENT_ID = int(request.POST.get('content_id'))
USER_ID = request.POST.get('user_id')
elif request.method == 'GET':
print("[指令]阅读详情")
USERNAME = request.GET.get('username')
CONTENT_ID = int(request.GET.get('content_id'))
USER_ID = request.GET.get('user_id')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[阅读指令]已经连接到WHXD数据库!")
sql = '''
SELECT READVALUE FROM USER_CONTENTS WHERE CONTENT_ID=%s
''' % CONTENT_ID
cur.execute(sql)
count = cur.fetchall()
count = count[0][0] + 1
sql = '''
UPDATE USER_CONTENTS SET READVALUE=%s WHERE CONTENT_ID=%s
''' % (count, CONTENT_ID)
cur.execute(sql)
database.commit()
# 查询USERBANE是否关注了USER_ID
sql = '''SELECT FOLLOW_ID FROM %s_FOLLOW WHERE FOLLOW_ID='%s'
''' % (USERNAME, USER_ID)
print(sql)
cur.execute(sql)
result = cur.fetchall()
print(result)
if len(result) == 0:
isfollow = '0'
else:
isfollow = '1'
# 查询USERNAME是否点赞了CONTENT_ID
sql = '''SELECT CONTENT_ID,USER_ID FROM AGREE WHERE CONTENT_ID=%s AND USER_ID='%s'
''' % (CONTENT_ID, USERNAME)
print(sql)
cur.execute(sql)
result = cur.fetchall()
if len(result) == 0:
isagree = '0'
else:
isagree = '1'
# 查询USERNAME是否收藏了CONTENT_ID
sql = '''SELECT CONTENT_ID,USER_ID FROM COLLECT WHERE CONTENT_ID=%s AND USER_ID='%s'
''' % (CONTENT_ID, USERNAME)
print(sql)
cur.execute(sql)
result = cur.fetchall()
if len(result) == 0:
iscollect = '0'
else:
iscollect = '1'
# 查询
# d.关闭数据库连接
database.close()
print("[阅读指令]已经关闭WHXD数据库连接!")
return HttpResponse('ok:' + isfollow + isagree + iscollect)
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def worlddt(request):
# 4.全站动态列表请求指令处理
if request.method == 'POST':
print("[指令]全站动态列表")
elif request.method == 'GET':
print("[指令]全站动态列表")
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求全站动态列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='动态' ORDER BY DATE DESC
'''
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求全站动态列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("全站动态列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def worldxm(request):
# 5.全站项目列表指令处理
if request.method == 'POST':
print("[指令]全站项目列表")
elif request.method == 'GET':
print("[指令]全站项目列表")
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求全站项目列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='项目' ORDER BY DATE DESC
'''
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求全站项目列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("全站项目列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def worldwz(request):
# 6.全站文章列表指令处理
if request.method == 'POST':
print("[指令]全站文章列表")
elif request.method == 'GET':
print("[指令]全站文章列表")
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求全站文章列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='文章' ORDER BY DATE DESC
'''
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求全站文章列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("全站文章列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def worldfield(request):
FIELD_ID = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]领域列表")
FIELD_ID = request.POST.get('field_id')
elif request.method == 'GET':
print("[指令]领域列表")
FIELD_ID = request.GET.get('field_id')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求领域列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE FIELD_ID=%s ORDER BY DATE DESC
''' % FIELD_ID
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求领域列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("领域列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def follow(request):
# 14.某用户关注他人指令处理
USERNAME = ''
USER_ID = ''
if request.method == 'POST':
print("[指令]某用户关注他人")
print("username:", request.POST.get('username'))
print("USER_ID:", request.POST.get('user_id'))
USERNAME = request.POST.get('username')
USER_ID = request.POST.get('user_id')
elif request.method == 'GET':
print("[指令]某用户关注他人")
print("username:", request.GET.get('username'))
print("USER_ID:", request.GET.get('user_id'))
USERNAME = request.GET.get('username')
USER_ID = request.GET.get('user_id')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[关注他人]已经连接到WHXD数据库!")
# 向该用户的关注表中写入数据
sql = '''
INSERT INTO %s_FOLLOW (FOLLOW_ID) VALUE('%s')
''' % (USERNAME, USER_ID)
cur.execute(sql)
database.commit()
# 向被关注人的粉丝表中写入数据
sql = '''
INSERT INTO %s_FANS (FANS_ID) VALUE('%s')
''' % (USER_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[关注他人]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def unfollow(request):
# 15.某用户取消关注他人指令处理
USERNAME = ''
USER_ID = ''
if request.method == 'POST':
print("[指令]某用户取消关注他人")
print("username:", request.POST.get('username'))
print("USER_ID:", request.POST.get('user_id'))
USERNAME = request.POST.get('username')
USER_ID = request.POST.get('user_id')
elif request.method == 'GET':
print("[指令]某用户取消关注他人")
print("username:", request.GET.get('username'))
print("USER_ID:", request.GET.get('user_id'))
USERNAME = request.GET.get('username')
USER_ID = request.GET.get('user_id')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[取消关注他人]已经连接到WHXD数据库!")
# 从该用户的关注表中删除数据
sql = '''
DELETE FROM %s_FOLLOW WHERE FOLLOW_ID='%s'
''' % (USERNAME, USER_ID)
cur.execute(sql)
database.commit()
# 判断他人粉丝表是否存在
sql = '''
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='%s_FANS'
''' % USER_ID
cur.execute(sql)
result = cur.fetchall()
if len(result) != 0:
# 从被关注人的粉丝表中删除数据
sql = '''
DELETE FROM %s_FANS WHERE FANS_ID='%s'
''' % (USER_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[取消关注他人]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def collect(request):
USERNAME = ''
CONTENT_ID = ''
TIME = ''
# 16.某用户收藏内容指令处理
# 请求领域数据
if request.method == 'POST':
print("[指令]某用户收藏内容")
print("username:", request.POST.get('username'))
print("contentid:", request.POST.get('contentid'))
print("time:", request.POST.get('time'))
USERNAME = request.POST.get('username')
CONTENT_ID = request.POST.get('contentid')
TIME = request.POST.get('time')
elif request.method == 'GET':
print("[指令]某用户收藏内容")
print("username:", request.GET.get('username'))
print("contentid:", request.GET.get('contentid'))
print("time:", request.GET.get('time'))
USERNAME = request.GET.get('username')
CONTENT_ID = request.GET.get('contentid')
TIME = request.GET.get('time')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[收藏内容]已经连接到WHXD数据库!")
sql = '''
INSERT INTO COLLECT (TIME,CONTENT_ID,USER_ID) VALUE('%s',%s,'%s')
''' % (TIME, CONTENT_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[收藏内容]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def uncollect(request):
USERNAME = ''
CONTENT_ID = ''
TIME = ''
# 17.某用户取消收藏内容指令处理
# 请求领域数据
if request.method == 'POST':
print("[指令]某用户取消收藏内容")
print("username:", request.POST.get('username'))
print("contentid:", request.POST.get('contentid'))
print("time:", request.POST.get('time'))
USERNAME = request.POST.get('username')
CONTENT_ID = request.POST.get('contentid')
TIME = request.POST.get('time')
elif request.method == 'GET':
print("[指令]某用户取消收藏内容")
print("username:", request.GET.get('username'))
print("contentid:", request.GET.get('contentid'))
print("time:", request.GET.get('time'))
USERNAME = request.GET.get('username')
CONTENT_ID = request.GET.get('contentid')
TIME = request.GET.get('time')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[取消收藏内容]已经连接到WHXD数据库!")
sql = '''
DELETE FROM COLLECT WHERE CONTENT_ID=%s AND USER_ID = '%s'
''' % (CONTENT_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[取消收藏内容]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def agree(request):
USERNAME = ''
CONTENT_ID = ''
TIME = ''
# 20.某用户点赞内容指令处理
# 请求领域数据
if request.method == 'POST':
print("[指令]某用户点赞内容")
print("username:", request.POST.get('username'))
print("contentid:", request.POST.get('contentid'))
print("time:", request.POST.get('time'))
USERNAME = request.POST.get('username')
CONTENT_ID = request.POST.get('contentid')
TIME = request.POST.get('time')
elif request.method == 'GET':
print("[指令]某用户点赞内容")
print("username:", request.GET.get('username'))
print("contentid:", request.GET.get('contentid'))
print("time:", request.GET.get('time'))
USERNAME = request.GET.get('username')
CONTENT_ID = request.GET.get('contentid')
TIME = request.GET.get('time')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[点赞内容]已经连接到WHXD数据库!")
sql = '''
INSERT INTO AGREE (TIME,CONTENT_ID,USER_ID) VALUE('%s',%s,'%s')
''' % (TIME, CONTENT_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[点赞内容]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def unagree(request):
USERNAME = ''
CONTENT_ID = ''
TIME = ''
# 20.某用户点赞内容指令处理
# 请求领域数据
if request.method == 'POST':
print("[指令]某用户取消点赞内容")
print("username:", request.POST.get('username'))
print("contentid:", request.POST.get('contentid'))
print("time:", request.POST.get('time'))
USERNAME = request.POST.get('username')
CONTENT_ID = request.POST.get('contentid')
TIME = request.POST.get('time')
elif request.method == 'GET':
print("[指令]某用户取消点赞内容")
print("username:", request.GET.get('username'))
print("contentid:", request.GET.get('contentid'))
print("time:", request.GET.get('time'))
USERNAME = request.GET.get('username')
CONTENT_ID = request.GET.get('contentid')
TIME = request.GET.get('time')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[取消点赞内容]已经连接到WHXD数据库!")
sql = '''
DELETE FROM AGREE WHERE CONTENT_ID=%s AND USER_ID = '%s'
''' % (CONTENT_ID, USERNAME)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[取消点赞内容]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def pushcontent(request):
USERNAME = ''
TYPE = ''
FIELD_ID = ''
DATE = ''
DETAIL = ''
TITLE = ''
NODEONE = ''
NODETWO = ''
NODETHREE = ''
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[上传内容指令]已经连接到WHXD数据库!")
# 22.某用户发布内容指令处理
if request.method == 'POST':
type = request.POST.get('type')
if type == '0':
print("[指令]某用户发布[动态]内容")
print("username:", request.POST.get('username'))
print("type: 动态")
print("field:", request.POST.get('field'))
print("time:", request.POST.get('time'))
print("detail:", request.POST.get('detail'))
USERNAME = request.POST.get('username')
TYPE = "动态"
FIELD_ID = request.POST.get('field')
DATE = request.POST.get('time')
DETAIL = request.POST.get('detail')
DETAIL = DETAIL.replace("\n", "\\\\n")
print(DETAIL)
DETAIL = '{"detail":"' + DETAIL + '"' + '}'
print(DETAIL)
elif type == '1':
print("[指令]某用户发布[项目]内容")
print("username:", request.POST.get('username'))
print("type: 项目")
print("field:", request.POST.get('field'))
print("time:", request.POST.get('time'))
print('title:', request.POST.get('title'))
print('nodeone', request.POST.get('nodeone'))
print('nodetwo', request.POST.get('nodetwo'))
print('nodethree', request.POST.get('nodethree'))
print("detail:", request.POST.get('detail'))
USERNAME = request.POST.get('username')
TYPE = "项目"
FIELD_ID = request.POST.get('field')
DATE = request.POST.get('time')
DETAIL = request.POST.get('detail')
TITLE = request.POST.get('title')
NODEONE = request.POST.get('nodeone')
NODETWO = request.POST.get('nodetwo')
NODETHREE = request.POST.get('nodethree')
DETAIL = DETAIL.replace("\n", "\\\\n")
DETAIL = '{"title":"' + TITLE + '"' + \
',"nodeone":"' + NODEONE + '"' + \
',"nodetwo":"' + NODETWO + '"' + \
',"nodethree":"' + NODETHREE + '"' + \
',"detail":"' + DETAIL + '"' + \
'}'
print(DETAIL)
elif type == '2':
print("[指令]某用户发布[文章]内容")
print("username:", request.POST.get('username'))
print("type: 文章")
print("field:", request.POST.get('field'))
print("time:", request.POST.get('time'))
print("detail:", request.POST.get('detail'))
USERNAME = request.POST.get('username')
TYPE = "文章"
FIELD_ID = request.POST.get('field')
DATE = request.POST.get('time')
DETAIL = request.POST.get('detail')
DETAIL = DETAIL.replace("\n", "\\\\n")
print(DETAIL)
DETAIL = '{"detail":"' + DETAIL + '"' + '}'
print(DETAIL)
elif request.method == 'GET':
type = request.GET.get('type')
if type == '0':
print("[指令]某用户发布[动态]内容")
print("username:", request.GET.get('username'))
print("type: 动态")
print("field:", request.GET.get('field'))
print("time:", request.GET.get('time'))
print("detail:", request.GET.get('detail'))
USERNAME = request.GET.get('username')
TYPE = "动态"
FIELD_ID = request.GET.get('field')
DATE = request.GET.get('time')
DETAIL = request.GET.get('detail')
DETAIL = DETAIL.replace("\n", "\\\\n")
print(DETAIL)
DETAIL = '{"detail":"' + DETAIL + '"' + '}'
print(DETAIL)
elif type == '1':
print("[指令]某用户发布[项目]内容")
print("username:", request.GET.get('username'))
print("type: 项目")
print("field:", request.GET.get('field'))
print("time:", request.GET.get('time'))
print('title:', request.GET.get('title'))
print('nodeone', request.GET.get('nodeone'))
print('nodetwo', request.GET.get('nodetwo'))
print('nodethree', request.GET.get('nodethree'))
print("detail:", request.GET.get('detail'))
USERNAME = request.GET.get('username')
TYPE = "项目"
FIELD_ID = request.GET.get('field')
DATE = request.GET.get('time')
DETAIL = request.GET.get('detail')
TITLE = request.GET.get('title')
NODEONE = request.GET.get('nodeone')
NODETWO = request.GET.get('nodetwo')
NODETHREE = request.GET.get('nodethree')
DETAIL = DETAIL.replace("\n", "\\\\n")
DETAIL = '{"title":"' + TITLE + '"' + \
',"nodeone":"' + NODEONE + '"' + \
',"nodetwo":"' + NODETWO + '"' + \
',"nodethree":"' + NODETHREE + '"' + \
',"detail":"' + DETAIL + '"' + \
'}'
print(DETAIL)
elif type == '2':
print("[指令]某用户发布[文章]内容")
print("username:", request.GET.get('username'))
print("type: 文章")
print("field:", request.GET.get('field'))
print("time:", request.GET.get('time'))
print("detail:", request.GET.get('detail'))
USERNAME = request.GET.get('username')
TYPE = "文章"
FIELD_ID = request.GET.get('field')
DATE = request.GET.get('time')
DETAIL = request.GET.get('detail')
DETAIL = DETAIL.replace("\n", "\\\\n")
print(DETAIL)
DETAIL = '{"detail":"' + DETAIL + '"' + '}'
print(DETAIL)
content_insertsql = '''
INSERT INTO USER_CONTENTS (TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID) VALUE('%s','%s',0,'%s','%s',%s)
''' % (TYPE, DATE, DETAIL, USERNAME, FIELD_ID)
# c.使用execute()方法执行SQL语句
cur.execute(content_insertsql)
database.commit()
# d.关闭数据库连接
database.close()
print("[上传内容指令]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def deleteusercontent(request):
USERNAME = ''
TYPE = ''
CONTENTID = ''
if request.method == 'POST':
print("[指令]删除用户内容")
USERNAME = request.POST.get('username')
TYPE = request.POST.get('type')
CONTENTID = request.POST.get('contentid')
elif request.method == 'GET':
print("[指令]删除用户内容")
USERNAME = request.GET.get('username')
TYPE = request.GET.get('type')
CONTENTID = request.GET.get('contentid')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[删除用户创作内容]已经连接到WHXD数据库!")
sql = '''
DELETE FROM USER_CONTENTS WHERE CONTENT_ID=%s AND USER_ID='%s'
''' % (CONTENTID, USERNAME)
print(sql)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[删除用户创作内容]已经关闭WHXD数据库连接!")
return HttpResponse('OK')
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def message(request):
USERNAME = ''
MESSAGETYPE = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]消息列表")
USERNAME = request.POST.get('username')
MESSAGETYPE = request.POST.get('messagetype')
elif request.method == 'GET':
print("[指令]消息列表")
USERNAME = request.GET.get('username')
MESSAGETYPE = request.GET.get('messagetype')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求消息列表]已经连接到WHXD数据库!")
sql = ''
if MESSAGETYPE == 'AGREE' or MESSAGETYPE == 'COLLECT':
sql = '''
SELECT %s.USER_ID,%s.CONTENT_ID FROM %s,USER_CONTENTS
WHERE %s.CONTENT_ID=USER_CONTENTS.CONTENT_ID AND USER_CONTENTS.USER_ID = '%s'
''' % (MESSAGETYPE, MESSAGETYPE, MESSAGETYPE, MESSAGETYPE, USERNAME)
else:
sql = '''
SELECT DISCUSS.USER_ID,DISCUSS.CONTENT_ID,DISCUSS.DETAIL FROM DISCUSS,USER_CONTENTS
WHERE DISCUSS.CONTENT_ID=USER_CONTENTS.CONTENT_ID AND USER_CONTENTS.USER_ID = '%s'
''' % USERNAME
print(sql)
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求领域列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("领域列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
backjson['sum'] = result_len
if MESSAGETYPE == 'AGREE':
for i in range(0, result_len):
record = result[i][0] + "点赞你内容:" + str(result[i][1])
backjson[str(i)] = record
elif MESSAGETYPE == 'COLLECT':
for i in range(0, result_len):
record = result[i][0] + "收藏你内容:" + str(result[i][1])
backjson[str(i)] = record
else:
for i in range(0, result_len):
record = result[i][0] + "评论你内容:" + str(result[i][1]) + ",评论:" + result[i][2]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def usercontentlist(request):
USERNAME = ''
TYPE = ''
# 7.某用户动态列表请求指令处理
if request.method == 'POST':
print("[指令]用户内容列表")
USERNAME = request.POST.get('username')
TYPE = request.POST.get('type')
elif request.method == 'GET':
print("[指令]用户内容列表")
USERNAME = request.GET.get('username')
TYPE = request.GET.get('type')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
if TYPE == 'dtlist':
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求用户动态列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='动态' AND USER_ID='%s' ORDER BY DATE DESC
''' % USERNAME
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求用户动态列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("用户动态列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
elif TYPE == 'xmlist':
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[用户项目列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='项目' AND USER_ID='%s' ORDER BY DATE DESC
''' % USERNAME
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[用户项目列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("用户项目列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
elif TYPE == 'wzlist':
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[用户文章列表]已经连接到WHXD数据库!")
sql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE TYPE='文章' AND USER_ID='%s' ORDER BY DATE DESC
''' % USERNAME
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[用户文章列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("用户文章列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
for j in range(0, len(result[i])):
if j == 2:
record[table_fiels[j]] = result[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = result[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
elif TYPE == 'collectlist':
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[用户收藏列表]已经连接到WHXD数据库!")
# 从收藏列表中找到USERNAME的收藏记录的CONTENT_ID
sql = '''
SELECT CONTENT_ID FROM COLLECT WHERE USER_ID='%s'
''' % USERNAME
print(sql)
cur.execute(sql)
result = cur.fetchall()
result_len = len(result)
finallresult = []
for i in range(0, result_len):
# 从USER_CONTENTS表里查出改CONTENT_ID的详细信息
tsql = '''
SELECT CONTENT_ID,TYPE,DATE,READVALUE,DETAIL,USER_ID,FIELD_ID FROM USER_CONTENTS
WHERE CONTENT_ID=%s
''' % result[i][0]
print(tsql)
cur.execute(tsql)
tresult = cur.fetchall()
finallresult.append(tresult[0])
# d.关闭数据库连接
database.close()
print("[用户收藏列表]已经关闭WHXD数据库连接!")
finallresult_len = len(finallresult)
if finallresult_len == 0:
print("用户收藏列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
table_fiels = ['CONTENT_ID', 'TYPE', 'DATE', 'READVALUE', 'DETAIL', 'USER_ID', 'FIELD_ID']
backjson['sum'] = finallresult_len
for i in range(0, finallresult_len):
record = {}
for j in range(0, len(finallresult[i])):
if j == 2:
record[table_fiels[j]] = finallresult[i][j].strftime('%Y-%m-%d %H:%M:%S')
else:
record[table_fiels[j]] = finallresult[i][j]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def pulldiscuss(request):
CONTENTID = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]评论列表")
CONTENTID = request.POST.get('contentid')
elif request.method == 'GET':
print("[指令]评论列表")
CONTENTID = request.GET.get('contentid')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求评论列表]已经连接到WHXD数据库!")
sql = '''SELECT TIME,DETAIL,USER_ID FROM DISCUSS WHERE CONTENT_ID=%s ORDER BY TIME DESC'''%CONTENTID
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[请求评论列表]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
print("内容评论列表查询为空!")
return HttpResponse("NULL")
else:
backjson = {}
backjson['sum'] = result_len
for i in range(0, result_len):
record = {}
record['detail'] = result[i][0].strftime('%Y-%m-%d %H:%M:%S')+"\n"+result[i][1]+"\n"+result[i][2]
backjson[str(i)] = record
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def pushdiscuss(request):
USERNAME = ''
CONTENTID = ''
DETAIL = ''
TIME = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]发布评论")
USERNAME = request.POST.get('username')
CONTENTID = request.POST.get('contentid')
DETAIL = request.POST.get('detail')
TIME = request.POST.get('time')
elif request.method == 'GET':
print("[指令]发布评论")
USERNAME = request.GET.get('username')
CONTENTID = request.GET.get('contentid')
DETAIL = request.GET.get('detail')
TIME = request.GET.get('time')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[发布评论]已经连接到WHXD数据库!")
sql = '''
INSERT INTO DISCUSS (TIME,DETAIL,CONTENT_ID,USER_ID) VALUE('%s','%s',%s,'%s')
'''%(TIME,DETAIL,CONTENTID,USERNAME)
print(sql)
cur.execute(sql)
database.commit()
# d.关闭数据库连接
database.close()
print("[发布评论]已经关闭WHXD数据库连接!")
return HttpResponse("OK")
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def count(request):
USERNAME = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]发布评论")
USERNAME = request.POST.get('username')
elif request.method == 'GET':
print("[指令]发布评论")
USERNAME = request.GET.get('username')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[请求计数]已经连接到WHXD数据库!")
sum =[]
sql = ''
result = ''
sql = '''SELECT COUNT(*) FROM %s_FOLLOW'''%USERNAME
cur.execute(sql)
result = cur.fetchall()
result = str(result[0][0])
print('sum:',result)
sum.append(result)
sql = '''SELECT COUNT(*) FROM %s_FANS'''%USERNAME
cur.execute(sql)
result = cur.fetchall()
result = str(result[0][0])
print('sum:',result)
sum.append(result)
sql = '''
SELECT READVALUE FROM USER_CONTENTS WHERE USER_ID='%s'
'''%USERNAME
cur.execute(sql)
result = cur.fetchall()
tsum = 0
for i in range(0,len(result)):
tsum = tsum + int(result[i][0])
result = str(tsum)
print('sum:',result)
sum.append(result)
# d.关闭数据库连接
database.close()
print("[请求计数]已经关闭WHXD数据库连接!")
return HttpResponse('OK:'+sum[0]+','+sum[1]+','+sum[2])
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def searchuser(request):
USERNAME = ''
OBJECTNAME = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]搜索用户")
USERNAME = request.POST.get('username')
OBJECTNAME = request.POST.get('objectname')
elif request.method == 'GET':
print("[指令]搜索用户")
USERNAME = request.GET.get('username')
OBJECTNAME = request.GET.get('objectname')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[搜索用户]已经连接到WHXD数据库!")
sql = ''
result = ''
sql = '''SELECT USER_ID FROM USERS WHERE USER_ID='%s'
'''%OBJECTNAME
print(sql)
cur.execute(sql)
result = cur.fetchall()
if len(result) == 0:
# d.关闭数据库连接
database.close()
print("[搜索用户]已经关闭WHXD数据库连接!")
return HttpResponse('NULL')
else:
sql = '''
SELECT FOLLOW_ID FROM %s_FOLLOW WHERE FOLLOW_ID='%s'
'''%(USERNAME.upper(),OBJECTNAME)
cur.execute(sql)
result = cur.fetchall()
print(sql)
# d.关闭数据库连接
database.close()
print("[搜索用户]已经关闭WHXD数据库连接!")
if len(result) == 0:
return HttpResponse('OK:'+OBJECTNAME+'[关注]')
else:
return HttpResponse('OK:' + OBJECTNAME + '[已关注]')
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def followlist(request):
USERNAME = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]用户关注列表请求")
USERNAME = request.POST.get('username')
elif request.method == 'GET':
print("[指令]用户关注列表请求")
USERNAME = request.GET.get('username')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[关注列表请求]已经连接到WHXD数据库!")
sql = '''SELECT FOLLOW_ID FROM %s_FOLLOW'''%USERNAME
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[关注列表请求]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
return HttpResponse("NULL")
else:
backjson = {}
backjson['sum'] = result_len
for i in range(0,result_len):
backjson[str(i)] = result[i][0]+'[已关注]'
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
@csrf_exempt
def fanslist(request):
USERNAME = ''
# 请求领域数据
if request.method == 'POST':
print("[指令]用户粉丝列表请求")
USERNAME = request.POST.get('username')
elif request.method == 'GET':
print("[指令]用户粉丝列表请求")
USERNAME = request.GET.get('username')
# a.打开数据库连接
database = pymysql.connect(host='localhost'
, user='root'
, password='000000'
, port=3306
, database='WHXD')
# b.使用cursor()方法创建一个游标对象cur
cur = database.cursor()
print("[粉丝列表请求]已经连接到WHXD数据库!")
sql = '''SELECT FANS_ID FROM %s_FANS'''%USERNAME
cur.execute(sql)
result = cur.fetchall()
# d.关闭数据库连接
database.close()
print("[粉丝列表请求]已经关闭WHXD数据库连接!")
result_len = len(result)
if result_len == 0:
return HttpResponse("NULL")
else:
backjson = {}
backjson['sum'] = result_len
for i in range(0,result_len):
backjson[str(i)] = result[i][0]
print("backjson is:", backjson)
return HttpResponse(json.dumps(backjson, ensure_ascii=False))
# --------------------------已完成-分割线----------------------#
def index(request):
# 测试页面
return HttpResponse("OK")
"""whxd URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('register/',views.register),
path('login/',views.login),
path('destory/',views.destory),
path('worlddt/',views.worlddt),
path('worldxm/',views.worldxm),
path('worldwz/',views.worldwz),
path('worldfield/',views.worldfield),
path('usercontentlist/',views.usercontentlist),
path('message/',views.message),
path('followlist/', views.followlist),
path('fanslist/', views.fanslist),
path('pushcontent/', views.pushcontent),
path('deleteusercontent/', views.deleteusercontent),
path('read/',views.read),
path('follow/', views.follow),
path('unfollow/', views.unfollow),
path('agree/', views.agree),
path('unagree/', views.unagree),
path('pulldiscuss/', views.pulldiscuss),
path('pushdiscuss/', views.pushdiscuss),
path('collect/',views.collect),
path('uncollect/',views.uncollect),
path('count/',views.count),
path('searchuser/',views.searchuser),
path('index/',views.index) #测试页面
]
【APP运行视频链接已上传B站】https://www.bilibili.com/video/BV1iZ4y187c7
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。