获取表单结果2

This commit is contained in:
qianhao.xu 2024-06-05 15:02:11 +08:00
parent 4bbce67791
commit eb584aa00d
5 changed files with 97 additions and 22 deletions

View File

@ -271,7 +271,7 @@ namespace ZR.Admin.WebApi.Controllers
return ToResponse(ResultCode.CUSTOM_ERROR, "数据不合法只能是1或者2");
}
var response = _DeviceTaskExecuteService.AchieveFormResult(query);
var response = _DeviceTaskExecuteService.AchieveFormResult2(query);
return SUCCESS(response);

View File

@ -78,12 +78,7 @@ namespace ZR.Model.MES.dev
[SugarColumn(ColumnName = "form_name")]
public string FormName { get; set; }
/// <summary>
/// 表单结果1
/// </summary>
[SugarColumn(ColumnName = "form_result")]
public int? FormResult { get; set; }
/// <summary>
/// 巡检人
/// </summary>

View File

@ -43,7 +43,7 @@ namespace ZR.Model.MES.dev.Dto
public string FormName { get; set; }
public int? FormResult { get; set; }
public string Person { get; set; }

View File

@ -400,7 +400,7 @@ namespace ZR.Service.MES.dev
List<DeviceTaskExecuteResult1> resultList = Context.Queryable<DeviceTaskExecuteResult1>()
.Where(it => it.PlanType == query.PlanType)
.Where(it=>it.FkPlanId==query.FkPlanId)
.Where(it => it.FkPlanId == query.FkPlanId)
.Where(it => it.FkDeviceId == query.FkDeviceId)
.Where(it => it.FkInspectId == query.FkInspectId)
.ToList();
@ -475,7 +475,7 @@ namespace ZR.Service.MES.dev
else if (resultList.Count > 0)
{
// 直接从结果表中获取
if (resultList.Count > 0)
{
@ -492,20 +492,21 @@ namespace ZR.Service.MES.dev
item.Type = temp[0].FormType;
item.Value = "";
item.Children = resultList.Where(it => it.FormType == FormTypeArray[i]).Select(it => it.FormName).Distinct().ToArray();
List<DeviceTaskExecuteResult1> FormResultArray = resultList.Where(it => it.FormType == FormTypeArray[i]).Where(it=>it.FormResult==1).ToList();
if (FormResultArray.Count == 1) {
List<DeviceTaskExecuteResult1> FormResultArray = resultList.Where(it => it.FormType == FormTypeArray[i]).Where(it => it.FormResult == 1).ToList();
if (FormResultArray.Count == 1)
{
item.Value = FormResultArray[0].FormName;
}
else if(FormResultArray.Count>1)
else if (FormResultArray.Count > 1)
{
string[] str= new string[FormResultArray.Count];
string[] str = new string[FormResultArray.Count];
for (int ii = 0; ii < str.Length; ii++)
{
str[i]=FormResultArray[ii].FormName;
str[i] = FormResultArray[ii].FormName;
}
item.Value= string.Join(", ", str).ToString();
item.Value = string.Join(", ", str).ToString();
}
else
{
@ -520,7 +521,85 @@ namespace ZR.Service.MES.dev
return final_result_list;
}
/// <summary>
/// 获取表单结果
/// 结果表只存选中的结果,多选也只有一个结果
/// </summary>
/// <returns></returns>
public List<DeviceTaskExecuteResult1_result> AchieveFormResult2(DeviceTaskExecuteResult1QueryDto_TaskExecute query)
{
List<DeviceTaskExecuteResult1_result> final_result_list = new List<DeviceTaskExecuteResult1_result>();
// 获取 设备检查项 所有表单类型
List<DeviceFormConfig> all_config_list = Context.Queryable<DeviceFormConfig>().Where(it => it.FkDeviceInspectId == query.FkInspectId).ToList();
int?[] config_type = all_config_list.Select(it => it.Type).Distinct().ToArray();
if (config_type.Length > 0)
{
for (int i = 0; i < config_type.Length; i++)
{
//在结果表里查看是否有结果
DeviceTaskExecuteResult1 executeResult = Context.Queryable<DeviceTaskExecuteResult1>()
.Where(it => it.PlanType == query.PlanType)
.Where(it => it.FkPlanId == query.FkPlanId)
.Where(it => it.FkDeviceId == query.FkDeviceId)
.Where(it => it.FkInspectId == query.FkInspectId)
.Where(it => it.FormType == config_type[0])
.First();
if (executeResult != null)
{
DeviceTaskExecuteResult1_result item = new DeviceTaskExecuteResult1_result();
item.Id = executeResult.Id;
item.Title = executeResult.FormTitle;
item.Value = executeResult.FormName;
item.Type = executeResult.FormType;
item.Children = all_config_list.Where(it => it.Type == config_type[i]).Select(it => it.Content).ToArray();
final_result_list.Add(item);
}
else
{
DeviceTaskExecuteResult1 insertData = new DeviceTaskExecuteResult1();
insertData.Id = SnowFlakeSingle.Instance.NextId().ToString();
insertData.PlanType = query.PlanType;
insertData.FkPlanId = query.FkPlanId;
insertData.FkDeviceId = query.FkDeviceId;
insertData.FormType = config_type[i];
insertData.FormTitle = all_config_list.Where(it => it.Type == config_type[i]).Select(it => it.Title).First();
Context.Insertable(insertData).ExecuteReturnIdentity();
DeviceTaskExecuteResult1_result item = new DeviceTaskExecuteResult1_result();
item.Id = insertData.Id;
item.Title = insertData.FormTitle;
item.Value = "";
item.Type = insertData.FormType;
item.Children = all_config_list.Where(it => it.Type == config_type[i]).Select(it => it.Content).ToArray();
final_result_list.Add(item);
}
}
}
return final_result_list;
}
/// <summary>
/// 更新结果表单
/// </summary>
@ -528,11 +607,11 @@ namespace ZR.Service.MES.dev
/// <returns></returns>
public int UpdateFormResult(DeviceTaskExecuteResult1Dto result)
{
DeviceTaskExecuteResult1 item= result.Adapt<DeviceTaskExecuteResult1>();
DeviceTaskExecuteResult1 item = result.Adapt<DeviceTaskExecuteResult1>();
return Context.Updateable(item).IgnoreColumns(true).EnableDiffLogEvent("更新结果表单").ExecuteCommand();
}
}
}

View File

@ -37,8 +37,9 @@ namespace ZR.Service.MES.dev.IService
List<DeviceFormConfig> AchieveInspectbindForm(int fk_device_inspect_id);
List<DeviceTaskExecuteResult1_result> AchieveFormResult(DeviceTaskExecuteResult1QueryDto_TaskExecute query);
List<DeviceTaskExecuteResult1_result> AchieveFormResult2(DeviceTaskExecuteResult1QueryDto_TaskExecute query);
int UpdateFormResult(DeviceTaskExecuteResult1Dto result);
int UpdateFormResult(DeviceTaskExecuteResult1Dto result);
}
}