diff --git a/jnpf-java-boot/jnpf-admin/src/main/resources/application-dev.yml b/jnpf-java-boot/jnpf-admin/src/main/resources/application-dev.yml index 8f8dc75..3239988 100644 --- a/jnpf-java-boot/jnpf-admin/src/main/resources/application-dev.yml +++ b/jnpf-java-boot/jnpf-admin/src/main/resources/application-dev.yml @@ -13,19 +13,21 @@ spring: thymeleaf: cache: false #spring内置thymeleaf缓存 - # ===================== 数据源配置 ===================== - exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure #排除自动配置,手动配置druid - datasource: - db-type: MySQL #数据库类型(可选值 MySQL、SQLServer、Oracle、DM8、KingbaseES、PostgreSQL,请严格按可选值填写) - host: 222.71.165.188 - port: 3309 - username: root - password: linus,.123 - db-name: jnpf_yys_dev - db-schema: #金仓达梦选填 - prepare-url: #自定义url + # ===================== 数据源配置 ===================== + # exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure #排除自动配置,手动配置druid + # datasource: + # db-type: MySQL #数据库类型(可选值 MySQL、SQLServer、Oracle、DM8、KingbaseES、PostgreSQL,请严格按可选值填写) + # host: 222.71.165.188 + # port: 3309 + # username: root + # password: linus,.123 + # db-name: jnpf_yys_dev + # db-schema: #金仓达梦选填 + # prepare-url: #自定义url # ===================== 动态多数据源 ===================== + datasource: + db-type: MySQL dynamic: primary: master #设置默认的数据源或者数据源组,默认值即为master strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源 @@ -59,21 +61,26 @@ spring: statementPrepareAfterLogEnabled: false statementPrepareCallAfterLogEnabled: false statementParameterSetLogEnabled: false - # datasource: - # master: - # url: jdbc:mysql://${spring.datasource.host}:${spring.datasource.port}/${spring.datasource.dbname}?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=UTC - # username: ${spring.datasource.username} - # password: ${spring.datasource.password} - # driver-class-name: com.mysql.cj.jdbc.Driver + datasource: + master: + url: jdbc:mysql://222.71.165.188:3309/jnpf_yys_dev?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: linus,.123 + driver-class-name: com.mysql.cj.jdbc.Driver + slave_1: + url: jdbc:mysql://222.71.165.188:3309/yys-sc?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: linus,.123 + driver-class-name: com.mysql.cj.jdbc.Driver # ===================== Redis配置 ===================== # redis单机模式 redis: database: 1 #缓存库编号 -# host: 222.71.165.188 + # host: 222.71.165.188 host: 127.0.0.1 port: 6379 -# password: qweasd,.123 # 密码为空时,请将本行注释 + # password: qweasd,.123 # 密码为空时,请将本行注释 timeout: 3000 #超时时间(单位:秒) lettuce: #Lettuce为Redis的Java驱动包 pool: diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceDataService.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceDataService.java index 10cc27c..e96e890 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceDataService.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceDataService.java @@ -32,4 +32,6 @@ public interface YysDeviceDataService extends IService { void saveOrUpdate(YysDeviceDataForm yysDeviceDataForm,String id, boolean isSave) throws Exception; + List syncData(List syncIds); + } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnService.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnService.java index 59505be..9c51adc 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnService.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnService.java @@ -32,4 +32,5 @@ public interface YysDeviceWarnService extends IService { void saveOrUpdate(YysDeviceWarnForm yysDeviceWarnForm,String id, boolean isSave) throws Exception; + void syncCount(List collect); } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnStatisticsService.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnStatisticsService.java index 61f8292..b40d302 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnStatisticsService.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysDeviceWarnStatisticsService.java @@ -2,7 +2,9 @@ package jnpf.service; import jnpf.model.yysdevicewarnstatistics.*; import jnpf.entity.*; + import java.util.*; + import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -16,7 +18,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; public interface YysDeviceWarnStatisticsService extends IService { List getList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination); - List getTypeList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination,String dataType); + List getTypeList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination, String dataType); YysDeviceWarnStatisticsEntity getInfo(String id); @@ -28,8 +30,10 @@ public interface YysDeviceWarnStatisticsService extends IService syncData(List syncIds); } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceDataServiceImpl.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceDataServiceImpl.java index 020b2fb..3b7188c 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceDataServiceImpl.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceDataServiceImpl.java @@ -1,23 +1,37 @@ package jnpf.service.impl; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.google.common.collect.Lists; import jnpf.entity.*; import jnpf.mapper.YysDeviceDataMapper; import jnpf.service.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import jnpf.model.yysdevicedata.*; + import java.math.BigDecimal; + import cn.hutool.core.util.ObjectUtil; import jnpf.permission.model.authorize.AuthorizeConditionModel; import jnpf.util.GeneraterSwapUtil; import jnpf.database.model.superQuery.SuperQueryJsonModel; import jnpf.database.model.superQuery.ConditionJsonModel; import jnpf.database.model.superQuery.SuperQueryConditionModel; + import java.lang.reflect.Field; + import com.baomidou.mybatisplus.annotation.TableField; + import java.util.regex.Pattern; + import jnpf.model.QueryModel; + import java.util.stream.Collectors; + import jnpf.base.model.ColumnDataModel; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import jnpf.database.model.superQuery.SuperJsonModel; @@ -25,13 +39,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + import java.text.SimpleDateFormat; + import jnpf.util.*; + import java.util.*; + import jnpf.base.UserInfo; import jnpf.permission.entity.UserEntity; + /** - * * yysDeviceData * 版本: V3.5 * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com) @@ -39,244 +57,278 @@ import jnpf.permission.entity.UserEntity; * 日期: 2024-08-09 */ @Service -public class YysDeviceDataServiceImpl extends ServiceImpl implements YysDeviceDataService{ +public class YysDeviceDataServiceImpl extends ServiceImpl implements YysDeviceDataService { @Autowired private GeneraterSwapUtil generaterSwapUtil; @Autowired private UserProvider userProvider; + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override - public List getList(YysDeviceDataPagination yysDeviceDataPagination){ - return getTypeList(yysDeviceDataPagination,yysDeviceDataPagination.getDataType()); + public List getList(YysDeviceDataPagination yysDeviceDataPagination) { + return getTypeList(yysDeviceDataPagination, yysDeviceDataPagination.getDataType()); } - /** 列表查询 */ + + /** + * 列表查询 + */ @Override - public List getTypeList(YysDeviceDataPagination yysDeviceDataPagination,String dataType){ - String userId=userProvider.get().getUserId(); - List AllIdList =new ArrayList(); - List> intersectionList =new ArrayList<>(); + public List getTypeList(YysDeviceDataPagination yysDeviceDataPagination, String dataType) { + String userId = userProvider.get().getUserId(); + List AllIdList = new ArrayList(); + List> intersectionList = new ArrayList<>(); boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc"); String columnData = !isPc ? YysDeviceDataConstant.getAppColumnData() : YysDeviceDataConstant.getColumnData(); ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class); String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList()); - int total=0; - int yysDeviceDataNum =0; - QueryWrapper yysDeviceDataQueryWrapper=new QueryWrapper<>(); + int total = 0; + int yysDeviceDataNum = 0; + QueryWrapper yysDeviceDataQueryWrapper = new QueryWrapper<>(); List allSuperIDlist = new ArrayList<>(); - String superOp =""; - if (ObjectUtil.isNotEmpty(yysDeviceDataPagination.getSuperQueryJson())){ + String superOp = ""; + if (ObjectUtil.isNotEmpty(yysDeviceDataPagination.getSuperQueryJson())) { List allSuperList = new ArrayList<>(); - List> intersectionSuperList = new ArrayList<>(); + List> intersectionSuperList = new ArrayList<>(); String queryJson = yysDeviceDataPagination.getSuperQueryJson(); SuperJsonModel superJsonModel = JsonUtil.getJsonToBean(queryJson, SuperJsonModel.class); int superNum = 0; QueryWrapper yysDeviceDataSuperWrapper = new QueryWrapper<>(); - yysDeviceDataSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceDataSuperWrapper,YysDeviceDataEntity.class,queryJson,"0")); + yysDeviceDataSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceDataSuperWrapper, YysDeviceDataEntity.class, queryJson, "0")); int yysDeviceDataNum1 = yysDeviceDataSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceDataNum1>0){ - List yysDeviceDataList =this.list(yysDeviceDataSuperWrapper).stream().map(YysDeviceDataEntity::getId).collect(Collectors.toList()); + if (yysDeviceDataNum1 > 0) { + List yysDeviceDataList = this.list(yysDeviceDataSuperWrapper).stream().map(YysDeviceDataEntity::getId).collect(Collectors.toList()); allSuperList.addAll(yysDeviceDataList); intersectionSuperList.add(yysDeviceDataList); superNum++; } superOp = superNum > 0 ? superJsonModel.getMatchLogic() : ""; //and or - if(superOp.equalsIgnoreCase("and")){ + if (superOp.equalsIgnoreCase("and")) { allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList); - }else{ + } else { allSuperIDlist = allSuperList; } } List allRuleIDlist = new ArrayList<>(); - String ruleOp =""; - if (ObjectUtil.isNotEmpty(ruleJson)){ + String ruleOp = ""; + if (ObjectUtil.isNotEmpty(ruleJson)) { List allRuleList = new ArrayList<>(); - List> intersectionRuleList = new ArrayList<>(); + List> intersectionRuleList = new ArrayList<>(); SuperJsonModel ruleJsonModel = JsonUtil.getJsonToBean(ruleJson, SuperJsonModel.class); int ruleNum = 0; QueryWrapper yysDeviceDataSuperWrapper = new QueryWrapper<>(); - yysDeviceDataSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceDataSuperWrapper,YysDeviceDataEntity.class,ruleJson,"0")); + yysDeviceDataSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceDataSuperWrapper, YysDeviceDataEntity.class, ruleJson, "0")); int yysDeviceDataNum1 = yysDeviceDataSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceDataNum1>0){ - List yysDeviceDataList =this.list(yysDeviceDataSuperWrapper).stream().map(YysDeviceDataEntity::getId).collect(Collectors.toList()); + if (yysDeviceDataNum1 > 0) { + List yysDeviceDataList = this.list(yysDeviceDataSuperWrapper).stream().map(YysDeviceDataEntity::getId).collect(Collectors.toList()); allRuleList.addAll(yysDeviceDataList); intersectionRuleList.add(yysDeviceDataList); ruleNum++; } ruleOp = ruleNum > 0 ? ruleJsonModel.getMatchLogic() : ""; //and or - if(ruleOp.equalsIgnoreCase("and")){ + if (ruleOp.equalsIgnoreCase("and")) { allRuleIDlist = generaterSwapUtil.getIntersection(intersectionRuleList); - }else{ + } else { allRuleIDlist = allRuleList; } } - boolean pcPermission = false; - boolean appPermission = false; - if(isPc && pcPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceDataObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceDataQueryWrapper,YysDeviceDataEntity.class,yysDeviceDataPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceDataObj)){ - return new ArrayList<>(); - } else { - yysDeviceDataQueryWrapper = (QueryWrapper)yysDeviceDataObj; - if( yysDeviceDataQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceDataNum++; - } - } - } - } - if(!isPc && appPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceDataObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceDataQueryWrapper,YysDeviceDataEntity.class,yysDeviceDataPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceDataObj)){ - return new ArrayList<>(); - } else { - yysDeviceDataQueryWrapper = (QueryWrapper)yysDeviceDataObj; - if( yysDeviceDataQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceDataNum++; - } + boolean pcPermission = false; + boolean appPermission = false; + if (isPc && pcPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceDataObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceDataQueryWrapper, YysDeviceDataEntity.class, yysDeviceDataPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceDataObj)) { + return new ArrayList<>(); + } else { + yysDeviceDataQueryWrapper = (QueryWrapper) yysDeviceDataObj; + if (yysDeviceDataQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceDataNum++; + } + } + } } + if (!isPc && appPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceDataObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceDataQueryWrapper, YysDeviceDataEntity.class, yysDeviceDataPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceDataObj)) { + return new ArrayList<>(); + } else { + yysDeviceDataQueryWrapper = (QueryWrapper) yysDeviceDataObj; + if (yysDeviceDataQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceDataNum++; + } + } - } - } - if(isPc){ - if(ObjectUtil.isNotEmpty(yysDeviceDataPagination.getProductionLine())){ - yysDeviceDataNum++; + } + } + if (isPc) { + if (ObjectUtil.isNotEmpty(yysDeviceDataPagination.getProductionLine())) { + yysDeviceDataNum++; String value = yysDeviceDataPagination.getProductionLine() instanceof List ? - JsonUtil.getObjectToString(yysDeviceDataPagination.getProductionLine()) : - String.valueOf(yysDeviceDataPagination.getProductionLine()); - yysDeviceDataQueryWrapper.lambda().like(YysDeviceDataEntity::getProductionLine,value); + JsonUtil.getObjectToString(yysDeviceDataPagination.getProductionLine()) : + String.valueOf(yysDeviceDataPagination.getProductionLine()); + yysDeviceDataQueryWrapper.lambda().like(YysDeviceDataEntity::getProductionLine, value); } - if(ObjectUtil.isNotEmpty(yysDeviceDataPagination.getCreatorTime())){ - yysDeviceDataNum++; + if (ObjectUtil.isNotEmpty(yysDeviceDataPagination.getCreatorTime())) { + yysDeviceDataNum++; - List CreatorTimeList = JsonUtil.getJsonToList(yysDeviceDataPagination.getCreatorTime(),String.class); - Long fir = Long.valueOf(String.valueOf(CreatorTimeList.get(0))); - Long sec = Long.valueOf(String.valueOf(CreatorTimeList.get(1))); + List CreatorTimeList = JsonUtil.getJsonToList(yysDeviceDataPagination.getCreatorTime(), String.class); + Long fir = Long.valueOf(String.valueOf(CreatorTimeList.get(0))); + Long sec = Long.valueOf(String.valueOf(CreatorTimeList.get(1))); - yysDeviceDataQueryWrapper.lambda().ge(YysDeviceDataEntity::getCreatorTime, new Date(fir)) - .le(YysDeviceDataEntity::getCreatorTime, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59")); + yysDeviceDataQueryWrapper.lambda().ge(YysDeviceDataEntity::getCreatorTime, new Date(fir)) + .le(YysDeviceDataEntity::getCreatorTime, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59")); } } List intersection = generaterSwapUtil.getIntersection(intersectionList); - if (total>0){ - if (intersection.size()==0){ + if (total > 0) { + if (intersection.size() == 0) { intersection.add("jnpfNullList"); } yysDeviceDataQueryWrapper.lambda().in(YysDeviceDataEntity::getId, intersection); } - //是否有高级查询 - if (StringUtil.isNotEmpty(superOp)){ - if (allSuperIDlist.size()==0){ + //是否有高级查询 + if (StringUtil.isNotEmpty(superOp)) { + if (allSuperIDlist.size() == 0) { allSuperIDlist.add("jnpfNullList"); } List finalAllSuperIDlist = allSuperIDlist; - yysDeviceDataQueryWrapper.lambda().and(t->t.in(YysDeviceDataEntity::getId, finalAllSuperIDlist)); + yysDeviceDataQueryWrapper.lambda().and(t -> t.in(YysDeviceDataEntity::getId, finalAllSuperIDlist)); } - //是否有数据过滤查询 - if (StringUtil.isNotEmpty(ruleOp)){ - if (allRuleIDlist.size()==0){ + //是否有数据过滤查询 + if (StringUtil.isNotEmpty(ruleOp)) { + if (allRuleIDlist.size() == 0) { allRuleIDlist.add("jnpfNullList"); } List finalAllRuleIDlist = allRuleIDlist; - yysDeviceDataQueryWrapper.lambda().and(t->t.in(YysDeviceDataEntity::getId, finalAllRuleIDlist)); + yysDeviceDataQueryWrapper.lambda().and(t -> t.in(YysDeviceDataEntity::getId, finalAllRuleIDlist)); } //排序 - if(StringUtil.isEmpty(yysDeviceDataPagination.getSidx())){ + if (StringUtil.isEmpty(yysDeviceDataPagination.getSidx())) { yysDeviceDataQueryWrapper.lambda().orderByDesc(YysDeviceDataEntity::getId); - }else{ + } else { try { String sidx = yysDeviceDataPagination.getSidx(); - String[] strs= sidx.split("_name"); + String[] strs = sidx.split("_name"); YysDeviceDataEntity yysDeviceDataEntity = new YysDeviceDataEntity(); Field declaredField = yysDeviceDataEntity.getClass().getDeclaredField(strs[0]); declaredField.setAccessible(true); String value = declaredField.getAnnotation(TableField.class).value(); - yysDeviceDataQueryWrapper="asc".equals(yysDeviceDataPagination.getSort().toLowerCase())?yysDeviceDataQueryWrapper.orderByAsc(value):yysDeviceDataQueryWrapper.orderByDesc(value); + yysDeviceDataQueryWrapper = "asc".equals(yysDeviceDataPagination.getSort().toLowerCase()) ? yysDeviceDataQueryWrapper.orderByAsc(value) : yysDeviceDataQueryWrapper.orderByDesc(value); } catch (NoSuchFieldException e) { e.printStackTrace(); } } - if("0".equals(dataType)){ - if((total>0 && AllIdList.size()>0) || total==0){ - Page page=new Page<>(yysDeviceDataPagination.getCurrentPage(), yysDeviceDataPagination.getPageSize()); - IPage userIPage=this.page(page, yysDeviceDataQueryWrapper); - return yysDeviceDataPagination.setData(userIPage.getRecords(),userIPage.getTotal()); - }else{ + if ("0".equals(dataType)) { + if ((total > 0 && AllIdList.size() > 0) || total == 0) { + Page page = new Page<>(yysDeviceDataPagination.getCurrentPage(), yysDeviceDataPagination.getPageSize()); + IPage userIPage = this.page(page, yysDeviceDataQueryWrapper); + return yysDeviceDataPagination.setData(userIPage.getRecords(), userIPage.getTotal()); + } else { List list = new ArrayList(); return yysDeviceDataPagination.setData(list, list.size()); } - }else{ + } else { return this.list(yysDeviceDataQueryWrapper); } } + @Override - public YysDeviceDataEntity getInfo(String id){ - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(YysDeviceDataEntity::getId,id); + public YysDeviceDataEntity getInfo(String id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(YysDeviceDataEntity::getId, id); return this.getOne(queryWrapper); } + @Override - public void create(YysDeviceDataEntity entity){ + public void create(YysDeviceDataEntity entity) { this.save(entity); } + @Override - public boolean update(String id, YysDeviceDataEntity entity){ + public boolean update(String id, YysDeviceDataEntity entity) { return this.updateById(entity); } + @Override - public void delete(YysDeviceDataEntity entity){ - if(entity!=null){ + public void delete(YysDeviceDataEntity entity) { + if (entity != null) { this.removeById(entity.getId()); } } - /** 验证表单唯一字段,正则,非空 i-0新增-1修改*/ + + /** + * 验证表单唯一字段,正则,非空 i-0新增-1修改 + */ @Override - public String checkForm(YysDeviceDataForm form,int i) { - boolean isUp =StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); - String id=""; + public String checkForm(YysDeviceDataForm form, int i) { + boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); + String id = ""; String countRecover = ""; - if (isUp){ + if (isUp) { id = form.getId(); } //主表字段验证 return countRecover; } + /** - * 新增修改数据(事务回滚) - * @param id - * @param yysDeviceDataForm - * @return - */ + * 新增修改数据(事务回滚) + * + * @param id + * @param yysDeviceDataForm + * @return + */ @Override @Transactional - public void saveOrUpdate(YysDeviceDataForm yysDeviceDataForm,String id, boolean isSave) throws Exception{ - UserInfo userInfo=userProvider.get(); + public void saveOrUpdate(YysDeviceDataForm yysDeviceDataForm, String id, boolean isSave) throws Exception { + UserInfo userInfo = userProvider.get(); UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId()); yysDeviceDataForm = JsonUtil.getJsonToBean( - generaterSwapUtil.swapDatetime(YysDeviceDataConstant.getFormData(),yysDeviceDataForm),YysDeviceDataForm.class); + generaterSwapUtil.swapDatetime(YysDeviceDataConstant.getFormData(), yysDeviceDataForm), YysDeviceDataForm.class); YysDeviceDataEntity entity = JsonUtil.getJsonToBean(yysDeviceDataForm, YysDeviceDataEntity.class); - if(isSave){ - String mainId = RandomUtil.uuId() ; - entity.setCreatorTime(DateUtil.getNowDate()); + if (isSave) { + String mainId = RandomUtil.uuId(); + entity.setCreatorTime(DateUtil.getNowDate()); entity.setId(mainId); - }else{ - entity.setCreatorTime(DateUtil.getNowDate()); + } else { + entity.setCreatorTime(DateUtil.getNowDate()); } this.saveOrUpdate(entity); } + + @Override + @DS("slave_1") + public List syncData(List syncIds) { + List result = Lists.newArrayList(); + String[] lines = new String[]{"1", "2", "3", "4"}; + for (String line : lines) { + String childTable = "eqmt_collect_data_sc_" + line; + String sql = "select b.*," + line + " as line from " + childTable + " a left join eqmt_collect_pub_data b on a.eqmt_id = b.eqmt_id"; + RowMapper rowMapper = new BeanPropertyRowMapper<>(EqmtCollectPubDataEntity.class); + result.addAll(this.jdbcTemplate.query(sql, rowMapper)); + } + if (CollectionUtils.isEmpty(syncIds)) { + return result; + } + //过滤出已经生成的 + return result.stream().filter(obj -> !syncIds.contains(obj.getId())).collect(Collectors.toList()); + } } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnServiceImpl.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnServiceImpl.java index 59be6d1..2ec8588 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnServiceImpl.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnServiceImpl.java @@ -1,23 +1,34 @@ package jnpf.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.google.common.collect.Lists; import jnpf.entity.*; import jnpf.mapper.YysDeviceWarnMapper; import jnpf.service.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import jnpf.model.yysdevicewarn.*; + import java.math.BigDecimal; + import cn.hutool.core.util.ObjectUtil; import jnpf.permission.model.authorize.AuthorizeConditionModel; import jnpf.util.GeneraterSwapUtil; import jnpf.database.model.superQuery.SuperQueryJsonModel; import jnpf.database.model.superQuery.ConditionJsonModel; import jnpf.database.model.superQuery.SuperQueryConditionModel; + import java.lang.reflect.Field; + import com.baomidou.mybatisplus.annotation.TableField; + import java.util.regex.Pattern; + import jnpf.model.QueryModel; + import java.util.stream.Collectors; + import jnpf.base.model.ColumnDataModel; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import jnpf.database.model.superQuery.SuperJsonModel; @@ -25,13 +36,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + import java.text.SimpleDateFormat; + import jnpf.util.*; + import java.util.*; + import jnpf.base.UserInfo; import jnpf.permission.entity.UserEntity; + /** - * * yysDeviceWarn * 版本: V3.5 * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com) @@ -39,7 +54,7 @@ import jnpf.permission.entity.UserEntity; * 日期: 2024-08-09 */ @Service -public class YysDeviceWarnServiceImpl extends ServiceImpl implements YysDeviceWarnService{ +public class YysDeviceWarnServiceImpl extends ServiceImpl implements YysDeviceWarnService { @Autowired private GeneraterSwapUtil generaterSwapUtil; @@ -47,233 +62,298 @@ public class YysDeviceWarnServiceImpl extends ServiceImpl getList(YysDeviceWarnPagination yysDeviceWarnPagination){ - return getTypeList(yysDeviceWarnPagination,yysDeviceWarnPagination.getDataType()); + public List getList(YysDeviceWarnPagination yysDeviceWarnPagination) { + return getTypeList(yysDeviceWarnPagination, yysDeviceWarnPagination.getDataType()); } - /** 列表查询 */ + + /** + * 列表查询 + */ @Override - public List getTypeList(YysDeviceWarnPagination yysDeviceWarnPagination,String dataType){ - String userId=userProvider.get().getUserId(); - List AllIdList =new ArrayList(); - List> intersectionList =new ArrayList<>(); + public List getTypeList(YysDeviceWarnPagination yysDeviceWarnPagination, String dataType) { + String userId = userProvider.get().getUserId(); + List AllIdList = new ArrayList(); + List> intersectionList = new ArrayList<>(); boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc"); String columnData = !isPc ? YysDeviceWarnConstant.getAppColumnData() : YysDeviceWarnConstant.getColumnData(); ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class); String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList()); - int total=0; - int yysDeviceWarnNum =0; - QueryWrapper yysDeviceWarnQueryWrapper=new QueryWrapper<>(); + int total = 0; + int yysDeviceWarnNum = 0; + QueryWrapper yysDeviceWarnQueryWrapper = new QueryWrapper<>(); List allSuperIDlist = new ArrayList<>(); - String superOp =""; - if (ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getSuperQueryJson())){ + String superOp = ""; + if (ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getSuperQueryJson())) { List allSuperList = new ArrayList<>(); - List> intersectionSuperList = new ArrayList<>(); + List> intersectionSuperList = new ArrayList<>(); String queryJson = yysDeviceWarnPagination.getSuperQueryJson(); SuperJsonModel superJsonModel = JsonUtil.getJsonToBean(queryJson, SuperJsonModel.class); int superNum = 0; QueryWrapper yysDeviceWarnSuperWrapper = new QueryWrapper<>(); - yysDeviceWarnSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnSuperWrapper,YysDeviceWarnEntity.class,queryJson,"0")); + yysDeviceWarnSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnSuperWrapper, YysDeviceWarnEntity.class, queryJson, "0")); int yysDeviceWarnNum1 = yysDeviceWarnSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceWarnNum1>0){ - List yysDeviceWarnList =this.list(yysDeviceWarnSuperWrapper).stream().map(YysDeviceWarnEntity::getId).collect(Collectors.toList()); + if (yysDeviceWarnNum1 > 0) { + List yysDeviceWarnList = this.list(yysDeviceWarnSuperWrapper).stream().map(YysDeviceWarnEntity::getId).collect(Collectors.toList()); allSuperList.addAll(yysDeviceWarnList); intersectionSuperList.add(yysDeviceWarnList); superNum++; } superOp = superNum > 0 ? superJsonModel.getMatchLogic() : ""; //and or - if(superOp.equalsIgnoreCase("and")){ + if (superOp.equalsIgnoreCase("and")) { allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList); - }else{ + } else { allSuperIDlist = allSuperList; } } List allRuleIDlist = new ArrayList<>(); - String ruleOp =""; - if (ObjectUtil.isNotEmpty(ruleJson)){ + String ruleOp = ""; + if (ObjectUtil.isNotEmpty(ruleJson)) { List allRuleList = new ArrayList<>(); - List> intersectionRuleList = new ArrayList<>(); + List> intersectionRuleList = new ArrayList<>(); SuperJsonModel ruleJsonModel = JsonUtil.getJsonToBean(ruleJson, SuperJsonModel.class); int ruleNum = 0; QueryWrapper yysDeviceWarnSuperWrapper = new QueryWrapper<>(); - yysDeviceWarnSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnSuperWrapper,YysDeviceWarnEntity.class,ruleJson,"0")); + yysDeviceWarnSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnSuperWrapper, YysDeviceWarnEntity.class, ruleJson, "0")); int yysDeviceWarnNum1 = yysDeviceWarnSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceWarnNum1>0){ - List yysDeviceWarnList =this.list(yysDeviceWarnSuperWrapper).stream().map(YysDeviceWarnEntity::getId).collect(Collectors.toList()); + if (yysDeviceWarnNum1 > 0) { + List yysDeviceWarnList = this.list(yysDeviceWarnSuperWrapper).stream().map(YysDeviceWarnEntity::getId).collect(Collectors.toList()); allRuleList.addAll(yysDeviceWarnList); intersectionRuleList.add(yysDeviceWarnList); ruleNum++; } ruleOp = ruleNum > 0 ? ruleJsonModel.getMatchLogic() : ""; //and or - if(ruleOp.equalsIgnoreCase("and")){ + if (ruleOp.equalsIgnoreCase("and")) { allRuleIDlist = generaterSwapUtil.getIntersection(intersectionRuleList); - }else{ + } else { allRuleIDlist = allRuleList; } } - boolean pcPermission = false; - boolean appPermission = false; - if(isPc && pcPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceWarnObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnQueryWrapper,YysDeviceWarnEntity.class,yysDeviceWarnPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceWarnObj)){ - return new ArrayList<>(); - } else { - yysDeviceWarnQueryWrapper = (QueryWrapper)yysDeviceWarnObj; - if( yysDeviceWarnQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceWarnNum++; - } - } - } - } - if(!isPc && appPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceWarnObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnQueryWrapper,YysDeviceWarnEntity.class,yysDeviceWarnPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceWarnObj)){ - return new ArrayList<>(); - } else { - yysDeviceWarnQueryWrapper = (QueryWrapper)yysDeviceWarnObj; - if( yysDeviceWarnQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceWarnNum++; - } + boolean pcPermission = false; + boolean appPermission = false; + if (isPc && pcPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceWarnObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnQueryWrapper, YysDeviceWarnEntity.class, yysDeviceWarnPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceWarnObj)) { + return new ArrayList<>(); + } else { + yysDeviceWarnQueryWrapper = (QueryWrapper) yysDeviceWarnObj; + if (yysDeviceWarnQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceWarnNum++; + } + } + } } + if (!isPc && appPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceWarnObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnQueryWrapper, YysDeviceWarnEntity.class, yysDeviceWarnPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceWarnObj)) { + return new ArrayList<>(); + } else { + yysDeviceWarnQueryWrapper = (QueryWrapper) yysDeviceWarnObj; + if (yysDeviceWarnQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceWarnNum++; + } + } - } - } - if(isPc){ - if(ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getProductionLine())){ - yysDeviceWarnNum++; + } + } + if (isPc) { + if (ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getProductionLine())) { + yysDeviceWarnNum++; String value = yysDeviceWarnPagination.getProductionLine() instanceof List ? - JsonUtil.getObjectToString(yysDeviceWarnPagination.getProductionLine()) : - String.valueOf(yysDeviceWarnPagination.getProductionLine()); - yysDeviceWarnQueryWrapper.lambda().like(YysDeviceWarnEntity::getProductionLine,value); + JsonUtil.getObjectToString(yysDeviceWarnPagination.getProductionLine()) : + String.valueOf(yysDeviceWarnPagination.getProductionLine()); + yysDeviceWarnQueryWrapper.lambda().like(YysDeviceWarnEntity::getProductionLine, value); } - if(ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getCreatorTime())){ - yysDeviceWarnNum++; + if (ObjectUtil.isNotEmpty(yysDeviceWarnPagination.getCreatorTime())) { + yysDeviceWarnNum++; - List CreatorTimeList = JsonUtil.getJsonToList(yysDeviceWarnPagination.getCreatorTime(),String.class); - String fir = String.valueOf(CreatorTimeList.get(0)); - String sec = String.valueOf(CreatorTimeList.get(1)); - yysDeviceWarnQueryWrapper.lambda().ge(YysDeviceWarnEntity::getCreatorTime, fir) - .le(YysDeviceWarnEntity::getCreatorTime, sec); + List CreatorTimeList = JsonUtil.getJsonToList(yysDeviceWarnPagination.getCreatorTime(), String.class); + String fir = String.valueOf(CreatorTimeList.get(0)); + String sec = String.valueOf(CreatorTimeList.get(1)); + yysDeviceWarnQueryWrapper.lambda().ge(YysDeviceWarnEntity::getCreatorTime, fir) + .le(YysDeviceWarnEntity::getCreatorTime, sec); } } List intersection = generaterSwapUtil.getIntersection(intersectionList); - if (total>0){ - if (intersection.size()==0){ + if (total > 0) { + if (intersection.size() == 0) { intersection.add("jnpfNullList"); } yysDeviceWarnQueryWrapper.lambda().in(YysDeviceWarnEntity::getId, intersection); } - //是否有高级查询 - if (StringUtil.isNotEmpty(superOp)){ - if (allSuperIDlist.size()==0){ + //是否有高级查询 + if (StringUtil.isNotEmpty(superOp)) { + if (allSuperIDlist.size() == 0) { allSuperIDlist.add("jnpfNullList"); } List finalAllSuperIDlist = allSuperIDlist; - yysDeviceWarnQueryWrapper.lambda().and(t->t.in(YysDeviceWarnEntity::getId, finalAllSuperIDlist)); + yysDeviceWarnQueryWrapper.lambda().and(t -> t.in(YysDeviceWarnEntity::getId, finalAllSuperIDlist)); } - //是否有数据过滤查询 - if (StringUtil.isNotEmpty(ruleOp)){ - if (allRuleIDlist.size()==0){ + //是否有数据过滤查询 + if (StringUtil.isNotEmpty(ruleOp)) { + if (allRuleIDlist.size() == 0) { allRuleIDlist.add("jnpfNullList"); } List finalAllRuleIDlist = allRuleIDlist; - yysDeviceWarnQueryWrapper.lambda().and(t->t.in(YysDeviceWarnEntity::getId, finalAllRuleIDlist)); + yysDeviceWarnQueryWrapper.lambda().and(t -> t.in(YysDeviceWarnEntity::getId, finalAllRuleIDlist)); } //排序 - if(StringUtil.isEmpty(yysDeviceWarnPagination.getSidx())){ + if (StringUtil.isEmpty(yysDeviceWarnPagination.getSidx())) { yysDeviceWarnQueryWrapper.lambda().orderByDesc(YysDeviceWarnEntity::getId); - }else{ + } else { try { String sidx = yysDeviceWarnPagination.getSidx(); - String[] strs= sidx.split("_name"); + String[] strs = sidx.split("_name"); YysDeviceWarnEntity yysDeviceWarnEntity = new YysDeviceWarnEntity(); Field declaredField = yysDeviceWarnEntity.getClass().getDeclaredField(strs[0]); declaredField.setAccessible(true); String value = declaredField.getAnnotation(TableField.class).value(); - yysDeviceWarnQueryWrapper="asc".equals(yysDeviceWarnPagination.getSort().toLowerCase())?yysDeviceWarnQueryWrapper.orderByAsc(value):yysDeviceWarnQueryWrapper.orderByDesc(value); + yysDeviceWarnQueryWrapper = "asc".equals(yysDeviceWarnPagination.getSort().toLowerCase()) ? yysDeviceWarnQueryWrapper.orderByAsc(value) : yysDeviceWarnQueryWrapper.orderByDesc(value); } catch (NoSuchFieldException e) { e.printStackTrace(); } } - if("0".equals(dataType)){ - if((total>0 && AllIdList.size()>0) || total==0){ - Page page=new Page<>(yysDeviceWarnPagination.getCurrentPage(), yysDeviceWarnPagination.getPageSize()); - IPage userIPage=this.page(page, yysDeviceWarnQueryWrapper); - return yysDeviceWarnPagination.setData(userIPage.getRecords(),userIPage.getTotal()); - }else{ + if ("0".equals(dataType)) { + if ((total > 0 && AllIdList.size() > 0) || total == 0) { + Page page = new Page<>(yysDeviceWarnPagination.getCurrentPage(), yysDeviceWarnPagination.getPageSize()); + IPage userIPage = this.page(page, yysDeviceWarnQueryWrapper); + return yysDeviceWarnPagination.setData(userIPage.getRecords(), userIPage.getTotal()); + } else { List list = new ArrayList(); return yysDeviceWarnPagination.setData(list, list.size()); } - }else{ + } else { return this.list(yysDeviceWarnQueryWrapper); } } + @Override - public YysDeviceWarnEntity getInfo(String id){ - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(YysDeviceWarnEntity::getId,id); + public YysDeviceWarnEntity getInfo(String id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(YysDeviceWarnEntity::getId, id); return this.getOne(queryWrapper); } + @Override - public void create(YysDeviceWarnEntity entity){ + public void create(YysDeviceWarnEntity entity) { this.save(entity); } + @Override - public boolean update(String id, YysDeviceWarnEntity entity){ + public boolean update(String id, YysDeviceWarnEntity entity) { return this.updateById(entity); } + @Override - public void delete(YysDeviceWarnEntity entity){ - if(entity!=null){ + public void delete(YysDeviceWarnEntity entity) { + if (entity != null) { this.removeById(entity.getId()); } } - /** 验证表单唯一字段,正则,非空 i-0新增-1修改*/ + + /** + * 验证表单唯一字段,正则,非空 i-0新增-1修改 + */ @Override - public String checkForm(YysDeviceWarnForm form,int i) { - boolean isUp =StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); - String id=""; + public String checkForm(YysDeviceWarnForm form, int i) { + boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); + String id = ""; String countRecover = ""; - if (isUp){ + if (isUp) { id = form.getId(); } //主表字段验证 return countRecover; } + /** - * 新增修改数据(事务回滚) - * @param id - * @param yysDeviceWarnForm - * @return - */ + * 新增修改数据(事务回滚) + * + * @param id + * @param yysDeviceWarnForm + * @return + */ @Override @Transactional - public void saveOrUpdate(YysDeviceWarnForm yysDeviceWarnForm,String id, boolean isSave) throws Exception{ - UserInfo userInfo=userProvider.get(); + public void saveOrUpdate(YysDeviceWarnForm yysDeviceWarnForm, String id, boolean isSave) throws Exception { + UserInfo userInfo = userProvider.get(); UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId()); yysDeviceWarnForm = JsonUtil.getJsonToBean( - generaterSwapUtil.swapDatetime(YysDeviceWarnConstant.getFormData(),yysDeviceWarnForm),YysDeviceWarnForm.class); + generaterSwapUtil.swapDatetime(YysDeviceWarnConstant.getFormData(), yysDeviceWarnForm), YysDeviceWarnForm.class); YysDeviceWarnEntity entity = JsonUtil.getJsonToBean(yysDeviceWarnForm, YysDeviceWarnEntity.class); - if(isSave){ - String mainId = RandomUtil.uuId() ; + if (isSave) { + String mainId = RandomUtil.uuId(); entity.setId(mainId); - }else{ + } else { } this.saveOrUpdate(entity); } + + @Override + public void syncCount(List collect) { + if (CollectionUtils.isEmpty(collect)) { + return; + } + Map> collect1 = collect + .stream().collect(Collectors.groupingBy(entity -> String.join("-", entity.getDeviceName(), entity.getWarnType(), entity.getWarnDetails()))); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(YysDeviceWarnEntity.class); + wrapper.isNull(YysDeviceWarnEntity::getDeleteMark); + List list = this.list(wrapper); + if (CollectionUtils.isEmpty(list)) { + List result = Lists.newArrayList(); + for (Map.Entry> entry : collect1.entrySet()) { + String mainId = RandomUtil.uuId(); + YysDeviceWarnStatisticsEntity entity1 = entry.getValue().get(0); + YysDeviceWarnEntity entity = new YysDeviceWarnEntity(); + entity.setId(mainId); + entity.setProductionLine(entity1.getDeviceName()); + entity.setProductionTime(entity1.getProductionTime()); + entity.setWarnName(entity1.getWarnType()); + entity.setWarnDetails(entity1.getWarnDetails()); + entity.setWarnNums(String.valueOf(entry.getValue().size())); + entity.setCreatorUserId(userProvider.get().getUserId()); + entity.setCreatorTime(DateUtil.getNowDate()); + result.add(entity); + } + this.saveBatch(result); + } else { + for (YysDeviceWarnEntity entity : list) { + String key = String.join("-", entity.getProductionLine(), entity.getWarnName(), entity.getWarnDetails()); + if (collect1.containsKey(key)) { + entity.setWarnNums(String.valueOf(Integer.parseInt(entity.getWarnNums()) + collect1.get(key).size())); + } else { + List entities = collect1.get(key); + String mainId = RandomUtil.uuId(); + YysDeviceWarnStatisticsEntity entity2 = entities.get(0); + YysDeviceWarnEntity entity3 = new YysDeviceWarnEntity(); + entity3.setId(mainId); + entity3.setProductionLine(entity2.getDeviceName()); + entity3.setProductionTime(entity2.getProductionTime()); + entity3.setWarnName(entity2.getWarnType()); + entity3.setWarnDetails(entity2.getWarnDetails()); + entity3.setWarnNums(String.valueOf(entities.size())); + entity3.setCreatorUserId(userProvider.get().getUserId()); + entity3.setCreatorTime(DateUtil.getNowDate()); + list.add(entity); + } + } + this.saveOrUpdateBatch(list); + } + } } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnStatisticsServiceImpl.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnStatisticsServiceImpl.java index 98ce48c..f9f46c3 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnStatisticsServiceImpl.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/impl/YysDeviceWarnStatisticsServiceImpl.java @@ -1,23 +1,37 @@ package jnpf.service.impl; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.google.common.collect.Lists; import jnpf.entity.*; import jnpf.mapper.YysDeviceWarnStatisticsMapper; import jnpf.service.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import jnpf.model.yysdevicewarnstatistics.*; + import java.math.BigDecimal; + import cn.hutool.core.util.ObjectUtil; import jnpf.permission.model.authorize.AuthorizeConditionModel; import jnpf.util.GeneraterSwapUtil; import jnpf.database.model.superQuery.SuperQueryJsonModel; import jnpf.database.model.superQuery.ConditionJsonModel; import jnpf.database.model.superQuery.SuperQueryConditionModel; + import java.lang.reflect.Field; + import com.baomidou.mybatisplus.annotation.TableField; + import java.util.regex.Pattern; + import jnpf.model.QueryModel; + import java.util.stream.Collectors; + import jnpf.base.model.ColumnDataModel; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import jnpf.database.model.superQuery.SuperJsonModel; @@ -25,13 +39,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + import java.text.SimpleDateFormat; + import jnpf.util.*; + import java.util.*; + import jnpf.base.UserInfo; import jnpf.permission.entity.UserEntity; + /** - * * yysDeviceWarnStatistics * 版本: V3.5 * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com) @@ -39,242 +57,275 @@ import jnpf.permission.entity.UserEntity; * 日期: 2024-08-09 */ @Service -public class YysDeviceWarnStatisticsServiceImpl extends ServiceImpl implements YysDeviceWarnStatisticsService{ +public class YysDeviceWarnStatisticsServiceImpl extends ServiceImpl implements YysDeviceWarnStatisticsService { @Autowired private GeneraterSwapUtil generaterSwapUtil; + @Autowired + private JdbcTemplate jdbcTemplate; + @Autowired private UserProvider userProvider; @Override - public List getList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination){ - return getTypeList(yysDeviceWarnStatisticsPagination,yysDeviceWarnStatisticsPagination.getDataType()); + public List getList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination) { + return getTypeList(yysDeviceWarnStatisticsPagination, yysDeviceWarnStatisticsPagination.getDataType()); } - /** 列表查询 */ + + /** + * 列表查询 + */ @Override - public List getTypeList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination,String dataType){ - String userId=userProvider.get().getUserId(); - List AllIdList =new ArrayList(); - List> intersectionList =new ArrayList<>(); + public List getTypeList(YysDeviceWarnStatisticsPagination yysDeviceWarnStatisticsPagination, String dataType) { + String userId = userProvider.get().getUserId(); + List AllIdList = new ArrayList(); + List> intersectionList = new ArrayList<>(); boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc"); String columnData = !isPc ? YysDeviceWarnStatisticsConstant.getAppColumnData() : YysDeviceWarnStatisticsConstant.getColumnData(); ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class); String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList()); - int total=0; - int yysDeviceWarnStatisticsNum =0; - QueryWrapper yysDeviceWarnStatisticsQueryWrapper=new QueryWrapper<>(); + int total = 0; + int yysDeviceWarnStatisticsNum = 0; + QueryWrapper yysDeviceWarnStatisticsQueryWrapper = new QueryWrapper<>(); List allSuperIDlist = new ArrayList<>(); - String superOp =""; - if (ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getSuperQueryJson())){ + String superOp = ""; + if (ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getSuperQueryJson())) { List allSuperList = new ArrayList<>(); - List> intersectionSuperList = new ArrayList<>(); + List> intersectionSuperList = new ArrayList<>(); String queryJson = yysDeviceWarnStatisticsPagination.getSuperQueryJson(); SuperJsonModel superJsonModel = JsonUtil.getJsonToBean(queryJson, SuperJsonModel.class); int superNum = 0; QueryWrapper yysDeviceWarnStatisticsSuperWrapper = new QueryWrapper<>(); - yysDeviceWarnStatisticsSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnStatisticsSuperWrapper,YysDeviceWarnStatisticsEntity.class,queryJson,"0")); + yysDeviceWarnStatisticsSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnStatisticsSuperWrapper, YysDeviceWarnStatisticsEntity.class, queryJson, "0")); int yysDeviceWarnStatisticsNum1 = yysDeviceWarnStatisticsSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceWarnStatisticsNum1>0){ - List yysDeviceWarnStatisticsList =this.list(yysDeviceWarnStatisticsSuperWrapper).stream().map(YysDeviceWarnStatisticsEntity::getId).collect(Collectors.toList()); + if (yysDeviceWarnStatisticsNum1 > 0) { + List yysDeviceWarnStatisticsList = this.list(yysDeviceWarnStatisticsSuperWrapper).stream().map(YysDeviceWarnStatisticsEntity::getId).collect(Collectors.toList()); allSuperList.addAll(yysDeviceWarnStatisticsList); intersectionSuperList.add(yysDeviceWarnStatisticsList); superNum++; } superOp = superNum > 0 ? superJsonModel.getMatchLogic() : ""; //and or - if(superOp.equalsIgnoreCase("and")){ + if (superOp.equalsIgnoreCase("and")) { allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList); - }else{ + } else { allSuperIDlist = allSuperList; } } List allRuleIDlist = new ArrayList<>(); - String ruleOp =""; - if (ObjectUtil.isNotEmpty(ruleJson)){ + String ruleOp = ""; + if (ObjectUtil.isNotEmpty(ruleJson)) { List allRuleList = new ArrayList<>(); - List> intersectionRuleList = new ArrayList<>(); + List> intersectionRuleList = new ArrayList<>(); SuperJsonModel ruleJsonModel = JsonUtil.getJsonToBean(ruleJson, SuperJsonModel.class); int ruleNum = 0; QueryWrapper yysDeviceWarnStatisticsSuperWrapper = new QueryWrapper<>(); - yysDeviceWarnStatisticsSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnStatisticsSuperWrapper,YysDeviceWarnStatisticsEntity.class,ruleJson,"0")); + yysDeviceWarnStatisticsSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysDeviceWarnStatisticsSuperWrapper, YysDeviceWarnStatisticsEntity.class, ruleJson, "0")); int yysDeviceWarnStatisticsNum1 = yysDeviceWarnStatisticsSuperWrapper.getExpression().getNormal().size(); - if (yysDeviceWarnStatisticsNum1>0){ - List yysDeviceWarnStatisticsList =this.list(yysDeviceWarnStatisticsSuperWrapper).stream().map(YysDeviceWarnStatisticsEntity::getId).collect(Collectors.toList()); + if (yysDeviceWarnStatisticsNum1 > 0) { + List yysDeviceWarnStatisticsList = this.list(yysDeviceWarnStatisticsSuperWrapper).stream().map(YysDeviceWarnStatisticsEntity::getId).collect(Collectors.toList()); allRuleList.addAll(yysDeviceWarnStatisticsList); intersectionRuleList.add(yysDeviceWarnStatisticsList); ruleNum++; } ruleOp = ruleNum > 0 ? ruleJsonModel.getMatchLogic() : ""; //and or - if(ruleOp.equalsIgnoreCase("and")){ + if (ruleOp.equalsIgnoreCase("and")) { allRuleIDlist = generaterSwapUtil.getIntersection(intersectionRuleList); - }else{ + } else { allRuleIDlist = allRuleList; } } - boolean pcPermission = false; - boolean appPermission = false; - if(isPc && pcPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceWarnStatisticsObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnStatisticsQueryWrapper,YysDeviceWarnStatisticsEntity.class,yysDeviceWarnStatisticsPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceWarnStatisticsObj)){ - return new ArrayList<>(); - } else { - yysDeviceWarnStatisticsQueryWrapper = (QueryWrapper)yysDeviceWarnStatisticsObj; - if( yysDeviceWarnStatisticsQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceWarnStatisticsNum++; - } - } - } - } - if(!isPc && appPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysDeviceWarnStatisticsObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnStatisticsQueryWrapper,YysDeviceWarnStatisticsEntity.class,yysDeviceWarnStatisticsPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysDeviceWarnStatisticsObj)){ - return new ArrayList<>(); - } else { - yysDeviceWarnStatisticsQueryWrapper = (QueryWrapper)yysDeviceWarnStatisticsObj; - if( yysDeviceWarnStatisticsQueryWrapper.getExpression().getNormal().size()>0){ - yysDeviceWarnStatisticsNum++; - } + boolean pcPermission = false; + boolean appPermission = false; + if (isPc && pcPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceWarnStatisticsObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnStatisticsQueryWrapper, YysDeviceWarnStatisticsEntity.class, yysDeviceWarnStatisticsPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceWarnStatisticsObj)) { + return new ArrayList<>(); + } else { + yysDeviceWarnStatisticsQueryWrapper = (QueryWrapper) yysDeviceWarnStatisticsObj; + if (yysDeviceWarnStatisticsQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceWarnStatisticsNum++; + } + } + } } + if (!isPc && appPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysDeviceWarnStatisticsObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysDeviceWarnStatisticsQueryWrapper, YysDeviceWarnStatisticsEntity.class, yysDeviceWarnStatisticsPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysDeviceWarnStatisticsObj)) { + return new ArrayList<>(); + } else { + yysDeviceWarnStatisticsQueryWrapper = (QueryWrapper) yysDeviceWarnStatisticsObj; + if (yysDeviceWarnStatisticsQueryWrapper.getExpression().getNormal().size() > 0) { + yysDeviceWarnStatisticsNum++; + } + } - } - } - if(isPc){ - if(ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getProductionLine())){ - yysDeviceWarnStatisticsNum++; + } + } + if (isPc) { + if (ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getProductionLine())) { + yysDeviceWarnStatisticsNum++; String value = yysDeviceWarnStatisticsPagination.getProductionLine() instanceof List ? - JsonUtil.getObjectToString(yysDeviceWarnStatisticsPagination.getProductionLine()) : - String.valueOf(yysDeviceWarnStatisticsPagination.getProductionLine()); - yysDeviceWarnStatisticsQueryWrapper.lambda().like(YysDeviceWarnStatisticsEntity::getProductionLine,value); + JsonUtil.getObjectToString(yysDeviceWarnStatisticsPagination.getProductionLine()) : + String.valueOf(yysDeviceWarnStatisticsPagination.getProductionLine()); + yysDeviceWarnStatisticsQueryWrapper.lambda().like(YysDeviceWarnStatisticsEntity::getProductionLine, value); } - if(ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getCreatTime())){ - yysDeviceWarnStatisticsNum++; + if (ObjectUtil.isNotEmpty(yysDeviceWarnStatisticsPagination.getCreatTime())) { + yysDeviceWarnStatisticsNum++; - List CreatTimeList = JsonUtil.getJsonToList(yysDeviceWarnStatisticsPagination.getCreatTime(),String.class); - Long fir = Long.valueOf(String.valueOf(CreatTimeList.get(0))); - Long sec = Long.valueOf(String.valueOf(CreatTimeList.get(1))); + List CreatTimeList = JsonUtil.getJsonToList(yysDeviceWarnStatisticsPagination.getCreatTime(), String.class); + Long fir = Long.valueOf(String.valueOf(CreatTimeList.get(0))); + Long sec = Long.valueOf(String.valueOf(CreatTimeList.get(1))); - yysDeviceWarnStatisticsQueryWrapper.lambda().ge(YysDeviceWarnStatisticsEntity::getCreatTime, new Date(fir)) - .le(YysDeviceWarnStatisticsEntity::getCreatTime, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59")); + yysDeviceWarnStatisticsQueryWrapper.lambda().ge(YysDeviceWarnStatisticsEntity::getCreatTime, new Date(fir)) + .le(YysDeviceWarnStatisticsEntity::getCreatTime, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59")); } } List intersection = generaterSwapUtil.getIntersection(intersectionList); - if (total>0){ - if (intersection.size()==0){ + if (total > 0) { + if (intersection.size() == 0) { intersection.add("jnpfNullList"); } yysDeviceWarnStatisticsQueryWrapper.lambda().in(YysDeviceWarnStatisticsEntity::getId, intersection); } - //是否有高级查询 - if (StringUtil.isNotEmpty(superOp)){ - if (allSuperIDlist.size()==0){ + //是否有高级查询 + if (StringUtil.isNotEmpty(superOp)) { + if (allSuperIDlist.size() == 0) { allSuperIDlist.add("jnpfNullList"); } List finalAllSuperIDlist = allSuperIDlist; - yysDeviceWarnStatisticsQueryWrapper.lambda().and(t->t.in(YysDeviceWarnStatisticsEntity::getId, finalAllSuperIDlist)); + yysDeviceWarnStatisticsQueryWrapper.lambda().and(t -> t.in(YysDeviceWarnStatisticsEntity::getId, finalAllSuperIDlist)); } - //是否有数据过滤查询 - if (StringUtil.isNotEmpty(ruleOp)){ - if (allRuleIDlist.size()==0){ + //是否有数据过滤查询 + if (StringUtil.isNotEmpty(ruleOp)) { + if (allRuleIDlist.size() == 0) { allRuleIDlist.add("jnpfNullList"); } List finalAllRuleIDlist = allRuleIDlist; - yysDeviceWarnStatisticsQueryWrapper.lambda().and(t->t.in(YysDeviceWarnStatisticsEntity::getId, finalAllRuleIDlist)); + yysDeviceWarnStatisticsQueryWrapper.lambda().and(t -> t.in(YysDeviceWarnStatisticsEntity::getId, finalAllRuleIDlist)); } //排序 - if(StringUtil.isEmpty(yysDeviceWarnStatisticsPagination.getSidx())){ + if (StringUtil.isEmpty(yysDeviceWarnStatisticsPagination.getSidx())) { yysDeviceWarnStatisticsQueryWrapper.lambda().orderByDesc(YysDeviceWarnStatisticsEntity::getId); - }else{ + } else { try { String sidx = yysDeviceWarnStatisticsPagination.getSidx(); - String[] strs= sidx.split("_name"); + String[] strs = sidx.split("_name"); YysDeviceWarnStatisticsEntity yysDeviceWarnStatisticsEntity = new YysDeviceWarnStatisticsEntity(); Field declaredField = yysDeviceWarnStatisticsEntity.getClass().getDeclaredField(strs[0]); declaredField.setAccessible(true); String value = declaredField.getAnnotation(TableField.class).value(); - yysDeviceWarnStatisticsQueryWrapper="asc".equals(yysDeviceWarnStatisticsPagination.getSort().toLowerCase())?yysDeviceWarnStatisticsQueryWrapper.orderByAsc(value):yysDeviceWarnStatisticsQueryWrapper.orderByDesc(value); + yysDeviceWarnStatisticsQueryWrapper = "asc".equals(yysDeviceWarnStatisticsPagination.getSort().toLowerCase()) ? yysDeviceWarnStatisticsQueryWrapper.orderByAsc(value) : yysDeviceWarnStatisticsQueryWrapper.orderByDesc(value); } catch (NoSuchFieldException e) { e.printStackTrace(); } } - if("0".equals(dataType)){ - if((total>0 && AllIdList.size()>0) || total==0){ - Page page=new Page<>(yysDeviceWarnStatisticsPagination.getCurrentPage(), yysDeviceWarnStatisticsPagination.getPageSize()); - IPage userIPage=this.page(page, yysDeviceWarnStatisticsQueryWrapper); - return yysDeviceWarnStatisticsPagination.setData(userIPage.getRecords(),userIPage.getTotal()); - }else{ + if ("0".equals(dataType)) { + if ((total > 0 && AllIdList.size() > 0) || total == 0) { + Page page = new Page<>(yysDeviceWarnStatisticsPagination.getCurrentPage(), yysDeviceWarnStatisticsPagination.getPageSize()); + IPage userIPage = this.page(page, yysDeviceWarnStatisticsQueryWrapper); + return yysDeviceWarnStatisticsPagination.setData(userIPage.getRecords(), userIPage.getTotal()); + } else { List list = new ArrayList(); return yysDeviceWarnStatisticsPagination.setData(list, list.size()); } - }else{ + } else { return this.list(yysDeviceWarnStatisticsQueryWrapper); } } + @Override - public YysDeviceWarnStatisticsEntity getInfo(String id){ - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(YysDeviceWarnStatisticsEntity::getId,id); + public YysDeviceWarnStatisticsEntity getInfo(String id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(YysDeviceWarnStatisticsEntity::getId, id); return this.getOne(queryWrapper); } + @Override - public void create(YysDeviceWarnStatisticsEntity entity){ + public void create(YysDeviceWarnStatisticsEntity entity) { this.save(entity); } + @Override - public boolean update(String id, YysDeviceWarnStatisticsEntity entity){ + public boolean update(String id, YysDeviceWarnStatisticsEntity entity) { return this.updateById(entity); } + @Override - public void delete(YysDeviceWarnStatisticsEntity entity){ - if(entity!=null){ + public void delete(YysDeviceWarnStatisticsEntity entity) { + if (entity != null) { this.removeById(entity.getId()); } } - /** 验证表单唯一字段,正则,非空 i-0新增-1修改*/ + + /** + * 验证表单唯一字段,正则,非空 i-0新增-1修改 + */ @Override - public String checkForm(YysDeviceWarnStatisticsForm form,int i) { - boolean isUp =StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); - String id=""; + public String checkForm(YysDeviceWarnStatisticsForm form, int i) { + boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); + String id = ""; String countRecover = ""; - if (isUp){ + if (isUp) { id = form.getId(); } //主表字段验证 return countRecover; } + /** - * 新增修改数据(事务回滚) - * @param id - * @param yysDeviceWarnStatisticsForm - * @return - */ + * 新增修改数据(事务回滚) + * + * @param id + * @param yysDeviceWarnStatisticsForm + * @return + */ @Override @Transactional - public void saveOrUpdate(YysDeviceWarnStatisticsForm yysDeviceWarnStatisticsForm,String id, boolean isSave) throws Exception{ - UserInfo userInfo=userProvider.get(); + public void saveOrUpdate(YysDeviceWarnStatisticsForm yysDeviceWarnStatisticsForm, String id, boolean isSave) throws Exception { + UserInfo userInfo = userProvider.get(); UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId()); yysDeviceWarnStatisticsForm = JsonUtil.getJsonToBean( - generaterSwapUtil.swapDatetime(YysDeviceWarnStatisticsConstant.getFormData(),yysDeviceWarnStatisticsForm),YysDeviceWarnStatisticsForm.class); + generaterSwapUtil.swapDatetime(YysDeviceWarnStatisticsConstant.getFormData(), yysDeviceWarnStatisticsForm), YysDeviceWarnStatisticsForm.class); YysDeviceWarnStatisticsEntity entity = JsonUtil.getJsonToBean(yysDeviceWarnStatisticsForm, YysDeviceWarnStatisticsEntity.class); - if(isSave){ - String mainId = RandomUtil.uuId() ; + if (isSave) { + String mainId = RandomUtil.uuId(); entity.setId(mainId); - }else{ + } else { } this.saveOrUpdate(entity); } + + @Override + @DS("slave_1") + public List syncData(List syncIds) { + List result = Lists.newArrayList(); + String[] lines = new String[]{"1", "2", "3", "4"}; + for (String line : lines) { + String childTable = "eqmt_collect_data_sc_" + line; + String sql = "select b.*," + line + " as line from " + childTable + " a left join eqmt_collect_except_master b on a.eqmt_id = b.eqmt_id"; + RowMapper rowMapper = new BeanPropertyRowMapper<>(EqmtCollectExceptMasterEntity.class); + result.addAll(this.jdbcTemplate.query(sql, rowMapper)); + } + if (CollectionUtils.isEmpty(syncIds)) { + return result; + } + //过滤出已经生成的 + return result.stream().filter(obj -> !syncIds.contains(obj.getId())).collect(Collectors.toList()); + } } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectExceptMasterEntity.java b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectExceptMasterEntity.java new file mode 100644 index 0000000..5e902d3 --- /dev/null +++ b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectExceptMasterEntity.java @@ -0,0 +1,24 @@ +package jnpf.entity; + +import lombok.Data; + +import java.util.Date; + +@Data +public class EqmtCollectExceptMasterEntity { + private Long id; + private Date gmtCreate; + private Date gmtModified; + private Long collectId; + private Long eqmtId; + private String exceptType; + private String exceptTypeName; + private String registorAddress; + private String exceptMessage; + private String createBy; + private Date createTime; + private String updateBy; + private Date updateTime; + private String sysOrgCode; + private String line; +} diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectPubDataEntity.java b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectPubDataEntity.java new file mode 100644 index 0000000..4197f3e --- /dev/null +++ b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/EqmtCollectPubDataEntity.java @@ -0,0 +1,39 @@ +package jnpf.entity; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class EqmtCollectPubDataEntity { + private Long id; + private Long eqmtId; + private String productType; + private Double speed; + private Integer totalProductQty; + private Integer intradayProductQty; + private Integer intradayOkQty; + private Integer intradayNgQty; + private BigDecimal intradayYieldRate; + private Long intradayEqmtRunTime; + private Long intradayEqmtWorkTime; + private Double intradayEqmtWorkRate; + private Long intradayEqmtStopTime; + private Integer intradayEqmtStopTimes; + private String eqmtStatus; + private String eqmtExceptFlag; + private String eqmtAlarmFlag; + private Date gmtCreate; + private Long collectId; + private Date gmtModified; + private BigDecimal oee; + private String productTypeName; + private String createBy; + private Date createTime; + private String updateBy; + private Date updateTime; + private String sysOrgCode; + + private String line; +} diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceDataEntity.java b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceDataEntity.java index 44989e1..72057bc 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceDataEntity.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceDataEntity.java @@ -50,6 +50,8 @@ public class YysDeviceDataEntity { private String dayStopNum; @TableField(value = "OEE" , updateStrategy = FieldStrategy.IGNORED) private BigDecimal oee; + @TableField(value = "SYNCID" , updateStrategy = FieldStrategy.IGNORED) + private Long syncId; @TableField("F_CREATOR_TIME") private Date creatorTime; @TableField("F_CREATOR_USER_ID") diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceWarnStatisticsEntity.java b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceWarnStatisticsEntity.java index a97534c..c819a24 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceWarnStatisticsEntity.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-entity/src/main/java/jnpf/entity/YysDeviceWarnStatisticsEntity.java @@ -30,6 +30,8 @@ public class YysDeviceWarnStatisticsEntity { private String warnDetails; @TableField(value = "WARN_TYPE" , updateStrategy = FieldStrategy.IGNORED) private String warnType; + @TableField(value = "SYNCID" , updateStrategy = FieldStrategy.IGNORED) + private Long syncId; @TableField("F_CREATOR_TIME") private Date creatorTime; @TableField("F_CREATOR_USER_ID") diff --git a/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/pom.xml b/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/pom.xml index 5b16ed7..dd95d76 100644 --- a/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/pom.xml +++ b/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/pom.xml @@ -27,6 +27,11 @@ jnpf-system-biz ${project.version} + + com.jnpf + jnpf-example-biz + ${project.version} + \ No newline at end of file diff --git a/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/src/main/java/jnpf/scheduletask/task/YysTaskHandler.java b/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/src/main/java/jnpf/scheduletask/task/YysTaskHandler.java new file mode 100644 index 0000000..1163a12 --- /dev/null +++ b/jnpf-java-boot/jnpf-scheduletask/jnpf-scheduletask-biz/src/main/java/jnpf/scheduletask/task/YysTaskHandler.java @@ -0,0 +1,111 @@ +package jnpf.scheduletask.task; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.xxl.job.core.handler.annotation.XxlJob; +import jnpf.entity.EqmtCollectExceptMasterEntity; +import jnpf.entity.EqmtCollectPubDataEntity; +import jnpf.entity.YysDeviceDataEntity; +import jnpf.entity.YysDeviceWarnStatisticsEntity; +import jnpf.service.YysDeviceDataService; +import jnpf.service.YysDeviceWarnService; +import jnpf.service.YysDeviceWarnStatisticsService; +import jnpf.util.DateUtil; +import jnpf.util.RandomUtil; +import jnpf.util.UserProvider; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@Component +public class YysTaskHandler { + + @Resource + private YysDeviceDataService yysDeviceDataService; + + @Resource + private YysDeviceWarnStatisticsService yysDeviceWarnStatisticsService; + + @Resource + private YysDeviceWarnService yysDeviceWarnService; + + @Autowired + private UserProvider userProvider; + + //每十分钟执行一次 + @XxlJob("syncDeviceData") + public void syncDeviceData() { + //查询表中数据 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(YysDeviceDataEntity.class); + wrapper.isNull(YysDeviceDataEntity::getDeleteMark); + List list1 = yysDeviceDataService.list(wrapper); + List list = yysDeviceDataService.syncData(list1.stream().map(YysDeviceDataEntity::getSyncId).collect(Collectors.toList())); + if (CollectionUtils.isEmpty(list)) { + return; + } + List collect = list.stream().map(obj -> { + String mainId = RandomUtil.uuId(); + YysDeviceDataEntity entity = new YysDeviceDataEntity(); + entity.setId(mainId); + entity.setProductionLine(obj.getLine()); + entity.setProductionTime(obj.getGmtCreate()); + entity.setCreatorTime(obj.getCreateTime()); + entity.setProductionModels(obj.getProductType()); + entity.setProductionName(obj.getProductTypeName()); + entity.setProductionSpeed(String.valueOf(obj.getSpeed())); + entity.setProductionNum(String.valueOf(obj.getTotalProductQty())); + entity.setDayNum(String.valueOf(obj.getIntradayProductQty())); + entity.setDayQualifiedNum(String.valueOf(obj.getIntradayOkQty())); + entity.setDayBadNum(String.valueOf(obj.getIntradayNgQty())); + entity.setDayPassRate(obj.getIntradayYieldRate()); + entity.setDayOnTime(String.valueOf(obj.getIntradayEqmtRunTime())); + entity.setDayLoadingTime(String.valueOf(obj.getIntradayEqmtWorkTime())); + entity.setDayStopTime(String.valueOf(obj.getIntradayEqmtStopTime())); + entity.setDayStopNum(String.valueOf(obj.getIntradayEqmtStopTimes())); + entity.setOee(obj.getOee()); + entity.setSyncId(obj.getId()); + entity.setCreatorUserId(userProvider.get().getUserId()); + return entity; + }).collect(Collectors.toList()); + //批量存储 + yysDeviceDataService.saveBatch(collect); + } + + + //每十分钟执行一次 + @XxlJob("syncDeviceWarnData") + public void syncDeviceWarnData() { + //查询表中数据 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(YysDeviceWarnStatisticsEntity.class); + wrapper.isNull(YysDeviceWarnStatisticsEntity::getDeleteMark); + List list1 = yysDeviceWarnStatisticsService.list(wrapper); + List list = yysDeviceWarnStatisticsService.syncData(list1.stream().map(YysDeviceWarnStatisticsEntity::getSyncId).collect(Collectors.toList())); + if (CollectionUtils.isEmpty(list)) { + return; + } + List collect = list.stream().map(obj -> { + String mainId = RandomUtil.uuId(); + YysDeviceWarnStatisticsEntity entity = new YysDeviceWarnStatisticsEntity(); + entity.setId(mainId); + entity.setDeviceName(obj.getLine()); + entity.setProductionTime(obj.getGmtCreate()); + entity.setCreatorTime(obj.getCreateTime()); + entity.setRegisterAddress(obj.getRegistorAddress()); + entity.setWarnDetails(obj.getExceptMessage()); + entity.setWarnType(obj.getExceptTypeName()); + entity.setSyncId(obj.getId()); + entity.setCreatorUserId(userProvider.get().getUserId()); + return entity; + }).collect(Collectors.toList()); + //批量存储 + boolean result = yysDeviceWarnStatisticsService.saveBatch(collect); + //存储成功之后 统计数量 + if (result) { + CompletableFuture.runAsync(() -> yysDeviceWarnService.syncCount(collect)); + } + } +}