25 changed files with 1199 additions and 193 deletions
@ -0,0 +1,88 @@
|
||||
package com.mh.web.controller.device; |
||||
|
||||
import com.mh.common.annotation.Log; |
||||
import com.mh.common.core.controller.BaseController; |
||||
import com.mh.common.core.domain.AjaxResult; |
||||
import com.mh.common.core.domain.entity.DeviceLedger; |
||||
import com.mh.common.core.page.TableDataInfo; |
||||
import com.mh.common.enums.BusinessType; |
||||
import com.mh.system.service.device.IDeviceLedgerService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备台账管理 |
||||
* @date 2025-01-10 16:38:04 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/device/ledger") |
||||
public class DeviceLedgerController extends BaseController { |
||||
|
||||
@Autowired |
||||
private IDeviceLedgerService deviceLedgerService; |
||||
|
||||
/** |
||||
* 获取设备台账列表内容数据 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ledger:list')") |
||||
@GetMapping("/list") |
||||
public TableDataInfo list(DeviceLedger ledgerInfo) |
||||
{ |
||||
startPage(); |
||||
List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(ledgerInfo); |
||||
return getDataTable(list); |
||||
} |
||||
|
||||
/** |
||||
* 根据设备台账id获取详细信息 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ledger:query')") |
||||
@GetMapping(value = "/{ledgerId}") |
||||
public AjaxResult getInfo(@PathVariable String ledgerId) |
||||
{ |
||||
return success(deviceLedgerService.selectDeviceLedgerById(ledgerId)); |
||||
} |
||||
|
||||
/** |
||||
* 新增设备台账 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ledger:add')") |
||||
@Log(title = "设备台账管理", businessType = BusinessType.INSERT) |
||||
@PostMapping |
||||
public AjaxResult add(@Validated @RequestBody DeviceLedger deviceLedger) |
||||
{ |
||||
deviceLedger.setCreateBy(getUsername()); |
||||
return toAjax(deviceLedgerService.insertDeviceLedger(deviceLedger)); |
||||
} |
||||
|
||||
/** |
||||
* 修改设备台账信息 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ledger:edit')") |
||||
@Log(title = "设备台账管理", businessType = BusinessType.UPDATE) |
||||
@PutMapping |
||||
public AjaxResult edit(@Validated @RequestBody DeviceLedger deviceLedger) |
||||
{ |
||||
deviceLedger.setUpdateBy(getUsername()); |
||||
return toAjax(deviceLedgerService.updateDeviceLedger(deviceLedger)); |
||||
} |
||||
|
||||
/** |
||||
* 删除设备台账管理 |
||||
*/ |
||||
@PreAuthorize("@ss.hasPermi('system:ledger:remove')") |
||||
@Log(title = "设备台账管理", businessType = BusinessType.DELETE) |
||||
@DeleteMapping("/{ledgerIds}") |
||||
public AjaxResult remove(@PathVariable String[] ledgerIds) |
||||
{ |
||||
return toAjax(deviceLedgerService.deleteDeviceLedgerByIds(ledgerIds)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.mh; |
||||
|
||||
import com.mh.common.core.domain.entity.SysUser; |
||||
import com.mh.system.service.ISysUserService; |
||||
import com.mh.system.service.device.IDeviceQrManageService; |
||||
import org.checkerframework.checker.units.qual.A; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 测试类 |
||||
* @date 2025-01-10 11:28:36 |
||||
*/ |
||||
@SpringBootTest |
||||
public class MHApplicationTest { |
||||
|
||||
@Autowired |
||||
private IDeviceQrManageService deviceQrManageService; |
||||
|
||||
@Autowired |
||||
private ISysUserService sysUserService; |
||||
|
||||
@Test |
||||
public void test() throws Exception { |
||||
SysUser sysUser = sysUserService.selectUserById(1L); |
||||
System.out.println(sysUser); |
||||
deviceQrManageService.createQrCode(10, "admin"); |
||||
} |
||||
} |
@ -0,0 +1,254 @@
|
||||
package com.mh.common.core.domain.entity; |
||||
|
||||
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 com.fasterxml.jackson.annotation.JsonInclude; |
||||
import com.mh.common.core.domain.BaseEntity; |
||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||
|
||||
import java.util.Date; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备二维码维护管理 |
||||
* @date 2025-01-09 16:42:51 |
||||
*/ |
||||
@TableName("device_ledger") |
||||
public class DeviceLedger extends BaseEntity { |
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID) |
||||
private String id; |
||||
|
||||
/** |
||||
* 设备名称 |
||||
*/ |
||||
private String deviceName; |
||||
|
||||
/** |
||||
* 设备规格型号 |
||||
*/ |
||||
private String modelSpecs; |
||||
|
||||
/** |
||||
* 设备资产编号 |
||||
*/ |
||||
private String assetNum; |
||||
|
||||
/** |
||||
* 设备二维码id |
||||
*/ |
||||
private String qrCodeId; |
||||
|
||||
/** |
||||
* 设备的预计使用寿命 |
||||
*/ |
||||
private String serviceLife; |
||||
|
||||
/** |
||||
* 设备所属类型(字典值获取) |
||||
*/ |
||||
private String deviceType; |
||||
|
||||
/** |
||||
* 设备的技术参数描述 |
||||
*/ |
||||
private String techParams; |
||||
|
||||
/** |
||||
* 设备相关的技术文档链接或文件名 |
||||
*/ |
||||
private String techDoc; |
||||
|
||||
/** |
||||
* 设备的安装日期和时间 |
||||
*/ |
||||
private Date installTime; |
||||
|
||||
/** |
||||
* 二维码状态:0:已绑定,1:未绑定 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 是否是需要采集(0:是,1:不采集) |
||||
*/ |
||||
private Integer isCollection; |
||||
|
||||
/** |
||||
* 是否计算能效(0:计算,1不计算) |
||||
*/ |
||||
private Integer isCalcEnergy; |
||||
|
||||
@TableField(exist = false) |
||||
private String searchValue; |
||||
|
||||
/** 备注 */ |
||||
@TableField(exist = false) |
||||
private String remark; |
||||
|
||||
/** 请求参数 */ |
||||
@TableField(exist = false) |
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
||||
private Map<String, Object> params; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getDeviceName() { |
||||
return deviceName; |
||||
} |
||||
|
||||
public void setDeviceName(String deviceName) { |
||||
this.deviceName = deviceName; |
||||
} |
||||
|
||||
public String getModelSpecs() { |
||||
return modelSpecs; |
||||
} |
||||
|
||||
public void setModelSpecs(String modelSpecs) { |
||||
this.modelSpecs = modelSpecs; |
||||
} |
||||
|
||||
public String getAssetNum() { |
||||
return assetNum; |
||||
} |
||||
|
||||
public void setAssetNum(String assetNum) { |
||||
this.assetNum = assetNum; |
||||
} |
||||
|
||||
public String getQrCodeId() { |
||||
return qrCodeId; |
||||
} |
||||
|
||||
public void setQrCodeId(String qrCodeId) { |
||||
this.qrCodeId = qrCodeId; |
||||
} |
||||
|
||||
public String getServiceLife() { |
||||
return serviceLife; |
||||
} |
||||
|
||||
public void setServiceLife(String serviceLife) { |
||||
this.serviceLife = serviceLife; |
||||
} |
||||
|
||||
public String getDeviceType() { |
||||
return deviceType; |
||||
} |
||||
|
||||
public void setDeviceType(String deviceType) { |
||||
this.deviceType = deviceType; |
||||
} |
||||
|
||||
public String getTechParams() { |
||||
return techParams; |
||||
} |
||||
|
||||
public void setTechParams(String techParams) { |
||||
this.techParams = techParams; |
||||
} |
||||
|
||||
public String getTechDoc() { |
||||
return techDoc; |
||||
} |
||||
|
||||
public void setTechDoc(String techDoc) { |
||||
this.techDoc = techDoc; |
||||
} |
||||
|
||||
public Date getInstallTime() { |
||||
return installTime; |
||||
} |
||||
|
||||
public void setInstallTime(Date installTime) { |
||||
this.installTime = installTime; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public Integer getIsCollection() { |
||||
return isCollection; |
||||
} |
||||
|
||||
public void setIsCollection(Integer isCollection) { |
||||
this.isCollection = isCollection; |
||||
} |
||||
|
||||
public Integer getIsCalcEnergy() { |
||||
return isCalcEnergy; |
||||
} |
||||
|
||||
public void setIsCalcEnergy(Integer isCalcEnergy) { |
||||
this.isCalcEnergy = isCalcEnergy; |
||||
} |
||||
|
||||
@Override |
||||
public String getSearchValue() { |
||||
return searchValue; |
||||
} |
||||
|
||||
@Override |
||||
public void setSearchValue(String searchValue) { |
||||
this.searchValue = searchValue; |
||||
} |
||||
|
||||
@Override |
||||
public String getRemark() { |
||||
return remark; |
||||
} |
||||
|
||||
@Override |
||||
public void setRemark(String remark) { |
||||
this.remark = remark; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Object> getParams() { |
||||
return params; |
||||
} |
||||
|
||||
@Override |
||||
public void setParams(Map<String, Object> params) { |
||||
this.params = params; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new ToStringBuilder(this) |
||||
.append("id", id) |
||||
.append("deviceName", deviceName) |
||||
.append("modelSpecs", modelSpecs) |
||||
.append("assetNum", assetNum) |
||||
.append("qrCodeId", qrCodeId) |
||||
.append("serviceLife", serviceLife) |
||||
.append("deviceType", deviceType) |
||||
.append("techParams", techParams) |
||||
.append("techDoc", techDoc) |
||||
.append("installTime", installTime) |
||||
.append("status", status) |
||||
.append("isCollection", isCollection) |
||||
.append("isCalcEnergy", isCalcEnergy) |
||||
.append("searchValue", searchValue) |
||||
.append("remark", remark) |
||||
.append("params", params) |
||||
.toString(); |
||||
} |
||||
} |
@ -0,0 +1,140 @@
|
||||
package com.mh.common.utils.qrcode; |
||||
|
||||
import com.google.zxing.*; |
||||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource; |
||||
import com.google.zxing.common.BitMatrix; |
||||
import com.google.zxing.common.HybridBinarizer; |
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
import java.awt.*; |
||||
import java.awt.geom.RoundRectangle2D; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.OutputStream; |
||||
import java.util.Hashtable; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 二维码工具类 |
||||
* @date 2025-01-10 11:01:32 |
||||
*/ |
||||
public class QrCodeUtil { |
||||
//编码格式,采用utf-8
|
||||
private static final String UNICODE = "utf-8"; |
||||
//图片格式
|
||||
private static final String FORMAT = "JPG"; |
||||
//二维码宽度像素pixels数量
|
||||
private static final int QRCODE_WIDTH = 300; |
||||
//二维码高度像素pixels数量
|
||||
private static final int QRCODE_HEIGHT = 300; |
||||
//LOGO宽度像素pixels数量
|
||||
private static final int LOGO_WIDTH = 100; |
||||
//LOGO高度像素pixels数量
|
||||
private static final int LOGO_HEIGHT = 100; |
||||
|
||||
//生成二维码图片
|
||||
//content 二维码内容
|
||||
//logoPath logo图片地址
|
||||
private static BufferedImage createImage(String content, String logoPath) throws Exception { |
||||
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); |
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); |
||||
hints.put(EncodeHintType.CHARACTER_SET, UNICODE); |
||||
hints.put(EncodeHintType.MARGIN, 1); |
||||
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_WIDTH, QRCODE_HEIGHT, |
||||
hints); |
||||
int width = bitMatrix.getWidth(); |
||||
int height = bitMatrix.getHeight(); |
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
||||
for (int x = 0; x < width; x++) { |
||||
for (int y = 0; y < height; y++) { |
||||
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); |
||||
} |
||||
} |
||||
if (logoPath == null || "".equals(logoPath)) { |
||||
return image; |
||||
} |
||||
// 插入图片
|
||||
QrCodeUtil.insertImage(image, logoPath); |
||||
return image; |
||||
} |
||||
|
||||
//在图片上插入LOGO
|
||||
//source 二维码图片内容
|
||||
//logoPath LOGO图片地址
|
||||
private static void insertImage(BufferedImage source, String logoPath) throws Exception { |
||||
File file = new File(logoPath); |
||||
if (!file.exists()) { |
||||
throw new Exception("logo file not found."); |
||||
} |
||||
Image src = ImageIO.read(new File(logoPath)); |
||||
int width = src.getWidth(null); |
||||
int height = src.getHeight(null); |
||||
if (width > LOGO_WIDTH) { |
||||
width = LOGO_WIDTH; |
||||
} |
||||
if (height > LOGO_HEIGHT) { |
||||
height = LOGO_HEIGHT; |
||||
} |
||||
Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); |
||||
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
||||
Graphics g = tag.getGraphics(); |
||||
g.drawImage(image, 0, 0, null); // 绘制缩小后的图
|
||||
g.dispose(); |
||||
src = image; |
||||
// 插入LOGO
|
||||
Graphics2D graph = source.createGraphics(); |
||||
int x = (QRCODE_WIDTH - width) / 2; |
||||
int y = (QRCODE_HEIGHT - height) / 2; |
||||
graph.drawImage(src, x, y, width, height, null); |
||||
Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); |
||||
graph.setStroke(new BasicStroke(3f)); |
||||
graph.draw(shape); |
||||
graph.dispose(); |
||||
} |
||||
|
||||
//生成带logo的二维码图片,保存到指定的路径
|
||||
// content 二维码内容
|
||||
// logoPath logo图片地址
|
||||
// destPath 生成图片的存储路径
|
||||
public static String save(String content, String logoPath, String destPath) throws Exception { |
||||
BufferedImage image = QrCodeUtil.createImage(content, logoPath); |
||||
File file = new File(destPath); |
||||
String path = file.getAbsolutePath(); |
||||
File filePath = new File(path); |
||||
if (!filePath.exists() && !filePath.isDirectory()) { |
||||
filePath.mkdirs(); |
||||
} |
||||
String fileName = file.getName(); |
||||
fileName = fileName.substring(0, fileName.indexOf(".")>0?fileName.indexOf("."):fileName.length()) |
||||
+ "." + FORMAT.toLowerCase(); |
||||
System.out.println("destPath:"+destPath); |
||||
ImageIO.write(image, FORMAT, new File(destPath)); |
||||
return fileName; |
||||
} |
||||
|
||||
//生成二维码图片,直接输出到OutputStream
|
||||
public static void encode(String content, String logoPath, OutputStream output) |
||||
throws Exception { |
||||
BufferedImage image = QrCodeUtil.createImage(content, logoPath); |
||||
ImageIO.write(image, FORMAT, output); |
||||
} |
||||
|
||||
//解析二维码图片,得到包含的内容
|
||||
public static String decode(String path) throws Exception { |
||||
File file = new File(path); |
||||
BufferedImage image = ImageIO.read(file); |
||||
if (image == null) { |
||||
return null; |
||||
} |
||||
BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image); |
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); |
||||
Result result; |
||||
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); |
||||
hints.put(DecodeHintType.CHARACTER_SET, UNICODE); |
||||
result = new MultiFormatReader().decode(bitmap, hints); |
||||
return result.getText(); |
||||
} |
||||
} |
@ -1,132 +1,132 @@
|
||||
package com.mh.framework.config; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import javax.sql.DataSource; |
||||
import org.apache.ibatis.io.VFS; |
||||
import org.apache.ibatis.session.SqlSessionFactory; |
||||
import org.mybatis.spring.SqlSessionFactoryBean; |
||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.core.io.DefaultResourceLoader; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
||||
import org.springframework.core.io.support.ResourcePatternResolver; |
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory; |
||||
import org.springframework.core.type.classreading.MetadataReader; |
||||
import org.springframework.core.type.classreading.MetadataReaderFactory; |
||||
import org.springframework.util.ClassUtils; |
||||
import com.mh.common.utils.StringUtils; |
||||
|
||||
/** |
||||
* Mybatis支持*匹配扫描包 |
||||
* |
||||
* @author mh |
||||
*/ |
||||
@Configuration |
||||
public class MyBatisConfig |
||||
{ |
||||
@Autowired |
||||
private Environment env; |
||||
|
||||
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class"; |
||||
|
||||
public static String setTypeAliasesPackage(String typeAliasesPackage) |
||||
{ |
||||
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); |
||||
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); |
||||
List<String> allResult = new ArrayList<String>(); |
||||
try |
||||
{ |
||||
for (String aliasesPackage : typeAliasesPackage.split(",")) |
||||
{ |
||||
List<String> result = new ArrayList<String>(); |
||||
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX |
||||
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN; |
||||
Resource[] resources = resolver.getResources(aliasesPackage); |
||||
if (resources != null && resources.length > 0) |
||||
{ |
||||
MetadataReader metadataReader = null; |
||||
for (Resource resource : resources) |
||||
{ |
||||
if (resource.isReadable()) |
||||
{ |
||||
metadataReader = metadataReaderFactory.getMetadataReader(resource); |
||||
try |
||||
{ |
||||
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); |
||||
} |
||||
catch (ClassNotFoundException e) |
||||
{ |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (result.size() > 0) |
||||
{ |
||||
HashSet<String> hashResult = new HashSet<String>(result); |
||||
allResult.addAll(hashResult); |
||||
} |
||||
} |
||||
if (allResult.size() > 0) |
||||
{ |
||||
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0])); |
||||
} |
||||
else |
||||
{ |
||||
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包"); |
||||
} |
||||
} |
||||
catch (IOException e) |
||||
{ |
||||
e.printStackTrace(); |
||||
} |
||||
return typeAliasesPackage; |
||||
} |
||||
|
||||
public Resource[] resolveMapperLocations(String[] mapperLocations) |
||||
{ |
||||
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); |
||||
List<Resource> resources = new ArrayList<Resource>(); |
||||
if (mapperLocations != null) |
||||
{ |
||||
for (String mapperLocation : mapperLocations) |
||||
{ |
||||
try |
||||
{ |
||||
Resource[] mappers = resourceResolver.getResources(mapperLocation); |
||||
resources.addAll(Arrays.asList(mappers)); |
||||
} |
||||
catch (IOException e) |
||||
{ |
||||
// ignore
|
||||
} |
||||
} |
||||
} |
||||
return resources.toArray(new Resource[resources.size()]); |
||||
} |
||||
|
||||
@Bean |
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception |
||||
{ |
||||
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage"); |
||||
String mapperLocations = env.getProperty("mybatis.mapperLocations"); |
||||
String configLocation = env.getProperty("mybatis.configLocation"); |
||||
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage); |
||||
VFS.addImplClass(SpringBootVFS.class); |
||||
|
||||
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); |
||||
sessionFactory.setDataSource(dataSource); |
||||
sessionFactory.setTypeAliasesPackage(typeAliasesPackage); |
||||
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); |
||||
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); |
||||
return sessionFactory.getObject(); |
||||
} |
||||
} |
||||
//package com.mh.framework.config;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.HashSet;
|
||||
//import java.util.List;
|
||||
//import javax.sql.DataSource;
|
||||
//import org.apache.ibatis.io.VFS;
|
||||
//import org.apache.ibatis.session.SqlSessionFactory;
|
||||
//import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
//import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.core.env.Environment;
|
||||
//import org.springframework.core.io.DefaultResourceLoader;
|
||||
//import org.springframework.core.io.Resource;
|
||||
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
//import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
//import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
//import org.springframework.core.type.classreading.MetadataReader;
|
||||
//import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
//import org.springframework.util.ClassUtils;
|
||||
//import com.mh.common.utils.StringUtils;
|
||||
//
|
||||
///**
|
||||
// * Mybatis支持*匹配扫描包
|
||||
// *
|
||||
// * @author mh
|
||||
// */
|
||||
//@Configuration
|
||||
//public class MyBatisConfig
|
||||
//{
|
||||
// @Autowired
|
||||
// private Environment env;
|
||||
//
|
||||
// static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
|
||||
//
|
||||
// public static String setTypeAliasesPackage(String typeAliasesPackage)
|
||||
// {
|
||||
// ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
|
||||
// MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
|
||||
// List<String> allResult = new ArrayList<String>();
|
||||
// try
|
||||
// {
|
||||
// for (String aliasesPackage : typeAliasesPackage.split(","))
|
||||
// {
|
||||
// List<String> result = new ArrayList<String>();
|
||||
// aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
|
||||
// + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
|
||||
// Resource[] resources = resolver.getResources(aliasesPackage);
|
||||
// if (resources != null && resources.length > 0)
|
||||
// {
|
||||
// MetadataReader metadataReader = null;
|
||||
// for (Resource resource : resources)
|
||||
// {
|
||||
// if (resource.isReadable())
|
||||
// {
|
||||
// metadataReader = metadataReaderFactory.getMetadataReader(resource);
|
||||
// try
|
||||
// {
|
||||
// result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
|
||||
// }
|
||||
// catch (ClassNotFoundException e)
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (result.size() > 0)
|
||||
// {
|
||||
// HashSet<String> hashResult = new HashSet<String>(result);
|
||||
// allResult.addAll(hashResult);
|
||||
// }
|
||||
// }
|
||||
// if (allResult.size() > 0)
|
||||
// {
|
||||
// typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
|
||||
// }
|
||||
// }
|
||||
// catch (IOException e)
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return typeAliasesPackage;
|
||||
// }
|
||||
//
|
||||
// public Resource[] resolveMapperLocations(String[] mapperLocations)
|
||||
// {
|
||||
// ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
||||
// List<Resource> resources = new ArrayList<Resource>();
|
||||
// if (mapperLocations != null)
|
||||
// {
|
||||
// for (String mapperLocation : mapperLocations)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Resource[] mappers = resourceResolver.getResources(mapperLocation);
|
||||
// resources.addAll(Arrays.asList(mappers));
|
||||
// }
|
||||
// catch (IOException e)
|
||||
// {
|
||||
// // ignore
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return resources.toArray(new Resource[resources.size()]);
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
|
||||
// {
|
||||
// String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
|
||||
// String mapperLocations = env.getProperty("mybatis.mapperLocations");
|
||||
// String configLocation = env.getProperty("mybatis.configLocation");
|
||||
// typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
|
||||
// VFS.addImplClass(SpringBootVFS.class);
|
||||
//
|
||||
// final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||
// sessionFactory.setDataSource(dataSource);
|
||||
// sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
|
||||
// sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
|
||||
// sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
|
||||
// return sessionFactory.getObject();
|
||||
// }
|
||||
//}
|
@ -0,0 +1,134 @@
|
||||
package com.mh.framework.config; |
||||
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; |
||||
import com.mh.common.utils.StringUtils; |
||||
import org.apache.ibatis.io.VFS; |
||||
import org.apache.ibatis.session.SqlSessionFactory; |
||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.core.io.DefaultResourceLoader; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
||||
import org.springframework.core.io.support.ResourcePatternResolver; |
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory; |
||||
import org.springframework.core.type.classreading.MetadataReader; |
||||
import org.springframework.core.type.classreading.MetadataReaderFactory; |
||||
import org.springframework.util.ClassUtils; |
||||
|
||||
import javax.sql.DataSource; |
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Mybatis支持*匹配扫描包 |
||||
* |
||||
* @author mh |
||||
*/ |
||||
@Configuration |
||||
public class MyBatisPlusConfig |
||||
{ |
||||
@Autowired |
||||
private Environment env; |
||||
|
||||
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class"; |
||||
|
||||
public static String setTypeAliasesPackage(String typeAliasesPackage) |
||||
{ |
||||
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); |
||||
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); |
||||
List<String> allResult = new ArrayList<String>(); |
||||
try |
||||
{ |
||||
for (String aliasesPackage : typeAliasesPackage.split(",")) |
||||
{ |
||||
List<String> result = new ArrayList<String>(); |
||||
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX |
||||
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN; |
||||
Resource[] resources = resolver.getResources(aliasesPackage); |
||||
if (resources != null && resources.length > 0) |
||||
{ |
||||
MetadataReader metadataReader = null; |
||||
for (Resource resource : resources) |
||||
{ |
||||
if (resource.isReadable()) |
||||
{ |
||||
metadataReader = metadataReaderFactory.getMetadataReader(resource); |
||||
try |
||||
{ |
||||
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); |
||||
} |
||||
catch (ClassNotFoundException e) |
||||
{ |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (result.size() > 0) |
||||
{ |
||||
HashSet<String> hashResult = new HashSet<String>(result); |
||||
allResult.addAll(hashResult); |
||||
} |
||||
} |
||||
if (allResult.size() > 0) |
||||
{ |
||||
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0])); |
||||
} |
||||
else |
||||
{ |
||||
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包"); |
||||
} |
||||
} |
||||
catch (IOException e) |
||||
{ |
||||
e.printStackTrace(); |
||||
} |
||||
return typeAliasesPackage; |
||||
} |
||||
|
||||
public Resource[] resolveMapperLocations(String[] mapperLocations) |
||||
{ |
||||
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); |
||||
List<Resource> resources = new ArrayList<Resource>(); |
||||
if (mapperLocations != null) |
||||
{ |
||||
for (String mapperLocation : mapperLocations) |
||||
{ |
||||
try |
||||
{ |
||||
Resource[] mappers = resourceResolver.getResources(mapperLocation); |
||||
resources.addAll(Arrays.asList(mappers)); |
||||
} |
||||
catch (IOException e) |
||||
{ |
||||
// ignore
|
||||
} |
||||
} |
||||
} |
||||
return resources.toArray(new Resource[resources.size()]); |
||||
} |
||||
|
||||
@Bean |
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception |
||||
{ |
||||
String typeAliasesPackage = env.getProperty("mybatis-plus.type-aliases-package"); |
||||
String mapperLocations = env.getProperty("mybatis-plus.mapper-locations"); |
||||
String configLocation = env.getProperty("mybatis-plus.config-location"); |
||||
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage); |
||||
VFS.addImplClass(SpringBootVFS.class); |
||||
|
||||
// 如果想使用mybatis-plus自带方法,需要改成使用 MybatisSqlSessionFactoryBean,不然会报 Invalid bound statement (not found)
|
||||
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean(); |
||||
sessionFactory.setDataSource(dataSource); |
||||
sessionFactory.setTypeAliasesPackage(typeAliasesPackage); |
||||
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); |
||||
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); |
||||
return sessionFactory.getObject(); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.mh.system.mapper.device; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.mh.common.core.domain.entity.DeviceLedger; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备台账管理 |
||||
* @date 2025-01-10 16:59:47 |
||||
*/ |
||||
@Mapper |
||||
public interface DeviceLedgerMapper extends BaseMapper<DeviceLedger> { |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.mh.system.service.device; |
||||
|
||||
import com.mh.common.core.domain.entity.DeviceLedger; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备台账管理 |
||||
* @date 2025-01-10 16:54:29 |
||||
*/ |
||||
public interface IDeviceLedgerService { |
||||
List<DeviceLedger> selectDeviceLedgerList(DeviceLedger ledgerInfo); |
||||
|
||||
DeviceLedger selectDeviceLedgerById(String ledgerId); |
||||
|
||||
int insertDeviceLedger(DeviceLedger gatewayManage); |
||||
|
||||
int updateDeviceLedger(DeviceLedger gatewayManage); |
||||
|
||||
int deleteDeviceLedgerByIds(String[] ledgerIds); |
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.mh.system.service.device.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.mh.common.core.domain.entity.DeviceLedger; |
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.system.mapper.device.DeviceLedgerMapper; |
||||
import com.mh.system.service.device.IDeviceLedgerService; |
||||
import jakarta.annotation.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project EEMCS |
||||
* @description 设备台账管理 |
||||
* @date 2025-01-10 16:55:28 |
||||
*/ |
||||
@Service |
||||
public class DeviceLedgerServiceImpl implements IDeviceLedgerService { |
||||
|
||||
@Resource |
||||
private DeviceLedgerMapper deviceLedgerMapper; |
||||
|
||||
@Override |
||||
public List<DeviceLedger> selectDeviceLedgerList(DeviceLedger ledgerInfo) { |
||||
if (ledgerInfo == null) { |
||||
return List.of(); |
||||
} |
||||
QueryWrapper<DeviceLedger> queryWrapper = new QueryWrapper<>(); |
||||
// 设备名称
|
||||
if (!StringUtils.isEmpty(ledgerInfo.getDeviceName())) { |
||||
queryWrapper.like("device_name", ledgerInfo.getDeviceName()); |
||||
} |
||||
// 资产编号
|
||||
if (!StringUtils.isEmpty(ledgerInfo.getAssetNum())) { |
||||
queryWrapper.like("asset_num", ledgerInfo.getAssetNum()); |
||||
} |
||||
// 设备类型
|
||||
if (!StringUtils.isEmpty(ledgerInfo.getDeviceType())) { |
||||
queryWrapper.like("device_type", ledgerInfo.getDeviceType()); |
||||
} |
||||
// 出入库时间范围
|
||||
if (!ledgerInfo.getParams().isEmpty()) { |
||||
queryWrapper.between("create_time", ledgerInfo.getParams().get("beginTime"), ledgerInfo.getParams().get("endTime")); |
||||
} |
||||
return deviceLedgerMapper.selectList(queryWrapper); |
||||
} |
||||
|
||||
@Override |
||||
public DeviceLedger selectDeviceLedgerById(String ledgerId) { |
||||
return deviceLedgerMapper.selectById(ledgerId); |
||||
} |
||||
|
||||
@Override |
||||
public int insertDeviceLedger(DeviceLedger deviceLedger) { |
||||
return deviceLedgerMapper.insert(deviceLedger); |
||||
} |
||||
|
||||
@Override |
||||
public int updateDeviceLedger(DeviceLedger deviceLedger) { |
||||
return deviceLedgerMapper.updateById(deviceLedger); |
||||
} |
||||
|
||||
@Override |
||||
public int deleteDeviceLedgerByIds(String[] ledgerIds) { |
||||
if (ledgerIds != null && ledgerIds.length > 0) { |
||||
for (String cmpId : ledgerIds) { |
||||
deviceLedgerMapper.deleteById(cmpId); |
||||
} |
||||
return ledgerIds.length; |
||||
} |
||||
return 0; |
||||
} |
||||
} |
Loading…
Reference in new issue