From 34dd2e330668b59ab4e8130ed5099eab827647aa Mon Sep 17 00:00:00 2001 From: wangqiy <1530284170@qq.com> Date: Thu, 17 Apr 2025 16:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CultivationBreedingBaseController.java | 146 ++ base-common/pom.xml | 7 + .../core/controller/BaseController.java | 15 + .../agri/common/utils/DateReplaceUtil.java | 171 +++ .../java/com/agri/common/utils/Dateutil.java | 1259 +++++++++++++++++ .../agri/generator/util/VelocityUtils.java | 87 +- .../main/resources/vm/java/controller.java.vm | 93 +- .../src/main/resources/vm/java/dto.java.vm | 14 +- .../src/main/resources/vm/java/vo.java.vm | 3 - .../domain/CultivationBreedingBase.java | 118 ++ .../dto/CultivationBreedingBaseDto.java | 125 ++ .../domain/vo/CultivationBreedingBaseVo.java | 113 ++ .../mapper/CultivationBreedingBaseMapper.java | 17 + .../ICultivationBreedingBaseService.java | 22 + .../CultivationBreedingBaseServiceImpl.java | 44 + .../CultivationBreedingBaseMapper.xml | 327 +++++ 16 files changed, 2456 insertions(+), 105 deletions(-) create mode 100644 base-admin/src/main/java/com/agri/web/controller/business/CultivationBreedingBaseController.java create mode 100644 base-common/src/main/java/com/agri/common/utils/DateReplaceUtil.java create mode 100644 base-common/src/main/java/com/agri/common/utils/Dateutil.java create mode 100644 base-system/src/main/java/com/agri/business/domain/CultivationBreedingBase.java create mode 100644 base-system/src/main/java/com/agri/business/domain/dto/CultivationBreedingBaseDto.java create mode 100644 base-system/src/main/java/com/agri/business/domain/vo/CultivationBreedingBaseVo.java create mode 100644 base-system/src/main/java/com/agri/business/mapper/CultivationBreedingBaseMapper.java create mode 100644 base-system/src/main/java/com/agri/business/service/ICultivationBreedingBaseService.java create mode 100644 base-system/src/main/java/com/agri/business/service/impl/CultivationBreedingBaseServiceImpl.java create mode 100644 base-system/src/main/resources/mapper/business/CultivationBreedingBaseMapper.xml diff --git a/base-admin/src/main/java/com/agri/web/controller/business/CultivationBreedingBaseController.java b/base-admin/src/main/java/com/agri/web/controller/business/CultivationBreedingBaseController.java new file mode 100644 index 0000000..c07dfcc --- /dev/null +++ b/base-admin/src/main/java/com/agri/web/controller/business/CultivationBreedingBaseController.java @@ -0,0 +1,146 @@ +package com.agri.web.controller.business; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import cn.hutool.core.convert.Convert; +import com.agri.business.domain.dto.CultivationBreedingBaseDto; +import com.agri.common.utils.ApiUtils; +import com.agri.common.utils.DateReplaceUtil; +import com.agri.common.utils.bean.BeanUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.agri.common.annotation.Log; +import com.agri.common.core.controller.BaseController; +import com.agri.common.core.domain.AjaxResult; +import com.agri.common.enums.BusinessType; +import com.agri.business.domain.CultivationBreedingBase; +import com.agri.business.service.ICultivationBreedingBaseService; +import com.agri.common.utils.poi.ExcelUtil; +import com.agri.common.core.page.TableDataInfo; + +/** + * 种养殖基地Controller + * + * @author wqy + * @date 2025-04-17 + */ +@Api(tags = "种养殖基地") +@RestController +@RequestMapping(value = "/cultivationBreedingBase", produces = "application/json") +public class CultivationBreedingBaseController extends BaseController +{ + @Autowired + private ICultivationBreedingBaseService cultivationBreedingBaseService; + + /** + * 查询种养殖基地列表 + */ + @ApiOperation("查询种养殖基地列表") + @PreAuthorize("@ss.hasPermi('business:base:list')") + @GetMapping("/list") + public String list(CultivationBreedingBaseDto cultivationBreedingBaseDto) { + startPage(); + List list = getList(cultivationBreedingBaseDto, true); + return getApiDataTable(list); + } + + private List getList(CultivationBreedingBaseDto cultivationBreedingBaseDto, boolean isPage) { + if (isPage) { + startPage(); + } + Map params = new HashMap(); + params.put("createTimes", cultivationBreedingBaseDto.getCreateTimes()); + params.put("createTimee", cultivationBreedingBaseDto.getCreateTimee()); + DateReplaceUtil.spliceTime_00_00_00(params, "createTimes"); + DateReplaceUtil.spliceTime_23_59_59(params, "createTimee"); + List list = cultivationBreedingBaseService.findListByParam(params); + return list; + } + + /** + * 导出条件搜索出的种养殖基地数据列表 + */ + @PreAuthorize("@ss.hasPermi('business:base:export')") + @Log(title = "种养殖基地", businessType = BusinessType.EXPORT) + @PostMapping("/export") + @ApiOperation("导出") + public String export(CultivationBreedingBaseDto cultivationBreedingBaseDto) { + List list = getList(cultivationBreedingBaseDto, false); + cultivationBreedingBaseService.exportCultivationBreedingBaseExcel(list, 2); + return ApiUtils.success("操作成功,请到文件导出记录中下载"); + } + + /** + * 导出选中的种养殖基地数据列表 + */ + @PreAuthorize("@ss.hasPermi('business:base:exportSelected')") + @Log(title = "种养殖基地", businessType = BusinessType.EXPORT) + @PostMapping("/exportSelected") + @ApiOperation("导入") + public String exportSelected(@RequestBody List list) { + cultivationBreedingBaseService.exportCultivationBreedingBaseExcel(list, 2); + return ApiUtils.success("操作成功,请到文件导出记录中下载"); + } + + /** + * 获取种养殖基地详细信息 + */ + @ApiOperation("获取种养殖基地详细信息") + @PreAuthorize("@ss.hasPermi('business:base:query')") + @GetMapping(value = "/{id}") + public String getInfo(@PathVariable("id") Long id) { + return ApiUtils.successData(cultivationBreedingBaseService.find(id)); + } + + /** + * 新增种养殖基地 + */ + @ApiOperation("新增种养殖基地") + @PreAuthorize("@ss.hasPermi('business:base:add')") + @Log(title = "种养殖基地", businessType = BusinessType.INSERT) + @PostMapping + public String add(@RequestBody CultivationBreedingBaseDto cultivationBreedingBaseDto) { + CultivationBreedingBase cultivationBreedingBase = new CultivationBreedingBase(); + BeanUtils.copyProperties(cultivationBreedingBaseDto, cultivationBreedingBase); + cultivationBreedingBaseService.save(cultivationBreedingBase); + return ApiUtils.success(); + } + + /** + * 修改种养殖基地 + */ + @ApiOperation("修改种养殖基地") + @PreAuthorize("@ss.hasPermi('business:base:edit')") + @Log(title = "种养殖基地", businessType = BusinessType.UPDATE) + @PutMapping + public String edit(@RequestBody CultivationBreedingBaseDto cultivationBreedingBaseDto) { + CultivationBreedingBase cultivationBreedingBase = new CultivationBreedingBase(); + BeanUtils.copyProperties(cultivationBreedingBaseDto, cultivationBreedingBase); + cultivationBreedingBaseService.update(cultivationBreedingBase); + return ApiUtils.success(); + } + + /** + * 删除种养殖基地 + */ + @ApiOperation("删除种养殖基地") + @PreAuthorize("@ss.hasPermi('business:base:remove')") + @Log(title = "种养殖基地", businessType = BusinessType.DELETE) + @PostMapping( "/remove") + public String remove(String ids) { + Long rows = cultivationBreedingBaseService.deleteByIds(Convert.toLongArray(ids)); + return rows > 0 ? ApiUtils.success() : ApiUtils.error(); + } +} diff --git a/base-common/pom.xml b/base-common/pom.xml index 3771874..74c7b88 100644 --- a/base-common/pom.xml +++ b/base-common/pom.xml @@ -156,6 +156,13 @@ hutool-all 5.7.18 + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3.1 + \ No newline at end of file diff --git a/base-common/src/main/java/com/agri/common/core/controller/BaseController.java b/base-common/src/main/java/com/agri/common/core/controller/BaseController.java index f663817..f2f4e48 100644 --- a/base-common/src/main/java/com/agri/common/core/controller/BaseController.java +++ b/base-common/src/main/java/com/agri/common/core/controller/BaseController.java @@ -3,6 +3,9 @@ package com.agri.common.core.controller; import java.beans.PropertyEditorSupport; import java.util.Date; import java.util.List; + +import com.agri.common.utils.ApiUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.WebDataBinder; @@ -89,6 +92,18 @@ public class BaseController return rspData; } + /** + * 前后台分离,获取表格数据 + * @param list + * @return + */ + protected String getApiDataTable(List list) { + Page page = new Page(); + page.setRecords(list); + page.setTotal(list.size()); + return ApiUtils.successData(page); + } + /** * 返回成功 */ diff --git a/base-common/src/main/java/com/agri/common/utils/DateReplaceUtil.java b/base-common/src/main/java/com/agri/common/utils/DateReplaceUtil.java new file mode 100644 index 0000000..7bae460 --- /dev/null +++ b/base-common/src/main/java/com/agri/common/utils/DateReplaceUtil.java @@ -0,0 +1,171 @@ +package com.agri.common.utils; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.map.MapUtil; +import com.agri.common.exception.BusinessException; +import lombok.Data; + +import java.text.ParseException; +import java.util.Date; +import java.util.Map; + +@Data +public class DateReplaceUtil { + + private String paramKey; + private String startKey; + private String endKey; + + public static final String TIME_00_00_00 = " 00:00:00"; + + public static final String TIME_23_59_59 = " 23:59:59"; + + public DateReplaceUtil() {} + + public DateReplaceUtil(String paramKey, String startKey, String endKey) { + this.paramKey = paramKey; + this.startKey = startKey; + this.endKey = endKey; + } + + /** + * 把map中的参数替换为拼接 00:00:00的数据 + * @param paramMap + * @param key + */ + public static void spliceTime_00_00_00(Map paramMap, String key) { + if (StringUtils.isEmpty(key)) { + // throw new BusinessException("时间转化参数不能为空"); + return; + } + String value = MapUtil.getStr(paramMap, key); + if (StringUtils.isNotEmpty(value)) { + paramMap.put(key, value+TIME_00_00_00); + } + } + + /** + * 把map中的参数替换为拼接 23:59:59的数据 + * @param paramMap + * @param key + */ + public static void spliceTime_23_59_59(Map paramMap, String key) { + if (StringUtils.isEmpty(key)) { + // throw new BusinessException("时间转化参数不能为空"); + return; + } + String value = MapUtil.getStr(paramMap, key); + if (StringUtils.isNotEmpty(value)) { + paramMap.put(key, value+TIME_23_59_59); + } + } + + + /** + * 把map中的参数替换为另一个起始时间段的数据, paramKey格式: 年-月-日 + * @param paramMap + * @param data + */ + public static void spliceTimeSection(Map paramMap, DateReplaceUtil data) { + if (StringUtils.isEmpty(data.getParamKey()) || StringUtils.isEmpty(data.getStartKey()) || StringUtils.isEmpty(data.getEndKey())) { + throw new BusinessException("时间转化参数不能为空"); + } + String value = MapUtil.getStr(paramMap, data.getParamKey()); + if (StringUtils.isNotEmpty(value)) { + paramMap.remove(data.getParamKey()); + paramMap.put(data.getStartKey(), value+TIME_00_00_00); + paramMap.put(data.getEndKey(), value+TIME_23_59_59); + } + } + + + /** + * 年-月-日格式拼接 00:00:00 + * @param time + * @return + */ + public static String addTime_00_00_00(String time) { + if (StringUtils.isEmpty(time)) { + throw new BusinessException("时间转化参数不能为空"); + } + return time + TIME_00_00_00; + } + + /** + * 年-月-日格式拼接 23:59:59 + * @param time + * @return + */ + public static String addTime_23_59_59(String time) { + if (StringUtils.isEmpty(time)) { + throw new BusinessException("时间转化参数不能为空"); + } + return time + TIME_23_59_59; + } + + + + /** + * 入参年-月 换成查询这个月的起止时间范围 + * 把map中的参数替换为另一个起始时间段的数据, paramKey格式: 年-月 + * @param paramMap + * @param data + */ + public static void spliceTimeYM(Map paramMap, DateReplaceUtil data) { + if (StringUtils.isEmpty(data.getParamKey()) || StringUtils.isEmpty(data.getStartKey()) || StringUtils.isEmpty(data.getEndKey())) { + throw new BusinessException("时间转化参数不能为空"); + } + try { + String value = MapUtil.getStr(paramMap, data.getParamKey()); + if (StringUtils.isNotEmpty(value)) { + String startTimeStr = value + "-01" + TIME_00_00_00; + Date startTime = Dateutil.dateParse(startTimeStr, Dateutil.DATE_TIME_PATTERN); + int daysOfMonth = Dateutil.getDaysOfMonth(startTime); + int month = Dateutil.getMonth(startTime); + int year = Dateutil.getYear(startTime); + String endTimeStr = year + "-" + (month < 10? "0"+month:month) + "-" + (daysOfMonth < 10? "0"+daysOfMonth:daysOfMonth) + TIME_23_59_59; + paramMap.remove(data.getParamKey()); + paramMap.put(data.getStartKey(), startTimeStr); + paramMap.put(data.getEndKey(), endTimeStr); + } + } catch (ParseException e) { + throw new BusinessException("格式错误"); + } + } + + /** + * @param map + * @param dateType 日期类型 1-今天(默认) 2-近七天 3-近半月 4-近一月 5-自定义时间范围 + * @param startTime 搜索开始时间(yyyy-MM-dd) + * @param endTime 搜索结束时间(yyyy-MM-dd) + */ + public static void dateParamAnalysis(Map map, Integer dateType, String startTime, String endTime) { + String data = DateUtil.format(new Date(), "yyyy-MM-dd 23:59:59"); + switch (dateType) { + case 2: + map.put("startTime", DateUtil.format(DateUtil.offsetDay(new Date(), -7), "yyyy-MM-dd 00:00:00")); + map.put("endTime", data); + break; + case 3: + map.put("startTime", DateUtil.format(DateUtil.offsetDay(new Date(), -15), "yyyy-MM-dd 00:00:00")); + map.put("endTime", data); + break; + case 4: + map.put("startTime", DateUtil.format(DateUtil.offsetDay(new Date(), -30), "yyyy-MM-dd 00:00:00")); + map.put("endTime", data); + break; + case 5: + if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { + throw new BusinessException("自定义时间参数错误"); + } + map.put("startTime", startTime + " 00:00:00"); + map.put("endTime", endTime + " 23:59:59"); + break; + default: + map.put("startTime", DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00")); + map.put("endTime", data); + break; + } + } + +} diff --git a/base-common/src/main/java/com/agri/common/utils/Dateutil.java b/base-common/src/main/java/com/agri/common/utils/Dateutil.java new file mode 100644 index 0000000..ec981c6 --- /dev/null +++ b/base-common/src/main/java/com/agri/common/utils/Dateutil.java @@ -0,0 +1,1259 @@ +package com.agri.common.utils; + +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.github.pagehelper.util.StringUtil; +import org.apache.commons.lang3.tuple.Pair; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; +import java.util.*; + + +public class Dateutil { + public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; + public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm"; + public static final String HOUR_PATTERN = "yyyy-MM-dd HH:mm:ss"; + public static final String DATE_PATTERN = "yyyy-MM-dd"; + public static final String DATE_PATTERN_2 = "yyyyMMdd"; + public static final String MONTH_PATTERN = "yyyy-MM"; + public static final String YEAR_PATTERN = "yyyy"; + public static final String dd = "dd"; + public static final String MINUTE_ONLY_PATTERN = "mm"; + public static final String HOUR_ONLY_PATTERN = "HH"; + public static final String HH_mm = "HH:mm"; + public static final String HH_mm_ss = "HH:mm:ss"; + public static final String MM_dd = "MM-dd"; + + /** + * 取得当前日期是多少周 + * + * @param date + * @return + */ + public static int getWeekOfYear(Date date) { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setMinimalDaysInFirstWeek(7); + c.setTime(date); + return c.get(Calendar.WEEK_OF_YEAR); + } + + /** + * 得到某一年周的总数 + * + * @param year + * @return + */ + public static int getMaxWeekNumOfYear(int year) { + Calendar c = new GregorianCalendar(); + c.set(year, Calendar.DECEMBER, 31, 23, 59, 59); + return getWeekOfYear(c.getTime()); + } + + /** + * 得到某年某周的第一天 + * + * @param year + * @param week + * @return + */ + public static Date getFirstDayOfWeek(int year, int week) { + Calendar c = new GregorianCalendar(); + c.set(Calendar.YEAR, year); + c.set(Calendar.MONTH, Calendar.JANUARY); + c.set(Calendar.DATE, 1); + Calendar cal = (GregorianCalendar) c.clone(); + cal.add(Calendar.DATE, week * 7); + return getFirstDayOfWeek(cal.getTime()); + } + + /** + * 得到某年某周的最后一天 + * + * @param year + * @param week + * @return + */ + public static Date getLastDayOfWeek(int year, int week) { + Calendar c = new GregorianCalendar(); + c.set(Calendar.YEAR, year); + c.set(Calendar.MONTH, Calendar.JANUARY); + c.set(Calendar.DATE, 1); + Calendar cal = (GregorianCalendar) c.clone(); + cal.add(Calendar.DATE, week * 7); + return getLastDayOfWeek(cal.getTime()); + } + + /** + * 取得指定日期所在周的第一天 + * + * @param date + * @return + */ + public static Date getFirstDayOfWeek(Date date) { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(date); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday + return c.getTime(); + } + + /** + * 取得指定日期所在周的最后一天 + * + * @param date + * @return + */ + public static Date getLastDayOfWeek(Date date) { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(date); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday + return c.getTime(); + } + + /** + * 取得当前日期所在周的第一天 + * + * @return + */ + public static Date getFirstDayOfWeek() { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(new Date()); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() - 1); // Monday + return c.getTime(); + } + + /** + * 取得当前日期所在周的最后一天 + * + * @return + */ + public static Date getLastDayOfWeek() { + Calendar c = new GregorianCalendar(); + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(new Date()); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday + return c.getTime(); + } + + public static String longTimeToString(Long time) { + if (null == time || time <= 0) { + return ""; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + //前面的lSysTime是秒数,先乘1000得到毫秒数,再转为java.util.Date类型 + Date date = new Date(time); + //Date date = new Date(); + //date.setTime(time); + +// Calendar cal = Calendar.getInstance(); +// cal.setTimeInMillis(time*1000); +// Date date = cal.getTime(); + String sDateTime = sdf.format(date); //得到精确到秒的表示:08/31/2006 21:08:00 + return sDateTime; + + } + + /** + * 获取当前时间 yyyyMMddHHmmss + * + * @return String + */ + public static String getCurrTime() { + Date now = new Date(); + SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String s = outFormat.format(now); + return s; + } + + /** + * 获取当前时间 yyyyMMddHHmmss + * + * @return String + */ + public static String getCurrDate() { + Date now = new Date(); + SimpleDateFormat outFormat = new SimpleDateFormat(DATE_TIME_PATTERN); + String s = outFormat.format(now); + return s; + } + + + /** + * 获取当前时间之后两个小时: yyyyMMddHHmmss + * + * @return String + */ + public static String getCurrTimeAfter() { + Date now = new Date(); + SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + Calendar ca = Calendar.getInstance(); + ca.setTime(now); + ca.add(Calendar.HOUR_OF_DAY, 2); + String s = outFormat.format(ca.getTime()); + return s; + } + + + /** + * 日期相加减天数 + * + * @param date 如果为Null,则为当前时间 + * @param days 加减天数 + * @param includeTime 是否包括时分秒,true表示包含 + * @return + * @throws ParseException + */ + public static Date dateAdd(Date date, int days, boolean includeTime) { + if (date == null) { + date = new Date(); + } + if (!includeTime) { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN); + try { + date = sdf.parse(sdf.format(date)); + } catch (ParseException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } + } + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.DATE, days); + return cal.getTime(); + } + + /** + * 时间格式化成字符串 + * + * @param date Date + * @param pattern StrUtils.DATE_TIME_PATTERN || StrUtils.DATE_PATTERN, 如果为空,则为yyyy-MM-dd + * @return + * @throws ParseException + */ + public static String dateFormat(Date date, String pattern) throws ParseException { + if (StringUtil.isEmpty(pattern)) { + pattern = DATE_PATTERN; + } + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return sdf.format(date); + } + + /** + * 字符串解析成时间对象 + * + * @param dateTimeString String + * @param pattern StrUtils.DATE_TIME_PATTERN || StrUtils.DATE_PATTERN,如果为空,则为yyyy-MM-dd + * @return + * @throws ParseException + */ + public static Date dateParse(String dateTimeString, String pattern) throws ParseException { + if (StringUtil.isEmpty(pattern)) { + pattern = DATE_PATTERN; + } + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return sdf.parse(dateTimeString); + } + + /** + * 将日期时间格式成只有日期的字符串(可以直接使用dateFormat,Pattern为Null进行格式化) + * + * @param dateTime Date + * @return + * @throws ParseException + */ + public static String dateTimeToDateString(Date dateTime) throws ParseException { + String dateTimeString = Dateutil.dateFormat(dateTime, DATE_TIME_PATTERN); + return dateTimeString.substring(0, 10); + } + + /** + * 当时、分、秒为00:00:00时,将日期时间格式成只有日期的字符串, + * 当时、分、秒不为00:00:00时,直接返回 + * + * @param dateTime Date + * @return + * @throws ParseException + */ + public static String dateTimeToDateStringIfTimeEndZero(Date dateTime) throws ParseException { + String dateTimeString = Dateutil.dateFormat(dateTime, DATE_TIME_PATTERN); + if (dateTimeString.endsWith("00:00:00")) { + return dateTimeString.substring(0, 10); + } else { + return dateTimeString; + } + } + + /** + * 将日期时间格式成日期对象,和dateParse互用 + * + * @param dateTime Date + * @return Date + * @throws ParseException + */ + public static Date dateTimeToDate(Date dateTime) throws ParseException { + Calendar cal = Calendar.getInstance(); + cal.setTime(dateTime); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + /** + * 时间加减小时 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param hours 加减的小时 + * @return Date + */ + public static Date dateAddHours(Date startDate, int hours) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.HOUR, c.get(Calendar.HOUR) + hours); + return c.getTime(); + } + + /** + * 时间加减分钟 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param minutes 加减的分钟 + * @return + */ + public static Date dateAddMinutes(Date startDate, int minutes) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + minutes); + return c.getTime(); + } + + /** + * 时间加减秒数 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param seconds 加减的秒数 + * @return + */ + public static Date dateAddSeconds(Date startDate, int seconds) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.SECOND, c.get(Calendar.SECOND) + seconds); + return c.getTime(); + } + + /** + * 时间加减天数 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param days 加减的天数 + * @return Date + */ + public static Date dateAddDays(Date startDate, int days) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.DATE, c.get(Calendar.DATE) + days); + return c.getTime(); + } + + /** + * 时间加减月数 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param months 加减的月数 + * @return Date + */ + public static Date dateAddMonths(Date startDate, int months) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.MONTH, c.get(Calendar.MONTH) + months); + return c.getTime(); + } + + /** + * 时间加减年数 + * + * @param startDate 要处理的时间,Null则为当前时间 + * @param years 加减的年数 + * @return Date + */ + public static Date dateAddYears(Date startDate, int years) { + if (startDate == null) { + startDate = new Date(); + } + Calendar c = Calendar.getInstance(); + c.setTime(startDate); + c.set(Calendar.YEAR, c.get(Calendar.YEAR) + years); + return c.getTime(); + } + + /** + * 时间比较(如果myDate>compareDate返回1,<返回-1,相等返回0) + * + * @param myDate 时间 + * @param compareDate 要比较的时间 + * @return int + */ + public static int dateCompare(Date myDate, Date compareDate) { + Calendar myCal = Calendar.getInstance(); + Calendar compareCal = Calendar.getInstance(); + myCal.setTime(myDate); + compareCal.setTime(compareDate); + return myCal.compareTo(compareCal); + } + + /** + * 获取两个时间中最小的一个时间 + * + * @param date + * @param compareDate + * @return + */ + public static Date dateMin(Date date, Date compareDate) { + if (date == null) { + return compareDate; + } + if (compareDate == null) { + return date; + } + if (1 == dateCompare(date, compareDate)) { + return compareDate; + } else if (-1 == dateCompare(date, compareDate)) { + return date; + } + return date; + } + + /** + * 获取两个时间中最大的一个时间 + * + * @param date + * @param compareDate + * @return + */ + public static Date dateMax(Date date, Date compareDate) { + if (date == null) { + return compareDate; + } + if (compareDate == null) { + return date; + } + if (1 == dateCompare(date, compareDate)) { + return date; + } else if (-1 == dateCompare(date, compareDate)) { + return compareDate; + } + return date; + } + + /** + * 获取两个日期(不含时分秒)相差的天数,不包含今天 + * + * @param startDate + * @param endDate + * @return + * @throws ParseException + */ + public static int dateBetween(Date startDate, Date endDate) throws ParseException { + Date dateStart = dateParse(dateFormat(startDate, DATE_PATTERN), DATE_PATTERN); + Date dateEnd = dateParse(dateFormat(endDate, DATE_PATTERN), DATE_PATTERN); + return (int) ((dateEnd.getTime() - dateStart.getTime()) / 1000 / 60 / 60 / 24); + } + + /** + * 获取两个日期(不含时分秒)相差的天数,包含今天 + * + * @param startDate + * @param endDate + * @return + * @throws ParseException + */ + public static int dateBetweenIncludeToday(Date startDate, Date endDate) throws ParseException { + return dateBetween(startDate, endDate) + 1; + } + + /** + * 获取日期时间的年份,如2017-02-13,返回2017 + * + * @param date + * @return + */ + public static int getYear(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.get(Calendar.YEAR); + } + + /** + * 获取日期时间的月份,如2017年2月13日,返回2 + * + * @param date + * @return + */ + public static int getMonth(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.get(Calendar.MONTH) + 1; + } + + /** + * 获取日期时间的第几天(即返回日期的dd),如2017-02-13,返回13 + * + * @param date + * @return + */ + public static int getDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.get(Calendar.DATE); + } + + /** + * 获取日期时间当月的总天数,如2017-02-13,返回28 + * + * @param date + * @return + */ + public static int getDaysOfMonth(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.getActualMaximum(Calendar.DATE); + } + + /** + * 获取日期时间当年的总天数,如2017-02-13,返回2017年的总天数 + * + * @param date + * @return + */ + public static int getDaysOfYear(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.getActualMaximum(Calendar.DAY_OF_YEAR); + } + + /** + * 根据时间获取当月最大的日期 + *
  • 2017-02-13,返回2017-02-28
  • + *
  • 2016-02-13,返回2016-02-29
  • + *
  • 2016-01-11,返回2016-01-31
  • + * + * @param date Date + * @return + * @throws Exception + */ + public static Date maxDateOfMonth(Date date) throws Exception { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int value = cal.getActualMaximum(Calendar.DATE); + return dateParse(dateFormat(date, MONTH_PATTERN) + "-" + value, null); + } + + /** + * 根据时间获取当月最小的日期,也就是返回当月的1号日期对象 + * + * @param date Date + * @return + * @throws Exception + */ + public static Date minDateOfMonth(Date date) throws Exception { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int value = cal.getActualMinimum(Calendar.DATE); + return dateParse(dateFormat(date, MONTH_PATTERN) + "-" + value, null); + } + + /** + * 获取昨天的日期时间 + * @return + * @throws Exception + */ + public static Date getYesterday() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, -1); + return cal.getTime(); + } + + + /** + * 判断时间是否超过今天 + * 超过 返回 true + * + * @return String + */ + public static boolean isTimeExpires(Date endDate) { + Calendar now = Calendar.getInstance(); + Calendar auditTime = Calendar.getInstance(); + + auditTime.clear(); + auditTime.setTime(endDate); + + if (auditTime.before(now)) { + return false; + + } + return true; + } + + /** + * 两时间相减取得分钟数 + * + * @param startTime + * @param endTime + * @return + */ + public static Long getMinuts(Date startTime, Date endTime) { + Long millisecond = endTime.getTime() - startTime.getTime(); + Long minuts = millisecond / ((long) 1000 * 60); + return minuts; + } + + /** + * 两时间相减取得分钟数 (返回小数类型) + * @param beginTime + * @param endTime + * @return + */ + public static BigDecimal calculateMinutes(Date beginTime, Date endTime){ + return new BigDecimal(endTime.getTime() - beginTime.getTime()).divide(new BigDecimal("60000"), 2, BigDecimal.ROUND_HALF_UP); + } + + /** + * 两时间相减取得秒 + * + * @param startTime + * @param endTime + * @return + */ + public static Long getSeconds(Date startTime, Date endTime) { + Long millisecond = endTime.getTime() - startTime.getTime(); + Long seconds = millisecond / ((long) 1000); + return seconds; + } + + /** + * 获取两个时间相差的月数 + * @param d1 + * @param d2 + * @return + */ + public static int getMonthDiff(Date d1, Date d2) { + Calendar c1 = Calendar.getInstance(); + Calendar c2 = Calendar.getInstance(); + c1.setTime(d1); + c2.setTime(d2); + int year1 = c1.get(Calendar.YEAR); + int year2 = c2.get(Calendar.YEAR); + int month1 = c1.get(Calendar.MONTH); + int month2 = c2.get(Calendar.MONTH); + int day1 = c1.get(Calendar.DAY_OF_MONTH); + int day2 = c2.get(Calendar.DAY_OF_MONTH); + // 获取年的差值 + int yearInterval = year1 - year2; + // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数 + if (month1 < month2 || month1 == month2 && day1 < day2) { + yearInterval--; + } + // 获取月数差值 + int monthInterval = (month1 + 12) - month2; + if (day1 < day2) { + monthInterval--; + } + monthInterval %= 12; + int monthsDiff = Math.abs(yearInterval * 12 + monthInterval); + return monthsDiff; + } + + + /** + * @param date + * @return + * @author hou + * @desc 显示消息推送时间 一天之内显示{时分} 一天前显示{昨天 时分} 超过一天显示{日期+时分} + */ + public static String getTimeStr(Date date) { + if (null == date) { + return ""; + } + String todySDF = "今天 HH:mm"; + String yesterDaySDF = "昨天 HH:mm"; + String otherSDF = "M月d日 HH:mm"; + SimpleDateFormat sfd = null; + String time = ""; + Calendar dateCalendar = Calendar.getInstance(); + dateCalendar.setTime(date); + Date now = new Date(); + Calendar targetCalendar = Calendar.getInstance(); + targetCalendar.setTime(now); + targetCalendar.set(Calendar.HOUR_OF_DAY, 0); + targetCalendar.set(Calendar.MINUTE, 0); + if (dateCalendar.after(targetCalendar)) { + sfd = new SimpleDateFormat(todySDF); + time = sfd.format(date); + return time; + } else { + targetCalendar.add(Calendar.DATE, -1); + if (dateCalendar.after(targetCalendar)) { + sfd = new SimpleDateFormat(yesterDaySDF); + time = sfd.format(date); + return time; + } + } + sfd = new SimpleDateFormat(otherSDF); + time = sfd.format(date); + + return time; + } + + /** + * @param date + * @return + * @author hou + * @desc 显示消息推送时间 一天之内显示{时分} 一天前显示{昨天 时分} 超过一天显示{日期+时分} + */ + public static String getTimeCustom(Date date) { + if (null == date) { + return ""; + } + String todySDF = "HH:mm"; + String yesterDaySDF = "昨天 HH:mm"; + String otherSDF = "yyyy-MM-dd HH:mm"; + SimpleDateFormat sfd = null; + String time = ""; + Calendar dateCalendar = Calendar.getInstance(); + dateCalendar.setTime(date); + Date now = new Date(); + Calendar targetCalendar = Calendar.getInstance(); + targetCalendar.setTime(now); + targetCalendar.set(Calendar.HOUR_OF_DAY, 0); + targetCalendar.set(Calendar.MINUTE, 0); + if (dateCalendar.after(targetCalendar)) { + sfd = new SimpleDateFormat(todySDF); + time = sfd.format(date); + return time; + } else { + targetCalendar.add(Calendar.DATE, -1); + if (dateCalendar.after(targetCalendar)) { + sfd = new SimpleDateFormat(yesterDaySDF); + time = sfd.format(date); + return time; + } + } + sfd = new SimpleDateFormat(otherSDF); + time = sfd.format(date); + + return time; + } + + + /** + * 日期加减月份 + * + * @return + */ + public static String monthAdd(Date date, int addMonth) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar c = new GregorianCalendar(); + c.setTime(new Date()); + c.add(Calendar.MONTH, addMonth); + Date m = c.getTime(); + String mon = format.format(m); + return mon; + } + + /** + * 日期加减(yyyy-MM-dd) 以年、月、日为单位, + * @param date 时间 + * @param type 单位 1-日、2-月、3-年 默认:1-日 + * @param addNum 加减的值 + * @return + */ + public static String timeAdd(String date, Integer type, Integer addNum) { + try { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN); + Calendar c = new GregorianCalendar(); + c.setTime(sdf.parse(date)); + if (null == addNum) { + addNum = 0; + } + if (null == type) { + c.set(Calendar.DATE, c.get(Calendar.DATE) + addNum); + } + if (1 == type) { + c.set(Calendar.DATE, c.get(Calendar.DATE) + addNum); + } else if (2 == type) { + c.add(Calendar.MONTH, addNum); + } else { + c.add(Calendar.YEAR, addNum); + } + Date m = c.getTime(); + return sdf.format(m); + } catch (Exception e){ + e.printStackTrace(); + return null; + } + } + + /** + * 计算2个日期(yyyy-MM-dd)之间相差的 以年、月、日为单位,计算结果是多少 (不包含开始当天) + * @param startDate 开始时间 + * @param endDate 结束时间 + * @param type 单位 1-日、2-月、3-年 默认:1-日 + * @return + */ + public static int timeDifference(String startDate, String endDate, Integer type) { + try { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN); + Date dateStart = sdf.parse(startDate); + Date dateEnd = sdf.parse(endDate); + Calendar from = Calendar.getInstance(); + from.setTime(dateStart); + Calendar to = Calendar.getInstance(); + to.setTime(dateEnd); + + if (null == type){ + return (int) ((to.getTimeInMillis() - from.getTimeInMillis()) / (24 * 3600 * 1000)); + } + if (1 == type) { + return (int) ((to.getTimeInMillis() - from.getTimeInMillis()) / (24 * 3600 * 1000)); + } else if (2 == type) { + int fromYear = from.get(Calendar.YEAR); + int fromMonth = from.get(Calendar.MONTH); + + int toYear = to.get(Calendar.YEAR); + int toMonth = to.get(Calendar.MONTH); + + return toYear * 12 + toMonth - (fromYear * 12 + fromMonth); + } else { + int fromYear = from.get(Calendar.YEAR); + + int toYear = to.get(Calendar.YEAR); + + return toYear - fromYear; + } + } catch (Exception e){ + e.printStackTrace(); + return -1; + } + } + + /** + * 获取指定时间所在季度的第一天(且是一天中最小时间) + * @param date + */ + public static Date getFristQuarterDay(Date date) throws ParseException { + /**设置初始值*/ + Calendar cal = Calendar.getInstance();; + cal.setTime(date); + int month = cal.get(cal.MONTH) + 1; + int quarter = 0; + //判断季度 + if (month >= 1 && month <= 3) { + quarter = 1; + } else if (month >= 4 && month <= 6) { + quarter = 2; + } else if (month >= 7 && month <= 9) { + quarter = 3; + } else { + quarter = 4; + } + String str = Dateutil.dateFormat(new Date(), Dateutil.YEAR_PATTERN); + String startDay = ""; + switch (quarter){ + case 1://第一季度 + startDay = str + "-01-01 00:00:00"; + break; + case 2://第二季度 + startDay = str + "-04-01 00:00:00"; + break; + case 3://第三季度 + startDay = str + "-07-01 00:00:00"; + break; + case 4://第四季度 + startDay = str + "-10-01 00:00:00"; + break; + } + return Dateutil.dateParse(startDay, Dateutil.DATE_TIME_PATTERN); + } + + /** + * 获取指定时间所在季度的最后一天(且是一天中最大时间) + * @param date + */ + public static Date getLastQuarterDay(Date date) throws ParseException { + /**设置初始值*/ + Calendar cal = Calendar.getInstance();; + cal.setTime(date); + int month = cal.get(cal.MONTH) + 1; + int quarter = 0; + //判断季度 + if (month >= 1 && month <= 3) { + quarter = 1; + } else if (month >= 4 && month <= 6) { + quarter = 2; + } else if (month >= 7 && month <= 9) { + quarter = 3; + } else { + quarter = 4; + } + String str = Dateutil.dateFormat(new Date(), Dateutil.YEAR_PATTERN); + String endDay = ""; + switch (quarter){ + case 1://第一季度 + endDay = str + "-03-31 23:59:59"; + break; + case 2://第二季度 + endDay = str + "-06-30 23:59:59"; + break; + case 3://第三季度 + endDay = str + "-09-30 23:59:59"; + break; + case 4://第四季度 + endDay = str + "-12-31 23:59:59"; + break; + } + return Dateutil.dateParse(endDay, Dateutil.DATE_TIME_PATTERN); + } + + /** + * 获取指定时间是星期几 + * 星期天返回的是7,返回值符合中国的周期 + * @param date + * @return + */ + public static int getWeekOfDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int w = cal.get(Calendar.DAY_OF_WEEK) - 1; + if(w == 0){ + w = 7;//星期天返回7 + } + return w; + } + + + /** + * 获取指定时间是星期几 + * 周 + * @param date + * @return + */ + public static String getWeekStrOfDate(Date date) { + String[] weekArr = new String[]{"周一", "周二", "周三","周四","周五","周六","周日"}; + return weekArr[getWeekOfDate(date) - 1]; + } + + + + /** + * 获取时间段内的所有天天 + * + * @param beginTime 开始时间 + * @param endTime 结束时间 + * @return / + */ + public static List getDays(String beginTime, String endTime) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date dBegin = null; + Date dEnd = null; + try { + dBegin = sdf.parse(beginTime); + dEnd = sdf.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + List daysStrList = new ArrayList(); + daysStrList.add(sdf.format(dBegin)); + Calendar calBegin = Calendar.getInstance(); + calBegin.setTime(dBegin); + Calendar calEnd = Calendar.getInstance(); + calEnd.setTime(dEnd); + while (dEnd.after(calBegin.getTime())) { + calBegin.add(Calendar.DAY_OF_MONTH, 1); + String dayStr = sdf.format(calBegin.getTime()); + daysStrList.add(dayStr); + } + return daysStrList; + } + + public static List getMonths(String beginTime, String endTime) { + Date startDate = null; + Date endDate = null; + try { + startDate = new SimpleDateFormat("yyyy-MM").parse(beginTime); + endDate = new SimpleDateFormat("yyyy-MM").parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + Calendar calendar = Calendar.getInstance(); + calendar.setTime(startDate); + // 获取开始年份和开始月份 + int startYear = calendar.get(Calendar.YEAR); + int startMonth = calendar.get(Calendar.MONTH); + // 获取结束年份和结束月份 + calendar.setTime(endDate); + int endYear = calendar.get(Calendar.YEAR); + int endMonth = calendar.get(Calendar.MONTH); + // + List list = new ArrayList(); + for (int i = startYear; i <= endYear; i++) { + String date = ""; + if (startYear == endYear) { + for (int j = startMonth; j <= endMonth; j++) { + if (j < 9) { + date = i + "-0" + (j + 1); + } else { + date = i + "-" + (j + 1); + } + list.add(date); + } + + } else { + if (i == startYear) { + for (int j = startMonth; j < 12; j++) { + if (j < 9) { + date = i + "-0" + (j + 1); + } else { + date = i + "-" + (j + 1); + } + list.add(date); + } + } else if (i == endYear) { + for (int j = 0; j <= endMonth; j++) { + if (j < 9) { + date = i + "-0" + (j + 1); + } else { + date = i + "-" + (j + 1); + } + list.add(date); + } + } else { + for (int j = 0; j < 12; j++) { + if (j < 9) { + date = i + "-0" + (j + 1); + } else { + date = i + "-" + (j + 1); + } + list.add(date); + } + } + + } + + } + return list; + } + + /** + * 时间格式化(传入的时间与当前时间比较) + * 一分钟以内的显示xx秒,一小时以内的显示xx分钟,24小时以内的显示xx小时,7天以内的显示x天前,超过7天的显示时期年-月-日 + * @param date + * @return + */ + public static String publishTime(Date date) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date now = new Date(); + long time = now.getTime() - date.getTime(); + long seconds = time / 1000; + long minutes = seconds / 60; + long hours = minutes / 60; + long days = hours / 24; + + if (seconds < 60) { + return String.format("%d秒前", seconds); + } else if (hours < 1) { + return String.format("%d分钟前", minutes); + } else if (hours < 24) { + return String.format("%d小时前", hours); + } else if (days < 7) { + return String.format("%d天前", days); + } else { + return dateFormat.format(date); + } + } + + /** + * 距离结束时间格式化 + * eg: 3天 22:20:56 + * @param endDate + * @return + */ + public static String rangeEndTime(Date endDate) { + Date nowDate = new Date(); + long diffInMillis = endDate.getTime() - nowDate.getTime(); + long days = diffInMillis / (24 * 60 * 60 * 1000); + long hours = (diffInMillis % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000); + long minutes = (diffInMillis % (60 * 60 * 1000)) / (60 * 1000); + long seconds = (diffInMillis % (60 * 1000)) / 1000; + String timeStr = hours + ":" + minutes + ":" + seconds; + if(days > 0){ + return String.format("%d天 " + timeStr, days); + } + return timeStr; + } + + /** + * 获取开始时间和结束时间 + * @param timeType 时间类型 + * @return 开始时间和结束时间 + */ + public static Pair genStartTimeAndEndTime(String timeType) { + DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate now = LocalDate.now(); + String startTime = ""; + String endTime = ""; + switch (timeType) { + case "today": + startTime = DateUtil.beginOfDay(new Date()).toString(); + endTime = DateUtil.now(); + break; + case "yesterday": + DateTime yesterday = DateUtil.yesterday(); + startTime = DateUtil.beginOfDay(yesterday).toString(); + endTime = DateUtil.endOfDay(yesterday).toString(); + break; + case "last7days": // 近七天 + startTime = now.minusDays(6).format(pattern); + endTime =now.format(pattern); + break; + case "thisWeek": + DateTime beginOfThisWeek = DateUtil.beginOfWeek(new Date()); + startTime = DateUtil.beginOfDay(beginOfThisWeek).toString(); + endTime = DateUtil.endOfDay(new Date()).toString(); + break; + case "lastWeek": + DateTime beginOfLastWeek = DateUtil.beginOfWeek(DateUtil.lastWeek()); + DateTime endOfLastWeek = DateUtil.endOfWeek(DateUtil.lastWeek()); + startTime = DateUtil.beginOfDay(beginOfLastWeek).toString(); + endTime = DateUtil.endOfDay(endOfLastWeek).toString(); + break; + case "thisMonth": + DateTime beginOfThisMonth = DateUtil.beginOfMonth(new Date()); + startTime = DateUtil.beginOfDay(beginOfThisMonth).toString(); + endTime = DateUtil.endOfDay(new Date()).toString(); + break; + case "lastMonth": + DateTime beginOfLastMonth = DateUtil.beginOfMonth(DateUtil.lastMonth()); + DateTime endOfLastMonth = DateUtil.endOfMonth(DateUtil.lastMonth()); + startTime = DateUtil.beginOfDay(beginOfLastMonth).toString(); + endTime = DateUtil.endOfDay(endOfLastMonth).toString(); + break; + case "thisQuarter": + DateTime beginOfQuarter = DateUtil.beginOfQuarter(new Date()); + startTime = DateUtil.beginOfDay(beginOfQuarter).toString(); + endTime = DateUtil.endOfDay(new Date()).toString(); + break; + case "lastQuarter": + // 获取本季度开始时间 + DateTime dateTime = DateUtil.offsetDay(DateUtil.beginOfQuarter(new Date()), -5); + startTime = DateUtil.beginOfDay(dateTime).toString(); + endTime = DateUtil.endOfDay(new Date()).toString(); + break; + case "thisYear": + startTime = DateUtil.beginOfYear(new Date()).toString(); + endTime = DateUtil.now(); + break; + case "lastYear": + DateTime lastYear = DateUtil.offset(new Date(), DateField.YEAR, -1); + startTime = DateUtil.beginOfYear(lastYear).toString(); + endTime = DateUtil.endOfYear(lastYear).toString(); + break; + case "all": + startTime = DateUtil.beginOfDay(DateUtil.parseDateTime("2023-01-01 00:00:00")).toString(); + endTime = DateUtil.now(); + break; + default: + break; + } + return Pair.of(startTime, endTime); + } + + + /** + * 获取开始日期和结束日期 + * @param type 1=今天,2=昨天,3=近七天 + * @return + */ + public static Pair getStartDateAndEndDate(Integer type){ + String startDate = ""; + String endDate = ""; + DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate now = LocalDate.now(); + switch (type){ + case 1: + startDate =now.format(pattern); + endDate = now.format(pattern); + break; + case 2: + LocalDate yesterday = now.minusDays(1); + startDate = yesterday.format(pattern); + endDate = yesterday.format(pattern); + break; + case 3: + startDate=now.minusDays(6).format(pattern); + endDate =now.format(pattern); + break; + } + + return Pair.of(startDate, endDate); + } + + public static Pair getStartAndEndTimeOfMonth(String month){ + month = month+"-01 00:00:00"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime time = LocalDateTime.parse(month, formatter); + LocalDateTime startDateTime = time.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN); + LocalDateTime endDateTime = time.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); + + String startTime = startDateTime.format(formatter); + String endTime = endDateTime.format(formatter); + + return Pair.of(startTime, endTime); + } + + /** + * 获取开始日期到结束日期直接的所有日期 + * @param startDate + * @param endDate + * @return + */ + public static List getMiddleDate(String startDate, String endDate) { + DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate start = LocalDate.parse(startDate, pattern); + LocalDate end = LocalDate.parse(endDate, pattern); + long length = end.toEpochDay() - start.toEpochDay(); + + ArrayList list = new ArrayList<>(); + for (long i = length; i >=0; i--) { + LocalDate localDate = end.minusDays(i); + list.add(localDate.format(pattern)); + } + return list; + } +} diff --git a/base-generator/src/main/java/com/agri/generator/util/VelocityUtils.java b/base-generator/src/main/java/com/agri/generator/util/VelocityUtils.java index 72f41b4..1576e10 100644 --- a/base-generator/src/main/java/com/agri/generator/util/VelocityUtils.java +++ b/base-generator/src/main/java/com/agri/generator/util/VelocityUtils.java @@ -193,26 +193,24 @@ public class VelocityUtils { templates.add("vm/java/service.java.vm"); templates.add("vm/java/serviceImpl.java.vm"); templates.add("vm/java/controller.java.vm"); - templates.add("vm/java/vo.java.vm"); +// templates.add("vm/java/vo.java.vm"); templates.add("vm/java/dto.java.vm"); - templates.add("vm/java/exportdto.java.vm"); +// templates.add("vm/java/exportdto.java.vm"); templates.add("vm/xml/mapper.xml.vm"); + templates.add("vm/js/api.js.vm"); if (GenConstants.TPL_CRUD.equals(tplCategory)) { - templates.add("vm/html/list.html.vm"); + templates.add("vm/vue/index.vue.vm"); } else if (GenConstants.TPL_TREE.equals(tplCategory)) { - templates.add("vm/html/tree.html.vm"); - templates.add("vm/html/list-tree.html.vm"); + templates.add("vm/vue/index-tree.vue.vm"); } else if (GenConstants.TPL_SUB.equals(tplCategory)) { - templates.add("vm/html/list.html.vm"); + templates.add("vm/vue/index.vue.vm"); templates.add("vm/java/sub-domain.java.vm"); } - templates.add("vm/html/add.html.vm"); - templates.add("vm/html/edit.html.vm"); templates.add("vm/sql/sql.vm"); return templates; } @@ -229,29 +227,6 @@ public class VelocityUtils { String packageName = genTable.getPackageName(); // 模块名 String moduleName = genTable.getModuleName(); -// boolean isSupplyBusiness = false; -// if (genTable.getTableName().startsWith("t_supply") || genTable.getTableName().startsWith("t_purchase")) { -// isSupplyBusiness = true; -// } -// if (isSupplyBusiness) { -// packageName = "com.shidian.supply"; -// } -// boolean isTeamBuy = false; -// if (genTable.getTableName().startsWith("t_team")) { -// isTeamBuy = true; -// } -// if (isTeamBuy) { -// packageName = "com.shidian.teambuy"; -// } -// // 是否是心选业务 -// boolean isXinxuan = false; -// if (genTable.getTableName().startsWith("t_xinxuan")) { -// isXinxuan = true; -// } -// if (isXinxuan) { -// packageName = "com.shidian.xinxuan"; -// moduleName = "xinxuan"; -// } // 大写类名 String className = genTable.getClassName(); @@ -260,21 +235,19 @@ public class VelocityUtils { String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); String mybatisPath = MYBATIS_PATH + "/" + moduleName; - String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName; +// String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName; + String vuePath = "vue"; if (template.equals("domain.java.vm")) { fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); -// if (isSupplyBusiness || isTeamBuy || isXinxuan) { -// fileName = StringUtils.format("{}/domain/entity/{}.java", javaPath, className); -// } + } + if (template.equals("dto.java.vm")){ + fileName = StringUtils.format("{}/domain/dto/{}Dto.java", javaPath, className); } if (template.equals("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) { fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); -// if (isSupplyBusiness || isTeamBuy || isXinxuan) { -// fileName = StringUtils.format("{}/domain/entity/{}.java", javaPath, genTable.getSubTable().getClassName()); -// } } else if (template.equals("mapper.java.vm")) { @@ -290,48 +263,24 @@ public class VelocityUtils { } else if (template.equals("controller.java.vm")) { - String controllerJavaPath = PROJECT_PATH + "/" + "com/shidian/web/controller/business"; -// if (isSupplyBusiness) { -// controllerJavaPath = PROJECT_PATH + "/" + "com/shidian/web/controller/business/supply"; -// } -// if (isTeamBuy) { -// controllerJavaPath = PROJECT_PATH + "/" + "com/shidian/web/controller/business/teambuy"; -// } -// if (isXinxuan) { -// controllerJavaPath = PROJECT_PATH + "/" + "com/shidian/web/controller/xinxuan"; -// } + String controllerJavaPath = PROJECT_PATH + "/" + "com/agri/web/controller/business"; fileName = StringUtils.format("{}/{}Controller.java", controllerJavaPath, className); } else if (template.equals("mapper.xml.vm")) { fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); -// if (isSupplyBusiness) { -// fileName = StringUtils.format("{}/{}Mapper.xml", "supply", className); -// } else if (isTeamBuy) { -// fileName = StringUtils.format("{}/{}Mapper.xml", "teambuy", className); -// } else if (isXinxuan) { -// fileName = StringUtils.format("{}/{}Mapper.xml", "xinxuan", className); -// } } - else if (template.equals("list.html.vm")) + else if (template.contains("api.js.vm")) { - fileName = StringUtils.format("{}/{}.html", htmlPath, businessName); + fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); } - else if (template.equals("list-tree.html.vm")) + else if (template.contains("index.vue.vm")) { - fileName = StringUtils.format("{}/{}.html", htmlPath, businessName); + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); } - else if (template.equals("tree.html.vm")) + else if (template.contains("index-tree.vue.vm")) { - fileName = StringUtils.format("{}/tree.html", htmlPath); - } - else if (template.equals("add.html.vm")) - { - fileName = StringUtils.format("{}/add.html", htmlPath); - } - else if (template.equals("edit.html.vm")) - { - fileName = StringUtils.format("{}/edit.html", htmlPath); + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); } else if (template.equals("sql.vm")) { diff --git a/base-generator/src/main/resources/vm/java/controller.java.vm b/base-generator/src/main/resources/vm/java/controller.java.vm index 225cebf..038376c 100644 --- a/base-generator/src/main/resources/vm/java/controller.java.vm +++ b/base-generator/src/main/resources/vm/java/controller.java.vm @@ -1,7 +1,14 @@ package ${packageName}.controller; +import java.util.HashMap; import java.util.List; -import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +import cn.hutool.core.convert.Convert; +import com.agri.business.domain.dto.CultivationBreedingBaseDto; +import com.agri.common.utils.ApiUtils; +import com.agri.common.utils.DateReplaceUtil; +import com.agri.common.utils.bean.BeanUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; @@ -32,9 +39,9 @@ import com.agri.common.core.page.TableDataInfo; * @author ${author} * @date ${datetime} */ -@Api(tags = "${moduleName}-${functionName}") +@Api(tags = "${functionName}") @RestController -@RequestMapping("/${moduleName}/${businessName}") +@RequestMapping(value = "/${className}", produces = "application/json") public class ${ClassName}Controller extends BaseController { @Autowired @@ -47,32 +54,55 @@ public class ${ClassName}Controller extends BaseController @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") @GetMapping("/list") #if($table.crud || $table.sub) - public TableDataInfo list(${ClassName} ${className}) - { + public String list(${ClassName}Dto ${className}Dto) { startPage(); - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - return getDataTable(list); + List<${ClassName}> list = getList(${className}Dto, true); + return getApiDataTable(list); } #elseif($table.tree) - public AjaxResult list(${ClassName} ${className}) + public AjaxResult list(${ClassName}Dto ${className}Dto) { - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - return AjaxResult.success(list); + List<${ClassName}> list = getList(${className}Dto, true); + return getApiDataTable(list); } #end + private List<${ClassName}> getList(${ClassName}Dto ${className}Dto, boolean isPage) { + if (isPage) { + startPage(); + } + Map params = new HashMap(); + params.put("createTimes", ${className}Dto.getCreateTimes()); + params.put("createTimee", ${className}Dto.getCreateTimee()); + DateReplaceUtil.spliceTime_00_00_00(params, "createTimes"); + DateReplaceUtil.spliceTime_23_59_59(params, "createTimee"); + List<${ClassName}> list = ${className}Service.findListByParam(params); + return list; + } + /** - * 导出${functionName}列表 + * 导出条件搜索出的${functionName}数据列表 */ - @ApiOperation("导出${functionName}列表") @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") @Log(title = "${functionName}", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, ${ClassName} ${className}) - { - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); - util.exportExcel(response, list, "${functionName}数据"); + @ApiOperation("导出") + public String export(${ClassName}Dto ${className}Dto) { + List<${ClassName}> list = getList(${className}Dto, false); + ${className}Service.export${ClassName}Excel(list, 2); + return ApiUtils.success("操作成功,请到文件导出记录中下载"); + } + + /** + * 导出选中的${functionName}数据列表 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:exportSelected')") + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) + @PostMapping("/exportSelected") + @ApiOperation("导入") + public String exportSelected(@RequestBody List<${ClassName}> list) { + ${className}Service.export${ClassName}Excel(list, 2); + return ApiUtils.success("操作成功,请到文件导出记录中下载"); } /** @@ -81,9 +111,8 @@ public class ${ClassName}Controller extends BaseController @ApiOperation("获取${functionName}详细信息") @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") @GetMapping(value = "/{${pkColumn.javaField}}") - public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) - { - return AjaxResult.success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField})); + public String getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) { + return ApiUtils.successData(${className}Service.find(${pkColumn.javaField})); } /** @@ -93,9 +122,11 @@ public class ${ClassName}Controller extends BaseController @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") @Log(title = "${functionName}", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody ${ClassName} ${className}) - { - return toAjax(${className}Service.insert${ClassName}(${className})); + public String add(@RequestBody ${ClassName}Dto ${className}Dto) { + ${ClassName} ${className} = new ${ClassName}(); + BeanUtils.copyProperties(${className}Dto, ${className}); + ${className}Service.save(${className}); + return ApiUtils.success(); } /** @@ -105,9 +136,11 @@ public class ${ClassName}Controller extends BaseController @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") @Log(title = "${functionName}", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody ${ClassName} ${className}) - { - return toAjax(${className}Service.update${ClassName}(${className})); + public String edit(@RequestBody ${ClassName}Dto ${className}Dto) { + ${ClassName} ${className} = new ${ClassName}(); + BeanUtils.copyProperties(${className}Dto, ${className}); + ${className}Service.update(${className}); + return ApiUtils.success(); } /** @@ -116,9 +149,9 @@ public class ${ClassName}Controller extends BaseController @ApiOperation("删除${functionName}") @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") @Log(title = "${functionName}", businessType = BusinessType.DELETE) - @DeleteMapping("/{${pkColumn.javaField}s}") - public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) - { - return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s)); + @PostMapping( "/remove") + public String remove(String ids) { + Long rows = ${className}Service.deleteByIds(Convert.toLongArray(ids)); + return rows > 0 ? ApiUtils.success() : ApiUtils.error(); } } diff --git a/base-generator/src/main/resources/vm/java/dto.java.vm b/base-generator/src/main/resources/vm/java/dto.java.vm index 5643c50..61d2733 100644 --- a/base-generator/src/main/resources/vm/java/dto.java.vm +++ b/base-generator/src/main/resources/vm/java/dto.java.vm @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.springframework.format.annotation.DateTimeFormat; /** * ${functionName} @@ -24,9 +25,6 @@ import io.swagger.annotations.ApiModelProperty; */ @Data -@NoArgsConstructor -@AllArgsConstructor -@TableName(value = "${tableName}" ) @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel(value = "${functionName}" , description = "${functionName}" ) public class ${ClassName}Dto implements Serializable { @@ -43,4 +41,14 @@ public class ${ClassName}Dto implements Serializable { #end #end + + /** 开始时间 */ + @ApiModelProperty(value = "开始时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimes; + + /** 结束时间 */ + @ApiModelProperty(value = "结束时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimee; } diff --git a/base-generator/src/main/resources/vm/java/vo.java.vm b/base-generator/src/main/resources/vm/java/vo.java.vm index 3ec6e5f..6d0d860 100644 --- a/base-generator/src/main/resources/vm/java/vo.java.vm +++ b/base-generator/src/main/resources/vm/java/vo.java.vm @@ -24,9 +24,6 @@ import io.swagger.annotations.ApiModelProperty; */ @Data -@NoArgsConstructor -@AllArgsConstructor -@TableName(value = "${tableName}") @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel(value = "${functionName}", description = "${functionName}") public class ${ClassName}Vo implements Serializable { diff --git a/base-system/src/main/java/com/agri/business/domain/CultivationBreedingBase.java b/base-system/src/main/java/com/agri/business/domain/CultivationBreedingBase.java new file mode 100644 index 0000000..dbee5a2 --- /dev/null +++ b/base-system/src/main/java/com/agri/business/domain/CultivationBreedingBase.java @@ -0,0 +1,118 @@ +package com.agri.business.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + import java.math.BigDecimal; +import java.io.Serializable; +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonInclude; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * 种养殖基地 + * + * @author wqy + * @date 2025-04-17 + */ + +@Data +@NoArgsConstructor +@AllArgsConstructor +@TableName(value = "t_cultivation_breeding_base") +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value="种养殖基地",description="种养殖基地") +public class CultivationBreedingBase implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 唯一标识每个基地的主键ID */ + @ApiModelProperty(value = "唯一标识每个基地的主键ID") + private Long id; + + /** 种养殖基地的名称 */ + @ApiModelProperty(value = "种养殖基地的名称") + private String baseName; + + /** 对应分类表中的ID */ + @ApiModelProperty(value = "对应分类表中的ID") + private Long categoryId; + + /** 基地类型(种植基地、养殖基地、综合基地) */ + @ApiModelProperty(value = "基地类型(种植基地、养殖基地、综合基地)") + private String baseType; + + /** 基地所在省份的行政区域编码 */ + @ApiModelProperty(value = "基地所在省份的行政区域编码") + private String provinceCode; + + /** 基地所在省份的名称 */ + @ApiModelProperty(value = "基地所在省份的名称") + private String provinceName; + + /** 基地所在市的行政区域编码 */ + @ApiModelProperty(value = "基地所在市的行政区域编码") + private String cityCode; + + /** 基地所在市的名称 */ + @ApiModelProperty(value = "基地所在市的名称") + private String cityName; + + /** 基地所在区/县的行政区域编码 */ + @ApiModelProperty(value = "基地所在区/县的行政区域编码") + private String districtCode; + + /** 基地所在区/县的名称 */ + @ApiModelProperty(value = "基地所在区/县的名称") + private String districtName; + + /** 种养殖基地的详细地址 */ + @ApiModelProperty(value = "种养殖基地的详细地址") + private String address; + + /** 基地的联系人姓名 */ + @ApiModelProperty(value = "基地的联系人姓名") + private String contactPerson; + + /** 基地的联系电话 */ + @ApiModelProperty(value = "基地的联系电话") + private String contactPhone; + + /** 对基地的详细描述,可为空 */ + @ApiModelProperty(value = "对基地的详细描述,可为空") + private String description; + + /** 种养殖基地的面积(单位:平方米) */ + @ApiModelProperty(value = "种养殖基地的面积(单位:平方米)") + private BigDecimal area; + + /** 面积单位 */ + @ApiModelProperty(value = "面积单位") + private String unit; + + /** 记录基地创建的时间 */ + @ApiModelProperty(value = "记录基地创建的时间") + private Date createdAt; + + /** 记录基地最后更新的时间 */ + @ApiModelProperty(value = "记录基地最后更新的时间") + private Date updatedAt; + + /** 1表示启用,0表示禁用 */ + @ApiModelProperty(value = "1表示启用,0表示禁用") + private Integer status; + + /** 地块ID */ + @ApiModelProperty(value = "地块ID") + private String landId; + + /** 地块名称 */ + @ApiModelProperty(value = "地块名称") + private String landName; + +} diff --git a/base-system/src/main/java/com/agri/business/domain/dto/CultivationBreedingBaseDto.java b/base-system/src/main/java/com/agri/business/domain/dto/CultivationBreedingBaseDto.java new file mode 100644 index 0000000..92c4239 --- /dev/null +++ b/base-system/src/main/java/com/agri/business/domain/dto/CultivationBreedingBaseDto.java @@ -0,0 +1,125 @@ +package com.agri.business.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + import java.math.BigDecimal; +import java.io.Serializable; +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonInclude; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * 种养殖基地 + * + * @author wqy + * @date 2025-04-17 + */ + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "种养殖基地" , description = "种养殖基地" ) +public class CultivationBreedingBaseDto implements Serializable { + private static final long serialVersionUID = 1L; + + /** 唯一标识每个基地的主键ID */ + @ApiModelProperty(value = "唯一标识每个基地的主键ID") + private Long id; + + /** 种养殖基地的名称 */ + @ApiModelProperty(value = "种养殖基地的名称") + private String baseName; + + /** 对应分类表中的ID */ + @ApiModelProperty(value = "对应分类表中的ID") + private Long categoryId; + + /** 基地类型(种植基地、养殖基地、综合基地) */ + @ApiModelProperty(value = "基地类型(种植基地、养殖基地、综合基地)") + private String baseType; + + /** 基地所在省份的行政区域编码 */ + @ApiModelProperty(value = "基地所在省份的行政区域编码") + private String provinceCode; + + /** 基地所在省份的名称 */ + @ApiModelProperty(value = "基地所在省份的名称") + private String provinceName; + + /** 基地所在市的行政区域编码 */ + @ApiModelProperty(value = "基地所在市的行政区域编码") + private String cityCode; + + /** 基地所在市的名称 */ + @ApiModelProperty(value = "基地所在市的名称") + private String cityName; + + /** 基地所在区/县的行政区域编码 */ + @ApiModelProperty(value = "基地所在区/县的行政区域编码") + private String districtCode; + + /** 基地所在区/县的名称 */ + @ApiModelProperty(value = "基地所在区/县的名称") + private String districtName; + + /** 种养殖基地的详细地址 */ + @ApiModelProperty(value = "种养殖基地的详细地址") + private String address; + + /** 基地的联系人姓名 */ + @ApiModelProperty(value = "基地的联系人姓名") + private String contactPerson; + + /** 基地的联系电话 */ + @ApiModelProperty(value = "基地的联系电话") + private String contactPhone; + + /** 对基地的详细描述,可为空 */ + @ApiModelProperty(value = "对基地的详细描述,可为空") + private String description; + + /** 种养殖基地的面积(单位:平方米) */ + @ApiModelProperty(value = "种养殖基地的面积(单位:平方米)") + private BigDecimal area; + + /** 面积单位 */ + @ApiModelProperty(value = "面积单位") + private String unit; + + /** 记录基地创建的时间 */ + @ApiModelProperty(value = "记录基地创建的时间") + private Date createdAt; + + /** 记录基地最后更新的时间 */ + @ApiModelProperty(value = "记录基地最后更新的时间") + private Date updatedAt; + + /** 1表示启用,0表示禁用 */ + @ApiModelProperty(value = "1表示启用,0表示禁用") + private Integer status; + + /** 地块ID */ + @ApiModelProperty(value = "地块ID") + private String landId; + + /** 地块名称 */ + @ApiModelProperty(value = "地块名称") + private String landName; + + /** 开始时间 */ + @ApiModelProperty(value = "开始时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimes; + + /** 结束时间 */ + @ApiModelProperty(value = "结束时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTimee; + +} diff --git a/base-system/src/main/java/com/agri/business/domain/vo/CultivationBreedingBaseVo.java b/base-system/src/main/java/com/agri/business/domain/vo/CultivationBreedingBaseVo.java new file mode 100644 index 0000000..8b0867b --- /dev/null +++ b/base-system/src/main/java/com/agri/business/domain/vo/CultivationBreedingBaseVo.java @@ -0,0 +1,113 @@ +package com.agri.business.domain.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 种养殖基地 + * + * @author wqy + * @date 2025-04-17 + */ + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value="种养殖基地",description="种养殖基地") +public class CultivationBreedingBaseVo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 唯一标识每个基地的主键ID */ + @ApiModelProperty(value = "唯一标识每个基地的主键ID") + private Long id; + + /** 种养殖基地的名称 */ + @ApiModelProperty(value = "种养殖基地的名称") + private String baseName; + + /** 对应分类表中的ID */ + @ApiModelProperty(value = "对应分类表中的ID") + private Long categoryId; + + /** 基地类型(种植基地、养殖基地、综合基地) */ + @ApiModelProperty(value = "基地类型(种植基地、养殖基地、综合基地)") + private String baseType; + + /** 基地所在省份的行政区域编码 */ + @ApiModelProperty(value = "基地所在省份的行政区域编码") + private String provinceCode; + + /** 基地所在省份的名称 */ + @ApiModelProperty(value = "基地所在省份的名称") + private String provinceName; + + /** 基地所在市的行政区域编码 */ + @ApiModelProperty(value = "基地所在市的行政区域编码") + private String cityCode; + + /** 基地所在市的名称 */ + @ApiModelProperty(value = "基地所在市的名称") + private String cityName; + + /** 基地所在区/县的行政区域编码 */ + @ApiModelProperty(value = "基地所在区/县的行政区域编码") + private String districtCode; + + /** 基地所在区/县的名称 */ + @ApiModelProperty(value = "基地所在区/县的名称") + private String districtName; + + /** 种养殖基地的详细地址 */ + @ApiModelProperty(value = "种养殖基地的详细地址") + private String address; + + /** 基地的联系人姓名 */ + @ApiModelProperty(value = "基地的联系人姓名") + private String contactPerson; + + /** 基地的联系电话 */ + @ApiModelProperty(value = "基地的联系电话") + private String contactPhone; + + /** 对基地的详细描述,可为空 */ + @ApiModelProperty(value = "对基地的详细描述,可为空") + private String description; + + /** 种养殖基地的面积(单位:平方米) */ + @ApiModelProperty(value = "种养殖基地的面积(单位:平方米)") + private BigDecimal area; + + /** 面积单位 */ + @ApiModelProperty(value = "面积单位") + private String unit; + + /** 记录基地创建的时间 */ + @ApiModelProperty(value = "记录基地创建的时间") + private Date createdAt; + + /** 记录基地最后更新的时间 */ + @ApiModelProperty(value = "记录基地最后更新的时间") + private Date updatedAt; + + /** 1表示启用,0表示禁用 */ + @ApiModelProperty(value = "1表示启用,0表示禁用") + private Integer status; + + /** 地块ID */ + @ApiModelProperty(value = "地块ID") + private String landId; + + /** 地块名称 */ + @ApiModelProperty(value = "地块名称") + private String landName; + +} diff --git a/base-system/src/main/java/com/agri/business/mapper/CultivationBreedingBaseMapper.java b/base-system/src/main/java/com/agri/business/mapper/CultivationBreedingBaseMapper.java new file mode 100644 index 0000000..b3969ff --- /dev/null +++ b/base-system/src/main/java/com/agri/business/mapper/CultivationBreedingBaseMapper.java @@ -0,0 +1,17 @@ +package com.agri.business.mapper; + +import java.util.List; +import com.agri.common.dao.BaseDao; +import com.agri.business.domain.CultivationBreedingBase; +import org.apache.ibatis.annotations.Mapper; + +/** + * 种养殖基地Mapper接口 + * + * @author wqy + * @since 2025-04-17 + */ +@Mapper +public interface CultivationBreedingBaseMapper extends BaseDao { + +} diff --git a/base-system/src/main/java/com/agri/business/service/ICultivationBreedingBaseService.java b/base-system/src/main/java/com/agri/business/service/ICultivationBreedingBaseService.java new file mode 100644 index 0000000..971bd6f --- /dev/null +++ b/base-system/src/main/java/com/agri/business/service/ICultivationBreedingBaseService.java @@ -0,0 +1,22 @@ +package com.agri.business.service; + +import java.util.List; +import com.agri.business.domain.CultivationBreedingBase; +import com.agri.common.service.BaseService; + +/** + * 种养殖基地Service接口 + * + * @author wqy + * @since 2025-04-17 + */ +public interface ICultivationBreedingBaseService extends BaseService { + + /** + * 导出种养殖基地数据列表 + * @param list 数据列表 + * @param sourceType 1-总后台 2-集货中心 3-基地供应商后台 + */ + void exportCultivationBreedingBaseExcel(List list, Integer sourceType); + +} diff --git a/base-system/src/main/java/com/agri/business/service/impl/CultivationBreedingBaseServiceImpl.java b/base-system/src/main/java/com/agri/business/service/impl/CultivationBreedingBaseServiceImpl.java new file mode 100644 index 0000000..4bd0fd9 --- /dev/null +++ b/base-system/src/main/java/com/agri/business/service/impl/CultivationBreedingBaseServiceImpl.java @@ -0,0 +1,44 @@ +package com.agri.business.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.agri.business.mapper.CultivationBreedingBaseMapper; +import com.agri.business.domain.CultivationBreedingBase; +import com.agri.business.service.ICultivationBreedingBaseService; +import com.agri.common.service.impl.BaseServiceImpl; +import com.agri.common.enums.ExportEnum; + +/** + * 种养殖基地Service业务层处理 + * + * @author wqy + * @since 2025-04-17 + */ +@Service +public class CultivationBreedingBaseServiceImpl extends BaseServiceImpl implements ICultivationBreedingBaseService { + + @Autowired + private CultivationBreedingBaseMapper cultivationBreedingBaseMapper; + + // @Autowired + // private IExportService exportService; + + /** + * 导出种养殖基地数据列表 + * @param list 数据列表 + * @param sourceType 1-总后台 2-集货中心 3-基地供应商后台 + */ + @Override + public void exportCultivationBreedingBaseExcel(List list, Integer sourceType) { + /*if (list == null || list.size() == 0) { + throw new BusinessException("没有要导出的记录"); + } + List exportList = CultivationBreedingBaseExportDto.build(list); + ExcelUtil util = new ExcelUtil<>(CultivationBreedingBaseExportDto.class); + String sheetName = ExportEnum.APP_USER_EXPORT.getDesc(); + int code = ExportEnum.APP_USER_EXPORT.getCode() + Workbook workHook = util.getWorkHook(exportList, sheetName); + exportService.exportRecord(workHook, sheetName, code, sourceType);*/ + } +} diff --git a/base-system/src/main/resources/mapper/business/CultivationBreedingBaseMapper.xml b/base-system/src/main/resources/mapper/business/CultivationBreedingBaseMapper.xml new file mode 100644 index 0000000..96dfab9 --- /dev/null +++ b/base-system/src/main/resources/mapper/business/CultivationBreedingBaseMapper.xml @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + ,base_name + ,category_id + ,base_type + ,province_code + ,province_name + ,city_code + ,city_name + ,district_code + ,district_name + ,address + ,contact_person + ,contact_phone + ,description + ,area + ,unit + ,created_at + ,updated_at + ,status + ,land_id + ,land_name + + + + + + #{id} + ,#{baseName} + ,#{categoryId} + ,#{baseType} + ,#{provinceCode} + ,#{provinceName} + ,#{cityCode} + ,#{cityName} + ,#{districtCode} + ,#{districtName} + ,#{address} + ,#{contactPerson} + ,#{contactPhone} + ,#{description} + ,#{area} + ,#{unit} + ,#{createdAt} + ,#{updatedAt} + ,#{status} + ,#{landId} + ,#{landName} + + + + + + AND id = #{id} + + + AND base_name = #{baseName} + + + AND base_name like CONCAT('%', #{baseNameLike}, '%') + + + AND category_id = #{categoryId} + + + AND base_type = #{baseType} + + + AND province_code = #{provinceCode} + + + AND province_name = #{provinceName} + + + AND city_code = #{cityCode} + + + AND city_name = #{cityName} + + + AND district_code = #{districtCode} + + + AND district_name = #{districtName} + + + AND address = #{address} + + + AND contact_person = #{contactPerson} + + + AND contact_phone = #{contactPhone} + + + AND description = #{description} + + + AND area = #{area} + + + AND unit = #{unit} + + + AND created_at = #{createdAt} + + + AND created_at =]]> #{createdAts} + + + AND created_at #{createdAte} + + + AND id in + + + #{idInListItem} + + + + (-1) + + + + AND updated_at = #{updatedAt} + + + AND status = #{status} + + + AND land_id = #{landId} + + + AND land_name = #{landName} + + + + + + id = #{id}, + + + base_name = #{baseName}, + + + category_id = #{categoryId}, + + + base_type = #{baseType}, + + + province_code = #{provinceCode}, + + + province_name = #{provinceName}, + + + city_code = #{cityCode}, + + + city_name = #{cityName}, + + + district_code = #{districtCode}, + + + district_name = #{districtName}, + + + address = #{address}, + + + contact_person = #{contactPerson}, + + + contact_phone = #{contactPhone}, + + + description = #{description}, + + + area = #{area}, + + + unit = #{unit}, + + + created_at = #{createdAt}, + + + updated_at = #{updatedAt}, + + + status = #{status}, + + + land_id = #{landId}, + + + land_name = #{landName}, + + + + + + + + + + SELECT LAST_INSERT_ID() AS id + + INSERT into t_cultivation_breeding_base + () + VALUES + () + + + + + update t_cultivation_breeding_base + + + + where id = #{id} + + + + + + + + + + + + + + DELETE FROM t_cultivation_breeding_base + WHERE id = #{id} + + + + + + + + DELETE FROM t_cultivation_breeding_base + + + + + + + + DELETE FROM t_cultivation_breeding_base + WHERE id IN + + #{id} + + + +