using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;
using System.Linq;
using DataModel.Model;
using LitJson;
public class ScoreBase : MonoBehaviour
{
///
/// 评估序号
///
public int code;
///
/// 评估点
///
[DisplayOnly]
public string scoreName;
///
/// 岗位名
///
[DisplayOnly]
public string seatName;
///
/// 步骤序号
///
[DisplayOnly]
public int stepOrder;
///
/// 分值
///
[DisplayOnly]
public int scoreValue;
[Header("如果有前置打分点,则配置有效")]
///
/// 是否有前置打分点
///
public bool hasFrontPoint;
///
/// 前置评估点编号
///
public int frontScorePointCode;
///
/// 前置打分点
///
[HideInInspector]
public ScoreBase frontScorePoint;
[Header("==============")]
///
/// 评分点是否正确
///
[DisplayOnly]
public bool IsRight;
///
/// 是否激活
///
[DisplayOnly]
public bool IsActive = false;
///
/// 判断点完成顺序
///
[HideInInspector]
public int Completed = 0;
public virtual void Init(string subjectName,int code)
{
this.code = code;
XmlNode node = ScoreManage.scoreXML.SelectSingleNode("root/Sub_" + subjectName);
foreach (XmlNode item in node.ChildNodes)
{
if(item.Attributes["code"].Value==code.ToString())
{
scoreName = item.Attributes["Text"].Value;
seatName= item.Attributes["seatName"].Value;
scoreValue = int.Parse(item.Attributes["scoreValue"].Value);
stepOrder = int.Parse(item.Attributes["stepOrder"].Value);
break;
}
}
//获取前置
if (hasFrontPoint)
{
ScoreBase sb= transform.parent.GetComponentsInChildren(true).ToList().Find(a => a.code == frontScorePointCode);
if(sb!=null)
{
frontScorePoint = sb;
}
else
{
Debug.LogError("前置条件错误:" + subjectName + " " + code);
}
}
}
///
/// 激活(按科目激活)
///
public virtual void SetActive(bool isActive)
{
IsActive = isActive;
if(isActive)
{
transform.GetComponentsInChildren(true).ToList().ForEach(a =>
{
a.AddAction();
});
}
else
{
transform.GetComponentsInChildren(true).ToList().ForEach(a =>
{
a.RemoveAction();
});
}
}
public virtual void SetIsRight()
{
}
///
/// 提交分表分数 (暂定点击步骤结束提交)
///
public virtual void Submit()
{
if (IsActive)
{
SetActive(false);
appraisedetail appraisedetail = new appraisedetail
{
Id = System.Guid.NewGuid().ToString(),
PracticeId = LoadManage.Instance.currentPractice.Id,
AppraiseId = LoadManage.Instance.currentPractice.Id,
SubjectId = LoadManage.Instance.psubjects.Find(a => a.Name == transform.parent.name).SubjectId,
PracticeSubjectId= LoadManage.Instance.psubjects.Find(a => a.Name == transform.parent.name).Id,
UserAccount = LoadManage.Instance.me.user.user_name,
RoleName = seatName,
Idx = code,
Notice = scoreName,
Score = (IsRight ? 0 : -scoreValue),
Completed=(IsRight ? 1:0)
};
//提交数据库
string url = "http://"+MyNetMQClient.CallIP+ "/Handler/Api_Appraise.ashx";
var tmp= new KeyValuePair[2];
tmp[0] = new KeyValuePair("action", "setScore");
tmp[1] = new KeyValuePair("appraiseDetail", JsonMapper.ToJson(appraisedetail));
StartCoroutine(MyNetMQClient.CallPost(url, tmp, result =>
{
var json = JsonMapper.ToObject(result);
if (json.state)
{
Debug.Log("上传分数:++++++++++++++++++++++++++++++" + JsonMapper.ToJson(appraisedetail));
}
else
{
Debug.Log(json.message);
}
}));
}
}
}