Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
data-acquisition
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
竹天卫
data-acquisition
Commits
1900ea9b
Commit
1900ea9b
authored
Apr 26, 2021
by
renchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
送验单模块代码编写
parent
02b3b0eb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
134 additions
and
38 deletions
+134
-38
TSampleLaboratorysheetController.java
...business/controller/TSampleLaboratorysheetController.java
+13
-1
ITSampleLaboratorysheetService.java
...tion/business/service/ITSampleLaboratorysheetService.java
+4
-0
TSampleLaboratorysheetServiceImpl.java
...iness/service/impl/TSampleLaboratorysheetServiceImpl.java
+30
-0
TSampleListServiceImpl.java
...isition/business/service/impl/TSampleListServiceImpl.java
+4
-33
ImageUtil.java
.../java/cn/wise/sc/acquisition/business/util/ImageUtil.java
+83
-4
No files found.
acquisition-business/src/main/java/cn/wise/sc/acquisition/business/controller/TSampleLaboratorysheetController.java
View file @
1900ea9b
...
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* <p>
* <p>
* 前端控制器
* 前端控制器
...
@@ -81,6 +83,16 @@ public class TSampleLaboratorysheetController {
...
@@ -81,6 +83,16 @@ public class TSampleLaboratorysheetController {
return
tSampleLaboratorysheetService
.
insertTSampleLaboratorysheet
(
tSampleLaboratorysheetQuery
);
return
tSampleLaboratorysheetService
.
insertTSampleLaboratorysheet
(
tSampleLaboratorysheetQuery
);
}
}
/**
* 二维码下载
*
* @param tSampleLaboratorysheetQuery
* @return
*/
@ApiOperation
(
value
=
"二维码下载"
)
@RequestMapping
(
value
=
"/getImage"
,
method
=
RequestMethod
.
POST
)
public
R
getImage
(
TSampleLaboratorysheetQuery
tSampleLaboratorysheetQuery
,
final
HttpServletResponse
response
)
{
return
tSampleLaboratorysheetService
.
getImage
(
tSampleLaboratorysheetQuery
,
response
);
}
}
}
acquisition-business/src/main/java/cn/wise/sc/acquisition/business/service/ITSampleLaboratorysheetService.java
View file @
1900ea9b
...
@@ -5,6 +5,8 @@ import cn.wise.sc.acquisition.business.model.query.TSampleLaboratorysheetQuery;
...
@@ -5,6 +5,8 @@ import cn.wise.sc.acquisition.business.model.query.TSampleLaboratorysheetQuery;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* <p>
* <p>
* 服务类
* 服务类
...
@@ -22,4 +24,6 @@ public interface ITSampleLaboratorysheetService extends IService<TSampleLaborato
...
@@ -22,4 +24,6 @@ public interface ITSampleLaboratorysheetService extends IService<TSampleLaborato
R
deleteByYh
(
TSampleLaboratorysheetQuery
tSampleLaboratorysheetQuery
);
R
deleteByYh
(
TSampleLaboratorysheetQuery
tSampleLaboratorysheetQuery
);
R
insertTSampleLaboratorysheet
(
TSampleLaboratorysheetQuery
tSampleLaboratorysheetQuery
);
R
insertTSampleLaboratorysheet
(
TSampleLaboratorysheetQuery
tSampleLaboratorysheetQuery
);
R
getImage
(
TSampleLaboratorysheetQuery
query
,
final
HttpServletResponse
response
);
}
}
acquisition-business/src/main/java/cn/wise/sc/acquisition/business/service/impl/TSampleLaboratorysheetServiceImpl.java
View file @
1900ea9b
...
@@ -2,10 +2,12 @@ package cn.wise.sc.acquisition.business.service.impl;
...
@@ -2,10 +2,12 @@ package cn.wise.sc.acquisition.business.service.impl;
import
cn.wise.sc.acquisition.business.constant.Rcode
;
import
cn.wise.sc.acquisition.business.constant.Rcode
;
import
cn.wise.sc.acquisition.business.entity.TSampleLaboratorysheet
;
import
cn.wise.sc.acquisition.business.entity.TSampleLaboratorysheet
;
import
cn.wise.sc.acquisition.business.enumation.ProjectEnum
;
import
cn.wise.sc.acquisition.business.mapper.TSampleLaboratorysheetMapper
;
import
cn.wise.sc.acquisition.business.mapper.TSampleLaboratorysheetMapper
;
import
cn.wise.sc.acquisition.business.model.query.TSampleLaboratorysheetQuery
;
import
cn.wise.sc.acquisition.business.model.query.TSampleLaboratorysheetQuery
;
import
cn.wise.sc.acquisition.business.model.query.TSampleListQuery
;
import
cn.wise.sc.acquisition.business.model.query.TSampleListQuery
;
import
cn.wise.sc.acquisition.business.service.ITSampleLaboratorysheetService
;
import
cn.wise.sc.acquisition.business.service.ITSampleLaboratorysheetService
;
import
cn.wise.sc.acquisition.business.util.ImageUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.baomidou.mybatisplus.extension.api.R
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
@@ -13,6 +15,10 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -13,6 +15,10 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* <p>
* <p>
...
@@ -98,6 +104,9 @@ public class TSampleLaboratorysheetServiceImpl extends ServiceImpl<TSampleLabora
...
@@ -98,6 +104,9 @@ public class TSampleLaboratorysheetServiceImpl extends ServiceImpl<TSampleLabora
//封装
//封装
TSampleLaboratorysheet
tSampleLaboratorysheet
=
new
TSampleLaboratorysheet
();
TSampleLaboratorysheet
tSampleLaboratorysheet
=
new
TSampleLaboratorysheet
();
BeanUtils
.
copyProperties
(
tSampleLaboratorysheetQuery
,
tSampleLaboratorysheet
);
BeanUtils
.
copyProperties
(
tSampleLaboratorysheetQuery
,
tSampleLaboratorysheet
);
//生成二维码 并且保存
tSampleLaboratorysheet
.
setQRCode
(
ImageUtil
.
QRCodeGenerator
(
JSON
.
toJSONString
(
tSampleLaboratorysheet
)));
//保存
int
insert
=
baseMapper
.
insert
(
tSampleLaboratorysheet
);
int
insert
=
baseMapper
.
insert
(
tSampleLaboratorysheet
);
if
(
insert
>
0
)
{
if
(
insert
>
0
)
{
return
R
.
ok
(
"添加成功"
);
return
R
.
ok
(
"添加成功"
);
...
@@ -106,4 +115,25 @@ public class TSampleLaboratorysheetServiceImpl extends ServiceImpl<TSampleLabora
...
@@ -106,4 +115,25 @@ public class TSampleLaboratorysheetServiceImpl extends ServiceImpl<TSampleLabora
return
R
.
failed
(
"添加失败"
);
return
R
.
failed
(
"添加失败"
);
}
}
}
}
/**
* 获取图片二维码
*
* @param query
* @param response
*/
@Override
@Transactional
public
R
getImage
(
TSampleLaboratorysheetQuery
query
,
final
HttpServletResponse
response
)
{
log
.
info
(
JSON
.
toJSONString
(
query
));
//参加校验
Rcode
.
NOT_PARAM
.
assertNotNull
(
query
);
Rcode
.
NOT_PARAM
.
assertNotEmpty
(
query
.
getYh
());
TSampleLaboratorysheet
tSampleLaboratorysheet
=
baseMapper
.
selectById
(
query
.
getYh
());
//获取二维码或者记录形式
ImageUtil
.
getImage
(
ProjectEnum
.
ImageType
.
QR_CODE
.
getValue
(),
tSampleLaboratorysheet
,
response
);
//如果下载失败才会执行return
return
R
.
failed
(
"该条数据没有图片"
);
}
}
}
acquisition-business/src/main/java/cn/wise/sc/acquisition/business/service/impl/TSampleListServiceImpl.java
View file @
1900ea9b
...
@@ -154,7 +154,7 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
...
@@ -154,7 +154,7 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
TSampleList
tSampleList
=
new
TSampleList
();
TSampleList
tSampleList
=
new
TSampleList
();
BeanUtils
.
copyProperties
(
query
,
tSampleList
);
BeanUtils
.
copyProperties
(
query
,
tSampleList
);
//转化图片
//转化图片
setImage
(
query
,
tSampleList
,
file
);
ImageUtil
.
setImage
(
query
.
getImageType
()
,
tSampleList
,
file
);
//保存
//保存
int
update
=
baseMapper
.
updateById
(
tSampleList
);
int
update
=
baseMapper
.
updateById
(
tSampleList
);
if
(
update
>
0
)
{
if
(
update
>
0
)
{
...
@@ -165,22 +165,6 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
...
@@ -165,22 +165,6 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
}
}
/**
* 私有方法,根据类型保存并转化文件为图片 需要请求参数ImageType 保存的实体TSampleList 以及file
*/
private
void
setImage
(
TSampleListQuery
query
,
TSampleList
tSampleList
,
MultipartFile
file
)
{
//判断保存二维码还是记录形式
Optional
<
Integer
>
ofNullable
=
Optional
.
ofNullable
(
query
.
getImageType
());
ofNullable
.
ifPresent
(
e
->
{
if
(
ProjectEnum
.
ImageType
.
getLabel
(
query
.
getImageType
()).
equals
(
ProjectEnum
.
ImageType
.
RECORD_CODE
.
getLabel
()))
{
tSampleList
.
setRecordCode
(
ImageUtil
.
transformByte
(
file
));
}
if
(
ProjectEnum
.
ImageType
.
getLabel
(
query
.
getImageType
()).
equals
(
ProjectEnum
.
ImageType
.
QR_CODE
.
getLabel
()))
{
tSampleList
.
setQRCode
(
ImageUtil
.
transformByte
(
file
));
}
});
}
/**
/**
* 获取图片二维码
* 获取图片二维码
*
*
...
@@ -196,22 +180,9 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
...
@@ -196,22 +180,9 @@ public class TSampleListServiceImpl extends ServiceImpl<TSampleListMapper, TSamp
Rcode
.
NOT_PARAM
.
assertNotEmpty
(
query
.
getYh
());
Rcode
.
NOT_PARAM
.
assertNotEmpty
(
query
.
getYh
());
Rcode
.
NOT_PARAM
.
assertNotNull
(
query
.
getImageType
());
Rcode
.
NOT_PARAM
.
assertNotNull
(
query
.
getImageType
());
TSampleList
tSampleList
=
baseMapper
.
selectById
(
query
.
getYh
());
TSampleList
tSampleList
=
baseMapper
.
selectById
(
query
.
getYh
());
//判断获取二维码还是记录形式
//获取二维码或者记录形式
Optional
<
Integer
>
ofNullable
=
Optional
.
ofNullable
(
query
.
getImageType
());
ImageUtil
.
getImage
(
query
.
getImageType
(),
tSampleList
,
response
);
ofNullable
.
ifPresent
(
e
->
{
//如果下载失败才会执行return
byte
[]
data
=
null
;
if
(
ProjectEnum
.
ImageType
.
getLabel
(
query
.
getImageType
()).
equals
(
ProjectEnum
.
ImageType
.
RECORD_CODE
.
getLabel
()))
{
data
=
tSampleList
.
getRecordCode
();
}
if
(
ProjectEnum
.
ImageType
.
getLabel
(
query
.
getImageType
()).
equals
(
ProjectEnum
.
ImageType
.
QR_CODE
.
getLabel
()))
{
data
=
tSampleList
.
getQRCode
();
}
if
(
data
!=
null
)
{
//下载图片
ImageUtil
.
transformImage
(
data
,
response
);
}
});
return
R
.
failed
(
"该条数据没有图片"
);
return
R
.
failed
(
"该条数据没有图片"
);
}
}
...
...
acquisition-business/src/main/java/cn/wise/sc/acquisition/business/util/ImageUtil.java
View file @
1900ea9b
package
cn
.
wise
.
sc
.
acquisition
.
business
.
util
;
package
cn
.
wise
.
sc
.
acquisition
.
business
.
util
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.extra.qrcode.QrCodeUtil
;
import
cn.wise.sc.acquisition.business.entity.TSampleLaboratorysheet
;
import
cn.wise.sc.acquisition.business.entity.TSampleList
;
import
cn.wise.sc.acquisition.business.enumation.ProjectEnum
;
import
cn.wise.sc.acquisition.business.model.query.TSampleListQuery
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.alibaba.fastjson.TypeReference
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.io.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
/**
/**
* Author renchao
* Author renchao
* 文件上传下载转化工具类
* 文件上传下载转化工具类
,二维码生成
*/
*/
public
class
ImageUtil
{
public
class
ImageUtil
{
...
@@ -92,13 +102,14 @@ public class ImageUtil {
...
@@ -92,13 +102,14 @@ public class ImageUtil {
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
OutputStream
outputSream
=
null
;
OutputStream
outputSream
=
null
;
try
{
try
{
List
<
byte
[]>
bytes
=
JSON
.
parseObject
(
new
String
(
data
),
new
TypeReference
<
List
<
byte
[]>>()
{});
List
<
byte
[]>
bytes
=
JSON
.
parseObject
(
new
String
(
data
),
new
TypeReference
<
List
<
byte
[]>>()
{
});
outputSream
=
response
.
getOutputStream
();
outputSream
=
response
.
getOutputStream
();
for
(
byte
[]
picture
:
bytes
)
{
for
(
byte
[]
picture
:
bytes
)
{
outputSream
.
write
(
picture
);
outputSream
.
write
(
picture
);
}
}
outputSream
.
flush
();
outputSream
.
flush
();
if
(
outputSream
!=
null
)
{
if
(
outputSream
!=
null
)
{
outputSream
.
close
();
outputSream
.
close
();
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -107,4 +118,72 @@ public class ImageUtil {
...
@@ -107,4 +118,72 @@ public class ImageUtil {
}
}
}
}
/**
* 根据obj类型获取图片
*/
public
static
void
getImage
(
Integer
imageType
,
Object
obj
,
final
HttpServletResponse
response
)
{
if
(
imageType
==
null
||
imageType
.
intValue
()
==
0
)
throw
new
RuntimeException
(
"下载图片时imageType为空"
);
if
(
obj
==
null
)
throw
new
RuntimeException
(
"下载图片时obj为空"
);
if
(
response
==
null
)
throw
new
RuntimeException
(
"下载图片时response为空"
);
byte
[]
data
=
null
;
if
(
obj
instanceof
TSampleList
)
{
TSampleList
tSampleList
=
(
TSampleList
)
obj
;
//判断获取二维码还是记录形式
if
(
ProjectEnum
.
ImageType
.
getLabel
(
imageType
).
equals
(
ProjectEnum
.
ImageType
.
RECORD_CODE
.
getLabel
()))
{
data
=
tSampleList
.
getRecordCode
();
}
if
(
ProjectEnum
.
ImageType
.
getLabel
(
imageType
).
equals
(
ProjectEnum
.
ImageType
.
QR_CODE
.
getLabel
()))
{
data
=
tSampleList
.
getQRCode
();
}
}
else
if
(
obj
instanceof
TSampleLaboratorysheet
)
{
TSampleLaboratorysheet
tSampleLaboratorysheet
=
(
TSampleLaboratorysheet
)
obj
;
data
=
tSampleLaboratorysheet
.
getQRCode
();
}
if
(
data
!=
null
)
{
//下载图片
ImageUtil
.
transformImage
(
data
,
response
);
}
return
;
}
/**
* 根据类型保存并转化文件为图片 需要请求参数ImageType 保存的实体TSampleList 以及file
*/
public
static
void
setImage
(
Integer
imageType
,
Object
obj
,
MultipartFile
file
)
{
if
(
obj
instanceof
TSampleList
)
{
TSampleList
tSampleList
=
(
TSampleList
)
obj
;
//判断保存二维码还是记录形式
if
(
ProjectEnum
.
ImageType
.
getLabel
(
imageType
).
equals
(
ProjectEnum
.
ImageType
.
RECORD_CODE
.
getLabel
()))
{
tSampleList
.
setRecordCode
(
transformByte
(
file
));
}
if
(
ProjectEnum
.
ImageType
.
getLabel
(
imageType
).
equals
(
ProjectEnum
.
ImageType
.
QR_CODE
.
getLabel
()))
{
tSampleList
.
setQRCode
(
transformByte
(
file
));
}
}
else
if
(
obj
instanceof
TSampleLaboratorysheet
)
{
TSampleLaboratorysheet
tSampleLaboratorysheet
=
(
TSampleLaboratorysheet
)
obj
;
tSampleLaboratorysheet
.
setQRCode
(
transformByte
(
file
));
}
}
/**
* 二维码生成工具类
*
* @param content
*/
public
static
byte
[]
QRCodeGenerator
(
String
content
)
{
if
(
StringUtils
.
isEmpty
(
content
))
throw
new
RuntimeException
(
"二维码转化内容为空"
);
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
BufferedImage
bufferedImage
=
QrCodeUtil
.
generate
(
content
,
200
,
200
);
try
{
ImageIO
.
write
(
bufferedImage
,
"png"
,
stream
);
stream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//String encode = Base64.encode(stream.toByteArray());
return
stream
.
toByteArray
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment