商品管理添加删除

This commit is contained in:
bunny 2023-12-16 19:19:22 +08:00
parent 71508d5050
commit 0546776bdf
28 changed files with 3977 additions and 6 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal" created-in="IU-232.10227.8">
<data-source name="db_spzx@60.204.230.80" uuid="3eae447a-3ae1-4be3-aa70-1183cffb0765">
<database-info product="MySQL" version="8.0.28" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-java-8.0.25 (Revision: 08be9e9b4cba6aa115f9b27b215887af40b159e0)" dbms="MYSQL" exact-version="8.0.28" exact-driver-version="8.0">
<extra-name-characters>#@</extra-name-characters>
<identifier-quote-string>`</identifier-quote-string>
<jdbc-catalog-is-schema>true</jdbc-catalog-is-schema>
</database-info>
<case-sensitivity plain-identifiers="exact" quoted-identifiers="exact" />
<secret-storage>master_key</secret-storage>
<user-name>root</user-name>
<schema-mapping>
<introspection-scope>
<node kind="schema" qname="@" />
</introspection-scope>
</schema-mapping>
</data-source>
</component>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
#n:db_spzx
!<md> [1702742235000, 0, null, null, -2147483648, -2147483648]

View File

@ -0,0 +1,2 @@
#n:information_schema
!<md> [null, 0, null, null, -2147483648, -2147483648]

View File

@ -0,0 +1,2 @@
#n:mysql
!<md> [null, 0, null, null, -2147483648, -2147483648]

View File

@ -0,0 +1,2 @@
#n:performance_schema
!<md> [null, 0, null, null, -2147483648, -2147483648]

View File

@ -0,0 +1,2 @@
#n:sys
!<md> [null, 0, null, null, -2147483648, -2147483648]

View File

@ -1,6 +1,9 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,com.github.pagehelper.page.PageMethod,startPage" />
</inspection_tool>
<inspection_tool class="RawUseOfParameterizedType" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

160
.idea/workspace.xml Normal file
View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="94fab532-0084-41f1-bb0f-d2d2811915a7" name="Changes" comment="商品管理查询分页">
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductUntilController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductDetailMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSkuMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductUntilMapper.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductUntilService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductUntilServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductDetailMapper.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSkuMapper.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductUntilMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductSpecController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/controller/ProductSpecController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSpecMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSpecMapper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductSpecService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/ProductSpecService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductSpecServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/service/impl/ProductSpecServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSpecMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-manager/src/main/resources/mapper/product/ProductSpecMapper.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
<option value="Interface" />
<option value="Mybatis" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="localRepository" value="D:\software\Plugins\Maven\maven_reo" />
<option name="mavenHome" value="D:/software/Plugins/Maven" />
<option name="userSettingsFile" value="D:\software\Plugins\Maven\conf\settings.xml" />
</MavenGeneralSettings>
</option>
</component>
<component name="ProjectColorInfo">{
&quot;customColor&quot;: &quot;&quot;,
&quot;associatedIndex&quot;: 5
}</component>
<component name="ProjectId" id="2Zc8hDNtVz2Z0OCxf9vAyM8Xxum" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RequestMappingsPanelOrder0": "0",
"RequestMappingsPanelOrder1": "1",
"RequestMappingsPanelWidth0": "75",
"RequestMappingsPanelWidth1": "75",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "master",
"last_opened_file_path": "G:/File/Java/spzx-parent/spzx-manager/src/main/resources/mapper",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
"settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
"DatabaseDriversLRU": [
"mysql"
]
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="G:\File\Java\spzx-parent\spzx-manager\src\main\resources\mapper" />
</key>
</component>
<component name="RunManager">
<configuration name="MangerApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" temporary="true" nameIsGenerated="true">
<module name="spzx-manager" />
<option name="SPRING_BOOT_MAIN_CLASS" value="cn.bunny.MangerApplication" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="cn.bunny.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Spring Boot.MangerApplication" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="94fab532-0084-41f1-bb0f-d2d2811915a7" name="Changes" comment="" />
<created>1702710124940</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1702710124940</updated>
<workItem from="1702710126987" duration="661000" />
<workItem from="1702713203759" duration="7512000" />
</task>
<task id="LOCAL-00001" summary="商品管理查询分页">
<option name="closed" value="true" />
<created>1702714985398</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1702714985398</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="商品管理查询分页" />
<option name="LAST_COMMIT_MESSAGE" value="商品管理查询分页" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-method">
<url>file://$PROJECT_DIR$/spzx-manager/src/main/java/cn/bunny/mapper/ProductSpecMapper.java</url>
<line>22</line>
<properties class="cn.bunny.mapper.ProductSpecMapper" method="findAll">
<option name="EMULATED" value="true" />
<option name="WATCH_EXIT" value="false" />
</properties>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -9,10 +9,7 @@ import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -23,6 +20,28 @@ public class ProductController {
@Autowired
private ProductService productService;
@Operation(summary = "保存修改数据",description = "保存修改数据")
@PostMapping("updateById")
public Result updateById(@RequestBody Product product) {
productService.updateById(product);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "根据id查询商品信息",description = "根据id查询商品信息")
@GetMapping("getById/{id}")
public Result getById(@PathVariable("id") Long id) {
Product product = productService.getById(id);
return Result.build(product, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "保存商品数据接口",description = "保存商品数据接口")
@PostMapping("save")
public Result save(@RequestBody Product product) {
productService.save(product);
return Result.build(null, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "商品管理查询分页", description = "商品管理查询分页")
@GetMapping("/{page}/{limit}")
public Result findByPage(@PathVariable("page") Integer page,

View File

@ -10,6 +10,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "商品规格列表接口")
@RestController
@RequestMapping("/admin/product/productSpec")
@ -17,6 +19,13 @@ public class ProductSpecController {
@Autowired
private ProductSpecService productSpecService;
@Operation(summary = "加载商品单元数据",description = "加载商品单元数据")
@GetMapping("findAll")
public Result findAll() {
List<ProductSpec> productSpecList= productSpecService.findAll();
return Result.build(productSpecList, ResultCodeEnum.SUCCESS);
}
@Operation(summary = "分页查询商品规格列表", description = "分页查询商品规格列表")
@GetMapping("{page}/{limit}")
public Result lis(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit) {

View File

@ -0,0 +1,30 @@
package cn.bunny.controller;
import cn.bunny.common.spzx.model.entity.base.ProductUnit;
import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.service.ProductUntilService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "商品管理添加功能")
@RestController
@RequestMapping("/admin/product/productUnit")
public class ProductUntilController {
@Autowired
private ProductUntilService productUntilService;
@Operation(summary = "加载商品单元数据", description = "加载商品单元数据")
@GetMapping("findAll")
public Result findAll() {
List<ProductUnit> productUnitList= productUntilService.findAll();
return Result.build(productUnitList, ResultCodeEnum.SUCCESS);
}
}

View File

@ -0,0 +1,15 @@
package cn.bunny.mapper;
import cn.bunny.common.spzx.model.entity.product.ProductDetails;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductDetailMapper {
void save(ProductDetails productDetails);
// 根据id查询商品信息
ProductDetails findProductDetailsById(Long id);
// 修改product_details表
void updateById(ProductDetails productDetails);
}

View File

@ -10,4 +10,13 @@ import java.util.List;
public interface ProductMapper {
// 查询分页
public List<Product> findByPage(ProductDto productDto);
// 保存商品数据接口
void save(Product product);
// 1. 根据id查询商品基本信息
Product findProductById(Long id);
// 修改product表
void updateProduct(Product product);
}

View File

@ -0,0 +1,17 @@
package cn.bunny.mapper;
import cn.bunny.common.spzx.model.entity.product.ProductSku;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductSkuMapper {
void save(ProductSku productSku);
// 根据id查询商品信息
List<ProductSku> findProductSkuByProductId(Long id);
// 修改product_sku表
void updateById(ProductSku productSku);
}

View File

@ -18,4 +18,7 @@ public interface ProductSpecMapper {
// 商品规格删除
void deleteById(Integer id);
// 加载商品单元数据
List<ProductSpec> findAll();
}

View File

@ -0,0 +1,12 @@
package cn.bunny.mapper;
import cn.bunny.common.spzx.model.entity.base.ProductUnit;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductUntilMapper {
// 加载商品单元数据
List<ProductUnit> findAll();
}

View File

@ -9,4 +9,13 @@ import java.util.List;
public interface ProductService {
// 查询分页
PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto productDto);
// 保存商品数据接口
void save(Product product);
// 根据id查询商品信息
Product getById(Long id);
// 保存修改数据
void updateById(Product product);
}

View File

@ -3,6 +3,8 @@ package cn.bunny.service;
import cn.bunny.common.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface ProductSpecService {
// 分页查询商品规格列表
PageInfo<ProductSpec> findByPage(Integer page, Integer limit);
@ -15,4 +17,7 @@ public interface ProductSpecService {
// 商品规格删除
void deleteById(Integer id);
// 加载商品单元数据
List<ProductSpec> findAll();
}

View File

@ -0,0 +1,10 @@
package cn.bunny.service;
import cn.bunny.common.spzx.model.entity.base.ProductUnit;
import java.util.List;
public interface ProductUntilService {
// 加载商品单元数据
List<ProductUnit> findAll();
}

View File

@ -2,7 +2,11 @@ package cn.bunny.service.impl;
import cn.bunny.common.spzx.model.dto.product.ProductDto;
import cn.bunny.common.spzx.model.entity.product.Product;
import cn.bunny.common.spzx.model.entity.product.ProductDetails;
import cn.bunny.common.spzx.model.entity.product.ProductSku;
import cn.bunny.mapper.ProductDetailMapper;
import cn.bunny.mapper.ProductMapper;
import cn.bunny.mapper.ProductSkuMapper;
import cn.bunny.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -16,6 +20,12 @@ public class ProductServiceImpl implements ProductService {
@Autowired
private ProductMapper productMapper;
@Autowired
private ProductSkuMapper productSkuMapper;
@Autowired
private ProductDetailMapper productDetailMapper;
// 查询分页
@Override
public PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto productDto) {
@ -23,4 +33,66 @@ public class ProductServiceImpl implements ProductService {
List<Product> productList = productMapper.findByPage(productDto);
return new PageInfo<>(productList);
}
// 保存商品数据接口
@Override
public void save(Product product) {
product.setStatus(0);
product.setAuditStatus(0);
productMapper.save(product);
List<ProductSku> productSkuList = product.getProductSkuList();
for (int i = 0; i < productSkuList.size(); i++) {
ProductSku productSku = productSkuList.get(i);
// 商品编号
productSku.setSkuCode(product.getId() + "_" + i);
// 商品Id
productSku.setProductId(product.getId());
// skuName
productSku.setSkuName(product.getName() + productSku.getSkuSpec());
productSkuMapper.save(productSku);
}
ProductDetails productDetails = new ProductDetails();
productDetails.setProductId(product.getId());
productDetails.setImageUrls(product.getDetailsImageUrls());
productDetailMapper.save(productDetails);
}
// 根据id查询商品信息
@Override
public Product getById(Long id) {
// 1. 根据id查询商品基本信息
Product product = productMapper.findProductById(id);
// 2. 根据id查询商品sku信息列表 productsku
List<ProductSku> productSkuList = productSkuMapper.findProductSkuByProductId(id);
product.setProductSkuList(productSkuList);
// 3. 根据id查询商品详情信息 productdetails
ProductDetails productDetails = productDetailMapper.findProductDetailsById(id);
String imageUrls = productDetails.getImageUrls();
product.setDetailsImageUrls(imageUrls);
return product;
}
// 保存修改数据
@Override
public void updateById(Product product) {
// 修改product表
productMapper.updateProduct(product);
// 修改product_sku表
List<ProductSku> productSkuList = product.getProductSkuList();
for (ProductSku productSku : productSkuList) {
productSkuMapper.updateById(productSku);
}
// 修改product_details表
String detailsImageUrls = product.getDetailsImageUrls();
ProductDetails productDetails= productDetailMapper.findProductDetailsById(product.getId());
productDetails.setImageUrls(detailsImageUrls);
productDetailMapper.updateById(productDetails);
}
}

View File

@ -40,4 +40,10 @@ public class ProductSpecServiceImpl implements ProductSpecService {
public void deleteById(Integer id) {
productSpecMapper.deleteById(id);
}
// 加载商品单元数据
@Override
public List<ProductSpec> findAll() {
return productSpecMapper.findAll();
}
}

View File

@ -0,0 +1,22 @@
package cn.bunny.service.impl;
import cn.bunny.common.spzx.model.entity.base.ProductUnit;
import cn.bunny.mapper.ProductUntilMapper;
import cn.bunny.service.ProductUntilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductUntilServiceImpl implements ProductUntilService {
@Autowired
private ProductUntilMapper productUnitMapper;
// 加载商品单元数据
@Override
public List<ProductUnit> findAll() {
return productUnitMapper.findAll();
}
}

View File

@ -0,0 +1,44 @@
<?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="cn.bunny.mapper.ProductDetailMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,product_id,image_urls,create_time,update_time,is_deleted
</sql>
<insert id="save" useGeneratedKeys="true" keyProperty="id">
insert into product_details (id,
product_id,
image_urls,
create_time, update_time, is_deleted)
values (#{id},
#{productId},
#{imageUrls},
now(),
now(),
0)
</insert>
<!-- 修改product_details表 -->
<update id="updateById">
update product_details set
<if test="productId != null and productId != ''">
product_id = #{productId},
</if>
<if test="imageUrls != null and imageUrls != ''">
image_urls = #{imageUrls},
</if>
update_time = now()
where
id = #{id}
</update>
<!-- 根据id查询商品信息 -->
<select id="findProductDetailsById" resultType="cn.bunny.common.spzx.model.entity.product.ProductDetails">
select
<include refid="columns"/>
from product_details
where
product_id = #{productId} and is_deleted=0
</select>
</mapper>

View File

@ -27,11 +27,61 @@
</where>
</sql>
<!-- 保存商品数据接口 -->
<insert id="save" useGeneratedKeys="true" keyProperty="id">
insert into product (id, name, brand_id, category1_id, category2_id, category3_id, unit_name, slider_urls,
spec_value, status, audit_status, audit_message, create_time, update_time, is_deleted)
values (#{id}, #{name}, #{brandId}, #{category1Id}, #{category2Id}, #{category3Id}, #{unitName}, #{sliderUrls},
#{specValue}, #{status}, #{auditStatus}, #{auditMessage}, now(), now(), 0)
</insert>
<!-- 修改product表 -->
<update id="updateProduct">
update product set
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="brandId != null and brandId != ''">
brand_id = #{brandId},
</if>
<if test="category1Id != null and category1Id != ''">
category1_id = #{category1Id},
</if>
<if test="category2Id != null and category2Id != ''">
category2_id = #{category2Id},
</if>
<if test="category3Id != null and category3Id != ''">
category3_id = #{category3Id},
</if>
<if test="unitName != null and unitName != ''">
unit_name = #{unitName},
</if>
<if test="sliderUrls != null and sliderUrls != ''">
slider_urls = #{sliderUrls},
</if>
<if test="specValue != null and specValue != ''">
spec_value = #{specValue},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
<if test="auditStatus != null and auditStatus != ''">
audit_status = #{auditStatus},
</if>
<if test="auditMessage != null and auditMessage != ''">
audit_message = #{auditMessage},
</if>
update_time = now()
where
id = #{id}
</update>
<!-- 查询分页 -->
<select id="findByPage" resultType="cn.bunny.common.spzx.model.entity.product.Product">
select
p.id, p.name , p.brand_id , p.category1_id , p.category2_id , p.category3_id, p.unit_name,
p.slider_urls , p.spec_value , p.status , p.audit_status , p.audit_message , p.create_time , p.update_time , p.is_deleted ,
p.slider_urls , p.spec_value , p.status , p.audit_status , p.audit_message , p.create_time , p.update_time ,
p.is_deleted ,
b.name brandName , c1.name category1Name , c2.name category2Name , c3.name category3Name
from product p
LEFT JOIN brand b on b.id = p.brand_id
@ -41,4 +91,33 @@
<include refid="findPageWhere"/>
order by id desc
</select>
<!-- 1. 根据id查询商品基本信息 -->
<select id="findProductById" resultType="cn.bunny.common.spzx.model.entity.product.Product">
select p.id,
p.name,
p.brand_id,
p.category1_id,
p.category2_id,
p.category3_id,
p.unit_name,
p.slider_urls,
p.spec_value,
p.status,
p.audit_status,
p.audit_message,
p.create_time,
p.update_time,
p.is_deleted,
b.name brandName,
c1.name category1Name,
c2.name category2Name,
c3.name category3Name
from product p
LEFT JOIN brand b on b.id = p.brand_id
LEFT JOIN category c1 on c1.id = p.category1_id
LEFT JOIN category c2 on c2.id = p.category2_id
LEFT JOIN category c3 on c3.id = p.category3_id
where p.id = #{id}
</select>
</mapper>

View File

@ -0,0 +1,99 @@
<?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="cn.bunny.mapper.ProductSkuMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,sku_code,sku_name,product_id,thumb_img,sale_price,market_price,cost_price,stock_num,sku_spec,weight,volume,status,create_time,update_time,is_deleted
</sql>
<insert id="save" useGeneratedKeys="true" keyProperty="id">
insert into product_sku (id,
sku_code,
sku_name,
product_id,
thumb_img,
sale_price,
market_price,
cost_price,
stock_num,
sku_spec,
weight,
volume,
status,
sale_num,
create_time,
update_time,
is_deleted)
values (#{id},
#{skuCode},
#{skuName},
#{productId},
#{thumbImg},
#{salePrice},
#{marketPrice},
#{costPrice},
#{stockNum},
#{skuSpec},
#{weight},
#{volume},
#{status},
#{saleNum},
now(),
now(),
0)
</insert>
<!-- 修改product_sku表 -->
<update id="updateById">
update product_sku set
<if test="skuCode != null and skuCode != ''">
sku_code = #{skuCode},
</if>
<if test="skuName != null and skuName != ''">
sku_name = #{skuName},
</if>
<if test="productId != null and productId != ''">
product_id = #{productId},
</if>
<if test="thumbImg != null and thumbImg != ''">
thumb_img = #{thumbImg},
</if>
<if test="salePrice != null and salePrice != ''">
sale_price = #{salePrice},
</if>
<if test="marketPrice != null and marketPrice != ''">
market_price = #{marketPrice},
</if>
<if test="costPrice != null and costPrice != ''">
cost_price = #{costPrice},
</if>
<if test="stockNum != null and stockNum != ''">
stock_num = #{stockNum},
</if>
<if test="skuSpec != null and skuSpec != ''">
sku_spec = #{skuSpec},
</if>
<if test="weight != null and weight != ''">
weight = #{weight},
</if>
<if test="volume != null and volume != ''">
volume = #{volume},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
update_time = now()
where
id = #{id}
</update>
<!-- 根据id查询商品信息 -->
<select id="findProductSkuByProductId" resultType="cn.bunny.common.spzx.model.entity.product.ProductSku">
select <include refid="columns" />
from product_sku
where product_id = #{productId}
and is_deleted = 0
order by id desc
</select>
</mapper>

View File

@ -44,4 +44,10 @@
where is_deleted = 0
order by id desc
</select>
</mapper>
<!-- 加载商品单元数据 -->
<select id="findAll" resultType="cn.bunny.common.spzx.model.entity.product.ProductSpec">
select
<include refid="columns"/>
from product_spec where is_deleted = 0 order by id
</select></mapper>

View File

@ -0,0 +1,17 @@
<?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="cn.bunny.mapper.ProductUntilMapper">
<resultMap id="productUnitMap" type="cn.bunny.common.spzx.model.entity.base.ProductUnit" autoMapping="true"/>
<sql id="columns">
id,name,create_time,update_time,is_deleted
</sql>
<!-- 加载商品单元数据 -->
<select id="findAll" resultType="cn.bunny.common.spzx.model.entity.base.ProductUnit">
select <include refid="columns" />
from product_unit
where is_deleted = 0
order by id
</select>
</mapper>