This commit is contained in:
GatsbyH 2024-02-12 21:12:32 +08:00
parent 41c1eea1c3
commit 4db10c4fe2
27 changed files with 888 additions and 98 deletions

View File

@ -4,8 +4,9 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="17" /> <option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ASMIdeaPluginConfiguration"> <component name="ASMIdeaPluginConfiguration">
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" /> <asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
@ -50,7 +49,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="11" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -8,7 +8,7 @@ spring:
master: master:
url: jdbc:mysql://localhost:3306/jizhang?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3306/jizhang?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: 336699 password: jieyi123
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭

View File

@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers("/login", "/register", "/captchaImage").permitAll() .antMatchers("/login", "/register", "/captchaImage").permitAll()
// 静态资源可匿名访问 // 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/app/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证 // 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()

View File

@ -1,10 +1,20 @@
package com.ruoyi.app.controller; package com.ruoyi.app.controller;
import com.ruoyi.app.system.domain.Accounttb;
import com.ruoyi.app.system.service.IAccounttbService;
import com.ruoyi.app.system.service.ICategoryService; import com.ruoyi.app.system.service.ICategoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Category;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -17,6 +27,9 @@ import org.springframework.web.bind.annotation.RestController;
public class AppCategoryController { public class AppCategoryController {
@Autowired @Autowired
private ICategoryService categoryService; private ICategoryService categoryService;
@Autowired
private IAccounttbService accounttbService;
@PutMapping @PutMapping
private AjaxResult addCategory(@RequestBody com.ruoyi.system.domain.Category category){ private AjaxResult addCategory(@RequestBody com.ruoyi.system.domain.Category category){
Long userId = SecurityUtils.getLoginUser().getUser().getUserId(); Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
@ -24,4 +37,28 @@ public class AppCategoryController {
return AjaxResult.success( categoryService.insertCategory(category)); return AjaxResult.success( categoryService.insertCategory(category));
} }
@PostMapping
public AjaxResult add(@RequestBody Accounttb accounttb)
{
return AjaxResult.success(accounttbService.insertAccounttb(accounttb));
}
@GetMapping("/list")
public AjaxResult list(Accounttb accounttb)
{
List<Accounttb> list = accounttbService.selectAccounttbList(accounttb);
return AjaxResult.success(list);
}
@GetMapping("/getSumMoneyOneDay")
public AjaxResult getSumMoneyOneDay(Accounttb accounttb)
{
Float sumMoneyOneDay = accounttbService.getSumMoneyOneDay(accounttb);
return AjaxResult.success(sumMoneyOneDay);
}
} }

View File

@ -40,7 +40,7 @@ public class AppUserController {
AjaxResult ajax = new AjaxResult(); AjaxResult ajax = new AjaxResult();
String token = loginService.loginNoCode(loginBody.getUsername(),loginBody.getPassword()); String token = loginService.loginNoCode(loginBody.getUsername(),loginBody.getPassword());
ajax.put(Constants.TOKEN,token); ajax.put(Constants.TOKEN,token);
return success(ajax); return AjaxResult.success("登陆成功",token);
} }
@ -63,6 +63,7 @@ public class AppUserController {
SysUser currentUser = SecurityUtils.getLoginUser().getUser(); SysUser currentUser = SecurityUtils.getLoginUser().getUser();
currentUser.setNickName(user.getNickName()); currentUser.setNickName(user.getNickName());
currentUser.setEmail(user.getEmail()); currentUser.setEmail(user.getEmail());
currentUser.setPassword(user.getPassword());
currentUser.setPhonenumber(user.getPhonenumber()); currentUser.setPhonenumber(user.getPhonenumber());
currentUser.setSex(user.getSex()); currentUser.setSex(user.getSex());
user.setUserId(userId); user.setUserId(userId);

View File

@ -37,6 +37,7 @@ public class Accounttb extends BaseEntity
private Long money; private Long money;
/** $column.columnComment */ /** $column.columnComment */
@JsonFormat(pattern = "yyyy年MM月dd日 HH:mm")
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
private Date time; private Date time;

View File

@ -60,4 +60,6 @@ public interface AccounttbMapper
* @return 结果 * @return 结果
*/ */
public int deleteAccounttbByIds(Long[] ids); public int deleteAccounttbByIds(Long[] ids);
Float getSumMoneyOneDay(Accounttb accounttb);
} }

View File

@ -60,4 +60,6 @@ public interface IAccounttbService
* @return 结果 * @return 结果
*/ */
public int deleteAccounttbById(Long id); public int deleteAccounttbById(Long id);
Float getSumMoneyOneDay(Accounttb accounttb);
} }

View File

@ -93,4 +93,9 @@ public class AccounttbServiceImpl implements IAccounttbService
{ {
return accounttbMapper.deleteAccounttbById(id); return accounttbMapper.deleteAccounttbById(id);
} }
@Override
public Float getSumMoneyOneDay(Accounttb accounttb) {
return accounttbMapper.getSumMoneyOneDay(accounttb);
}
} }

View File

@ -40,6 +40,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectAccounttbVo"/> <include refid="selectAccounttbVo"/>
where id = #{id} where id = #{id}
</select> </select>
<select id="getSumMoneyOneDay" resultType="float">
SELECT SUM(money) AS total
FROM accounttb
WHERE
<trim prefix="(" suffix=")" suffixOverrides="AND">
<if test="year != null">year = #{year} AND</if>
<if test="month != null">month = #{month} AND</if>
<if test="day != null">day = #{day} AND</if>
<if test="kind != null">kind = #{kind} AND</if>
</trim>
</select>
<insert id="insertAccounttb" parameterType="Accounttb" useGeneratedKeys="true" keyProperty="id"> <insert id="insertAccounttb" parameterType="Accounttb" useGeneratedKeys="true" keyProperty="id">
insert into accounttb insert into accounttb

View File

@ -39,6 +39,11 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.4.1' implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1' implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'com.github.xuexiangjys:XHttp2:1.0.4'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.12'
implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' // implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
@ -46,5 +51,12 @@ dependencies {
implementation 'me.majiajie:pager-bottom-tab-strip:2.4.0' implementation 'me.majiajie:pager-bottom-tab-strip:2.4.0'
implementation 'com.blankj:utilcodex:1.31.1' implementation 'com.blankj:utilcodex:1.31.1'
implementation 'com.github.xuexiangjys:XHttp2:2.0.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
} }

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tally" > package="com.example.tally" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application <application
android:usesCleartextTraffic="true"
android:name=".UniteApp" android:name=".UniteApp"
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/logo" android:icon="@drawable/logo"
@ -10,6 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Tally" > android:theme="@style/Theme.Tally" >
<activity <activity
android:name=".XinxiActivity" android:name=".XinxiActivity"
android:exported="false" /> android:exported="false" />

View File

@ -3,8 +3,11 @@ package com.example.tally;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
@ -14,6 +17,10 @@ import com.example.tally.adapter.AccountAdapter;
import com.example.tally.db.AccountBean; import com.example.tally.db.AccountBean;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.example.tally.utils.CalendarDialog; import com.example.tally.utils.CalendarDialog;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -74,10 +81,34 @@ public class HistoryActivity extends AppCompatActivity {
/* 获取指定年份月份收支情况的列表*/ /* 获取指定年份月份收支情况的列表*/
private void loadData(int year,int month) { private void loadData(int year,int month) {
List<AccountBean> list = DBManager.getAccountListOneMonthFromAccounttb(year, month);//两个参数是指定的年份月份
XHttpSDK.setSuccessCode(200);
SharedPreferences sharedPreferences = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
XHttp.get("/app/Category/list")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<List<AccountBean>>() {
@Override
public void onSuccess(List<AccountBean> response) throws Throwable {
if (response != null && response.size() > 0) {
mDatas.clear(); mDatas.clear();
mDatas.addAll(list); mDatas.addAll(response);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
Log.e("YourClass", "getHistoryInfo success, response: " + response.toString());
}
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getHistoryInfo error: " + e.getMessage());
}
});
} }
private void initTime() { private void initTime() {

View File

@ -3,11 +3,13 @@ package com.example.tally;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -16,6 +18,17 @@ import android.widget.RadioGroup;
import android.widget.Toast; import android.widget.Toast;
import com.example.tally.db.DBOpenHelper; import com.example.tally.db.DBOpenHelper;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xhttp2.model.HttpHeaders;
import org.json.JSONException;
import org.json.JSONObject;
import okhttp3.FormBody;
import okhttp3.RequestBody;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener { public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
EditText ed_name; EditText ed_name;
@ -70,6 +83,42 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
Toast.makeText(LoginActivity.this, "请输入密码", Toast.LENGTH_LONG).show(); Toast.makeText(LoginActivity.this, "请输入密码", Toast.LENGTH_LONG).show();
return; return;
} }
JSONObject requestBody = new JSONObject();
try {
requestBody.put("username", name);
requestBody.put("password", password);
} catch (JSONException e) {
throw new RuntimeException(e);
}
String requestBodyString = requestBody.toString();
XHttpSDK.setSuccessCode(200);
XHttp.post("/app/user/login")
// .params("username", name)
// .params("password", password)
.upJson(requestBodyString)
.execute(new SimpleCallBack<String>() {
@Override
public void onSuccess(String result){
SharedPreferences sp = getSharedPreferences("myPrefs",MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("token",result);
editor.apply();
Log.e("TAG", "成功:" + result );
Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
}
@Override
public void onError(ApiException e) {
Log.e("TAG", "登录失败:" + e.getMessage() + ", Code: " + e.getCode() );
}
});
// SharedPreferences sp = getSharedPreferences("regInfo",MODE_PRIVATE); // SharedPreferences sp = getSharedPreferences("regInfo",MODE_PRIVATE);
// String name1 = sp.getString("account",""); // String name1 = sp.getString("account","");
// String pass1 = sp.getString("password",""); // String pass1 = sp.getString("password","");
@ -80,32 +129,32 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
// startActivity(intent); // startActivity(intent);
// } // }
// 从数据库中国获取信息 // 从数据库中国获取信息
db = helper.getReadableDatabase(); // db = helper.getReadableDatabase();
//select * from where name="mark" // //select * from where name="mark"
Cursor cursor = db.query("user", null, "account=?", new String[]{name}, null, null, null); // Cursor cursor = db.query("user", null, "account=?", new String[]{name}, null, null, null);
// db.query("user",null,"name=?",new String[]{ed_name.getText().toString()},null,null,null); //// db.query("user",null,"name=?",new String[]{ed_name.getText().toString()},null,null,null);
if (cursor.getCount() > 0) { // if (cursor.getCount() > 0) {
cursor.moveToNext();//结果集中的指针指向下一个位置 // cursor.moveToNext();//结果集中的指针指向下一个位置
userName = cursor.getString(cursor.getColumnIndex("account")); // userName = cursor.getString(cursor.getColumnIndex("account"));
Password = cursor.getString(cursor.getColumnIndex("password")); // Password = cursor.getString(cursor.getColumnIndex("password"));
} // }
db.close(); // db.close();
if (name.equals(userName) && password.equals(Password)) { // if (name.equals(userName) && password.equals(Password)) {
Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_LONG).show(); // Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class); // Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent); // startActivity(intent);
SharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE); // SharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit(); // SharedPreferences.Editor editor = sp.edit();
editor.putString("account", name); // editor.putString("account", name);
editor.putString("password", password); // editor.putString("password", password);
editor.commit(); // editor.commit();
// Intent intent = getIntent(); //// Intent intent = getIntent();
// String name = intent.getStringExtra("name"); //// String name = intent.getStringExtra("name");
// Intent intent1 = new Intent(UserActivity.this,EditInfoActivity.class); //// Intent intent1 = new Intent(UserActivity.this,EditInfoActivity.class);
// intent1.putExtra("name",name); //// intent1.putExtra("name",name);
} else { // } else {
Toast.makeText(LoginActivity.this, "账号或密码错误", Toast.LENGTH_LONG).show(); // Toast.makeText(LoginActivity.this, "账号或密码错误", Toast.LENGTH_LONG).show();
} // }
break; break;
case R.id.btn_reg: case R.id.btn_reg:
Intent intent = new Intent(LoginActivity.this, RegistActivity.class); Intent intent = new Intent(LoginActivity.this, RegistActivity.class);

View File

@ -54,6 +54,7 @@ public class MainActivity extends AppCompatActivity{
} }
/** 初始化自带的View的方法*/ /** 初始化自带的View的方法*/
private void initView() { private void initView() {
mFragmentList = new ArrayList<>(); mFragmentList = new ArrayList<>();
mainBottomNavigationAdapter = new MainBottomNavigationAdapter(getSupportFragmentManager()); mainBottomNavigationAdapter = new MainBottomNavigationAdapter(getSupportFragmentManager());
viewPager = findViewById(R.id.viewpager); viewPager = findViewById(R.id.viewpager);

View File

@ -4,8 +4,11 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@ -15,6 +18,10 @@ import com.example.tally.db.DBManager;
import com.example.tally.frag_chart.IncomeChartFragment; import com.example.tally.frag_chart.IncomeChartFragment;
import com.example.tally.frag_chart.OutcomeChartFragment; import com.example.tally.frag_chart.OutcomeChartFragment;
import com.example.tally.utils.CalendarDialog; import com.example.tally.utils.CalendarDialog;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -31,7 +38,8 @@ public class MonthChartActivity extends AppCompatActivity {
private IncomeChartFragment incomChartFragment; private IncomeChartFragment incomChartFragment;
private OutcomeChartFragment outcomChartFragment; private OutcomeChartFragment outcomChartFragment;
private ChartVPAdapter chartVPAdapter; private ChartVPAdapter chartVPAdapter;
float inMoneyOneMonth=0;
float outMoneyOneMonth=0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -73,16 +81,74 @@ public class MonthChartActivity extends AppCompatActivity {
/* 统计某年某月的收支情况数据*/ /* 统计某年某月的收支情况数据*/
private void initStatistics(int year, int month) { private void initStatistics(int year, int month) {
float inMoneyOneMonth = DBManager.getSumMoneyOneMonth(year, month, 1); //收入总钱数 SharedPreferences sharedPreferences = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
float outMoneyOneMonth = DBManager.getSumMoneyOneMonth(year, month, 0); //支出总钱数 String token = sharedPreferences.getString("token", "");
XHttpSDK.setSuccessCode(200);
XHttp.get("/app/Category/getSumMoneyOneDay")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("kind",1)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
inMoneyOneMonth=response;
updateStatistics();
Log.e("YourClass", "getSumMoneyOneMonth incountItemOneMonth success, response: " + response.toString());
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getSumMoneyOneMonth error: " + e.getMessage());
}
});
XHttpSDK.setSuccessCode(200);
XHttp.get("/app/Category/getSumMoneyOneDay")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("kind",0)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
outMoneyOneMonth=response;
updateStatistics();
Log.e("YourClass", "getSumMoneyOneMonth outcountItemOneMonth success, response: " + response.toString());
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getSumMoneyOneMonth error: " + e.getMessage());
}
});
// float inMoneyOneMonth = DBManager.getSumMoneyOneMonth(year, month, 1); //收入总钱数
// float outMoneyOneMonth = DBManager.getSumMoneyOneMonth(year, month, 0); //支出总钱数
int incountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 1); //收入多少笔 int incountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 1); //收入多少笔
int outcountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 0); //支出多少笔 int outcountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 0); //支出多少笔
dateTv.setText(year+""+month+"月账单"); dateTv.setText(year+""+month+"月账单");
inTv.setText(""+incountItemOneMonth+"笔收入, ¥ "+inMoneyOneMonth); inTv.setText(""+incountItemOneMonth+"笔收入, ¥ "+inMoneyOneMonth);
outTv.setText(""+outcountItemOneMonth+"笔支出, ¥ "+outMoneyOneMonth); outTv.setText(""+outcountItemOneMonth+"笔支出, ¥ "+outMoneyOneMonth);
} }
private void updateStatistics() {
int incountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 1);
int outcountItemOneMonth = DBManager.getCountItemOneMonth(year, month, 0);
// 更新UI
runOnUiThread(new Runnable() {
@Override
public void run() {
dateTv.setText(year + "" + month + "月账单");
inTv.setText("" + incountItemOneMonth + "笔收入, ¥ " + inMoneyOneMonth);
outTv.setText("" + outcountItemOneMonth + "笔支出, ¥ " + outMoneyOneMonth);
}
});
}
/** 初始化时间的方法*/ /** 初始化时间的方法*/
private void initTime() { private void initTime() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();

View File

@ -13,6 +13,13 @@ import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.example.tally.db.DBOpenHelper; import com.example.tally.db.DBOpenHelper;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
public class RegistActivity extends AppCompatActivity implements View.OnClickListener { public class RegistActivity extends AppCompatActivity implements View.OnClickListener {
EditText ed_username,ed_userpwd,ed_userpwdr,ed_email,ed_phone; EditText ed_username,ed_userpwd,ed_userpwdr,ed_email,ed_phone;
@ -52,23 +59,51 @@ public class RegistActivity extends AppCompatActivity implements View.OnClickLis
if(!userPsd.equals(confirPsd)){ if(!userPsd.equals(confirPsd)){
Toast.makeText(RegistActivity.this,"两次输入的密码不一致,注册失败",Toast.LENGTH_LONG).show(); Toast.makeText(RegistActivity.this,"两次输入的密码不一致,注册失败",Toast.LENGTH_LONG).show();
}else { }else {
SharedPreferences sp = getSharedPreferences("regInfo",MODE_PRIVATE); JSONObject requestBody = new JSONObject();
SharedPreferences.Editor editor = sp.edit(); try {
editor.putString("account",userName); requestBody.put("username", userName);
editor.putString("password",userPsd); requestBody.put("password", userPsd);
editor.putString("email",userEmail); } catch (JSONException e) {
editor.putString("phone",userPhone); throw new RuntimeException(e);
editor.commit();//获取创建的数据库对象 }
db = helper.getWritableDatabase();//获取创建的数据库对象
ContentValues values = new ContentValues(); String requestBodyString = requestBody.toString();
values.put("account",userName); XHttpSDK.setSuccessCode(200);
values.put("password",userPsd); XHttp.post("/app/user/register")
values.put("email",userEmail); // .params("username", name)
values.put("phone",userPhone); // .params("password", password)
db.insert("user",null,values); .upJson(requestBodyString)
db.close(); .execute(new SimpleCallBack<String>() {
Log.i("animee","insertItemToUserb:ok!!!"); @Override
public void onSuccess(String result){
Toast.makeText(RegistActivity.this,"注册成功",Toast.LENGTH_LONG).show();//获取创建的数据库对象 Toast.makeText(RegistActivity.this,"注册成功",Toast.LENGTH_LONG).show();//获取创建的数据库对象
Log.e("TAG", "成功:" + result );
}
@Override
public void onError(ApiException e) {
Log.e("TAG", "注册失败:" + e.getMessage() + ", Code: " + e.getCode() );
}
});
// SharedPreferences sp = getSharedPreferences("regInfo",MODE_PRIVATE);
// SharedPreferences.Editor editor = sp.edit();
// editor.putString("account",userName);
// editor.putString("password",userPsd);
// editor.putString("email",userEmail);
// editor.putString("phone",userPhone);
// editor.commit();//获取创建的数据库对象
// db = helper.getWritableDatabase();//获取创建的数据库对象
// ContentValues values = new ContentValues();
// values.put("account",userName);
// values.put("password",userPsd);
// values.put("email",userEmail);
// values.put("phone",userPhone);
// db.insert("user",null,values);
// db.close();
// Log.i("animee","insertItemToUserb:ok!!!");
// Toast.makeText(RegistActivity.this,"注册成功",Toast.LENGTH_LONG).show();//获取创建的数据库对象
} }
break; break;
case R.id.BackLoginButton: case R.id.BackLoginButton:

View File

@ -3,6 +3,7 @@ package com.example.tally;
import android.app.Application; import android.app.Application;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.xuexiang.xhttp2.XHttpSDK;
/* 表示全局应用的类*/ /* 表示全局应用的类*/
public class UniteApp extends Application { public class UniteApp extends Application {
@ -11,6 +12,10 @@ public class UniteApp extends Application {
super.onCreate(); super.onCreate();
// 初始化数据库 // 初始化数据库
DBManager.initDB(getApplicationContext()); DBManager.initDB(getApplicationContext());
XHttpSDK.init(this);
//设置网络请求的全局基础地址
XHttpSDK.setBaseUrl("http://192.168.0.8:8831/");
} }
} }

View File

@ -3,17 +3,27 @@ package com.example.tally;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.example.tally.db.DBOpenHelper; import com.example.tally.db.DBOpenHelper;
import com.example.tally.entity.SysUser;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
public class XinxiActivity extends AppCompatActivity implements View.OnClickListener{ public class XinxiActivity extends AppCompatActivity implements View.OnClickListener{
EditText ed_username,ed_userpwd,ed_email,ed_phone; EditText ed_username,ed_userpwd,ed_email,ed_phone;
@ -50,26 +60,70 @@ public class XinxiActivity extends AppCompatActivity implements View.OnClickList
// ed_email.setText(sp.getString("email","")); // ed_email.setText(sp.getString("email",""));
// ed_phone.setText(sp.getString("phone","")); // ed_phone.setText(sp.getString("phone",""));
// //
String name = sp.getString("account",""); XHttpSDK.setSuccessCode(200);
db = helper.getReadableDatabase(); SharedPreferences sharedPreferences = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
Cursor cursor = db.query("user",null,"account=?",new String[]{name},null,null,null); String token = sharedPreferences.getString("token", "");
if(cursor.getCount()>0){ Log.e("缓存",token);
cursor.moveToNext(); XHttp.get("app/user")
ed_username.setText(cursor.getString(cursor.getColumnIndex("account"))); .headers("Authorization", "Bearer " + token)
ed_userpwd.setText(cursor.getString(cursor.getColumnIndex("password"))); .syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<SysUser>() {
@Override
public void onSuccess(SysUser result) {
Log.e("TAG", "查询结果:" + result );
ed_username.setText(result.getUserName());
// ed_userpwd.setText(result.getPassword());
// ed_PasswordR.setText(cursor.getString(cursor.getColumnIndex("password"))); // ed_PasswordR.setText(cursor.getString(cursor.getColumnIndex("password")));
ed_email.setText(cursor.getString(cursor.getColumnIndex("email"))); ed_email.setText(result.getEmail());
ed_phone.setText(cursor.getString(cursor.getColumnIndex("phone"))); ed_phone.setText(result.getPhonenumber());
}
db.close();
} }
@Override
public void onError(ApiException e) {
Log.e("TAG", "查询失败:" + e.getMessage() + ", Code: " + e.getCode() ); }
});
}
JSONObject requestBody = new JSONObject();
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String pp = ed_userpwd.getText().toString(); String pp = ed_userpwd.getText().toString();
if (pp.isEmpty()) { if (pp.isEmpty()) {
Toast.makeText(XinxiActivity.this, "密码不能为空,请输入", Toast.LENGTH_LONG).show(); Toast.makeText(XinxiActivity.this, "密码不能为空,请输入", Toast.LENGTH_LONG).show();
}else }else
try {
requestBody.put("nickName", ed_username.getText().toString());
requestBody.put("password", ed_userpwd.getText().toString());
requestBody.put("email", ed_email.getText().toString());
requestBody.put("phonenumber", ed_phone.getText().toString());
} catch (JSONException e) {
throw new RuntimeException(e);
}
SharedPreferences sharedPreferences = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
String requestBodyString = requestBody.toString();
XHttpSDK.setSuccessCode(200);
XHttp.post("/app/user")
.headers("Authorization", "Bearer " + token)
.upJson(requestBodyString)
.execute(new SimpleCallBack<Integer>() {
@Override
public void onSuccess(Integer result){
if (result > 0) {
Toast.makeText(XinxiActivity.this, "修改成功", Toast.LENGTH_LONG).show();
}
}
@Override
public void onError(ApiException e) {
Log.e("TAG", "登录失败:" + e.getMessage() + ", Code: " + e.getCode() );
}
});
db = helper.getWritableDatabase(); db = helper.getWritableDatabase();
values = new ContentValues(); values = new ContentValues();
values.put("password", ed_userpwd.getText().toString()); values.put("password", ed_userpwd.getText().toString());

View File

@ -1,13 +1,27 @@
package com.example.tally.db; package com.example.tally.db;
import static android.content.Context.MODE_PRIVATE;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.example.tally.LoginActivity;
import com.example.tally.MainActivity;
import com.example.tally.utils.FloatUtils; import com.example.tally.utils.FloatUtils;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -60,6 +74,8 @@ public class DBManager {
values.put("month",bean.getMonth()); values.put("month",bean.getMonth());
values.put("day",bean.getDay()); values.put("day",bean.getDay());
values.put("kind",bean.getKind()); values.put("kind",bean.getKind());
db.insert("accounttb",null,values); db.insert("accounttb",null,values);
Log.i("animee","insertItemToAccounttb:ok!!!"); Log.i("animee","insertItemToAccounttb:ok!!!");
} }

View File

@ -0,0 +1,201 @@
package com.example.tally.entity;
/**
* 用户对象 sys_user
*
* @author ruoyi
*/
public class SysUser
{
private static final long serialVersionUID = 1L;
/** 用户ID */
private Long userId;
/** 部门ID */
private Long deptId;
/** 用户账号 */
private String userName;
/** 用户昵称 */
private String nickName;
/** 用户邮箱 */
private String email;
/** 手机号码 */
private String phonenumber;
/** 用户性别 */
private String sex;
/** 用户头像 */
private String avatar;
/** 密码 */
private String password;
/** 帐号状态0正常 1停用 */
private String status;
/** 删除标志0代表存在 2代表删除 */
private String delFlag;
/** 最后登录IP */
private String loginIp;
public String getNickName()
{
return nickName;
}
public void setNickName(String nickName)
{
this.nickName = nickName;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getPhonenumber()
{
return phonenumber;
}
public void setPhonenumber(String phonenumber)
{
this.phonenumber = phonenumber;
}
public String getSex()
{
return sex;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getAvatar()
{
return avatar;
}
public void setAvatar(String avatar)
{
this.avatar = avatar;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public String getDelFlag()
{
return delFlag;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getLoginIp()
{
return loginIp;
}
public void setLoginIp(String loginIp)
{
this.loginIp = loginIp;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
@Override
public String toString() {
return "SysUser{" +
"userId=" + userId +
", deptId=" + deptId +
", userName='" + userName + '\'' +
", nickName='" + nickName + '\'' +
", email='" + email + '\'' +
", phonenumber='" + phonenumber + '\'' +
", sex='" + sex + '\'' +
", avatar='" + avatar + '\'' +
", password='" + password + '\'' +
", status='" + status + '\'' +
", delFlag='" + delFlag + '\'' +
", loginIp='" + loginIp + '\'' +
'}';
}
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
}

View File

@ -8,6 +8,7 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod; import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -33,6 +34,10 @@ import com.example.tally.db.AccountBean;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.example.tally.utils.BudgetDialog; import com.example.tally.utils.BudgetDialog;
import com.example.tally.utils.MoreDialog; import com.example.tally.utils.MoreDialog;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -54,6 +59,12 @@ public class MainFragment extends Fragment implements View.OnClickListener {
SharedPreferences preferences;//设置预算 SharedPreferences preferences;//设置预算
private Context mContext; private Context mContext;
float incomeOneDay=0;
float outcomeOneDay=0;
float incomeOneMonth=0;
float outcomeOneMonth=0;
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
super.onAttach(context); super.onAttach(context);
@ -187,32 +198,169 @@ public class MainFragment extends Fragment implements View.OnClickListener {
/* 设置头布局当中文本内容的显示*/ /* 设置头布局当中文本内容的显示*/
private void setTopTvShow() { private void setTopTvShow() {
//获取今日支出和收入总金额显示在view当中 //获取今日支出和收入总金额显示在view当中
float incomeOneDay = DBManager.getSumMoneyOneDay(year, month, day, 1); XHttpSDK.setSuccessCode(200);
float outcomeOneDay = DBManager.getSumMoneyOneDay(year, month, day, 0); Context context = getContext();
String infoOneDay = "今日支出 ¥"+outcomeOneDay+" 收入 ¥"+incomeOneDay; SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
topConTv.setText(infoOneDay); String token = sharedPreferences.getString("token", "");
// 获取本月收入和支出总金额 XHttp.get("/app/Category/getSumMoneyOneDay")
float incomeOneMonth = DBManager.getSumMoneyOneMonth(year, month, 1); .headers("Authorization", "Bearer " + token)
float outcomeOneMonth = DBManager.getSumMoneyOneMonth(year, month, 0); .params("year",year)
topInTv.setText(""+incomeOneMonth); .params("month",month)
topOutTv.setText(""+outcomeOneMonth); .params("day",day)
.params("kind",1)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
incomeOneDay=response;
updateTopTvShow();
Log.e("YourClass", "getDemoNewInfos success, response: " + response.toString());
}
// 设置显示运算剩余 @Override
float bmoney = preferences.getFloat("bmoney", 0);//预算 public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getDemoNewInfos error: " + e.getMessage());
}
});
//获取今日支出和收入总金额显示在view当中
XHttpSDK.setSuccessCode(200);
XHttp.get("/app/Category/getSumMoneyOneDay")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("day",day)
.params("kind",0)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
outcomeOneDay=response;
updateTopTvShow();
Log.e("YourClass", "getSumMoneyOneDay outcomeOneDay success, response: " + response.toString());
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getDemoNewInfos error: " + e.getMessage());
}
});
// float incomeOneDay = DBManager.getSumMoneyOneDay(year, month, day, 1);
// float outcomeOneDay = DBManager.getSumMoneyOneDay(year, month, day, 0);
// String infoOneDay = "今日支出 ¥"+outcomeOneDay+" 收入 ¥"+incomeOneDay;
// topConTv.setText(infoOneDay);
// 获取本月收入和支出总金额
// float incomeOneMonth = DBManager.getSumMoneyOneMonth(year, month, 1);
// float outcomeOneMonth = DBManager.getSumMoneyOneMonth(year, month, 0);
XHttpSDK.setSuccessCode(200);
XHttp.get("/app/Category/getSumMoneyOneDay")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("kind",1)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
incomeOneMonth=response;
updateTopTvShow();
Log.e("YourClass", "getSumMoneyOneMonth outcomeOneMonth success, response: " + response.toString());
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getSumMoneyOneMonth error: " + e.getMessage());
}
});
XHttpSDK.setSuccessCode(200);
XHttp.get("/app/Category/getSumMoneyOneDay")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("kind",0)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<Float>() {
@Override
public void onSuccess(Float response) throws Throwable {
outcomeOneMonth=response;
updateTopTvShow();
Log.e("YourClass", "getSumMoneyOneMonth outcomeOneMonth success, response: " + response.toString());
}
@Override
public void onError(ApiException e) {
e.printStackTrace();
Log.e("YourClass", "getSumMoneyOneMonth error: " + e.getMessage());
}
});
// topInTv.setText(""+incomeOneMonth);
// topOutTv.setText(""+outcomeOneMonth);
// accountAdapter.notifyDataSetChanged();
//// 设置显示运算剩余
// float bmoney = preferences.getFloat("bmoney", 0);//预算
// if (bmoney == 0) {
// topbudgetTv.setText("¥ 0");
// }else{
// float syMoney = bmoney-outcomeOneMonth;
// topbudgetTv.setText(""+syMoney);
// }
}
private void updateTopTvShow() {
// 更新UI
String infoOneDay = "今日支出 ¥" + outcomeOneDay + " 收入 ¥" + incomeOneDay;
topConTv.setText(infoOneDay);
topInTv.setText("" + incomeOneMonth);
topOutTv.setText("" + outcomeOneMonth);
accountAdapter.notifyDataSetChanged();
// 设置显示运算剩余
float bmoney = preferences.getFloat("bmoney", 0); // 预算
if (bmoney == 0) { if (bmoney == 0) {
topbudgetTv.setText("¥ 0"); topbudgetTv.setText("¥ 0");
}else{ } else {
float syMoney = bmoney-outcomeOneMonth; float syMoney = bmoney - outcomeOneMonth;
topbudgetTv.setText(""+syMoney); topbudgetTv.setText("" + syMoney);
}
}
// 加载数据库数据
private void LoadDBData() {
XHttpSDK.setSuccessCode(200);
Context context = getContext();
SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
XHttp.get("/app/Category/list")
.headers("Authorization", "Bearer " + token)
.params("year",year)
.params("month",month)
.params("day",day)
.syncRequest(false) //异步请求
.onMainThread(true) //回到主线程
.execute(new SimpleCallBack<List<AccountBean>>() {
@Override
public void onSuccess(List<AccountBean> response) throws Throwable {
if (response != null && response.size() > 0) {
mDatas.clear();
mDatas.addAll(response);
accountAdapter.notifyDataSetChanged();
Log.e("YourClass", "getDemoNewInfos success, response: " + response.toString());
} }
} }
// 加载数据库数据 @Override
private void LoadDBData() { public void onError(ApiException e) {
List<AccountBean> list = DBManager.getAccountListOneDayFromAccounttb(year, month, day); e.printStackTrace();
mDatas.clear(); Log.e("YourClass", "getDemoNewInfos error: " + e.getMessage());
mDatas.addAll(list); }
accountAdapter.notifyDataSetChanged(); });
} }
//头布局的点击事件 //头布局的点击事件

View File

@ -1,5 +1,7 @@
package com.example.tally.frag_record; package com.example.tally.frag_record;
import android.content.Context;
import android.content.SharedPreferences;
import android.inputmethodservice.KeyboardView; import android.inputmethodservice.KeyboardView;
import android.os.Bundle; import android.os.Bundle;
@ -7,6 +9,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -15,14 +18,23 @@ import android.widget.EditText;
import android.widget.GridView; import android.widget.GridView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.example.tally.R; import com.example.tally.R;
import com.example.tally.XinxiActivity;
import com.example.tally.db.AccountBean; import com.example.tally.db.AccountBean;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.example.tally.db.TypeBean; import com.example.tally.db.TypeBean;
import com.example.tally.utils.BeiZhuDialog; import com.example.tally.utils.BeiZhuDialog;
import com.example.tally.utils.KeyBoardUtils; import com.example.tally.utils.KeyBoardUtils;
import com.example.tally.utils.SelectTimeDialog; import com.example.tally.utils.SelectTimeDialog;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -126,6 +138,7 @@ public abstract class BaseRecordFragment extends Fragment implements View.OnClic
} }
float money = Float.parseFloat(moneyStr); float money = Float.parseFloat(moneyStr);
accountBean.setMoney(money); accountBean.setMoney(money);
//获取记录的信息保存在数据库当中 //获取记录的信息保存在数据库当中
saveAccountToDB(); saveAccountToDB();
// 返回上一级页面 // 返回上一级页面

View File

@ -1,9 +1,12 @@
package com.example.tally.frag_record; package com.example.tally.frag_record;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -11,6 +14,13 @@ import android.view.ViewGroup;
import com.example.tally.R; import com.example.tally.R;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.example.tally.db.TypeBean; import com.example.tally.db.TypeBean;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List; import java.util.List;
@ -32,6 +42,42 @@ public class IncomeFragment extends BaseRecordFragment {
@Override @Override
public void saveAccountToDB() { public void saveAccountToDB() {
accountBean.setKind(1); accountBean.setKind(1);
DBManager.insertItemToAccounttb(accountBean); JSONObject requestBody = new JSONObject();
try {
requestBody.put("typename", accountBean.getTypename());
requestBody.put("money", accountBean.getMoney());
requestBody.put("kind", accountBean.getKind());
requestBody.put("beizhu", accountBean.getBeizhu());
requestBody.put("time", accountBean.getTime());
requestBody.put("year", accountBean.getYear());
requestBody.put("month", accountBean.getMonth());
requestBody.put("day", accountBean.getDay());
requestBody.put("sImageId", accountBean.getsImageId());
} catch (JSONException e) {
throw new RuntimeException(e);
}
Context context = getContext();
SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
String requestBodyString = requestBody.toString();
XHttpSDK.setSuccessCode(200);
XHttp.post("/app/Category")
.headers("Authorization", "Bearer " + token)
.upJson(requestBodyString)
.execute(new SimpleCallBack<Integer>() {
@Override
public void onSuccess(Integer result){
if (result > 0) {
Log.e("TAG", "添加成功:"+result );
}
}
@Override
public void onError(ApiException e) {
Log.e("TAG", "添加失败:" + e.getMessage() + ", Code: " + e.getCode() );
}
});
// DBManager.insertItemToAccounttb(accountBean);
} }
} }

View File

@ -1,9 +1,12 @@
package com.example.tally.frag_record; package com.example.tally.frag_record;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -11,6 +14,13 @@ import android.view.ViewGroup;
import com.example.tally.R; import com.example.tally.R;
import com.example.tally.db.DBManager; import com.example.tally.db.DBManager;
import com.example.tally.db.TypeBean; import com.example.tally.db.TypeBean;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.XHttpSDK;
import com.xuexiang.xhttp2.callback.SimpleCallBack;
import com.xuexiang.xhttp2.exception.ApiException;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List; import java.util.List;
@ -33,7 +43,43 @@ public class OutcomeFragment extends BaseRecordFragment{
@Override @Override
public void saveAccountToDB() { public void saveAccountToDB() {
accountBean.setKind(0); accountBean.setKind(0);
DBManager.insertItemToAccounttb(accountBean); JSONObject requestBody = new JSONObject();
try {
requestBody.put("typename", accountBean.getTypename());
requestBody.put("money", accountBean.getMoney());
requestBody.put("kind", accountBean.getKind());
requestBody.put("beizhu", accountBean.getBeizhu());
requestBody.put("time", accountBean.getTime());
requestBody.put("year", accountBean.getYear());
requestBody.put("month", accountBean.getMonth());
requestBody.put("day", accountBean.getDay());
requestBody.put("sImageId", accountBean.getsImageId());
} catch (JSONException e) {
throw new RuntimeException(e);
}
Context context = getContext();
SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
String requestBodyString = requestBody.toString();
XHttpSDK.setSuccessCode(200);
XHttp.post("/app/Category")
.headers("Authorization", "Bearer " + token)
.upJson(requestBodyString)
.execute(new SimpleCallBack<Integer>() {
@Override
public void onSuccess(Integer result){
if (result > 0) {
Log.e("TAG", "添加成功:"+result );
}
}
@Override
public void onError(ApiException e) {
Log.e("TAG", "添加失败:" + e.getMessage() + ", Code: " + e.getCode() );
}
});
// DBManager.insertItemToAccounttb(accountBean);
} }
} }

View File

@ -14,6 +14,10 @@ dependencyResolutionManagement {
google() google()
mavenCentral() mavenCentral()
} }
repositories {
// JitPack https://jitpack.io
maven { url 'https://jitpack.io' }
}
} }