123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package cross_variety
- import (
- "encoding/json"
- "eta_gn/eta_api/controllers"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage/cross_variety"
- "eta_gn/eta_api/models/data_manage/cross_variety/request"
- "eta_gn/eta_api/models/data_manage/cross_variety/response"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // VarietyController
- // @Description: 品种列表
- type VarietyController struct {
- controllers.BaseAuthController
- }
- // Add
- // @Title 新增品种
- // @Description 新增品种接口
- // @Param request body request.AddVarietyReq true "type json string"
- // @Success 200 Ret=200 添加成功
- // @router /variety/add [post]
- func (c *VarietyController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.AddVarietyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.VarietyName == "" {
- br.Msg = "请输入品种名称"
- br.IsSendEmail = false
- return
- }
- varietyName := utils.TrimStr(req.VarietyName)
- item, err := cross_variety.GetVarietyByName(varietyName)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "添加失败"
- br.ErrMsg = "添加失败,Err:" + err.Error()
- return
- }
- if item != nil && item.ChartVarietyId > 0 {
- br.Msg = "添加失败,品种名称不能重复"
- br.IsSendEmail = false
- return
- }
- variety := &cross_variety.ChartVariety{
- ChartVarietyId: 0,
- ChartVarietyName: varietyName,
- ChartVarietyNameEn: varietyName,
- SysUserId: c.SysUser.AdminId,
- SysUserRealName: c.SysUser.RealName,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = cross_variety.AddVariety(variety)
- if err != nil {
- br.Msg = "添加品种失败"
- br.ErrMsg = "添加品种失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "添加成功"
- br.IsAddLog = true
- br.Success = true
- }
- // Edit
- // @Title 编辑品种接口
- // @Description 编辑品种接口
- // @Param request body request.EditVarietyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /variety/edit [post]
- func (c *VarietyController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.EditVarietyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartVarietyId <= 0 {
- br.Msg = "请选择品种"
- br.IsSendEmail = false
- return
- }
- if req.VarietyName == "" {
- br.Msg = "请输入品种名称"
- br.IsSendEmail = false
- return
- }
- varietyName := utils.TrimStr(req.VarietyName)
- item, err := cross_variety.GetVarietyByName(varietyName)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "添加失败"
- br.ErrMsg = "添加失败,Err:" + err.Error()
- return
- }
- if item != nil && item.ChartVarietyId > 0 && item.ChartVarietyId != req.ChartVarietyId {
- br.Msg = "添加失败,品种名称不能重复"
- br.IsSendEmail = false
- return
- }
- // 获取品种详情
- varietyInfo, err := cross_variety.GetVarietyById(req.ChartVarietyId)
- if err != nil {
- br.Msg = "查询品种失败"
- br.ErrMsg = "查询品种失败;ERR:" + err.Error()
- return
- }
- // 编辑
- switch c.Lang {
- case utils.EnLangVersion:
- varietyInfo.ChartVarietyNameEn = varietyName
- default:
- varietyInfo.ChartVarietyName = varietyName
- }
- varietyInfo.ModifyTime = time.Now()
- err = varietyInfo.Update([]string{"ChartVarietyName", "ChartVarietyNameEn", "ModifyTime"})
- if err != nil {
- br.Msg = "修改品种失败"
- br.ErrMsg = "修改品种失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "修改成功"
- br.IsAddLog = true
- br.Success = true
- }
- // DeleteCheck
- // @Title 删除品种检测接口
- // @Description 删除品种检测接口
- // @Param request body request.DelVarietyReq true "type json string"
- // @Success 200 Ret=200 检测成功
- // @router /variety/delete/check [post]
- func (c *VarietyController) DeleteCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.DelVarietyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartVarietyId <= 0 {
- br.Msg = "请选择品种"
- br.IsSendEmail = false
- return
- }
- var deleteStatus int
- var tipsMsg string
- // 获取该品种关联的图表数
- count, err := cross_variety.GetCountChartByVarietyId(req.ChartVarietyId)
- if err != nil {
- br.Msg = "检测异常"
- br.ErrMsg = "检测异常,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- if count > 0 {
- deleteStatus = 1
- tipsMsg = "已关联图表的品种,不允许删除!"
- }
- if deleteStatus == 0 {
- tipsMsg = "可删除,进行删除操作"
- }
- resp := response.VarietyDeleteCheckResp{
- DeleteStatus: deleteStatus,
- TipsMsg: tipsMsg,
- }
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- // Delete
- // @Title 删除品种
- // @Description 删除品种接口
- // @Param request body request.DeleteChartClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /variety/delete [post]
- func (c *VarietyController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.DelVarietyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartVarietyId <= 0 {
- br.Msg = "请选择品种"
- br.IsSendEmail = false
- return
- }
- // 获取该品种关联的图表数
- count, err := cross_variety.GetCountChartByVarietyId(req.ChartVarietyId)
- if err != nil {
- br.Msg = "检测异常"
- br.ErrMsg = "检测异常,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- if count > 0 {
- br.Msg = "已关联图表的品种,不允许删除!"
- br.ErrMsg = "已关联图表的品种,不允许删除!"
- br.IsSendEmail = false
- return
- }
- varietyInfo, err := cross_variety.GetVarietyById(req.ChartVarietyId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "该品种不存在或已删除"
- br.IsSendEmail = false
- } else {
- br.Msg = "删除失败"
- br.ErrMsg = "查找品种失败,ERR:" + err.Error()
- }
- return
- }
- err = varietyInfo.Delete()
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除品种失败,ERR:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.IsAddLog = true
- }
- // List
- // @Title 获取标签中的指标与品种的映射关系
- // @Description 获取标签中的指标与品种的映射关系
- // @Success 200 Ret=200 保存成功
- // @router /variety/list [get]
- func (c *VarietyController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- // 获取数据
- list, err := cross_variety.GetVarietyList()
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,ERR:" + err.Error()
- return
- }
- dataCount := len(list)
- page := paging.GetPaging(1, dataCount, dataCount)
- resp := response.VarietyListResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Msg = "获取成功"
- br.Success = true
- br.Data = resp
- }
|