提交 b3121cfe 作者: xiaowang

新增:产品类型

上级 c461414e
package com.mmc.pms.controller.category;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.model.category.vo.ProductTypeVO;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import com.mmc.pms.service.category.ProductAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @Author LW
* @date 2023/8/5 10:35
* 概要:
*/
@RestController
@RequestMapping("/attribute")
@Api(tags = {"V1.0.3-产品属性-相关接口"})
public class ProductAttributeController {
@Resource
ProductAttributeService productAttributeService;
@ApiOperation(value = "类型新增")
@PostMapping("/addType")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody addType(@RequestBody @Validated(value = {Create.class}) ProductTypeVO param) {
return productAttributeService.addType(param);
}
@ApiOperation(value = "类型编辑")
@PostMapping("/editType")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody editType(@RequestBody @Validated(value = {Update.class}) ProductTypeVO param) {
return productAttributeService.editType(param);
}
@ApiOperation(value = "类型删除")
@GetMapping("/removeType")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody removeType(@RequestParam Integer id) {
return productAttributeService.removeType(id);
}
@ApiOperation(value = "类型详情")
@GetMapping("/typeDetails")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ProductTypeVO.class)})
public ResultBody<ProductTypeVO> typeDetails(@RequestParam Integer id) {
return productAttributeService.typeDetails(id);
}
@ApiOperation(value = "类型列表")
@GetMapping("/typeList")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ProductTypeVO.class)})
public ResultBody<ProductTypeVO> typeList(@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
return ResultBody.success(productAttributeService.typeList(pageNo, pageSize));
}
}
package com.mmc.pms.controller.lease;
/**
* @Author LW
* @date 2023/8/4 10:35
* 概要:
*/
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.controller.BaseController;
import com.mmc.pms.model.mall.MallGoodsVO;
import com.mmc.pms.service.lease.LeaseGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @Author LW
* @date 2023/7/24 16:56 概要:
*/
@RestController
@RequestMapping("/lease/goods")
@Api(tags = {"V1.0.3-租赁商品-相关接口"})
public class LeaseGoodsController extends BaseController {
@Resource
LeaseGoodsService leaseGoodsService;
@ApiOperation(value = "新增商城商品")
@PostMapping("addLeaseGoods")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody addLeaseGoods(@RequestBody MallGoodsVO mallGoodsVO, HttpServletRequest request) {
return null;
// return leaseGoodsService.addLeaseGoods(mallGoodsVO, this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
}
package com.mmc.pms.dao.category;
import com.mmc.pms.entity.category.ProductTypeDO;
import com.mmc.pms.model.category.vo.ProductTypeVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author LW
* @date 2023/8/5 10:44
* 概要:
*/
@Mapper
public interface ProductAttributeDao {
int countTypeByName(ProductTypeVO param);
void addType(ProductTypeVO param);
void editType(ProductTypeVO param);
void removeType(Integer id);
ProductTypeDO getType(Integer id);
int countType();
List<ProductTypeDO> listType(Integer pageNo, Integer pageSize);
}
package com.mmc.pms.dao.lease;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author LW
* @date 2023/8/4 10:38
* 概要:
*/
@Mapper
public interface LeaseGoodsDao {
}
package com.mmc.pms.entity.category;
import com.mmc.pms.model.category.vo.ProductTypeVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* (ProductTypeDO)实体类
*
* @author makejava
* @since 2023-08-05 14:21:20
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductTypeDO implements Serializable {
private static final long serialVersionUID = -18535389603045721L;
private Integer id;
private String name;
private String url;
private Date createTime;
private Date updateTime;
public ProductTypeVO buildProductType() {
return ProductTypeVO.builder().id(id).name(name).url(url).build();
}
}
package com.mmc.pms.model.category.vo;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @Author LW
* @date 2023/8/5 14:32
* 概要:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ProductTypeVO implements Serializable {
private static final long serialVersionUID = -1466513739991843345L;
@ApiModelProperty(value = "id", example = "1")
@NotNull(groups = {Update.class}, message = "id不能为空")
private Integer id;
@ApiModelProperty(value = "类型名称", example = "航拍无人机")
@NotEmpty(groups = {Create.class, Update.class}, message = "类型名称不能为空")
private String name;
@ApiModelProperty(value = "图标", example = "https://pad-video-x.oss-cn-shenzhen.aliyuncs.com/file/ad0e77b4-8518-4ecc-9b7f-19218f56b755.png")
@NotEmpty(groups = {Create.class, Update.class}, message = "图标不能为空")
private String url;
}
package com.mmc.pms.service.category;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.model.category.vo.ProductTypeVO;
import com.mmc.pms.page.PageResult;
/**
* @Author LW
* @date 2023/8/5 10:43
* 概要:
*/
public interface ProductAttributeService {
/**
* 添加类型
*
* @param param 参数
* @return {@link ResultBody}
*/
ResultBody addType(ProductTypeVO param);
/**
* 编辑类型
*
* @param param 参数
* @return {@link ResultBody}
*/
ResultBody editType(ProductTypeVO param);
/**
* 删除类型
*
* @param id id
* @return {@link ResultBody}
*/
ResultBody removeType(Integer id);
/**
* 类型详情
*
* @param id id
* @return {@link ResultBody}<{@link ProductTypeVO}>
*/
ResultBody<ProductTypeVO> typeDetails(Integer id);
PageResult typeList(Integer pageNo, Integer pageSize);
}
package com.mmc.pms.service.category.impl;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.common.ResultEnum;
import com.mmc.pms.dao.category.ProductAttributeDao;
import com.mmc.pms.entity.category.ProductTypeDO;
import com.mmc.pms.model.category.vo.ProductTypeVO;
import com.mmc.pms.page.PageResult;
import com.mmc.pms.service.category.ProductAttributeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author LW
* @date 2023/8/5 10:44
* 概要:
*/
@Service
public class ProductAttributeServiceImpl implements ProductAttributeService {
@Resource
ProductAttributeDao productAttributeDao;
@Override
public ResultBody addType(ProductTypeVO param) {
int count = productAttributeDao.countTypeByName(param);
if (count > 0) {
return ResultBody.error(ResultEnum.GOODS_CATEGORY_NAME_EXIST_ERROR);
}
productAttributeDao.addType(param);
return ResultBody.success();
}
@Override
public ResultBody editType(ProductTypeVO param) {
int count = productAttributeDao.countTypeByName(param);
if (count > 0) {
return ResultBody.error(ResultEnum.GOODS_CATEGORY_NAME_EXIST_ERROR);
}
productAttributeDao.editType(param);
return ResultBody.success();
}
@Override
public ResultBody removeType(Integer id) {
productAttributeDao.removeType(id);
return ResultBody.success();
}
@Override
public ResultBody<ProductTypeVO> typeDetails(Integer id) {
ProductTypeDO productType = productAttributeDao.getType(id);
return ResultBody.success(productType == null ? null : productType.buildProductType());
}
@Override
public PageResult typeList(Integer pageNo, Integer pageSize) {
int count = productAttributeDao.countType();
if (count == 0) {
return PageResult.buildPage(pageNo, pageSize, count);
}
List<ProductTypeDO> productTypeList = productAttributeDao.listType((pageNo - 1) * pageSize, pageSize);
return PageResult.buildPage(pageNo, pageSize, count, productTypeList.stream().map(ProductTypeDO::buildProductType).collect(Collectors.toList()));
}
}
package com.mmc.pms.service.lease;
/**
* @Author LW
* @date 2023/8/4 10:37
* 概要:
*/
public interface LeaseGoodsService {
}
package com.mmc.pms.service.lease.impl;
import com.mmc.pms.service.lease.LeaseGoodsService;
import org.springframework.stereotype.Service;
/**
* @Author LW
* @date 2023/8/4 10:37
* 概要:
*/
@Service
public class LeaseGoodsServiceImpl implements LeaseGoodsService {
}
<?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.mmc.pms.dao.category.ProductAttributeDao">
<insert id="addType">
insert into product_type(`name`, url)
values (#{name}, #{url})
</insert>
<update id="editType">
update product_type
<set>
<if test="name != null">
name = #{name},
</if>
<if test="url != null">
url = #{url}
</if>
</set>
where id = #{id}
</update>
<delete id="removeType">
delete
from product_type
where id = #{id}
</delete>
<select id="countTypeByName" resultType="java.lang.Integer">
select count(*)
from product_type
where `name` = #{name}
<if test="id != null">
and id <![CDATA[<>]]> #{id}
</if>
</select>
<select id="getType" resultType="com.mmc.pms.entity.category.ProductTypeDO">
select id, `name`, url
from product_type
where id = #{id}
</select>
<select id="countType" resultType="java.lang.Integer">
select count(*)
from product_type
</select>
<select id="listType" resultType="com.mmc.pms.entity.category.ProductTypeDO">
select id, `name`, url
from product_type
order by create_time desc
limit #{pageNo}, #{pageSize}
</select>
</mapper>
\ No newline at end of file
<?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.mmc.pms.dao.lease.LeaseGoodsDao">
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论