You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.6 KiB
Java

package com.example.haiwei_mom;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import com.example.haiwei_mom.base.BaseActivity;
import com.example.haiwei_mom.base.MyRecultCall;
import com.example.haiwei_mom.base.MyResult;
import com.example.haiwei_mom.data.TeamInfoVo;
import com.example.haiwei_mom.databinding.ActivityClassItemBinding;
import com.example.haiwei_mom.uitls.SharedPreferencesUtils;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import okhttp3.RequestBody;
public class ClassItemActivity extends BaseActivity {
private List<String> classList;
private List<String> shiftList;
private ActivityClassItemBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_class_item);
binding.setDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
selectShiftInfo();
}
private List<TeamInfoVo> list;
// 获取班次
private void selectShiftInfo() {
OkGo.<MyResult>post(url + "/wms/pda/selectTeams").execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getCode() == 200) {
list = gson.fromJson(body.getDataJson(), new TypeToken<List<TeamInfoVo>>() {
}.getType());
classList = new ArrayList<>();
shiftList = new ArrayList<>();
list.forEach(teamInfoVo -> {
if (teamInfoVo.getType().equals("班组")) {
classList.add(teamInfoVo.getTeamName());
} else {
shiftList.add(teamInfoVo.getTeamName());
}
});
binding.setList1(classList);
binding.setList2(shiftList);
}
}
});
}
public void classSubmit(View view) {
String shiftText = binding.spinner2.getSelectedItem().toString();
String classText = binding.spinner1.getSelectedItem().toString();
Optional<Long> shiftId = list.stream().filter(t -> t.getTeamName().equals(shiftText)).map(TeamInfoVo::getTeamId).findFirst();
Optional<Long> classTeamId = list.stream().filter(t -> t.getTeamName().equals(classText)).map(TeamInfoVo::getTeamId).findFirst();
OkGo.<MyResult>post(url + "/wms/pda/shiftChangeSubmit")
.params("shiftId", shiftId.get())
.params("classTeamId",classTeamId.get() )
.params("userName", SharedPreferencesUtils.getstring("nickname", ""))
.execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getCode() == 200) {
finish();
return;
}
myToastUitls.show(body.getMsg());
}
});
}
}