|
@ -0,0 +1,84 @@ |
|
|
|
|
|
package a8k.dbservice; |
|
|
|
|
|
|
|
|
|
|
|
import a8k.dbservice.type.A8kProjIdCardDBIterm; |
|
|
|
|
|
import a8k.dbservice.type.AppSetting; |
|
|
|
|
|
import a8k.dbservice.type.appsetting.AppSettingName; |
|
|
|
|
|
import a8k.dbservice.type.appsetting.AppSettingTab; |
|
|
|
|
|
import a8k.dbservice.type.appsetting.AppSettingType; |
|
|
|
|
|
import a8k.type.projecttype.a8kidcard.A8kIdCardInfo; |
|
|
|
|
|
import a8k.utils.ZEnumHelper; |
|
|
|
|
|
import a8k.utils.ZSqliteJdbcHelper; |
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.ResultSet; |
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
|
public class A8kProjIdCardDBService { |
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(A8kProjIdCardDBService.class); |
|
|
|
|
|
private static final String tableName = "zapp_a8k_idcards"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
JdbcTemplate jdbcTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
|
|
void init() { |
|
|
|
|
|
if (!ZSqliteJdbcHelper.isTableExist(jdbcTemplate, tableName)) { |
|
|
|
|
|
createTable(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private AppSetting rowMapper(ResultSet rs, int rowNum) throws SQLException |
|
|
|
|
|
|
|
|
|
|
|
private A8kProjIdCardDBIterm rowMapper(ResultSet rs, int rowNum) throws SQLException { |
|
|
|
|
|
A8kProjIdCardDBIterm obj = new A8kProjIdCardDBIterm(); |
|
|
|
|
|
obj.id = rs.getInt("id"); |
|
|
|
|
|
obj.lotid = rs.getString("lotid"); |
|
|
|
|
|
try { |
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
|
|
obj.idcardinfo = objectMapper.readValue(rs.getString("idcardinfo"), A8kIdCardInfo.class); |
|
|
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
|
|
logger.error(e.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return obj; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void createTable() { |
|
|
|
|
|
jdbcTemplate.execute("create table " + tableName + " ('id' integer," |
|
|
|
|
|
+ " 'lotid' text," |
|
|
|
|
|
+ " 'idcardinfo' text," |
|
|
|
|
|
+ " PRIMARY KEY ('id' DESC));"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addIdCard(A8kProjIdCardDBIterm idcard) { |
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
jdbcTemplate.update("insert into " + tableName + "(lotid, idcardinfo) values(?, ?);",// |
|
|
|
|
|
idcard.lotid, objectMapper.writeValueAsString(idcard.idcardinfo)); |
|
|
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
|
|
logger.error(e.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<A8kProjIdCardDBIterm> getAllIdCards() { |
|
|
|
|
|
return jdbcTemplate.query("select * from " + tableName + ";", this::rowMapper); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public A8kProjIdCardDBIterm getIdCardByLotId(String lotid) { |
|
|
|
|
|
return jdbcTemplate.queryForObject("select * from " + tableName + " where lotid = ?;", this::rowMapper, lotid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |