| | |
| | | package com.jilongda.manage.controller; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.jilongda.common.basic.ApiResult; |
| | | import com.jilongda.common.basic.PageInfo; |
| | | import com.jilongda.manage.dto.TModelDTO; |
| | | import com.jilongda.manage.model.TModel; |
| | | import com.jilongda.manage.query.TModelQuery; |
| | | import com.jilongda.manage.service.TModelService; |
| | | import com.jilongda.manage.vo.TModelVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author 无关风月 |
| | | * @since 2024-12-09 |
| | | */ |
| | | @Api(tags = "镜架型号表") |
| | | @RestController |
| | | @RequestMapping("/t-model") |
| | | public class TModelController { |
| | | |
| | | @Autowired |
| | | private TModelService modelService; |
| | | |
| | | /** |
| | | * 获取镜架型号列表 |
| | | */ |
| | | @ApiOperation(value = "获取镜架型号分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public ApiResult<PageInfo<TModelVO>> pageList(@RequestBody TModelQuery query) { |
| | | return ApiResult.success(modelService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 通过品牌查询型号列表 |
| | | */ |
| | | @ApiOperation(value = "通过品牌id查询型号列表") |
| | | @GetMapping(value = "/getListByBrandId") |
| | | public ApiResult<List<TModel>> pageList(@RequestParam Integer brandId) { |
| | | List<TModel> list = modelService.list(Wrappers.lambdaQuery(TModel.class) |
| | | .eq(TModel::getBrandId, brandId) |
| | | .groupBy(TModel::getName)); |
| | | return ApiResult.success(list); |
| | | } |
| | | |
| | | /** |
| | | * 通过型号查询色号列表 |
| | | */ |
| | | @ApiOperation(value = "通过型号查询色号列表") |
| | | @GetMapping(value = "/getListByName") |
| | | public ApiResult<List<TModel>> pageList(@RequestParam String name) { |
| | | List<TModel> list = modelService.list(Wrappers.lambdaQuery(TModel.class) |
| | | .eq(TModel::getName, name)); |
| | | return ApiResult.success(list); |
| | | } |
| | | |
| | | /** |
| | | * 添加镜架型号 |
| | | */ |
| | | @ApiOperation(value = "添加镜架型号") |
| | | @PostMapping(value = "/add") |
| | | public ApiResult<String> add(@Validated @RequestBody TModelDTO dto) { |
| | | List<String> colorList = dto.getColorList(); |
| | | List<TModel> models = new ArrayList<>(); |
| | | for (String s : colorList) { |
| | | TModel model = new TModel(); |
| | | BeanUtils.copyProperties(dto, model); |
| | | model.setColor(s); |
| | | models.add(model); |
| | | } |
| | | modelService.saveBatch(models); |
| | | return ApiResult.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改镜架型号") |
| | | @PostMapping(value = "/update") |
| | | public ApiResult<String> update(@RequestBody TModelDTO dto) { |
| | | List<TModel> list = modelService.lambdaQuery() |
| | | .eq(TModel::getName, dto.getName()).list(); |
| | | List<String> colorList = dto.getColorList(); |
| | | if (list.size()<colorList.size()){ |
| | | for (int i = 0; i < colorList.size(); i++) { |
| | | if (i>list.size()-1){ |
| | | TModel model = new TModel(); |
| | | BeanUtils.copyProperties(dto, model); |
| | | model.setId(null); |
| | | model.setColor(colorList.get(i)); |
| | | list.add(model); |
| | | }else { |
| | | list.get(i).setColor(colorList.get(i)); |
| | | } |
| | | } |
| | | }else if (list.size()>colorList.size()){ |
| | | List<TModel> removeList = new ArrayList<>(); |
| | | List<TModel> updateList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (i<colorList.size()){ |
| | | updateList.add(list.get(i)); |
| | | list.get(i).setColor(colorList.get(i)); |
| | | }else { |
| | | removeList.add(list.get(i)); |
| | | } |
| | | } |
| | | list = updateList; |
| | | modelService.removeByIds(removeList.stream().map(TModel::getId) |
| | | .collect(Collectors.toList())); |
| | | }else { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | list.get(i).setColor(colorList.get(i)); |
| | | } |
| | | } |
| | | modelService.saveOrUpdateBatch(list); |
| | | // List<TModel> models = new ArrayList<>(); |
| | | // for (String s : colorList) { |
| | | // TModel model = new TModel(); |
| | | // BeanUtils.copyProperties(dto, model); |
| | | // model.setId(null); |
| | | // model.setColor(s); |
| | | // models.add(model); |
| | | // } |
| | | // modelService.saveBatch(models); |
| | | return ApiResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 镜架型号上下架 |
| | | */ |
| | | @ApiOperation(value = "镜架型号上下架--列表使用") |
| | | @GetMapping(value = "/upAndDown") |
| | | public ApiResult<Boolean> upAndDown(@RequestParam String name, |
| | | @RequestParam Integer status) { |
| | | return ApiResult.success(modelService.upAndDown(name,status)); |
| | | } |
| | | |
| | | /** |
| | | * 镜架型号上下架 |
| | | */ |
| | | @ApiOperation(value = "镜架型号上下架--修改界面使用") |
| | | @GetMapping(value = "/upAndDownColor") |
| | | public ApiResult<Boolean> upAndDownColor(@RequestParam String name, |
| | | @RequestParam String color, |
| | | @RequestParam Integer status) { |
| | | return ApiResult.success(modelService.upAndDownColor(name,color,status)); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除镜架型号") |
| | | @DeleteMapping(value = "/deleteByName") |
| | | public ApiResult<String> deleteById(@RequestParam String name) { |
| | | modelService.remove(Wrappers.lambdaQuery(TModel.class) |
| | | .eq(TModel::getName, name)); |
| | | return ApiResult.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "批量删除镜架型号") |
| | | @DeleteMapping(value = "/deleteByNames") |
| | | public ApiResult<String> deleteByIds(@RequestBody List<String> names) { |
| | | modelService.remove(Wrappers.lambdaQuery(TModel.class) |
| | | .in(TModel::getName, names)); |
| | | return ApiResult.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "查询镜架型号详情") |
| | | @GetMapping(value = "/getDetailByName") |
| | | public ApiResult<TModelVO> getDetailById(@RequestParam String name) { |
| | | List<TModel> models = modelService.list(Wrappers.lambdaQuery(TModel.class) |
| | | .eq(TModel::getName, name)); |
| | | TModelVO modelVO = new TModelVO(); |
| | | BeanUtils.copyProperties(models.get(0), modelVO); |
| | | List<String> colorList = models.stream().map(TModel::getColor).collect(Collectors.toList()); |
| | | modelVO.setColorList(colorList); |
| | | return ApiResult.success(modelVO); |
| | | } |
| | | |
| | | } |
| | | |