12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package backend
- import (
- "context"
- "kpt-pasture/model"
- "net/http"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
- "gitee.com/xuyiping_admin/pkg/xerr"
- "go.uber.org/zap"
- )
- func (s *StoreEntry) SystemBasicList(ctx context.Context) (*pasturePb.SearchBaseDataConfigResponse, error) {
- userModel, err := s.GetUserModel(ctx)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- systemBasicList := make([]*model.SystemBasic, 0)
- if err = s.DB.Model(new(model.SystemBasic)).
- Where("pasture_id = ?", userModel.AppPasture.Id).
- Where("is_show = ?", pasturePb.IsShow_Ok).Find(&systemBasicList).Error; err != nil {
- return nil, xerr.WithStack(err)
- }
- return &pasturePb.SearchBaseDataConfigResponse{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &pasturePb.SearchBaseDataConfigData{
- List: model.SystemBasicSlice(systemBasicList).ToPb(),
- Total: int32(len(systemBasicList)),
- },
- }, nil
- }
- func (s *StoreEntry) SystemBasicEdit(ctx context.Context, req *pasturePb.BaseDataConfigBatch) error {
- userModel, err := s.GetUserModel(ctx)
- if err != nil {
- return xerr.WithStack(err)
- }
- for _, v := range req.Item {
- systemBasic := &model.SystemBasic{Id: v.Id}
- if err = s.DB.Model(systemBasic).
- Where("is_show = ?", pasturePb.IsShow_Ok).
- Where("pasture_id = ?", userModel.AppPasture.Id).
- First(systemBasic).Error; err != nil {
- zaplog.Error("SystemBasicEdit", zap.Any("err", err), zap.Any("req", req))
- return xerr.Customf("该配置信息不存在: %d", v.Id)
- }
- systemBasic.EditUpdate(v.MinValue, v.MaxValue, v.WeekValue, userModel.SystemUser)
- if err = s.DB.Model(systemBasic).
- Select("min_value", "max_value", "week_value", "operation_id", "operation_name").
- Updates(systemBasic).Error; err != nil {
- zaplog.Error("SystemBasicEdit", zap.Any("err", err), zap.Any("req", req))
- return xerr.WithStack(err)
- }
- }
- return nil
- }
- func (s *StoreEntry) FindSystemBasic(ctx context.Context, pastureId int64, name string) (*pasturePb.BaseDataConfig, error) {
- systemBasic := &model.SystemBasic{}
- if err := s.DB.Model(new(model.SystemBasic)).
- Where("pasture_id = ?", pastureId).
- Where("name = ?", name).
- Where("is_show = ?", pasturePb.IsShow_Ok).
- Find(&systemBasic).Error; err != nil {
- return nil, xerr.WithStack(err)
- }
- return &pasturePb.BaseDataConfig{
- Id: systemBasic.Id,
- Name: systemBasic.Name,
- CategoryId: systemBasic.CategoryId,
- CategoryName: systemBasic.CategoryName,
- MinValue: systemBasic.MinValue,
- MaxValue: systemBasic.MinValue,
- ValueType: systemBasic.ValueType,
- WeekValue: systemBasic.WeekValue,
- }, nil
- }
|