feat(商店模块): 新增商店管理功能,包括商店的增删改查及与智能柜的关联
此次提交引入了完整的商店管理功能,包括商店的增删改查操作,以及商店与智能柜的关联。新增了ShopEntity、ShopService、ShopMapper等相关类,并实现了ShopController用于前端交互。同时,更新了智能柜模块,增加了商店ID字段,以支持商店与智能柜的关联管理。
This commit is contained in:
parent
a1416fa7d7
commit
fa900ef3f5
|
@ -0,0 +1,68 @@
|
|||
package com.agileboot.admin.controller.shop;
|
||||
|
||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.shop.shop.ShopApplicationService;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.dto.ShopDTO;
|
||||
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/shop/shops")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class ShopController extends BaseController {
|
||||
|
||||
private final ShopApplicationService shopApplicationService;
|
||||
|
||||
@Operation(summary = "商店列表")
|
||||
@GetMapping
|
||||
public ResponseDTO<PageDTO<ShopDTO>> list(SearchShopQuery<ShopEntity> query) {
|
||||
PageDTO<ShopDTO> page = shopApplicationService.getShopList(query);
|
||||
return ResponseDTO.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.ADD)
|
||||
@PostMapping
|
||||
public ResponseDTO<Void> add(@Validated @RequestBody AddShopCommand command) {
|
||||
shopApplicationService.addShop(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PutMapping("/{id}")
|
||||
public ResponseDTO<Void> edit(@PathVariable Long id, @Validated @RequestBody UpdateShopCommand command) {
|
||||
command.setShopId(id);
|
||||
shopApplicationService.updateShop(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除商店")
|
||||
@AccessLog(title = "商店管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
|
||||
shopApplicationService.deleteShop(new BulkOperationCommand<>(ids));
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
|
@ -43,6 +43,10 @@ public class SmartCabinetEntity extends BaseEntity<SmartCabinetEntity> {
|
|||
@TableField("mqtt_server_id")
|
||||
private Long mqttServerId;
|
||||
|
||||
@ApiModelProperty("商店ID")
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
@ApiModelProperty("柜机模版编号")
|
||||
@TableField("template_no")
|
||||
private String templateNo;
|
||||
|
|
|
@ -37,6 +37,9 @@ public class SmartCabinetDTO {
|
|||
@ExcelColumn(name = "MQTT服务ID")
|
||||
private Long mqttServerId;
|
||||
|
||||
@ExcelColumn(name = "商店ID")
|
||||
private Long shopId;
|
||||
|
||||
@ExcelColumn(name = "柜机模版编号")
|
||||
private String templateNo;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ public class SearchSmartCabinetQuery<T> extends AbstractPageQuery<T> {
|
|||
private Date startTime;
|
||||
private Date endTime;
|
||||
private Long mqttServerId;
|
||||
private Long shopId;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
|
@ -26,6 +27,7 @@ public class SearchSmartCabinetQuery<T> extends AbstractPageQuery<T> {
|
|||
.like(StrUtil.isNotEmpty(cabinetName), "cabinet_name", cabinetName)
|
||||
.eq(cabinetType != null, "cabinet_type", cabinetType)
|
||||
.eq(mqttServerId!= null, "mqtt_server_id", mqttServerId)
|
||||
.eq(shopId!= null, "shop_id", shopId)
|
||||
.eq(StrUtil.isNotEmpty(templateNo), "template_no", templateNo)
|
||||
.eq("deleted", false)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.agileboot.domain.shop.shop;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import com.agileboot.domain.shop.shop.dto.ShopDTO;
|
||||
import com.agileboot.domain.shop.shop.model.ShopModel;
|
||||
import com.agileboot.domain.shop.shop.model.ShopModelFactory;
|
||||
import com.agileboot.domain.shop.shop.query.SearchShopQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ShopApplicationService {
|
||||
private final ShopService shopService;
|
||||
private final ShopModelFactory shopModelFactory;
|
||||
|
||||
public PageDTO<ShopDTO> getShopList(SearchShopQuery<ShopEntity> query) {
|
||||
Page<ShopEntity> page = shopService.page(query.toPage(), query.toQueryWrapper());
|
||||
List<ShopDTO> dtoList = page.getRecords().stream()
|
||||
.map(ShopDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
return new PageDTO<>(dtoList, page.getTotal());
|
||||
}
|
||||
|
||||
public void addShop(AddShopCommand command) {
|
||||
ShopModel model = shopModelFactory.create();
|
||||
model.loadAddCommand(command);
|
||||
model.insert();
|
||||
}
|
||||
|
||||
public void updateShop(UpdateShopCommand command) {
|
||||
ShopModel model = shopModelFactory.loadById(command.getShopId());
|
||||
model.loadUpdateCommand(command);
|
||||
model.updateById();
|
||||
}
|
||||
|
||||
public void deleteShop(BulkOperationCommand<Long> command) {
|
||||
for (Long shopId : command.getIds()) {
|
||||
ShopModel model = shopModelFactory.loadById(shopId);
|
||||
model.deleteById();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.agileboot.domain.shop.shop.command;
|
||||
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class AddShopCommand extends ShopEntity {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.agileboot.domain.shop.shop.command;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UpdateShopCommand extends AddShopCommand {
|
||||
|
||||
@NotNull
|
||||
@PositiveOrZero
|
||||
private Long shopId;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.agileboot.common.core.base.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("shop")
|
||||
@ApiModel(value = "ShopEntity对象", description = "商店表,每个柜子属于一个商店")
|
||||
public class ShopEntity extends BaseEntity<ShopEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("主键ID")
|
||||
@TableId(value = "shop_id", type = IdType.AUTO)
|
||||
private Long shopId;
|
||||
|
||||
@ApiModelProperty("商店名称")
|
||||
@TableField("shop_name")
|
||||
private String shopName;
|
||||
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.shopId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
public interface ShopMapper extends BaseMapper<ShopEntity> {
|
||||
@Select("SELECT shop_id, shop_name " +
|
||||
"FROM shop " +
|
||||
"${ew.customSqlSegment}")
|
||||
Page<ShopEntity> getShopList(
|
||||
Page<ShopEntity> page,
|
||||
@Param(Constants.WRAPPER) Wrapper<ShopEntity> queryWrapper
|
||||
);
|
||||
|
||||
@Select("SELECT * " +
|
||||
"FROM shop " +
|
||||
"ORDER BY shop_id DESC " +
|
||||
"LIMIT 1")
|
||||
ShopEntity selectFirstShop();
|
||||
|
||||
@Select("SELECT * FROM shop ORDER BY shop_id DESC")
|
||||
List<ShopEntity> selectAll();
|
||||
|
||||
@Select("SELECT * FROM shop WHERE shop_id = #{shopId} LIMIT 1")
|
||||
ShopEntity selectByShopId(Long shopId);
|
||||
|
||||
@Select("SELECT * FROM shop WHERE shop_name = #{shopName} LIMIT 1")
|
||||
ShopEntity selectByShopName(String shopName);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
public interface ShopService extends IService<ShopEntity> {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.agileboot.domain.shop.shop.db;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商店表,每个柜子属于一个商店 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author valarchie
|
||||
* @since 2025-05-09
|
||||
*/
|
||||
@Service
|
||||
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopEntity> implements ShopService {
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.shop.shop.dto;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.common.annotation.ExcelColumn;
|
||||
import com.agileboot.common.annotation.ExcelSheet;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@ExcelSheet(name = "商店列表")
|
||||
@Data
|
||||
public class ShopDTO {
|
||||
|
||||
public ShopDTO(ShopEntity entity) {
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ExcelColumn(name = "商店ID")
|
||||
private Long shopId;
|
||||
|
||||
@ExcelColumn(name = "商店名称")
|
||||
private String shopName;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.agileboot.domain.shop.shop.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.agileboot.domain.shop.shop.command.AddShopCommand;
|
||||
import com.agileboot.domain.shop.shop.command.UpdateShopCommand;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ShopModel extends ShopEntity {
|
||||
|
||||
private ShopService shopService;
|
||||
|
||||
public ShopModel(ShopEntity entity, ShopService shopService) {
|
||||
this(shopService);
|
||||
if (entity != null) {
|
||||
BeanUtil.copyProperties(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
public ShopModel(ShopService shopService) {
|
||||
this.shopService = shopService;
|
||||
}
|
||||
|
||||
public void loadAddCommand(AddShopCommand command) {
|
||||
if (command != null) {
|
||||
BeanUtil.copyProperties(command, this, "id");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUpdateCommand(UpdateShopCommand command) {
|
||||
if (command != null) {
|
||||
loadAddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileboot.domain.shop.shop.model;
|
||||
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.shop.shop.db.ShopEntity;
|
||||
import com.agileboot.domain.shop.shop.db.ShopService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ShopModelFactory {
|
||||
|
||||
private final ShopService shopService;
|
||||
|
||||
public ShopModel loadById(Long shopId) {
|
||||
ShopEntity entity = shopService.getById(shopId);
|
||||
if (entity == null) {
|
||||
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, shopId, "店铺");
|
||||
}
|
||||
return new ShopModel(entity, shopService);
|
||||
}
|
||||
|
||||
public ShopModel create() {
|
||||
return new ShopModel(shopService);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.agileboot.domain.shop.shop.query;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchShopQuery<T> extends AbstractPageQuery<T> {
|
||||
|
||||
private String shopName;
|
||||
private String enable;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
@Override
|
||||
public QueryWrapper<T> addQueryCondition() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
queryWrapper
|
||||
.like(StrUtil.isNotEmpty(shopName), "shop_name", shopName)
|
||||
.eq(StrUtil.isNotEmpty(enable), "enable", enable)
|
||||
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
|
||||
|
||||
this.timeRangeColumn = "create_time";
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.agileboot.domain.shop.shop.db.ShopMapper">
|
||||
|
||||
</mapper>
|
|
@ -61,7 +61,7 @@ public class CodeGenerator {
|
|||
//生成的类 放在orm子模块下的/target/generated-code目录底下
|
||||
.module("/agileboot-orm/target/generated-code")
|
||||
.parentPackage("com.agileboot")
|
||||
.tableName("mqtt_server")
|
||||
.tableName("shop")
|
||||
// 决定是否继承基类
|
||||
.isExtendsFromBaseEntity(true)
|
||||
.build();
|
||||
|
|
|
@ -19,3 +19,20 @@ CREATE TABLE `mqtt_server` (
|
|||
ALTER TABLE `smart_cabinet`
|
||||
ADD COLUMN `mqtt_server_id` BIGINT NULL COMMENT 'MQTT服务ID'
|
||||
AFTER `cabinet_type`;
|
||||
|
||||
DROP TABLE IF EXISTS `shop`;
|
||||
|
||||
CREATE TABLE `shop` (
|
||||
`shop_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`shop_name` VARCHAR(100) NOT NULL COMMENT '商店名称',
|
||||
`creator_id` BIGINT NULL DEFAULT 0 COMMENT '创建者ID',
|
||||
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater_id` BIGINT NULL DEFAULT 0 COMMENT '更新者ID',
|
||||
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
|
||||
PRIMARY KEY (`shop_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商店表,每个柜子属于一个商店';
|
||||
|
||||
ALTER TABLE `smart_cabinet`
|
||||
ADD COLUMN `shop_id` BIGINT NULL COMMENT '归属商店ID'
|
||||
AFTER `cabinet_type`;
|
Loading…
Reference in New Issue