package cn.flightfeather.thirdappmodule.activity;
|
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.graphics.Color;
|
import android.graphics.Paint;
|
import android.graphics.drawable.ShapeDrawable;
|
import android.graphics.drawable.shapes.RoundRectShape;
|
import android.os.Bundle;
|
import android.support.annotation.NonNull;
|
import android.support.design.widget.FloatingActionButton;
|
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.LinearLayoutCompat;
|
import android.view.Gravity;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.view.animation.Animation;
|
import android.view.animation.AnimationUtils;
|
import android.widget.BaseAdapter;
|
import android.widget.Button;
|
import android.widget.CompoundButton;
|
import android.widget.LinearLayout;
|
import android.widget.ListAdapter;
|
import android.widget.ListView;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.ping.greendao.gen.EvaluationruleDao;
|
import com.ping.greendao.gen.EvaluationsubruleDao;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
import cn.flightfeather.thirdappmodule.CommonApplication;
|
import cn.flightfeather.thirdappmodule.R;
|
import cn.flightfeather.thirdappmodule.adapter.AllListViewAdapter;
|
import cn.flightfeather.thirdappmodule.bean.entity.Evaluation;
|
import cn.flightfeather.thirdappmodule.bean.entity.Evaluationrule;
|
import cn.flightfeather.thirdappmodule.bean.entity.Evaluationsubrule;
|
import cn.flightfeather.thirdappmodule.bean.entity.Itemevaluation;
|
import cn.flightfeather.thirdappmodule.bean.entity.Scense;
|
import cn.flightfeather.thirdappmodule.bean.entity.Subtask;
|
import cn.flightfeather.thirdappmodule.bean.vo.EvaluationsubruleVo;
|
import cn.flightfeather.thirdappmodule.httpservice.EvaluationService;
|
import cn.flightfeather.thirdappmodule.util.Constant;
|
import cn.flightfeather.thirdappmodule.util.UUIDGenerator;
|
import io.reactivex.Observable;
|
import io.reactivex.ObservableEmitter;
|
import io.reactivex.ObservableOnSubscribe;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.disposables.Disposable;
|
import io.reactivex.functions.Consumer;
|
import io.reactivex.schedulers.Schedulers;
|
import okhttp3.ResponseBody;
|
import retrofit2.Call;
|
import retrofit2.Callback;
|
import retrofit2.Response;
|
import retrofit2.http.Body;
|
import retrofit2.http.GET;
|
import retrofit2.http.POST;
|
import retrofit2.http.PUT;
|
import retrofit2.http.Path;
|
|
public class GradeActivity extends AppCompatActivity {
|
|
private Context context;
|
private CommonApplication mApplication;
|
|
// private MyAdapter<Evaluationsubrule> myAdapter = null;
|
private List<EvaluationsubruleVo> mData = new ArrayList<>();//ListView的item的数据
|
|
//考核规范的类别
|
private Byte RULETYPE = 2;//1:规范性,2:评分
|
|
private Evaluationrule evaluationruleTitle;//考核规范
|
private EvaluationsubruleVo evaluationruleTitleVo;//考核规范Vo
|
private final String TITLE = "title";//考核规范Vo的fatherid设为TITLE,判定为标题
|
|
private List<EvaluationsubruleVo> allEvaluationsubruleVos = new ArrayList<>();//所有规范考核项
|
// private HashMap<String, List<EvaluationsubruleVo>> allEvaluationsubruleVos = new HashMap<>();//所有规范考核项
|
private List<EvaluationsubruleVo> baseEvaluationsubruleVos = new ArrayList<>();//所有父规范考核项(没有fatherid)
|
private List<EvaluationsubruleVo> subEvaluationsubruleVos = new ArrayList<>();//所有子规范考核项(有fatherid)
|
private List<Itemevaluation> itemevaluationList = new ArrayList<>();//巡查单项考核评估表
|
private Evaluation evaluation;//巡查综合评估表
|
private int TOTALPOINTS;
|
|
//上级传入的信息
|
private Subtask subtask;//子任务
|
private String inspectionGuid;//巡查ID
|
private Scense scense;//场景
|
private String isreform = Constant.BEFOREREFORM;//整改前或整改后
|
//服务器交互接口
|
private GradeService gradeService;
|
private EvaluationService evaluationService;
|
//打分模式
|
private int sign = -1;//当前打分是扣分模式(-1)或加分模式(+1)
|
//评分的三种模式
|
private final String SINGELSELECT= "0";//单选
|
private final String MUTISELECT = "1";//多选
|
private final String ALLSELECT = "2";//全选
|
//父项初始分数为零(每次提交重新计算总分)
|
private final String INITSCORE = "0";
|
|
//标题文字大小(每次增加5)
|
private int TEXTSIZE = 15;
|
|
boolean ismDataexist = false;//判定子任务是否已有打分记录
|
//基础评分项
|
private List<AllListViewAdapter> adapters = new ArrayList<>();
|
// List<List<EvaluationsubruleVo>> mDataList = new ArrayList<>();
|
private TextView text_total_point;
|
|
private FloatingActionButton fab_refresh;
|
|
private List<Disposable> disposables = new ArrayList<>();
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_grade);
|
context = GradeActivity.this;
|
|
mApplication = (CommonApplication) getApplication();
|
gradeService = mApplication.getRetrofit().create(GradeService.class);
|
evaluationService = mApplication.getRetrofit().create(EvaluationService.class);
|
|
Intent intent = getIntent();
|
subtask = (Subtask) intent.getSerializableExtra("subtask");
|
inspectionGuid = (String) intent.getSerializableExtra("inspectionGuid");
|
scense = (Scense) intent.getSerializableExtra("scense");
|
|
// getActionBar().setTitle("工地评分考核");
|
//设置默认标题
|
setTitle(Constant.DEFAULTGRADETITLE);
|
|
initEvaluationsubrules(scense, subtask);
|
// baseEvaluationsubruleVos = GradeActivityTest.initbase();
|
// subEvaluationsubruleVos = GradeActivityTest.initsub();
|
|
// init(context);
|
initStatusBar();
|
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
for (Disposable d :
|
disposables) {
|
d.dispose();
|
}
|
}
|
|
//初始化状态栏(总分)
|
Animation rotateAnimation;
|
|
private void initStatusBar() {
|
text_total_point = findViewById(R.id.text_total_point);
|
fab_refresh = findViewById(R.id.fab_refresh);
|
rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
|
setTotalPointClickListener(fab_refresh);
|
}
|
|
private void setTotalPointClickListener(final View view) {
|
Disposable disposable = Observable.create(new ObservableOnSubscribe<String>() {
|
@Override
|
public void subscribe(final ObservableEmitter<String> emitter) throws Exception {
|
view.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
Evaluation evaluation = new Evaluation();
|
updateEvaluation(evaluation);
|
String point = "";
|
if (evaluation.getResultscoreaft() == null || evaluation.getResultscoreaft().equals("")) {
|
point = evaluation.getResultscorebef();
|
} else {
|
point = evaluation.getResultscoreaft();
|
}
|
emitter.onNext(point);
|
fab_refresh.startAnimation(rotateAnimation);
|
}
|
});
|
}
|
}).subscribeOn(Schedulers.computation())
|
.observeOn(AndroidSchedulers.mainThread())
|
.subscribe(new Consumer<String>() {
|
@Override
|
public void accept(String s) throws Exception {
|
text_total_point.setText(s);
|
}
|
});
|
disposables.add(disposable);
|
}
|
|
|
/**
|
* 数据库数据初始化
|
*/
|
public void initEvaluationsubrules(Scense scense, Subtask subtask){
|
allEvaluationsubruleVos.clear();
|
baseEvaluationsubruleVos.clear();
|
subEvaluationsubruleVos.clear();
|
EvaluationruleDao evaluationruleDao = mApplication.getDaoSession().getEvaluationruleDao();
|
EvaluationsubruleDao evaluationsubruleDao = mApplication.getDaoSession().getEvaluationsubruleDao();
|
QueryBuilder<Evaluationrule> qb_rule = evaluationruleDao.queryBuilder().where(
|
EvaluationruleDao.Properties.Provincecode.eq(subtask.getProvincecode()),
|
EvaluationruleDao.Properties.Citycode.eq(subtask.getCitycode()),
|
EvaluationruleDao.Properties.Districtcode.eq(subtask.getDistrictcode()),
|
EvaluationruleDao.Properties.Scensetypeid.eq(scense.getTypeid()),
|
EvaluationruleDao.Properties.Isuse.eq(false)
|
);
|
|
//获取场景
|
try {
|
final Evaluationrule evaluationrule = qb_rule.list().get(0);//获取考核规范表(评分/规范性)
|
|
this.evaluationruleTitle = evaluationrule;
|
this.evaluationruleTitleVo = transformToEvaluationsubruleVo(evaluationrule);
|
//设置标题
|
setTitle(evaluationrule.getRulename());
|
|
List<Evaluationsubrule> tmp = evaluationsubruleDao.queryBuilder().where(
|
EvaluationsubruleDao.Properties.Erguid.eq(evaluationrule.getGuid())
|
).orderAsc(EvaluationsubruleDao.Properties.Displayid).list();
|
|
//javabean间数据转换
|
allEvaluationsubruleVos = transformToEvaluationsubruleVo(tmp, allEvaluationsubruleVos);
|
|
Call<List<Itemevaluation>> getItemEvaluationList;
|
getItemEvaluationList = gradeService.getItemEvaluationList(subtask.getStguid());
|
getItemEvaluationList.enqueue(new Callback<List<Itemevaluation>>() {
|
@Override
|
public void onResponse(Call<List<Itemevaluation>> call, Response<List<Itemevaluation>> response) {
|
itemevaluationList = response.body();
|
if (response.body() != null && !response.body().isEmpty()) {
|
for (int i = 0; i < allEvaluationsubruleVos.size(); i++){
|
for(int y = 0; y < response.body().size(); y++) {
|
if(Objects.equals(allEvaluationsubruleVos.get(i).getGuid(), response.body().get(y).getEsrguid())) {
|
if (getByFatherId(allEvaluationsubruleVos, allEvaluationsubruleVos.get(i).getGuid()).size() == 0)
|
allEvaluationsubruleVos.get(i).setGrade(response.body().get(y).getValue());
|
else
|
allEvaluationsubruleVos.get(i).setGrade(INITSCORE);
|
|
if (response.body().get(y).getValue() == null){//按照分数决定默认是否被选中
|
allEvaluationsubruleVos.get(i).setSelected(false);
|
}else {
|
allEvaluationsubruleVos.get(i).setSelected(true);
|
}
|
break;
|
}
|
|
}
|
}
|
ismDataexist = true;
|
}
|
else {
|
for (int i = 0; i < allEvaluationsubruleVos.size(); i++){
|
try {
|
String mutichoice = findByFatherIdVo(allEvaluationsubruleVos, allEvaluationsubruleVos.get(i).getFatherid()).getMutichoice();
|
if (getByFatherId(allEvaluationsubruleVos, allEvaluationsubruleVos.get(i).getGuid()).size() == 0)
|
allEvaluationsubruleVos.get(i).setGrade(allEvaluationsubruleVos.get(i).getDefaultvalue());
|
if (Objects.equals(mutichoice, ALLSELECT)) {//全选
|
allEvaluationsubruleVos.get(i).setSelected(true);
|
} else {
|
allEvaluationsubruleVos.get(i).setSelected(false);
|
}
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
}
|
|
// allEvaluationsubruleVos.clear();
|
baseEvaluationsubruleVos.clear();
|
subEvaluationsubruleVos.clear();
|
for (EvaluationsubruleVo esr : allEvaluationsubruleVos) {
|
if (esr.getFatherid() == null || esr.getFatherid().equals("")) {
|
esr.setFatherid(evaluationrule.getGuid());
|
baseEvaluationsubruleVos.add(esr);
|
TOTALPOINTS += esr.getMaxscore();
|
} else {
|
subEvaluationsubruleVos.add(esr);
|
}
|
}
|
|
init(context);//初始化界面
|
}
|
|
@Override
|
public void onFailure(Call<List<Itemevaluation>> call, Throwable t) {
|
|
}
|
});
|
}catch (IndexOutOfBoundsException|NullPointerException e){
|
e.printStackTrace();
|
}
|
|
//巡查综合评估表
|
try{
|
Call<List<Evaluation>> getEvaluationList = evaluationService.takeAllEvaluations();
|
getEvaluationList.enqueue(new Callback<List<Evaluation>>() {
|
@Override
|
public void onResponse(Call<List<Evaluation>> call, Response<List<Evaluation>> response) {
|
if (response.body() != null && !response.body().isEmpty()){
|
for (Evaluation tmp : response.body()){
|
if (Objects.equals(tmp.getIguid(), inspectionGuid)) {
|
evaluation = tmp;
|
break;
|
}
|
}
|
}
|
}
|
|
@Override
|
public void onFailure(Call<List<Evaluation>> call, Throwable t) {
|
|
}
|
});
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 界面初始化
|
* @param context
|
*/
|
public void init(Context context) {
|
|
//布局文件的最外层View容器
|
LinearLayout baselinearLayout = (LinearLayout) findViewById(R.id.ll_grade);
|
// ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_grade, null);
|
|
//评分表
|
// LinearLayout ll_of_cardView = generateNewLinearLayout(LinearLayout.VERTICAL);
|
// ll_of_cardView = generateNewSingleGrade(ll_of_cardView, evaluationruleTitleVo);
|
// baselinearLayout.addView(ll_of_cardView);
|
for(int i = 0; i< baseEvaluationsubruleVos.size(); i++) {
|
// 不添加cardView
|
LinearLayout ll_of_cardView = generateNewLinearLayout(LinearLayout.VERTICAL);
|
ll_of_cardView = generateNewSingleGrade(ll_of_cardView, baseEvaluationsubruleVos.get(i));
|
baselinearLayout.addView(ll_of_cardView);
|
//添加cardView
|
// CardView cardView = generateSingleLayout(baseEvaluationsubruleVos.get(i));
|
// baselinearLayout.addView(cardView);
|
|
// EditText editText = new EditText(this);
|
// baselinearLayout.addView(editText);
|
}
|
|
if (!allEvaluationsubruleVos.isEmpty()){
|
//保存与上传按钮
|
LinearLayout ll_of_button = generateNewLinearLayout(LinearLayout.HORIZONTAL);
|
|
Button btnSave = generateNewButtonView(ll_of_button, "保存", Color.WHITE, Color.argb(255,3,169,244));
|
btnSave.setVisibility(View.GONE );//隐藏
|
btnSave.setOnClickListener(new setButtonSaveClickListener());
|
ll_of_button.addView(btnSave);
|
|
Button btnUploading;
|
if(ismDataexist) {
|
btnUploading = generateNewButtonView(ll_of_button, "修改", Color.BLACK, Color.WHITE);
|
} else{
|
btnUploading = generateNewButtonView(ll_of_button, "提交", Color.BLACK, Color.WHITE);
|
}
|
ll_of_button.addView(btnUploading);
|
btnUploading.setOnClickListener(new setButtonUploadingClickListener());
|
baselinearLayout.addView(ll_of_button);
|
//无数据文字隐藏
|
TextView tv_no_data = (TextView) findViewById(R.id.tv_no_data);
|
tv_no_data.setVisibility(View.GONE);
|
}
|
|
}
|
|
/**
|
* 动态生成一个评分块(CardView)
|
* @param baseEvaluationsubrule
|
* @return
|
*/
|
public CardView generateNewCardView(EvaluationsubruleVo baseEvaluationsubrule) {
|
|
//具体的打分项
|
LinearLayout ll_of_cardView = generateNewLinearLayout(LinearLayout.VERTICAL);
|
ll_of_cardView = generateNewSingleGrade(ll_of_cardView, baseEvaluationsubrule);
|
|
//具体打分项由一个CardView包装
|
return generateNewCardView(ll_of_cardView);
|
}
|
|
/**
|
* dip转像素
|
* @param context
|
* @param dipValue
|
* @return
|
*/
|
public static int dip2px(Context context, float dipValue) {
|
final float scale = context.getResources().getDisplayMetrics().density;
|
return (int) (dipValue * scale + 0.5f);
|
}
|
|
/**
|
* 一个规范考核项的内容主体
|
* @param linearLayout
|
*/
|
private LinearLayout generateNewSingleGrade(LinearLayout linearLayout, EvaluationsubruleVo baseEvaluationsubrule){
|
|
//打分类别初始化
|
try {
|
linearLayout = fun(allEvaluationsubruleVos, baseEvaluationsubrule, linearLayout);
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
|
return linearLayout;
|
}
|
|
|
/**
|
* 对于每一个规范考核项,生成相应的评分块中的各级标题,及得到具体评分的基本项list: mData
|
* @param list
|
* @param baseEvaluationsubrule
|
* @param linearLayout
|
*/
|
private LinearLayout fun(List<EvaluationsubruleVo> list, EvaluationsubruleVo baseEvaluationsubrule, LinearLayout linearLayout){
|
List<EvaluationsubruleVo> tmplist = getByFatherId(list, baseEvaluationsubrule.getGuid());
|
|
//对于没有子项的具体评分项目,生成评分列表(ListView)
|
if(tmplist.size() == 0){
|
this.mData.add(baseEvaluationsubrule);
|
return linearLayout;
|
}
|
//对于有子项的规范评分考核项,生成为标题(TextView)
|
else{
|
// baseEvaluationsubrule.setGrade("0");//初始化分数为零分
|
// if (!Objects.equals(baseEvaluationsubrule.getFatherid(), TITLE)) {
|
// linearLayout = generateNewTextView(linearLayout, baseEvaluationsubrule.getItemname() + "(" + baseEvaluationsubrule.getMaxscore() + "分)", TEXTSIZE);
|
// TEXTSIZE += 5;
|
// }
|
if (!Objects.equals(baseEvaluationsubrule.getFatherid(), TITLE)) {
|
if (Objects.equals(baseEvaluationsubrule.getFatherid(), evaluationruleTitleVo.getGuid()))
|
linearLayout = generateNewTextView(linearLayout, baseEvaluationsubrule.getItemname() + "(" + baseEvaluationsubrule.getMaxscore() + "分)", 20);
|
else
|
linearLayout = generateNewTextView(linearLayout, baseEvaluationsubrule.getItemname() + "(" + baseEvaluationsubrule.getMaxscore() + "分)", 15);
|
}
|
for(int i = 0; i < tmplist.size(); i++){
|
linearLayout = fun(list, tmplist.get(i), linearLayout);
|
if(i == tmplist.size()-1 && !this.mData.isEmpty()){
|
List<EvaluationsubruleVo> tmpData = new ArrayList<>();
|
tmpData.addAll(mData);
|
linearLayout = generateNewListView(tmpData, linearLayout);
|
this.mData.clear();
|
}
|
}
|
}
|
return linearLayout;
|
}
|
|
/**
|
* 通过Guid作为fatherid找到所有下级子规范评分项
|
* @param mEvaluationsubrules
|
* @param fatherid
|
* @return
|
*/
|
private static List<EvaluationsubruleVo> getByFatherId(List<EvaluationsubruleVo> mEvaluationsubrules, String fatherid){
|
List<EvaluationsubruleVo> reslist = new ArrayList<>();
|
|
for(int i =0; i<mEvaluationsubrules.size(); i++){
|
if (Objects.equals(mEvaluationsubrules.get(i).getFatherid(), fatherid)){
|
reslist.add(mEvaluationsubrules.get(i));
|
}
|
}
|
|
return reslist;
|
}
|
|
/**
|
* 通过fatherid找到父评分项( 默认父评分项只有一个)
|
* @param mEvaluationsubrules
|
* @param fatherid
|
* @return
|
*/
|
private static EvaluationsubruleVo findByFatherIdVo(List<EvaluationsubruleVo> mEvaluationsubrules, String fatherid){
|
|
if (fatherid == null)return null;
|
|
EvaluationsubruleVo resEvaluationsubrule = new EvaluationsubruleVo();
|
|
for(int i =0; i<mEvaluationsubrules.size(); i++){
|
if (mEvaluationsubrules.get(i).getGuid().equals(fatherid)){
|
resEvaluationsubrule = mEvaluationsubrules.get(i);
|
break;
|
}
|
}
|
|
return resEvaluationsubrule;
|
}
|
|
/**
|
* 通过fatherid找到父评分项( 默认父评分项只有一个)
|
* @param mEvaluationsubrules
|
* @param fatherid
|
* @return
|
*/
|
private static Evaluationsubrule findByFatherId(List<Evaluationsubrule> mEvaluationsubrules, String fatherid){
|
|
if (fatherid == null)return null;
|
|
Evaluationsubrule resEvaluationsubrule = new Evaluationsubrule();
|
|
for(int i =0; i<mEvaluationsubrules.size(); i++){
|
if (mEvaluationsubrules.get(i).getGuid().equals(fatherid)){
|
resEvaluationsubrule = mEvaluationsubrules.get(i);
|
break;
|
}
|
}
|
|
return resEvaluationsubrule;
|
}
|
|
/**
|
*
|
* @param mEvaluationsubrules
|
* @param Guid
|
* @return
|
*/
|
private static EvaluationsubruleVo getByGuid(List<EvaluationsubruleVo> mEvaluationsubrules, String Guid){
|
EvaluationsubruleVo resEvaluationsubrule = new EvaluationsubruleVo();
|
|
for(int i =0; i<mEvaluationsubrules.size(); i++){
|
if (mEvaluationsubrules.get(i).getGuid().equals(Guid)){
|
resEvaluationsubrule = mEvaluationsubrules.get(i);
|
}
|
}
|
|
return resEvaluationsubrule;
|
}
|
|
/**
|
* 新增一个TextView
|
* @param linearLayout
|
* @param text
|
* @param size
|
* @return
|
*/
|
private LinearLayout generateNewTextView(LinearLayout linearLayout, String text, int size){
|
// linearLayout.setPadding(dip2px(context, 5), dip2px(context, 5), dip2px(context, 5), dip2px(context, 5));
|
LinearLayout.LayoutParams LL_LP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
TextView textView = new TextView(this);
|
textView.setText(text);
|
textView.setLayoutParams(LL_LP);
|
textView.setTextSize(size);
|
// textView.setWidth(0);
|
// textView.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
|
// textView.setInputType(InputType.TYPE_CLASS_TEXT);
|
textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
textView.setPadding(dip2px(context, 5), dip2px(context, 5), dip2px(context, 5), dip2px(context, 5));
|
textView.setBackgroundColor(0);
|
textView.setTextColor(Color.BLACK);
|
textView.setHintTextColor(Color.rgb(199, 199, 199));
|
|
linearLayout.addView(textView, LL_LP);
|
|
return linearLayout;
|
}
|
|
/**
|
* 生成一个空的规范考核项的CardView
|
* @param linearLayout
|
* @return
|
*/
|
private CardView generateNewCardView(LinearLayout linearLayout){
|
|
LinearLayout.LayoutParams CV_LP1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
CardView cardView = new CardView(this);
|
cardView.setLayoutParams(new CardView.LayoutParams(
|
CardView.LayoutParams.MATCH_PARENT, // width
|
dip2px(context, 50))); // height
|
cardView.setPreventCornerOverlap(true);
|
cardView.setRadius(dip2px(context, 4));
|
cardView.setCardElevation(dip2px(context, 6));
|
cardView.setBackgroundColor(Color.WHITE);
|
|
cardView.setLayoutParams(CV_LP1);
|
|
final CardView.LayoutParams CV_LP = new CardView.LayoutParams(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT);
|
CV_LP.setMargins(dip2px(context, 5), dip2px(context, 5), dip2px(context, 5), dip2px(context, 5));
|
|
cardView.setLayoutParams(CV_LP);
|
|
cardView.addView(linearLayout, CV_LP);
|
|
return cardView;
|
}
|
|
/**
|
* 创建一个新的LinerLayout布局
|
* @return
|
*/
|
private LinearLayout generateNewLinearLayout(int orientation) {
|
|
LinearLayout linearLayout = new LinearLayout(this);
|
linearLayout.setPadding(dip2px(context, 5), dip2px(context, 5), dip2px(context, 5), dip2px(context, 5));
|
LinearLayout.LayoutParams LL_LP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
linearLayout.setLayoutParams(LL_LP);
|
linearLayout.setOrientation(orientation);
|
// linearLayout.setOrientation(LinearLayout.VERTICAL);
|
// linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
|
return linearLayout;
|
}
|
|
/**
|
* 创建一个新的LsitView
|
* @param mData
|
* @param linearLayout
|
* @return
|
*/
|
private LinearLayout generateNewListView(final List<EvaluationsubruleVo> mData, LinearLayout linearLayout){
|
|
//*****下面是生成具体评分列表(ListView)*****
|
ListView listView = new ListView(this);
|
// listView.setMinimumHeight(500);
|
LinearLayout.LayoutParams LL_LP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
listView.setLayoutParams(LL_LP);
|
|
final AllListViewAdapter<EvaluationsubruleVo> myAdapter;
|
|
if (RULETYPE == 1){
|
myAdapter = new AllListViewAdapter<EvaluationsubruleVo>() {
|
@Override
|
public void bindView(ViewHolder holder, EvaluationsubruleVo obj) {
|
|
}
|
};
|
}else{//(RULETYPE == 2)
|
myAdapter = new AllListViewAdapter<EvaluationsubruleVo>((ArrayList<EvaluationsubruleVo>) mData, R.layout.item_gradelist_2) {
|
@Override
|
public void bindView(ViewHolder holder, final EvaluationsubruleVo obj) {
|
final EvaluationsubruleVo tmpFatherVo = findByFatherIdVo(allEvaluationsubruleVos, obj.getFatherid());
|
final String mutichoice = tmpFatherVo.getMutichoice();
|
//*****下面为三种CheckBox监听事件********************************************************************
|
if (Objects.equals(mutichoice, SINGELSELECT)){//单选
|
holder.setOnCheckedChangeListener(R.id.CB_item, new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
if (!buttonView.isPressed())return;//加这一条,否则当setChecked()时会触发此listener
|
obj.setSelected(isChecked);
|
for (int i = 0; i < adapters.size(); i++){
|
Boolean bool = false;
|
AllListViewAdapter<EvaluationsubruleVo> tmpAdapter = adapters.get(i);
|
for (int y = 0; y < tmpAdapter.getCount(); y++){//定位点击的评分项所在父项
|
if (Objects.equals(obj.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
bool = true;
|
break;
|
}
|
}
|
if (bool) {//将评分项所在父项的其他子项至为false(不被选取状态)
|
for (int y = 0; y < tmpAdapter.getCount(); y++){
|
if (!Objects.equals(obj.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
tmpAdapter.getItem(y).setSelected(false);
|
// tmpAdapter.getItem(y).setGrade(tmpAdapter.getItem(y).getDefaultvalue());
|
}
|
}
|
tmpAdapter.notifyDataSetChanged();
|
}
|
}
|
}
|
});
|
}
|
else if (Objects.equals(mutichoice, MUTISELECT)){//多选
|
//CheckBox监听事件
|
holder.setOnCheckedChangeListener(R.id.CB_item, new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
int tmpScore = 0;
|
if (sign == 1) tmpScore = getMaxScore(obj,mutichoice);
|
else if (sign == -1) tmpScore = getMinScore(obj, mutichoice);
|
if (Math.abs(Integer.parseInt(obj.getGrade())) >= Math.abs(tmpScore)) obj.setGrade(String.valueOf(tmpScore));
|
obj.setSelected(isChecked);
|
notifyDataSetChanged();
|
}
|
});
|
}
|
else if (Objects.equals(mutichoice, ALLSELECT)){//全选
|
holder.setClickable(R.id.CB_item, false);
|
// holder.setEnabled(R.id.CB_item, false);
|
}
|
//*****上面为三种CheckBox监听事件********************************************************************
|
|
//CheckBox
|
// holder.setSelect(R.id.CB_item, obj.isSelected());
|
|
//设置能否点击
|
if(!obj.isSelected()){
|
obj.setGrade(obj.getDefaultvalue());//取消勾选时分数变为默认分数
|
holder.setChecked(R.id.CB_item, false);
|
holder.setEnabled(R.id.tv_item, false);
|
holder.setEnabled(R.id.TV_grade, false);
|
holder.setEnabled(R.id.ll_item, false);
|
holder.setEnabled(R.id.BT_minus, false);
|
holder.setEnabled(R.id.BT_plus, false);
|
}else {
|
holder.setChecked(R.id.CB_item, true);
|
holder.setEnabled(R.id.tv_item, true);
|
holder.setEnabled(R.id.TV_grade, true);
|
holder.setEnabled(R.id.ll_item,true);
|
holder.setEnabled(R.id.BT_minus, true);
|
holder.setEnabled(R.id.BT_plus, true);
|
}
|
|
//基本评分项
|
if(Objects.equals(mutichoice, ALLSELECT))//全选
|
holder.setText(R.id.tv_item, obj.getItemname() + "(" + obj.getMaxscore() + "分)");
|
else
|
holder.setText(R.id.tv_item, obj.getItemname());
|
|
//避免分数为null
|
if (obj.getGrade() == null)
|
obj.setGrade("0");
|
holder.setText(R.id.TV_grade, obj.getGrade());
|
|
//点击评分项文字选择评分数值
|
holder.setOnClickListener(R.id.ll_item, new OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
int maxScore = 0, minScore = 0;
|
//按照打分方式设定分数范围
|
maxScore = getMaxScore(obj, mutichoice);
|
minScore = getMinScore(obj, mutichoice);
|
showChoiceDialog(Integer.toString(minScore), Integer.toString((minScore+maxScore)/2), Integer.toString(maxScore),obj, adapters);
|
// obj.setGrade(tmpGrade);
|
notifyDataSetChanged();
|
}
|
});
|
|
//减号监听事件
|
holder.setOnClickListener(R.id.BT_minus, new OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
int minScore;
|
//按照打分方式设定分数范围
|
minScore = getMinScore(obj, mutichoice);
|
try {
|
int tmpScore = Integer.parseInt(obj.getGrade());
|
|
if (tmpScore > minScore) {
|
obj.setGrade(Integer.toString(tmpScore - 1));
|
// holder.setTitle(R.id.TV_grade, obj.getGrade());
|
notifyDataSetChanged();
|
}
|
} catch (NumberFormatException e) {
|
e.printStackTrace();
|
}
|
|
}
|
});
|
|
//加号监听事件
|
holder.setOnClickListener(R.id.BT_plus, new OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
int maxScore;
|
//按照打分方式设定分数范围
|
maxScore = getMaxScore(obj, mutichoice);
|
try {
|
int tmpScore = Integer.parseInt(obj.getGrade());
|
|
if (tmpScore < maxScore) {
|
obj.setGrade(Integer.toString(tmpScore + 1));
|
// holder.setTitle(R.id.TV_grade, obj.getGrade());
|
notifyDataSetChanged();
|
}
|
} catch (NumberFormatException e) {
|
e.printStackTrace();
|
}
|
}
|
});
|
|
}
|
};
|
}
|
|
listView.setAdapter(myAdapter);
|
adapters.add(myAdapter);
|
//*****下面是listView点击事件*****
|
// listView.setOnItemClickListener(new AdapterView.OnSwipeItemClickListener() {
|
// @Override
|
// public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
//// adapterView.g
|
// }
|
// });
|
//*****上面是listView点击事件*****
|
setListViewHeightBasedOnChildren(listView);
|
linearLayout.addView(listView, LL_LP);
|
|
return linearLayout;
|
}
|
|
private void onListDataChanged(BaseAdapter adapter) {
|
adapter.notifyDataSetChanged();
|
|
}
|
|
/**
|
* 计算listView每个Item的高度
|
* @param listView
|
*/
|
public void setListViewHeightBasedOnChildren(ListView listView) {
|
|
// 获取ListView对应的Adapter
|
ListAdapter listAdapter = listView.getAdapter();
|
if (listAdapter == null) {
|
return;
|
}
|
|
int totalHeight = 0;
|
for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount()返回数据项的数目
|
View listItem = listAdapter.getView(i, null, listView);
|
listItem.measure(0, 0); // 计算子项View 的宽高
|
totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
|
}
|
|
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
params.height = totalHeight
|
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
// listView.getDividerHeight()获取子项间分隔符占用的高度
|
// params.height最后得到整个ListView完整显示需要的高度
|
listView.setLayoutParams(params);
|
}
|
|
/**
|
* 创建一个新的按钮
|
* @param linearLayout
|
* @return
|
*/
|
private Button generateNewButtonView(LinearLayout linearLayout, String text, int textColor, int bgColor){
|
|
Button button = new Button(this);
|
// button.setTitle("保存");
|
button.setText(text);
|
button.setTextSize(dip2px(context,12));
|
button.setTextColor(textColor);
|
// button.setBackgroundColor(Color.BLUE);
|
// *******圆角矩形******************************************************************
|
//外部矩形弧度
|
float[] outerRadian = new float[]{20, 20, 20, 20, 20, 20, 20, 20};
|
// 内部矩形与外部矩形的距离
|
// RectF insetDistance = new RectF(100, 100, 50, 50);
|
//内部矩形弧度
|
// float[] insideRadian = new float[]{20, 20, 20, 20, 20, 20, 20, 20};
|
//如果insetDistance与insideRadian设为null亦可
|
RoundRectShape roundRectShape = new RoundRectShape(outerRadian, null, null);
|
ShapeDrawable drawable = new ShapeDrawable(roundRectShape);
|
//指定填充颜色
|
// drawable.getPaint().setColor(Color.argb(255,3,169,244));
|
drawable.getPaint().setColor(bgColor);
|
//指定填充模式
|
drawable.getPaint().setStyle(Paint.Style.FILL);
|
//**********************************************************************************
|
button.setBackground(drawable);
|
|
//LinearLayout.LayoutParams(width, height, weight)
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT, 1.0f);
|
layoutParams.setMargins(dip2px(context,2), dip2px(context,2), dip2px(context,2), dip2px(context,2));//设置margin
|
|
button.setLayoutParams(layoutParams);
|
button.setPadding(dip2px(context,10), dip2px(context,10), dip2px(context,10), dip2px(context,10));
|
|
return button;
|
}
|
|
/**
|
* 上传按钮监听事件
|
*/
|
private class setButtonUploadingClickListener implements OnClickListener{
|
@Override
|
public void onClick(View view) {
|
AlertDialog.Builder choiceDialog = new AlertDialog.Builder(context);
|
choiceDialog.setTitle("确认提交");
|
choiceDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
Uploading();
|
}
|
});
|
choiceDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
|
}
|
});
|
|
choiceDialog.create().show();
|
}
|
}
|
|
/**
|
* 保存按钮监听事件
|
*/
|
private class setButtonSaveClickListener implements OnClickListener{
|
|
@Override
|
public void onClick(View view) {
|
Toast.makeText(context,"保存中", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context,"保存成功", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
/**
|
* 计算所有分数
|
* @param allEvaluationsubrules
|
* @param baseEvaluationsubrule
|
* @return
|
*/
|
private List<EvaluationsubruleVo> caculateGrade(List<EvaluationsubruleVo> allEvaluationsubrules, EvaluationsubruleVo baseEvaluationsubrule){
|
|
List<EvaluationsubruleVo> tmplist = getByFatherId(allEvaluationsubrules, baseEvaluationsubrule.getGuid());
|
// EvaluationsubruleVo fatherEvaluationsubrule = findByFatherIdVo(allEvaluationsubrules, baseEvaluationsubrule.getFatherid());
|
|
if(tmplist.size() == 0){//无子项的评分项
|
// for (int i = 0; i < allEvaluationsubrules.size(); i++){
|
// if(Objects.equals(allEvaluationsubrules.get(i).getAdGuid(), fatherEvaluationsubrule.getAdGuid())) {
|
// if (baseEvaluationsubrule.isSelected()) {//选中的评分项的分数才会被计算
|
// allEvaluationsubrules.get(i).setSelected(true);
|
// if (allEvaluationsubrules.get(i).getGrade() != null) {
|
// int resScore = Integer.parseInt(allEvaluationsubrules.get(i).getGrade());
|
// int subScore = Integer.parseInt(baseEvaluationsubrule.getGrade());
|
// resScore += subScore;
|
// allEvaluationsubrules.get(i).setGrade(String.valueOf(resScore));
|
// } else {
|
// allEvaluationsubrules.get(i).setGrade(baseEvaluationsubrule.getGrade());
|
// }
|
//
|
// return allEvaluationsubrules;
|
// }
|
// break;
|
// }
|
// }
|
return allEvaluationsubrules;
|
}
|
else {//其余有子项的评分项
|
for(int i = 0; i < tmplist.size(); i++) {
|
EvaluationsubruleVo tmpVo = tmplist.get(i);
|
allEvaluationsubrules = caculateGrade(allEvaluationsubrules, tmpVo);//递归
|
// if(fatherEvaluationsubrule != null){
|
|
for (int t = 0; t < allEvaluationsubrules.size(); t++){
|
if(Objects.equals(allEvaluationsubrules.get(t).getGuid(), baseEvaluationsubrule.getGuid())) {
|
if (tmpVo.isSelected()) {//选中的评分项的分数才会被计算
|
allEvaluationsubrules.get(t).setSelected(true);
|
if (allEvaluationsubrules.get(t).getGrade() != null) {
|
int resScore = Integer.parseInt(allEvaluationsubrules.get(t).getGrade());
|
int subScore = Integer.parseInt(tmpVo.getGrade());
|
resScore += subScore;
|
allEvaluationsubrules.get(t).setGrade(String.valueOf(resScore));
|
} else {
|
allEvaluationsubrules.get(t).setGrade(tmpVo.getGrade());
|
}
|
}
|
}
|
}
|
|
}
|
}
|
|
return allEvaluationsubrules;
|
}
|
|
/**
|
* 新增记录
|
* @param allEvaluationsubrules
|
*/
|
private void add(List<EvaluationsubruleVo> allEvaluationsubrules) {
|
// mApplication.getDaoSession().getEvaluationsubruleDao().updateInTx(allEvaluationsubruleVos);
|
List<Itemevaluation> itemevaluationList = new ArrayList<>();
|
itemevaluationList = transformToItemvaluation(allEvaluationsubrules,itemevaluationList);
|
Evaluation evaluation = generateNewEvaluation();
|
try{
|
Call<ResponseBody> putItemEvaluationList = gradeService.putItemEvaluationList(itemevaluationList);
|
putItemEvaluationList.enqueue(new Callback<ResponseBody>() {
|
@Override
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
|
}
|
|
@Override
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
|
}
|
});
|
|
Call<ResponseBody> putEvaluation = evaluationService.putEvaluation(evaluation);
|
putEvaluation.enqueue(new Callback<ResponseBody>() {
|
@Override
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
if (response.body()!=null){
|
Toast.makeText(context,"上传成功", Toast.LENGTH_SHORT).show();
|
}else if (response.errorBody()!=null){
|
Toast.makeText(context,"上传失败", Toast.LENGTH_SHORT).show();
|
}
|
}
|
@Override
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
Toast.makeText(context,"网络连接失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 更新记录
|
* @param allEvaluationsubrules
|
* @param itemevaluationList
|
*/
|
private void update(List<EvaluationsubruleVo> allEvaluationsubrules, List<Itemevaluation> itemevaluationList) {
|
itemevaluationList = transformToItemvaluation(allEvaluationsubrules, itemevaluationList);
|
try {
|
if (evaluation == null) {
|
evaluation = generateNewEvaluation();
|
Call<ResponseBody> putEvaluation = evaluationService.putEvaluation(evaluation);
|
putEvaluation.enqueue(new Callback<ResponseBody>() {
|
@Override
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
// if (response.body() != null)
|
// Toast.makeText(context, "总分添加成功", Toast.LENGTH_SHORT).show();
|
}
|
@Override
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
}
|
});
|
}else {
|
evaluation = updateEvaluation(evaluation);
|
Call<ResponseBody> uploadEvaluation = evaluationService.uploadEvaluation(evaluation);
|
uploadEvaluation.enqueue(new Callback<ResponseBody>() {
|
@Override
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
// if (response.body() != null)
|
// Toast.makeText(context, "总分修改成功", Toast.LENGTH_SHORT).show();
|
}
|
|
@Override
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
|
}
|
});
|
}
|
Call<ResponseBody> uploadItemEvaluationList = gradeService.uploadItemEvaluationList(itemevaluationList);
|
uploadItemEvaluationList.enqueue(new Callback<ResponseBody>() {
|
@Override
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
|
if (response.body() != null) {
|
Toast.makeText(context, "修改成功", Toast.LENGTH_SHORT).show();
|
} else if (response.errorBody() != null) {
|
Toast.makeText(context, "修改失败", Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFailure(Call<ResponseBody> call, Throwable t) {
|
Toast.makeText(context, "网络连接失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 数据传递
|
* @param allEvaluationsubrules
|
* @param itemevaluationList
|
*/
|
private List<Itemevaluation> transformToItemvaluation(List<EvaluationsubruleVo> allEvaluationsubrules, List<Itemevaluation> itemevaluationList){
|
|
if(itemevaluationList != null && allEvaluationsubrules.size() == itemevaluationList.size()){
|
for (int i = 0; i < allEvaluationsubrules.size(); i++){
|
for(int y = 0; y < itemevaluationList.size(); y++) {
|
if(Objects.equals(allEvaluationsubrules.get(i).getGuid(), itemevaluationList.get(y).getEsrguid())) {
|
// itemevaluationList.get(i).setIeguid(UUIDGenerator.generate16ShortUUID());
|
// itemevaluationList.get(i).setIguid(inspectionGuid);
|
// itemevaluationList.get(i).setStguid(subtask.getStguid());
|
// itemevaluationList.get(i).setSguid(scense.getAdGuid());
|
// itemevaluationList.get(i).setSensename(scense.getName());
|
// itemevaluationList.get(i).setErguid(evaluationruleTitle.getAdGuid());
|
// itemevaluationList.get(i).setRulename(evaluationruleTitle.getRulename());
|
// itemevaluationList.get(i).setRuletype(evaluationruleTitle.getRuletype());
|
// itemevaluationList.get(i).setErtype(allEvaluationsubruleVos.get(i).getErtype());
|
// itemevaluationList.get(i).setEsrguid(allEvaluationsubruleVos.get(i).getAdGuid());
|
// itemevaluationList.get(i).setName(allEvaluationsubruleVos.get(i).getItemname());
|
try {
|
if (allEvaluationsubrules.get(i).isSelected())
|
itemevaluationList.get(y).setValue(allEvaluationsubrules.get(i).getGrade());
|
else
|
itemevaluationList.get(y).setValue(null);
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
// itemevaluationList.get(i).setResultafter(" resultafter");
|
// itemevaluationList.get(i).setVecheckvalue(" vecheckvalue");
|
// itemevaluationList.get(i).setGrade(" Grade");
|
// itemevaluationList.get(i).setExtension2(" extension2");
|
// itemevaluationList.get(i).setTitle(" extension3");
|
// itemevaluationList.get(i).setRemark(" remark");
|
break;
|
}
|
}
|
}
|
}
|
else {
|
for (int i = 0; i < allEvaluationsubrules.size(); i++){
|
|
Itemevaluation itemevaluation = new Itemevaluation();
|
|
itemevaluation.setIeguid(UUIDGenerator.generate16ShortUUID());
|
itemevaluation.setIguid(inspectionGuid);
|
itemevaluation.setStguid(subtask.getStguid());
|
itemevaluation.setSguid(scense.getGuid());
|
itemevaluation.setSensename(scense.getName());
|
itemevaluation.setErguid(evaluationruleTitle.getGuid());
|
itemevaluation.setRulename(evaluationruleTitle.getRulename());
|
// itemevaluation.setRuletype(evaluationruleTitle.getRuletype() + 0);//服务器数据类型未boolean,错误
|
// itemevaluation.setErtype(allEvaluationsubruleVos.get(i).getErtype() + 0);
|
itemevaluation.setEsrguid(allEvaluationsubrules.get(i).getGuid());
|
itemevaluation.setName(allEvaluationsubrules.get(i).getItemname());
|
try {
|
if (allEvaluationsubrules.get(i).isSelected())
|
itemevaluation.setValue(allEvaluationsubrules.get(i).getGrade());
|
else
|
itemevaluation.setValue(null);
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
|
itemevaluationList.add(itemevaluation);
|
}
|
}
|
|
return itemevaluationList;
|
}
|
|
/**
|
* 分数选择对话框
|
* @param lowestScore
|
* @param halfScore
|
* @param fullScore
|
* @param obj
|
* @param adapters
|
*/
|
private void showChoiceDialog(final String lowestScore, final String halfScore, final String fullScore, final EvaluationsubruleVo obj,
|
final List<AllListViewAdapter> adapters){
|
AlertDialog.Builder choiceDialog = new AlertDialog.Builder(this);
|
// choiceDialog.setIcon(R.drawable.icon_dialog);
|
choiceDialog.setTitle("选择分数");
|
choiceDialog.setPositiveButton(fullScore,
|
new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
// ...To-do
|
try {
|
obj.setGrade(fullScore);
|
for (int i = 0; i < adapters.size(); i++)
|
adapters.get(i).notifyDataSetChanged();
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
});
|
choiceDialog.setNeutralButton(lowestScore,
|
new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
// ...To-do
|
try {
|
obj.setGrade(lowestScore);
|
for (int i = 0; i < adapters.size(); i++)
|
adapters.get(i).notifyDataSetChanged();
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
});
|
choiceDialog.setNegativeButton(halfScore,
|
new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
// ...To-do
|
try {
|
obj.setGrade(halfScore);
|
for (int i = 0; i < adapters.size(); i++)
|
adapters.get(i).notifyDataSetChanged();
|
}catch (NullPointerException e){
|
e.printStackTrace();
|
}
|
}
|
});
|
// 创建实例并显示
|
choiceDialog.create().show();
|
}
|
|
/**
|
* 数据传递(List)
|
* @param evaluationsubruleList
|
* @param evaluationsubruleVoList
|
* @return
|
*/
|
private List<EvaluationsubruleVo> transformToEvaluationsubruleVo(List<Evaluationsubrule> evaluationsubruleList, List<EvaluationsubruleVo> evaluationsubruleVoList){
|
|
for(int i=0; i<evaluationsubruleList.size(); i++){
|
EvaluationsubruleVo tmpVo = new EvaluationsubruleVo();
|
Evaluationsubrule tmp = evaluationsubruleList.get(i);
|
Evaluationsubrule tmpfather = tmp;
|
if (tmp.getFatherid() != null && !tmp.getFatherid().equals(""))
|
tmpfather = findByFatherId(evaluationsubruleList, tmp.getFatherid());
|
//确定默认分数的正负
|
if (sign == 1) tmpVo.setDefaultvalue(tmp.getDefaultvalue());
|
else if (sign == -1 && tmpfather != null){
|
int defaultvalue = Integer.parseInt(tmp.getDefaultvalue());
|
if (Objects.equals(tmpfather.getExtension1(), ALLSELECT))
|
tmpVo.setDefaultvalue(String.valueOf(defaultvalue - (tmp.getMaxscore())));
|
else
|
tmpVo.setDefaultvalue(String.valueOf(defaultvalue - (tmpfather.getMaxscore())));
|
}
|
// tmpVo.setSelected(false);
|
tmpVo.setGuid(tmp.getGuid());
|
tmpVo.setErguid(tmp.getErguid());
|
tmpVo.setErtype(tmp.getErtype());
|
tmpVo.setFatherid(tmp.getFatherid());
|
tmpVo.setFathername(tmp.getFathername());
|
tmpVo.setUsedanalyse(tmp.getUsedanalyse());
|
tmpVo.setItemname(tmp.getItemname());
|
tmpVo.setItemdescription(tmp.getItemdescription());
|
tmpVo.setMinscore(tmp.getMinscore());
|
tmpVo.setMaxscore(tmp.getMaxscore());
|
tmpVo.setDisplayid(tmp.getDisplayid());
|
tmpVo.setDisplaylevel(tmp.getDisplaylevel());
|
tmpVo.setProblemlist(tmp.getProblemlist());
|
tmpVo.setGitlist(tmp.getGitlist());
|
tmpVo.setDevicelist(tmp.getDevicelist());
|
tmpVo.setCreatedate(tmp.getCreatedate());
|
tmpVo.setUpdatedate(tmp.getUpdatedate());
|
// tmpVo.setGrade(tmp.getExtension1());
|
tmpVo.setMutichoice(tmp.getExtension1());
|
// tmpVo.setTitle(tmp.getTitle());
|
tmpVo.setRemark(tmp.getRemark());
|
|
evaluationsubruleVoList.add(tmpVo);
|
}
|
return evaluationsubruleVoList;
|
}
|
|
/**
|
* 巡查综合评估表
|
* @return
|
*/
|
private Evaluation generateNewEvaluation(){
|
Evaluation evaluation = new Evaluation();
|
evaluation.setGuid(UUIDGenerator.generate16ShortUUID());
|
evaluation.setIguid(inspectionGuid);
|
evaluation.setStguid(subtask.getStguid());
|
evaluation.setSguid(scense.getGuid());
|
evaluation.setScensetypeid(scense.getTypeid());
|
evaluation.setScensetype(scense.getType());
|
evaluation.setSubscensetypeid(scense.getScensesubtypeid());
|
evaluation.setSubscensetype(scense.getScensesubtype());
|
// evaluation.setErtype(evaluationruleTitle.getRuletype());
|
evaluation.setProvincecode(scense.getProvincecode());
|
evaluation.setProvincename(scense.getProvincename());
|
evaluation.setCitycode(scense.getCitycode());
|
evaluation.setCityname(scense.getCityname());
|
evaluation.setDistrictcode(scense.getDistrictcode());
|
evaluation.setDistrictname(scense.getDistrictname());
|
evaluation.setTowncode(scense.getTowncode());
|
evaluation.setTownname(scense.getTownname());
|
evaluation.setScensename(scense.getName());
|
evaluation.setScenseaddress(scense.getLocation());
|
evaluation.setEvaluatetime(new Date());
|
evaluation.setEvaluatorguid(mApplication.getCurrentUser().getGuid());
|
evaluation.setEvaluatorusername(mApplication.getCurrentUser().getAcountname());
|
evaluation.setEvaluatorrealname(mApplication.getCurrentUser().getRealname());
|
|
int resScore = getTotalPoint();
|
evaluation.setResultscorebef(String.valueOf(resScore));
|
if (resScore >= Constant.SCORELEVEL1)
|
evaluation.setResultstandardbef(Constant.EXCELLENT);
|
else if (resScore >= Constant.SCORELEVEL2)
|
evaluation.setResultstandardbef(Constant.GOOD);
|
else if (resScore >= Constant.SCORELEVEL3)
|
evaluation.setResultstandardbef(Constant.MEDIUM);
|
else
|
evaluation.setResultstandardbef(Constant.BAD);
|
// evaluation.setPromissednum(Integerpromissednum);
|
// evaluation.setChangednum(Integerchangednum);
|
// evaluation.setResultstandardaft(Stringresultstandardaft);
|
// evaluation.setResultscoreaft(Stringresultscoreaft);
|
evaluation.setCreatedate(new Date());
|
// evaluation.setUpdatedate(Dateupdatedate);
|
// evaluation.setExtension1(Stringextension1);
|
// evaluation.setExtension2(Stringextension2);
|
// evaluation.setTitle(Stringextension3);
|
// evaluation.setRemark(String remark);
|
return evaluation;
|
}
|
|
//获取总分
|
private int getTotalPoint() {
|
int resScore = 0;
|
for (EvaluationsubruleVo evaluationsubruleVo : baseEvaluationsubruleVos) {
|
String grade = evaluationsubruleVo.getGrade();
|
int subScore = 0;
|
if (grade != null && !grade.isEmpty()) {
|
subScore = Integer.parseInt(evaluationsubruleVo.getGrade());
|
}
|
resScore += subScore;
|
}
|
if (sign == -1) resScore = TOTALPOINTS - Math.abs(resScore);//减分模式需要计算总分(总分应该为正数)
|
return resScore;
|
}
|
|
/**
|
* 更新巡查综合评估表
|
* @param evaluation
|
* @return
|
*/
|
private Evaluation updateEvaluation(Evaluation evaluation){
|
|
if (Objects.equals(isreform, Constant.BEFOREREFORM)){//整改前
|
int resScore = 0;
|
for (EvaluationsubruleVo evaluationsubruleVo : baseEvaluationsubruleVos) {
|
int subScore = 0;
|
try {
|
subScore = Integer.parseInt(evaluationsubruleVo.getGrade());
|
} catch (NumberFormatException e) {
|
e.printStackTrace();
|
}
|
resScore += subScore;
|
}
|
if (sign == -1) resScore = TOTALPOINTS - Math.abs(resScore);//减分模式需要计算总分(总分应该为正数)
|
evaluation.setResultscorebef(String.valueOf(resScore));
|
if (resScore >= Constant.SCORELEVEL1)
|
evaluation.setResultstandardbef(Constant.EXCELLENT);
|
else if (resScore >= Constant.SCORELEVEL2)
|
evaluation.setResultstandardbef(Constant.GOOD);
|
else if (resScore >= Constant.SCORELEVEL3)
|
evaluation.setResultstandardbef(Constant.MEDIUM);
|
else
|
evaluation.setResultstandardbef(Constant.BAD);
|
}else if (Objects.equals(isreform, Constant.AFTERREFORM)){//整改后
|
int resScore = 0;
|
for (EvaluationsubruleVo evaluationsubruleVo : baseEvaluationsubruleVos) {
|
int subScore = 0;
|
try {
|
subScore = Integer.parseInt(evaluationsubruleVo.getGrade());
|
} catch (NumberFormatException e) {
|
e.printStackTrace();
|
}
|
resScore += subScore;
|
}
|
if (sign == -1) resScore = TOTALPOINTS - Math.abs(resScore);//减分模式需要计算总分(总分应该为正数)
|
evaluation.setResultscoreaft(String.valueOf(resScore));
|
if (resScore >= Constant.SCORELEVEL1)
|
evaluation.setResultstandardaft(Constant.EXCELLENT);
|
else if (resScore >= Constant.SCORELEVEL2)
|
evaluation.setResultstandardaft(Constant.GOOD);
|
else if (resScore >= Constant.SCORELEVEL3)
|
evaluation.setResultstandardaft(Constant.MEDIUM);
|
else
|
evaluation.setResultstandardaft(Constant.BAD);
|
}
|
return evaluation;
|
}
|
|
/**
|
* 评分表格标题
|
* @param evaluationrule
|
* @return
|
*/
|
private EvaluationsubruleVo transformToEvaluationsubruleVo(Evaluationrule evaluationrule){
|
|
EvaluationsubruleVo evaluationsubruleVo = new EvaluationsubruleVo();
|
evaluationsubruleVo.setGuid(evaluationrule.getGuid());
|
evaluationsubruleVo.setFatherid(TITLE);//表示为标题
|
|
return evaluationsubruleVo;
|
}
|
|
/**
|
* 最高分
|
* @param tmpVo
|
* @param mutichoice
|
* @return
|
*/
|
public int getMaxScore(EvaluationsubruleVo tmpVo, String mutichoice){
|
int maxScore = 0;
|
EvaluationsubruleVo tmpFatherVo = findByFatherIdVo(allEvaluationsubruleVos, tmpVo.getFatherid());
|
int rangeFather = tmpFatherVo.getMaxscore() - 0;
|
int range = tmpVo.getMaxscore() - 0;
|
|
if (Objects.equals(mutichoice, SINGELSELECT)) {//单选
|
if (sign == 1) maxScore = tmpFatherVo.getMaxscore();
|
else if (sign == -1) maxScore = (tmpFatherVo.getMaxscore() - rangeFather);
|
}else if (Objects.equals(mutichoice, MUTISELECT)){//多选
|
for (int i = 0; i < adapters.size(); i++){
|
Boolean bool = false;
|
AllListViewAdapter<EvaluationsubruleVo> tmpAdapter = adapters.get(i);
|
for (int y = 0; y < tmpAdapter.getCount(); y++){//定位点击的评分项所在父项
|
if (Objects.equals(tmpVo.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
bool = true;
|
break;
|
}
|
}
|
if (bool) {//计算剩余分数
|
int tmpScore = 0;
|
for (int y = 0; y < tmpAdapter.getCount(); y++){
|
if (!Objects.equals(tmpVo.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
if (tmpAdapter.getItem(y).isSelected())
|
tmpScore += Integer.parseInt( tmpAdapter.getItem(y).getGrade());
|
}
|
}
|
if (sign == 1) maxScore = (tmpFatherVo.getMaxscore() - tmpScore);
|
else if (sign == -1) maxScore = (tmpFatherVo.getMaxscore() - rangeFather);
|
}
|
}
|
}else if (Objects.equals(mutichoice, ALLSELECT)){//全选
|
if (sign == 1) maxScore = tmpVo.getMaxscore();
|
else if (sign == -1) maxScore = (tmpVo.getMaxscore() - range) ;
|
}
|
|
return maxScore;
|
}
|
|
/**
|
* 最低分
|
* @param tmpVo
|
* @param mutichoice
|
* @return
|
*/
|
public int getMinScore(EvaluationsubruleVo tmpVo, String mutichoice){
|
int minScore = 0;
|
EvaluationsubruleVo tmpFatherVo = findByFatherIdVo(allEvaluationsubruleVos, tmpVo.getFatherid());
|
int rangeFather = tmpFatherVo.getMaxscore() - 0;
|
int range = tmpVo.getMaxscore() - 0;
|
|
if (Objects.equals(mutichoice, SINGELSELECT)) {//单选
|
if (sign == 1) minScore = tmpFatherVo.getMinscore();
|
else if (sign == -1) minScore = (tmpFatherVo.getMinscore() - rangeFather);
|
}else if (Objects.equals(mutichoice, MUTISELECT)){//多选
|
for (int i = 0; i < adapters.size(); i++){
|
Boolean bool = false;
|
AllListViewAdapter<EvaluationsubruleVo> tmpAdapter = adapters.get(i);
|
for (int y = 0; y < tmpAdapter.getCount(); y++){//定位点击的评分项所在父项
|
if (Objects.equals(tmpVo.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
bool = true;
|
break;
|
}
|
}
|
if (bool) {//计算剩余分数
|
int tmpScore = 0;
|
for (int y = 0; y < tmpAdapter.getCount(); y++){
|
if (!Objects.equals(tmpVo.getGuid(), tmpAdapter.getItem(y).getGuid())){
|
if (tmpAdapter.getItem(y).isSelected())
|
tmpScore += Integer.parseInt( tmpAdapter.getItem(y).getGrade());
|
}
|
}
|
if (sign == 1) {
|
if (tmpScore >= tmpFatherVo.getMinscore())
|
minScore = 0;
|
else minScore = tmpFatherVo.getMinscore();
|
}
|
else if (sign == -1) minScore = (tmpFatherVo.getMinscore() - rangeFather - tmpScore);
|
}
|
}
|
}else if (Objects.equals(mutichoice, ALLSELECT)){//全选
|
if (sign == 1) minScore = tmpVo.getMinscore();
|
else if (sign == -1) minScore = (tmpVo.getMinscore() - range) ;
|
}
|
return minScore;
|
}
|
|
/**
|
* 设定打分模式
|
* @param sign
|
*/
|
public void setSign(int sign){
|
this.sign = sign;
|
}
|
|
public int getSign() {
|
return sign;
|
}
|
|
/**
|
* 判定是否所有项都已评分
|
* @return
|
*/
|
@NonNull
|
private Boolean isCommited(){
|
for (int i = 0; i < adapters.size(); i++){
|
AllListViewAdapter<EvaluationsubruleVo> tmpAdapter = adapters.get(i);
|
Boolean tmpbool = false;
|
for (int y = 0; y < tmpAdapter.getCount(); y++){
|
if (tmpAdapter.getItem(y).isSelected()) tmpbool = true;
|
}
|
if (!tmpbool)
|
return false;
|
}
|
|
return true;
|
}
|
|
/**
|
* 上传至服务器
|
*/
|
public void Uploading(){
|
if (!isCommited()){//判定是否所有项都已评分
|
Toast.makeText(context,"有未评分项,请继续评分", Toast.LENGTH_SHORT).show();
|
return;
|
}
|
//将所有基础评分存储到allEvaluationsubrules中
|
for(int i = 0; i < adapters.size(); i++){
|
AllListViewAdapter<EvaluationsubruleVo> tmpAdapter = adapters.get(i);
|
|
for (int x = 0; x < tmpAdapter.getCount(); x++){
|
EvaluationsubruleVo tmpEvaluationsubrule = tmpAdapter.getItem(x);
|
|
for (int y = 0; y < allEvaluationsubruleVos.size(); y++){
|
if(Objects.equals(allEvaluationsubruleVos.get(y).getGuid(), tmpEvaluationsubrule.getGuid()))
|
allEvaluationsubruleVos.get(y).setGrade(tmpEvaluationsubrule.getGrade());//基本单元评分项
|
// if(allEvaluationsubruleVos.get(y).getAdGuid() == tmpEvaluationsubrule.getFatherid())
|
// allEvaluationsubruleVos.get(y).setGrade(allEvaluationsubruleVos.get(y).getGrade() + tmpEvaluationsubrule.getGrade());
|
}
|
|
}
|
}
|
//将所有父评分项计算填充至allEvaluationsubrules
|
for(int i = 0; i < baseEvaluationsubruleVos.size(); i++){
|
allEvaluationsubruleVos = caculateGrade(allEvaluationsubruleVos, baseEvaluationsubruleVos.get(i));
|
}
|
|
Toast.makeText(context,"上传中", Toast.LENGTH_SHORT).show();
|
|
// 上传至服务器
|
// Call<List<Itemevaluation>> getItemEvaluationList = gradeService.getItemEvaluationList(subtask.getStguid());
|
if (ismDataexist) {
|
try {
|
update(allEvaluationsubruleVos, itemevaluationList);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
} else {
|
try {
|
add(allEvaluationsubruleVos);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
finish();
|
}
|
|
/**
|
*
|
*/
|
interface GradeService{
|
@PUT("itemevaluation/addlist/")
|
Call<ResponseBody> putItemEvaluationList(@Body List<Itemevaluation> itemevaluationList);
|
|
@GET("itemevaluation/subtask/{SubTakGuid}/")
|
Call<List<Itemevaluation>> getItemEvaluationList(@Path("SubTakGuid") String subtaskGuid);
|
|
@POST("itemevaluation/uplist/")
|
Call<ResponseBody> uploadItemEvaluationList(@Body List<Itemevaluation> itemevaluationList);
|
}
|
|
|
}
|