This commit is contained in:
caixiang 2022-06-22 09:14:03 +08:00
parent 0806c22316
commit 342f843f2c
8 changed files with 368 additions and 0 deletions

View File

@ -0,0 +1,116 @@
package com.cnbm.generator.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.cnbm.generator.dto.ProductTypeDTO;
import com.cnbm.generator.excel.ProductTypeExcel;
import com.cnbm.generator.service.IProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 产品类型 前端控制器
*
* @author why
* @since 2022-06-21
*/
@RestController
@RequestMapping("/generator/productType")
@Api(tags="产品类型 表")
public class ProductTypeController {
@Autowired
private IProductTypeService productTypeService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
@PreAuthorize("@ex.hasAuthority('generator:productType:page')")
public Result<PageData<ProductTypeDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<ProductTypeDTO> page = productTypeService.page(params);
return new Result<PageData<ProductTypeDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('generator:productType:info')")
public Result<ProductTypeDTO> get(@PathVariable("id") Long id){
ProductTypeDTO data = productTypeService.get(id);
return new Result<ProductTypeDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('generator:productType:save')")
public Result save(@RequestBody ProductTypeDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
productTypeService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('generator:productType:update')")
public Result update(@RequestBody ProductTypeDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
productTypeService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('generator:productType:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
productTypeService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@PreAuthorize("@ex.hasAuthority('generator:productType:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<ProductTypeDTO> list = productTypeService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, ProductTypeExcel.class);
}
}

View File

@ -0,0 +1,67 @@
package com.cnbm.generator.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 产品类型
*
* @author why
* @since 2022-06-21
*/
@Data
@ApiModel(value = "产品类型 表DTO对象")
public class ProductTypeDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID")
private BigDecimal id;
@ApiModelProperty(value = "产品类型 名")
private String name;
@ApiModelProperty(value = "产品类型 编码")
private String code;
@ApiModelProperty(value = "描述")
private String desc;
@ApiModelProperty(value = "1 可用0 不可用")
private BigDecimal status;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "删除标志,是否有效:1 可用 0不可用")
private BigDecimal valid;
@ApiModelProperty(value = "创建人")
private BigDecimal creatorId;
@ApiModelProperty(value = "创建人姓名")
private String creatorName;
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "更新人")
private BigDecimal updaterId;
@ApiModelProperty(value = "更新人姓名")
private String updaterName;
@ApiModelProperty(value = "更新时间")
private LocalDateTime updateTime;
@ApiModelProperty(value = "版本号")
private BigDecimal version;
}

View File

@ -0,0 +1,69 @@
package com.cnbm.generator.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
* 产品类型
* </p>
*
* @author why
* @since 2022-06-21
*/
@Data
@TableName("product_type")
@ApiModel(value = "ProductType对象", description = "产品类型 表")
public class ProductType implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("ID")
private BigDecimal id;
@ApiModelProperty("产品类型 名")
private String name;
@ApiModelProperty("产品类型 编码")
private String code;
@ApiModelProperty("描述")
private String desc;
@ApiModelProperty("1 可用0 不可用")
private BigDecimal status;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("删除标志,是否有效:1 可用 0不可用")
private BigDecimal valid;
@ApiModelProperty("创建人")
private BigDecimal creatorId;
@ApiModelProperty("创建人姓名")
private String creatorName;
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
@ApiModelProperty("更新人")
private BigDecimal updaterId;
@ApiModelProperty("更新人姓名")
private String updaterName;
@ApiModelProperty("更新时间")
private LocalDateTime updateTime;
@ApiModelProperty("版本号")
private BigDecimal version;
}

View File

@ -0,0 +1,46 @@
package com.cnbm.generator.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
/**
* 产品类型
*
* @author why
* @since 2022-06-21
*/
@Data
public class ProductTypeExcel {
@Excel(name = "ID")
private BigDecimal id;
@Excel(name = "产品类型 名")
private String name;
@Excel(name = "产品类型 编码")
private String code;
@Excel(name = "描述")
private String desc;
@Excel(name = "1 可用0 不可用")
private BigDecimal status;
@Excel(name = "备注")
private String remark;
@Excel(name = "删除标志,是否有效:1 可用 0不可用")
private BigDecimal valid;
@Excel(name = "创建人")
private BigDecimal creatorId;
@Excel(name = "创建人姓名")
private String creatorName;
@Excel(name = "创建时间")
private LocalDateTime createTime;
@Excel(name = "更新人")
private BigDecimal updaterId;
@Excel(name = "更新人姓名")
private String updaterName;
@Excel(name = "更新时间")
private LocalDateTime updateTime;
@Excel(name = "版本号")
private BigDecimal version;
}

View File

@ -0,0 +1,16 @@
package com.cnbm.generator.mapper;
import com.cnbm.common.dao.BaseDao;
import com.cnbm.generator.entity.ProductType;
import org.apache.ibatis.annotations.Mapper;
/**
* 产品类型
*
* @author why
* @since 2022-06-21
*/
@Mapper
public interface ProductTypeMapper extends BaseDao<ProductType> {
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cnbm.generator.mapper.ProductTypeMapper">
</mapper>

View File

@ -0,0 +1,15 @@
package com.cnbm.generator.service;
import com.cnbm.common.service.CrudService;
import com.cnbm.generator.dto.ProductTypeDTO;
import com.cnbm.generator.entity.ProductType;
/**
* 产品类型
*
* @author why
* @since 2022-06-21
*/
public interface IProductTypeService extends CrudService<ProductType, ProductTypeDTO> {
}

View File

@ -0,0 +1,34 @@
package com.cnbm.generator.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnbm.common.service.impl.CrudServiceImpl;
import com.cnbm.generator.dto.ProductTypeDTO;
import com.cnbm.generator.mapper.ProductTypeMapper;
import com.cnbm.generator.entity.ProductType;
import com.cnbm.generator.service.IProductTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 产品类型
*
* @author why
* @since 2022-06-21
*/
@Service
public class ProductTypeServiceImpl extends CrudServiceImpl<ProductTypeMapper, ProductType, ProductTypeDTO> implements IProductTypeService {
@Override
public QueryWrapper<ProductType> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<ProductType> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}