123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package logic
- import (
- MI "app.yhyue.com/moapp/jyInfo/rpc/manager/init"
- "app.yhyue.com/moapp/jyInfo/rpc/manager/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/manager/type/manager"
- "app.yhyue.com/moapp/jyInfo/rpc/model"
- es "app.yhyue.com/moapp/jyInfo/rpc/model/es"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- mc "app.yhyue.com/moapp/jybase/common"
- se "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- "time"
- )
- type InfoOneKeyActionLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewInfoOneKeyActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoOneKeyActionLogic {
- return &InfoOneKeyActionLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 管理后台一键操作 1:管理后台一键敏感词过滤;2:管理后台一键发布;3管理后台一键删除;
- func (l *InfoOneKeyActionLogic) InfoOneKeyAction(in *manager.OneKeyActionReq) (*manager.InfoResp, error) {
- var resp = &manager.InfoResp{}
- if in.UserId != "" && MI.MUserIdMap[in.UserId] {
- msgId := se.SE.DecodeString(in.MsgId)
- var tname = mc.If(in.MsgType == "3", "supply_info", "information").(string)
- data := model.Mysql.SelectBySql(fmt.Sprintf(`SELECT * FROM %s WHERE id = ? AND type = ?`, tname), msgId, in.MsgType)
- if len(*data) > 0 {
- query := map[string]interface{}{
- "id": msgId,
- "app_id": in.AppId,
- }
- res := (*data)[0]
- switch in.Type {
- case 1: //一键敏感词过滤
- appendInfo := make(map[string]interface{})
- if res["title"] != nil {
- appendInfo["title"] = mc.InterfaceToStr(res["title"])
- }
- if res["detail"] != nil {
- appendInfo["detail"] = mc.InterfaceToStr(res["detail"])
- }
- if res["attach"] != nil && mc.InterfaceToStr(res["attach"]) != "{}" {
- appendInfo["attach"] = mc.StringToMap(mc.InterfaceToStr(res["attach"]))
- }
- nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
- if err != nil || nsq.NsqPushInfo() != nil {
- resp.ErrCode = -1
- resp.ErrMsg = fmt.Sprintf("nsq 发布异常:%s", res["id"])
- }
- if !model.Mysql.Update(tname, query, map[string]interface{}{
- "status": 1, //待审核
- "published": 1, //未发布
- "is_del": 1, //未删除
- }) {
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "更新信息失败"
- }
- case 2: //一键信息发布
- switch in.MsgType {
- case "3": //供应信息生成索引
- upData := make(map[string]interface{})
- upData["publish_time"] = time.Now().Format("2006-01-02 15:04:05")
- upData["published"] = 2
- entName := in.EntName
- if res["ent_name"] != nil && mc.InterfaceToStr(res["ent_name"]) != "" {
- entName = mc.InterfaceToStr(res["ent_name"])
- }
- supInfo := make(map[string]interface{})
- supInfo["id"] = msgId
- supInfo["title"] = res["title"]
- supInfo["detail"] = res["detail"]
- supInfo["province"] = res["province"]
- supInfo["city"] = res["city"]
- supInfo["ent_id"] = res["ent_id"]
- validityTime := time.Now().Unix()
- if res["validity_time"] != nil && res["validity_time"] != "" {
- validity, _ := time.ParseInLocation("2006-01-02 15:04:05", mc.InterfaceToStr(res["validity_time"]), time.Local)
- validityTime = validity.Unix()
- }
- supInfo["validity_time"] = validityTime
- if ok := es.SaveSupplyInfo(entName, supInfo); ok {
- if !model.Mysql.Update(tname, query, map[string]interface{}{
- "published": 1,
- "is_del": 1,
- }) {
- resp.ErrCode = -1
- resp.ErrMsg = "更新信息失败-"
- }
- break
- }
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "信息发布调用失败"
- case "1", "2", "4", "5", "6": //招标信息,采购信息
- //nsq发布信息
- nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "2", mc.InterfaceToStr(in.MsgType), false, res)
- if err != nil || nsq.NsqPushInfo() != nil {
- resp.ErrCode = -1
- resp.ErrMsg = "调用nsq失败"
- }
- if !model.Mysql.Update(tname, query, map[string]interface{}{
- "status": 4,
- "review_time": time.Now().Format("2006-01-02 15:04:05"),
- }) {
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "更新信息失败"
- }
- }
- case 3: //一键删除
- query := map[string]interface{}{
- "id": msgId,
- "app_id": in.AppId,
- }
- if data := model.Mysql.FindOne(tname, query, "", ""); data != nil && len(*data) > 0 {
- update := map[string]interface{}{"is_del": -1}
- if !model.Mysql.Update(tname, query, update) {
- resp.ErrCode = -1
- resp.ErrMsg = resp.ErrMsg + "更新信息失败"
- }
- }
- switch in.MsgType {
- case "3": //删除供应信息索引
- if mc.IntAll(res["published"]) == 2 {
- if !es.DelSupplyInfo(mc.InterfaceToStr(msgId)) {
- resp.ErrCode = -1
- resp.ErrMsg = "es删除供应信息失败"
- }
- }
- case "1", "2", "4", "5", "6": //删除 招标信息,采购信息 索引
- if mc.IntAll(res["published"]) == 2 {
- //如果是已经正常发布的信息 同步调用nsq删除
- nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, msgId, "3", in.MsgType, false, res)
- if err != nil || nsq.NsqPushInfo() != nil {
- resp.ErrCode = -1
- resp.ErrMsg = "nsq回调删除,同步删除信息失败"
- }
- }
- }
- }
- }
- }
- return resp, nil
- }
|