|
@@ -6,24 +6,32 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/gogf/gf/v2/container/gset"
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
IC "jyBXCore/rpc/init"
|
|
|
"jyBXCore/rpc/model/tidb"
|
|
|
"jyBXCore/rpc/type/bxcore"
|
|
|
- "log"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- TableEntnicheUser = "entniche_user" // 企业用户表
|
|
|
- TableParticipateUser = "participate_user" // 参标用户表
|
|
|
- PositionTypeEnt = 1 // 职位类型企业
|
|
|
- PositionTypePersonal = 0 // 职位类型个人
|
|
|
- ButtonValueParticipate = 0 // 参标按钮 显示值 0-参标
|
|
|
- ButtonValueParticipated = 1 // 按钮显示值 列表页面 1-已参标
|
|
|
- RoleEntManager = 1 // 企业管理员角色
|
|
|
- RoleDepartManager = 2 // 部门管理员角色
|
|
|
- BidTypeDirect = 1 // 直接投标
|
|
|
- BidTypeChanel = 2 // 渠道投标
|
|
|
+ TableEntnicheUser = "entniche_user" // 企业用户表
|
|
|
+ TableParticipateUser = "participate_user" // 参标用户表
|
|
|
+
|
|
|
+ PositionTypeEnt = 1 // 职位类型企业
|
|
|
+ PositionTypePersonal = 0 // 职位类型个人
|
|
|
+
|
|
|
+ ButtonValueParticipate = 0 // 参标按钮 显示值 0-参标
|
|
|
+ ButtonValueParticipated = 1 // 按钮显示值 列表页面 1-已参标
|
|
|
+
|
|
|
+ RoleEntManager = 1 // 企业管理员角色
|
|
|
+ RoleDepartManager = 2 // 部门管理员角色
|
|
|
+
|
|
|
+ BidTypeDirect = 1 // 直接投标
|
|
|
+ BidTypeChanel = 2 // 渠道投标
|
|
|
+
|
|
|
+ RecordTypeBidStatus = 1 // 存储类型 1:投标状态更新
|
|
|
+
|
|
|
)
|
|
|
|
|
|
type ParticipateBid struct {
|
|
@@ -276,24 +284,9 @@ func (p *ParticipateBid) CheckUpdateBidPower(projectId string) (b bool) {
|
|
|
|
|
|
// UpdateBidStatus 更新投标状态
|
|
|
func (p *ParticipateBid) UpdateBidStatus(in *bxcore.UpdateBidStatusReq, projectId string) (flag bool) {
|
|
|
- // 查询项目投标信息 区分企业和个人
|
|
|
- var exist bool
|
|
|
- var rs *[]map[string]interface{}
|
|
|
- switch p.PositionType {
|
|
|
- case PositionTypeEnt:
|
|
|
- rs = tidb.GetBidContentEnt(projectId, p.EntId)
|
|
|
- case PositionTypePersonal:
|
|
|
- rs = tidb.GetBidContentPersonal(projectId, p.PositionId)
|
|
|
-
|
|
|
- }
|
|
|
- oldMap := map[string]interface{}{}
|
|
|
- id := 0
|
|
|
- if rs != nil && len(*rs) > 0 {
|
|
|
- exist = true
|
|
|
- oldMap = *common.ObjToMap((*rs)[0]["records_data"])
|
|
|
- id = common.IntAll((*rs)[0]["id"])
|
|
|
- }
|
|
|
- // 处理操作记录
|
|
|
+ // 如果查出来旧的 那么就需要做新旧对比
|
|
|
+ oldMap := p.GetLastBidStatus(projectId) // 查询出最新的招标状态信息
|
|
|
+ // 新的
|
|
|
newMap := map[string]interface{}{
|
|
|
"bidType": in.BidType,
|
|
|
"bidStage": in.BidStage,
|
|
@@ -303,56 +296,55 @@ func (p *ParticipateBid) UpdateBidStatus(in *bxcore.UpdateBidStatusReq, projectI
|
|
|
"channelPhone": in.ChannelPhone,
|
|
|
"winner": in.Winner,
|
|
|
}
|
|
|
- recordsData_, _ := json.Marshal(newMap)
|
|
|
- recordsData := string(recordsData_)
|
|
|
- // todo
|
|
|
- recordContent := processRecordStr(oldMap, newMap)
|
|
|
+ // 新旧对比 处理成要保存的字段
|
|
|
+ recordContent, err := processRecordStr(oldMap, newMap)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 保存
|
|
|
recordData := map[string]interface{}{
|
|
|
"ent_id": p.EntId,
|
|
|
"ent_user_id": p.EntUserId,
|
|
|
"position_id": p.PositionId,
|
|
|
"project_id": projectId,
|
|
|
"record_content": recordContent,
|
|
|
+ "record_type": RecordTypeBidStatus,
|
|
|
"create_date": date.NowFormat(date.Date_Full_Layout),
|
|
|
}
|
|
|
- if exist {
|
|
|
- // 已经存在 则进行更新
|
|
|
- if id == 0 {
|
|
|
- log.Println("id有误")
|
|
|
- return false
|
|
|
- }
|
|
|
- query := map[string]interface{}{
|
|
|
- "id": id,
|
|
|
- }
|
|
|
- updateData := map[string]interface{}{
|
|
|
- "records_data": recordsData,
|
|
|
- "update_date": date.NowFormat(date.Date_Full_Layout),
|
|
|
- }
|
|
|
- flag = tidb.UpdateBidContent(query, updateData, recordData)
|
|
|
- } else {
|
|
|
- // 否则进行新增操作
|
|
|
- insertData := map[string]interface{}{
|
|
|
- "ent_id": p.EntId,
|
|
|
- "ent_user_id": p.EntUserId,
|
|
|
- "position_id": p.PositionId,
|
|
|
- "project_id": projectId,
|
|
|
- "records_data": recordsData,
|
|
|
- "create_date": date.NowFormat(date.Date_Full_Layout),
|
|
|
- }
|
|
|
-
|
|
|
- flag = tidb.InsertBidContent(insertData, recordData)
|
|
|
- }
|
|
|
+ flag = tidb.InsertBidContent(recordData)
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
-// 获取投标状态信息
|
|
|
+// GetLastBidStatus 获取投标状态信息
|
|
|
+func (p *ParticipateBid) GetLastBidStatus(projectId string) map[string]interface{} {
|
|
|
+ rs := map[string]interface{}{}
|
|
|
+ // 查询项目投标信息 区分企业和个人
|
|
|
+ var result *[]map[string]interface{}
|
|
|
+ switch p.PositionType {
|
|
|
+ case PositionTypeEnt:
|
|
|
+ result = tidb.GetBidContentEnt(projectId, p.EntId)
|
|
|
+ case PositionTypePersonal:
|
|
|
+ result = tidb.GetBidContentPersonal(projectId, p.PositionId)
|
|
|
+ }
|
|
|
+ if rs != nil && len(*result) > 0 {
|
|
|
+ content := common.ObjToMap((*result)[0]["record_content"])
|
|
|
+ if content != nil {
|
|
|
+ bidStatus := common.ObjToMap((*content)["after"])
|
|
|
+ if bidStatus != nil {
|
|
|
+ rs = *bidStatus
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rs
|
|
|
|
|
|
-// 获取操作记录
|
|
|
-func (p ParticipateBid) GetXXX() {
|
|
|
+}
|
|
|
|
|
|
- // 1. 查询出操作记录
|
|
|
+// GetBidRecords 获取操作记录
|
|
|
+func (p *ParticipateBid) GetBidRecords(page, pageSize int) {
|
|
|
|
|
|
+ // 1. 查询出操作记录
|
|
|
+ //tidb.GetBidRecordsEnt()
|
|
|
// 2. todo 补充上操作人姓名
|
|
|
}
|
|
|
|
|
@@ -367,45 +359,93 @@ var (
|
|
|
"channelPhone": "联系电话",
|
|
|
"winner": "中标单位",
|
|
|
}
|
|
|
+ BidTypeMap = map[int]interface{}{
|
|
|
+ BidTypeDirect: "直接投标",
|
|
|
+ BidTypeChanel: "渠道投标",
|
|
|
+ }
|
|
|
+ WinMap = map[int]interface{}{
|
|
|
+ 1: "是",
|
|
|
+ 2: "否",
|
|
|
+ 0: "未选择",
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
-func processRecordStr(old, new map[string]interface{}) (recordContent string) {
|
|
|
- // actonStr := "%s%s%s"
|
|
|
- // var rs []string
|
|
|
- // for k, v := range ParticipateBidContentKey {
|
|
|
- // changeStr := ""
|
|
|
- // if k == "bidType" || k == "isWin" {
|
|
|
- // oldv := common.IntAll(old[k])
|
|
|
- // newv := common.IntAll(new[k])
|
|
|
- // if oldv == newv {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // if oldv == 0 && newv != 0 { // 说明是新增
|
|
|
- //
|
|
|
- // } else { // 调整
|
|
|
- //
|
|
|
- // }
|
|
|
- // rs = append(rs, changeStr)
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // if k == "bidStage" {
|
|
|
- // // todo 计算差集
|
|
|
- //
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // oldv := common.ObjToString(old[k])
|
|
|
- // newv := common.ObjToString(new[k])
|
|
|
- // if oldv == newv {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // //actionType := "(调整):"
|
|
|
- // if oldv == "" && newv != "" { // 说明是新增
|
|
|
- // actionType = ""
|
|
|
- // }
|
|
|
- // changeStr = fmt.Sprintf(actonStr, v, newv)
|
|
|
- //
|
|
|
- // rs = append(rs, changeStr)
|
|
|
- // }
|
|
|
- //
|
|
|
- return
|
|
|
+func processRecordStr(oldMap, newMap map[string]interface{}) (recordContent string, err error) {
|
|
|
+ actonStr := "%s%s%s"
|
|
|
+ changeField := []string{}
|
|
|
+ result := []string{}
|
|
|
+ for k, fieldName := range ParticipateBidContentKey {
|
|
|
+ changeStr := ""
|
|
|
+ switch k {
|
|
|
+ case "bidType":
|
|
|
+ oldv := common.IntAll(oldMap[k])
|
|
|
+ newv := common.IntAll(newMap[k])
|
|
|
+ if oldv == newv { // 没有改变
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if oldv == 0 && newv != 0 { // 说明是新增
|
|
|
+ changeStr = fmt.Sprintf(actonStr, fieldName, ": (新增)", BidTypeMap[newv])
|
|
|
+ } else { // 调整
|
|
|
+ changeStr = fmt.Sprintf(actonStr, fieldName, "(调整):", BidTypeMap[newv])
|
|
|
+
|
|
|
+ }
|
|
|
+ case "isWin":
|
|
|
+ oldV := common.IntAll(oldMap[k])
|
|
|
+ newV := common.IntAll(newMap[k])
|
|
|
+ if oldV == newV { // 没有改变
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ fieldName := fieldName
|
|
|
+ if common.IntAll(newMap["bidType"]) == BidTypeChanel {
|
|
|
+ fieldName = fmt.Sprintf("%s%s", "渠道", fieldName)
|
|
|
+ }
|
|
|
+ changeStr = fmt.Sprintf(actonStr, fieldName, "(调整) 为", WinMap[newV])
|
|
|
+ case "bidStage":
|
|
|
+ bidAction := "%s%s"
|
|
|
+ bidChangeArr := []string{}
|
|
|
+ oldSet := gset.NewFrom(oldMap[k])
|
|
|
+ newSet := gset.NewFrom(newMap[k])
|
|
|
+ // 判断相等
|
|
|
+ if oldSet.Equal(newSet) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 差集计算
|
|
|
+ // 取消勾选的
|
|
|
+ cancleSet := oldSet.Diff(newSet)
|
|
|
+ cancleSet.Iterator(func(v interface{}) bool {
|
|
|
+ bidChangeArr = append(bidChangeArr, fmt.Sprintf(bidAction, "(取消勾选)", v))
|
|
|
+ return true
|
|
|
+ })
|
|
|
+ // 新增的
|
|
|
+ addSet := newSet.Diff(oldSet)
|
|
|
+ addSet.Iterator(func(v interface{}) bool {
|
|
|
+ bidChangeArr = append(bidChangeArr, fmt.Sprintf(bidAction, "(新增)", v))
|
|
|
+ fmt.Println(v)
|
|
|
+ return true
|
|
|
+ })
|
|
|
+ tmpStr := strings.Join(bidChangeArr, " ")
|
|
|
+ changeStr = fmt.Sprintf(actonStr, fieldName, " :", tmpStr)
|
|
|
+ default:
|
|
|
+ oldV := common.ObjToString(oldMap[k])
|
|
|
+ newV := common.ObjToString(newMap[k])
|
|
|
+ if oldV == newV { // 没有变化
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ changeStr = fmt.Sprintf(actonStr, fieldName, "(调整)为", fmt.Sprintf("\"%s\"", newV))
|
|
|
+ }
|
|
|
+ result = append(result, changeStr)
|
|
|
+ changeField = append(changeField, k)
|
|
|
+ }
|
|
|
+ recordMap := map[string]interface{}{
|
|
|
+ "content": strings.Join(result, ";"), // 变更内容 文字描述
|
|
|
+ "before": oldMap, // 变更前
|
|
|
+ "after": newMap, // 变更后
|
|
|
+ "changeField": changeField, // 涉及变更的字段
|
|
|
+ }
|
|
|
+ tmp, err := json.Marshal(recordMap)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error("序列化操作记录失败:", err)
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ return string(tmp), nil
|
|
|
}
|