|
@@ -0,0 +1,106 @@
|
|
|
|
|
+package com.txz.mall.controller;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
|
+import com.txz.mall.core.Result;
|
|
|
|
|
+import com.txz.mall.core.UserUtil;
|
|
|
|
|
+import com.txz.mall.model.Diy;
|
|
|
|
|
+import com.txz.mall.service.DiyService;
|
|
|
|
|
+import com.txz.mall.web.param.BasePageParam;
|
|
|
|
|
+import com.txz.mall.web.ro.DiyRO;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * diy
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author: MTD®️
|
|
|
|
|
+ * @date: 2026/2/3
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+@RequestMapping("diy")
|
|
|
|
|
+public class DiyController {
|
|
|
|
|
+
|
|
|
|
|
+ private final DiyService diyService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 分页
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("page")
|
|
|
|
|
+ public Result<Page<Diy>> page(BasePageParam page, String queryStr) {
|
|
|
|
|
+ PageHelper.startPage(page.getPage(), page.getSize());
|
|
|
|
|
+ return Result.success(
|
|
|
|
|
+ new PageInfo<>(diyService.list(Wrappers.<Diy>lambdaQuery()
|
|
|
|
|
+ .select(Diy::getId, Diy::getTitle, Diy::getImage, Diy::getSort, Diy::getCreateTime, Diy::getUpdateTime, Diy::getStatus)
|
|
|
|
|
+ .and(StrUtil.isNotBlank(queryStr),
|
|
|
|
|
+ item -> item
|
|
|
|
|
+ .like(Diy::getTitle, queryStr)
|
|
|
|
|
+ )
|
|
|
|
|
+ .orderByDesc(Diy::getCreateTime)
|
|
|
|
|
+ ))
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("save")
|
|
|
|
|
+ public Result save(@Validated({DiyRO.Add.class}) @RequestBody DiyRO ro, HttpServletRequest request) {
|
|
|
|
|
+ Diy diy = BeanUtil.copyProperties(ro, Diy.class);
|
|
|
|
|
+ diy.setCreateUserId(UserUtil.getAdminUserId(request));
|
|
|
|
|
+ diyService.save(diy);
|
|
|
|
|
+ return Result.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("info/{id:^\\d+$}")
|
|
|
|
|
+ public Result info(@PathVariable("id") Long id) {
|
|
|
|
|
+ Diy info = diyService.getById(id);
|
|
|
|
|
+ if (ObjectUtil.isEmpty(info)) {
|
|
|
|
|
+ return Result.fail("数据不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(info);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改状态
|
|
|
|
|
+ */
|
|
|
|
|
+ @DeleteMapping("changeStatus/{id:^\\d+$}")
|
|
|
|
|
+ public Result delete(@PathVariable("id") Long id) {
|
|
|
|
|
+ Diy info = diyService.getById(id);
|
|
|
|
|
+ if (ObjectUtil.isEmpty(info)) {
|
|
|
|
|
+ return Result.fail("数据不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ info.setStatus(!info.getStatus());
|
|
|
|
|
+ return Result.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新
|
|
|
|
|
+ */
|
|
|
|
|
+ @PatchMapping("update/{id:^\\d+$}")
|
|
|
|
|
+ public Result update(@Validated({DiyRO.Update.class}) @RequestBody DiyRO ro, @PathVariable("id") Long id, HttpServletRequest request) {
|
|
|
|
|
+ Diy info = diyService.getById(id);
|
|
|
|
|
+ if (ObjectUtil.isEmpty(info)) {
|
|
|
|
|
+ return Result.fail("数据不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtil.copyProperties(ro, info);
|
|
|
|
|
+ info.setUpdateUserId(UserUtil.getAdminUserId(request));
|
|
|
|
|
+ diyService.updateById(info);
|
|
|
|
|
+ return Result.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|