重构后运行成功
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/SettleCtlDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/SettleCtlDao.java
new file mode 100644
index 0000000..ec8fadc
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/SettleCtlDao.java
@@ -0,0 +1,26 @@
+package com.supwisdom.dlpay.framework.dao;
+
+import com.supwisdom.dlpay.framework.domain.TSettlectl;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+import javax.persistence.LockModeType;
+
+@Repository
+public interface SettleCtlDao extends JpaRepository<TSettlectl, Integer> {
+ @Lock(value = LockModeType.PESSIMISTIC_WRITE)
+ TSettlectl findByBooksetno(Integer booksetno);
+
+ @Lock(value = LockModeType.PESSIMISTIC_WRITE)
+ @Query(value = "from TSettlectl where booksetno=:booksetno ")
+ TSettlectl findByBooksetnoWithLock(@Param("booksetno") Integer booksetno);
+
+ @Modifying(clearAutomatically = true)
+ @Query(value = "update TB_SETTLECTL set PERIODYEAR=:peridyear,PERIODMONTH=:peridmonth where BOOKSETNO=1 ", nativeQuery = true)
+ void updateSettlePeriod(@Param("peridyear") int peridyear, @Param("peridmonth") int peridmonth);
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TSettlectl.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TSettlectl.java
new file mode 100644
index 0000000..73dbf10
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TSettlectl.java
@@ -0,0 +1,88 @@
+package com.supwisdom.dlpay.framework.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_SETTLECTL")
+public class TSettlectl {
+ @Id
+ @Column(name="BOOKSETNO", nullable = false, precision = 2)
+ private Integer booksetno;
+
+ @Column(name="PERIODYEAR", nullable = false, precision = 4)
+ private Integer periodYear;
+
+ @Column(name="PERIODMONTH", nullable = false, precision = 2)
+ private Integer periodMonth;
+
+ @Column(name="STATDATE", precision = 8)
+ private Integer statdate;
+
+ @Column(name="SETTLEDATE",nullable = false, precision = 8)
+ private Integer settledate;
+
+ @Column(name="STATUS", nullable = false, precision = 1)
+ private Integer status;
+
+ @Column(name="UPDTIME", length = 14)
+ private String updtime;
+
+ public Integer getBooksetno() {
+ return booksetno;
+ }
+
+ public void setBooksetno(Integer booksetno) {
+ this.booksetno = booksetno;
+ }
+
+ public Integer getPeriodYear() {
+ return periodYear;
+ }
+
+ public void setPeriodYear(Integer periodYear) {
+ this.periodYear = periodYear;
+ }
+
+ public Integer getPeriodMonth() {
+ return periodMonth;
+ }
+
+ public void setPeriodMonth(Integer periodMonth) {
+ this.periodMonth = periodMonth;
+ }
+
+ public Integer getStatdate() {
+ return statdate;
+ }
+
+ public void setStatdate(Integer statdate) {
+ this.statdate = statdate;
+ }
+
+ public Integer getSettledate() {
+ return settledate;
+ }
+
+ public void setSettledate(Integer settledate) {
+ this.settledate = settledate;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ public String getUpdtime() {
+ return updtime;
+ }
+
+ public void setUpdtime(String updtime) {
+ this.updtime = updtime;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java b/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java
new file mode 100644
index 0000000..eee9e5a
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java
@@ -0,0 +1,243 @@
+package com.supwisdom.dlpay.framework.service.impl;
+
+import com.supwisdom.dlpay.framework.core.DatabaseConfig;
+import com.supwisdom.dlpay.framework.dao.*;
+import com.supwisdom.dlpay.framework.data.SystemDateTime;
+import com.supwisdom.dlpay.framework.domain.*;
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.DateUtil;
+import com.supwisdom.dlpay.framework.util.NumberUtil;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+@Service
+public class SystemUtilServiceImpl implements SystemUtilService {
+ @Autowired
+ private DatabaseConfig databaseConfig;
+
+ @Autowired
+ private TaskLockDao taskLockDao;
+ @Autowired
+ private SettleCtlDao settleCtlDao;
+ @Autowired
+ private TranscodeDao transcodeDao;
+ @Autowired
+ private SysparaDao sysparaDao;
+ @Autowired
+ private BusinessparaDao businessparaDao;
+
+ private static final Logger logger = LoggerFactory.getLogger(SystemUtilServiceImpl.class);
+
+ public static class SystemDateTimeImpl implements SystemDateTime {
+ private Date now;
+ private static final SimpleDateFormat sdft = new SimpleDateFormat("yyyyMMddHHmmss");
+
+ public SystemDateTimeImpl(Date now) {
+ this.now = now;
+ }
+
+ @Override
+ public String getHostdate() {
+ return sdft.format(this.now).substring(0, 8);
+ }
+
+ @Override
+ public String getHosttime() {
+ return sdft.format(this.now).substring(8, 14);
+ }
+
+ @Override
+ public String getHostdatetime() {
+ return sdft.format(this.now);
+ }
+
+ @Override
+ public Date getSysdate() {
+ return this.now;
+ }
+ }
+
+ /**
+ * 获取oracle数据库时间
+ */
+ private SystemDateTime getOracleDatetime() {
+ return taskLockDao.getOracleDatetime();
+ }
+
+ private SystemDateTime getPGDatetime() {
+ return taskLockDao.getPGDatetime();
+ }
+
+ @Override
+ public SystemDateTime getSysdatetime() {
+ switch (databaseConfig.getPlatform()) {
+ case "postgresql":
+ return getPGDatetime();
+ default:
+ return getOracleDatetime();
+ }
+ }
+
+ @Override
+ public TTaskLock updateTaskLock(TTaskLock lock) {
+ return taskLockDao.save(lock);
+ }
+
+ @Override
+ public TTaskLock doLockTask(String taskcode, Integer minRecover, String remark) {
+ if (null == minRecover) minRecover = 10; //默认10分钟
+ String hostdatetime = getSysdatetime().getHostdatetime(); //yyyyMMddHHmmss
+ TTaskLock lock = taskLockDao.getTaskLockWithLock(taskcode);
+ if (lock != null) {
+ if (lock.getTaskstatus() == 1 && DateUtil.compareDatetime(DateUtil.getNewTime(hostdatetime, -60 * minRecover), lock.getTasktime()) < 0) {
+ // 被锁,正在执行操作
+ return null;
+ } else {
+ lock.setTaskstatus(1);
+ lock.setTasktime(hostdatetime);
+ taskLockDao.save(lock);
+ return lock;
+ }
+ } else {
+ lock = new TTaskLock();
+ lock.setTaskcode(taskcode);
+ lock.setTaskstatus(1);
+ lock.setTasktime(hostdatetime);
+ lock.setRemark(remark);
+ taskLockDao.save(lock);
+ }
+ return lock;
+ }
+
+ @Override
+ public String getAccdate() {
+ String hostdate = getSysdatetime().getHostdate();
+ TSettlectl settlectl = settleCtlDao.getOne(1);
+ if (null != settlectl && null != settlectl.getSettledate()) {
+ if (Integer.valueOf(hostdate) < settlectl.getSettledate().intValue()) {
+ return settlectl.getSettledate().toString();
+ }
+ }
+ return hostdate;
+ }
+
+ private String getOracleRefno() {
+ return taskLockDao.getOracleRefno();
+ }
+
+ @Override
+ public String getRefno() {
+ switch (databaseConfig.getPlatform()) {
+ case "postgresql":
+ return taskLockDao.getPgRefno();
+ default:
+ return taskLockDao.getOracleRefno();
+ }
+ }
+
+ @Override
+ public String getTranscodeName(int transocde, String defaultValue) {
+ TTranscode tTranscode = transcodeDao.getOne(transocde);
+ if (null != tTranscode && !StringUtil.isEmpty(tTranscode.getTransname())) {
+ return tTranscode.getTransname();
+ }
+ return defaultValue;
+ }
+
+ @Override
+ public String getSysparaValue(int paraid) {
+ TSyspara syspara = sysparaDao.findByParaid(paraid);
+ if (null != syspara) return syspara.getParaval();
+ return null;
+ }
+
+ @Override
+ public String getSysparaValue(int paraid, String defaultValue) {
+ String paraval = getSysparaValue(paraid);
+ if (null != paraval) return paraval;
+ return defaultValue;
+ }
+
+ @Override
+ public boolean getSysparaValueAsBoolean(int paraid) {
+ TSyspara syspara = sysparaDao.findByParaid(paraid);
+ if (null != syspara && "1".equals(syspara.getParaval())) return true;
+ return false;
+ }
+
+ @Override
+ public int getSysparaValueAsInt(int paraid, int defaultValue) {
+ TSyspara syspara = sysparaDao.findByParaid(paraid);
+ if (null != syspara && NumberUtil.isNumber(syspara.getParaval())) return Integer.parseInt(syspara.getParaval());
+ return defaultValue;
+ }
+
+ @Override
+ public double getSysparaValueAsDouble(int paraid, double defaultValue) {
+ TSyspara syspara = sysparaDao.findByParaid(paraid);
+ if (null != syspara && NumberUtil.isDecimal(syspara.getParaval())) return Double.parseDouble(syspara.getParaval());
+ return defaultValue;
+ }
+
+ @Override
+ public TSyspara getSyspara(int paraid){
+ return sysparaDao.findByParaid(paraid);
+ }
+
+ @Override
+ public TSyspara getSysparaValueForUpdate(int paraid){
+ return sysparaDao.findByParaidWithLock(paraid);
+ }
+
+ @Override
+ public TSyspara getSysparaValueForUpdateNowait(int paraid){
+ return sysparaDao.findByParaidWithLockNowait(paraid);
+ }
+
+ @Override
+ public String getBusinessValue(String parakey) {
+ if (!StringUtil.isEmpty(parakey)) {
+ TBusinesspara businesspara = businessparaDao.findByParakey(parakey.trim());
+ if (null != businesspara) return businesspara.getParaval();
+ }
+ return null;
+ }
+
+ @Override
+ public String getBusinessValue(String parakey, String defaultValue) {
+ String paraval = getBusinessValue(parakey);
+ if (!StringUtil.isEmpty(paraval)) return paraval;
+ return defaultValue;
+ }
+
+ @Override
+ public TBusinesspara getBusiness(String parakey) {
+ if (!StringUtil.isEmpty(parakey)) return businessparaDao.findByParakey(parakey.trim());
+ return null;
+ }
+
+ @Override
+ public TBusinesspara getBusinessValueForUpdate(String parakey){
+ if (!StringUtil.isEmpty(parakey)) return businessparaDao.findByParakeyForUpdate(parakey.trim());
+ return null;
+ }
+
+ @Override
+ public TBusinesspara getBusinessValueForUpdateNowait(String parakey) {
+ if (!StringUtil.isEmpty(parakey)) return businessparaDao.findByParakeyForUpdateNowait(parakey.trim());
+ return null;
+ }
+
+ @Override
+ public String getSubsystemSignKey(String syscode){
+ // fixme: 验证数据无误性签名秘钥
+ return "";
+ }
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/water/dao/RegionDao.java b/src/main/java/com/supwisdom/dlpay/water/dao/AreaDao.java
similarity index 74%
rename from src/main/java/com/supwisdom/dlpay/water/dao/RegionDao.java
rename to src/main/java/com/supwisdom/dlpay/water/dao/AreaDao.java
index 4f9d450..8691348 100644
--- a/src/main/java/com/supwisdom/dlpay/water/dao/RegionDao.java
+++ b/src/main/java/com/supwisdom/dlpay/water/dao/AreaDao.java
@@ -10,7 +10,7 @@
import java.util.Optional;
@Repository
-public interface RegionDao extends JpaRepository<TArea, Integer> {
+public interface AreaDao extends JpaRepository<TArea, Integer> {
List<TArea> findByParentId(Integer parentId);
@@ -18,17 +18,17 @@
List<TArea> findByAvailableAndLevelNot(Integer available, Integer level);
- Optional<TArea> findByAvailableAndRegino(Integer available, Integer regino);
+ Optional<TArea> findByAvailableAndAreano(Integer available, Integer regino);
Page<TArea> findAllByAvailable(Integer available, Pageable pageable);
Page<TArea> findByAvailableAndParentId(Integer available, Integer parentId, Pageable pageable);
- Page<TArea> findAllByAvailableAndRegiNameContaining(Integer available, String regiName, Pageable pageable);
+ Page<TArea> findAllByAvailableAndAreaNameContaining(Integer available, String regiName, Pageable pageable);
- TArea findAllByAvailableAndRegiName(Integer available, String reiName);
+ TArea findAllByAvailableAndAreaName(Integer available, String reiName);
- TArea findByAvailableAndRegiNameAndReginoNot(Integer available, String reiName, Integer regino);
+ TArea findByAvailableAndAreaNameAndAreanoNot(Integer available, String reiName, Integer regino);
List<TArea> findByAvailableAndParentId(Integer available, Integer parentId);
}
diff --git a/src/main/java/com/supwisdom/dlpay/water/dao/DeviceDao.java b/src/main/java/com/supwisdom/dlpay/water/dao/DeviceDao.java
index a7a9348..c28dafa 100644
--- a/src/main/java/com/supwisdom/dlpay/water/dao/DeviceDao.java
+++ b/src/main/java/com/supwisdom/dlpay/water/dao/DeviceDao.java
@@ -11,12 +11,10 @@
@Repository
public interface DeviceDao extends JpaRepository<TDevice, String>, JpaSpecificationExecutor<TDevice> {
- List<TDevice> findByRegino(Integer regino);
+ List<TDevice> findByAreano(Integer regino);
- List<TDevice> findByDevinameAndDevinoNot(String deviname, String devino);
+ List<TDevice> findByDevicenameAndDevicenoNot(String deviname, String devino);
- List<TDevice> findByDeviname(String deviname);
+ List<TDevice> findByDevicename(String deviname);
- @Query("select devistatus from TDevice group by devistatus")
- List<String> groupStatus();
}
diff --git a/src/main/java/com/supwisdom/dlpay/water/service/impl/AreaServiceImpl.java b/src/main/java/com/supwisdom/dlpay/water/service/impl/AreaServiceImpl.java
index 8c3a0a4..27d6fb2 100644
--- a/src/main/java/com/supwisdom/dlpay/water/service/impl/AreaServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/water/service/impl/AreaServiceImpl.java
@@ -3,7 +3,7 @@
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.water.system.bean.RegionSearchBean;
-import com.supwisdom.dlpay.water.dao.RegionDao;
+import com.supwisdom.dlpay.water.dao.AreaDao;
import com.supwisdom.dlpay.water.domain.TArea;
import com.supwisdom.dlpay.water.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,7 +17,7 @@
public class AreaServiceImpl implements AreaService {
@Autowired
- private RegionDao regionDao;
+ private AreaDao regionDao;
/**
* 根据父区域id查询区域列表
@@ -31,7 +31,7 @@
PageResult<TArea> result = new PageResult<>(regionDao.findByAvailableAndParentId(1, param.getParentId(), pageable));
List<TArea> data = result.getData();
if (param.getPageNo()==1) {
- Optional<TArea> optional = regionDao.findByAvailableAndRegino(1, param.getParentId());
+ Optional<TArea> optional = regionDao.findByAvailableAndAreano(1, param.getParentId());
if (optional.isPresent()) {
data = new ArrayList<>(data);
data.add(0, optional.get());
@@ -70,7 +70,7 @@
public PageResult<TArea> queryAreasBySearchKey(RegionSearchBean param) {
Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize());
if (!StringUtil.isEmpty(param.getSearchKey())) {
- return new PageResult<>(regionDao.findAllByAvailableAndRegiNameContaining(1, param.getSearchKey(), pageable));
+ return new PageResult<>(regionDao.findAllByAvailableAndAreaNameContaining(1, param.getSearchKey(), pageable));
}
return new PageResult<>(regionDao.findAllByAvailable(1, pageable));
}
@@ -81,7 +81,7 @@
region.setParentName("无");
region.setLevel(1);
} else {
- Optional<TArea> optional = regionDao.findByAvailableAndRegino(1, region.getParentId());
+ Optional<TArea> optional = regionDao.findByAvailableAndAreano(1, region.getParentId());
if (optional.isPresent()) {
region.setParentName(optional.get().getAreaName());
region.setLevel(optional.get().getLevel() + 1);
@@ -95,7 +95,7 @@
}
public boolean updateArea(TArea region) {
- Optional<TArea> optional = regionDao.findByAvailableAndRegino(1, region.getAreano());
+ Optional<TArea> optional = regionDao.findByAvailableAndAreano(1, region.getAreano());
if (optional.isPresent()) {
TArea oldRegion = optional.get();
oldRegion.setAreaName(region.getAreaName());
@@ -110,9 +110,9 @@
@Override
public boolean checkAreaName(TArea region) {
if (region.getAreano() == null) {
- return regionDao.findAllByAvailableAndRegiName(1, region.getAreaName()) == null;
+ return regionDao.findAllByAvailableAndAreaName(1, region.getAreaName()) == null;
}else {
- return regionDao.findByAvailableAndRegiNameAndReginoNot(1,
+ return regionDao.findByAvailableAndAreaNameAndAreanoNot(1,
region.getAreaName(),
region.getAreano()) == null;
}
@@ -120,7 +120,7 @@
@Override
public boolean deleteArea(Integer regino) {
- Optional<TArea> optional = regionDao.findByAvailableAndRegino(1, regino);
+ Optional<TArea> optional = regionDao.findByAvailableAndAreano(1, regino);
if (optional.isPresent()) {
TArea region = optional.get();
region.setAvailable(0);
diff --git a/src/main/java/com/supwisdom/dlpay/water/service/impl/DeviceServiceImpl.java b/src/main/java/com/supwisdom/dlpay/water/service/impl/DeviceServiceImpl.java
deleted file mode 100644
index 25cab05..0000000
--- a/src/main/java/com/supwisdom/dlpay/water/service/impl/DeviceServiceImpl.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package com.supwisdom.dlpay.water.service.impl;
-
-import com.supwisdom.dlpay.framework.util.PageResult;
-import com.supwisdom.dlpay.water.dao.DeviceDao;
-import com.supwisdom.dlpay.water.dao.RegionDao;
-import com.supwisdom.dlpay.water.domain.TDevice;
-import com.supwisdom.dlpay.water.domain.TArea;
-import com.supwisdom.dlpay.water.service.DeviceService;
-import com.supwisdom.dlpay.water.system.bean.DeviceSearchBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-
-import javax.persistence.criteria.Predicate;
-import java.util.*;
-
-@Service
-public class DeviceServiceImpl implements DeviceService {
- @Autowired
- private DeviceDao deviceDao;
-
- @Autowired
- private RegionDao regionDao;
-
- @Override
- public boolean existSubDevice(Integer regino) {
- List<TDevice> devices = deviceDao.findByRegino(regino);
- return devices != null && devices.size() != 0;
- }
-
- @Override
- public PageResult<TDevice> queryDeviceList(DeviceSearchBean param) {
- Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize());
- return new PageResult<>(deviceDao.findAll(pageable));
- }
-
- @Override
- public TDevice queryDeviceById(String devino) {
- Optional<TDevice> optional = deviceDao.findById(devino);
- return optional.orElse(null);
- }
-
- @Override
- public boolean updateDevice(TDevice device) {
- Optional<TDevice> deviOption = deviceDao.findById(device.getDeviceno());
- Optional<TArea> regiOption = regionDao.findByAvailableAndRegino(1, device.getAreano());
- if (deviOption.isPresent() && regiOption.isPresent()) {
- TDevice oldDevice = deviOption.get();
- TArea region = regiOption.get();
- oldDevice.setDevicename(device.getDevicename());
- oldDevice.setAreano(region.getAreano());
- deviceDao.save(oldDevice);
- return true;
- }
- return false;
- }
-
- @Override
- public boolean saveDevice(TDevice device) {
- Optional<TArea> regiOption = regionDao.findByAvailableAndRegino(1, device.getAreano());
- if (regiOption.isPresent()) {
- TArea region = regiOption.get();
- device.setAreano(region.getAreano());
- device.setDeviceStatus("正常");
- deviceDao.save(device);
- return true;
- }
- return false;
- }
-
- @Override
- public Map<String, Object> checkParams(TDevice device) {
- Map<String, Object> result = new HashMap<>();
- if (null == device.getDevicename()) {
- result.put("flag", false);
- result.put("msg", "设备名称不能为空");
- return result;
- }
- if (null == device.getDeviceno()) {
- result.put("flag", false);
- result.put("msg", "设备编号不能为空");
- return result;
- }
- if (device.getDeviceno().toString().length() != 8) {
- result.put("flag", false);
- result.put("msg", "请输入合法的设备编号");
- return result;
- }
- Optional<TDevice> optional = deviceDao.findById(device.getDeviceno());
- List<TDevice> devices;
- if (optional.isPresent()) {
- // 更新
- devices = deviceDao.findByDevinameAndDevinoNot(device.getDevicename(), device.getDeviceno());
- result.put("type", "update");
- } else {
- // 新增
- devices = deviceDao.findByDeviname(device.getDevicename());
- result.put("type", "insert");
- }
- if (devices != null && devices.size() != 0) {
- result.put("flag", false);
- result.put("msg", "已存在的设备名");
- return result;
- }
- result.put("flag", true);
- return result;
- }
-
- @Override
- public boolean deleteDevice(String devino) {
- TDevice device = queryDeviceById(devino);
- if (device != null) {
- device.setDeviceStatus("注销");
- deviceDao.save(device);
- return true;
- }
- return false;
- }
-
- @Override
- public List<String> groupStatus() {
- List<String> status = deviceDao.groupStatus();
- return status == null || status.size() == 0 ? null : status;
- }
-
- @Override
- public PageResult<TDevice> queryDeviceByParams(DeviceSearchBean param) {
- Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize());
- Specification<TDevice> specification = (Specification<TDevice>) (root, query, cb) -> {
- List<Predicate> predicates = new ArrayList<>();
- if (param.getDevino() != null) {
- predicates.add(cb.equal(root.get("devino").as(Integer.class), param.getDevino()));
- }
- if (param.getRegino() != null) {
- predicates.add(cb.equal(root.get("regino").as(Integer.class), param.getRegino()));
- }
- if (param.getDevistatus() != null) {
- predicates.add(cb.equal(root.get("devistatus").as(String.class), param.getDevistatus()));
- }
- if (param.getDeviname() != null) {
- predicates.add(cb.like(root.get("deviname"), "%" + param.getDeviname() + "%"));
- }
- Predicate[] pre = new Predicate[predicates.size()];
- return query.where(predicates.toArray(pre)).getRestriction();
- };
- return new PageResult<>(deviceDao.findAll(specification, pageable));
- }
-}
diff --git a/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt b/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt
deleted file mode 100644
index 71aab56..0000000
--- a/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt
+++ /dev/null
@@ -1,142 +0,0 @@
-package com.supwisdom.dlpay.api.controller
-
-import com.supwisdom.dlpay.api.bean.ModifyUserParam
-import com.supwisdom.dlpay.api.bean.OpenUserParam
-import com.supwisdom.dlpay.api.bean.QueryUserParam
-import com.supwisdom.dlpay.api.service.UserService
-import com.supwisdom.dlpay.exception.RequestParamCheckException
-import com.supwisdom.dlpay.exception.TransactionException
-import com.supwisdom.dlpay.framework.ResponseBodyBuilder
-import com.supwisdom.dlpay.framework.service.CommonService
-import com.supwisdom.dlpay.framework.util.TradeErrorCode
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.http.ResponseEntity
-import org.springframework.web.bind.annotation.PostMapping
-import org.springframework.web.bind.annotation.RequestBody
-import org.springframework.web.bind.annotation.RequestMapping
-import org.springframework.web.bind.annotation.RestController
-import java.net.URLDecoder
-import javax.servlet.http.HttpServletRequest
-import javax.servlet.http.HttpServletResponse
-
-@RestController
-@RequestMapping("/api/user")
-class UserAPIController {
- @Autowired
- private lateinit var useService: UserService
- @Autowired
- private lateinit var commonService: CommonService
-
- @PostMapping("/open")
- fun openAccount(@RequestBody param: OpenUserParam, request: HttpServletRequest, response: HttpServletResponse): ResponseEntity<Any> {
- try {
-
- if (!param.checkParam() || !param.checkSign(commonService.getAppidSecretByRequest(request))) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.REQUEST_SIGN_ERROR, "参数签名错误"))
- }
- useService.findByThirdUniqueIdenty(param.uid).let {
- if (null != it) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.REGISTER_USER_EXIST, "该用户唯一号已经注册"))
- }
-
- param.name = URLDecoder.decode(param.name, Charsets.UTF_8.toString()) //解码
- param.address = param.address?.let { URLDecoder.decode(param.address, Charsets.UTF_8.toString()) } //解码
- useService.registerUser(param).let {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .data("userid", it.userid)
- .data("uid", param.uid)
- .success())
- }
- }
- } catch (ex: RequestParamCheckException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .requestException(ex, "请求参数错误"))
- } catch (et: TransactionException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .transException(et, "业务处理错误"))
- }
- }
-
- @PostMapping("/query")
- fun queryAccount(@RequestBody param: QueryUserParam, request: HttpServletRequest, response: HttpServletResponse): ResponseEntity<Any> {
- try {
- if (param.checkParam() && param.checkSign(commonService.getAppidSecretByRequest(request))) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.REQUEST_SIGN_ERROR, "参数签名错误"))
- }
-
- useService.findByUseridOrThirdUniqueIdenty(param.userid, param.uid).let {
- if (null != it) {
- val account = useService.findAccountByUserid(it.userid, null)
- val pointacc = useService.findPointsAccountByUserid(it.userid)
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .data("userid", it.userid)
- .data("name", it.name)
- .data("idtype", it.idtype)
- .data("idno", it.idno)
- .data("mobile", it.mobile)
- .data("email", it.email)
- .data("status", it.status)
- .data("balance", account.let {
- if (null == it) {
- 0.0
- } else {
- it.availbal
- }
- }) //账户余额
- .data("points", pointacc.let {
- if (null == it) {
- 0
- } else {
- it.points
- }
- }) //积分
- .success())
- }
-
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.ACCOUNT_NOT_EXISTS, "账户不存在"))
- }
- } catch (ex: RequestParamCheckException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .requestException(ex, "请求参数错误"))
- } catch (et: TransactionException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .transException(et, "业务处理错误"))
- }
- }
-
- @PostMapping("/modify")
- fun modifyAccount(@RequestBody param: ModifyUserParam, request: HttpServletRequest, response: HttpServletResponse): ResponseEntity<Any> {
- try {
- if (param.checkParam() && param.checkSign(commonService.getAppidSecretByRequest(request))) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.REQUEST_SIGN_ERROR, "参数签名错误"))
- }
- useService.findByUseridOrThirdUniqueIdenty(param.userid, param.uid)?.let {
- param.name = param.name?.let { URLDecoder.decode(param.name, Charsets.UTF_8.toString()) } //解码
- param.address = param.address?.let { URLDecoder.decode(param.address, Charsets.UTF_8.toString()) } //解码
- if (useService.modifyUserInfo(it, param)) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .success("修改成功"))
- } else {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.BUSINESS_DEAL_ERROR, "账户信息修改失败"))
- }
- }
-
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .fail(TradeErrorCode.ACCOUNT_NOT_EXISTS, "账户不存在"))
- } catch (ex: RequestParamCheckException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .requestException(ex, "请求参数错误"))
- } catch (et: TransactionException) {
- return ResponseEntity.ok(ResponseBodyBuilder.create()
- .transException(et, "业务处理错误"))
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/supwisdom/dlpay/water/controller/api_controller.kt b/src/main/kotlin/com/supwisdom/dlpay/water/controller/api_controller.kt
index 5561321..7e4c704 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/water/controller/api_controller.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/water/controller/api_controller.kt
@@ -15,7 +15,7 @@
@Autowired
private lateinit var systemUtilService: SystemUtilService
- @GetMapping("/login")
+ @GetMapping("/devicelogin")
fun deviceLogin(@RequestBody param: DeviceLoginParam): ResponseEntity<Any> {
TODO("")
}
diff --git a/src/main/kotlin/com/supwisdom/dlpay/water/service/device_service.kt b/src/main/kotlin/com/supwisdom/dlpay/water/service/device_service.kt
new file mode 100644
index 0000000..de0f0aa
--- /dev/null
+++ b/src/main/kotlin/com/supwisdom/dlpay/water/service/device_service.kt
@@ -0,0 +1,138 @@
+package com.supwisdom.dlpay.water.service
+
+
+import com.supwisdom.dlpay.framework.util.PageResult
+import com.supwisdom.dlpay.water.dao.DeviceDao
+import com.supwisdom.dlpay.water.dao.AreaDao
+import com.supwisdom.dlpay.water.domain.TDevice
+import com.supwisdom.dlpay.water.system.bean.DeviceSearchBean
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.data.domain.PageRequest
+import org.springframework.data.jpa.domain.Specification
+import org.springframework.stereotype.Service
+
+import javax.persistence.criteria.Predicate
+import java.util.*
+
+@Service
+class DeviceServiceImpl : DeviceService {
+ @Autowired
+ private lateinit var deviceDao: DeviceDao
+
+ @Autowired
+ private lateinit var areaDao: AreaDao
+
+ override fun existSubDevice(regino: Int?): Boolean {
+ val devices = deviceDao.findByAreano(regino)
+ return devices != null && devices.size != 0
+ }
+
+ override fun queryDeviceList(param: DeviceSearchBean): PageResult<TDevice> {
+ val pageable = PageRequest.of(param.pageNo - 1, param.pageSize)
+ return PageResult(deviceDao.findAll(pageable))
+ }
+
+ override fun queryDeviceById(devino: String): TDevice? {
+ val optional = deviceDao.findById(devino)
+ return optional.orElse(null)
+ }
+
+ override fun updateDevice(device: TDevice): Boolean {
+ val deviOption = deviceDao.findById(device.deviceno)
+ val regiOption = areaDao.findByAvailableAndAreano(1, device.areano)
+ if (deviOption.isPresent && regiOption.isPresent) {
+ val oldDevice = deviOption.get()
+ val region = regiOption.get()
+ oldDevice.devicename = device.devicename
+ oldDevice.areano = region.areano
+ deviceDao.save(oldDevice)
+ return true
+ }
+ return false
+ }
+
+ override fun saveDevice(device: TDevice): Boolean {
+ val regiOption = areaDao.findByAvailableAndAreano(1, device.areano)
+ if (regiOption.isPresent) {
+ val region = regiOption.get()
+ device.areano = region.areano
+ device.deviceStatus = "正常"
+ deviceDao.save(device)
+ return true
+ }
+ return false
+ }
+
+ override fun checkParams(device: TDevice): Map<String, Any> {
+ val result = HashMap<String, Any>()
+ if (null == device.devicename) {
+ result["flag"] = false
+ result["msg"] = "设备名称不能为空"
+ return result
+ }
+ if (null == device.deviceno) {
+ result["flag"] = false
+ result["msg"] = "设备编号不能为空"
+ return result
+ }
+ if (device.deviceno.toString().length != 8) {
+ result["flag"] = false
+ result["msg"] = "请输入合法的设备编号"
+ return result
+ }
+ val optional = deviceDao.findById(device.deviceno)
+ val devices: List<TDevice>?
+ if (optional.isPresent) {
+ // 更新
+ devices = deviceDao.findByDevicenameAndDevicenoNot(device.devicename, device.deviceno)
+ result["type"] = "update"
+ } else {
+ // 新增
+ devices = deviceDao.findByDevicename(device.devicename)
+ result["type"] = "insert"
+ }
+ if (devices != null && devices.isNotEmpty()) {
+ result["flag"] = false
+ result["msg"] = "已存在的设备名"
+ return result
+ }
+ result["flag"] = true
+ return result
+ }
+
+ override fun deleteDevice(devino: String): Boolean {
+ val device = queryDeviceById(devino)
+ if (device != null) {
+ device.deviceStatus = "注销"
+ deviceDao.save(device)
+ return true
+ }
+ return false
+ }
+
+ override fun groupStatus(): List<String>? {
+ return listOf("normal", "closed")
+ }
+
+ override fun queryDeviceByParams(param: DeviceSearchBean): PageResult<TDevice> {
+ val pageable = PageRequest.of(param.pageNo - 1, param.pageSize)
+ val specification = Specification<TDevice> { root, query, cb ->
+ val predicates = ArrayList<Predicate>()
+ if (param.devino != null) {
+ predicates.add(cb.equal(root.get<String>("devino"), param.devino))
+ }
+ if (param.regino != null) {
+ predicates.add(cb.equal(root.get<Int>("areano"), param.regino))
+ }
+ if (param.devistatus != null) {
+ predicates.add(cb.equal(root.get<String>("devistatus"), param.devistatus))
+ }
+ if (param.deviname != null) {
+ predicates.add(cb.like(root.get("deviname"), "%" + param.deviname + "%"))
+ }
+ val array = predicates.toTypedArray()
+ query.where(*array).restriction
+ }
+ return PageResult(deviceDao.findAll(specification, pageable))
+ }
+}
diff --git a/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt b/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt
deleted file mode 100644
index c8b875f..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/DlpayApplicationTests.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.supwisdom.dlpay
-
-import org.junit.runner.RunWith
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.test.context.junit4.SpringRunner
-
-@RunWith(SpringRunner::class)
-@SpringBootTest
-abstract class DlpayApplicationTests{
-
-}
diff --git a/src/test/kotlin/com/supwisdom/dlpay/MvcBaseTest.kt b/src/test/kotlin/com/supwisdom/dlpay/MvcBaseTest.kt
deleted file mode 100644
index 62a56a3..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/MvcBaseTest.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.supwisdom.dlpay
-
-import com.google.gson.Gson
-import org.junit.runner.RunWith
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.test.context.junit4.SpringRunner
-import org.springframework.test.web.servlet.MockMvc
-
-/**
- * mvc 基础测试类
- * 放置基础方法,如认证信息等
- */
-@RunWith(SpringRunner::class)
-@SpringBootTest
-@AutoConfigureMockMvc
-abstract class MvcBaseTest{
- @Autowired
- protected lateinit var mvc: MockMvc
- val gson = Gson()
-}
\ No newline at end of file
diff --git a/src/test/kotlin/com/supwisdom/dlpay/controller/ApiControllerTest.kt b/src/test/kotlin/com/supwisdom/dlpay/controller/ApiControllerTest.kt
deleted file mode 100644
index 0899c9a..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/controller/ApiControllerTest.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.supwisdom.dlpay.controller
-
-import com.supwisdom.dlpay.MvcBaseTest
-import org.junit.Test
-import org.springframework.http.MediaType
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
-import org.springframework.test.web.servlet.result.MockMvcResultHandlers
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers
-
-/**
- * Created by shuwei on 2019/4/16.
- */
-class ApiControllerTest : MvcBaseTest() {
- @Test
- fun testYktPay() {
- //TODO prepare data
- val stuempno="10000097"
- val ret = mvc.perform(MockMvcRequestBuilders.post("/ykt/payinit").content("")
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(MockMvcResultMatchers.status().isOk)
- .andDo(MockMvcResultHandlers.print())
- .andReturn()
- }
-}
\ No newline at end of file
diff --git a/src/test/kotlin/com/supwisdom/dlpay/controller/ShopControllerTest.kt b/src/test/kotlin/com/supwisdom/dlpay/controller/ShopControllerTest.kt
deleted file mode 100644
index c8fd5ec..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/controller/ShopControllerTest.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.supwisdom.dlpay.controller
-
-import com.google.gson.Gson
-import com.supwisdom.dlpay.MvcBaseTest
-import com.supwisdom.dlpay.api.bean.OpenShopParam
-import com.supwisdom.dlpay.api.bean.QueryShopParam
-import com.supwisdom.dlpay.framework.domain.TShop
-import org.junit.Assert
-import org.junit.Test
-import org.springframework.http.MediaType
-import org.springframework.test.context.ActiveProfiles
-
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
-import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
-
-/**
- * Created by shuwei on 2019/4/15.
- */
-@ActiveProfiles("devel-pg")
-class ShopControllerTest : MvcBaseTest() {
- class RetBean {
- var shopid: Int = 0
- var retcode: Int = 0
- lateinit var shop: TShop
- }
-
- @Test
- fun open() {
- val shopParam = OpenShopParam()
- shopParam.shopUniqueId = "ykt_shop_20001"
- shopParam.shopname = "测试名称"
- val gson = Gson()
- val ret = mvc.perform(post("/api/shop/open").content(gson.toJson(shopParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk)
- .andDo(print())
- .andReturn()
- val res = ret.response.contentAsString
- Assert.assertNotNull(res)
- val retBean = gson.fromJson(res, RetBean::class.java)
- Assert.assertNotNull(retBean)
- Assert.assertEquals(0, retBean.retcode)
- Assert.assertNotNull(retBean.shopid)
- Assert.assertNotEquals(0, retBean.shopid)
- }
-
- @Test
- fun get() {
- val shopParam = QueryShopParam()
- shopParam.shopUniqueId = "ykt_shop_20001"
- val gson = Gson()
- val ret = mvc.perform(post("/shop/open").content(gson.toJson(shopParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk)
- .andDo(print())
- .andReturn()
- val resOpen = ret.response.contentAsString
- Assert.assertNotNull(resOpen)
- val retBeanOpen = gson.fromJson(resOpen, RetBean::class.java)
- Assert.assertNotNull(retBeanOpen)
- Assert.assertNotNull(retBeanOpen.shopid)
- shopParam.shopid = retBeanOpen.shopid
-
- val retGet = mvc.perform(get("/shop/get").content(gson.toJson(shopParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk)
- .andDo(print())
- .andReturn()
- val res = retGet.response.contentAsString
- Assert.assertNotNull(res)
- val retBean = gson.fromJson(res, RetBean::class.java)
- Assert.assertNotNull(retBean)
- Assert.assertEquals(0, retBean.retcode)
- Assert.assertNotNull(retBean.shop)
- Assert.assertEquals(retBeanOpen.shopid, retBean.shop.shopid)
- }
-}
\ No newline at end of file
diff --git a/src/test/kotlin/com/supwisdom/dlpay/controller/UserControllerTest.kt b/src/test/kotlin/com/supwisdom/dlpay/controller/UserControllerTest.kt
deleted file mode 100644
index 5dc498e..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/controller/UserControllerTest.kt
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.supwisdom.dlpay.controller
-
-import com.google.gson.Gson
-import com.supwisdom.dlpay.MvcBaseTest
-import com.supwisdom.dlpay.api.bean.OpenUserParam
-import com.supwisdom.dlpay.api.bean.QueryUserParam
-import com.supwisdom.dlpay.api.domain.TAccount
-import com.supwisdom.dlpay.framework.domain.TPerson
-import org.junit.Assert
-import org.junit.Test
-import org.springframework.http.MediaType
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
-import org.springframework.test.web.servlet.result.MockMvcResultHandlers
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers
-
-
-class UserControllerTest : MvcBaseTest() {
-
- class RetBean {
- var userid: String = ""
- var retcode: Int = 0
- lateinit var person: TPerson
- lateinit var account: TAccount
- }
-
- @Test
- fun open() {
- val userParam = OpenUserParam()
- userParam.uid = ""//random req
- userParam.name = "测试名称"
-
- val ret = mvc.perform(MockMvcRequestBuilders.post("/api/user/open").content(gson.toJson(userParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(MockMvcResultMatchers.status().isOk)
- .andDo(MockMvcResultHandlers.print())
- .andReturn()
- val res = ret.response.contentAsString
- Assert.assertNotNull(res)
- val retBean = gson.fromJson(res, RetBean::class.java)
- Assert.assertNotNull(retBean)
- Assert.assertEquals(0, retBean.retcode)
- Assert.assertNotNull(retBean.userid)
- Assert.assertNotEquals("", retBean.userid)
- }
-
- @Test
- fun get() {
-
- val userParam = QueryUserParam()
- userParam.uid = "testuseruniqueId"//测试用
- val gson = Gson()
- val ret = mvc.perform(MockMvcRequestBuilders.post("/api/user/open").content(gson.toJson(userParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(MockMvcResultMatchers.status().isOk)
- .andDo(MockMvcResultHandlers.print())
- .andReturn()
- val resOpen = ret.response.contentAsString
- Assert.assertNotNull(resOpen)
- val retBeanOpen = gson.fromJson(resOpen, RetBean::class.java)
- Assert.assertNotNull(retBeanOpen)
- Assert.assertNotNull(retBeanOpen.userid)
- userParam.userid = retBeanOpen.userid
-
- val retGet = mvc.perform(MockMvcRequestBuilders.get("/api/user/query").content(gson.toJson(userParam))
- .contentType(MediaType.APPLICATION_JSON))
- .andExpect(MockMvcResultMatchers.status().isOk)
- .andDo(MockMvcResultHandlers.print())
- .andReturn()
- val res = retGet.response.contentAsString
- Assert.assertNotNull(res)
- val retBean = gson.fromJson(res, RetBean::class.java)
- Assert.assertNotNull(retBean)
- Assert.assertEquals(0, retBean.retcode)
- Assert.assertNotNull(retBean.person)
- Assert.assertEquals(retBeanOpen.userid, retBean.person.userid)
- Assert.assertNotNull(retBeanOpen.account)
- Assert.assertEquals(retBeanOpen.person.userid, retBean.account.userid)
- }
-
-}
\ No newline at end of file
diff --git a/src/test/kotlin/com/supwisdom/dlpay/controller/security_controller_test.kt b/src/test/kotlin/com/supwisdom/dlpay/controller/security_controller_test.kt
deleted file mode 100644
index 24853db..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/controller/security_controller_test.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.supwisdom.dlpay.controller
-
-import com.supwisdom.dlpay.MvcBaseTest
-import com.supwisdom.dlpay.framework.core.JwtConfig
-import com.supwisdom.dlpay.framework.util.HmacUtil
-import io.restassured.RestAssured
-import io.restassured.RestAssured.*
-import io.restassured.http.ContentType
-import io.restassured.path.json.JsonPath.from
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.*
-import org.junit.Before
-import org.junit.Test
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.boot.web.server.LocalServerPort
-import org.springframework.test.context.ActiveProfiles
-import java.text.SimpleDateFormat
-import java.util.*
-
-@ActiveProfiles("devel-pg-local")
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-class SecurityControllerTest : MvcBaseTest() {
- val appid = "100001"
- val appsecret = "oUw2NmA09ficiVWD4TUQLDOkPyzQa3VzbjjsW0B2qTk="
-
- @LocalServerPort
- private var port: Int = 0
-
- @Autowired
- lateinit var jwtConfig: JwtConfig
-
- @Before
- fun setUp() {
- RestAssured.port = port
- }
-
- fun getJwt(id: String, secret: String): String {
- val token = given().param("appid", id)
- .`when`()
- .get("/api/auth/gettoken")
- .then()
- .contentType(ContentType.JSON)
- .statusCode(200)
- .body("token", notNullValue())
- .extract().path<String>("token")
-
- val tokenCrypt = HmacUtil.HMACSHA256(token, secret)
-
- return given().param("appid", id)
- .param("secret", tokenCrypt)
- .`when`()
- .get("/api/auth/authentication")
- .then()
- .statusCode(200)
- .contentType(ContentType.JSON)
- .body("jwt", notNullValue())
- .extract().response().let {
- val exp = it.path<String>("expiredAt").run {
- SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").parse(this)
- }
- val now = Calendar.getInstance()
- assertThat(now.time, lessThanOrEqualTo(exp))
- it.path<String>("jwt")
- }
- }
-
- @Test
- fun testGetJwt() {
- getJwt(appid, appsecret)
- }
-
- @Test
- fun testGetJwtClient() {
- val clientid = "000030450"
- val response = given().param("appid", appid)
- .`when`()
- .get("/api/auth/gettoken/$clientid")
- .then()
- .statusCode(200)
- .body("token", notNullValue())
- .extract()
-
- val token = from(response.body().asString()).getString("token")
- val secret = HmacUtil.HMACSHA256(token, appsecret)
-
- given().param("appid", appid)
- .param("secret", secret)
- .`when`()
- .get("/api/auth/authentication/$clientid")
- .then()
- .statusCode(200)
- .body("jwt", notNullValue())
- }
-
- @Test
- fun testJwtRefresh() {
- getJwt(appid, appsecret).also { jwt ->
- given().header(jwtConfig.header, "${jwtConfig.tokenHeader}$jwt")
- .`when`()
- .get("/api/auth/refresh")
- .then()
- .statusCode(200)
- .body("jwt", notNullValue())
- }
- }
-
- @Test
- fun testAuthencationFail() {
- given().param("appid", appid)
- .`when`()
- .get("/api/auth/gettoken")
- .then()
- .body("token", notNullValue())
- .extract()
- .path<String>("token").also { token ->
- given().param("appid", appid)
- .param("secret", token)
- .`when`()
- .get("/api/auth/authentication")
- .then()
- .statusCode(401)
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/test/kotlin/com/supwisdom/dlpay/password_test.kt b/src/test/kotlin/com/supwisdom/dlpay/password_test.kt
deleted file mode 100644
index a89d759..0000000
--- a/src/test/kotlin/com/supwisdom/dlpay/password_test.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.supwisdom.dlpay
-
-import org.junit.Test
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
-import org.springframework.security.crypto.password.DelegatingPasswordEncoder
-import org.springframework.security.crypto.password.PasswordEncoder
-import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
-import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder
-import java.util.*
-
-
-class PasswordTest {
- private fun encodePassword(pswd: String) {
- val encoders = HashMap<String, PasswordEncoder>()
- encoders["bcrypt"] = BCryptPasswordEncoder()
- encoders["pbkdf2"] = Pbkdf2PasswordEncoder()
- encoders["scrypt"] = SCryptPasswordEncoder()
- val passwordEncoder = DelegatingPasswordEncoder("bcrypt", encoders)
- println(passwordEncoder.encode(pswd))
-
- }
-
- @Test
- fun testPassword() {
- encodePassword("123456")
- }
-}
\ No newline at end of file