202543日报
个人作业开发记录
package com.example.dailyreport.ui.dailylog;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.dailyreport.R;
import com.example.dailyreport.model.DailyLog;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class AddDailyLogActivity extends AppCompatActivity {
private String userId;
private EditText etDate, etPlanningTime, etAnalysis, etCodingStandard,
etDesignDetails, etCode, etCodeChanges, etWorkload,
etPostmortem, etImprovement, etTotalHours;
private CheckBox cbDesignDoc;
private Date selectedDate = new Date();
// 修改日期格式
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
private SimpleDateFormat apiDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_daily_log);
userId = getIntent().getStringExtra("userId");
if (userId == null) {
Toast.makeText(this, "用户ID获取失败", Toast.LENGTH_SHORT).show();
finish();
return;
}
initViews();
}
private void initViews() {
etDate = findViewById(R.id.etDate);
etPlanningTime = findViewById(R.id.etPlanningTime);
etAnalysis = findViewById(R.id.etAnalysis);
cbDesignDoc = findViewById(R.id.cbDesignDoc);
etCodingStandard = findViewById(R.id.etCodingStandard);
etDesignDetails = findViewById(R.id.etDesignDetails);
etCode = findViewById(R.id.etCode);
etCodeChanges = findViewById(R.id.etCodeChanges);
etWorkload = findViewById(R.id.etWorkload);
etPostmortem = findViewById(R.id.etPostmortem);
etImprovement = findViewById(R.id.etImprovement);
etTotalHours = findViewById(R.id.etTotalHours);
Button btnSubmit = findViewById(R.id.btnSubmit);
// 设置当前日期
etDate.setText(dateFormat.format(selectedDate));
// 设置日期选择器
etDate.setOnClickListener(v -> {
Calendar calendar = Calendar.getInstance();
if (selectedDate != null) {
calendar.setTime(selectedDate);
}
DatePickerDialog datePickerDialog = new DatePickerDialog(
this,
(view, year, month, dayOfMonth) -> {
Calendar newDate = Calendar.getInstance();
newDate.set(year, month, dayOfMonth);
selectedDate = newDate.getTime();
etDate.setText(dateFormat.format(selectedDate));
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);
datePickerDialog.show();
});
btnSubmit.setOnClickListener(v -> submitDailyLog());
}
private void submitDailyLog() {
// 验证必填字段
if (etAnalysis.getText().toString().trim().isEmpty()) {
Toast.makeText(this, "请填写开发分析内容", Toast.LENGTH_SHORT).show();
return;
}
// 创建DailyLog对象
DailyLog dailyLog = new DailyLog();
dailyLog.setId(userId);
dailyLog.setDate(selectedDate);
// 获取当前时间戳作为记录编号
dailyLog.setRecordNumber((int)(System.currentTimeMillis() / 1000));
try {
String planningTimeStr = etPlanningTime.getText().toString().trim();
if (!planningTimeStr.isEmpty()) {
dailyLog.setPlanningTimeEstimate(Double.parseDouble(planningTimeStr));
}
} catch (NumberFormatException e) {
Toast.makeText(this, "计划时间格式错误", Toast.LENGTH_SHORT).show();
return;
}
dailyLog.setDevelopmentAnalysis(etAnalysis.getText().toString().trim());
dailyLog.setDesignDocCreated(cbDesignDoc.isChecked());
dailyLog.setCodingStandard(etCodingStandard.getText().toString().trim());
dailyLog.setDesignDetails(etDesignDetails.getText().toString().trim());
dailyLog.setCode(etCode.getText().toString().trim());
dailyLog.setCodeChanges(etCodeChanges.getText().toString().trim());
dailyLog.setWorkloadMeasurement(etWorkload.getText().toString().trim());
dailyLog.setPostmortemAnalysis(etPostmortem.getText().toString().trim());
dailyLog.setImprovementPlan(etImprovement.getText().toString().trim());
try {
String totalHoursStr = etTotalHours.getText().toString().trim();
if (!totalHoursStr.isEmpty()) {
dailyLog.setTotalHours(Double.parseDouble(totalHoursStr));
}
} catch (NumberFormatException e) {
Toast.makeText(this, "总时间格式错误", Toast.LENGTH_SHORT).show();
return;
}
// 提交数据
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("正在提交...");
progressDialog.show();
RetrofitClient.getInstance().getApiService()
.addDailyLog(dailyLog)
.enqueue(new Callback<ApiResponse<String>>() {
@Override
public void onResponse(Call<ApiResponse<String>> call, Response<ApiResponse<String>> response) {
progressDialog.dismiss();
if (response.isSuccessful() && response.body() != null) {
ApiResponse<String> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
Toast.makeText(AddDailyLogActivity.this,
"添加成功", Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(AddDailyLogActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(AddDailyLogActivity.this,
"提交失败", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ApiResponse<String>> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(AddDailyLogActivity.this,
"网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
package com.example.dailyreport.ui.dailylog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.dailyreport.R;
import com.example.dailyreport.adapter.DailyLogAdapter;
import com.example.dailyreport.model.DailyLog;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DailyLogActivity extends AppCompatActivity {
private String userId;
private RecyclerView recyclerView;
private DailyLogAdapter adapter;
private List<DailyLog> dailyLogs = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_log);
// 获取当前用户ID
userId = getIntent().getStringExtra("userId");
if (userId == null) {
Toast.makeText(this, "用户ID获取失败", Toast.LENGTH_SHORT).show();
finish();
return;
}
initViews();
loadDailyLogs();
}
private void initViews() {
recyclerView = findViewById(R.id.rvDailyLogs);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new DailyLogAdapter(dailyLogs, dailyLog -> {
// 点击查看详情
Intent intent = new Intent(this, DailyLogDetailActivity.class);
intent.putExtra("dailyLogId", dailyLog.getId());
startActivity(intent);
});
recyclerView.setAdapter(adapter);
Button btnAddDailyLog = findViewById(R.id.btnAddDailyLog);
btnAddDailyLog.setOnClickListener(v -> {
Intent intent = new Intent(this, AddDailyLogActivity.class);
intent.putExtra("userId", userId);
startActivity(intent);
});
}
@Override
protected void onResume() {
super.onResume();
loadDailyLogs(); // 每次返回页面时刷新数据
}
private void loadDailyLogs() {
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("正在加载编程记录...");
progressDialog.show();
RetrofitClient.getInstance().getApiService()
.getDailyLogsByUserId(userId)
.enqueue(new Callback<ApiResponse<List<DailyLog>>>() {
@Override
public void onResponse(Call<ApiResponse<List<DailyLog>>> call, Response<ApiResponse<List<DailyLog>>> response) {
progressDialog.dismiss();
if (response.isSuccessful() && response.body() != null) {
ApiResponse<List<DailyLog>> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
dailyLogs.clear();
if (apiResponse.getData() != null) {
dailyLogs.addAll(apiResponse.getData());
}
adapter.notifyDataSetChanged();
if (dailyLogs.isEmpty()) {
Toast.makeText(DailyLogActivity.this, "暂无编程记录", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(DailyLogActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(DailyLogActivity.this,
"加载失败", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ApiResponse<List<DailyLog>>> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(DailyLogActivity.this,
"网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
package com.example.dailyreport.ui.dailylog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.dailyreport.R;
import com.example.dailyreport.model.DailyLog;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;
import java.text.SimpleDateFormat;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DailyLogDetailActivity extends AppCompatActivity {
private String dailyLogId;
private TextView tvDate, tvPlanningTime, tvAnalysis, tvDesignDoc, tvCodingStandard,
tvDesignDetails, tvCode, tvCodeChanges, tvWorkload, tvPostmortem, tvImprovement, tvTotalHours;
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_log_detail);
dailyLogId = getIntent().getStringExtra("dailyLogId");
if (dailyLogId == null) {
Toast.makeText(this, "记录ID获取失败", Toast.LENGTH_SHORT).show();
finish();
return;
}
initViews();
loadDailyLogDetail();
}
private void initViews() {
tvDate = findViewById(R.id.tvDate);
tvPlanningTime = findViewById(R.id.tvPlanningTime);
tvAnalysis = findViewById(R.id.tvAnalysis);
tvDesignDoc = findViewById(R.id.tvDesignDoc);
tvCodingStandard = findViewById(R.id.tvCodingStandard);
tvDesignDetails = findViewById(R.id.tvDesignDetails);
tvCode = findViewById(R.id.tvCode);
tvCodeChanges = findViewById(R.id.tvCodeChanges);
tvWorkload = findViewById(R.id.tvWorkload);
tvPostmortem = findViewById(R.id.tvPostmortem);
tvImprovement = findViewById(R.id.tvImprovement);
tvTotalHours = findViewById(R.id.tvTotalHours);
}
private void loadDailyLogDetail() {
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("正在加载详情...");
progressDialog.show();
RetrofitClient.getInstance().getApiService()
.getDailyLogById(dailyLogId)
.enqueue(new Callback<ApiResponse<DailyLog>>() {
@Override
public void onResponse(Call<ApiResponse<DailyLog>> call, Response<ApiResponse<DailyLog>> response) {
progressDialog.dismiss();
if (response.isSuccessful() && response.body() != null) {
ApiResponse<DailyLog> apiResponse = response.body();
if ("200".equals(apiResponse.getCode()) && apiResponse.getData() != null) {
displayDailyLog(apiResponse.getData());
} else {
Toast.makeText(DailyLogDetailActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
finish();
}
} else {
Toast.makeText(DailyLogDetailActivity.this,
"加载失败", Toast.LENGTH_SHORT).show();
finish();
}
}
@Override
public void onFailure(Call<ApiResponse<DailyLog>> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(DailyLogDetailActivity.this,
"网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
finish();
}
});
}
private void displayDailyLog(DailyLog dailyLog) {
tvDate.setText(dailyLog.getDate() != null ? dateFormat.format(dailyLog.getDate()) : "未知日期");
tvPlanningTime.setText(dailyLog.getPlanningTimeEstimate() != null ?
dailyLog.getPlanningTimeEstimate() + "小时" : "未设置");
tvAnalysis.setText(dailyLog.getDevelopmentAnalysis());
tvDesignDoc.setText(dailyLog.getDesignDocCreated() != null && dailyLog.getDesignDocCreated() ?
"是" : "否");
tvCodingStandard.setText(dailyLog.getCodingStandard());
tvDesignDetails.setText(dailyLog.getDesignDetails());
tvCode.setText(dailyLog.getCode());
tvCodeChanges.setText(dailyLog.getCodeChanges());
tvWorkload.setText(dailyLog.getWorkloadMeasurement());
tvPostmortem.setText(dailyLog.getPostmortemAnalysis());
tvImprovement.setText(dailyLog.getImprovementPlan());
tvTotalHours.setText(dailyLog.getTotalHours() != null ?
dailyLog.getTotalHours() + "小时" : "未设置");
}
}
package com.example.dailyreport.ui.statistics;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.dailyreport.R;
import com.example.dailyreport.adapter.DailyLogAdapter;
import com.example.dailyreport.model.DailyLog;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;
import com.example.dailyreport.ui.dailylog.DailyLogDetailActivity;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import android.app.DatePickerDialog;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class StatisticsActivity extends AppCompatActivity implements DailyLogAdapter.OnDailyLogClickListener {
private EditText etDate;
private Button btnSearch;
private RecyclerView rvDailyLogs;
private DailyLogAdapter adapter;
private List<DailyLog> dailyLogList = new ArrayList<>();
private Date selectedDate = new Date();
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
private SimpleDateFormat apiDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statistics);
initViews();
setupDatePicker();
setupRecyclerView();
btnSearch.setOnClickListener(v -> searchDailyLogs());
}
private void initViews() {
etDate = findViewById(R.id.etDate);
btnSearch = findViewById(R.id.btnSearch);
rvDailyLogs = findViewById(R.id.rvDailyLogs);
// 设置当前日期
etDate.setText(dateFormat.format(selectedDate));
}
private void setupDatePicker() {
etDate.setOnClickListener(v -> {
Calendar calendar = Calendar.getInstance();
if (selectedDate != null) {
calendar.setTime(selectedDate);
}
DatePickerDialog datePickerDialog = new DatePickerDialog(
this,
(view, year, month, dayOfMonth) -> {
Calendar newDate = Calendar.getInstance();
newDate.set(year, month, dayOfMonth);
selectedDate = newDate.getTime();
etDate.setText(dateFormat.format(selectedDate));
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);
datePickerDialog.show();
});
}
private void setupRecyclerView() {
adapter = new DailyLogAdapter(dailyLogList, this);
rvDailyLogs.setLayoutManager(new LinearLayoutManager(this));
rvDailyLogs.setAdapter(adapter);
// 删除原来的点击事件设置代码,因为现在通过接口实现
}
private void searchDailyLogs() {
if (selectedDate == null) {
Toast.makeText(this, "请选择日期", Toast.LENGTH_SHORT).show();
return;
}
String dateStr = apiDateFormat.format(selectedDate);
// 调用API获取指定日期的所有日志
RetrofitClient.getInstance().getApiService().getDailyLogsByDate(dateStr)
.enqueue(new Callback<ApiResponse<List<DailyLog>>>() {
@Override
public void onResponse(Call<ApiResponse<List<DailyLog>>> call,
Response<ApiResponse<List<DailyLog>>> response) {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<List<DailyLog>> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
dailyLogList.clear();
if (apiResponse.getData() != null) {
dailyLogList.addAll(apiResponse.getData());
}
adapter.notifyDataSetChanged();
if (dailyLogList.isEmpty()) {
Toast.makeText(StatisticsActivity.this,
"该日期没有日志记录", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(StatisticsActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(StatisticsActivity.this,
"获取数据失败", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ApiResponse<List<DailyLog>>> call, Throwable t) {
Toast.makeText(StatisticsActivity.this,
"网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onDailyLogClick(DailyLog dailyLog) {
Intent intent = new Intent(this, DailyLogDetailActivity.class);
intent.putExtra("dailyLogId", dailyLog.getId());
startActivity(intent);
}
}
package com.example.dailyreport.ui.weeklyplan;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.dailyreport.R;
import com.example.dailyreport.adapter.WeeklyPlanAdapter;
import com.example.dailyreport.model.WeeklyPlan;
import com.example.dailyreport.network.ApiResponse;
import com.example.dailyreport.network.RetrofitClient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class WeeklyPlanActivity extends AppCompatActivity {
private String userId;
private EditText etPlan;
private RecyclerView rvPlans;
private WeeklyPlanAdapter adapter;
private List<WeeklyPlan> plans = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weekly_plan);
userId = getIntent().getStringExtra("userId");
if (userId == null) {
Toast.makeText(this, "用户ID获取失败", Toast.LENGTH_SHORT).show();
finish();
return;
}
initViews();
loadPlans();
}
private void initViews() {
etPlan = findViewById(R.id.etPlan);
rvPlans = findViewById(R.id.rvPlans);
Button btnSubmit = findViewById(R.id.btnSubmit);
adapter = new WeeklyPlanAdapter(plans, this::deletePlan);
rvPlans.setLayoutManager(new LinearLayoutManager(this));
rvPlans.setAdapter(adapter);
btnSubmit.setOnClickListener(v -> submitPlan());
}
private void submitPlan() {
String planText = etPlan.getText().toString().trim();
if (planText.isEmpty()) {
Toast.makeText(this, "请输入计划内容", Toast.LENGTH_SHORT).show();
return;
}
WeeklyPlan plan = new WeeklyPlan();
plan.setId(userId);
plan.setDate(new Date());
plan.setPlan(planText);
RetrofitClient.getInstance().getApiService().addWeeklyPlan(plan)
.enqueue(new Callback<ApiResponse<String>>() {
@Override
public void onResponse(Call<ApiResponse<String>> call,
Response<ApiResponse<String>> response) {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<String> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
Toast.makeText(WeeklyPlanActivity.this,
"添加成功", Toast.LENGTH_SHORT).show();
etPlan.setText("");
loadPlans();
} else {
Toast.makeText(WeeklyPlanActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onFailure(Call<ApiResponse<String>> call, Throwable t) {
Toast.makeText(WeeklyPlanActivity.this,
"网络错误: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void loadPlans() {
RetrofitClient.getInstance().getApiService().getWeeklyPlans()
.enqueue(new Callback<ApiResponse<List<WeeklyPlan>>>() {
@Override
public void onResponse(Call<ApiResponse<List<WeeklyPlan>>> call,
Response<ApiResponse<List<WeeklyPlan>>> response) {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<List<WeeklyPlan>> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
plans = apiResponse.getData();
adapter.updatePlans(plans);
}
}
}
@Override
public void onFailure(Call<ApiResponse<List<WeeklyPlan>>> call, Throwable t) {
Toast.makeText(WeeklyPlanActivity.this,
"加载失败: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void deletePlan(WeeklyPlan plan) {
RetrofitClient.getInstance().getApiService().deleteWeeklyPlan(plan.getId())
.enqueue(new Callback<ApiResponse<String>>() {
@Override
public void onResponse(Call<ApiResponse<String>> call,
Response<ApiResponse<String>> response) {
if (response.isSuccessful() && response.body() != null) {
ApiResponse<String> apiResponse = response.body();
if ("200".equals(apiResponse.getCode())) {
Toast.makeText(WeeklyPlanActivity.this,
"删除成功", Toast.LENGTH_SHORT).show();
loadPlans();
} else {
Toast.makeText(WeeklyPlanActivity.this,
apiResponse.getMsg(), Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onFailure(Call<ApiResponse<String>> call, Throwable t) {
Toast.makeText(WeeklyPlanActivity.this,
"删除失败: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}

浙公网安备 33010602011771号