public Result PutSpotCheckLogImage([FromBody] SpotCheckLog spotCheckLog)
        {
            spotCheckLog.MarkedDateTime = DateTime.Now;
            ServerConfig.ApiDb.Execute(
                "UPDATE spot_check_log SET `MarkedDateTime` = @MarkedDateTime, `Images` = @Images WHERE `Id` = @Id;",
                spotCheckLog);

            return(Result.GenError <Result>(Error.Success));
        }
        public Result PostSpotCheckLog([FromBody] SpotCheckLog spotCheckLog)
        {
            var data = ServerConfig.ApiDb.Query <SpotCheckLog>("SELECT * FROM `spot_check_log` WHERE MarkedDelete = 0 AND DeviceId = @DeviceId AND PlanId = @PlanId AND PlannedTime = @PlannedTime;"
                                                               , spotCheckLog);

            if (data == null)
            {
                return(Result.GenError <Result>(Error.SpotCheckLogNotExist));
            }
            var createUserId   = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            spotCheckLog.CreateUserId   = createUserId;
            spotCheckLog.MarkedDateTime = markedDateTime;
            ServerConfig.ApiDb.Execute(
                "INSERT INTO spot_check_log (`CreateUserId`, `MarkedDateTime`, `PlannedTime`, `DeviceId`, `ItemId`, `Item`, `PlanId`, `Plan`, `Enable`, `Remind`, `Min`, `Max`, `Unit`, `Reference`, `Remarks`, `Interval`, `Day`, `Month`, `NormalHour`, `Week`, `WeekHour`, `SurveyorId`, `CheckTime`, `Actual`, `Desc`) " +
                "VALUES (@CreateUserId, @MarkedDateTime, @PlannedTime, @DeviceId, @ItemId, @Item, @PlanId, @Plan, @Enable, @Remind, @Min, @Max, @Unit, @Reference, @Remarks, @Interval, @Day, @Month, @NormalHour, @Week, @WeekHour, @SurveyorId, @CheckTime, @Actual, @Desc);",
                spotCheckLog);

            return(Result.GenError <Result>(Error.Success));
        }
        public Result PostSpotCheckImage([FromBody] SpotCheckLog spotCheckLog)
        {
            if (spotCheckLog == null)
            {
                return(Result.GenError <Result>(Error.SpotCheckItemNotExist));
            }

            //var cnt =
            //    //ServerConfig.ApiDb.Query<int>("SELECT COUNT(1) FROM `spot_check_plan` WHERE Id = @PlanId AND `MarkedDelete` = 0;", new { spotCheckLog.PlanId }).FirstOrDefault();
            //    ServerConfig.ApiDb.Query<int>("SELECT COUNT(1) FROM `spot_check_plan` WHERE Id = @PlanId;", new { spotCheckLog.PlanId }).FirstOrDefault();
            //if (cnt == 0)
            //{
            //    return Result.GenError<Result>(Error.SpotCheckPlanNotExist);
            //}

            var data = ServerConfig.ApiDb.Query <SpotCheckDevice>("SELECT * FROM `spot_check_device` WHERE Id = @Id AND `MarkedDelete` = 0;",
                                                                  new { spotCheckLog.Id }).FirstOrDefault();

            if (data == null)
            {
                return(Result.GenError <Result>(Error.SpotCheckItemNotExist));
            }

            //if (data.Expired)
            //{
            //    return Result.GenError<Result>(Error.SpotCheckDeviceExpired);
            //}

            var createUserId   = Request.GetIdentityInformation();
            var markedDateTime = DateTime.Now;

            if (data.LogId != 0)
            {
                #region 更新
                spotCheckLog.LogId          = data.LogId;
                spotCheckLog.MarkedDateTime = markedDateTime;
                ServerConfig.ApiDb.Execute("UPDATE spot_check_log SET `MarkedDateTime` = @MarkedDateTime, `Images` = @Images WHERE `Id` = @LogId;",
                                           spotCheckLog);
                #endregion
            }
            else
            {
                #region 新增
                var sql = "SELECT c.*, a.*, b.Plan FROM `spot_check_device` a " +
                          "JOIN `spot_check_plan` b ON a.PlanId = b.Id " +
                          "JOIN `spot_check_item` c ON a.ItemId = c.Id " +
                          "WHERE a.MarkedDelete = 0 " +
                          "AND b.MarkedDelete = 0 " +
                          "AND c.MarkedDelete = 0 " +
                          "AND c.`Interval` != 0 " +
                          "AND a.LogId = 0 " +
                          "AND a.Id = @Id;";
                var detail = ServerConfig.ApiDb.Query <SpotCheckLog>(sql, new { spotCheckLog.Id }).FirstOrDefault();
                if (detail != null)
                {
                    detail.CreateUserId   = createUserId;
                    detail.MarkedDateTime = markedDateTime;
                    detail.Images         = spotCheckLog.Images;

                    var id = ServerConfig.ApiDb.Query <int>(
                        "INSERT INTO spot_check_log (`CreateUserId`, `MarkedDateTime`, `MarkedDelete`, `PlannedTime`, `DeviceId`, `ItemId`, `Item`, `PlanId`, `Plan`, `Enable`, `Remind`, `Min`, `Max`, `Unit`, `Reference`, `Remarks`, `Interval`, `Day`, `Month`, `NormalHour`, `Week`, `WeekHour`, `SurveyorId`, `Images`) " +
                        "VALUES (@CreateUserId, @MarkedDateTime, @MarkedDelete, @PlannedTime, @DeviceId, @ItemId, @Item, @PlanId, @Plan, @Enable, @Remind, @Min, @Max, @Unit, @Reference, @Remarks, @Interval, @Day, @Month, @NormalHour, @Week, @WeekHour, @SurveyorId, @Images);" +
                        "SELECT LAST_INSERT_ID();",
                        detail).FirstOrDefault();
                    spotCheckLog.MarkedDateTime = markedDateTime;
                    spotCheckLog.LogId          = id;
                    ServerConfig.ApiDb.Execute("UPDATE `spot_check_device` SET `MarkedDateTime`= @MarkedDateTime, `LogId` = @LogId WHERE `Id` = @Id;", spotCheckLog);
                }
                #endregion
            }

            return(Result.GenError <Result>(Error.Success));
        }