demo模块案例v1

ccongli-dev-0811
LI-CCONG\李聪聪 1 year ago
parent 07a0553e03
commit d4ee54b27b

10
node_modules/.yarn-integrity generated vendored

@ -0,0 +1,10 @@
{
"systemParams": "win32-x64-93",
"modulesFolders": [],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}

@ -23,6 +23,7 @@
<!-- <module>yunxi-module-mall</module>-->
<!-- 示例项目 -->
<module>yunxi-example</module>
<module>yunxi-module-demo</module>
</modules>
<name>${project.artifactId}</name>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunxi</artifactId>
<groupId>com.yunxi.scm</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yunxi-module-demo</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>
demo 模块,主要实现 XXX、YYY、ZZZ 等功能。
</description>
<modules>
<module>yunxi-module-demo-api</module>
<module>yunxi-module-demo-biz</module>
</modules>
</project>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunxi-module-demo</artifactId>
<groupId>com.yunxi.scm</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yunxi-module-demo-api</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
demo 模块 API暴露给其它模块调用
</description>
<!-- 新增 yudao-common 依赖 -->
<dependencies>
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-common</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,18 @@
package com.yunxi.scm.module.demo.enums;
/**
* System
*
* @author
*/
public interface DictTypeConstants {
String USER_TYPE = "user_type"; // 用户类型
String COMMON_STATUS = "common_status"; // 系统状态
String MATERIAL_STATUS = "material_status"; // 物料状态
// ========== SYSTEM 模块 ==========
String TRADE_ORDER_TYPE = "trade_order_type"; // 订单交易类型
}

@ -0,0 +1,9 @@
// TODO 待办:请将下面的错误码复制到 yunxi-module-demo-api 模块的 ErrorCodeConstants 类中。注意请给“TODO 补充编号”设置一个错误码编号!!!
// ========== 物料管理 TODO 补充编号 ==========
package com.yunxi.scm.module.demo.enums;
import com.yunxi.scm.framework.common.exception.ErrorCode;
public interface ErrorCodeConstants {
ErrorCode MATERIAL_NOT_EXISTS = new ErrorCode(2023091001, "物料管理不存在");
}

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunxi-module-demo</artifactId>
<groupId>com.yunxi.scm</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>yunxi-module-demo-biz</artifactId>
<name>${project.artifactId}</name>
<description>
demo 模块,主要实现 XXX、YYY、ZZZ 等功能。
</description>
<!-- 新增依赖,这里引入的都是比较常用的业务组件、技术组件 -->
<dependencies>
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-module-demo-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-biz-operatelog</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-security</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-mybatis</artifactId>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-test</artifactId>
</dependency>
<!-- Excel 相关 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-spring-boot-starter-excel</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,28 @@
package com.yunxi.scm.module.demo.controller.admin;
import com.yunxi.scm.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.security.PermitAll;
import static com.yunxi.scm.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - Test")
@RestController
@RequestMapping("/demo/test")
@Validated
public class DemoTestController {
@GetMapping("/get")
@Operation(summary = "获取 test 信息")
@PermitAll // 无需认证即可访问
public CommonResult<String> get() {
return success("无需认证即可访问的后台接口");
}
}

@ -0,0 +1,102 @@
package com.yunxi.scm.module.demo.controller.admin.material;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import com.yunxi.scm.framework.common.pojo.PageResult;
import com.yunxi.scm.framework.common.pojo.CommonResult;
import static com.yunxi.scm.framework.common.pojo.CommonResult.success;
import com.yunxi.scm.framework.excel.core.util.ExcelUtils;
import com.yunxi.scm.framework.operatelog.core.annotations.OperateLog;
import static com.yunxi.scm.framework.operatelog.core.enums.OperateTypeEnum.*;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
import com.yunxi.scm.module.demo.convert.material.MaterialConvert;
import com.yunxi.scm.module.demo.service.material.MaterialService;
@Tag(name = "管理后台 - 物料管理")
@RestController
@RequestMapping("/demo/material")
@Validated
public class MaterialController {
@Resource
private MaterialService materialService;
@PostMapping("/create")
@Operation(summary = "创建物料管理")
@PreAuthorize("@ss.hasPermission('demo:material:create')")
public CommonResult<Long> createMaterial(@Valid @RequestBody MaterialCreateReqVO createReqVO) {
return success(materialService.createMaterial(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新物料管理")
@PreAuthorize("@ss.hasPermission('demo:material:update')")
public CommonResult<Boolean> updateMaterial(@Valid @RequestBody MaterialUpdateReqVO updateReqVO) {
materialService.updateMaterial(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除物料管理")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('demo:material:delete')")
public CommonResult<Boolean> deleteMaterial(@RequestParam("id") Long id) {
materialService.deleteMaterial(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得物料管理")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('demo:material:query')")
public CommonResult<MaterialRespVO> getMaterial(@RequestParam("id") Long id) {
MaterialDO material = materialService.getMaterial(id);
return success(MaterialConvert.INSTANCE.convert(material));
}
@GetMapping("/list")
@Operation(summary = "获得物料管理列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('demo:material:query')")
public CommonResult<List<MaterialRespVO>> getMaterialList(@RequestParam("ids") Collection<Long> ids) {
List<MaterialDO> list = materialService.getMaterialList(ids);
return success(MaterialConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得物料管理分页")
@PreAuthorize("@ss.hasPermission('demo:material:query')")
public CommonResult<PageResult<MaterialRespVO>> getMaterialPage(@Valid MaterialPageReqVO pageVO) {
PageResult<MaterialDO> pageResult = materialService.getMaterialPage(pageVO);
return success(MaterialConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出物料管理 Excel")
@PreAuthorize("@ss.hasPermission('demo:material:export')")
@OperateLog(type = EXPORT)
public void exportMaterialExcel(@Valid MaterialExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<MaterialDO> list = materialService.getMaterialList(exportReqVO);
// 导出 Excel
List<MaterialExcelVO> datas = MaterialConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "物料管理.xls", "数据", MaterialExcelVO.class, datas);
}
}

@ -0,0 +1,48 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class MaterialBaseVO {
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotNull(message = "名称不能为空")
private String name;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
private Byte status;
@Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "类型不能为空")
private Byte type;
@Schema(description = "分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1,2]")
@NotNull(message = "分类不能为空")
private List<Integer> category;
@Schema(description = "图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
@NotNull(message = "图片不能为空")
private String imgurl;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "库存数量不能为空")
private Integer stock;
@Schema(description = "单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "18.00")
@NotNull(message = "单价不能为空")
private BigDecimal price;
@Schema(description = "备注", example = "物料备注")
private String remark;
}

@ -0,0 +1,14 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 物料管理创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MaterialCreateReqVO extends MaterialBaseVO {
}

@ -0,0 +1,55 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.yunxi.scm.framework.excel.core.annotations.DictFormat;
import com.yunxi.scm.framework.excel.core.convert.DictConvert;
import com.yunxi.scm.module.demo.enums.DictTypeConstants;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* Excel VO
*
* @author ccongli
*/
@Data
public class MaterialExcelVO {
@ExcelProperty("ID")
private Long id;
@ExcelProperty("名称")
private String name;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.MATERIAL_STATUS)
private Byte status;
@ExcelProperty("类型")
@DictFormat(DictTypeConstants.TRADE_ORDER_TYPE)
private Byte type;
@ExcelProperty("分类")
@DictFormat(DictTypeConstants.TRADE_ORDER_TYPE)
private List<Integer> category;
@ExcelProperty("图片")
private String imgurl;
@ExcelProperty("库存数量")
private Integer stock;
@ExcelProperty("单价")
private BigDecimal price;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,32 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import java.util.List;
import static com.yunxi.scm.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 物料管理 Excel 导出 Request VO参数和 MaterialPageReqVO 是一致的")
@Data
public class MaterialExportReqVO {
@Schema(description = "名称", example = "李四")
private String name;
@Schema(description = "状态", example = "1")
private Byte status;
@Schema(description = "类型", example = "2")
private Byte type;
@Schema(description = "分类")
private List<Integer> category;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,37 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import com.yunxi.scm.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import java.util.List;
import static com.yunxi.scm.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 物料管理分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MaterialPageReqVO extends PageParam {
@Schema(description = "名称", example = "李四")
private String name;
@Schema(description = "状态", example = "1")
private Byte status;
@Schema(description = "类型", example = "2")
private Byte type;
@Schema(description = "分类", example = "[1,2]")
private List<Integer> category;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,19 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 物料管理 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MaterialRespVO extends MaterialBaseVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14541")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

@ -0,0 +1,18 @@
package com.yunxi.scm.module.demo.controller.admin.material.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 物料管理更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MaterialUpdateReqVO extends MaterialBaseVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14541")
@NotNull(message = "ID不能为空")
private Long id;
}

@ -0,0 +1,27 @@
package com.yunxi.scm.module.demo.controller.app;
import com.yunxi.scm.framework.common.pojo.CommonResult;
import com.yunxi.scm.framework.security.core.annotations.PreAuthenticated;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.yunxi.scm.framework.common.pojo.CommonResult.success;
@Tag(name = "用户 App - Test")
@RestController
@RequestMapping("/demo/test")
@Validated
public class AppDemoTestController {
@GetMapping("/get")
@Operation(summary = "获取 test 信息")
@PreAuthenticated // 认证后可访问
public CommonResult<String> get() {
return success("需认证后才能访问的app接口");
}
}

@ -0,0 +1,34 @@
package com.yunxi.scm.module.demo.convert.material;
import java.util.*;
import com.yunxi.scm.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
/**
* Convert
*
* @author ccongli
*/
@Mapper
public interface MaterialConvert {
MaterialConvert INSTANCE = Mappers.getMapper(MaterialConvert.class);
MaterialDO convert(MaterialCreateReqVO bean);
MaterialDO convert(MaterialUpdateReqVO bean);
MaterialRespVO convert(MaterialDO bean);
List<MaterialRespVO> convertList(List<MaterialDO> list);
PageResult<MaterialRespVO> convertPage(PageResult<MaterialDO> page);
List<MaterialExcelVO> convertList02(List<MaterialDO> list);
}

@ -0,0 +1,71 @@
package com.yunxi.scm.module.demo.dal.dataobject.material;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yunxi.scm.framework.mybatis.core.dataobject.BaseDO;
import com.yunxi.scm.framework.mybatis.core.type.IntegerListTypeHandler;
import lombok.*;
import java.math.BigDecimal;
import java.util.List;
/**
* DO
*
* @author ccongli
*/
@TableName(value = "demo_material",autoResultMap = true)
@KeySequence("demo_material_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MaterialDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
*
*/
private String name;
/**
*
*
* {@link TODO material_status }
*/
private Byte status;
/**
*
*/
private Byte type;
/**
*
*/
// @TableField(typeHandler = JacksonTypeHandler.class)
@TableField(typeHandler = IntegerListTypeHandler.class)
private List<Integer> category;
/**
*
*/
private String imgurl;
/**
*
*/
private Integer stock;
/**
*
*/
private BigDecimal price;
/**
*
*/
private String remark;
}

@ -0,0 +1,40 @@
package com.yunxi.scm.module.demo.dal.mysql.material;
import java.util.*;
import com.yunxi.scm.framework.common.pojo.PageResult;
import com.yunxi.scm.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yunxi.scm.framework.mybatis.core.mapper.BaseMapperX;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
import org.apache.ibatis.annotations.Mapper;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
/**
* Mapper
*
* @author ccongli
*/
@Mapper
public interface MaterialMapper extends BaseMapperX<MaterialDO> {
default PageResult<MaterialDO> selectPage(MaterialPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MaterialDO>()
.likeIfPresent(MaterialDO::getName, reqVO.getName())
.eqIfPresent(MaterialDO::getStatus, reqVO.getStatus())
.eqIfPresent(MaterialDO::getType, reqVO.getType())
.eqIfPresent(MaterialDO::getCategory, reqVO.getCategory())
.betweenIfPresent(MaterialDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MaterialDO::getId));
}
default List<MaterialDO> selectList(MaterialExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<MaterialDO>()
.likeIfPresent(MaterialDO::getName, reqVO.getName())
.eqIfPresent(MaterialDO::getStatus, reqVO.getStatus())
.eqIfPresent(MaterialDO::getType, reqVO.getType())
.eqIfPresent(MaterialDO::getCategory, reqVO.getCategory())
.betweenIfPresent(MaterialDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MaterialDO::getId));
}
}

@ -0,0 +1,70 @@
package com.yunxi.scm.module.demo.service.material;
import java.util.*;
import javax.validation.*;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
import com.yunxi.scm.framework.common.pojo.PageResult;
/**
* Service
*
* @author ccongli
*/
public interface MaterialService {
/**
*
*
* @param createReqVO
* @return
*/
Long createMaterial(@Valid MaterialCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateMaterial(@Valid MaterialUpdateReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteMaterial(Long id);
/**
*
*
* @param id
* @return
*/
MaterialDO getMaterial(Long id);
/**
*
*
* @param ids
* @return
*/
List<MaterialDO> getMaterialList(Collection<Long> ids);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<MaterialDO> getMaterialPage(MaterialPageReqVO pageReqVO);
/**
* , Excel
*
* @param exportReqVO
* @return
*/
List<MaterialDO> getMaterialList(MaterialExportReqVO exportReqVO);
}

@ -0,0 +1,82 @@
package com.yunxi.scm.module.demo.service.material;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
import com.yunxi.scm.framework.common.pojo.PageResult;
import com.yunxi.scm.module.demo.convert.material.MaterialConvert;
import com.yunxi.scm.module.demo.dal.mysql.material.MaterialMapper;
import static com.yunxi.scm.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yunxi.scm.module.demo.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author ccongli
*/
@Service
@Validated
public class MaterialServiceImpl implements MaterialService {
@Resource
private MaterialMapper materialMapper;
@Override
public Long createMaterial(MaterialCreateReqVO createReqVO) {
// 插入
MaterialDO material = MaterialConvert.INSTANCE.convert(createReqVO);
materialMapper.insert(material);
// 返回
return material.getId();
}
@Override
public void updateMaterial(MaterialUpdateReqVO updateReqVO) {
// 校验存在
validateMaterialExists(updateReqVO.getId());
// 更新
MaterialDO updateObj = MaterialConvert.INSTANCE.convert(updateReqVO);
materialMapper.updateById(updateObj);
}
@Override
public void deleteMaterial(Long id) {
// 校验存在
validateMaterialExists(id);
// 删除
materialMapper.deleteById(id);
}
private void validateMaterialExists(Long id) {
if (materialMapper.selectById(id) == null) {
throw exception(MATERIAL_NOT_EXISTS);
}
}
@Override
public MaterialDO getMaterial(Long id) {
return materialMapper.selectById(id);
}
@Override
public List<MaterialDO> getMaterialList(Collection<Long> ids) {
return materialMapper.selectBatchIds(ids);
}
@Override
public PageResult<MaterialDO> getMaterialPage(MaterialPageReqVO pageReqVO) {
return materialMapper.selectPage(pageReqVO);
}
@Override
public List<MaterialDO> getMaterialList(MaterialExportReqVO exportReqVO) {
return materialMapper.selectList(exportReqVO);
}
}

@ -0,0 +1,12 @@
<?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.yunxi.scm.module.demo.dal.mysql.material.MaterialMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

@ -0,0 +1,183 @@
package com.yunxi.scm.module.demo.service.material;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import com.yunxi.scm.framework.test.core.ut.BaseDbUnitTest;
import com.yunxi.scm.module.demo.controller.admin.material.vo.*;
import com.yunxi.scm.module.demo.dal.dataobject.material.MaterialDO;
import com.yunxi.scm.module.demo.dal.mysql.material.MaterialMapper;
import com.yunxi.scm.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static com.yunxi.scm.module.demo.enums.ErrorCodeConstants.*;
import static com.yunxi.scm.framework.test.core.util.AssertUtils.*;
import static com.yunxi.scm.framework.test.core.util.RandomUtils.*;
import static com.yunxi.scm.framework.common.util.date.LocalDateTimeUtils.*;
import static com.yunxi.scm.framework.common.util.object.ObjectUtils.*;
import static com.yunxi.scm.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link MaterialServiceImpl}
*
* @author ccongli
*/
@Import(MaterialServiceImpl.class)
public class MaterialServiceImplTest extends BaseDbUnitTest {
@Resource
private MaterialServiceImpl materialService;
@Resource
private MaterialMapper materialMapper;
@Test
public void testCreateMaterial_success() {
// 准备参数
MaterialCreateReqVO reqVO = randomPojo(MaterialCreateReqVO.class);
// 调用
Long materialId = materialService.createMaterial(reqVO);
// 断言
assertNotNull(materialId);
// 校验记录的属性是否正确
MaterialDO material = materialMapper.selectById(materialId);
assertPojoEquals(reqVO, material);
}
@Test
public void testUpdateMaterial_success() {
// mock 数据
MaterialDO dbMaterial = randomPojo(MaterialDO.class);
materialMapper.insert(dbMaterial);// @Sql: 先插入出一条存在的数据
// 准备参数
MaterialUpdateReqVO reqVO = randomPojo(MaterialUpdateReqVO.class, o -> {
o.setId(dbMaterial.getId()); // 设置更新的 ID
});
// 调用
materialService.updateMaterial(reqVO);
// 校验是否更新正确
MaterialDO material = materialMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, material);
}
@Test
public void testUpdateMaterial_notExists() {
// 准备参数
MaterialUpdateReqVO reqVO = randomPojo(MaterialUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> materialService.updateMaterial(reqVO), MATERIAL_NOT_EXISTS);
}
@Test
public void testDeleteMaterial_success() {
// mock 数据
MaterialDO dbMaterial = randomPojo(MaterialDO.class);
materialMapper.insert(dbMaterial);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbMaterial.getId();
// 调用
materialService.deleteMaterial(id);
// 校验数据不存在了
assertNull(materialMapper.selectById(id));
}
@Test
public void testDeleteMaterial_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> materialService.deleteMaterial(id), MATERIAL_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetMaterialPage() {
// mock 数据
MaterialDO dbMaterial = randomPojo(MaterialDO.class, o -> { // 等会查询到
o.setName(null);
o.setStatus(null);
o.setType(null);
o.setCategory(null);
o.setCreateTime(null);
});
materialMapper.insert(dbMaterial);
// 测试 name 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setName(null)));
// 测试 status 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setStatus(null)));
// 测试 type 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setType(null)));
// 测试 category 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setCategory(null)));
// 测试 createTime 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setCreateTime(null)));
// 准备参数
MaterialPageReqVO reqVO = new MaterialPageReqVO();
reqVO.setName(null);
reqVO.setStatus(null);
reqVO.setType(null);
reqVO.setCategory(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<MaterialDO> pageResult = materialService.getMaterialPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbMaterial, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetMaterialList() {
// mock 数据
MaterialDO dbMaterial = randomPojo(MaterialDO.class, o -> { // 等会查询到
o.setName(null);
o.setStatus(null);
o.setType(null);
o.setCategory(null);
o.setCreateTime(null);
});
materialMapper.insert(dbMaterial);
// 测试 name 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setName(null)));
// 测试 status 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setStatus(null)));
// 测试 type 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setType(null)));
// 测试 category 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setCategory(null)));
// 测试 createTime 不匹配
materialMapper.insert(cloneIgnoreId(dbMaterial, o -> o.setCreateTime(null)));
// 准备参数
MaterialExportReqVO reqVO = new MaterialExportReqVO();
reqVO.setName(null);
reqVO.setStatus(null);
reqVO.setType(null);
reqVO.setCategory(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<MaterialDO> list = materialService.getMaterialList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbMaterial, list.get(0));
}
}

@ -0,0 +1,2 @@
-- SQL yunxi-module-demo-biz test/resources/sql/clean.sql
DELETE FROM "demo_material";

@ -0,0 +1,19 @@
-- SQL yunxi-module-demo-biz test/resources/sql/create_tables.sql
CREATE TABLE IF NOT EXISTS "demo_material" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar NOT NULL,
"status" varchar NOT NULL,
"type" varchar NOT NULL,
"category" varchar NOT NULL,
"imgurl" varchar NOT NULL,
"stock" int NOT NULL,
"price" varchar NOT NULL,
"remark" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '';

@ -0,0 +1,55 @@
-- SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status, component_name
)
VALUES (
'', '', 2, 0, 1,
'material', '', 'demo/material/index', 0, 'Material'
);
-- ID
-- MySQL OraclePostgreSQLSQLServer @parentId
SELECT @parentId := LAST_INSERT_ID();
-- SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'', 'demo:material:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'', 'demo:material:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'', 'demo:material:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'', 'demo:material:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'', 'demo:material:export', 3, 5, @parentId,
'', '', '', 0
);

@ -41,6 +41,13 @@
<artifactId>yunxi-spring-boot-starter-biz-error-code</artifactId>
</dependency>
<!-- 引入demo业务模块 -->
<dependency>
<groupId>com.yunxi.scm</groupId>
<artifactId>yunxi-module-demo-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- 数据报表 -->
<!-- <dependency>-->
<!-- <groupId>com.yunxi.scm</groupId>-->

@ -1,5 +1,5 @@
server:
port: 48080
port: 8091
--- #################### 数据库相关配置 ####################
@ -44,24 +44,24 @@ spring:
primary: master
datasource:
master:
name: ruoyi-vue-pro
name: yxscm
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例
username: root
username: yxscm
password: 123456
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
slave: # 模拟从库,可根据自己需要修改
name: ruoyi-vue-pro
name: yxscm
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例
username: root
username: yxscm
password: 123456
# username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
@ -159,6 +159,7 @@ logging:
com.yunxi.scm.module.member.dal.mysql: debug
com.yunxi.scm.module.trade.dal.mysql: debug
com.yunxi.scm.module.promotion.dal.mysql: debug
com.yunxi.scm.module.demo.dal.mysql: debug # demo模块 MyBatis 操作日志
debug: false

@ -3,7 +3,7 @@ spring:
name: yunxi-server
profiles:
active: dev
active: local
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。

@ -0,0 +1,54 @@
import request from '@/utils/request'
// 创建物料管理
export function createMaterial(data) {
return request({
url: '/demo/material/create',
method: 'post',
data: data
})
}
// 更新物料管理
export function updateMaterial(data) {
return request({
url: '/demo/material/update',
method: 'put',
data: data
})
}
// 删除物料管理
export function deleteMaterial(id) {
return request({
url: '/demo/material/delete?id=' + id,
method: 'delete'
})
}
// 获得物料管理
export function getMaterial(id) {
return request({
url: '/demo/material/get?id=' + id,
method: 'get'
})
}
// 获得物料管理分页
export function getMaterialPage(query) {
return request({
url: '/demo/material/page',
method: 'get',
params: query
})
}
// 导出物料管理 Excel
export function exportMaterialExcel(query) {
return request({
url: '/demo/material/export-excel',
method: 'get',
params: query,
responseType: 'blob'
})
}

@ -139,3 +139,8 @@ input, textarea{
.el-upload__tip{
line-height: 1.2;
}
//
.multi_tags{
margin: 5px !important;
}

@ -81,6 +81,9 @@ export const DICT_TYPE = {
PROMOTION_COUPON_TAKE_TYPE: 'promotion_coupon_take_type', // 优惠劵的领取方式
PROMOTION_ACTIVITY_STATUS: 'promotion_activity_status', // 优惠活动的状态
PROMOTION_CONDITION_TYPE: 'promotion_condition_type', // 营销的条件类型枚举
// ============= DEMO 模块=================
MATERIAL_STATUS: 'material_status', // 物料状态
}
/**

@ -0,0 +1,300 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名称" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.MATERIAL_STATUS)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<el-form-item label="类型" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.TRADE_ORDER_TYPE)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
<!-- <el-form-item label="分类" prop="category">-->
<!-- <el-select v-model="queryParams.category" placeholder="请选择分类" clearable size="small">-->
<!-- <el-option v-for="dict in this.getDictDatas(DICT_TYPE.TRADE_ORDER_TYPE)"-->
<!-- :key="dict.value" :label="dict.label" :value="dict.value"/>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="创建时间" prop="createTime">
<el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['demo:material:create']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
v-hasPermi="['demo:material:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<el-table-column label="ID" align="center" prop="id" />
<el-table-column label="名称" align="center" prop="name" />
<el-table-column label="状态" align="center" prop="status">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.MATERIAL_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="类型" align="center" prop="type">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.TRADE_ORDER_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="分类" align="center" prop="category">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.TRADE_ORDER_TYPE" :value="scope.row.category" />
</template>
</el-table-column>
<el-table-column label="图片" align="center" prop="imgurl">
<template v-slot="scope">
<image-preview :src="scope.row.imgurl" :width="'100px'"></image-preview>
</template>
</el-table-column>
<el-table-column label="库存数量" align="center" prop="stock" />
<el-table-column label="单价" align="center" prop="price" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template v-slot="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template v-slot="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['demo:material:update']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['demo:material:delete']">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" placeholder="请输入名称" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.MATERIAL_STATUS)"
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="类型" prop="type">
<el-select v-model="form.type" placeholder="请选择类型" clearable>
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.TRADE_ORDER_TYPE)"
:key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
</el-select>
</el-form-item>
<el-form-item label="分类" prop="category">
<el-select v-model="form.category" placeholder="请选择分类(多选)" multiple clearable>
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.TRADE_ORDER_TYPE)"
:key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
</el-select>
</el-form-item>
<el-form-item label="图片">
<imageUpload v-model="form.imgurl"/>
</el-form-item>
<el-form-item label="库存数量" prop="stock">
<el-input v-model="form.stock" placeholder="请输入库存数量" />
</el-form-item>
<el-form-item label="单价" prop="price">
<el-input v-model="form.price" placeholder="请输入单价" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { createMaterial, updateMaterial, deleteMaterial, getMaterial, getMaterialPage, exportMaterialExcel } from "@/api/demo/material";
import ImageUpload from '@/components/ImageUpload';
import ImagePreview from "@/components/ImagePreview";
export default {
name: "Material",
components: {
ImageUpload,
ImagePreview
},
data() {
return {
//
loading: true,
//
exportLoading: false,
//
showSearch: true,
//
total: 0,
//
list: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNo: 1,
pageSize: 10,
name: null,
status: null,
type: null,
category: null,
createTime: [],
},
//
form: {},
//
rules: {
name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
type: [{ required: true, message: "类型不能为空", trigger: "change" }],
category: [{ required: true, message: "分类不能为空", trigger: "change", type: "array"}],
imgurl: [{ required: true, message: "图片不能为空", trigger: "blur" }],
stock: [{ required: true, message: "库存数量不能为空", trigger: "blur" }],
price: [{ required: true, message: "单价不能为空", trigger: "blur" }],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询列表 */
getList() {
this.loading = true;
//
getMaterialPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
/** 表单重置 */
reset() {
this.form = {
id: undefined,
name: undefined,
status: undefined,
type: undefined,
category: undefined,
imgurl: undefined,
stock: undefined,
price: undefined,
remark: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNo = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加物料管理";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id;
getMaterial(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改物料管理";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
//
if (this.form.id != null) {
updateMaterial(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
return;
}
//
createMaterial(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除物料管理编号为"' + id + '"的数据项?').then(function() {
return deleteMaterial(id);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
//
let params = {...this.queryParams};
params.pageNo = undefined;
params.pageSize = undefined;
this.$modal.confirm('是否确认导出所有物料管理数据项?').then(() => {
this.exportLoading = true;
return exportMaterialExcel(params);
}).then(response => {
this.$download.excel(response, '物料管理.xls');
this.exportLoading = false;
}).catch(() => {});
}
}
};
</script>
Loading…
Cancel
Save