Commit 535fb75e authored by liqin's avatar liqin 💬

bug fixed

parent 09639ff2
package cn.wisenergy.chnmuseum.party.common.util;
import javax.crypto.Cipher;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Base64;
public final class RSAUtils {
private static final String KEY_ALGORITHM = "RSA";
private static final int KEY_SIZE = 2048;
public static final String SIGNATURE_ALGORITHM = "SHA256withRSA";
public static final String RSA_TYPE = "RSA/ECB/PKCS1Padding";
private final static String PUBLIC_KEY_NAME = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsTVgqPjswjCKU7kjOfZO/jB1Oiz3zrW0kLfjBiRXHnXrm3Br4cgpA78snK/isaVykOBJYL549JkgHqTo17RSdqdS2i0rjzEUtKEotSpoP9XzNxt3ufKSq1MxBU5ZVuJTJ4Juat9RKcgNvhTc5NYMjF7PsBrrqPolgOd9Y5VyMaNRch+3owlDNzck0zWXAWas8KNJuV68ZH6hqu0Lb0QfrWETkm4o3ah7A1ss/UB//XSg0wipMa2em9WI6hUxW87JKR3W63dx89q9aP589UeE5XpamDhr1fglIpzeS/SdA61cY4K5v9v+mGxI3jePc6RSETvwc8P68/XNViSgT+uJAwIDAQAB";
private final static String PRIVATE_KEY_NAME = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCxNWCo+OzCMIpTuSM59k7+MHU6LPfOtbSQt+MGJFcedeubcGvhyCkDvyycr+KxpXKQ4Elgvnj0mSAepOjXtFJ2p1LaLSuPMRS0oSi1Kmg/1fM3G3e58pKrUzEFTllW4lMngm5q31EpyA2+FNzk1gyMXs+wGuuo+iWA531jlXIxo1FyH7ejCUM3NyTTNZcBZqzwo0m5XrxkfqGq7QtvRB+tYROSbijdqHsDWyz9QH/9dKDTCKkxrZ6b1YjqFTFbzskpHdbrd3Hz2r1o/nz1R4TlelqYOGvV+CUinN5L9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ut6tD08WWzUc24W5VdZMlfKVKwpOVJ5a0CgYByPWRuA7yJ+cWkmZl9yMCpNziSJgm7A1TwI9SRpfgx+azrLVSPZAYKzwmpsiOmuD/SSyDS7YE2d4QT/C+jbGlGYa3pGN7XUqmJVPhn9sJzoCHQf5LPbS5cLRC0c0qjFwsOw5hTVa0pPTiyRjF7xKc4yzBotifs4VdhXSH5GurFJg==";
private final static String SERVICE_PUBLIC_KEY_NAME = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsTVgqPjswjCKU7kjOfZO/jB1Oiz3zrW0kLfjBiRXHnXrm3Br4cgpA78snK/isaVykOBJYL549JkgHqTo17RSdqdS2i0rjzEUtKEotSpoP9XzNxt3ufKSq1MxBU5ZVuJTJ4Juat9RKcgNvhTc5NYMjF7PsBrrqPolgOd9Y5VyMaNRch+3owlDNzck0zWXAWas8KNJuV68ZH6hqu0Lb0QfrWETkm4o3ah7A1ss/UB//XSg0wipMa2em9WI6hUxW87JKR3W63dx89q9aP589UeE5XpamDhr1fglIpzeS/SdA61cY4K5v9v+mGxI3jePc6RSETvwc8P68/XNViSgT+uJAwIDAQAB";
/**
* 生成公、私钥
* 根据需要返回String或byte[]类型
*
* @return
*/
public static ArrayList<String> createRSAKeys() {
ArrayList<String> array = new ArrayList<>();
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
keyPairGenerator.initialize(KEY_SIZE, new SecureRandom());
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
//获取公、私钥值
String publicKeyValue = Base64.getEncoder().encodeToString(publicKey.getEncoded());
String privateKeyValue = Base64.getEncoder().encodeToString(privateKey.getEncoded());
//存入
array.add(publicKeyValue);
array.add(privateKeyValue);
} catch (Exception e) {
e.printStackTrace();
}
return array;
}
//获取本地RSA公钥
public static PublicKey getPublicKey() {
try {
return getPublicKey(PUBLIC_KEY_NAME);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//获取本地RSA公钥
public static String getPublicKeyString() {
try {
return PUBLIC_KEY_NAME;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//获取服务器RSA公钥
public static PublicKey getServicePublicKey() {
try {
return getPublicKey(SERVICE_PUBLIC_KEY_NAME);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//获取RSA公钥 根据钥匙字段
public static PublicKey getPublicKey(String key) {
try {
byte[] byteKey = Base64.getDecoder().decode(key);
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(byteKey);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
return keyFactory.generatePublic(x509EncodedKeySpec);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//获取RSA私钥 根据钥匙字段
private static PrivateKey getPrivateKey(String key) {
try {
byte[] byteKey = Base64.getDecoder().decode(key);
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(byteKey);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
return keyFactory.generatePrivate(pkcs8EncodedKeySpec);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//本地RSA私钥 签名
public static String sign(String requestData) {
String signature = null;
byte[] signed;
try {
PrivateKey privateKey = getPrivateKey(PRIVATE_KEY_NAME);
Signature Sign = Signature.getInstance(SIGNATURE_ALGORITHM);
Sign.initSign(privateKey);
Sign.update(requestData.getBytes());
signed = Sign.sign();
signature = Base64.getEncoder().encodeToString(signed);
} catch (Exception e) {
e.printStackTrace();
}
return signature;
}
//公钥验证签名 base64签名 signature 签名内容requestData
public static boolean verifySign(String requestData, String signature) {
boolean verifySignSuccess = false;
try {
PublicKey publicKey = getServicePublicKey();
Signature verifySign = Signature.getInstance(SIGNATURE_ALGORITHM);
verifySign.initVerify(publicKey);
verifySign.update(requestData.getBytes());
verifySignSuccess = verifySign.verify(Base64.getDecoder().decode(signature));
} catch (Exception e) {
e.printStackTrace();
}
return verifySignSuccess;
}
public static String encrypt(String clearText) {
String encryptedBase64 = "";
try {
Key key = getServicePublicKey();
final Cipher cipher = Cipher.getInstance(RSA_TYPE);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = cipher.doFinal(clearText.getBytes(StandardCharsets.UTF_8));
encryptedBase64 = Base64.getEncoder().encodeToString(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedBase64;
}
public static String encrypt(String clearText, String publicKey) {
String encryptedBase64 = "";
try {
Key key = getPublicKey(publicKey);
final Cipher cipher = Cipher.getInstance(RSA_TYPE);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = cipher.doFinal(clearText.getBytes(StandardCharsets.UTF_8));
encryptedBase64 = Base64.getEncoder().encodeToString(encryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedBase64;
}
public static String decrypt(String encryptedBase64, String privateKey) {
String decryptedString = "";
try {
Key key = getPrivateKey(privateKey);
final Cipher cipher = Cipher.getInstance(RSA_TYPE);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedBase64);
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
decryptedString = new String(decryptedBytes);
} catch (Exception e) {
e.printStackTrace();
}
return decryptedString;
}
}
package cn.wisenergy.chnmuseum.party.common.util;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
public class SignUtils {
private static final String ALGORITHM = "RSA";
private static final String SIGN_SHA256RSA_ALGORITHMS = "SHA256WithRSA";
private static final String DEFAULT_CHARSET = "UTF-8";
private final static String PUBLIC_KEY_NAME = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsTVgqPjswjCKU7kjOfZO/jB1Oiz3zrW0kLfjBiRXHnXrm3Br4cgpA78snK/isaVykOBJYL549JkgHqTo17RSdqdS2i0rjzEUtKEotS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NXkdrtR8lw3qnTquaxqor4IQMLsZa775H2zefYuqiOnFD9W4NpjwxG7yWhtbpSgWIQSHXVDO6mIR6Qh0lAUk4AYwjEae1auZgBoM5YsKMxN7PFDUHwKBgQDS2+Jg9GP1j8cmO14J/f+wBqTme1oz4bkES9tGcFapdVdlkPf5ahVH+yDhrgGVCcO2w6sam06WrmxV4H4OV5wl94hr36NC6S2lmIIF9DuX21cZandWI5vJr6umxrlo3f5+tpSC9Ekgd7Yro44+DohlMrUbAFwm6+hSIin210hOnQKBgFMJEr02ZKhK7rhwxb5souWUJxixhiI5ZjVnULk+1KfBzxDHB0VpXVaYxnCTGNG5/kyvyDE6ycEzmTBtvJcfF7cx/J0N4ejlL5h8Cy2BdQ0KFXEnf2KOIGz4i0YvLB5Kh7u0fnFHLXpA/tNCm2D1YvQ+p2IxLNy5YzZmjChOGSwlAoGAYAyTYTDR+8DDqbGvU4PlHazZHrgfzbRLkB5xwvNXNpfh+L0BiBZ/nStSvhqCU/5/rVgSL+uA7/iCFthM84GK+mx4MxNLDiajiWQgDlBDeRgL4+Lwe0d7JnMkELNDL/a3f8bxfXmDegut6tD08WWzUc24W5VdZMlfKVKwpOVJ5a0CgYByPWRuA7yJ+cWkmZl9yMCpNziSJgm7A1TwI9SRpfgx+azrLVSPZAYKzwmpsiOmuD/SSyDS7YE2d4QT/C+jbGlGYa3pGN7XUqmJVPhn9sJzoCHQf5LPbS5cLRC0c0qjFwsOw5hTVa0pPTiyRjF7xKc4yzBotifs4VdhXSH5GurFJg==";
public static String sign(String content, String privateKey) {
try {
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey));
KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM);
PrivateKey priKey = keyFactory.generatePrivate(priPKCS8);
Signature signature = Signature.getInstance(SIGN_SHA256RSA_ALGORITHMS);
signature.initSign(priKey);
signature.update(content.getBytes(DEFAULT_CHARSET));
byte[] signed = signature.sign();
return Base64.getEncoder().encodeToString(signed);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
...@@ -21,6 +21,7 @@ public final class AesFlushingCipher { ...@@ -21,6 +21,7 @@ public final class AesFlushingCipher {
public AesFlushingCipher(int mode, byte[] secretKey, long nonce, long offset) { public AesFlushingCipher(int mode, byte[] secretKey, long nonce, long offset) {
try { try {
//cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher = Cipher.getInstance("AES/CTR/NoPadding"); cipher = Cipher.getInstance("AES/CTR/NoPadding");
blockSize = cipher.getBlockSize(); blockSize = cipher.getBlockSize();
zerosBlock = new byte[blockSize]; zerosBlock = new byte[blockSize];
......
...@@ -5,7 +5,6 @@ import java.io.IOException; ...@@ -5,7 +5,6 @@ import java.io.IOException;
public interface DataSink { public interface DataSink {
interface Factory { interface Factory {
DataSink createDataSink(); DataSink createDataSink();
} }
......
...@@ -15,49 +15,46 @@ public class VideoTestUtil { ...@@ -15,49 +15,46 @@ public class VideoTestUtil {
private static final String cipher = "3348c95c60520be7"; private static final String cipher = "3348c95c60520be7";
private static final int dataLength = 4096; private static final int dataLength = 4096;
public static final void main(String[] args){ public static void main(String[] args){
//加密视频 //加密视频
new Thread(new Runnable() { new Thread(() -> {
@Override try {
public void run() { log.info("开始加解密");
try { File f = new File(plainFilePath, "中华人民共和国成立.mp4");
log.info("开始加解密"); FileInputStream fis = new FileInputStream(f);
File f = new File(plainFilePath, "中华人民共和国成立.mp4");
FileInputStream fis = new FileInputStream(f); File encryptFile = new File(plainFilePath, "中华人民共和国成立.chnmuseum");
AesCipherDataSink encryptingDataSink = new AesCipherDataSink(
File encryptFile = new File(plainFilePath, "中华人民共和国成立.chnmuseum"); "3348c95c60520be7".getBytes(StandardCharsets.UTF_8),
AesCipherDataSink encryptingDataSink = new AesCipherDataSink( new DataSink() {
"3348c95c60520be7".getBytes(StandardCharsets.UTF_8), private FileOutputStream fileOutputStream;
new DataSink() {
private FileOutputStream fileOutputStream; @Override
public void open() throws IOException {
@Override fileOutputStream = new FileOutputStream(encryptFile);
public void open() throws IOException { }
fileOutputStream = new FileOutputStream(encryptFile);
} @Override
public void write(byte[] buffer, int offset, int length) throws IOException {
@Override fileOutputStream.write(buffer, offset, length);
public void write(byte[] buffer, int offset, int length) throws IOException { }
fileOutputStream.write(buffer, offset, length);
} @Override
public void close() throws IOException {
@Override fileOutputStream.close();
public void close() throws IOException { }
fileOutputStream.close(); });
} encryptingDataSink.open();
}); int len;
encryptingDataSink.open(); byte[] buffer = new byte[dataLength];
int len; while ((len = fis.read(buffer)) != -1) {
byte[] buffer = new byte[dataLength]; encryptingDataSink.write(buffer, 0, len);
while ((len = fis.read(buffer)) != -1) {
encryptingDataSink.write(buffer, 0, len);
}
encryptingDataSink.close();
fis.close();
log.info("加解密完成");
} catch (Exception e) {
log.info(e.getLocalizedMessage());
} }
encryptingDataSink.close();
fis.close();
log.info("加解密完成");
} catch (Exception e) {
log.info(e.getLocalizedMessage());
} }
}).start(); }).start();
} }
......
package cn.wisenergy.chnmuseum.party.model; package cn.wisenergy.chnmuseum.party.model;
import com.baomidou.mybatisplus.annotation.TableName; import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add; import java.io.Serializable;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
/** /**
* <p> * <p>
...@@ -52,23 +38,31 @@ public class TBoxOperation implements Serializable { ...@@ -52,23 +38,31 @@ public class TBoxOperation implements Serializable {
@ApiModelProperty("机顶盒所属单位id") @ApiModelProperty("机顶盒所属单位id")
@TableField("organ_id") @TableField("organ_id")
private String organId; private String organId;
@ApiModelProperty("mac地址") @ApiModelProperty("mac地址")
@TableField("mac") @TableField("mac")
private String mac; private String mac;
@ApiModelProperty("状态 1.未激活 2.已激活 3.故障") @ApiModelProperty("状态 1.未激活 2.已激活 3.故障")
@TableField("status") @TableField("status")
private Integer status; private Integer status;
@ApiModelProperty("区域id") @ApiModelProperty("区域id")
@TableField("area_id") @TableField("area_id")
private String areaId; private String areaId;
@ApiModelProperty(hidden = true)
@TableField("public_key")
private String publicKey;
@ApiModelProperty(hidden = true)
@TableField("private_key")
private String privateKey;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT) @TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty("修改时间") @ApiModelProperty("修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime; private LocalDateTime updateTime;
...@@ -81,5 +75,4 @@ public class TBoxOperation implements Serializable { ...@@ -81,5 +75,4 @@ public class TBoxOperation implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private String areaName; private String areaName;
} }
...@@ -3,6 +3,7 @@ package cn.wisenergy.chnmuseum.party.web.controller; ...@@ -3,6 +3,7 @@ package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService; import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService;
import cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil; import cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil;
import cn.wisenergy.chnmuseum.party.common.enums.LanguageEnum; import cn.wisenergy.chnmuseum.party.common.enums.LanguageEnum;
import cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException;
import cn.wisenergy.chnmuseum.party.common.util.TimeUtils; import cn.wisenergy.chnmuseum.party.common.util.TimeUtils;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add; import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.vo.AudioVo; import cn.wisenergy.chnmuseum.party.common.vo.AudioVo;
...@@ -129,10 +130,14 @@ public class ChinaMobileRestApiController extends BaseController { ...@@ -129,10 +130,14 @@ public class ChinaMobileRestApiController extends BaseController {
final TBoxOperation tBoxOperation = this.boxOperationService.getOne(queryWrapper); final TBoxOperation tBoxOperation = this.boxOperationService.getOne(queryWrapper);
if (tBoxOperation != null) { if (tBoxOperation != null) {
final String organId = tBoxOperation.getOrganId(); final String organId = tBoxOperation.getOrganId();
final TUser tUser = getcurUser();
if (tUser != null && organId.equals(tUser.getOrgId())) {
return getResult(tBoxOperation.getPrivateKey());
} else {
throw new InterfaceException("400", "您无权获取本单位机顶盒密钥");
}
} }
throw new InterfaceException("400", "未查询到相关机顶盒信息");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -277,7 +282,7 @@ public class ChinaMobileRestApiController extends BaseController { ...@@ -277,7 +282,7 @@ public class ChinaMobileRestApiController extends BaseController {
jsonObject.put("effectiveDate", user.getEffectiveDate()); jsonObject.put("effectiveDate", user.getEffectiveDate());
jsonObject.put("expireDate", user.getExiredDate()); jsonObject.put("expireDate", user.getExiredDate());
jsonObject.put("orgCode", user.getOrgId()); jsonObject.put("orgCode", user.getOrgId());
jsonObject.put("orgName",organ.getName()); jsonObject.put("orgName", organ.getName());
resultMap.put("resultCode", 200); resultMap.put("resultCode", 200);
resultMap.put("message", "成功"); resultMap.put("message", "成功");
......
package cn.wisenergy.chnmuseum.party.web.controller; package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.common.util.RSAUtils;
import cn.wisenergy.chnmuseum.party.model.TBoxOperation; import cn.wisenergy.chnmuseum.party.model.TBoxOperation;
import cn.wisenergy.chnmuseum.party.model.TUser; import cn.wisenergy.chnmuseum.party.model.TUser;
import cn.wisenergy.chnmuseum.party.service.TBoxOperationService; import cn.wisenergy.chnmuseum.party.service.TBoxOperationService;
...@@ -17,6 +18,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; ...@@ -17,6 +18,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -81,6 +83,9 @@ public class TBoxOperationController extends BaseController { ...@@ -81,6 +83,9 @@ public class TBoxOperationController extends BaseController {
if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) { if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) {
tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase()); tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase());
} }
final ArrayList<String> rsaKeys = RSAUtils.createRSAKeys();
tBoxOperation.setPublicKey(rsaKeys.get(0));
tBoxOperation.setPrivateKey(rsaKeys.get(1));
result = tBoxOperationService.save(tBoxOperation); result = tBoxOperationService.save(tBoxOperation);
if (!result) { if (!result) {
return getFailResult(); return getFailResult();
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
<result column="mac" property="mac"/> <result column="mac" property="mac"/>
<result column="status" property="status"/> <result column="status" property="status"/>
<result column="area_id" property="areaId"/> <result column="area_id" property="areaId"/>
<result column="public_key" property="publicKey" />
<result column="private_key" property="privateKey" />
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/> <result column="update_time" property="updateTime"/>
<result column="organ_name" property="organName"/> <result column="organ_name" property="organName"/>
...@@ -17,7 +19,7 @@ ...@@ -17,7 +19,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, organ_id, mac, status, area_id, create_time, update_time id, organ_id, mac, status, area_id, public_key, private_key, create_time, update_time
</sql> </sql>
<select id="getList" resultMap="BaseResultMap"> <select id="getList" resultMap="BaseResultMap">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment