Commit 80a7ff94 authored by KeYong's avatar KeYong

Merge branch 'develop_dl_plan6' of http://39.98.45.134:8090/moa/amos-boot-biz into develop_dl_plan6

parents ce66bcf8 90101303
...@@ -191,8 +191,10 @@ public class ConfigureController extends AbstractBaseController { ...@@ -191,8 +191,10 @@ public class ConfigureController extends AbstractBaseController {
records.forEach(item -> { records.forEach(item -> {
String prefix = null; String prefix = null;
String suffix = null; String suffix = null;
String iotCode = item.get("iot_code").toString(); String iotCode = null;
if (iotCode.length() > 8) { if (!ObjectUtils.isEmpty(item.get("iot_code"))) {
iotCode = item.get("iot_code").toString();
if (iotCode.length() > 8) {
prefix = iotCode.substring(0, 8); prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8); suffix = iotCode.substring(8);
} else { } else {
...@@ -223,7 +225,13 @@ public class ConfigureController extends AbstractBaseController { ...@@ -223,7 +225,13 @@ public class ConfigureController extends AbstractBaseController {
e.printStackTrace(); e.printStackTrace();
} }
} }
}else {
item.put("carState", "无");
item.put("count", 0);
item.put("carStateDate", "--");
}
}); });
} }
return CommonResponseUtil.success(fireCarInfoByWL); return CommonResponseUtil.success(fireCarInfoByWL);
} }
......
...@@ -438,10 +438,11 @@ public class FireFightingSystemController extends AbstractBaseController { ...@@ -438,10 +438,11 @@ public class FireFightingSystemController extends AbstractBaseController {
QueryWrapper<EquipmentCategory> equipmentCategoryQueryWrapper = new QueryWrapper<>(); QueryWrapper<EquipmentCategory> equipmentCategoryQueryWrapper = new QueryWrapper<>();
equipmentCategoryQueryWrapper.eq("code", equipTypeAmountPage.getEquipmentClassificationCode()); equipmentCategoryQueryWrapper.eq("code", equipTypeAmountPage.getEquipmentClassificationCode());
equipmentCategoryQueryWrapper.eq("industry_code", equipTypeAmountPage.getIndustryCode()); equipmentCategoryQueryWrapper.eq("industry_code", equipTypeAmountPage.getIndustryCode());
EquipmentCategory equipmentCategory = equipmentCategoryService.getOne(equipmentCategoryQueryWrapper); List<EquipmentCategory> equipmentCategoryList = equipmentCategoryService.list(equipmentCategoryQueryWrapper);
if (equipmentCategory == null) { if (CollectionUtils.isEmpty(equipmentCategoryList)) {
throw new RuntimeException("装备定义code有误"); throw new RuntimeException("装备定义code有误");
} }
EquipmentCategory equipmentCategory = equipmentCategoryList.get(0);
int inhierarchy = 1; int inhierarchy = 1;
for (int i = 0; i < result.length + 1; i++) { for (int i = 0; i < result.length + 1; i++) {
//进来先判断是否默认就是空,如果为空第一层 //进来先判断是否默认就是空,如果为空第一层
......
...@@ -81,7 +81,7 @@ dcs.url.sendalarm=http://198.87.103.158:8001/alarm-service/appalarm/sendalarm ...@@ -81,7 +81,7 @@ dcs.url.sendalarm=http://198.87.103.158:8001/alarm-service/appalarm/sendalarm
param.system.online.date = 2019-02-12 param.system.online.date = 2019-02-12
# 视频转码服务开关 hls(关)/flv(开),默认关闭,数字换流站使用时开启 # 视频转码服务开关 hls(关)/flv(开),默认关闭,数字换流站使用时开启
window.vedioFormat = hls window.vedioFormat = flv
window.vedioFormat.video = flv window.vedioFormat.video = flv
# 航天视频服务地址 # 航天视频服务地址
param.htvideo.url=http://192.168.4.174:9001; param.htvideo.url=http://192.168.4.174:9001;
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto; import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import java.util.List; import java.util.List;
...@@ -29,4 +30,7 @@ public interface CheckResultMapper extends BaseMapper<CheckResult> { ...@@ -29,4 +30,7 @@ public interface CheckResultMapper extends BaseMapper<CheckResult> {
List<CheckResultDto> getOne(String amosOrgCode); List<CheckResultDto> getOne(String amosOrgCode);
List<CheckResult> getCheckItemNo(@Param("modelName") String modelName);
Map<String, Object> selectCheckItemTotal(@Param("modelName") String modelName);
} }
...@@ -2,11 +2,15 @@ package com.yeejoin.amos.boot.module.tdc.api.mapper; ...@@ -2,11 +2,15 @@ package com.yeejoin.amos.boot.module.tdc.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.tdc.api.entity.ModelItem; import com.yeejoin.amos.boot.module.tdc.api.entity.ModelItem;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import java.util.List;
/** /**
* @author DELL * @author DELL
*/ */
@Mapper @Mapper
public interface ModelItemMapper extends BaseMapper<ModelItem> { public interface ModelItemMapper extends BaseMapper<ModelItem> {
List<ModelItem> getListByName(@Param("modelName") String modelName, @Param("orgCode") String orgCode);
} }
package com.yeejoin.amos.boot.module.tdc.api.mapper; package com.yeejoin.amos.boot.module.tdc.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord; import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
...@@ -9,4 +11,6 @@ import org.mapstruct.Mapper; ...@@ -9,4 +11,6 @@ import org.mapstruct.Mapper;
*/ */
@Mapper @Mapper
public interface SubmitRecordMapper extends BaseMapper<SubmitRecord> { public interface SubmitRecordMapper extends BaseMapper<SubmitRecord> {
IPage<SubmitRecord> selectByOrgCode(Page page);
} }
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.tdc.api.service; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.tdc.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
...@@ -16,4 +17,5 @@ public interface CheckReportService extends IService<CheckReport> { ...@@ -16,4 +17,5 @@ public interface CheckReportService extends IService<CheckReport> {
Map getInfo(int pageNumber,int pageSize); Map getInfo(int pageNumber,int pageSize);
void createReport(String batchNo, AgencyUserModel userInfo);
} }
...@@ -6,6 +6,7 @@ import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto; ...@@ -6,6 +6,7 @@ import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto;
import com.yeejoin.amos.boot.module.tdc.api.dto.DimensionTableDto; import com.yeejoin.amos.boot.module.tdc.api.dto.DimensionTableDto;
import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto; import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
...@@ -58,4 +59,9 @@ public interface CheckResultService extends IService<CheckResult> { ...@@ -58,4 +59,9 @@ public interface CheckResultService extends IService<CheckResult> {
List<DimensionTableDto> getDimensionTable(String id); List<DimensionTableDto> getDimensionTable(String id);
List<ModelTreeDto> getModelTreeData(String modelName, AgencyUserModel userInfo);
List<CheckResult> getCheckItem(String modelName, AgencyUserModel userInfo);
Map<String, Object> selectCheckItemTotal(String modelName, AgencyUserModel userInfo);
} }
package com.yeejoin.amos.boot.module.tdc.api.service; package com.yeejoin.amos.boot.module.tdc.api.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.tdc.api.entity.ModelItem;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
......
package com.yeejoin.amos.boot.module.tdc.api.service; package com.yeejoin.amos.boot.module.tdc.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.module.tdc.api.dto.CheckModelDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord;
import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord; import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -8,6 +11,7 @@ import org.springframework.stereotype.Service; ...@@ -8,6 +11,7 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public interface SubmitRecordService { public interface SubmitRecordService {
IPage<SubmitRecord> selectByOrgCode(int current, int size);
int saveSubmitRecord(SubmitRecord submitRecord); int saveSubmitRecord(SubmitRecord submitRecord);
......
...@@ -36,4 +36,47 @@ ...@@ -36,4 +36,47 @@
select amos_org_name,amos_org_code,batch_no,model_id from tdc_check_result where amos_org_code = #{amosOrgCode} group by model_name ORDER BY check_date desc limit 0,1; select amos_org_name,amos_org_code,batch_no,model_id from tdc_check_result where amos_org_code = #{amosOrgCode} group by model_name ORDER BY check_date desc limit 0,1;
</select> </select>
<select id="getCheckItemNo" resultType="com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult">
SELECT
*
FROM
tdc_check_result
WHERE
batch_no = (
SELECT
batch_no
FROM
tdc_submit_record
ORDER BY
submit_time DESC
LIMIT 1
)
AND check_item_result = 1
<if test="modelName != null and modelName != '' and modelName != '-1'">
AND model_name = #{modelName}
</if>
</select>
<select id="selectCheckItemTotal" resultType="java.util.Map">
SELECT
count(1) AS total, COUNT(CASE WHEN (check_item_result=1) THEN check_item_result END) AS unqualified, batch_no AS batchNo
FROM
tdc_check_result
WHERE
batch_no = (
SELECT
batch_no
FROM
tdc_submit_record
-- WHERE
-- amos_org_code = '50*110'
ORDER BY
submit_time DESC
LIMIT 1
)
<if test="modelName != null and modelName != '' and modelName != '-1'">
AND model_name = #{modelName}
</if>
</select>
</mapper> </mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.tdc.api.mapper.ModelItemMapper"> <mapper namespace="com.yeejoin.amos.boot.module.tdc.api.mapper.ModelItemMapper">
<select id="getListByName" resultType="com.yeejoin.amos.boot.module.tdc.api.entity.ModelItem">
SELECT
sequence_nbr, check_item_label, check_item_value, model_name, submit_record_id
FROM
tdc_model_item
WHERE
submit_record_id = (
SELECT
sequence_nbr
FROM
tdc_submit_record
WHERE
amos_org_code = #{orgCode}
ORDER BY
submit_time DESC
LIMIT 1
)
<if test="modelName != null and modelName != '' and modelName != '-1'">
AND model_name = #{modelName}
</if>
</select>
</mapper> </mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.tdc.api.mapper.SubmitRecordMapper"> <mapper namespace="com.yeejoin.amos.boot.module.tdc.api.mapper.SubmitRecordMapper">
</mapper>
\ No newline at end of file <select id="selectByOrgCode" resultType="com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord">
SELECT sequence_nbr,submit_people,submit_time,amos_org_name FROM `tdc_submit_record`
</select>
</mapper>
...@@ -93,6 +93,7 @@ public class CheckModelAction { ...@@ -93,6 +93,7 @@ public class CheckModelAction {
checkResult.setCheckItemResult(result); checkResult.setCheckItemResult(result);
checkResult.setCheckExplain(checkExplain); checkResult.setCheckExplain(checkExplain);
checkResult.setCheckItem(checkItem); checkResult.setCheckItem(checkItem);
checkResult.setCheckItemLabel(checkItem);
checkResult.setCheckItemValue(checkItemValue); checkResult.setCheckItemValue(checkItemValue);
checkResult.setModelId(String.valueOf(checkModel.getSequenceNbr())); checkResult.setModelId(String.valueOf(checkModel.getSequenceNbr()));
checkResult.setAmosOrgCode(checkModel.getAmosOrgCode()); checkResult.setAmosOrgCode(checkModel.getAmosOrgCode());
......
package com.yeejoin.amos.boot.module.tdc.biz.controller; package com.yeejoin.amos.boot.module.tdc.biz.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService; import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService;
import com.yeejoin.amos.boot.module.tdc.biz.service.impl.CheckReportImpl; import com.yeejoin.amos.boot.module.tdc.biz.service.impl.CheckReportImpl;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
...@@ -24,7 +27,7 @@ import java.util.Map; ...@@ -24,7 +27,7 @@ import java.util.Map;
@RestController @RestController
@Api(tags = "校验报告api") @Api(tags = "校验报告api")
@RequestMapping(value = "/report") @RequestMapping(value = "/report")
public class CheckReportController { public class CheckReportController extends BaseController {
@Autowired @Autowired
CheckReportService checkReportService; CheckReportService checkReportService;
...@@ -41,7 +44,6 @@ public class CheckReportController { ...@@ -41,7 +44,6 @@ public class CheckReportController {
return ResponseHelper.buildResponse(checkReportService.selectAll(current,size,amosOrgCode)); return ResponseHelper.buildResponse(checkReportService.selectAll(current,size,amosOrgCode));
} }
/** /**
* *
* return * return
...@@ -53,4 +55,13 @@ public class CheckReportController { ...@@ -53,4 +55,13 @@ public class CheckReportController {
return ResponseHelper.buildResponse(checkReportService.getInfo(pageNumber,pageSize)); return ResponseHelper.buildResponse(checkReportService.getInfo(pageNumber,pageSize));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "createReport")
@ApiOperation(httpMethod = "GET",value = "创建报告", notes = "创建报告")
public ResponseModel createReport(String batchNo) {
AgencyUserModel userInfo = getUserInfo();
checkReportService.createReport(batchNo, userInfo);
return ResponseHelper.buildResponse(true);
}
} }
...@@ -11,10 +11,7 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; ...@@ -11,10 +11,7 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
...@@ -118,5 +115,27 @@ public class CheckResultController extends BaseController { ...@@ -118,5 +115,27 @@ public class CheckResultController extends BaseController {
return ResponseHelper.buildResponse(checkResultService.getDimensionTable(id)); return ResponseHelper.buildResponse(checkResultService.getDimensionTable(id));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/getModelTreeData")
@ApiOperation(httpMethod = "GET",value = "获取单独模型树", notes = "根据模型id获取模型树")
public ResponseModel<List<ModelTreeDto>> getModelTreeData(@RequestParam(required = false) String modelName) {
AgencyUserModel userInfo = getUserInfo();
return ResponseHelper.buildResponse(checkResultService.getModelTreeData(modelName, userInfo));
}
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/getCheckItemNo")
@ApiOperation(httpMethod = "GET",value = "获取不合格校验项", notes = "获取不合格校验项")
public ResponseModel<List<CheckResult>> getCheckItem(@RequestParam(required = false) String modelName) {
AgencyUserModel userInfo = getUserInfo();
return ResponseHelper.buildResponse(checkResultService.getCheckItem(modelName, userInfo));
}
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/selectCheckItemTotal")
@ApiOperation(httpMethod = "GET", value = "获取校验项统计", notes = "获取校验项统计")
public ResponseModel<Map<String, Object>> selectCheckItemTotal(@RequestParam(required = false) String modelName) {
AgencyUserModel userInfo = getUserInfo();
return ResponseHelper.buildResponse(checkResultService.selectCheckItemTotal(modelName, userInfo));
}
} }
package com.yeejoin.amos.boot.module.tdc.biz.controller; package com.yeejoin.amos.boot.module.tdc.biz.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord;
import com.yeejoin.amos.boot.module.tdc.api.service.SubmitRecordService; import com.yeejoin.amos.boot.module.tdc.api.service.SubmitRecordService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
...@@ -22,4 +21,13 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel; ...@@ -22,4 +21,13 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
@Api(tags = "校验项提交") @Api(tags = "校验项提交")
@RequestMapping(value = "/check-record") @RequestMapping(value = "/check-record")
public class SubmitRecordController { public class SubmitRecordController {
@Autowired
SubmitRecordService submitRecordService;
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "selectOrgCode")
@ApiOperation(httpMethod = "GET",value = "直接查询列表", notes = "直接查询列表")
public ResponseModel<IPage<SubmitRecord>> selectByOrgCode(int current,int size){
return ResponseHelper.buildResponse(submitRecordService.selectByOrgCode(current, size));
}
} }
\ No newline at end of file
...@@ -7,17 +7,24 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -7,17 +7,24 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport;
import com.yeejoin.amos.boot.module.tdc.api.enums.ReportStateEnum; import com.yeejoin.amos.boot.module.tdc.api.enums.ReportStateEnum;
import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService; import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckReportMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckReportMapper;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService; import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckResultService;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
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.util.CollectionUtils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import springfox.documentation.spring.web.json.Json; import springfox.documentation.spring.web.json.Json;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -29,6 +36,9 @@ public class CheckReportImpl extends ServiceImpl<CheckReportMapper, CheckReport> ...@@ -29,6 +36,9 @@ public class CheckReportImpl extends ServiceImpl<CheckReportMapper, CheckReport>
@Autowired @Autowired
IdxFeignService idxFeignService; IdxFeignService idxFeignService;
@Autowired
CheckResultService checkResultService;
@Override @Override
public IPage<CheckReport> selectAll(int current,int size,String amosOrgCode) { public IPage<CheckReport> selectAll(int current,int size,String amosOrgCode) {
Page<CheckReport> page = new Page<>(current,size); Page<CheckReport> page = new Page<>(current,size);
...@@ -78,4 +88,14 @@ public class CheckReportImpl extends ServiceImpl<CheckReportMapper, CheckReport> ...@@ -78,4 +88,14 @@ public class CheckReportImpl extends ServiceImpl<CheckReportMapper, CheckReport>
} }
@Override
public void createReport(String batchNo, AgencyUserModel userInfo) {
List<CompanyModel> companyList = userInfo.getCompanys();
if (!CollectionUtils.isEmpty(companyList)) {
String orgCode = companyList.get(0).getOrgCode();
String realName = userInfo.getRealName();
checkResultService.saveSql(orgCode, realName, batchNo);
}
}
} }
...@@ -15,15 +15,13 @@ import com.stoyanr.evictor.queue.NavigableMapEvictionQueue; ...@@ -15,15 +15,13 @@ import com.stoyanr.evictor.queue.NavigableMapEvictionQueue;
import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto; import com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto;
import com.yeejoin.amos.boot.module.tdc.api.dto.DimensionTableDto; import com.yeejoin.amos.boot.module.tdc.api.dto.DimensionTableDto;
import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto; import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckModel; import com.yeejoin.amos.boot.module.tdc.api.entity.*;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult;
import com.yeejoin.amos.boot.module.tdc.api.entity.PowerReportFile;
import com.yeejoin.amos.boot.module.tdc.api.enums.WordPowerTypeEum; import com.yeejoin.amos.boot.module.tdc.api.enums.WordPowerTypeEum;
import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService; import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckModelMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckModelMapper;
import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckReportMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckReportMapper;
import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckResultMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckResultMapper;
import com.yeejoin.amos.boot.module.tdc.api.mapper.ModelItemMapper;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService; import com.yeejoin.amos.boot.module.tdc.api.service.CheckReportService;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckResultService; import com.yeejoin.amos.boot.module.tdc.api.service.CheckResultService;
import com.yeejoin.amos.boot.module.tdc.api.utils.WordPowerUtils; import com.yeejoin.amos.boot.module.tdc.api.utils.WordPowerUtils;
...@@ -31,11 +29,13 @@ import com.yeejoin.amos.boot.module.tdc.api.vo.SubjectTreeVo; ...@@ -31,11 +29,13 @@ import com.yeejoin.amos.boot.module.tdc.api.vo.SubjectTreeVo;
import com.yeejoin.amos.boot.module.tdc.api.vo.TableColumnsVo; import com.yeejoin.amos.boot.module.tdc.api.vo.TableColumnsVo;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.systemctl.Systemctl; import com.yeejoin.amos.feign.systemctl.Systemctl;
import liquibase.pro.packaged.M; import liquibase.pro.packaged.M;
import org.codehaus.jettison.json.JSONString; import org.codehaus.jettison.json.JSONString;
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.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -65,6 +65,8 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> ...@@ -65,6 +65,8 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult>
@Autowired @Autowired
CheckModelMapper checkModelMapper; CheckModelMapper checkModelMapper;
@Autowired
ModelItemMapper modelItemMapper;
@Override @Override
public IPage<CheckResultDto> selectResult(int current,int size,String code) { public IPage<CheckResultDto> selectResult(int current,int size,String code) {
...@@ -345,6 +347,50 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> ...@@ -345,6 +347,50 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult>
} }
} }
@Override
public List<ModelTreeDto> getModelTreeData(String modelName, AgencyUserModel user) {
List<CompanyModel> companyList = user.getCompanys();
List<ModelTreeDto> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(companyList)) {
String companyName = companyList.get(0).getCompanyName();
String orgCode = companyList.get(0).getOrgCode();
List<ModelItem> listByName = modelItemMapper.getListByName(modelName, orgCode);
if (!CollectionUtils.isEmpty(listByName)) {
Map<String, List<ModelItem>> collect = listByName.stream().collect(Collectors.groupingBy(ModelItem::getModelName));
collect.forEach((key, value) -> {
ModelTreeDto modelTreeDto = new ModelTreeDto();
modelTreeDto.setAmosOrgName(companyName);
modelTreeDto.setName(key);
modelTreeDto.setId(key);
List<Map<String, Object>> valueList = value.stream().map(e -> {
Map<String, Object> map = new HashMap<>(3);
map.put("data", e.getCheckItemValue());
map.put("id", e.getSequenceNbr());
map.put("name", e.getCheckItemLabel());
return map;
}).collect(Collectors.toList());
modelTreeDto.setChildren(valueList);
list.add(modelTreeDto);
});
}
}
return list;
}
@Override
public List<CheckResult> getCheckItem(String modelName, AgencyUserModel userInfo) {
// List<CompanyModel> companyList = userInfo.getCompanys();
// List<CheckResult> resultList = new ArrayList<>();
// if (!CollectionUtils.isEmpty(companyList)) {
// String orgCode = companyList.get(0).getOrgCode();
// resultList = checkResultMapper.getCheckItemNo(modelName, orgCode);
// }
return checkResultMapper.getCheckItemNo(modelName);
}
@Override
public Map<String, Object> selectCheckItemTotal(String modelName, AgencyUserModel userInfo) {
return checkResultMapper.selectCheckItemTotal(modelName);
}
} }
...@@ -43,6 +43,9 @@ public class ModelItemServiceImpl extends ServiceImpl<ModelItemMapper, ModelItem ...@@ -43,6 +43,9 @@ public class ModelItemServiceImpl extends ServiceImpl<ModelItemMapper, ModelItem
@Autowired @Autowired
SubmitRecordMapper submitRecordMapper; SubmitRecordMapper submitRecordMapper;
@Autowired
ModelItemMapper modelItemMapper;
@Override @Override
public void saveModelItem(JSONObject jsonObject, AgencyUserModel userInfo) { public void saveModelItem(JSONObject jsonObject, AgencyUserModel userInfo) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
...@@ -160,5 +163,4 @@ public class ModelItemServiceImpl extends ServiceImpl<ModelItemMapper, ModelItem ...@@ -160,5 +163,4 @@ public class ModelItemServiceImpl extends ServiceImpl<ModelItemMapper, ModelItem
checkResultMapper.delete(resultWrapper); checkResultMapper.delete(resultWrapper);
} }
} }
} }
package com.yeejoin.amos.boot.module.tdc.biz.service.impl; package com.yeejoin.amos.boot.module.tdc.biz.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord; import com.yeejoin.amos.boot.module.tdc.api.entity.SubmitRecord;
import com.yeejoin.amos.boot.module.tdc.api.mapper.SubmitRecordMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.SubmitRecordMapper;
import com.yeejoin.amos.boot.module.tdc.api.service.SubmitRecordService; import com.yeejoin.amos.boot.module.tdc.api.service.SubmitRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -14,6 +17,15 @@ import org.springframework.util.ObjectUtils; ...@@ -14,6 +17,15 @@ import org.springframework.util.ObjectUtils;
@Service @Service
public class SubmitRecordServiceImpl extends ServiceImpl<SubmitRecordMapper, SubmitRecord> implements SubmitRecordService { public class SubmitRecordServiceImpl extends ServiceImpl<SubmitRecordMapper, SubmitRecord> implements SubmitRecordService {
@Autowired
SubmitRecordMapper submitRecordMapper;
@Override
public IPage<SubmitRecord> selectByOrgCode(int current, int size) {
Page page = new Page(current,size);
return submitRecordMapper.selectByOrgCode(page);
}
@Override @Override
public int saveSubmitRecord(SubmitRecord submitRecord) { public int saveSubmitRecord(SubmitRecord submitRecord) {
return this.baseMapper.insert(submitRecord); return this.baseMapper.insert(submitRecord);
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>amos-boot-utils</artifactId>
<groupId>com.amosframework.boot</groupId>
<version>1.0.0</version>
</parent>
<artifactId>amos-boot-utils-message</artifactId>
<properties>
<tyboot.version>1.1.23-SNAPSHOT</tyboot.version>
</properties>
<dependencies>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-core</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!--kafka依赖-->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-component-emq</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.yeejoin.amos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.core.env.Environment;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* <pre>
* 服务启动类
* </pre>
*
* @author amos
* @version $Id: YeeAMOSPatrolStart.java, v 0.1 2018年11月26日 下午4:56:29 amos Exp $
*/
@SpringBootApplication
@EnableConfigurationProperties
@ServletComponentScan
@EnableDiscoveryClient
@EnableFeignClients
@EnableAsync
@EnableEurekaClient
@ComponentScan({"org.typroject","com.yeejoin.amos"})
public class AmosBootUtilsMessageApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosBootUtilsMessageApplication.class);
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext context = SpringApplication.run(AmosBootUtilsMessageApplication.class, args);
Environment env = context.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
logger.info("\n----------------------------------------------------------\n\t" +
"Application Amos-Biz-Boot is running! Access URLs:\n\t" +
"Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
"----------------------------------------------------------");
}
}
package com.yeejoin.amos.message.eqmx;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.message.kafka.KafkaProducerService;
import org.apache.commons.io.IOUtils;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import net.sf.json.JSONObject;
@Component
public class EmqMessageService extends EmqxListener {
@Autowired
protected EmqKeeper emqKeeper;
@Autowired
protected KafkaProducerService kafkaProducerService;
@Value("classpath:/json/topic.json")
private Resource topic;
private List<Map> list;
private static final BlockingQueue<JSONObject> blockingQueue = new LinkedBlockingQueue<>();
@PostConstruct
void init() throws Exception {
new Thread(task_runnable).start();
String json = null;
try {
json = IOUtils.toString(topic.getInputStream(), java.lang.String.valueOf(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
list = com.alibaba.fastjson.JSONObject.parseArray(json, Map.class);
list.forEach(e->{
try {
emqKeeper.subscript(e.get("emqTopic").toString(), 0, this);
} catch (Exception exception) {
exception.printStackTrace();
}
});
}
@Override
public void processMessage(String topic, MqttMessage message) throws Exception {
JSONObject result = JSONObject.fromObject(new String(message.getPayload()));
JSONObject messageResult = new JSONObject();
messageResult.put("result", result);
messageResult.put("topic", topic);
blockingQueue.add(messageResult);
}
Runnable task_runnable = new Runnable() {
public void run() {
while (true) {
try {
JSONObject messageResult = blockingQueue.take();
JSONObject result = messageResult.getJSONObject("result");
// 处理逻辑
list.forEach(e->{
if (e.get("emqTopic").toString().equals(messageResult.getString("topic"))) {
kafkaProducerService.sendMessageAsync(e.get("akkaTopic").toString(),JSON.toJSONString(result));
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}
package com.yeejoin.amos.message.kafka;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* kafka 消费服务
*
* @author litw
* @create 2022/11/1 10:06
**/
@Slf4j
@Service
public class KafkaConsumerService {
/**
* 消费单条消息,topics 可以监听多个topic,如:topics = {"topic1", "topic2"}
* @param message 消息
*/
@KafkaListener(id = "consumerSingle", topics = "#{'${topics}'.split(',')}")
public void consumerSingle(String message,Acknowledgment ack) {
log.info("consumerSingle ====> message: {}", message);
ack.acknowledge();
}
/* @KafkaListener(id = "consumerBatch", topicPartitions = {
@TopicPartition(topic = "hello-batch1", partitions = "0"),
@TopicPartition(topic = "hello-batch2", partitionOffsets = @PartitionOffset(partition = "2", initialOffset = "4"))
})*/
// /**
// * 批量消费消息
// * @param messages
// */
// @KafkaListener(id = "consumerBatch", topics = "test-batch")
// public void consumerBatch(List<ConsumerRecord<String, String>> messages) {
// log.info("consumerBatch =====> messageSize: {}", messages.size());
// log.info(messages.toString());
// }
// /**
// * 指定消费异常处理器
// * @param message
// */
// @KafkaListener(id = "consumerException", topics = "kafka-test-topic", errorHandler = "consumerAwareListenerErrorHandler")
// public void consumerException(String message) {
// throw new RuntimeException("consumer exception");
// }
//
// /**
// * 验证ConsumerInterceptor
// * @param message
// */
// @KafkaListener(id = "interceptor", topics = "consumer-interceptor")
// public void consumerInterceptor(String message) {
// log.info("consumerInterceptor ====> message: {}", message);
// }
//
//
//
// //kafka的监听器,topic为"zhTest",消费者组为"zhTestGroup"
// @KafkaListener(topics = "test", groupId = "zhTestGroup")
// public void listenZhugeGroup(ConsumerRecord<String, String> record, Acknowledgment ack) {
// String value = record.value();
// System.out.println(value);
// System.out.println(record);
// //手动提交offset
// ack.acknowledge();
// }
}
package com.yeejoin.amos.message.kafka;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaOperations;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.kafka.support.SendResult;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* kafka 生产服务
*
* @author litw
* @create 2022/11/1 10:06
**/
@Slf4j
@Service
public class KafkaProducerService {
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
@Resource
private KafkaTemplate<String, String> kafkaTemplateWithTransaction;
/**
* 发送消息(同步)
* @param topic 主题
* @param key 键
* @param message 值
*/
public void sendMessageSync(String topic, String key, String message) throws InterruptedException, ExecutionException, TimeoutException {
//可以指定最长等待时间,也可以不指定
kafkaTemplate.send(topic, message).get(10, TimeUnit.SECONDS);
log.info("sendMessageSync => topic: {}, key: {}, message: {}", topic, key, message);
//指定key,kafka根据key进行hash,决定存入哪个partition
// kafkaTemplate.send(topic, key, message).get(10, TimeUnit.SECONDS);
//存入指定partition
// kafkaTemplate.send(topic, 0, key, message).get(10, TimeUnit.SECONDS);
}
/**
* 发送消息并获取结果
* @param topic
* @param message
* @throws ExecutionException
* @throws InterruptedException
*/
public void sendMessageGetResult(String topic, String key, String message) throws ExecutionException, InterruptedException {
SendResult<String, String> result = kafkaTemplate.send(topic, message).get();
log.info("sendMessageSync => topic: {}, key: {}, message: {}", topic, key, message);
log.info("The partition the message was sent to: " + result.getRecordMetadata().partition());
}
/**
* 发送消息(异步)
* @param topic 主题
* @param message 消息内容
*/
public void sendMessageAsync(String topic, String message) {
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, message);
//添加回调
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onFailure(Throwable throwable) {
log.error("sendMessageAsync failure! topic : {}, message: {}", topic, message);
}
@Override
public void onSuccess(SendResult<String, String> stringStringSendResult) {
log.info("sendMessageAsync success! topic: {}, message: {}", topic, message);
}
});
}
/**
* 可以将消息组装成 Message 对象和 ProducerRecord 对象发送
* @param topic
* @param key
* @param message
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
public void testMessageBuilder(String topic, String key, String message) throws InterruptedException, ExecutionException, TimeoutException {
// 组装消息
Message msg = MessageBuilder.withPayload(message)
.setHeader(KafkaHeaders.MESSAGE_KEY, key)
.setHeader(KafkaHeaders.TOPIC, topic)
.setHeader(KafkaHeaders.PREFIX,"kafka_")
.build();
//同步发送
kafkaTemplate.send(msg).get();
// 组装消息
// ProducerRecord<String, String> producerRecord = new ProducerRecord<>(topic, message);
// kafkaTemplate.send(producerRecord).get(10, TimeUnit.SECONDS);
}
/**
* 以事务方式发送消息
* @param topic
* @param key
* @param message
*/
public void sendMessageInTransaction(String topic, String key, String message) {
kafkaTemplateWithTransaction.executeInTransaction(new KafkaOperations.OperationsCallback<String, String, Object>() {
@Override
public Object doInOperations(KafkaOperations<String, String> kafkaOperations) {
kafkaOperations.send(topic, key, message);
//出现异常将会中断事务,消息不会发送出去
throw new RuntimeException("12");
}
});
}
}
package com.yeejoin.amos.message.kafka.config;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
/**
* topic初始化
*
* @author litw
* @create 2022/11/1 10:06
*/
@Configuration class KafkaConfig {
@Value("${init.topics}")
private String topics;
/**
* 创建一个名为topic.test的Topic并设置分区数为8,分区副本数为2
*/
@Bean public void initialTopic() {
String[] split = topics.split(",");
Arrays.stream(split).forEach(e->{
new NewTopic(e, 8, (short) 2);
});
}
}
\ No newline at end of file
package com.yeejoin.amos.message.kafka.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.listener.ConsumerAwareListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
/**
* kafka 消费者配置类
*
* @author Leo
* @create 2020/12/31 15:09
**/
@Slf4j
@Configuration
public class KafkaConsumerConfiguration {
/**
* 消费异常处理器
* @return
*/
@Bean
public ConsumerAwareListenerErrorHandler consumerAwareListenerErrorHandler() {
return new ConsumerAwareListenerErrorHandler() {
@Override
public Object handleError(Message<?> message, ListenerExecutionFailedException exception, Consumer<?, ?> consumer) {
//打印消费异常的消息和异常信息
log.error("consumer failed! message: {}, exceptionMsg: {}, groupId: {}", message, exception.getMessage(), exception.getGroupId());
return null;
}
};
}
}
#注册中心地址
eureka.client.service-url.defaultZone =http://172.16.11.201:10001/eureka/
eureka.instance.prefer-ip-address=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*
eureka.instance.health-check-url-path=/actuator/health
eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator
eureka.instance.status-page-url-path=/actuator/info
eureka.instance.metadata-map.management.api-docs=http://localhost:${server.port}${server.servlet.context-path}/swagger-ui.html
## emqx
emqx.clean-session=true
emqx.client-id=${spring.application.name}-${random.int[1024,65536]}
emqx.broker=tcp://172.16.11.201:1883
emqx.client-user-name=admin
emqx.client-password=public
emqx.max-inflight=1000
spring.redis.database=1
spring.redis.host=172.16.11.201
spring.redis.port=6379
spring.redis.password=1234560
topics=akka.iot.created,akka.patrol.created
init.topics=akka.iot.created,akka.patrol.created
\ No newline at end of file
spring.application.name=AMOS-MESSAGE
server.servlet.context-path=/message
server.port=8119
spring.profiles.active=dev
spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.serialization.write-dates-as-timestamps=true
# kafka集群信息
spring.kafka.bootstrap-servers=127.0.0.1:9092
# 生产者配置
# 设置大于0的值,则客户端会将发送失败的记录重新发送 # 重试次数
spring.kafka.producer.retries=3
#16K
spring.kafka.producer.batch-size=16384
spring.kafka.producer.buffer-memory=33554432
# 应答级别
# acks=0 把消息发送到kafka就认为发送成功
# acks=1 把消息发送到kafka leader分区,并且写入磁盘就认为发送成功
# acks=all 把消息发送到kafka leader分区,并且leader分区的副本follower对消息进行了同步就任务发送成功
spring.kafka.producer.acks=1
# 指定消息key和消息体的编解码方式
# # 批量处理的最大大小 单位 byte
# batch-size: 4096
# # 发送延时,当生产端积累的消息达到batch-size或接收到消息linger.ms后,生产者就会将消息提交给kafka
# buffer-memory: 33554432
# # 客户端ID
# client-id: hello-kafka
# # 消息压缩:none、lz4、gzip、snappy,默认为 none。
# compression-type: gzip
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
# 消费者组
# 当kafka中没有初始offset或offset超出范围时将自动重置offset
# earliest:重置为分区中最小的offset
# latest:重置为分区中最新的offset(消费分区中新产生的数据)
# none:只要有一个分区不存在已提交的offset,就抛出异常
spring.kafka.consumer.group-id=zhTestGroup
spring.kafka.consumer.enable-auto-commit=false
# 当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费
# # 自动提交的频率 单位 ms
# auto-commit-interval: 1000
# # 批量消费最大数量
# max-poll-records: 100
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
# 当每一条记录被消费者监听器(ListenerConsumer)处理之后提交
# RECORD
# 当每一批poll()的数据被消费者监听器(ListenerConsumer)处理之后提交
# BATCH
# 当每一批poll()的数据被消费者监听器(ListenerConsumer)处理之后,距离上次提交时间大于TIME时提交
# TIME
# 当每一批poll()的数据被消费者监听器(ListenerConsumer)处理之后,被处理record数量大于等于COUNT时提交
# COUNT
# TIME | COUNT 有一个条件满足时提交
# COUNT_TIME
# 当每一批poll()的数据被消费者监听器(ListenerConsumer)处理之后, 手动调用Acknowledgment.acknowledge()后提交
# MANUAL
# 手动调用Acknowledgment.acknowledge()后立即提交,一般使用这种
# MANUAL_IMMEDIATE
spring.kafka.listener.ack-mode=manual_immediate
[
{
"code": "iot",
"emqTopic": "eqm.iot.created",
"akkaTopic": "akka.iot.created",
"emqCoverAkkaTopic": "emq.iot.cover.akka"
},
{
"code": "patrol",
"emqTopic": "eqm.patrol.created",
"akkaTopic": "akka.patrol.created",
"emqCoverAkkaTopic": "emq.patrol.cover.akka"
}
]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log" />
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/jpush.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--日志文件大小-->
<MaxFileSize>30mb</MaxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- show parameters for hibernate sql 专为 Hibernate 定制
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
-->
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="DEBUG"/>
<logger name="org.mybatis" level="DEBUG" />
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="org.springframework" level="DEBUG"/>
<!-- 日志输出级别 -->
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log"/>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/jpush.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<!--按大小分割同一天的-->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- show parameters for hibernate sql 专为 Hibernate 定制
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" />
<logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG" />
<logger name="org.hibernate.SQL" level="DEBUG" />
<logger name="org.hibernate.engine.QueryParameters" level="DEBUG" />
<logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG" />
-->
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="INFO"/>
<logger name="org.mybatis" level="INFO"/>
<logger name="java.sql.Connection" level="INFO"/>
<logger name="java.sql.Statement" level="INFO"/>
<logger name="java.sql.PreparedStatement" level="INFO"/>
<logger name="com.baomidou.mybatisplus" level="INFO"/>
<logger name="org.typroject" level="INFO"/>
<logger name="com.yeejoin.amos" level="INFO"/>
<logger name="org.springframework" level="INFO"/>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="FILE"/>
</root>
</configuration>
\ No newline at end of file
package com.yeejoin.amos;
import com.yeejoin.amos.message.kafka.KafkaProducerService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AmosBootUtilsMessageApplicationTests {
@Autowired
private KafkaProducerService kafkaProducerService;
@Test
void contextLoads() {
String msg = "hello";
kafkaProducerService.sendMessageAsync("akka.iot.created",msg);
}
}
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