You've already forked FrameTour-BE
Merge remote-tracking branch 'origin/master'
This commit is contained in:
21
src/main/java/com/ycwl/basic/config/FaceDetectConfig.java
Normal file
21
src/main/java/com/ycwl/basic/config/FaceDetectConfig.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.ycwl.basic.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 阿里云OSS配置
|
||||
*
|
||||
* @author songmingsong
|
||||
**/
|
||||
@Data
|
||||
@Component
|
||||
public class FaceDetectConfig {
|
||||
@Value("${aliYunFace.accessKeyId}")
|
||||
private String accessKeyId;
|
||||
@Value("${aliYunFace.accessKeySecret}")
|
||||
private String accessKeySecret;
|
||||
@Value("${aliYunFace.region}")
|
||||
private String region;
|
||||
}
|
@ -21,4 +21,6 @@ public interface DeviceMapper {
|
||||
int deleteById(Long id);
|
||||
int update(DeviceAddOrUpdateReq deviceReqQuery);
|
||||
int updateStatus(Long id);
|
||||
|
||||
List<DeviceRespVO> listByScenicId(Long scenicId);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.ycwl.basic.mapper.pc;
|
||||
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ScenicAccountMapper {
|
||||
ScenicAccountEntity getByAccount(String account);
|
||||
int add(ScenicAccountEntity scenicAccount);
|
||||
ScenicAccountEntity getSuperAccountOfScenic(Long scenicId);
|
||||
int update(ScenicAccountEntity scenicAccount);
|
||||
int deleteById(Long id);
|
||||
int updateStatus(Long id);
|
||||
int deleteByScenicId(Long scenicId);
|
||||
}
|
@ -20,6 +20,7 @@ public class BrokerEntity {
|
||||
* 推客名称
|
||||
*/
|
||||
private String name;
|
||||
private String phone;
|
||||
/**
|
||||
* 专属优惠码,新建时生成
|
||||
*/
|
||||
@ -30,4 +31,8 @@ public class BrokerEntity {
|
||||
private Integer status;
|
||||
private Date createAt;
|
||||
private Date updateAt;
|
||||
private Integer brokerOrderCount;
|
||||
private Integer brokerOrderAmount;
|
||||
private Date firstBrokerDate;
|
||||
private Date lastBrokerDate;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public class BrokerReqQuery extends BaseQueryParameterReq {
|
||||
private Long id;
|
||||
@ApiModelProperty("推客名称")
|
||||
private String name;
|
||||
@ApiModelProperty("手机号")
|
||||
private String phone;
|
||||
@ApiModelProperty("专属优惠码")
|
||||
private String promoCode;
|
||||
@ApiModelProperty("状态,0禁用,1启用")
|
||||
|
@ -16,6 +16,10 @@ import java.util.Date;
|
||||
public class FaceEntity {
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 人脸得分
|
||||
*/
|
||||
private float score;
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
|
@ -15,10 +15,19 @@ import java.util.Date;
|
||||
public class FaceSampleEntity {
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long scenicId;
|
||||
/**
|
||||
* 来源设备
|
||||
*/
|
||||
private Long deviceId;
|
||||
/**
|
||||
* 样本ID
|
||||
*/
|
||||
private Long sourceId;
|
||||
private float score;
|
||||
/**
|
||||
* 人脸照片
|
||||
*/
|
||||
|
@ -16,6 +16,11 @@ import java.util.Date;
|
||||
@Data
|
||||
@ApiModel("人脸样本查询参数")
|
||||
public class FaceSampleReqQuery extends BaseQueryParameterReq {
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
@ApiModelProperty("景区ID")
|
||||
private Long scenicId;
|
||||
/**
|
||||
* 来源设备
|
||||
*/
|
||||
|
@ -16,6 +16,11 @@ import java.util.Date;
|
||||
@ApiModel("人脸样本响应参数")
|
||||
public class FaceSampleRespVO {
|
||||
private Long id;
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
@ApiModelProperty("景区ID")
|
||||
private Long scenicId;
|
||||
/**
|
||||
* 来源设备
|
||||
*/
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.ycwl.basic.model.pc.scenic.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("scenic_account")
|
||||
public class ScenicAccountEntity {
|
||||
private Long id;
|
||||
private Long scenicId;
|
||||
private Integer isSuper;
|
||||
private String name;
|
||||
private String account;
|
||||
private String password;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
@ -22,6 +22,11 @@ public class ScenicAddOrUpdateReq {
|
||||
*/
|
||||
@ApiModelProperty("景区名称")
|
||||
private String name;
|
||||
/**
|
||||
* 景区电话
|
||||
*/
|
||||
@ApiModelProperty("联系电话")
|
||||
private String phone;
|
||||
/**
|
||||
* 景区介绍
|
||||
*/
|
||||
@ -75,4 +80,9 @@ public class ScenicAddOrUpdateReq {
|
||||
private ScenicConfigEntity scenicConfig;
|
||||
@ApiModelProperty("景区源素材价格,元")
|
||||
private BigDecimal price;
|
||||
|
||||
@ApiModelProperty("账号")
|
||||
private String account;
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
}
|
||||
|
@ -23,6 +23,16 @@ public class ScenicRespVO {
|
||||
*/
|
||||
@ApiModelProperty("景区名称")
|
||||
private String name;
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
@ApiModelProperty("账号")
|
||||
private String account;
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@ApiModelProperty("联系电话")
|
||||
private String phone;
|
||||
/**
|
||||
* 景区介绍
|
||||
*/
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.ycwl.basic.model.task.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AddFaceRespVo {
|
||||
private float score;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.ycwl.basic.model.task.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SearchFaceRespVo {
|
||||
private float score;
|
||||
private List<Long> sampleListIds;
|
||||
}
|
@ -8,6 +8,7 @@ import com.ycwl.basic.model.pc.renderWorker.req.RenderWorkerReqQuery;
|
||||
import com.ycwl.basic.service.pc.RenderWorkerService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -44,6 +45,10 @@ public class RenderWorkerServiceImpl implements RenderWorkerService {
|
||||
@Override
|
||||
public ApiResponse<Integer> add(RenderWorkerEntity renderWorker) {
|
||||
renderWorker.setId(SnowFlakeUtil.getLongId());
|
||||
if (StringUtils.isEmpty(renderWorker.getAccessKey())) {
|
||||
renderWorker.setAccessKey(SnowFlakeUtil.getId());
|
||||
}
|
||||
renderWorker.setStatus(0);
|
||||
int add = renderWorkerMapper.add(renderWorker);
|
||||
if (add == 0) {
|
||||
return ApiResponse.fail("渲染机添加失败");
|
||||
|
@ -2,7 +2,9 @@ package com.ycwl.basic.service.impl.pc;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.pc.ScenicAccountMapper;
|
||||
import com.ycwl.basic.mapper.pc.ScenicMapper;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicAddOrUpdateReq;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
@ -10,6 +12,7 @@ import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -24,6 +27,8 @@ import java.util.List;
|
||||
public class ScenicServiceImpl implements ScenicService {
|
||||
@Autowired
|
||||
private ScenicMapper scenicMapper;
|
||||
@Autowired
|
||||
private ScenicAccountMapper scenicAccountMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<ScenicRespVO>> pageQuery(ScenicReqQuery scenicReqQuery) {
|
||||
@ -46,9 +51,21 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse<Boolean> add(ScenicAddOrUpdateReq scenicAddReq) {
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicAddReq.getAccount());
|
||||
if (scenicAccount != null) {
|
||||
return ApiResponse.fail("账号已存在");
|
||||
}
|
||||
Long scenicId = SnowFlakeUtil.getLongId();
|
||||
scenicAddReq.setId(scenicId);
|
||||
int add = scenicMapper.add(scenicAddReq);
|
||||
ScenicAccountEntity account = new ScenicAccountEntity();
|
||||
account.setId(SnowFlakeUtil.getLongId());
|
||||
account.setScenicId(scenicId);
|
||||
account.setName(scenicAddReq.getName() + "管理员");
|
||||
account.setAccount(scenicAddReq.getAccount());
|
||||
account.setPassword(scenicAddReq.getPassword());
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
if (add > 0) {
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
@ -62,6 +79,7 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
int i = scenicMapper.deleteById(id);
|
||||
if (i > 0) {
|
||||
scenicMapper.deleteConfigByscenicId(id);
|
||||
scenicAccountMapper.deleteByScenicId(id);
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区删除失败");
|
||||
@ -70,6 +88,29 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> update(ScenicAddOrUpdateReq scenicUpdateReq) {
|
||||
if (StringUtils.isNotBlank(scenicUpdateReq.getAccount()) && StringUtils.isNotBlank(scenicUpdateReq.getPassword())) {
|
||||
ScenicAccountEntity scenicAccount = scenicAccountMapper.getByAccount(scenicUpdateReq.getAccount());
|
||||
if (scenicAccount != null) {
|
||||
if (!scenicAccount.getScenicId().equals(scenicUpdateReq.getId())) {
|
||||
return ApiResponse.fail("账号已存在");
|
||||
}
|
||||
}
|
||||
ScenicAccountEntity account = scenicAccountMapper.getSuperAccountOfScenic(scenicUpdateReq.getId());
|
||||
if (account != null) {
|
||||
account.setAccount(scenicUpdateReq.getAccount());
|
||||
account.setPassword(scenicUpdateReq.getPassword());
|
||||
scenicAccountMapper.update(account);
|
||||
} else {
|
||||
account = new ScenicAccountEntity();
|
||||
account.setId(SnowFlakeUtil.getLongId());
|
||||
account.setScenicId(scenicUpdateReq.getId());
|
||||
account.setName(scenicUpdateReq.getName() + "管理员");
|
||||
account.setAccount(scenicUpdateReq.getAccount());
|
||||
account.setPassword(scenicUpdateReq.getPassword());
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
}
|
||||
}
|
||||
int i = scenicMapper.update(scenicUpdateReq);
|
||||
if (i > 0) {
|
||||
return ApiResponse.success(true);
|
||||
|
@ -0,0 +1,152 @@
|
||||
package com.ycwl.basic.service.impl.task;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.facebody.model.v20191230.AddFaceEntityRequest;
|
||||
import com.aliyuncs.facebody.model.v20191230.AddFaceRequest;
|
||||
import com.aliyuncs.facebody.model.v20191230.AddFaceResponse;
|
||||
import com.aliyuncs.facebody.model.v20191230.DeleteFaceEntityRequest;
|
||||
import com.aliyuncs.facebody.model.v20191230.SearchFaceRequest;
|
||||
import com.aliyuncs.facebody.model.v20191230.SearchFaceResponse;
|
||||
import com.ycwl.basic.config.FaceDetectConfig;
|
||||
import com.ycwl.basic.mapper.pc.DeviceMapper;
|
||||
import com.ycwl.basic.mapper.pc.FaceMapper;
|
||||
import com.ycwl.basic.mapper.pc.FaceSampleMapper;
|
||||
import com.ycwl.basic.mapper.pc.ScenicMapper;
|
||||
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
|
||||
import com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity;
|
||||
import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery;
|
||||
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
|
||||
import com.ycwl.basic.model.task.resp.AddFaceRespVo;
|
||||
import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
|
||||
import com.ycwl.basic.service.task.TaskFaceService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
@Autowired
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private ScenicMapper scenicMapper;
|
||||
private static final String DATE_FORMAT="yyyyMMddHHmmssSSS";
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
@Autowired
|
||||
private FaceDetectConfig faceDetectConfig;
|
||||
|
||||
private IAcsClient getClient() {
|
||||
DefaultProfile profile = DefaultProfile.getProfile(
|
||||
faceDetectConfig.getRegion(),faceDetectConfig.getAccessKeyId(), faceDetectConfig.getAccessKeySecret());
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
return client;
|
||||
}
|
||||
@Override
|
||||
public SearchFaceRespVo searchFace(Long scenicId, Long faceId) {
|
||||
FaceRespVO faceRespVO = faceMapper.getById(faceId);
|
||||
IAcsClient client = getClient();
|
||||
SearchFaceRequest request = new SearchFaceRequest();
|
||||
request.setDbName(scenicId.toString());
|
||||
request.setImageUrl(faceRespVO.getFaceUrl());
|
||||
request.setLimit(100);
|
||||
request.setQualityScoreThreshold(80F);
|
||||
try {
|
||||
SearchFaceResponse response = client.getAcsResponse(request);
|
||||
List<SearchFaceResponse.Data.MatchListItem> matchList = response.getData().getMatchList();
|
||||
if (matchList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
SearchFaceRespVo respVo = new SearchFaceRespVo();
|
||||
FaceEntity faceEntity = new FaceEntity();
|
||||
faceEntity.setId(faceId);
|
||||
faceEntity.setMatchResult(JSON.toJSONString(matchList));
|
||||
faceEntity.setScore(matchList.get(0).getQualitieScore());
|
||||
List<SearchFaceResponse.Data.MatchListItem.FaceItemsItem> faceItems = matchList.get(0).getFaceItems().stream()
|
||||
.filter(faceItemsItem -> faceItemsItem.getConfidence() > 50).collect(Collectors.toList());
|
||||
List<Long> faceSampleIds = faceItems.stream()
|
||||
.map(SearchFaceResponse.Data.MatchListItem.FaceItemsItem::getExtraData)
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
faceEntity.setMatchSampleIds(StringUtils.joinWith(",", faceSampleIds));
|
||||
faceMapper.update(faceEntity);
|
||||
respVo.setSampleListIds(faceSampleIds);
|
||||
respVo.setScore(matchList.get(0).getQualitieScore());
|
||||
return respVo;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddFaceRespVo addFaceSample(Long faceSampleId) {
|
||||
FaceSampleRespVO faceSampleRespVO = faceSampleMapper.getById(faceSampleId);
|
||||
AddFaceEntityRequest request = new AddFaceEntityRequest();
|
||||
request.setDbName(faceSampleRespVO.getScenicId().toString());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
||||
String entityId = faceSampleRespVO.getDeviceId().toString() + "_" + sdf.format(faceSampleRespVO.getCreateAt());
|
||||
request.setEntityId(entityId);
|
||||
IAcsClient client = getClient();
|
||||
try {
|
||||
client.getAcsResponse(request);
|
||||
} catch (ClientException e) {
|
||||
return null;
|
||||
}
|
||||
AddFaceRequest addFaceRequest = new AddFaceRequest();
|
||||
addFaceRequest.setDbName(faceSampleRespVO.getScenicId().toString());
|
||||
addFaceRequest.setEntityId(entityId);
|
||||
addFaceRequest.setImageUrl(faceSampleRespVO.getFaceUrl());
|
||||
addFaceRequest.setExtraData(faceSampleId.toString());
|
||||
AddFaceRespVo respVo = new AddFaceRespVo();
|
||||
try {
|
||||
AddFaceResponse acsResponse = client.getAcsResponse(addFaceRequest);
|
||||
FaceSampleEntity faceSampleEntity = new FaceSampleEntity();
|
||||
faceSampleEntity.setId(faceSampleId);
|
||||
faceSampleEntity.setScore(acsResponse.getData().getQualitieScore());
|
||||
faceSampleEntity.setUpdateAt(new Date());
|
||||
faceSampleMapper.update(faceSampleEntity);
|
||||
respVo.setScore(acsResponse.getData().getQualitieScore());
|
||||
} catch (ClientException e) {
|
||||
return null;
|
||||
}
|
||||
return respVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDeleteFace(Long scenicId) {
|
||||
FaceSampleReqQuery query = new FaceSampleReqQuery();
|
||||
query.setDeviceId(scenicId);
|
||||
faceSampleMapper.list(query);
|
||||
Date thatDay = DateUtil.offsetDay(new Date(), -3);
|
||||
Date dayStart = DateUtil.beginOfDay(thatDay);
|
||||
Date dayEnd = DateUtil.endOfDay(thatDay);
|
||||
query.setStartTime(dayStart);
|
||||
query.setEndTime(dayEnd);
|
||||
IAcsClient client = getClient();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
||||
faceSampleMapper.list(query).forEach(faceSampleEntity -> {
|
||||
String entityId = faceSampleEntity.getDeviceId().toString() + "_" + sdf.format(faceSampleEntity.getCreateAt());
|
||||
DeleteFaceEntityRequest request = new DeleteFaceEntityRequest();
|
||||
request.setDbName(scenicId.toString());
|
||||
request.setEntityId(entityId);
|
||||
try {
|
||||
client.getAcsResponse(request);
|
||||
} catch (ClientException e) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.ycwl.basic.service.task;
|
||||
|
||||
import com.ycwl.basic.model.task.resp.AddFaceRespVo;
|
||||
import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
|
||||
|
||||
public interface TaskFaceService {
|
||||
|
||||
SearchFaceRespVo searchFace(Long scenicId, Long faceId);
|
||||
|
||||
AddFaceRespVo addFaceSample(Long faceSampleId);
|
||||
|
||||
void batchDeleteFace(Long scenicId);
|
||||
}
|
Reference in New Issue
Block a user