| | |
| | | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import io.swagger.annotations.Api; |
| | |
| | | */ |
| | | @ApiOperation(value = "干燥配方获取", notes = "干燥配方下发") |
| | | @GetMapping(value = "/queryFormula") |
| | | public Result<String> queryFormulaByEqpType(Integer tenantId, String eqpCode) throws JAXBException { |
| | | public Result<List<HerbFormulaVo>> queryFormulaByEqpType(Integer tenantId, String eqpCode) throws JAXBException { |
| | | //获取request |
| | | HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); |
| | | // 获取请求主机的IP地址 |
| | |
| | | queryWrapper.eq(DryHerbFormula::getEqpType, dryEquipment.getType()) |
| | | .eq(DryHerbFormula::getTenantId, tenantId); |
| | | List<DryHerbFormula> list = dryHerbFormulaService.list(queryWrapper); |
| | | Formulas formulas = new Formulas(); |
| | | |
| | | List<HerbFormulaVo> voList = new ArrayList<>(); |
| | | |
| | | list.forEach(item -> { |
| | | DryHerbInfo byId = dryHerbInfoService.getById(item.getHerbId()); |
| | | if (byId != null) { |
| | | item.setPinyin(byId.getPinyin()); |
| | | item.setName(byId.getName()); |
| | | } |
| | | Formula formula = new Formula(); |
| | | BaseParam baseParam = new BaseParam(); |
| | | WaterParam waterParam = new WaterParam(); |
| | | TypeParam typeParam = new TypeParam(); |
| | | OffsetParam offsetParam = new OffsetParam(); |
| | | baseParam.setCode(item.getCode()); |
| | | baseParam.setIndex(item.getCode()); |
| | | baseParam.setName(item.getName()); |
| | | baseParam.setAb(item.getName()); |
| | | baseParam.setTyp(item.getCategory()); |
| | | waterParam.setDelay(Double.valueOf(item.getDelay())); |
| | | waterParam.setMoisture3(item.getTarget()); |
| | | waterParam.setWeight1(Double.valueOf(item.getFeed())); |
| | | waterParam.setTimes(item.getEt()); |
| | | waterParam.setTemp1(item.getWindTemp()); |
| | | waterParam.setTemp2(item.getEnvTemp()); |
| | | waterParam.setTemp3(item.getEnvHum()); |
| | | waterParam.setTurntime(item.getTurn()); |
| | | typeParam.setMtype(Integer.valueOf(item.getCategory())); |
| | | offsetParam.setMoisoffset(item.getMoisOffset()); |
| | | offsetParam.setColdwind(Double.valueOf(item.getCoolingDuration())); |
| | | // DryHerbInfo byId = dryHerbInfoService.getById(item.getHerbId()); |
| | | // if (byId != null) { |
| | | // item.setPinyin(byId.getPinyin()); |
| | | // item.setName(byId.getName()); |
| | | // } |
| | | |
| | | formula.setBaseParam(baseParam); |
| | | formula.setWaterParam(waterParam); |
| | | formula.setTypeParam(typeParam); |
| | | formula.setOffsetParam(offsetParam); |
| | | formulas.getDryFormulaList().add(formula); |
| | | // Formula formula = new Formula(); |
| | | // BaseParam baseParam = new BaseParam(); |
| | | // WaterParam waterParam = new WaterParam(); |
| | | // TypeParam typeParam = new TypeParam(); |
| | | // OffsetParam offsetParam = new OffsetParam(); |
| | | // baseParam.setCode(item.getCode()); |
| | | // baseParam.setIndex(item.getCode()); |
| | | // baseParam.setName(item.getName()); |
| | | // baseParam.setAb(item.getName()); |
| | | // baseParam.setTyp(item.getCategory()); |
| | | // waterParam.setDelay(Double.valueOf(item.getDelay())); |
| | | // waterParam.setMoisture3(item.getTarget()); |
| | | // waterParam.setWeight1(Double.valueOf(item.getFeed())); |
| | | // waterParam.setTimes(item.getEt()); |
| | | // waterParam.setTemp1(item.getWindTemp()); |
| | | // waterParam.setTemp2(item.getEnvTemp()); |
| | | // waterParam.setTemp3(item.getEnvHum()); |
| | | // waterParam.setTurntime(item.getTurn()); |
| | | // typeParam.setMtype(Integer.valueOf(item.getCategory())); |
| | | // offsetParam.setMoisoffset(item.getMoisOffset()); |
| | | // offsetParam.setColdwind(Double.valueOf(item.getCoolingDuration())); |
| | | // |
| | | // formula.setBaseParam(baseParam); |
| | | // formula.setWaterParam(waterParam); |
| | | // formula.setTypeParam(typeParam); |
| | | // formula.setOffsetParam(offsetParam); |
| | | // formulas.getDryFormulaList().add(formula); |
| | | |
| | | HerbFormulaVo vo = new HerbFormulaVo(); |
| | | BeanUtil.copyProperties(item, vo); |
| | | voList.add(vo); |
| | | }); |
| | | // 把vos转换成xml |
| | | // 创建JAXBContext实例 |
| | | JAXBContext jaxbContext = JAXBContext.newInstance(Formulas.class); |
| | | // // 把vos转换成xml |
| | | // // 创建JAXBContext实例 |
| | | // JAXBContext jaxbContext = JAXBContext.newInstance(Formulas.class); |
| | | // |
| | | // // 创建Marshaller实例 |
| | | // Marshaller marshaller = jaxbContext.createMarshaller(); |
| | | // |
| | | // // 设置是否格式化输出 |
| | | // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); |
| | | // |
| | | // // 将对象序列化到字符串 |
| | | // StringWriter writer = new StringWriter(); |
| | | // marshaller.marshal(formulas, writer); |
| | | |
| | | // 创建Marshaller实例 |
| | | Marshaller marshaller = jaxbContext.createMarshaller(); |
| | | // String jsonString = JSONObject.toJSONString(voList); |
| | | // |
| | | // String json = JSON.toJSONString(voList); |
| | | // System.out.println(jsonString); |
| | | |
| | | // 设置是否格式化输出 |
| | | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); |
| | | |
| | | // 将对象序列化到字符串 |
| | | StringWriter writer = new StringWriter(); |
| | | marshaller.marshal(formulas, writer); |
| | | |
| | | return Result.OK("请求成功", writer.toString()); |
| | | return Result.OK("请求成功", voList); |
| | | |
| | | |
| | | } |