package com.zt.life.core.controller;
|
|
import com.zt.common.annotation.LogOperation;
|
import com.zt.common.servlet.Result;
|
import com.zt.common.validator.AssertUtils;
|
import com.zt.common.validator.ValidatorUtils;
|
import com.zt.common.validator.group.AddGroup;
|
import com.zt.common.validator.group.DefaultGroup;
|
import com.zt.common.validator.group.UpdateGroup;
|
import com.zt.life.core.dto.ProductDto;
|
import com.zt.life.core.dto.SearchNodesDto;
|
import com.zt.life.core.mapstruct.ZtProductMapper;
|
import com.zt.life.core.model.Product;
|
import com.zt.life.core.model.ZtProduct;
|
import com.zt.life.core.service.ZtProductService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
|
/**
|
* CORE_PRODUCT
|
*
|
* @author zt generator
|
* @since 1.0.0 2020-07-15
|
*/
|
|
@RestController
|
@RequestMapping("/ztProduct")
|
@Api(tags = "CORE_PRODUCT")
|
public class ZtProductController {
|
@Autowired
|
private ZtProductService productService;
|
@Autowired
|
private ZtProductMapper productMapper;
|
|
@GetMapping("tree")
|
@ApiOperation("树形结构")
|
public Result<List<ZtProduct>> tree(
|
@RequestParam(value = "parentId", required = false, defaultValue = "0") Long parentId) {
|
List<ZtProduct> list = this.productService.getProductTree(parentId);
|
return Result.ok(list);
|
}
|
|
@GetMapping("treeSelect")
|
@ApiOperation("树形结构")
|
public Result<List<ZtProduct>> treeSelect(
|
@RequestParam(value = "parentIds", required = false, defaultValue = "0") String parentIds,
|
@RequestParam(value = "showLevel", required = false, defaultValue = "equipment") String showLevel) {
|
List<ZtProduct> list = this.productService.getProductTree(parentIds, showLevel);
|
//List<ProductDto> result= productMapper.toDto(list);
|
return Result.ok(list);
|
}
|
|
@GetMapping("getTreeNodes")
|
@ApiOperation("树节点列表")
|
Result<List<ZtProduct>> getTreeNodes(String pid){
|
List<ZtProduct> list = this.productService.getTreeNodes(pid);
|
return Result.ok(list);
|
}
|
|
@GetMapping("searchNodes")
|
@ApiOperation("树节点列表")
|
Result<List<SearchNodesDto>> searchNodes(String pid, String name){
|
List<SearchNodesDto> list = this.productService.searchNodes(pid,name);
|
return Result.ok(list);
|
}
|
|
@GetMapping("getShipList")
|
@ApiOperation("獲取X号")
|
public Result<List<ProductDto>> getShipList(String area) {
|
List<ZtProduct> list = this.productService.getShipList(area);
|
return Result.ok(productMapper.toDto(list));
|
}
|
@GetMapping("getSubList")
|
@ApiOperation("子节点列表")
|
public Result<List<ProductDto>> getSubList(String pid) {
|
List<ZtProduct> list = this.productService.getSubList(pid);
|
return Result.ok(productMapper.toDto(list));
|
}
|
|
@GetMapping("getListByIds")
|
@ApiOperation("列表")
|
public Result<List<ProductDto>> getListByIds(String ids) {
|
List<ZtProduct> list = this.productService.getListByIds(ids);
|
return Result.ok(productMapper.toDto(list));
|
}
|
@GetMapping("{id}")
|
@ApiOperation("信息")
|
public Result<ZtProduct> get(@PathVariable("id") Long id) {
|
ZtProduct data = productService.get(id);
|
|
return Result.ok(data);
|
}
|
|
@GetMapping("getByProductId")
|
@ApiOperation("根据productId获取信息")
|
public Result<ZtProduct> getByProductId(Long productId) {
|
ZtProduct data = productService.getByProductId(productId);
|
return Result.ok(data);
|
}
|
|
@PostMapping
|
@ApiOperation("新增")
|
@LogOperation("新增")
|
public Result insert(@RequestBody ZtProduct productTree) {
|
// 效验数据
|
ValidatorUtils.validateEntity(productTree, AddGroup.class, DefaultGroup.class);
|
productService.insert(productTree);
|
|
return Result.ok();
|
}
|
|
@PutMapping
|
@ApiOperation("修改")
|
@LogOperation("修改")
|
public Result update(@RequestBody ZtProduct productTree) {
|
// 效验数据
|
ValidatorUtils.validateEntity(productTree, UpdateGroup.class, DefaultGroup.class);
|
productService.update(productTree);
|
|
return Result.ok();
|
}
|
|
@DeleteMapping
|
@ApiOperation("删除")
|
@LogOperation("删除")
|
public Result delete(@RequestBody Long[] ids) {
|
// 效验数据
|
AssertUtils.isArrayEmpty(ids, "id");
|
productService.deleteLogic(ids);
|
|
return Result.ok();
|
}
|
|
@GetMapping("getModelList")
|
@ApiOperation("型号列表")
|
public Result<List<ZtProduct>> getModelList() {
|
List<ZtProduct> data = productService.getLevelList("model");
|
return Result.ok(data);
|
}
|
|
}
|