@ -2,11 +2,13 @@ using System;
using System.Collections.Generic ;
using System.Threading.Tasks ;
using Microsoft.AspNetCore.Mvc ;
using System.ComponentModel.DataAnnotations ;
using Haoliang.Core.Services ;
using Haoliang.Models. Models. System;
using Haoliang.Models. Models. Production;
using Haoliang.Models. Models. Template;
using Haoliang.Models. System;
using Haoliang.Models. Production;
using Haoliang.Models. Template;
using Haoliang.Models.Common ;
using Haoliang.Models.Models.System ;
namespace Haoliang.Api.Controllers
{
@ -40,11 +42,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetSystemConfigurationAsync ( ) ;
return Ok ( ApiResponse < SystemConfiguration > . Success ( config ) ) ;
return Ok ( ApiResponse < SystemConfiguration > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < SystemConfiguration > . InternalServerError ( $"Error getting system configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < SystemConfiguration > . InternalServerError Result ( $"Error getting system configuration: {ex.Message}" ) ) ;
}
}
@ -57,11 +59,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateSystemConfigurationAsync ( configuration ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating system configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating system configuration: {ex.Message}" ) ) ;
}
}
@ -74,7 +76,7 @@ namespace Haoliang.Api.Controllers
try
{
var targets = await _systemService . GetProductionTargetsAsync ( ) ;
return Ok ( ApiResponse < List < ProductionTargetConfig > > . Success ( targets ) ) ;
return Ok ( ApiResponse < List < ProductionTargetConfig > > . Ok ( targets ) ) ;
}
catch ( Exception ex )
{
@ -91,11 +93,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateProductionTargetsAsync ( targets ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating production targets: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating production targets: {ex.Message}" ) ) ;
}
}
@ -108,11 +110,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetWorkingHoursConfigAsync ( ) ;
return Ok ( ApiResponse < WorkingHoursConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < WorkingHoursConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < WorkingHoursConfig > . InternalServerError ( $"Error getting working hours config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < WorkingHoursConfig > . InternalServerError Result ( $"Error getting working hours config: {ex.Message}" ) ) ;
}
}
@ -125,11 +127,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateWorkingHoursConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating working hours config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating working hours config: {ex.Message}" ) ) ;
}
}
@ -142,11 +144,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetAlertConfigurationAsync ( ) ;
return Ok ( ApiResponse < AlertConfiguration > . Success ( config ) ) ;
return Ok ( ApiResponse < AlertConfiguration > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < AlertConfiguration > . InternalServerError ( $"Error getting alert configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < AlertConfiguration > . InternalServerError Result ( $"Error getting alert configuration: {ex.Message}" ) ) ;
}
}
@ -159,11 +161,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateAlertConfigurationAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating alert configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating alert configuration: {ex.Message}" ) ) ;
}
}
@ -171,16 +173,27 @@ namespace Haoliang.Api.Controllers
/// Get business rules configuration
/// </summary>
[HttpGet("rules")]
public async Task < ActionResult < ApiResponse < List < BusinessRuleConfig> > > > GetBusinessRules ( )
public async Task < ActionResult < ApiResponse < List < Haoliang. Models . System . BusinessRuleConfig> > > > GetBusinessRules ( )
{
try
{
var rules = await _rulesService . GetAllRulesAsync ( ) ;
return Ok ( ApiResponse < List < BusinessRuleConfig > > . Success ( rules ) ) ;
var ruleConfigs = rules . Select ( r = > new Haoliang . Models . System . BusinessRuleConfig
{
RuleId = r . RuleId ,
RuleName = r . RuleName ,
RuleType = r . RuleType ,
Category = r . Category ,
IsEnabled = r . IsEnabled ,
Configuration = r . Configuration ,
CreatedAt = r . CreatedAt ,
UpdatedAt = r . UpdatedAt
} ) . ToList ( ) ;
return Ok ( ApiResponse < List < Haoliang . Models . System . BusinessRuleConfig > > . Ok ( ruleConfigs ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < List < BusinessRuleConfig > > . InternalServerError ( $"Error getting business rules: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < List < Haoliang. Models . System . BusinessRuleConfig> > . InternalServerError ( $"Error getting business rules: {ex.Message}" ) ) ;
}
}
@ -188,16 +201,38 @@ namespace Haoliang.Api.Controllers
/// Create or update business rule
/// </summary>
[HttpPost("rules")]
public async Task < ActionResult < ApiResponse < BusinessRuleConfig> > > CreateOrUpdateBusinessRule ( [ FromBody ] BusinessRuleConfig rule )
public async Task < ActionResult < ApiResponse < Haoliang. Models . System . BusinessRuleConfig> > > CreateOrUpdateBusinessRule ( [ FromBody ] Haoliang . Models . System . BusinessRuleConfig rule )
{
try
{
var result = await _rulesService . CreateOrUpdateRuleAsync ( rule ) ;
return Ok ( ApiResponse < BusinessRuleConfig > . Success ( result ) ) ;
var businessRule = new Haoliang . Core . Services . BusinessRule
{
RuleId = rule . RuleId ,
RuleName = rule . RuleName ,
RuleType = rule . RuleType ,
Category = rule . Category ,
IsEnabled = rule . IsEnabled ,
Configuration = rule . Configuration ,
CreatedAt = rule . CreatedAt ,
UpdatedAt = rule . UpdatedAt
} ;
var result = await _rulesService . CreateOrUpdateRuleAsync ( businessRule ) ;
var resultConfig = new Haoliang . Models . System . BusinessRuleConfig
{
RuleId = result . RuleId ,
RuleName = result . RuleName ,
RuleType = result . RuleType ,
Category = result . Category ,
IsEnabled = result . IsEnabled ,
Configuration = result . Configuration ,
CreatedAt = result . CreatedAt ,
UpdatedAt = result . UpdatedAt
} ;
return Ok ( ApiResponse < Haoliang . Models . System . BusinessRuleConfig > . Ok ( resultConfig ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < BusinessRuleConfig > . InternalServerError ( $"Error creating/updating business rule: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < Haoliang. Models . System . BusinessRuleConfig> . InternalServerError Result ( $"Error creating/updating business rule: {ex.Message}" ) ) ;
}
}
@ -210,11 +245,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _rulesService . DeleteRuleAsync ( ruleId ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error deleting business rule: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error deleting business rule: {ex.Message}" ) ) ;
}
}
@ -222,16 +257,27 @@ namespace Haoliang.Api.Controllers
/// Get statistical analysis rules
/// </summary>
[HttpGet("statistics-rules")]
public async Task < ActionResult < ApiResponse < List < StatisticsRuleConfig> > > > GetStatisticsRules ( )
public async Task < ActionResult < ApiResponse < List < Haoliang. Models . System . StatisticsRuleConfig> > > > GetStatisticsRules ( )
{
try
{
var rules = await _rulesService . GetStatisticsRulesAsync ( ) ;
return Ok ( ApiResponse < List < StatisticsRuleConfig > > . Success ( rules ) ) ;
var ruleConfigs = rules . Select ( r = > new Haoliang . Models . System . StatisticsRuleConfig
{
ConfigId = r . RuleId ,
ConfigName = r . RuleName ,
ConfigType = r . RuleType ,
Formula = r . Configuration ,
GroupBy = "" ,
IsActive = r . IsEnabled ,
CreatedAt = r . CreatedAt ,
UpdatedAt = r . UpdatedAt
} ) . ToList ( ) ;
return Ok ( ApiResponse < List < Haoliang . Models . System . StatisticsRuleConfig > > . Ok ( ruleConfigs ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < List < StatisticsRuleConfig > > . InternalServerError ( $"Error getting statistics rules: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < List < Haoliang. Models . System . StatisticsRuleConfig> > . InternalServerError ( $"Error getting statistics rules: {ex.Message}" ) ) ;
}
}
@ -239,16 +285,27 @@ namespace Haoliang.Api.Controllers
/// Update statistics rules
/// </summary>
[HttpPut("statistics-rules")]
public async Task < ActionResult < ApiResponse < bool > > > UpdateStatisticsRules ( [ FromBody ] List < StatisticsRuleConfig> rules )
public async Task < ActionResult < ApiResponse < bool > > > UpdateStatisticsRules ( [ FromBody ] List < Haoliang. Models . System . StatisticsRuleConfig> rules )
{
try
{
var result = await _rulesService . UpdateStatisticsRulesAsync ( rules ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
var businessRules = rules . Select ( r = > new Haoliang . Core . Services . BusinessRule
{
RuleId = r . ConfigId ,
RuleName = r . ConfigName ,
RuleType = r . ConfigType ,
Category = r . GroupBy ,
IsEnabled = r . IsActive ,
Configuration = r . Formula ,
CreatedAt = r . CreatedAt ,
UpdatedAt = r . UpdatedAt
} ) . ToList ( ) ;
var result = await _rulesService . UpdateStatisticsRulesAsync ( businessRules ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating statistics rules: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating statistics rules: {ex.Message}" ) ) ;
}
}
@ -261,11 +318,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetDataRetentionConfigAsync ( ) ;
return Ok ( ApiResponse < DataRetentionConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < DataRetentionConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < DataRetentionConfig > . InternalServerError ( $"Error getting data retention config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < DataRetentionConfig > . InternalServerError Result ( $"Error getting data retention config: {ex.Message}" ) ) ;
}
}
@ -278,11 +335,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateDataRetentionConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating data retention config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating data retention config: {ex.Message}" ) ) ;
}
}
@ -295,11 +352,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetDashboardConfigAsync ( ) ;
return Ok ( ApiResponse < DashboardConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < DashboardConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < DashboardConfig > . InternalServerError ( $"Error getting dashboard config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < DashboardConfig > . InternalServerError Result ( $"Error getting dashboard config: {ex.Message}" ) ) ;
}
}
@ -312,11 +369,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateDashboardConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating dashboard config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating dashboard config: {ex.Message}" ) ) ;
}
}
@ -329,11 +386,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetExportConfigAsync ( ) ;
return Ok ( ApiResponse < ExportConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < ExportConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < ExportConfig > . InternalServerError ( $"Error getting export config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < ExportConfig > . InternalServerError Result ( $"Error getting export config: {ex.Message}" ) ) ;
}
}
@ -346,11 +403,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateExportConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating export config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating export config: {ex.Message}" ) ) ;
}
}
@ -363,11 +420,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetCollectionConfigAsync ( ) ;
return Ok ( ApiResponse < CollectionConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < CollectionConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < CollectionConfig > . InternalServerError ( $"Error getting collection config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < CollectionConfig > . InternalServerError Result ( $"Error getting collection config: {ex.Message}" ) ) ;
}
}
@ -380,11 +437,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateCollectionConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating collection config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating collection config: {ex.Message}" ) ) ;
}
}
@ -397,11 +454,11 @@ namespace Haoliang.Api.Controllers
try
{
var config = await _systemService . GetNotificationConfigAsync ( ) ;
return Ok ( ApiResponse < NotificationConfig > . Success ( config ) ) ;
return Ok ( ApiResponse < NotificationConfig > . Ok ( config ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < NotificationConfig > . InternalServerError ( $"Error getting notification config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < NotificationConfig > . InternalServerError Result ( $"Error getting notification config: {ex.Message}" ) ) ;
}
}
@ -414,11 +471,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . UpdateNotificationConfigAsync ( config ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error updating notification config: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error updating notification config: {ex.Message}" ) ) ;
}
}
@ -431,11 +488,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . ValidateConfigurationAsync ( configuration ) ;
return Ok ( ApiResponse < ValidationResult > . Success ( result ) ) ;
return Ok ( ApiResponse < ValidationResult > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < ValidationResult > . InternalServerError ( $"Error validating configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < ValidationResult > . InternalServerError Result ( $"Error validating configuration: {ex.Message}" ) ) ;
}
}
@ -469,12 +526,13 @@ namespace Haoliang.Api.Controllers
{
try
{
var result = await _systemService . ImportConfigurationAsync ( configuration ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
var json = System . Text . Json . JsonSerializer . Serialize ( configuration ) ;
var result = await _systemService . ImportConfigurationAsync ( json ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error importing configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error importing configuration: {ex.Message}" ) ) ;
}
}
@ -487,11 +545,11 @@ namespace Haoliang.Api.Controllers
try
{
var result = await _systemService . ResetToDefaultConfigurationAsync ( ) ;
return Ok ( ApiResponse < bool > . Success ( result ) ) ;
return Ok ( ApiResponse < bool > . Ok ( result ) ) ;
}
catch ( Exception ex )
{
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError ( $"Error resetting configuration: {ex.Message}" ) ) ;
return StatusCode ( 500 , ApiResponse < bool > . InternalServerError Result ( $"Error resetting configuration: {ex.Message}" ) ) ;
}
}
@ -504,7 +562,7 @@ namespace Haoliang.Api.Controllers
try
{
var history = await _systemService . GetConfigurationChangeHistoryAsync ( startDate , endDate ) ;
return Ok ( ApiResponse < List < ConfigurationChange > > . Success ( history ) ) ;
return Ok ( ApiResponse < List < ConfigurationChange > > . Ok ( history ) ) ;
}
catch ( Exception ex )
{