作者 tangxvhui

。。

... ... @@ -201,3 +201,53 @@ func (c *CommonController) SelectorChanceType() {
msg = protocol.NewReturnResponse(data, nil)
return
}
//SelectCompanyUserList 下拉选择框 获取公司成员列表
func (c *CommonController) SelectCompanyUserList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
UserName string `json:"user_name"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
listData := servecommon.SelectCompanyUserList(param.PageIndex, param.PageSize, companyid, param.UserName)
rspData := map[string]interface{}{
"gridResult": listData,
}
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//SelectChanceList 下拉选择框 获取机会列表
func (c *CommonController) SelectChanceList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
ChanceCode string `json:"chance_code"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
// companyid := c.GetCompanyId()
// listData := servecommon.SelectCompanyUserList(param.PageIndex, param.PageSize, companyid, param.UserName)
// rspData := map[string]interface{}{
// "gridResult": listData,
// }
// msg = protocol.NewReturnResponse(rspData, nil)
return
}
... ...
... ... @@ -45,6 +45,12 @@ func (c RankController) EditRankType() {
msg = protocol.BadRequestParam("1")
return
}
param.Name = strings.TrimSpace(param.Name)
n := []rune(param.Name)
if len(n) > 5 || len(n) == 0 {
msg = protocol.BadRequestParam("10103")
return
}
companyid := c.GetCompanyId()
err := serverank.UpdateRankType(param.Id, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
... ... @@ -126,7 +132,17 @@ func (c RankController) RankSeasonAdd() {
}
param.Name = strings.TrimSpace(param.Name)
if len(param.Name) == 0 {
msg = protocol.BadRequestParam("1")
msg = protocol.BadRequestParam("10104")
return
}
param.BeginTime = strings.TrimSpace(param.BeginTime)
if len(param.BeginTime) == 0 {
msg = protocol.BadRequestParam("10105")
return
}
param.EndTime = strings.TrimSpace(param.EndTime)
if len(param.EndTime) == 0 {
msg = protocol.BadRequestParam("10106")
return
}
var (
... ... @@ -135,13 +151,13 @@ func (c RankController) RankSeasonAdd() {
)
t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
msg = protocol.BadRequestParam("10105")
return
}
beginTime = t1.Unix()
t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
msg = protocol.BadRequestParam("10106")
return
}
endTime = t2.Unix() + 86399 //60*60*24-1
... ... @@ -185,6 +201,16 @@ func (c RankController) RankSeasonEdit() {
msg = protocol.BadRequestParam("1")
return
}
param.BeginTime = strings.TrimSpace(param.BeginTime)
if len(param.BeginTime) == 0 {
msg = protocol.BadRequestParam("10105")
return
}
param.EndTime = strings.TrimSpace(param.EndTime)
if len(param.EndTime) == 0 {
msg = protocol.BadRequestParam("10106")
return
}
var (
beginTime int64
endTime int64
... ... @@ -192,14 +218,14 @@ func (c RankController) RankSeasonEdit() {
t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
if err != nil {
log.Error(err.Error())
msg = protocol.BadRequestParam("1")
msg = protocol.BadRequestParam("10105")
return
}
beginTime = t1.Unix()
t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
if err != nil {
log.Error(err.Error())
msg = protocol.BadRequestParam("1")
msg = protocol.BadRequestParam("10106")
return
}
... ... @@ -261,6 +287,12 @@ func (c RankController) RankRangeAdd() {
msg = protocol.BadRequestParam("1")
return
}
param.Name = strings.TrimSpace(param.Name)
n := []rune(param.Name)
if len(n) == 0 || len(n) > 5 {
msg = protocol.BadRequestParam("10107")
return
}
switch param.RangeType {
case 1:
//员工
... ... @@ -306,6 +338,14 @@ func (c RankController) RankRangeEdit() {
msg = protocol.BadRequestParam("1")
return
}
param.Name = strings.TrimSpace(param.Name)
n := []rune(param.Name)
if len(n) == 0 || len(n) > 5 {
msg = protocol.BadRequestParam("10107")
return
}
switch param.RangeType {
case 1:
//员工
... ... @@ -498,8 +538,8 @@ func (c RankController) RankTypeConfigSet() {
}()
type Parameter struct {
RankTypeId int64 `json:"rank_type_id"`
AutoCreate int `json:"auto_create"` //【0:不自动创建】【1:自动创建】
AutoCreateDay int64 `json:"auto_create_day"` //赛季时间, 单位:天
AutoCreate int8 `json:"auto_create"` //【0:不自动创建】【1:自动创建】
AutoCreateDay int `json:"auto_create_day"` //赛季时间, 单位:天
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
... ... @@ -525,13 +565,14 @@ func (c RankController) RankTypeConfigSet() {
msg = protocol.NewReturnResponse(nil, e)
return
}
v := models.RankTypeConfigSet{
AutoCreate: param.AutoCreate,
AutoCreateLength: param.AutoCreateDay,
if param.AutoCreate > 1 || param.AutoCreate < 0 {
e := protocol.NewErrWithMessage("1")
msg = protocol.NewReturnResponse(nil, e)
return
}
bt, _ := json.Marshal(v)
rankType.ConfigSet = string(bt)
err = models.UpdateRankById(rankType, []string{"ConfigSet"})
rankType.AutoCreate = param.AutoCreate
rankType.AutoPeriod = param.AutoCreateDay
err = models.UpdateRankById(rankType, []string{"AutoCreate", "AutoCreateDay"})
if err != nil {
log.Error("更新rank_type数据失败;%s", err)
e := protocol.NewErrWithMessage("1")
... ... @@ -576,8 +617,13 @@ func (c RankController) RankTypeConfigShow() {
msg = protocol.NewReturnResponse(nil, e)
return
}
v := &models.RankTypeConfigSet{}
json.Unmarshal([]byte(rankType.ConfigSet), v)
v := struct {
AutoCreate int8 `json:"auto_create"`
AutoCreateDay int `json:"auto_create_day"`
}{
AutoCreate: rankType.AutoCreate,
AutoCreateDay: rankType.AutoPeriod,
}
msg = protocol.NewReturnResponse(v, nil)
return
}
... ...
... ... @@ -15,7 +15,8 @@ type RankType struct {
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
Type int8 `orm:"column(type)"`
ConfigSet string `orm:"column(config_set)"`
AutoCreate int8 `orm:"column(auto_create)"` //是否自动创建赛季 【0:否】【1:是】
AutoPeriod int `orm:"column(auto_period)"`
}
func (t *RankType) TableName() string {
... ... @@ -38,11 +39,6 @@ const (
RANK_STATUS_NO int8 = 2 //禁用
)
type RankTypeConfigSet struct {
AutoCreate int `json:"auto_create"` //【0:不自动创建】【1:自动创建】
AutoCreateLength int64 `json:"auto_create_length"` //【创建的赛季间隔,单位:天】
}
// AddRank insert a new Rank into database and returns
// last inserted Id on success.
func AddRank(m *RankType) (id int64, err error) {
... ...
... ... @@ -271,6 +271,7 @@ type RspAuditList struct {
}
type ChanceFlowLog struct {
Id int64 `json:"id" orm:"column(id)"`
ChanceId string `json:"chance_id" orm:"column(chance_id)"`
CreateAt string `json:"create_at" orm:"column(create_at)"`
Content string `json:"content" orm:"column(content)"`
... ...
... ... @@ -77,3 +77,16 @@ type ChanceTypeBase struct {
ChanceTypeId int64 `orm:"column(chance_type_id)" json:"chance_type_id"`
Name string `orm:"column(name)" json:"name"`
}
type SelectCompanyUserListItem struct {
UserCompanyId int64 `json:"user_company_id"`
UserName string `json:"user_name"`
DepartmentId int64 `json:"department_id"`
DepartmentName string `json:"department_name"`
}
//下拉选择公司员工
type SelectCompanyUserList struct {
ResponsePageInfo
List []SelectCompanyUserListItem `json:"list"`
}
... ...
... ... @@ -109,6 +109,11 @@ var errmessge ErrorMap = map[string]string{
//榜单设置
"10101": "赛季周期设置与其他赛季重叠",
"10102": "参与人类型不一致",
"10103": "排行榜名称最多5个字符",
"10104": "赛季名称最多输入20个字符",
"10105": "赛季开始时间必填",
"10106": "赛季结束时间必填",
"10107": "参与范围名称最多输入5个字符",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -425,7 +425,7 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) {
flowLogs = make([]protocol.ChanceFlowLog, 0)
err error
)
const datasql string = `SELECT a.chance_id,a.content,a.create_at,c.nick_name,a.code
const datasql string = `SELECT a.id, a.chance_id,a.content,a.create_at,c.nick_name,a.code
FROM audit_flow_log AS a
LEFT JOIN user_company AS b ON a.approve_user_id=b.id
LEFT JOIN user AS c ON b.user_id = c.id
... ...
... ... @@ -182,3 +182,103 @@ func SeleteGetChanceTypeList(companyid int64) []protocol.ChanceTypeBase {
}
return data
}
func SelectCompanyUserList(pageIndex int, pageSize int, companyid int64, userName string) protocol.SelectCompanyUserList {
datasql := `SELECT a.id,d.nick_name,c.name AS department_name,c.id AS department_id
FROM user_company AS a
LEFT JOIN user_department AS b ON a.id = b.user_company_id
LEFT JOIN department AS c ON b.department_id = c.id
LEFT JOIN user AS d ON a.user_id = d.id
WHERE a.delete_at = 0 AND c.company_id = ? `
countsql := `SELECT count(*)
FROM user_company AS a
LEFT JOIN user_department AS b ON a.id = b.user_company_id
LEFT JOIN department AS c ON b.department_id = c.id
LEFT JOIN user AS d ON a.user_id = d.id
WHERE a.delete_at = 0 AND c.company_id =? `
cond := []interface{}{companyid}
where := ""
if len(userName) > 0 {
where += ` And d.nick_name like ? `
cond = append(cond, "%"+userName+"%")
}
datasql += where
countsql += where
pageStart := (pageIndex - 1) * pageSize
datasql += fmt.Sprintf(` limit %d,%d `, pageStart, pageSize)
var (
err error
cnt int
)
rspData := protocol.SelectCompanyUserList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0, CurrentPage: pageIndex,
},
List: make([]protocol.SelectCompanyUserListItem, 0),
}
err = utils.ExecuteQueryOne(&cnt, countsql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
if cnt == 0 {
return rspData
}
err = utils.ExecuteQueryAll(&rspData, datasql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
return rspData
}
func SelectChanceList(pageIndex int, pageSize int, companyid int64, chanceCode string) protocol.SelectCompanyUserList {
datasql := ` SELECT id ,department_id,chance_type_id,audit_template_id,user_id,create_at,code
FROM chance WHERE company_id =? `
countsql := `SELECT count(*)
FROM chance WHERE company_id =?
`
cond := []interface{}{companyid}
where := ""
if len(chanceCode) > 0 {
where += ` And code like ? `
cond = append(cond, "%"+chanceCode+"%")
}
datasql += where
countsql += where
pageStart := (pageIndex - 1) * pageSize
datasql += fmt.Sprintf(` ORDER BY create_at DESC limit %d,%d `, pageStart, pageSize)
type SqlData struct {
Id int64 `orm:"column(id)"`
DeparmentId int64 `orm:"column(DeparmentId)"`
ChanceType int64 `orm:"column(ChanceType)"`
AuditTemplate int64 `orm:"column(AuditTemplate)"`
UserId int64 `orm:"column(UserId)"`
CreateAt string `orm:"column(CreateAt)"`
Code string `orm:"column(Code)"`
}
var (
err error
cnt int
)
rspData := protocol.SelectCompanyUserList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0, CurrentPage: pageIndex,
},
List: make([]protocol.SelectCompanyUserListItem, 0),
}
err = utils.ExecuteQueryOne(&cnt, countsql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
if cnt == 0 {
return rspData
}
err = utils.ExecuteQueryAll(&rspData, datasql, cond...)
if err != nil {
log.Error("SQL EXECUTE ERR:%s", err)
return rspData
}
return rspData
}
... ...