Author homepage:Programming Compass
About the author: High-quality creator in the Java field, CSDN blog expert, CSDN content partner, Nuggets guest author, Alibaba Cloud blog expert, 51CTO guest author, many years of architect design experience, Tencent classroom resident lecturer
Main contents: Java projects, Python projects, front-end projects, artificial intelligence and big data, resume templates, study materials, interview question bank, technical mutual assistance
Collect, like and don’t get lost. It’s good to follow the author.
Get the source code at the end of the article
Project number: L-BS-SC-03
1. Introduction to the environment
Locale: Java: jdk1.8
Database: Mysql: mysql5.7
Application server: Tomcat: tomcat8.5.31
Development tools: IDEA or eclipse
2. Project Introduction
This project is an e-commerce system, including a front-end mall system and a back-end management system, implemented based on SpringBoot+MyBatis. The front-end mall system includes modules such as homepage portal, product recommendation, product search, product display, shopping cart, order process, member center, customer service, and help center. The backend management system includes modules such as product management, order management, membership management, promotion management, operations management, content management, statistical reports, financial management, authority management, and settings.
Backend technology
Mall is implemented using current mainstream technologies, covering almost all technologies used in general projects.
technology | Version | illustrate |
---|---|---|
SpringBoot | 2.7.5 | Container + MVC framework |
SpringSecurity | 5.7.4 | Authentication and Authorization Framework |
MyBatis | 3.5.10 | ORM framework |
MyBatisGenerator | 1.4.1 | Data layer code generation |
RabbitMQ | 3.10.5 | message queue |
Redis | 7.0 | Distributed cache |
MongoDB | 5.0 | NoSQL database |
Elasticsearch | 7.17.3 | search engine |
LogStash | 7.17.3 | Log collection tool |
Kibana | 7.17.3 | Log visualization tool |
Nginx | 1.22 | Static resource server |
Druid | 1.2.14 | Database connection pool |
MinIO/OSS | 8.4.5 | object storage |
Hutool | 5.8.0 | Java tool library |
PageHelper | 5.3.2 | MyBatis physical paging plug-in |
Swagger-UI | 3.0.0 | Document generation tool |
logstash logback encoder | 7.2 | Logstash log collection plug-in |
docker-maven-plugin | 0.40.2 | Maven plugin that applies applications packaged into Docker images |
Front-end technology
The project adopts the currently popular front-end and back-end separation development model. The front-end project of the e-commerce management system is implemented based on Vue+Element.
technology | illustrate |
---|---|
View | front-end framework |
Vue-router | routing framework |
Vuex | Global state management framework |
Element | Front-end UI framework |
Axios | Front-end HTTP framework |
v-charts | Chart framework based on Echarts |
Js-cookie | cookie management tools |
nprogress | progress bar control |
vue-element-admin | Project scaffolding reference |
Mobile technology
The mobile terminal project of the e-commerce system is implemented based onuni-app
. It mainly includes functions such as homepage portal, product recommendation, product search, product display, shopping cart, order process, member center, customer service, and help center.
technology | illustrate |
---|---|
View | Core front-end framework |
Vuex | Global state management framework |
uni-app | Mobile front-end framework |
mix-mall | E-commerce project template |
luch-request | HTTP request framework |
Backend management system
-
The product module includes: product management, product classification management, product type management, and brand management.
-
The order module includes: order management, order setting, return application processing, return reason setting
-
Marketing modules include: flash sale activity management, coupon management, brand recommendation management, new product recommendation management, popularity recommendation management, topic recommendation management, and homepage advertising management
-
Permission modules include: user management, menu management, role management, resource management
Mobile mall
-
Home page: carousel ads, functional modules, direct supply from brand manufacturers, flash sale area, fresh products, popular recommendations, guess what you like
-
Product: Product classification [supports Level 2], product list, product details, product operations (add to shopping cart, collection, shopping cart)
-
Shopping cart: shopping cart product list, order payment, order list, order details
-
My: member information, coupons, order management, address management, footprints, my attention, my collection, my evaluation
3. System display
4. Core code display
4.1 Member interface
@Service
public class MemberCollectionServiceImpl implements MemberCollectionService {
@Value("${mongo.insert.sqlEnable}")
private Boolean sqlEnable;
@Autowired
private PmsProductMapper productMapper;
@Autowired
private MemberProductCollectionRepository productCollectionRepository;
@Autowired
private UmsMemberService memberService;
@Override
public int add(MemberProductCollection productCollection) {
int count = 0;
if (productCollection.getProductId() == null) {
return 0;
}
UmsMember member = memberService.getCurrentMember();
productCollection.setMemberId(member.getId());
productCollection.setMemberNickname(member.getNickname());
productCollection.setMemberIcon(member.getIcon());
MemberProductCollection findCollection = productCollectionRepository.findByMemberIdAndProductId(productCollection.getMemberId(), productCollection.getProductId());
if (findCollection == null) {
if (sqlEnable) {
PmsProduct product = productMapper.selectByPrimaryKey(productCollection.getProductId());
if (product == null || product.getDeleteStatus() == 1) {
return 0;
}
productCollection.setProductName(product.getName());
productCollection.setProductSubTitle(product.getSubTitle());
productCollection.setProductPrice(product.getPrice() + "");
productCollection.setProductPic(product.getPic());
}
productCollectionRepository.save(productCollection);
count = 1;
}
return count;
}
@Override
public int delete(Long productId) {
UmsMember member = memberService.getCurrentMember();
return productCollectionRepository.deleteByMemberIdAndProductId(member.getId(), productId);
}
@Override
public Page<MemberProductCollection> list(Integer pageNum, Integer pageSize) {
UmsMember member = memberService.getCurrentMember();
Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
return productCollectionRepository.findByMemberId(member.getId(), pageable);
}
@Override
public MemberProductCollection detail(Long productId) {
UmsMember member = memberService.getCurrentMember();
return productCollectionRepository.findByMemberIdAndProductId(member.getId(), productId);
}
@Override
public void clear() {
UmsMember member = memberService.getCurrentMember();
productCollectionRepository.deleteAllByMemberId(member.getId());
}
}
4.2 Product interface
@Service
public class PmsProductServiceImpl implements PmsProductService {
private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
@Autowired
private PmsProductMapper productMapper;
@Autowired
private PmsMemberPriceDao memberPriceDao;
@Autowired
private PmsMemberPriceMapper memberPriceMapper;
@Autowired
private PmsProductLadderDao productLadderDao;
@Autowired
private PmsProductLadderMapper productLadderMapper;
@Autowired
private PmsProductFullReductionDao productFullReductionDao;
@Autowired
private PmsProductFullReductionMapper productFullReductionMapper;
@Autowired
private PmsSkuStockDao skuStockDao;
@Autowired
private PmsSkuStockMapper skuStockMapper;
@Autowired
private PmsProductAttributeValueDao productAttributeValueDao;
@Autowired
private PmsProductAttributeValueMapper productAttributeValueMapper;
@Autowired
private CmsSubjectProductRelationDao subjectProductRelationDao;
@Autowired
private CmsSubjectProductRelationMapper subjectProductRelationMapper;
@Autowired
private CmsPrefrenceAreaProductRelationDao prefrenceAreaProductRelationDao;
@Autowired
private CmsPrefrenceAreaProductRelationMapper prefrenceAreaProductRelationMapper;
@Autowired
private PmsProductDao productDao;
@Autowired
private PmsProductVertifyRecordDao productVertifyRecordDao;
@Override
public int create(PmsProductParam productParam) {
int count;
//创建商品
PmsProduct product = productParam;
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:会员价格、阶梯价格、满减价格
Long productId = product.getId();
//会员价格
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
//阶梯价格
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);
//满减价格
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
//处理sku的编码
handleSkuStockCode(productParam.getSkuStockList(),productId);
//添加sku库存信息
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
//添加商品参数,添加自定义商品规格
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
//关联专题
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
//关联优选
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
count = 1;
return count;
}
private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId) {
if(CollectionUtils.isEmpty(skuStockList))return;
for(int i=0;i<skuStockList.size();i++){
PmsSkuStock skuStock = skuStockList.get(i);
if(StrUtil.isEmpty(skuStock.getSkuCode())){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
StringBuilder sb = new StringBuilder();
//日期
sb.append(sdf.format(new Date()));
//四位商品id
sb.append(String.format("%04d", productId));
//三位索引id
sb.append(String.format("%03d", i+1));
skuStock.setSkuCode(sb.toString());
}
}
}
@Override
public PmsProductResult getUpdateInfo(Long id) {
return productDao.getUpdateInfo(id);
}
@Override
public int update(Long id, PmsProductParam productParam) {
int count;
//更新商品信息
PmsProduct product = productParam;
product.setId(id);
productMapper.updateByPrimaryKeySelective(product);
//会员价格
PmsMemberPriceExample pmsMemberPriceExample = new PmsMemberPriceExample();
pmsMemberPriceExample.createCriteria().andProductIdEqualTo(id);
memberPriceMapper.deleteByExample(pmsMemberPriceExample);
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), id);
//阶梯价格
PmsProductLadderExample ladderExample = new PmsProductLadderExample();
ladderExample.createCriteria().andProductIdEqualTo(id);
productLadderMapper.deleteByExample(ladderExample);
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), id);
//满减价格
PmsProductFullReductionExample fullReductionExample = new PmsProductFullReductionExample();
fullReductionExample.createCriteria().andProductIdEqualTo(id);
productFullReductionMapper.deleteByExample(fullReductionExample);
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
//修改sku库存信息
handleUpdateSkuStockList(id, productParam);
//修改商品参数,添加自定义商品规格
PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
productAttributeValueMapper.deleteByExample(productAttributeValueExample);
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), id);
//关联专题
CmsSubjectProductRelationExample subjectProductRelationExample = new CmsSubjectProductRelationExample();
subjectProductRelationExample.createCriteria().andProductIdEqualTo(id);
subjectProductRelationMapper.deleteByExample(subjectProductRelationExample);
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), id);
//关联优选
CmsPrefrenceAreaProductRelationExample prefrenceAreaExample = new CmsPrefrenceAreaProductRelationExample();
prefrenceAreaExample.createCriteria().andProductIdEqualTo(id);
prefrenceAreaProductRelationMapper.deleteByExample(prefrenceAreaExample);
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), id);
count = 1;
return count;
}
private void handleUpdateSkuStockList(Long id, PmsProductParam productParam) {
//当前的sku信息
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
//当前没有sku直接删除
if(CollUtil.isEmpty(currSkuList)){
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
skuStockMapper.deleteByExample(skuStockExample);
return;
}
//获取初始sku信息
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);
//获取新增sku信息
List<PmsSkuStock> insertSkuList = currSkuList.stream().filter(item->item.getId()==null).collect(Collectors.toList());
//获取需要更新的sku信息
List<PmsSkuStock> updateSkuList = currSkuList.stream().filter(item->item.getId()!=null).collect(Collectors.toList());
List<Long> updateSkuIds = updateSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
//获取需要删除的sku信息
List<PmsSkuStock> removeSkuList = oriStuList.stream().filter(item-> !updateSkuIds.contains(item.getId())).collect(Collectors.toList());
handleSkuStockCode(insertSkuList,id);
handleSkuStockCode(updateSkuList,id);
//新增sku
if(CollUtil.isNotEmpty(insertSkuList)){
relateAndInsertList(skuStockDao, insertSkuList, id);
}
//删除sku
if(CollUtil.isNotEmpty(removeSkuList)){
List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
PmsSkuStockExample removeExample = new PmsSkuStockExample();
removeExample.createCriteria().andIdIn(removeSkuIds);
skuStockMapper.deleteByExample(removeExample);
}
//修改sku
if(CollUtil.isNotEmpty(updateSkuList)){
for (PmsSkuStock pmsSkuStock : updateSkuList) {
skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);
}
}
}
@Override
public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
PmsProductExample productExample = new PmsProductExample();
PmsProductExample.Criteria criteria = productExample.createCriteria();
criteria.andDeleteStatusEqualTo(0);
if (productQueryParam.getPublishStatus() != null) {
criteria.andPublishStatusEqualTo(productQueryParam.getPublishStatus());
}
if (productQueryParam.getVerifyStatus() != null) {
criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());
}
if (!StrUtil.isEmpty(productQueryParam.getKeyword())) {
criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");
}
if (!StrUtil.isEmpty(productQueryParam.getProductSn())) {
criteria.andProductSnEqualTo(productQueryParam.getProductSn());
}
if (productQueryParam.getBrandId() != null) {
criteria.andBrandIdEqualTo(productQueryParam.getBrandId());
}
if (productQueryParam.getProductCategoryId() != null) {
criteria.andProductCategoryIdEqualTo(productQueryParam.getProductCategoryId());
}
return productMapper.selectByExample(productExample);
}
@Override
public int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail) {
PmsProduct product = new PmsProduct();
product.setVerifyStatus(verifyStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
List<PmsProductVertifyRecord> list = new ArrayList<>();
int count = productMapper.updateByExampleSelective(product, example);
//修改完审核状态后插入审核记录
for (Long id : ids) {
PmsProductVertifyRecord record = new PmsProductVertifyRecord();
record.setProductId(id);
record.setCreateTime(new Date());
record.setDetail(detail);
record.setStatus(verifyStatus);
record.setVertifyMan("test");
list.add(record);
}
productVertifyRecordDao.insertList(list);
return count;
}
@Override
public int updatePublishStatus(List<Long> ids, Integer publishStatus) {
PmsProduct record = new PmsProduct();
record.setPublishStatus(publishStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}
@Override
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus) {
PmsProduct record = new PmsProduct();
record.setRecommandStatus(recommendStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}
@Override
public int updateNewStatus(List<Long> ids, Integer newStatus) {
PmsProduct record = new PmsProduct();
record.setNewStatus(newStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}
@Override
public int updateDeleteStatus(List<Long> ids, Integer deleteStatus) {
PmsProduct record = new PmsProduct();
record.setDeleteStatus(deleteStatus);
PmsProductExample example = new PmsProductExample();
example.createCriteria().andIdIn(ids);
return productMapper.updateByExampleSelective(record, example);
}
@Override
public List<PmsProduct> list(String keyword) {
PmsProductExample productExample = new PmsProductExample();
PmsProductExample.Criteria criteria = productExample.createCriteria();
criteria.andDeleteStatusEqualTo(0);
if(!StrUtil.isEmpty(keyword)){
criteria.andNameLike("%" + keyword + "%");
productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");
}
return productMapper.selectByExample(productExample);
}
/**
* 建立和插入关系表操作
*
* @param dao 可以操作的dao
* @param dataList 要插入的数据
* @param productId 建立关系的id
*/
private void relateAndInsertList(Object dao, List dataList, Long productId) {
try {
if (CollectionUtils.isEmpty(dataList)) return;
for (Object item : dataList) {
Method setId = item.getClass().getMethod("setId", Long.class);
setId.invoke(item, (Long) null);
Method setProductId = item.getClass().getMethod("setProductId", Long.class);
setProductId.invoke(item, productId);
}
Method insertList = dao.getClass().getMethod("insertList", List.class);
insertList.invoke(dao, dataList);
} catch (Exception e) {
LOGGER.warn("创建产品出错:{}", e.getMessage());
throw new RuntimeException(e.getMessage());
}
}
}
5. Display of related works
Practical projects based on Java development, Python development, PHP development, C# development and other related languages
Front-end practical projects developed based on Nodejs, Vue and other front-end technologies
Related works based on WeChat applet and Android APP application development
Development and application of embedded Internet of Things based on 51 microcontroller and other embedded devices
AI intelligent applications based on various algorithms
Various data management and recommendation systems based on big data