From 14192a0c7d0028d6251c4344cb6e789ebc48c4ca Mon Sep 17 00:00:00 2001 From: pengjie <17373303529@163.com> Date: Fri, 23 Aug 2024 15:34:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeatherController.java | 299 ++++++++++++++++++ .../modules/basicdata/entity/Weather.java | 95 ++++++ .../basicdata/mapper/WeatherMapper.java | 19 ++ .../basicdata/mapper/xml/WeatherMapper.xml | 5 + .../basicdata/service/IWeatherService.java | 14 + .../service/impl/WeatherServiceImpl.java | 19 ++ 6 files changed, 451 insertions(+) create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/controller/WeatherController.java create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/entity/Weather.java create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/WeatherMapper.java create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/xml/WeatherMapper.xml create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/service/IWeatherService.java create mode 100644 src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/WeatherServiceImpl.java diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/WeatherController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/WeatherController.java new file mode 100644 index 000000000..184eb001f --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/WeatherController.java @@ -0,0 +1,299 @@ +package com.zhgd.xmgl.modules.basicdata.controller; + +import cn.hutool.core.date.DateUtil; +import com.zhgd.annotation.OperLog; +import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; +import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; +import com.zhgd.xmgl.security.entity.UserInfo; +import com.zhgd.xmgl.security.util.SecurityUtils; +import com.zhgd.xmgl.util.PageUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.zhgd.jeecg.common.api.vo.Result; +import com.zhgd.jeecg.common.system.query.QueryGenerator; +import com.zhgd.jeecg.common.util.oConvertUtils; +import com.zhgd.xmgl.modules.basicdata.entity.Weather; +import com.zhgd.xmgl.modules.basicdata.service.IWeatherService; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.collections.MapUtils; +import org.jeecgframework.poi.excel.ExcelImportUtil; +import org.jeecgframework.poi.excel.def.NormalExcelConstants; +import org.jeecgframework.poi.excel.entity.ExportParams; +import org.jeecgframework.poi.excel.entity.ImportParams; +import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.servlet.ModelAndView; +import com.alibaba.fastjson.JSON; +import springfox.documentation.annotations.ApiIgnore; + + +/** + * @Title: Controller + * @Description: 天气信息 + * @author: pengj + * @date: 2024-08-23 + * @version: V1.0 + */ +@RestController +@RequestMapping("/xmgl/weather") +@Slf4j +@Api(tags = "天气信息管理") +public class WeatherController { + @Autowired + private IWeatherService weatherService; + + @Autowired + private ISystemUserService systemUserService; + + + @OperLog(operModul = "天气信息管理", operType = "查询最近一周的天气", operDesc = "查询最近一周的天气") + @ApiOperation(value = "查询天气-周", notes = "查询天气-周", httpMethod = "POST") + @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "body", dataType = "String") + @PostMapping(value = "/getWeatherData") + public Result> getWeatherData(@RequestBody Weather weather) { + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(weather); + queryWrapper.lambda().ge(Weather::getDate, new Date()); + queryWrapper.lambda().le(Weather::getDate, DateUtil.offsetDay(new Date(), 7)); + return Result.success(weatherService.list(queryWrapper)); + } + + /** + * 分页列表查询 + * + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "分页查询", operDesc = "分页列表查询天气信息信息") + @ApiOperation(value = " 分页列表查询天气信息信息", notes = "分页列表查询天气信息信息", httpMethod = "POST") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNo", value = "页数", paramType = "body", required = true, defaultValue = "1", dataType = "Integer"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "body", required = true, defaultValue = "10", dataType = "Integer") + }) + @PostMapping(value = "/page") + public Result> queryPageList(@ApiIgnore @RequestBody Map map) { + QueryWrapper queryWrapper = QueryGenerator.initPageQueryWrapper(Weather.class, map); + Page page = PageUtil.getPage(map); + IPage pageList = weatherService.page(page, queryWrapper); + return Result.success(pageList); + } + + /** + * 列表查询 + * + * @param weather + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "列表查询", operDesc = "列表查询天气信息信息") + @ApiOperation(value = " 列表查询天气信息信息", notes = "列表查询天气信息信息", httpMethod = "POST") + @PostMapping(value = "/list") + public Result> queryList(@RequestBody Weather weather) { + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(weather); + List list = weatherService.list(queryWrapper); + return Result.success(list); + } + + + /** + * 添加 + * + * @param weather + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "新增", operDesc = "添加天气信息信息") + @ApiOperation(value = " 添加天气信息信息", notes = "添加天气信息信息", httpMethod = "POST") + @PostMapping(value = "/add") + public Result add(@RequestBody Weather weather) { + weatherService.save(weather); + return Result.success("添加成功!"); + } + + /** + * 编辑 + * + * @param weather + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "修改", operDesc = "编辑天气信息信息") + @ApiOperation(value = "编辑天气信息信息", notes = "编辑天气信息信息", httpMethod = "POST") + @PostMapping(value = "/edit") + public Result edit(@RequestBody Weather weather) { + Result result = new Result(); + Weather weatherEntity = weatherService.getById(weather.getId()); + if (weatherEntity == null) { + result.error500("未找到对应实体"); + } else { + boolean ok = weatherService.updateById(weather); + if (ok) { + result.success("修改成功!"); + } else { + result.success("操作失败!"); + } + } + + return result; + } + + /** + * 通过id删除 + * + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "删除", operDesc = "删除天气信息信息") + @ApiOperation(value = "删除天气信息信息", notes = "删除天气信息信息", httpMethod = "POST") + @ApiImplicitParam(name = "id", value = "天气信息ID", paramType = "body", required = true, dataType = "Integer") + @PostMapping(value = "/delete") + public Result delete(@RequestBody Weather weather) { + Result result = new Result(); + Weather weatherEntity = weatherService.getById(weather.getId()); + if (weatherEntity == null) { + result.error500("未找到对应实体"); + } else { + boolean ok = weatherService.removeById(weather.getId()); + if (ok) { + result.success("删除成功!"); + } else { + result.success("操作失败!"); + } + } + return result; + } + + /** + * 批量删除 + * + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "批量删除", operDesc = "批量删除天气信息信息") + @ApiOperation(value = "批量删除天气信息信息", notes = "批量删除天气信息信息", httpMethod = "POST") + @ApiImplicitParam(name = "ids", value = "天气信息ID字符串", paramType = "body", required = true, dataType = "String") + @PostMapping(value = "/deleteBatch") + public Result deleteBatch(@ApiIgnore @RequestBody Map map) { + Result result = new Result(); + String ids = MapUtils.getString(map, "ids"); + if (ids == null || "".equals(ids.trim())) { + result.error500("参数不识别!"); + } else { + this.weatherService.removeByIds(Arrays.asList(ids.split(","))); + result.success("删除成功!"); + } + return result; + } + + /** + * 通过id查询 + * + * @return + */ + @OperLog(operModul = "天气信息管理", operType = "查询", operDesc = "通过id查询天气信息信息") + @ApiOperation(value = "通过id查询天气信息信息", notes = "通过id查询天气信息信息", httpMethod = "POST") + @ApiImplicitParam(name = "id", value = "天气信息ID", paramType = "body", required = true, dataType = "Integer") + @PostMapping(value = "/queryById") + public Result queryById(@ApiIgnore @RequestBody Map map) { + Result result = new Result(); + Weather weather = weatherService.getById(MapUtils.getString(map, "id")); + if (weather == null) { + result.error500("未找到对应实体"); + } else { + result.setResult(weather); + result.setSuccess(true); + } + return result; + } + + /** + * 导出excel + * + * @param request + * @param response + */ + @ApiOperation(value = "导出excel天气信息信息", notes = "导出excel天气信息信息", httpMethod = "POST") + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) { + // Step.1 组装查询条件 + QueryWrapper queryWrapper = null; + try { + String paramsStr = request.getParameter("paramsStr"); + if (oConvertUtils.isNotEmpty(paramsStr)) { + String deString = URLDecoder.decode(paramsStr, "UTF-8"); + Weather weather = JSON.parseObject(deString, Weather.class); + queryWrapper = QueryGenerator.initQueryWrapper(weather, request.getParameterMap()); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + //Step.2 AutoPoi 导出Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + List pageList = weatherService.list(queryWrapper); + //导出文件名称 + mv.addObject(NormalExcelConstants.FILE_NAME, "天气信息列表"); + mv.addObject(NormalExcelConstants.CLASS, Weather.class); + mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("天气信息列表数据", "导出人:Jeecg", "导出信息")); + mv.addObject(NormalExcelConstants.DATA_LIST, pageList); + return mv; + } + + /** + * 通过excel导入数据 + * + * @param request + * @param response + * @return + */ + @ApiOperation(value = "通过excel导入天气信息信息", notes = "通过excel导入天气信息信息", httpMethod = "POST") + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) + public Result importExcel(HttpServletRequest request, HttpServletResponse response) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + UserInfo user = SecurityUtils.getUser(); + SystemUser systemUser = systemUserService.getById(user.getUserId()); + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue();// 获取上传文件对象 + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setNeedSave(true); + try { + List listWeathers = ExcelImportUtil.importExcel(file.getInputStream(), Weather.class, params); + for (Weather weatherExcel : listWeathers) { + weatherExcel.setUpdateTime(new Date()); + weatherExcel.setProjectSn(systemUser.getSn()); + weatherService.save(weatherExcel); + } + return Result.ok("文件导入成功!数据行数:" + listWeathers.size()); + } catch (Exception e) { + log.error(e.getMessage()); + return Result.error("文件导入失败!"); + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return Result.ok("文件导入失败!"); + } + +} diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/Weather.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/Weather.java new file mode 100644 index 000000000..c97eb2dab --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/Weather.java @@ -0,0 +1,95 @@ +package com.zhgd.xmgl.modules.basicdata.entity; + +import java.io.Serializable; +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; +import org.jeecgframework.poi.excel.annotation.Excel; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @Description: 天气信息 + * @author: pengj + * @date: 2024-08-23 + * @version: V1.0 + */ +@Data +@TableName("weather") +@ApiModel(value = "Weather实体类", description = "Weather") +public class Weather implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 天气ID + */ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "天气ID") + private Long id; + /** + * 预报日期 + */ + @Excel(name = "预报日期", width = 15, format = "yyyy-MM-dd") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") + @DateTimeFormat(pattern = "yyyy-MM-dd") + @ApiModelProperty(value = "预报日期") + private Date date; + /** + * 白天温度(高温) + */ + @Excel(name = "白天温度(高温)", width = 15) + @ApiModelProperty(value = "白天温度(高温)") + private String temDay; + /** + * 城市名称 + */ + @Excel(name = "城市名称", width = 15) + @ApiModelProperty(value = "城市名称") + private String city; + /** + * 白天温度(低温) + */ + @Excel(name = "白天温度(低温)", width = 15) + @ApiModelProperty(value = "白天温度(低温)") + private String temNight; + /** + * 天气情况 + */ + @Excel(name = "天气情况", width = 15) + @ApiModelProperty(value = "天气情况") + private String wea; + /** + * 更新时间 + */ + @ApiModelProperty(value = "更新时间") + private Date updateTime; + /** + * 天气对应图标固定9种类型(您也可以根据wea字段自己处理): + * xue、lei、shachen、wu、bingbao、yun、yu、yin、qing + */ + @Excel(name = "天气对应图标固定9种类型", width = 15) + @ApiModelProperty(value = "天气对应图标固定9种类型(您也可以根据wea字段自己处理):xue、lei、shachen、wu、bingbao、yun、yu、yin、qing") + private String weaImg; + /** + * 风力等级 + */ + @Excel(name = "风力等级", width = 15) + @ApiModelProperty(value = "风力等级") + private Double winSpeed; + /** + * 风向 + */ + @Excel(name = "风向", width = 15) + @ApiModelProperty(value = "风向") + private String win; + /** + * 项目SN + */ + @ApiModelProperty(value = "项目SN") + private String projectSn; +} diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/WeatherMapper.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/WeatherMapper.java new file mode 100644 index 000000000..d6d940480 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/WeatherMapper.java @@ -0,0 +1,19 @@ +package com.zhgd.xmgl.modules.basicdata.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import com.zhgd.xmgl.modules.basicdata.entity.Weather; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * @Description: 天气信息 + * @author: pengj + * @date: 2024-08-23 + * @version: V1.0 + */ +@Mapper +public interface WeatherMapper extends BaseMapper { + +} diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/xml/WeatherMapper.xml b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/xml/WeatherMapper.xml new file mode 100644 index 000000000..3424d1fdc --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/xml/WeatherMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/service/IWeatherService.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/IWeatherService.java new file mode 100644 index 000000000..9d518ecad --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/IWeatherService.java @@ -0,0 +1,14 @@ +package com.zhgd.xmgl.modules.basicdata.service; + +import com.zhgd.xmgl.modules.basicdata.entity.Weather; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * @Description: 天气信息 + * @author: pengj + * @date: 2024-08-23 + * @version: V1.0 + */ +public interface IWeatherService extends IService { + +} diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/WeatherServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/WeatherServiceImpl.java new file mode 100644 index 000000000..ef3981c74 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/WeatherServiceImpl.java @@ -0,0 +1,19 @@ +package com.zhgd.xmgl.modules.basicdata.service.impl; + +import com.zhgd.xmgl.modules.basicdata.entity.Weather; +import com.zhgd.xmgl.modules.basicdata.mapper.WeatherMapper; +import com.zhgd.xmgl.modules.basicdata.service.IWeatherService; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +/** + * @Description: 天气信息 + * @author: pengj + * @date: 2024-08-23 + * @version: V1.0 + */ +@Service +public class WeatherServiceImpl extends ServiceImpl implements IWeatherService { + +}