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