diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java b/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java index 49a17e7..196d32f 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/controller/SetmealController.java @@ -17,6 +17,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -34,6 +36,7 @@ import java.util.Map; * @author zyx * @since 1.0.0 2023-06-09 */ +@Slf4j @RestController @RequestMapping("takeout/setmeal") @Api(tags="套餐") @@ -52,7 +55,6 @@ public class SetmealController { @RequiresPermissions("takeout:setmeal:page") public Result> page(@ApiIgnore @RequestParam Map params){ PageData page = setmealService.page(params); - return new Result>().ok(page); } @@ -117,4 +119,22 @@ public class SetmealController { ExcelUtils.exportExcelToTarget(response, null, list, SetmealExcel.class); } + @PutMapping("updateStatus") + @ApiOperation("更新套餐状态") + @LogOperation("更新套餐状态") + @RequiresPermissions("takeout:setmeal:updateStatus") + @CacheEvict(value = "setmealCache", allEntries = true) + public Result updateStatus(@RequestParam Map params) { + List ids=new ArrayList<>(); + for (Map.Entry entry : params.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key != null && value != null) { + ids.add(value); + } + } + log.info("ids=-={}",ids); + setmealService.updateStatus(ids); + return new Result(); + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java b/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java index 58f1cfb..38c43bd 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/service/SetmealService.java @@ -4,6 +4,8 @@ import io.renren.common.service.CrudService; import io.renren.modules.takeout.dto.SetmealDTO; import io.renren.modules.takeout.entity.SetmealEntity; +import java.util.List; + /** * 套餐 * @@ -12,4 +14,7 @@ import io.renren.modules.takeout.entity.SetmealEntity; */ public interface SetmealService extends CrudService { + void updateStatus(int status, List ids); + + void updateStatus(List ids); } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java index c3cc0c7..385096d 100644 --- a/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/takeout/service/impl/SetmealServiceImpl.java @@ -1,14 +1,18 @@ package io.renren.modules.takeout.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import io.renren.common.service.impl.CrudServiceImpl; import io.renren.modules.takeout.dao.SetmealDao; import io.renren.modules.takeout.dto.SetmealDTO; import io.renren.modules.takeout.entity.SetmealEntity; import io.renren.modules.takeout.service.SetmealService; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; /** @@ -17,6 +21,7 @@ import java.util.Map; * @author zyx * @since 1.0.0 2023-06-09 */ +@Slf4j @Service public class SetmealServiceImpl extends CrudServiceImpl implements SetmealService { @@ -31,4 +36,40 @@ public class SetmealServiceImpl extends CrudServiceImpl ids) { + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.in(SetmealEntity::getId, ids).set(SetmealEntity::getStatus, status); + this.update(new SetmealEntity(), wrapper); + } + @Override + public void updateStatus(List ids) { + if (ids == null || ids.isEmpty()) { + log.info("ids==null----"); + return; + } + if (ids.size()>1){ + int index =Integer.parseInt(ids.get(0)) ; + log.info("index=={}",index); + for (int i = 1; i < ids.size(); i++) { + Long id =Long.parseLong(ids.get(i)) ; + SetmealEntity setmeal = this.selectById(id); + setmeal.setStatus(index); + this.updateById(setmeal); + } + }else { + Long id =Long.parseLong(ids.get(0)) ; + SetmealEntity setmeal = this.selectById(id); + log.info("SetmealEntity111={}",setmeal); + if (setmeal.getStatus().equals(1)){ + setmeal.setStatus(0); + this.updateById(setmeal); + } + else { + setmeal.setStatus(1); + this.updateById(setmeal); + } + log.info("SetmealEntity222={}",setmeal); + } + } } \ No newline at end of file diff --git a/renren-admin/src/main/resources/application.yml b/renren-admin/src/main/resources/application.yml index 45a4b52..8b03c27 100644 --- a/renren-admin/src/main/resources/application.yml +++ b/renren-admin/src/main/resources/application.yml @@ -7,6 +7,7 @@ server: min-spare: 30 port: 8080 servlet: +# context-path: /renren-admin context-path: /api session: cookie: