初始
This commit is contained in:
266
internal/app/system/logic/busSalaryDetails/bus_salary_details.go
Normal file
266
internal/app/system/logic/busSalaryDetails/bus_salary_details.go
Normal file
@ -0,0 +1,266 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-02-01 16:39:01
|
||||
// 生成路径: internal/app/system/logic/bus_salary_details.go
|
||||
// 生成人:gfast
|
||||
// desc:员工工资考核记录
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterBusSalaryDetails(New())
|
||||
}
|
||||
|
||||
func New() *sBusSalaryDetails {
|
||||
return &sBusSalaryDetails{}
|
||||
}
|
||||
|
||||
type sBusSalaryDetails struct{}
|
||||
|
||||
func (s *sBusSalaryDetails) SalarySheetFunc(ctx context.Context, req *system.SalarySheetFuncReq) (res *system.SalarySheetFuncRes, err error) {
|
||||
res = new(system.SalarySheetFuncRes)
|
||||
var ssr []model.SalarySheetRes
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、获取数据
|
||||
var bsdlr []*model.BusSalaryDetailsInfoRes
|
||||
sql := dao.BusSalaryDetails.Ctx(ctx).Where("a.date_of_issue", req.DateOfIssue).As("a").
|
||||
LeftJoin("sys_project", "b", "b.id = a.project_id").
|
||||
LeftJoin("sys_project_team", "c", "c.id = a.team_id")
|
||||
if req.Project > 0 {
|
||||
sql = sql.Where("a."+dao.BusSalaryDetails.Columns().ProjectId, req.Project)
|
||||
}
|
||||
if req.Team > 0 {
|
||||
sql = sql.Where("a."+dao.BusSalaryDetails.Columns().TeamId, req.Team)
|
||||
}
|
||||
if req.SfzNumber != "" {
|
||||
sql = sql.Where("a."+dao.BusSalaryDetails.Columns().SfzNumber, req.SfzNumber)
|
||||
}
|
||||
err := sql.Fields("a.name,a.account,a.banking_house,a.sum_duration,a.salary,b.project_name as projectName,c.name as teamName").Scan(&bsdlr)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
//2、组装需要导出为excel的数据
|
||||
for i := range bsdlr {
|
||||
// 创建 Decimal 类型的金钱值
|
||||
one := decimal.NewFromFloat(bsdlr[i].SumDuration)
|
||||
two := decimal.NewFromFloat(bsdlr[i].Salary)
|
||||
product := one.Mul(two)
|
||||
sheetRes := model.SalarySheetRes{
|
||||
YhkNumber: bsdlr[i].Account,
|
||||
UserName: bsdlr[i].Name,
|
||||
Money: product.String(),
|
||||
BankingHouse: bsdlr[i].BankingHouse,
|
||||
ProjectName: bsdlr[i].ProjectName,
|
||||
TeamName: bsdlr[i].TeamName,
|
||||
}
|
||||
ssr = append(ssr, sheetRes)
|
||||
}
|
||||
return
|
||||
})
|
||||
res.List = ssr
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) GetByIdDetailFunc(ctx context.Context, req *system.GetByIdDetailFuncReq) (listRes *system.GetByIdDetailFuncRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
listRes = new(system.GetByIdDetailFuncRes)
|
||||
sql := g.DB().Model("bus_salary_details_record").Ctx(ctx).Where("sfz_number", req.SfzNumber)
|
||||
if req.DateOfIssue != "" {
|
||||
sql = sql.Where("date_of_issue", req.DateOfIssue)
|
||||
}
|
||||
listRes.Total, err = sql.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "date_of_issue desc,id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.DateTwoRes
|
||||
err = sql.Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = res
|
||||
return
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) List(ctx context.Context, req *system.BusSalaryDetailsSearchReq) (listRes *system.BusSalaryDetailsSearchRes, err error) {
|
||||
listRes = new(system.BusSalaryDetailsSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.BusSalaryDetails.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.BusSalaryDetails.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.SfzNumber != "" {
|
||||
m = m.Where(dao.BusSalaryDetails.Columns().SfzNumber+" like ?", "%"+req.SfzNumber+"%")
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where(dao.BusSalaryDetails.Columns().ProjectId+" = ?", req.ProjectId)
|
||||
}
|
||||
if req.TeamId != "" {
|
||||
m = m.Where(dao.BusSalaryDetails.Columns().TeamId+" = ?", req.TeamId)
|
||||
}
|
||||
if req.DateOfIssue != "" {
|
||||
m = m.Where("date_of_issue = ?", req.DateOfIssue)
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "date_of_issue desc,id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.BusSalaryDetailsInfoRes
|
||||
err = m.Fields(system.BusSalaryDetailsSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.BusSalaryDetailsListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.BusSalaryDetailsListRes{
|
||||
Id: v.Id,
|
||||
SfzNumber: v.SfzNumber,
|
||||
Name: v.Name,
|
||||
Account: v.Account,
|
||||
SumDuration: v.SumDuration,
|
||||
Salary: v.Salary,
|
||||
DateOfIssue: v.DateOfIssue,
|
||||
Lister: v.Lister,
|
||||
CreatedAt: v.CreatedAt,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) GetById(ctx context.Context, id int64) (res *model.BusSalaryDetailsInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.BusSalaryDetails.Ctx(ctx).WithAll().Where(dao.BusSalaryDetails.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) Add(ctx context.Context, req *system.BusSalaryDetailsAddReq) (err error) {
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
//1、获取他们的身份证信息,然后去数据库里面查询到对应的项目+班组+银行卡+薪水+
|
||||
var sfz []string
|
||||
for _, data := range req.DataList {
|
||||
sfz = append(sfz, data.SfzNumber)
|
||||
}
|
||||
var realInformationTwo []*model.AttendanceImportTwoRes
|
||||
err = dao.BusConstructionUser.Ctx(ctx).As("a").
|
||||
Fields(`
|
||||
a.id,
|
||||
a.user_name,
|
||||
a.sfz_number,
|
||||
a.yhk_number,
|
||||
a.project_id,
|
||||
a.team_id,
|
||||
a.yhk_opening_bank,
|
||||
CASE
|
||||
WHEN a.salary > 0 THEN a.salary
|
||||
ELSE b.standard
|
||||
END AS final_salary`).
|
||||
LeftJoin("bus_type_of_wage", "b", "a.type_of_work = b.type_of_work ").
|
||||
WhereIn("a.sfz_number", sfz).Where("a.sfz_number <> ''").Scan(&realInformationTwo)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
//2、数据匹配
|
||||
var sfzs []string
|
||||
var years string
|
||||
var i = 0
|
||||
var bsd []do.BusSalaryDetails //最终插入到bus_salary_details的数据
|
||||
var dtr []model.DateTwoRes //最终插入到bus_salary_details的数据
|
||||
for _, dl := range req.DataList {
|
||||
for _, ri := range realInformationTwo {
|
||||
//身份证不匹配
|
||||
if dl.SfzNumber != ri.SfzNumber {
|
||||
continue
|
||||
}
|
||||
if i == 0 {
|
||||
years = dl.DateOfIssue
|
||||
}
|
||||
//主表数据
|
||||
details := do.BusSalaryDetails{
|
||||
SfzNumber: ri.SfzNumber,
|
||||
Name: dl.Name,
|
||||
Account: ri.YhkNumber,
|
||||
BankingHouse: ri.YhkOpeningBank,
|
||||
SumDuration: dl.SumDuration,
|
||||
Salary: ri.FinalSalary,
|
||||
ProjectId: ri.ProjectId,
|
||||
TeamId: ri.TeamId,
|
||||
DateOfIssue: dl.DateOfIssue,
|
||||
Lister: dl.Lister,
|
||||
}
|
||||
bsd = append(bsd, details)
|
||||
//副表数据
|
||||
for i := range dl.Dates {
|
||||
res := model.DateTwoRes{
|
||||
SfzNumber: ri.SfzNumber,
|
||||
WorkingDate: dl.Dates[i].WorkingDate,
|
||||
Duration: dl.Dates[i].Duration,
|
||||
DateOfIssue: dl.DateOfIssue,
|
||||
}
|
||||
dtr = append(dtr, res)
|
||||
}
|
||||
sfzs = append(sfzs, ri.SfzNumber)
|
||||
}
|
||||
}
|
||||
|
||||
//先删除重复数据
|
||||
_, err = dao.BusSalaryDetails.Ctx(ctx).Where("date_of_issue", years).WhereIn("sfz_number", sfz).Delete()
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
_, err := g.DB().Model("bus_salary_details_record").Ctx(ctx).Where("date_of_issue", years).WhereIn("sfz_number", sfz).Delete()
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
//插入数据
|
||||
_, err = dao.BusSalaryDetails.Ctx(ctx).Data(bsd).Batch(100).Insert()
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
_, err = g.DB().Model("bus_salary_details_record").Ctx(ctx).Data(dtr).Batch(100).Insert()
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) Edit(ctx context.Context, req *system.BusSalaryDetailsEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusSalaryDetails.Ctx(ctx).WherePri(req.Id).Update(do.BusSalaryDetails{})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sBusSalaryDetails) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.BusSalaryDetails.Ctx(ctx).Delete(dao.BusSalaryDetails.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user