diff --git a/README.md b/README.md index cbe0641..b379ebe 100644 --- a/README.md +++ b/README.md @@ -2517,9 +2517,10 @@ DBEngine.Select("status", "update_time", "update_user").Updates(cat) **实现步骤:** **1). 定义Minio相关配置,生成一个配置对象** -我们在internal文件夹下创建minio文件夹,然后文件夹创建,config.go文件,并生成一个 +我们在pkg文件夹下先建一个obs文件夹,然后创建一个config.go文件。 +>pkg/obs/config.go ```go -package main +package obs import ( "github.com/minio/minio-go" @@ -2527,7 +2528,8 @@ import ( ) var ( - MinioClient *minio.Client + minioClient *minio.Client + OBS OBSClient ) const ( @@ -2535,260 +2537,179 @@ const ( accessKeyID = "minioadmin" // 对象存储的Access key secretAccessKey = "minioadmin" /// 对象存储的Secret key ssl = false //true代表使用HTTPS + bucketName = "sky-take-out" // 设置同名称 ) func init() { // 初使化minio client对象。 - minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, ssl) + mc, err := minio.New(endpoint, accessKeyID, secretAccessKey, ssl) if err != nil { log.Println(err) } else { - MinioClient = minioClient + minioClient = mc } + OBS = &MyMinio{} } -func main() { - if MinioClient != nil { - log.Println("链接服务器成功") - } -} - ``` **2). 生成防腐层** - - - -其中,AliOssUtil.java已在sky-common模块中定义 - ```go +package obs -``` - - - -#### 新增菜品实现 - -**1). 设计DTO类** - -在sky-pojo模块中 - -```java - -``` - - - -**2). Controller层** - -进入到sky-server模块 - -```java -package com.sky.controller.admin; - -/** - * 菜品管理 - */ -@RestController -@RequestMapping("/admin/dish") -@Api(tags = "菜品相关接口") -@Slf4j -public class DishController { - - @Autowired - private DishService dishService; +import ( + "github.com/google/uuid" + "github.com/minio/minio-go" + "log" + "mime/multipart" + "path" + "strings" + "time" +) - /** - * 新增菜品 - * - * @param dishDTO - * @return - */ - @PostMapping - @ApiOperation("新增菜品") - public Result save(@RequestBody DishDTO dishDTO) { - log.info("新增菜品:{}", dishDTO); - dishService.saveWithFlavor(dishDTO);//后绪步骤开发 - return Result.success(); - } +type OBSClient interface { + UploadImg(fh *multipart.FileHeader) *string } -``` +/* +实现类 +*/ +type MyMinio struct { +} - -**3). Service层接口** - -```java -package com.sky.service; - -import com.sky.dto.DishDTO; -import com.sky.entity.Dish; - -public interface DishService { - - /** - * 新增菜品和对应的口味 - * - * @param dishDTO - */ - public void saveWithFlavor(DishDTO dishDTO); - +func (*MyMinio) UploadImg(fh *multipart.FileHeader) *string { + var str strings.Builder + str.WriteString(time.Now().Format("2006/01/02/")) + // 生成一个新的UUIDv4 + id := uuid.New() + str.WriteString(id.String()) + str.WriteString(path.Ext(fh.Filename)) + filepath := str.String() + file_body, _ := fh.Open() + _, err := minioClient.PutObject(bucketName, filepath, file_body, fh.Size, minio.PutObjectOptions{ + ContentType: fh.Header.Get("Content-Type"), + }) + filepath = "http://" + path.Join(endpoint, bucketName, filepath) + if err != nil { + log.Fatalln(err) + return nil + } + return &filepath } ``` +在上面的代码中我们抽象了一层接口,定义了OBSClient 接口,之后我们进行存储的时候,只需要调用该接口的方法,这样方便我们更换成华为,腾讯等OBS。 +之后我们定义了MyMinio的实体类,让他实现OBSClient的接口。 +**3). 添加路由** +在router.go添加以下内容 +```go +com := adm.Group("/common") + { + com.POST("/upload", admin.UploadImg) + } +``` +**3). 添加route方法** +我们在admin文件夹下创建eommon_router.go文件,并且添加以下内容、 +```go +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" + "mime/multipart" + "net/http" + "reggie/internal/models/common" + "reggie/internal/models/constant/message_c" + "reggie/pkg/obs" +) -**4). Service层实现类** - -```java -package com.sky.service.impl; - - -@Service -@Slf4j -public class DishServiceImpl implements DishService { +func getFile(from *multipart.Form) *multipart.FileHeader { + fileH := from.File["file"][0] + return fileH +} +func UploadImg(ctx context.Context, c *app.RequestContext) { + form, err := c.MultipartForm() + if err != nil { + c.JSON(http.StatusOK, common.Result{0, message_c.UPLOAD_FAILED, nil}) + } + if str := obs.OBS.UploadImg(getFile(form)); str != nil { + c.JSON(http.StatusOK, common.Result{1, "", str}) + } +} - @Autowired - private DishMapper dishMapper; - @Autowired - private DishFlavorMapper dishFlavorMapper; +``` +这样我们的上传文件的功能就完成了。 - /** - * 新增菜品和对应的口味 - * - * @param dishDTO - */ - @Transactional - public void saveWithFlavor(DishDTO dishDTO) { +##### 客户端测试 ? - Dish dish = new Dish(); - BeanUtils.copyProperties(dishDTO, dish); - //向菜品表插入1条数据 - dishMapper.insert(dish);//后绪步骤实现 - //获取insert语句生成的主键值 - Long dishId = dish.getId(); - List flavors = dishDTO.getFlavors(); - if (flavors != null && flavors.size() > 0) { - flavors.forEach(dishFlavor -> { - dishFlavor.setDishId(dishId); - }); - //向口味表插入n条数据 - dishFlavorMapper.insertBatch(flavors);//后绪步骤实现 - } - } +#### 新增菜品实现 +**1). 添加路由** +>internal/router/router.go +```go +dish := adm.Group("/dish") +{ +// 添加菜品 +dish.POST("", admin.SaveDish) } -``` - - -**5). Mapper层** - -DishMapper.java中添加 - -```java - /** - * 插入菜品数据 - * - * @param dish - */ - @AutoFill(value = OperationType.INSERT) - void insert(Dish dish); ``` -在/resources/mapper中创建DishMapper.xml - -```xml - - - - - - insert into dish (name, category_id, price, image, description, create_time, update_time, create_user,update_user, status) - values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{status}) - - +**2). router层** +我们在admin文件夹下创建dish_router.go文件 +>internal/router/admin/dish_router.go +```go +func SaveDish(ctx context.Context, c *app.RequestContext) { + var dish model.Dish + c.Bind(&dish) + // 赋予创建用户和更新用户的数据 + dish.CreateUser, dish.UpdateUser = middleware.GetJwtPayload(c), middleware.GetJwtPayload(c) + // 赋予创建时间和更新时间数据 + dish.CreateTime, dish.UpdateTime = time.Now(), time.Now() + log.Println("新增分类:", dish) + service.SaveDish(&dish) + c.JSON(http.StatusOK, common.Result{1, "", nil}) +} ``` -DishFlavorMapper.java -```java -package com.sky.mapper; - -import com.sky.entity.DishFlavor; -import java.util.List; - -@Mapper -public interface DishFlavorMapper { - /** - * 批量插入口味数据 - * @param flavors - */ - void insertBatch(List flavors); +**3). Service层接口** +>internal/router/service/dish_service.go +```go +func SaveDish(dish *model.Dish) { + db.DisDao.Save(dish) } ``` -在/resources/mapper中创建DishFlavorMapper.xml -```xml - - - - - insert into dish_flavor (dish_id, name, value) VALUES - - (#{df.dishId},#{df.name},#{df.value}) - - - -``` - - - -### 2.3 功能测试 - -进入到菜品管理--->新建菜品 - -image-20221121195440804 - -由于没有实现菜品查询功能,所以保存后,暂且在表中查看添加的数据。 - -dish表: - -image-20221121195737692 - -dish_flavor表: - -image-20221121195902555 - -测试成功。 - - - -### 2.4代码提交 - -image-20221121200332933 - -后续步骤和上述功能代码提交一致,不再赘述。 +**4). dao层实现类** +我们在db文件夹下的db.go添加以下内容。 +>var DisDao dishI = &dishDao{} +```go +type dishI interface { + Save(dish *model.Dish) +} +type dishDao struct { +} +func (*dishDao) Save(dish *model.Dish) { + DBEngine.Create(dish) +} +``` -## 3. 菜品分页查询 +## 菜品分页查询 ? -### 3.1 需求分析和设计 +### 需求分析和设计 -#### 3.1.1 产品原型 +#### 产品原型 系统中的菜品数据很多的时候,如果在一个页面中全部展示出来会显得比较乱,不便于查看,所以一般的系统中都会以分页的方式来展示列表数据。 **菜品分页原型:** - -image-20221121201552489 +![img](images/img_64.png) 在菜品列表展示时,除了菜品的基本信息(名称、售价、售卖状态、最后操作时间)外,还有两个字段略微特殊,第一个是图片字段 ,我们从数据库查询出来的仅仅是图片的名字,图片要想在表格中回显展示出来,就需要下载这个图片。第二个是菜品分类,这里展示的是分类名称,而不是分类ID,此时我们就需要根据菜品的分类ID,去分类表中查询分类信息,然后在页面展示。 @@ -2800,93 +2721,50 @@ dish_flavor表: -#### 3.1.2 接口设计 +#### 接口设计 根据上述原型图,设计出相应的接口。 -image-20221121202019258 image-20221121202033284 +![img](images/img_65.png) +### 代码开发 - -### 3.2 代码开发 - -#### 3.2.1 设计DTO类 +#### 设计DTO类 **根据菜品分页查询接口定义设计对应的DTO:** +>internal/models/dto/common.go +```go +/* +添加分页id +*/ +type DishPageQueryDTO struct { + Page int `json:"page,omitempty" form:"page,omitempty"` -在sky-pojo模块中,已定义 - -```java -package com.sky.dto; - -import lombok.Data; -import java.io.Serializable; + PageSize int `json:"pageSize,omitempty" form:"pageSize,omitempty"` -@Data -public class DishPageQueryDTO implements Serializable { + Name *string `json:"name,omitempty" form:"name,omitempty"` - private int page; - private int pageSize; - private String name; - private Integer categoryId; //分类id - private Integer status; //状态 0表示禁用 1表示启用 + //分类id + CategoryId *int `json:"category_id,omitempty" form:"categoryId,omitempty"` + //状态 0表示禁用 1表示启用 + Status *int `json:"status,omitempty" form:"status,omitempty"` } + ``` -#### 3.2.2 设计VO类 +#### 设计VO类 **根据菜品分页查询接口定义设计对应的VO:** 在sky-pojo模块中,已定义 -```java -package com.sky.vo; - -import com.sky.entity.DishFlavor; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import java.io.Serializable; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DishVO implements Serializable { - - private Long id; - //菜品名称 - private String name; - //菜品分类id - private Long categoryId; - //菜品价格 - private BigDecimal price; - //图片 - private String image; - //描述信息 - private String description; - //0 停售 1 起售 - private Integer status; - //更新时间 - private LocalDateTime updateTime; - //分类名称 - private String categoryName; - //菜品关联的口味 - private List flavors = new ArrayList<>(); -} -``` -#### 3.2.3 Controller层 +#### Controller层 **根据接口定义创建DishController的page分页查询方法:** @@ -3008,18 +2886,17 @@ public class DishVO implements Serializable { -## 4. 删除菜品 +## 删除菜品 -### 4.1 需求分析和设计 +### 需求分析和设计 -#### 4.1.1 产品原型 +#### 产品原型 在菜品列表页面,每个菜品后面对应的操作分别为**修改**、**删除**、**停售**,可通过删除功能完成对菜品及相关的数据进行删除。 **删除菜品原型:** -image-20221121211236356 - +![img](images/img_66.png) **业务规则:** @@ -3031,21 +2908,19 @@ public class DishVO implements Serializable { -#### 4.1.2 接口设计 +#### 接口设计 根据上述原型图,设计出相应的接口。 - -image-20221121211801121 image-20221121211814429 +![img](images/img_67.png) **注意:**删除一个菜品和批量删除菜品共用一个接口,故ids可包含多个菜品id,之间用逗号分隔。 -#### 4.1.3 表设计 +#### 表设计 在进行删除菜品操作时,会涉及到以下三张表。 - -image-20221121212436851 +![img](images/img_67.png) **注意事项:** @@ -3508,13 +3383,191 @@ SetmealDishMapper.xml -### 5.4 代码提交 +## 店铺营业状态设置 -image-20221122141554380 +### 需求分析和设计 -后续步骤和上述功能代码提交一致,不再赘述。 +#### 产品原型 + +进到苍穹外卖后台,显示餐厅的营业状态,营业状态分为**营业中**和**打烊中**,若当前餐厅处于营业状态,自动接收任何订单,客户可在小程序进行下单操作;若当前餐厅处于打烊状态,不接受任何订单,客户便无法在小程序进行下单操作。 +![img](images/img_69.png) + +点击**营业状态**按钮时,弹出更改营业状态 +![img](images/img_70.png) +选择营业,设置餐厅为**营业中**状态 + +选择打烊,设置餐厅为**打烊中**状态 + +**状态说明:** + +![img](images/img_71.png) + +#### 接口设计 + +根据上述原型图设计接口,共包含3个接口。 + +**接口设计:** + +- 设置营业状态 +- 管理端查询营业状态 +- 用户端查询营业状态 + +**注:**从技术层面分析,其实管理端和用户端查询营业状态时,可通过一个接口去实现即可。因为营业状态是一致的。但是,本项目约定: + +- **管理端**发出的请求,统一使用/admin作为前缀。 +- **用户端**发出的请求,统一使用/user作为前缀。 + +因为访问路径不一致,故分为两个接口实现。 + +**1). 设置营业状态** +![img](images/img_71.png) + + +**2). 管理端营业状态** +![img](images/img_73.png) +**3). 用户端营业状态** +![img](images/img_74.png) + +#### 营业状态存储方式 + +虽然,可以通过一张表来存储营业状态数据,但整个表中只有一个字段,所以意义不大。 + +营业状态数据存储方式:基于Redis的字符串来进行存储 + +**约定:**1表示营业 0表示打烊 + + + +### 代码开发 + +#### 设置营业状态 +1. 添加路由 +>internal/router/router.go +```go +shop := adm.Group("/shop") + { + shop.POST("/:status", admin.SetStatusShop) + } +``` +2. 设置router +>internal/router/admin/shop_router.go +```go +func SetStatusShop(ctx context.Context, c *app.RequestContext) { + s := c.Param("status") + status, _ := strconv.Atoi(s) + var statusString string + if status == 1 { + statusString = "营业中" + } else { + statusString = "打烊中" + } + hlog.Infof("设置店铺的营业状态为:", statusString) + service.SetStatusShop(&status) + c.JSON(http.StatusOK, common.Result{1, "", nil}) +} +``` +3. 设置service +>internal/router/service/shop_service.go +```go +func SetStatusShop(status *int) { + redis.RC.SetStatus(status) +} + +``` + +#### 管理端查询营业状态 + + +1. 添加路由 +>internal/router/router.go +```go + shop.GET("/status", admin.GetStatusShop) +``` +2. 设置router +>internal/router/admin/shop_router.go +```go +func GetStatusShop(ctx context.Context, c *app.RequestContext) { + +status := *service.GetStatusShop() +var statusString string +if status == 1 { +statusString = "营业中" +} else { +statusString = "打烊中" +} +hlog.Infof("获取到店铺的营业状态为:{}", statusString) +service.SetStatusShop(&status) +c.JSON(http.StatusOK, common.Result{1, "", nil}) +} + +``` +3. 设置service +>internal/router/service/shop_service.go +```go +func GetStatusShop() *int { +return redis.RC.GetStatus() +} +``` +### 添加redis +在pkg在创建redis文件夹,然后在acl.go文件和config.go文件。 +>pkg/redis/acl.go +```go +package redis + +import "context" + +type RedisClient interface { + SetStatus(status *int) + GetStatus() *int +} +type redisClient struct { +} + +func (*redisClient) SetStatus(status *int) { + rc.Set( + context.Background(), + shop_key, + status, + 0, + ) +} +func (*redisClient) GetStatus() *int { + val, _ := rc.Get(context.Background(), shop_key).Int() + return &val +} + +``` +>pkg/redis/config.go +```go +package redis + +import "github.com/redis/go-redis/v9" + +var ( + rc *redis.Client + RC RedisClient +) + +const ( + addr = "localhost:6379" + pass_word = "" + db = 0 + shop_key = "SHOP_STATUS" +) + +func init() { + rdb := redis.NewClient(&redis.Options{ + Addr: addr, + Password: pass_word, // 没有密码,默认值 + DB: db, // 默认DB 0 + }) + rc = rdb + RC = &redisClient{} +} +``` + # 代码存在的问题 ## 问题一 日期无法正常显示 @@ -3545,6 +3598,9 @@ SetmealDishMapper.xml "sort": 3 } ``` + + + ### 解决方法 #### 添加vo视图(不推荐) 我们可以新建一个视图,让视图能够接受字符串类型,之后我们再转换成int类型赋值给需要插入的类,但是不建议这么做,因为go的类型转换还是有点繁琐,建议还是改前端。 diff --git a/go.mod b/go.mod index c1b1bc1..d614343 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/hertz-contrib/logger/accesslog v0.0.0-20240128134225-6b18af47a115 github.com/hertz-contrib/swagger v0.0.0-20230410084747-96f1a1b976ab github.com/minio/minio-go v6.0.14+incompatible + github.com/redis/go-redis/v9 v9.5.1 github.com/spf13/viper v1.16.0 github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 github.com/swaggo/swag v1.8.2 @@ -16,6 +17,11 @@ require ( gorm.io/gorm v1.25.7 ) +require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect +) + require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect @@ -34,7 +40,7 @@ require ( github.com/go-sql-driver/mysql v1.7.1 // indirect github.com/golang-jwt/jwt/v4 v4.4.1 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/uuid v1.6.0 // indirect + github.com/google/uuid v1.6.0 github.com/hashicorp/hcl v1.0.0 // indirect github.com/henrylee2cn/ameda v1.4.10 // indirect github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect @@ -63,7 +69,7 @@ require ( golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.18.0 // indirect + golang.org/x/tools v0.15.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index eae21dc..9b764b9 100644 --- a/go.sum +++ b/go.sum @@ -44,6 +44,10 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 h1:PtwsQyQJGxf8iaPptPNaduEIu9BnrNms+pcRdHAxZaM= @@ -54,6 +58,8 @@ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1 github.com/bytedance/sonic v1.8.1 h1:NqAHCaGaTzro0xMmnTCLUyRlbEP6r8MCA1cJUrH3Pu4= github.com/bytedance/sonic v1.8.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -72,6 +78,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -255,6 +263,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= +github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -414,8 +424,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -519,8 +529,8 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8= +golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/images/img_64.png b/images/img_64.png new file mode 100644 index 0000000..f98211e Binary files /dev/null and b/images/img_64.png differ diff --git a/images/img_65.png b/images/img_65.png new file mode 100644 index 0000000..302d671 Binary files /dev/null and b/images/img_65.png differ diff --git a/images/img_66.png b/images/img_66.png new file mode 100644 index 0000000..e4a9c9a Binary files /dev/null and b/images/img_66.png differ diff --git a/images/img_67.png b/images/img_67.png new file mode 100644 index 0000000..7ea4c48 Binary files /dev/null and b/images/img_67.png differ diff --git a/images/img_68.png b/images/img_68.png new file mode 100644 index 0000000..b1784a2 Binary files /dev/null and b/images/img_68.png differ diff --git a/images/img_69.png b/images/img_69.png new file mode 100644 index 0000000..4925ebb Binary files /dev/null and b/images/img_69.png differ diff --git a/images/img_70.png b/images/img_70.png new file mode 100644 index 0000000..3171fd2 Binary files /dev/null and b/images/img_70.png differ diff --git a/images/img_71.png b/images/img_71.png new file mode 100644 index 0000000..fd637b2 Binary files /dev/null and b/images/img_71.png differ diff --git a/images/img_72.png b/images/img_72.png new file mode 100644 index 0000000..aa8a498 Binary files /dev/null and b/images/img_72.png differ diff --git a/images/img_73.png b/images/img_73.png new file mode 100644 index 0000000..48971e9 Binary files /dev/null and b/images/img_73.png differ diff --git a/images/img_74.png b/images/img_74.png new file mode 100644 index 0000000..ae9551d Binary files /dev/null and b/images/img_74.png differ diff --git a/images/img_75.png b/images/img_75.png new file mode 100644 index 0000000..56b1904 Binary files /dev/null and b/images/img_75.png differ diff --git a/internal/models/dto/common.go b/internal/models/dto/common.go index 421afc6..fe7d18c 100644 --- a/internal/models/dto/common.go +++ b/internal/models/dto/common.go @@ -1,5 +1,11 @@ package dto +import ( + "encoding/json" + "reggie/internal/models/model" + "time" +) + type EmployeePageQueryDTO struct { //员工姓名 Name *string `json:"name,omitempty" form:"name,omitempty"` @@ -18,6 +24,26 @@ type CategoryPageQueryDTO struct { //分类类型 1菜品分类 2套餐分类 Type *int `json:"type,omitempty" form:"type,omitempty"` } +type DishDTO struct { + ID int64 `json:"id,omitempty"` + Name string `json:"name,omitempty"` + CategoryID int64 `json:"categoryId,omitempty"` + Price float64 `json:"price,omitempty"` + Image string `json:"image,omitempty"` + Description string `json:"description,omitempty"` + Status int32 `json:"status,omitempty"` + flavors []*model.DishFlavor `json:"flavors,omitempty"` +} + +// 如果传入的id不等于nil, +func (d *DishDTO) ToNewDish(id *int64) *model.Dish { + v, _ := json.Marshal(d) + var dish model.Dish + json.Unmarshal(v, &dish) + dish.CreateUser, dish.UpdateUser = *id, *id + dish.CreateTime, dish.UpdateTime = time.Now(), time.Now() + return &dish +} /* 添加分页id diff --git a/internal/models/vo/common.go b/internal/models/vo/common.go index d16e64d..eeb6bbd 100644 --- a/internal/models/vo/common.go +++ b/internal/models/vo/common.go @@ -1,5 +1,10 @@ package vo +import ( + "reggie/internal/models/model" + "time" +) + type EmployeeLoginVO struct { Id int64 `json:"id,omitempty"` @@ -9,3 +14,24 @@ type EmployeeLoginVO struct { Token string `json:"token,omitempty"` } +type DishVO struct { + id int64 `json:"id,omitempty"` + //菜品名称 + name string `json:"name,omitempty"` + //菜品分类id + categoryId int64 `json:"category_id,omitempty"` + //菜品价格 + price float64 `json:"price,omitempty"` + //图片 + image string `json:"image,omitempty"` + //描述信息 + description string `json:"description,omitempty"` + //0 停售 1 起售 + status int64 `json:"status,omitempty"` + //更新时间 + updateTime time.Time `json:"update_time"` + //分类名称 + categoryName string `json:"category_name,omitempty"` + //菜品关联的口味 + flavors []*model.DishFlavor `json:"flavors,omitempty"` +} diff --git a/internal/router/admin/common_router.go b/internal/router/admin/common_router.go index 6d4efb0..0095407 100644 --- a/internal/router/admin/common_router.go +++ b/internal/router/admin/common_router.go @@ -5,9 +5,9 @@ import ( "github.com/cloudwego/hertz/pkg/app" "mime/multipart" "net/http" - obs "reggie/internal/OBS" "reggie/internal/models/common" "reggie/internal/models/constant/message_c" + "reggie/pkg/obs" ) func getFile(from *multipart.Form) *multipart.FileHeader { diff --git a/internal/router/admin/dish_router.go b/internal/router/admin/dish_router.go index ff95aeb..7c0f8c1 100644 --- a/internal/router/admin/dish_router.go +++ b/internal/router/admin/dish_router.go @@ -16,14 +16,12 @@ import ( ) func SaveDish(ctx context.Context, c *app.RequestContext) { - var dish model.Dish - c.Bind(&dish) - // 赋予创建用户和更新用户的数据 - dish.CreateUser, dish.UpdateUser = middleware.GetJwtPayload(c), middleware.GetJwtPayload(c) - // 赋予创建时间和更新时间数据 - dish.CreateTime, dish.UpdateTime = time.Now(), time.Now() + var dist dto.DishDTO + c.Bind(dist) + id := middleware.GetJwtPayload(c) + var dish = dist.ToNewDish(&id) log.Println("新增分类:", dish) - service.SaveDish(&dish) + service.SaveDish(dish) c.JSON(http.StatusOK, common.Result{1, "", nil}) } diff --git a/internal/router/admin/shop_router.go b/internal/router/admin/shop_router.go new file mode 100644 index 0000000..04615b2 --- /dev/null +++ b/internal/router/admin/shop_router.go @@ -0,0 +1,39 @@ +package admin + +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/hlog" + "net/http" + "reggie/internal/models/common" + "reggie/internal/router/service" + "strconv" +) + +func SetStatusShop(ctx context.Context, c *app.RequestContext) { + s := c.Param("status") + status, _ := strconv.Atoi(s) + var statusString string + if status == 1 { + statusString = "营业中" + } else { + statusString = "打烊中" + } + hlog.Infof("设置店铺的营业状态为:", statusString) + service.SetStatusShop(&status) + c.JSON(http.StatusOK, common.Result{1, "", nil}) +} + +func GetStatusShop(ctx context.Context, c *app.RequestContext) { + + status := *service.GetStatusShop() + var statusString string + if status == 1 { + statusString = "营业中" + } else { + statusString = "打烊中" + } + hlog.Infof("获取到店铺的营业状态为:{}", statusString) + service.SetStatusShop(&status) + c.JSON(http.StatusOK, common.Result{1, "", nil}) +} diff --git a/internal/router/router.go b/internal/router/router.go index e453d94..05ab2f4 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -79,5 +79,10 @@ func InitRouter(r *server.Hertz) { // 根据类型查询分类 dish.GET("/list", admin.ListDish) } + shop := adm.Group("/shop") + { + shop.POST("/:status", admin.SetStatusShop) + shop.GET("/status", admin.GetStatusShop) + } } diff --git a/internal/router/service/dish_service.go b/internal/router/service/dish_service.go index b6e1645..5ba64ac 100644 --- a/internal/router/service/dish_service.go +++ b/internal/router/service/dish_service.go @@ -8,8 +8,9 @@ import ( "time" ) -func SaveDish(dish *model.Dish) { +func SaveDish(dish *model.Dish) *model.Dish { db.DisDao.Save(dish) + return dish } func PageQueryDish(categoryPage *dto.DishPageQueryDTO) *common.PageResult { var pageResult = common.PageResult{} diff --git a/internal/router/service/shop_service.go b/internal/router/service/shop_service.go new file mode 100644 index 0000000..82724bf --- /dev/null +++ b/internal/router/service/shop_service.go @@ -0,0 +1,10 @@ +package service + +import "reggie/pkg/redis" + +func SetStatusShop(status *int) { + redis.RC.SetStatus(status) +} +func GetStatusShop() *int { + return redis.RC.GetStatus() +} diff --git a/nginx-1.20.2/logs/access.log b/nginx-1.20.2/logs/access.log index f3c4d6f..d0e24e2 100644 --- a/nginx-1.20.2/logs/access.log +++ b/nginx-1.20.2/logs/access.log @@ -1809,3 +1809,27 @@ 127.0.0.1 - - [29/Feb/2024:21:11:31 +0800] "GET /img/noImg.89ccbe0c.png HTTP/1.1" 200 5432 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" 127.0.0.1 - - [29/Feb/2024:21:11:31 +0800] "GET /img/noImg.89ccbe0c.png HTTP/1.1" 200 5432 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" 127.0.0.1 - - [29/Feb/2024:21:11:31 +0800] "GET /img/noImg.89ccbe0c.png HTTP/1.1" 200 5432 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /index.html HTTP/1.1" 200 2012 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /css/chunk-vendors.37cc3fbd.css HTTP/1.1" 200 7903 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /css/app.fd9b670b.css HTTP/1.1" 200 364764 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /js/app.d0aa4eb3.js HTTP/1.1" 200 57032 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /css/404.6a750851.css HTTP/1.1" 200 5256 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:07 +0800] "GET /css/dashboard.8da8967e.css HTTP/1.1" 200 9605 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /css/login.f8377ced.css HTTP/1.1" 200 2533 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /css/shopTable.5fd29e98.css HTTP/1.1" 200 31547 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /js/chunk-vendors.9b7e46a0.js HTTP/1.1" 200 2333478 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /js/404.c61770cf.js HTTP/1.1" 200 2120 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /js/dashboard.630a609e.js HTTP/1.1" 200 40566 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /js/login.90288d75.js HTTP/1.1" 200 3401 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /js/shopTable.fe534d8f.js HTTP/1.1" 200 121212 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /img/icon_logo.38b01728.png HTTP/1.1" 200 12440 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /img/login-l.6ef9d260.png HTTP/1.1" 200 1871310 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /img/icons/favicon-32x32.png HTTP/1.1" 200 13342 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /img/icons/favicon-16x16.png HTTP/1.1" 200 13342 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /manifest.json HTTP/1.1" 200 454 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:08 +0800] "GET /img/icons/android-chrome-192x192.png HTTP/1.1" 200 2484 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:12 +0800] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:13 +0800] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:14 +0800] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:22 +0800] "GET /fonts/element-icons.535877f5.woff HTTP/1.1" 200 28200 "http://localhost/css/app.fd9b670b.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" +127.0.0.1 - - [03/Mar/2024:15:49:26 +0800] "POST /api/employee/login HTTP/1.1" 502 494 "http://localhost/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0" diff --git a/nginx-1.20.2/logs/error.log b/nginx-1.20.2/logs/error.log index ec327b6..b192758 100644 --- a/nginx-1.20.2/logs/error.log +++ b/nginx-1.20.2/logs/error.log @@ -188,3 +188,5 @@ 2024/02/29 21:09:31 [error] 2924#3292: *418 WSARecv() failed (10054: An existing connection was forcibly closed by the remote host) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "DELETE /api/dish?ids=75,74 HTTP/1.1", upstream: "http://127.0.0.1:8080/admin/dish?ids=75,74", host: "localhost", referrer: "http://localhost/" 2024/02/29 21:09:33 [error] 2924#3292: *418 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "DELETE /api/dish?ids=75,74 HTTP/1.1", upstream: "http://[::1]:8080/admin/dish?ids=75,74", host: "localhost", referrer: "http://localhost/" 2024/02/29 21:11:10 [error] 2924#3292: *444 CreateFile() "D:\ProjectGo\reggie\nginx-1.20.2/html/sky/undefined" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /undefined HTTP/1.1", host: "localhost", referrer: "http://localhost/" +2024/03/03 15:49:24 [error] 29632#28532: *2 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "POST /api/employee/login HTTP/1.1", upstream: "http://[::1]:8080/admin/employee/login", host: "localhost", referrer: "http://localhost/index.html" +2024/03/03 15:49:26 [error] 29632#28532: *2 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "POST /api/employee/login HTTP/1.1", upstream: "http://127.0.0.1:8080/admin/employee/login", host: "localhost", referrer: "http://localhost/index.html" diff --git a/nginx-1.20.2/logs/nginx.pid b/nginx-1.20.2/logs/nginx.pid index 27ef230..b004255 100644 --- a/nginx-1.20.2/logs/nginx.pid +++ b/nginx-1.20.2/logs/nginx.pid @@ -1 +1 @@ -16068 +22328 diff --git a/internal/OBS/acl.go b/pkg/obs/acl.go similarity index 96% rename from internal/OBS/acl.go rename to pkg/obs/acl.go index 03a5295..cdc53ab 100644 --- a/internal/OBS/acl.go +++ b/pkg/obs/acl.go @@ -10,7 +10,7 @@ import ( "time" ) -type OBSSave interface { +type OBSClient interface { UploadImg(fh *multipart.FileHeader) *string } diff --git a/internal/OBS/config.go b/pkg/obs/config.go similarity index 96% rename from internal/OBS/config.go rename to pkg/obs/config.go index fc2ec89..66f19ab 100644 --- a/internal/OBS/config.go +++ b/pkg/obs/config.go @@ -7,7 +7,7 @@ import ( var ( minioClient *minio.Client - OBS OBSSave + OBS OBSClient ) const ( diff --git a/pkg/redis/acl.go b/pkg/redis/acl.go new file mode 100644 index 0000000..1a3b1c7 --- /dev/null +++ b/pkg/redis/acl.go @@ -0,0 +1,23 @@ +package redis + +import "context" + +type RedisClient interface { + SetStatus(status *int) + GetStatus() *int +} +type redisClient struct { +} + +func (*redisClient) SetStatus(status *int) { + rc.Set( + context.Background(), + shop_key, + status, + 0, + ) +} +func (*redisClient) GetStatus() *int { + val, _ := rc.Get(context.Background(), shop_key).Int() + return &val +} diff --git a/pkg/redis/config.go b/pkg/redis/config.go new file mode 100644 index 0000000..5ad31ef --- /dev/null +++ b/pkg/redis/config.go @@ -0,0 +1,25 @@ +package redis + +import "github.com/redis/go-redis/v9" + +var ( + rc *redis.Client + RC RedisClient +) + +const ( + addr = "localhost:6379" + pass_word = "" + db = 0 + shop_key = "SHOP_STATUS" +) + +func init() { + rdb := redis.NewClient(&redis.Options{ + Addr: addr, + Password: pass_word, // 没有密码,默认值 + DB: db, // 默认DB 0 + }) + rc = rdb + RC = &redisClient{} +}