1. 新增公司管理 同時新增該平台角色
This commit is contained in:
parent
7480fee9df
commit
2185e4c3dd
@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using SolarPower.Models;
|
using SolarPower.Models;
|
||||||
using SolarPower.Models.Company;
|
using SolarPower.Models.Company;
|
||||||
|
using SolarPower.Models.Role;
|
||||||
using SolarPower.Repository.Interface;
|
using SolarPower.Repository.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -14,12 +15,17 @@ namespace SolarPower.Controllers
|
|||||||
public class CompanyController : MyBaseController<CompanyController>
|
public class CompanyController : MyBaseController<CompanyController>
|
||||||
{
|
{
|
||||||
private readonly ICompanyRepository companyRepository;
|
private readonly ICompanyRepository companyRepository;
|
||||||
|
private readonly IRoleRepository roleRepository;
|
||||||
private string logoPath = "/upload/company_logo/";
|
private string logoPath = "/upload/company_logo/";
|
||||||
private string logoSaveAsPath = "";
|
private string logoSaveAsPath = "";
|
||||||
|
|
||||||
public CompanyController(ICompanyRepository companyRepository) : base()
|
public CompanyController(
|
||||||
|
ICompanyRepository companyRepository,
|
||||||
|
IRoleRepository roleRepository
|
||||||
|
) : base()
|
||||||
{
|
{
|
||||||
this.companyRepository = companyRepository;
|
this.companyRepository = companyRepository;
|
||||||
|
this.roleRepository = roleRepository;
|
||||||
|
|
||||||
var xxx = Directory.GetCurrentDirectory();
|
var xxx = Directory.GetCurrentDirectory();
|
||||||
|
|
||||||
@ -75,6 +81,11 @@ namespace SolarPower.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer))
|
||||||
|
{ //如果只是身分公司管理員 或 公司使用者,就只能看自己公司的資料
|
||||||
|
post.SelectedCompanyId = myUser.CompanyId;
|
||||||
|
}
|
||||||
|
|
||||||
companies = await companyRepository.GetAllByFilterAsync(post);
|
companies = await companyRepository.GetAllByFilterAsync(post);
|
||||||
|
|
||||||
foreach (var company in companies)
|
foreach (var company in companies)
|
||||||
@ -94,18 +105,18 @@ namespace SolarPower.Controllers
|
|||||||
|
|
||||||
company.RegisterRatio = registerNumber.ToString() + " / " + company.RegisterUpperLimit.ToString();
|
company.RegisterRatio = registerNumber.ToString() + " / " + company.RegisterUpperLimit.ToString();
|
||||||
|
|
||||||
//if(mySimpleCompany.Id == 1)
|
if (myUser.IsGod == 1 || IsPlatformLayer(myUser.Role.Layer))
|
||||||
//{
|
{ //只有超級使用者 及 平台 可以使用
|
||||||
company.Function = @"
|
company.Function = @"
|
||||||
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed company-auth-btn'>權限池</button>
|
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed company-auth-btn'>權限池</button>
|
||||||
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'>修改</button>
|
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'>修改</button>
|
||||||
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'>刪除</button>";
|
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'>刪除</button>";
|
||||||
//}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// company.Functoin = @"
|
company.Function = @"
|
||||||
// <button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'>修改</button>";
|
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'>修改</button>";
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
totalRecords = companies.Count();
|
totalRecords = companies.Count();
|
||||||
recFilter = companies.Count();
|
recFilter = companies.Count();
|
||||||
@ -133,9 +144,9 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得單一系統管理員
|
/// 取得單一公司資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ApiResult<Company>> GetOneCompany(int id)
|
public async Task<ApiResult<Company>> GetOneCompany(int id)
|
||||||
@ -154,6 +165,15 @@ namespace SolarPower.Controllers
|
|||||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
else if(company.Id != myUser.CompanyId)
|
||||||
|
{
|
||||||
|
if(myUser.IsGod != 0 && !IsPlatformLayer(myUser.Role.Layer))
|
||||||
|
{
|
||||||
|
apiResult.Code = "9993";
|
||||||
|
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Data = company;
|
apiResult.Data = company;
|
||||||
@ -208,8 +228,6 @@ namespace SolarPower.Controllers
|
|||||||
return apiResult;
|
return apiResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
company = new Company()
|
company = new Company()
|
||||||
{
|
{
|
||||||
Name = post.Name,
|
Name = post.Name,
|
||||||
@ -226,11 +244,15 @@ namespace SolarPower.Controllers
|
|||||||
"TaxIDNumber",
|
"TaxIDNumber",
|
||||||
"Phone",
|
"Phone",
|
||||||
"Address",
|
"Address",
|
||||||
"RegisterUpperLimit",
|
|
||||||
"CreatedBy",
|
"CreatedBy",
|
||||||
};
|
};
|
||||||
|
|
||||||
var id = await companyRepository.AddAsync(company, properties);
|
if (myUser.IsGod == 1 || IsPlatformLayer(myUser.Role.Layer))
|
||||||
|
{ //超級使用者 或 平台人員可以修改 公司的註冊上限人數
|
||||||
|
properties.Add("RegisterUpperLimit");
|
||||||
|
}
|
||||||
|
|
||||||
|
var id = await companyRepository.AddOneAsync(company, properties);
|
||||||
|
|
||||||
//處裡公司Logo圖片
|
//處裡公司Logo圖片
|
||||||
if (post.LogoFile != null)
|
if (post.LogoFile != null)
|
||||||
@ -260,6 +282,28 @@ namespace SolarPower.Controllers
|
|||||||
await companyRepository.UpdateCompany(updateCompany, properties);
|
await companyRepository.UpdateCompany(updateCompany, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 幫別間公司新增"公司管理員"之角色
|
||||||
|
Role role = new Role()
|
||||||
|
{
|
||||||
|
CompanyId = id,
|
||||||
|
Name = "公司管理員",
|
||||||
|
Layer = 2,
|
||||||
|
CreatedBy = myUser.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
List<string> roleProperties = new List<string>()
|
||||||
|
{
|
||||||
|
"CompanyId",
|
||||||
|
"Name",
|
||||||
|
"Layer",
|
||||||
|
"CreatedBy",
|
||||||
|
};
|
||||||
|
|
||||||
|
await roleRepository.AddAsync(role, roleProperties);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//TODO 自動新增公司DB及Table,公司DB編號規則 solar_com_(公司編號共四碼),ex:solar_com_0001。
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Msg = "儲存成功";
|
apiResult.Msg = "儲存成功";
|
||||||
#endregion
|
#endregion
|
||||||
@ -282,7 +326,6 @@ namespace SolarPower.Controllers
|
|||||||
Id = post.Id,
|
Id = post.Id,
|
||||||
Name = post.Name,
|
Name = post.Name,
|
||||||
TaxIDNumber = post.TaxIDNumber,
|
TaxIDNumber = post.TaxIDNumber,
|
||||||
//Status = post.Status,
|
|
||||||
Phone = post.Phone,
|
Phone = post.Phone,
|
||||||
Address = post.Address,
|
Address = post.Address,
|
||||||
RegisterUpperLimit = post.RegisterUpperLimit,
|
RegisterUpperLimit = post.RegisterUpperLimit,
|
||||||
@ -296,10 +339,14 @@ namespace SolarPower.Controllers
|
|||||||
"TaxIDNumber",
|
"TaxIDNumber",
|
||||||
"Phone",
|
"Phone",
|
||||||
"Address",
|
"Address",
|
||||||
"RegisterUpperLimit",
|
|
||||||
"UpdatedBy",
|
"UpdatedBy",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (myUser.IsGod == 1 || IsPlatformLayer(myUser.Role.Layer))
|
||||||
|
{ //超級使用者 或 平台人員可以修改 公司的註冊上限人數
|
||||||
|
properties.Add("RegisterUpperLimit");
|
||||||
|
}
|
||||||
|
|
||||||
await companyRepository.UpdateCompany(update, properties);
|
await companyRepository.UpdateCompany(update, properties);
|
||||||
|
|
||||||
//處裡公司Logo圖片
|
//處裡公司Logo圖片
|
||||||
|
|||||||
@ -20,6 +20,7 @@ using System.Text;
|
|||||||
using SolarPower.Models.OperatorLogModel;
|
using SolarPower.Models.OperatorLogModel;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SolarPower.Models.Company;
|
using SolarPower.Models.Company;
|
||||||
|
using SolarPower.Models.Role;
|
||||||
|
|
||||||
namespace SolarPower.Controllers
|
namespace SolarPower.Controllers
|
||||||
{
|
{
|
||||||
@ -34,7 +35,6 @@ namespace SolarPower.Controllers
|
|||||||
private IOperatorLogRepository operatorLogRepository => HttpContext?.RequestServices.GetService<IOperatorLogRepository>();
|
private IOperatorLogRepository operatorLogRepository => HttpContext?.RequestServices.GetService<IOperatorLogRepository>();
|
||||||
|
|
||||||
protected MyUser myUser = null;
|
protected MyUser myUser = null;
|
||||||
protected SimpleCompany mySimpleCompany = null;
|
|
||||||
public string controllerName;
|
public string controllerName;
|
||||||
public string actionName;
|
public string actionName;
|
||||||
|
|
||||||
@ -103,5 +103,20 @@ namespace SolarPower.Controllers
|
|||||||
operatorLogRepository.Add(operatorLog, properties);
|
operatorLogRepository.Add(operatorLog, properties);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判斷是否維平台的管理員或平台使用者
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleLayer"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsPlatformLayer(byte roleLayer)
|
||||||
|
{
|
||||||
|
if(roleLayer == (int)RoleLayerEnum.PlatformAdmin || roleLayer == (int)RoleLayerEnum.PlatformUser)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,9 +93,9 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得單一使用者
|
/// 取得單一公司角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ApiResult<Role>> GetOneRole(int id)
|
public async Task<ApiResult<Role>> GetOneRole(int id)
|
||||||
@ -157,8 +157,6 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 新增公司角色
|
#region 新增公司角色
|
||||||
EDFunction edFunction = new EDFunction();
|
|
||||||
|
|
||||||
role = new Role()
|
role = new Role()
|
||||||
{
|
{
|
||||||
CompanyId = post.SelectedCompanyId,
|
CompanyId = post.SelectedCompanyId,
|
||||||
@ -183,7 +181,7 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#region 修改使用者
|
#region 修改公司角色
|
||||||
UpdateRole update = new UpdateRole()
|
UpdateRole update = new UpdateRole()
|
||||||
{
|
{
|
||||||
Id = post.Id,
|
Id = post.Id,
|
||||||
@ -191,7 +189,6 @@ namespace SolarPower.Controllers
|
|||||||
UpdatedBy = myUser.Id,
|
UpdatedBy = myUser.Id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
List<string> properties = new List<string>()
|
List<string> properties = new List<string>()
|
||||||
{
|
{
|
||||||
"Id",
|
"Id",
|
||||||
|
|||||||
@ -17,6 +17,7 @@ namespace SolarPower.Models
|
|||||||
{
|
{
|
||||||
{ "0000", "OK" },
|
{ "0000", "OK" },
|
||||||
{ "0001", "傳入參數錯誤。" },
|
{ "0001", "傳入參數錯誤。" },
|
||||||
|
{ "9993", "無此權限操作"},
|
||||||
{ "9994", "查無該公司角色"},
|
{ "9994", "查無該公司角色"},
|
||||||
{ "9995", "該統一編號已被使用。" },
|
{ "9995", "該統一編號已被使用。" },
|
||||||
{ "9996", "查無該公司資訊。" },
|
{ "9996", "查無該公司資訊。" },
|
||||||
|
|||||||
@ -90,7 +90,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
if (filter.SelectedCompanyId > 0)
|
if (filter.SelectedCompanyId > 0)
|
||||||
{
|
{
|
||||||
sql += @" Where Id = @SelectedCompanyId";
|
sql += @" AND Id = @SelectedCompanyId";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -55,6 +55,39 @@ namespace SolarPower.Repository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增單一筆資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <param name="properties"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<int> AddOneAsync(T entity, List<string> properties)
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = GenerateInsertQuery(properties);
|
||||||
|
|
||||||
|
sql += "SELECT LAST_INSERT_ID();";
|
||||||
|
|
||||||
|
id = (await conn.QueryAsync<int>(sql, entity)).Single();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 透過Id,軟刪除單一筆資料
|
/// 透過Id,軟刪除單一筆資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -222,7 +255,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
|
|
||||||
insertQuery
|
insertQuery
|
||||||
.Remove(insertQuery.Length - 1, 1)
|
.Remove(insertQuery.Length - 1, 1)
|
||||||
.Append(")");
|
.Append(");");
|
||||||
|
|
||||||
return insertQuery.ToString();
|
return insertQuery.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,15 @@ namespace SolarPower.Repository.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> AddAsync(T entity, List<string> properties);
|
Task<int> AddAsync(T entity, List<string> properties);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增單一筆資料
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity"></param>
|
||||||
|
/// <param name="properties"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> AddOneAsync(T entity, List<string> properties);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 修改資料
|
/// 修改資料
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -98,12 +98,12 @@
|
|||||||
<form class="company-form" id="company-form">
|
<form class="company-form" id="company-form">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="form-label" for="company_name_modal">名稱</label>
|
<label class="form-label" for="company_name_modal"><span class="text-danger">*</span>名稱</label>
|
||||||
<input type="text" id="company_name_modal" name="company_name_modal" class="form-control">
|
<input type="text" id="company_name_modal" name="company_name_modal" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="form-label" for="company_taxIDNumber_modal">統編</label>
|
<label class="form-label" for="company_taxIDNumber_modal"><span class="text-danger">*</span>統編</label>
|
||||||
<input type="text" id="company_taxIDNumber_modal" name="company_taxIDNumber_modal" class="form-control">
|
<input type="text" id="company_taxIDNumber_modal" name="company_taxIDNumber_modal" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -430,8 +430,12 @@
|
|||||||
//#region 公司資料表單驗證
|
//#region 公司資料表單驗證
|
||||||
$("#company-form").validate({
|
$("#company-form").validate({
|
||||||
rules: {
|
rules: {
|
||||||
|
company_name_modal: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
company_taxIDNumber_modal: {
|
company_taxIDNumber_modal: {
|
||||||
required: true,
|
required: true,
|
||||||
|
maxlength: 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -443,14 +447,6 @@
|
|||||||
if ($("#company-form").valid()) {
|
if ($("#company-form").valid()) {
|
||||||
var url = "/Company/SaveCompany";
|
var url = "/Company/SaveCompany";
|
||||||
|
|
||||||
var send_data = {
|
|
||||||
Id: selected_id,
|
|
||||||
Name: $("#company_name_modal").val(),
|
|
||||||
TaxIDNumber: $("#company_taxIDNumber_modal").val(),
|
|
||||||
Phone: $("#company_phone_modal").val(),
|
|
||||||
Address: $("#company_address_modal").val(),
|
|
||||||
}
|
|
||||||
|
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
var logos = $('#company_logo_modal')[0].files;
|
var logos = $('#company_logo_modal')[0].files;
|
||||||
|
|
||||||
@ -459,6 +455,7 @@
|
|||||||
formData.append("TaxIDNumber", $("#company_taxIDNumber_modal").val());
|
formData.append("TaxIDNumber", $("#company_taxIDNumber_modal").val());
|
||||||
formData.append("Phone", $("#company_phone_modal").val());
|
formData.append("Phone", $("#company_phone_modal").val());
|
||||||
formData.append("Address", $("#company_address_modal").val());
|
formData.append("Address", $("#company_address_modal").val());
|
||||||
|
formData.append("RegisterUpperLimit", $("#company_registerUpperLimit_modal").val());
|
||||||
if (logos.length > 0) {
|
if (logos.length > 0) {
|
||||||
formData.append("LogoFile", logos[0])
|
formData.append("LogoFile", logos[0])
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user