using BLL; using System; using System.Linq; using System.Web.Http; namespace WebAPI.Controllers { /// /// /// public class UnitController : ApiController { #region 根据UnitId获取单位信息 /// /// 根据UnitId获取单位信息 /// /// /// public Model.ResponeData getUnitByUnitId(string unitId) { var responeData = new Model.ResponeData(); try { responeData.data = APIUnitService.getUnitByUnitId(unitId); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; ErrLogInfo.WriteLog("WX接口-获取单位信息", ex); } return responeData; } #endregion #region 获取所有单位 /// /// 获取所有单位 /// /// public Model.ResponeData getUnitLists() { var responeData = new Model.ResponeData(); try { responeData.data = APIUnitService.getUnitLists(); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; ErrLogInfo.WriteLog("WX接口-获取所有单位", ex); } return responeData; } #endregion #region 根据projectId、unitType获取单位信息(总包1;施工分包2;监理3;业主4;其他5) /// /// 根据projectId、unitType获取单位信息(总包1;施工分包2;监理3;业主4;其他5) /// /// 项目ID /// 类型(null 所有单位) /// public Model.ResponeData getUnitByProjectIdUnitType(string projectId, string unitType) { var responeData = new Model.ResponeData(); try { responeData.data = APIUnitService.getUnitByProjectIdUnitType(projectId, unitType); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; ErrLogInfo.WriteLog("WX接口-获取单位信息", ex); } return responeData; } /// /// 根据projectId、unitType获取单位信息(总包1;施工分包2;监理3;业主4;其他5) /// /// 项目ID /// 查询条件 /// 类型(null 所有单位) /// public Model.ResponeData getUnitByProjectIdUnitTypeQuery(string projectId, string strParam, string unitType) { var responeData = new Model.ResponeData(); try { responeData.data = APIUnitService.getUnitByProjectIdUnitTypeQuery(projectId, strParam,unitType); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; ErrLogInfo.WriteLog("WX接口-获取单位信息", ex); } return responeData; } #endregion #region 根据subUnitQualityId获取分包商资质信息 /// /// 根据subUnitQualityId获取分包商资质信息 /// /// /// public Model.ResponeData getSubUnitQualityBySubUnitQualityId(string subUnitQualityId) { var responeData = new Model.ResponeData(); try { responeData.data = APIUnitService.getSubUnitQualityBySubUnitQualityId(subUnitQualityId); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } #endregion #region 根据projectId获取施工分包商资质各状态数 /// /// 根据projectId获取施工分包商资质各状态数 /// /// /// public Model.ResponeData getSubUnitQualityCount(string projectId) { var responeData = new Model.ResponeData(); try { var getDataList = new Model.SGGLDB(Funs.ConnString).View_QualityAudit_SubUnitQuality.Where(x => x.ProjectId == projectId); //// 总数 int tatalCount = getDataList.Count(); //// 过期 int count1 = getDataList.Where(x => x.BL_EnableDate < DateTime.Now || x.C_EnableDate < DateTime.Now || x.QL_EnableDate < DateTime.Now || x.H_EnableDate < DateTime.Now || x.SL_EnableDate < DateTime.Now).Count(); ////即将过期 int count2 = getDataList.Where(x => (x.BL_EnableDate >= DateTime.Now && x.BL_EnableDate < DateTime.Now.AddMonths(1)) || (x.C_EnableDate >= DateTime.Now && x.C_EnableDate < DateTime.Now.AddMonths(1)) || (x.QL_EnableDate >= DateTime.Now && x.QL_EnableDate < DateTime.Now.AddMonths(1)) || (x.H_EnableDate >= DateTime.Now && x.H_EnableDate < DateTime.Now.AddMonths(1)) || (x.SL_EnableDate >= DateTime.Now && x.SL_EnableDate < DateTime.Now.AddMonths(1))).Count(); responeData.data = new { tatalCount, count1, count2 }; } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } #endregion #region 根据projectId获取施工分包商资质信息 /// /// 根据projectId获取施工分包商资质信息 /// /// 项目ID /// 数据类型0-已过期;1-即将过期 /// 页码 /// public Model.ResponeData getSubUnitQualityByProjectId(string projectId, string type, int pageIndex) { var responeData = new Model.ResponeData(); try { IQueryable q = from x in new Model.SGGLDB(Funs.ConnString).View_QualityAudit_SubUnitQuality where x.ProjectId == projectId select x; if (type == "0") { q = q.Where(x => x.BL_EnableDate < DateTime.Now || x.C_EnableDate < DateTime.Now || x.QL_EnableDate < DateTime.Now || x.H_EnableDate < DateTime.Now || x.SL_EnableDate < DateTime.Now); } else if (type == "1") { q = q.Where(x => (x.BL_EnableDate >= DateTime.Now && x.BL_EnableDate < DateTime.Now.AddMonths(1)) || (x.C_EnableDate >= DateTime.Now && x.C_EnableDate < DateTime.Now.AddMonths(1)) || (x.QL_EnableDate >= DateTime.Now && x.QL_EnableDate < DateTime.Now.AddMonths(1)) || (x.H_EnableDate >= DateTime.Now && x.H_EnableDate < DateTime.Now.AddMonths(1)) || (x.SL_EnableDate >= DateTime.Now && x.SL_EnableDate < DateTime.Now.AddMonths(1))); } int pageCount = q.Count(); if (pageCount == 0) { responeData.data = new { pageCount, q }; } else { var getDataList = from x in q.OrderBy(u => u.UnitCode).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize) select new { x.UnitId, x.UnitName, x.ProjectId, x.SubUnitQualityId, x.SubUnitQualityName, x.BusinessLicense, BL_EnableDate = string.Format("{0:yyyy-MM-dd}", x.BL_EnableDate), BL_ScanUrl = x.BL_ScanUrl.Replace("\\", "/"), x.Certificate, C_EnableDate = string.Format("{0:yyyy-MM-dd}", x.C_EnableDate), C_ScanUrl = x.C_ScanUrl.Replace("\\", "/"), x.QualityLicense, QL_EnableDate = string.Format("{0:yyyy-MM-dd}", x.QL_EnableDate), QL_ScanUrl = x.QL_ScanUrl.Replace("\\", "/"), x.HSELicense, H_EnableDate = string.Format("{0:yyyy-MM-dd}", x.H_EnableDate), H_ScanUrl = x.H_ScanUrl.Replace("\\", "/"), x.SecurityLicense, SL_EnableDate = string.Format("{0:yyyy-MM-dd}", x.SL_EnableDate), SL_ScanUrl = x.SL_ScanUrl.Replace("\\", "/") }; responeData.data = new { pageCount, getDataList }; } } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; ErrLogInfo.WriteLog("WX接口-获取施工分包商资质信息", ex); } return responeData; } #endregion [HttpPost] public Model.ResponeData AddUnit([FromBody] Model.UnitItem unit) { var responeData = new Model.ResponeData(); try { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { Model.Base_Unit newUnit = db.Base_Unit.FirstOrDefault(x => x.CollCropCode == unit.CollCropCode); if (newUnit == null) { newUnit = new Model.Base_Unit { UnitId = SQLHelper.GetNewID(typeof(Model.Base_Unit)) }; db.Base_Unit.InsertOnSubmit(newUnit); newUnit.UnitCode = unit.UnitCode;//代码 newUnit.UnitName = unit.UnitName;//名称 newUnit.Corporate = unit.Corporate;//法人代表 newUnit.Address = unit.Address;//地址 newUnit.Telephone = unit.Telephone;//电话 newUnit.ShortUnitName = unit.ShortUnitName;//单位简称 newUnit.Fax = unit.Fax;//传真 newUnit.EMail = unit.EMail;//邮箱 newUnit.IsBranch = unit.IsBranch;//是否分公司 newUnit.ProjectRange = unit.ProjectRange;//工程范围 newUnit.IsChina = unit.IsChina;//是否中国企业 newUnit.CollCropCode = unit.CollCropCode;//社会统一信用代码 newUnit.LinkName = unit.LinkName;//联系人姓名 if (!string.IsNullOrEmpty(unit.IdcardType)) { var basicData = db.RealName_BasicData.FirstOrDefault(x => x.DictTypeCode == "ZHENGJIAN_TYPE" && x.DictName == unit.IdcardType); if (basicData != null) { newUnit.IdcardType = basicData.DictCode;//联系人证件类型 (香港永久性身份证 军官证 其他 警官证 台湾居民身份证 身份证 护照) } } newUnit.IdcardNumber = unit.IdcardNumber;//联系人证件号 newUnit.LinkMobile = unit.LinkMobile;//联系人电话 newUnit.CollCropStatus = unit.CollCropStatus;//是否黑名单企业 db.SubmitChanges(); } if (!string.IsNullOrEmpty(unit.ProjectId)) { Model.Project_ProjectUnit projectUnit = Funs.DB.Project_ProjectUnit.FirstOrDefault(x => x.UnitId == newUnit.UnitId && x.ProjectId == unit.ProjectId); if (projectUnit == null) { projectUnit = new Model.Project_ProjectUnit(); projectUnit.ProjectUnitId = SQLHelper.GetNewID(typeof(Model.Base_Unit)); db.Project_ProjectUnit.InsertOnSubmit(projectUnit); projectUnit.ProjectId = unit.ProjectId; projectUnit.UnitId = newUnit.UnitId; projectUnit.InTime = DateTime.Now; if (!string.IsNullOrEmpty(unit.UnitTypeId)) { var unitTypeList = (from x in Funs.DB.Sys_Const where x.GroupId == ConstValue.Group_ProjectUnitType orderby x.SortIndex select x).ToList(); var unitType = unitTypeList.FirstOrDefault(x => x.ConstText == unit.UnitTypeId); if (unitType != null) { projectUnit.UnitType = unitType.ConstValue;// 单位类型(监理 施工分包 安装 其他 业主 检测单位 其他 总包) } } //projectUnit.UnitType = newUnit.UnitTypeId; db.SubmitChanges(); } } responeData.data = newUnit.UnitId; } } catch (Exception ex) { } return responeData; } } }