@ -1,15 +1,21 @@
package com.glxp.udi.admin.controller.device ;
import com.github.pagehelper.PageInfo ;
import com.glxp.udi.admin.annotation.AuthRuleAnnotation ;
import com.glxp.udi.admin.dao.udid.DeviceMapper ;
import com.glxp.udi.admin.dao.udid.DevicedownloadMapper ;
import com.glxp.udi.admin.entity.auth.AuthAdmin ;
import com.glxp.udi.admin.entity.info.CompanyEntity ;
import com.glxp.udi.admin.entity.udid.* ;
import com.glxp.udi.admin.exception.JsonException ;
import com.glxp.udi.admin.req.udid.* ;
import com.glxp.udi.admin.res.PageSimpleResponse ;
import com.glxp.udi.admin.res.udid.ProgressResponse ;
import com.glxp.udi.admin.service.auth.AuthAdminService ;
import com.glxp.udi.admin.service.info.CompanyService ;
import com.glxp.udi.admin.service.inout.DeviceService ;
import com.glxp.udi.admin.service.inout.DruginfoService ;
import com.glxp.udi.admin.service.publish.UdiDeviceIdService ;
import com.glxp.udi.common.enums.ResultEnum ;
import com.glxp.udi.common.res.BaseResponse ;
import com.glxp.udi.common.util.ResultVOUtils ;
@ -19,8 +25,11 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RestController ;
import org.springframework.web.context.request.RequestContextHolder ;
import org.springframework.web.context.request.ServletRequestAttributes ;
import javax.annotation.Resource ;
import javax.servlet.http.HttpServletRequest ;
import javax.validation.Valid ;
import java.util.ArrayList ;
import java.util.List ;
@ -32,6 +41,8 @@ public class DeviceController {
DeviceMapper deviceMapper ;
@Resource
DruginfoService druginfoService ;
@Resource
AuthAdminService authAdminService ;
@Resource
private DeviceService deviceService ;
@ -82,11 +93,9 @@ public class DeviceController {
}
String key = deviceListRequest . getKey ( ) ;
boolean isScan = false ;
if ( key ! = null & & key . length ( ) > 22 ) {
key = key . substring ( 2 , 16 ) ;
deviceListRequest . setKey ( key ) ;
isScan = true ;
}
Device device = deviceService . searchByBs ( key ) ;
long total = 1 ;
@ -121,14 +130,19 @@ public class DeviceController {
pageSimpleResponse . setList ( deviceEntityList ) ;
return ResultVOUtils . success ( pageSimpleResponse ) ;
}
@GetMapping ( "warehouse/device/unionSearch" )
public BaseResponse search ( @Valid DeviceSearchRequest deviceSearchRequest , BindingResult bindingResult ) {
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
if ( bindingResult . hasErrors ( ) ) {
return ResultVOUtils . error ( ResultEnum . PARAM_VERIFY_FALL , bindingResult . getFieldError ( ) . getDefaultMessage ( ) ) ;
}
deviceSearchRequest . setCustomerId ( authAdmin . getCustomerId ( ) + "" ) ;
List < DeviceEntity > medicalResonseList = deviceService . search ( deviceSearchRequest ) ;
long total = deviceService . seatchTotal ( deviceSearchRequest ) ;
PageSimpleResponse < DeviceEntity > pageSimpleResponse = new PageSimpleResponse < > ( ) ;
@ -137,6 +151,20 @@ public class DeviceController {
return ResultVOUtils . success ( pageSimpleResponse ) ;
}
@Resource
UdiDeviceIdService udiDeviceIdService ;
@GetMapping ( "warehouse/device/downloadAll" )
public BaseResponse downloadAll ( ) {
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
return ResultVOUtils . success ( "下载成功" ) ;
}
@GetMapping ( "warehouse/device/combineSearch" )
public BaseResponse combineSearch ( @Valid DeviceSearchRequest deviceSearchRequest , BindingResult bindingResult ) {
@ -155,11 +183,11 @@ public class DeviceController {
total = devicedownload . getAlltotal ( ) - devicedownload . getAllindex ( ) ;
}
for ( int i = 0 ; i < medicalResonseList . size ( ) ; i + + ) {
for ( int i = 0 ; i < medicalResonseList . size ( ) ; i + + ) {
String nameCode = medicalResonseList . get ( i ) . getZxxsdycpbs ( ) ;
if ( druginfoService . isExit ( nameCode ) ) {
if ( druginfoService . isExit ( nameCode ) ) {
medicalResonseList . get ( i ) . setCheck ( true ) ;
} else
} else
medicalResonseList . get ( i ) . setCheck ( false ) ;
}
@ -168,12 +196,20 @@ public class DeviceController {
return ResultVOUtils . success ( pageSimpleResponse ) ;
}
@AuthRuleAnnotation ( "" )
@PostMapping ( "warehouse/device/loadsingle" )
public BaseResponse downLoadDiii ( @RequestBody DeviceDiRequest deviceRequest ) {
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyService ) ;
if ( deviceRequest . getPrimaryDeviceId ( ) = = null ) {
return ResultVOUtils . error ( 999 , "最小销售单元标识不能为空" ) ;
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
CompanyEntity companyEntity = companyService . findCompany ( authAdmin . getCustomerId ( ) ) ;
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyEntity ) ;
if ( deviceRequest . getPrimaryDeviceId ( ) = = null ) {
return ResultVOUtils . error ( 999 , "最小销售单元标识不能为空" ) ;
}
new Thread ( ( ) - > {
@ -181,7 +217,7 @@ public class DeviceController {
DownloadDiRequest downloadDiRequest1 = new DownloadDiRequest ( ) ;
downloadDiRequest1 . setAccessToken ( token . getAccessToken ( ) ) ;
downloadDiRequest1 . setPrimaryDeviceId ( deviceRequest . getPrimaryDeviceId ( ) ) ;
int result = downloadDeviceHelper . downloadBydi ( downloadDiRequest1 , deviceService ) ;
int result = downloadDeviceHelper . downloadBydi ( authAdmin . getCustomerId ( ) + "" , downloadDiRequest1 , deviceService ) ;
if ( result = = - 1 ) {
return ; // ResultVOUtils.error(505, "下载出错");
}
@ -192,9 +228,17 @@ public class DeviceController {
@PostMapping ( "warehouse/device/downLoadHisory" )
public BaseResponse downLoadHisory ( @RequestBody DeviceDiRequest deviceRequest ) {
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyService ) ;
if ( deviceRequest . getPrimaryDeviceId ( ) = = null ) {
return ResultVOUtils . error ( 999 , "最小销售单元标识不能为空" ) ;
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
CompanyEntity companyEntity = companyService . findCompany ( authAdmin . getCustomerId ( ) ) ;
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyEntity ) ;
if ( deviceRequest . getPrimaryDeviceId ( ) = = null ) {
return ResultVOUtils . error ( 999 , "最小销售单元标识不能为空" ) ;
}
new Thread ( ( ) - > {
String deviceRecordKey = deviceService . selectKey ( deviceRequest . getPrimaryDeviceId ( ) ) ;
@ -202,12 +246,12 @@ public class DeviceController {
DownloadHistoryRequest deviceHistoryRequest = new DownloadHistoryRequest ( ) ;
deviceHistoryRequest . setAccessToken ( token . getAccessToken ( ) ) ;
deviceHistoryRequest . setCurrentPageNumber ( "1" ) ;
List < DownloadHistoryRequest . DataSetBean > dataSetBeans = new ArrayList < > ( ) ;
List < DownloadHistoryRequest . DataSetBean > dataSetBeans = new ArrayList < > ( ) ;
DownloadHistoryRequest . DataSetBean keys = new DownloadHistoryRequest . DataSetBean ( ) ;
keys . setDeviceRecordKey ( deviceRecordKey ) ;
dataSetBeans . add ( keys ) ;
deviceHistoryRequest . setDataSet ( dataSetBeans ) ;
int result = downloadDeviceHelper . downloadHistory ( deviceHistoryRequest, deviceService ) ;
int result = downloadDeviceHelper . downloadHistory ( authAdmin. getCustomerId ( ) + "" , deviceHistoryRequest, deviceService ) ;
if ( result = = - 1 ) {
return ; // ResultVOUtils.error(505, "下载出错");
}
@ -217,9 +261,18 @@ public class DeviceController {
}
@PostMapping ( "warehouse/device/loadudid" )
public BaseResponse downLoadAll ( DownloadDeviceRequest downloadDeviceRequest , BindingResult bindingResult ) {
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyService ) ;
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
CompanyEntity companyEntity = companyService . findCompany ( authAdmin . getCustomerId ( ) ) ;
DownloadDeviceHelper downloadDeviceHelper = new DownloadDeviceHelper ( companyEntity ) ;
if ( bindingResult . hasErrors ( ) ) {
return ResultVOUtils . error ( ResultEnum . PARAM_VERIFY_FALL , bindingResult . getFieldError ( ) . getDefaultMessage ( ) ) ;
}
@ -228,22 +281,22 @@ public class DeviceController {
TokenEntity token = downloadDeviceHelper . getToken ( ) ;
int total = downloadDeviceHelper . getTotal ( token . getAccessToken ( ) ) ;
int curpage = total ;
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( "udid ") ;
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( authAdmin . getCustomerId ( ) + " ") ;
if ( devicedownload ! = null ) {
int offset = devicedownload . getAlltotal ( ) - devicedownload . getAllindex ( ) ;
curpage = total - offset ;
} else {
devicedownload = new Devicedownload ( ) ;
devicedownload . setId ( "udid ") ;
devicedownload = new Devicedownload ( ) ;
devicedownload . setId ( authAdmin . getCustomerId ( ) + " ") ;
devicedownload . setAlltotal ( 100 ) ;
devicedownload . setAllindex ( 99 ) ;
devicedownload . setAllindex ( 100 ) ;
devicedownloadMapper . insert ( devicedownload ) ;
}
devicedownload . setIsdownload ( 1 ) ;
long startTime = System . currentTimeMillis ( ) ;
devicedownload . setStarttime ( startTime + "" ) ;
devicedownloadMapper . updateByPrimaryKey ( devicedownload ) ;
Devicedownload stop = devicedownloadMapper . selectByPrimaryKey ( "udid ") ;
Devicedownload stop = devicedownloadMapper . selectByPrimaryKey ( authAdmin . getCustomerId ( ) + " ") ;
while ( curpage > 0 & & stop . getIsdownload ( ) = = 1 & & stop . getStarttime ( ) . equals ( startTime + "" ) ) {
@ -251,7 +304,7 @@ public class DeviceController {
deviceRequest . setAccessToken ( token . getAccessToken ( ) ) ;
deviceRequest . setRequestType ( 3 + "" ) ;
deviceRequest . setCurrentPageNumber ( curpage + "" ) ;
int result = downloadDeviceHelper . download Devices( deviceService , deviceRequest ) ;
int result = downloadDeviceHelper . download Product( authAdmin . getCustomerId ( ) + "" , deviceService , deviceRequest ) ;
if ( result = = - 1 ) {
return ; // ResultVOUtils.error(505, "下载出错");
}
@ -259,24 +312,24 @@ public class DeviceController {
Devicedownload devicedownload1 = new Devicedownload ( ) ;
devicedownload1 . setAlltotal ( total ) ;
devicedownload1 . setAllindex ( curpage ) ;
devicedownload1 . setId ( "udid ") ;
devicedownload1 . setId ( authAdmin . getCustomerId ( ) + " ") ;
devicedownloadMapper . updateProgress ( devicedownload1 ) ;
stop = devicedownloadMapper . selectByPrimaryKey ( "udid ") ;
stop = devicedownloadMapper . selectByPrimaryKey ( authAdmin . getCustomerId ( ) + " ") ;
}
} ) . start ( ) ;
// Devicedownload devicedownload1 = new Devicedownload();
// devicedownload1.setAlltotal(total);
// devicedownload1.setAllindex(curpage + 1);
// devicedownload1.setId("udid");
// devicedownloadMapper.updateByExample(devicedownload1, new DevicedownloadExample());
return ResultVOUtils . success ( "开始下载" ) ;
}
@GetMapping ( "warehouse/device/stop" )
public BaseResponse stopDown ( ) {
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( "udid" ) ;
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( authAdmin . getCustomerId ( ) + "" ) ;
devicedownload . setIsdownload ( 2 ) ;
devicedownloadMapper . updateByPrimaryKey ( devicedownload ) ;
return ResultVOUtils . success ( "停止成功" ) ;
@ -284,7 +337,14 @@ public class DeviceController {
@GetMapping ( "warehouse/device/progress" )
public BaseResponse getProgress ( ) {
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( "udid" ) ;
ServletRequestAttributes attributes = ( ServletRequestAttributes ) RequestContextHolder . getRequestAttributes ( ) ;
if ( attributes = = null ) {
throw new JsonException ( ResultEnum . NOT_NETWORK ) ;
}
HttpServletRequest request = attributes . getRequest ( ) ;
String userId = request . getHeader ( "ADMIN_ID" ) ;
AuthAdmin authAdmin = authAdminService . findById ( Long . parseLong ( userId ) ) ;
Devicedownload devicedownload = devicedownloadMapper . selectByPrimaryKey ( authAdmin . getCustomerId ( ) + "" ) ;
ProgressResponse response = new ProgressResponse ( ) ;
if ( devicedownload ! = null ) {
double index = devicedownload . getAlltotal ( ) - devicedownload . getAllindex ( ) ;
@ -297,9 +357,9 @@ public class DeviceController {
response . setIndex ( index * 10 ) ;
response . setProgress ( progress * 100 ) ;
} else {
response . setTotal ( 100 ) ;
response . setIndex ( 1 ) ;
response . setProgress ( 1 ) ;
response . setTotal ( 100 0 ) ;
response . setIndex ( 0 ) ;
response . setProgress ( 0 ) ;
}
return ResultVOUtils . success ( response ) ;