Commit b46f2106 authored by tangwei's avatar tangwei

增加人员es

parent e05d2721
package com.yeejoin.amos.boot.module.common.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
@Data
@Document(indexName = "user", shards = 1, replicas = 0)
public class ESOrgUser {
@Id
@ApiModelProperty(value = "人员id")
@Field(type = FieldType.Long)
private Long sequenceNbr;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "人员code")
private String bizOrgCode;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "人员名称")
private String bizOrgName;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "人员对应平台id")
private String amosOrgId;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "父id")
private String parentId;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "人员黄绿码")
private String personStatus;
@Field(type = FieldType.Date)
@ApiModelProperty(value = "更新时间")
private String recDate;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "人员父节点名称")
private String companyName;
@Field(type = FieldType.Integer)
@ApiModelProperty(value = "人员巡检任务统计/动态数据")
private String patrol;
@Field(type = FieldType.Integer)
@ApiModelProperty(value = "人员非巡检任务统计/动态数据")
private String other;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "员工编号")
private String personNumber;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "证件类型")
private String certificatesTypeCode;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "性别")
private String gender;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "证件号码")
private String certificatesNumber;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "联系电话")
private String telephone;
// @Field(type = FieldType.Keyword)
// @ApiModelProperty(value = "人员状态")
// private String state;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "是否进行安全培训")
private String safetyTraining;
// @Field(type = FieldType.Text)
// @ApiModelProperty(value = "行政职务")
// private String administrativePositionCode;
// @Field(type = FieldType.Text)
// @ApiModelProperty(value = "消防管理组织机构内部职务")
// private String internalPositionCode;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "消防管理岗位code")
private String fireManagementPostCode;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "消防管理岗位")
private String fireManagementPostName;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "岗位类型code")
private String positionType;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "岗位类型")
private String positionTypeName;
// @Field(type = FieldType.Text)
// @ApiModelProperty(value = "持证类别")
// private String certificateType;
// @Field(type = FieldType.Date)
// @ApiModelProperty(value = "持证时间")
// private String holdingTime;
// @Field(type = FieldType.Keyword)
// @ApiModelProperty(value = "审核周期")
// private String auditCycle;
@Field(type = FieldType.Keyword)
@ApiModelProperty(value = "人员照片")
private String personImg;
// @Field(type = FieldType.Keyword)
// @ApiModelProperty(value = "重点工种资质证书")
// private String certificateImg;
@Field(type = FieldType.Text)
@ApiModelProperty(value = "人员类型")
private String peopleType;
// @Field(type = FieldType.Text)
// @ApiModelProperty(value = "人员状态名称")
// private String stateName;
// @Field(type = FieldType.Text)
// @ApiModelProperty(value = "人员对应平台code")
// private String amosOrgCode;
@ApiModelProperty(value = "对象id")
@Field(type = FieldType.Long)
private String instance_id;
}
package com.yeejoin.amos.boot.module.common.api.dto;
import lombok.Data;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
@Data
public class EsUserData {
private String bizOrgName;
private String positionType;
private String amosOrgId;
private String OrgCode;
private int pageNum;
private int pageSize;
}
......@@ -18,7 +18,7 @@ import java.util.Map;
*/
public interface OrgUsrMapper extends BaseMapper<OrgUsr> {
String selectUpUnitByParam(@Param("id")String biz_org_code);
int selectPersonListCount(@Param("map")Map<String, Object> map);
List<Map<String, Object>> selectPersonList(@Param("map")Map<String, Object> map);
......@@ -103,7 +103,7 @@ public interface OrgUsrMapper extends BaseMapper<OrgUsr> {
void updatelistByParentId(String codex, String code);
List< Map<String,String>> getPersonSimpleDetail();
List<Map<String, Long>> countDeptByCompanyId(@Param("companyIdList") List<String> companyIdList);
......@@ -169,4 +169,7 @@ public interface OrgUsrMapper extends BaseMapper<OrgUsr> {
int getManagePersonCount(@Param("map") Map<String, Object> map);
List<Map<String, Object>> getManagePersonPage(@Param("map") Map<String, Object> map);
//查询用户,构建es数据
List<ESOrgUser> selectESOrgUsrList(@Param("sequenceNbr") Long sequenceNbr);
}
package com.yeejoin.amos.boot.module.common.api.service;
import com.yeejoin.amos.boot.module.common.api.dto.ESOrgUser;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
public interface IESOrgUserService {
//全量录入数据
public void init() ;
//新增/修改数据
public void saveAll(List<ESOrgUser> orgUsrs);
//删除
public Boolean deleteByIds(List<Long> sequenceNbr);
}
......@@ -1666,4 +1666,78 @@
ORDER BY a.personStatus DESC
LIMIT #{map.pageNum}, #{map.pageSize}
</select>
<select id="selectESOrgUsrList" resultType="com.yeejoin.amos.boot.module.common.api.dto.ESOrgUser">
select * from (
SELECT
DISTINCT
u.sequence_nbr sequenceNbr,
u.biz_org_name bizOrgName,
u.amos_org_id amosOrgId,
u.biz_org_code bizOrgCode,
u.parent_id parentId,
u.person_status personStatus,
u.rec_date recDate,
(select biz_org_name from cb_org_usr where sequence_nbr = u.parent_id) as companyName,
(SELECT IFNULL(SUM(IF(aqr.SOURCE = 'patrol', 1, 0)), 0) FROM dl_amos_idx_biz.idx_access_qrcode_record aqr WHERE
aqr.buss_id = u.sequence_nbr ) as 'patrol',
(SELECT IFNULL(SUM(IF(aqr.SOURCE != 'patrol', 1, 0)), 0) FROM dl_amos_idx_biz.idx_access_qrcode_record aqr WHERE
aqr.buss_id = u.sequence_nbr ) as 'other',
g.*
FROM
cb_org_usr u
LEFT JOIN
( SELECT
v.`instance_id`,
max(case v.field_code when 'personNumber' then IFNULL(v.field_value_label,v.field_value) end) personNumber,
max(case v.field_code when 'certificatesTypeCode' then IFNULL(v.field_value_label,v.field_value) end)
certificatesTypeCode,
max(case v.field_code when 'gender' then IFNULL(v.field_value_label,v.field_value) end) gender,
max(case v.field_code when 'certificatesNumber' then IFNULL(v.field_value_label,v.field_value) end)
certificatesNumber,
max(case v.field_code when 'telephone' then IFNULL(v.field_value_label,v.field_value) end) telephone,
-- max(case v.field_code when 'stateCode' then IFNULL(v.field_value_label,v.field_value) end) state,
max(case v.field_code when 'safetyTraining' then IFNULL(v.field_value_label,v.field_value) end) safetyTraining,
-- max(case v.field_code when 'administrativePositionCode' then IFNULL(v.field_value_label,v.field_value) end)
-- administrativePositionCode,
-- max(case v.field_code when 'internalPositionCode' then IFNULL(v.field_value_label,v.field_value) end)
-- internalPositionCode,
max(case v.field_code when 'fireManagementPostCode' then IFNULL(v.field_value_label,v.field_value) end)
fireManagementPostCode,
max(case v.field_code when 'fireManagementPostCode' then v.field_value end) fireManagementPost,
max(case v.field_code when 'fireManagementPostCode' then IFNULL(v.field_value_label,'其他') end)
fireManagementPostName,
max(case v.field_code when 'positionType' then IFNULL(v.field_value,v.field_value_label) end) positionType,
max(case v.field_code when 'positionType' then IFNULL(v.field_value_label,'其他') end) positionTypeName,
-- max(case v.field_code when 'certificateType' then IFNULL(v.field_value_label,v.field_value) end)
-- certificateType,
-- max(case v.field_code when 'holdingTime' then IFNULL(v.field_value_label,v.field_value) end) holdingTime,
-- max(case v.field_code when 'auditCycle' then IFNULL(v.field_value_label,v.field_value) end) auditCycle,
max(case v.field_code when 'personImg' then IFNULL(v.field_value_label,v.field_value) end) personImg,
-- max(case v.field_code when 'certificateImg' then IFNULL(v.field_value_label,v.field_value) end) certificateImg,
max(case v.field_code when 'peopleType' then v.field_value end) peopleType
FROM
`cb_dynamic_form_instance` v
WHERE
v.group_code = 246
GROUP BY
v.`instance_id`
) g
on u.sequence_nbr = g.instance_id
where
u.biz_org_type = 'person'
AND
u.is_delete = 0
) a where a.sequenceNbr is not null
<if test="sequenceNbr != null and sequenceNbr != ''">
AND a.sequenceNbr = #{sequenceNbr}
</if>
</select>
</mapper>
package com.yeejoin.amos.boot.module.common.biz.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.common.api.dto.ESOrgUser;
import com.yeejoin.amos.boot.module.common.api.dto.EsUserData;
import com.yeejoin.amos.boot.module.common.api.dto.FailureDetailsDto;
import com.yeejoin.amos.boot.module.common.biz.service.impl.ESOrgUserServicempl;
import com.yeejoin.amos.boot.module.common.biz.service.impl.OrgUsrServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
@RestController
@Api(tags = "es人员")
@RequestMapping(value = "/es/esOrgUser")
public class ESOrgUserController extends BaseController {
@Autowired
ESOrgUserServicempl esOrgUserServicempl;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/save")
@ApiOperation(httpMethod = "POST", value = "新增/修改", notes = "新增/修改")
public ResponseModel<List<ESOrgUser>> saveEsOrgUser(@RequestBody List<ESOrgUser> model) throws Exception {
esOrgUserServicempl.saveAll(model);
return ResponseHelper.buildResponse(model);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/delete")
@ApiOperation(httpMethod = "POST", value = "删除", notes = "删除")
public ResponseModel<Object> deleteEsOrgUser(@RequestBody List<Long> ids) throws Exception {
esOrgUserServicempl.deleteByIds(ids);
return ResponseHelper.buildResponse("成功");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping (value = "/init")
@ApiOperation(httpMethod = "GET", value = "初始化", notes = "初始化")
public ResponseModel<Object> initEsOrgUser() throws Exception {
esOrgUserServicempl.init();
return ResponseHelper.buildResponse("成功");
}
@TycloudOperation( ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "列表分页查询", notes = "列表分页查询")
public ResponseModel<Page<ESOrgUser>> listPage(@RequestParam EsUserData requestBody) {
Page<ESOrgUser> pa= esOrgUserServicempl.listPage(requestBody,requestBody.getPageNum(),requestBody.getPageSize());
return ResponseHelper.buildResponse(pa);
}
}
package com.yeejoin.amos.boot.module.common.biz.dao;
import com.yeejoin.amos.boot.module.common.api.dto.ESOrgUser;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
@Repository
public interface ESOrgUserRepository extends ElasticsearchRepository<ESOrgUser, Long> {
}
package com.yeejoin.amos.boot.module.common.biz.service.impl;
import com.yeejoin.amos.boot.module.common.api.dto.ESOrgUser;
import com.yeejoin.amos.boot.module.common.api.dto.EsUserData;
import com.yeejoin.amos.boot.module.common.api.mapper.OrgUsrMapper;
import com.yeejoin.amos.boot.module.common.api.service.IESOrgUserService;
import com.yeejoin.amos.boot.module.common.biz.dao.ESOrgUserRepository;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.*;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2024/8/14
*/
@Service
public class ESOrgUserServicempl implements IESOrgUserService {
@Autowired
OrgUsrMapper orgUsrMapper;
@Autowired
private ESOrgUserRepository esOrgUsrRepository;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Override
public void init() {
//清除索引
esOrgUsrRepository.deleteAll();
//获取全部数据
List<ESOrgUser> orgUsrs=new ArrayList<>();
//查询用户,构建es数据
orgUsrs= orgUsrMapper.selectESOrgUsrList(null);
//保存所有数据
if(!orgUsrs.isEmpty()){
esOrgUsrRepository.saveAll(orgUsrs);
}
}
@Override
public void saveAll(List<ESOrgUser> orgUsrs) {
esOrgUsrRepository.saveAll(orgUsrs);
}
@Override
@Transactional
public Boolean deleteByIds(List<Long> sequenceNbrs) {
for (Long sequenceNbr : sequenceNbrs) {
if (esOrgUsrRepository.existsById(sequenceNbr)) {
esOrgUsrRepository.deleteById(sequenceNbr);
}
}
return true;
}
public Page<ESOrgUser> listPage(EsUserData keyword, int current, int size) {
//构建返回对象
Page<ESOrgUser> result = new Page<ESOrgUser>(current, size);
//组装查询条件 must类似and匹配到所有字段后进行组合查询
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if(StringUtils.isNotBlank(keyword.getBizOrgName())){
queryBuilder.must(QueryBuilders.matchQuery("bizOrgName", keyword.getBizOrgName()));
}
if(StringUtils.isNotBlank(keyword.getAmosOrgId())){
queryBuilder.must(QueryBuilders.matchQuery("amosOrgId", keyword.getAmosOrgId()));
}
if(StringUtils.isNotBlank(keyword.getPositionType())){
queryBuilder.must(QueryBuilders.termQuery("positionType",keyword.getPositionType()));
}
queryBuilder.must(QueryBuilders.wildcardQuery("bizOrgCode", keyword.getOrgCode()));
NativeSearchQuery build = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.withPageable(PageRequest.of(current, size))
.withSort(SortBuilders.fieldSort("companyName").order(SortOrder.ASC))
.withSort(SortBuilders.fieldSort("personStatus").order(SortOrder.DESC))
.withSort(SortBuilders.fieldSort("recDate").order(SortOrder.DESC))
.build();
SearchHits<ESOrgUser> search = elasticsearchTemplate.search(build, ESOrgUser.class);
SearchPage<ESOrgUser> page = SearchHitSupport.searchPageFor(search, build.getPageable());
List<ESOrgUser> list = new LinkedList<>();
long totle = 0;
for (SearchHit<ESOrgUser> each : page) {
ESOrgUser vo = each.getContent();
list.add(vo);
}
totle =search.getTotalHits();
//组装分页对象
result.setRecords(list);
result.setTotal(totle);
return result;
}
}
......@@ -62,7 +62,7 @@ public class ESAlertCalledService {
private Long time;
private static final String CALLTIMELONG="callTimeLong";
@PostConstruct
public void init() throws Exception
{
......@@ -281,7 +281,7 @@ public class ESAlertCalledService {
}
}
boolMustAll.must(qb0);
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
//接警时间,距离当前时间不超过半小时的
long currentTime = System.currentTimeMillis() ;
......@@ -370,7 +370,7 @@ public class ESAlertCalledService {
try
{
SearchHits<ESAlertCalled> searchHits =elasticsearchTemplate.search(queryBuilder.build(), ESAlertCalled.class);
for (SearchHit searchHit : searchHits.getSearchHits())
{
JSONObject jsonObject = (JSONObject) JSON.toJSON(searchHit.getContent());
......@@ -390,7 +390,7 @@ public class ESAlertCalledService {
}
@SuppressWarnings({ "rawtypes" })
public Page<ESAlertCalledDto> queryByKeys(ESAlertCalledRequestDto alertCalledVo, int current, int size,String type)
{
{
Page<ESAlertCalledDto> result = new Page<ESAlertCalledDto>(current, size);
String[] alertStatus = alertCalledVo.getAlertStatus();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment