作者 唐旭辉

修复 “职位无法删除” 的bug

... ... @@ -44,6 +44,7 @@ type PositionBase struct {
type DepartUserBase struct {
UserCompanyId int64 `json:"id" orm:"column(user_company_id)"`
NickName string `json:"name" orm:"column(nick_name)"`
UserId int64 `json:"-" orm:"column(user_id)"`
}
//部门和人员混合
... ...
... ... @@ -380,8 +380,9 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
log.Error("deparment.CompanyId err")
return returnData, protocol.NewErrWithMessage("1")
}
const dataSql string = `SELECT b.nick_name,a.user_company_id FROM user_department AS a
JOIN user_company AS b ON a.user_company_id = b.id
const dataSql string = `SELECT a.user_company_id,b.user_id
FROM user_department AS a
LEFT JOIN user_company AS b ON a.user_company_id = b.id
WHERE a.department_id=? AND b.delete_at=0 AND a.enable_status = 1 `
err = utils.ExecuteQueryAll(&returnData, dataSql, department.Id)
... ... @@ -389,5 +390,13 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
log.Error("EXECUTE SQL err:%s", err)
return returnData, protocol.NewErrWithMessage("1")
}
for i := range returnData {
uInfo, err := models.GetUserById(returnData[i].UserId)
if err == nil {
returnData[i].NickName = uInfo.NickName
} else {
log.Error("GetUserById(%d) err:%s", returnData[i].UserId, err)
}
}
return returnData, nil
}
... ...
... ... @@ -272,7 +272,7 @@ func PositionDelete(param protocol.RequestPositionDelete) error {
log.Error(e.Error())
return protocol.NewErrWithMessage("10011", e)
}
if _, ok := toDelete[subset.Id]; ok {
if _, ok := toDelete[subset.Id]; ok && subset.Id != pos.Id {
delete(toDelete, subset.Id)
}
}
... ...
... ... @@ -503,7 +503,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) {
datasql := `SELECT a.id as user_company_id,a.enable, b.phone,a.nick_name
datasql := `SELECT a.id as user_company_id,a.enable, b.phone,b.nick_name
FROM user_company AS a
LEFT JOIN user AS b ON a.user_id = b.id
WHERE a.company_id=? AND a.delete_at = 0 `
... ... @@ -517,7 +517,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
)
cond = append(cond, param.Companyid)
if len(param.NickName) > 0 {
whereString += ` AND a.nick_name LIKE ? `
whereString += ` AND b.nick_name LIKE ? `
likeCond := "%" + param.NickName + "%"
cond = append(cond, likeCond)
}
... ...