|
|
package com.controller;
|
|
|
|
|
|
import java.math.BigDecimal; // 导入BigDecimal以处理高精度数值
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Map;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator; // 导入迭代器接口
|
|
|
import java.util.Date;
|
|
|
import java.util.List; // 导入List接口
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import com.utils.ValidatorUtils;
|
|
|
import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang的字符串处理类
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
|
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.RequestParam; // 导入请求参数注解
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper,用于构建查询条件
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis-Plus的Wrapper接口
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
|
|
import com.entity.LeixingEntity;
|
|
|
import com.entity.view.LeixingView; // 导入类型视图类
|
|
|
|
|
|
import com.service.LeixingService; // 导入类型服务类
|
|
|
import com.service.TokenService;
|
|
|
import com.utils.PageUtils; // 导入分页工具类
|
|
|
import com.utils.R; // 导入响应工具类
|
|
|
import com.utils.MD5Util;
|
|
|
import com.utils.MPUtil; // 导入MyBatis-Plus工具类
|
|
|
import com.utils.CommonUtil;
|
|
|
|
|
|
/**
|
|
|
* 类型
|
|
|
* 后端接口
|
|
|
* @author
|
|
|
* @email
|
|
|
* @date 2023-02-21 09:46:06
|
|
|
*/
|
|
|
@RestController // 标记该类为REST控制器
|
|
|
@RequestMapping("/leixing") // 设置基本请求路径为"/leixing"
|
|
|
public class LeixingController {
|
|
|
@Autowired
|
|
|
private LeixingService leixingService; // 自动注入类型服务
|
|
|
|
|
|
/**
|
|
|
* 后端列表
|
|
|
* @param params 请求参数
|
|
|
* @param leixing 类型实体
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 列表数据
|
|
|
*/
|
|
|
@RequestMapping("/page") // 映射请求路径为"/page"
|
|
|
public R page(@RequestParam Map<String, Object> params, LeixingEntity leixing,
|
|
|
HttpServletRequest request) {
|
|
|
|
|
|
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
|
|
|
|
|
|
// 查询分页数据
|
|
|
PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params));
|
|
|
request.setAttribute("data", page); // 将数据设置到请求属性中
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前端列表
|
|
|
* @param params 请求参数
|
|
|
* @param leixing 类型实体
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 列表数据
|
|
|
*/
|
|
|
@IgnoreAuth // 忽略身份验证
|
|
|
@RequestMapping("/list") // 映射请求路径为"/list"
|
|
|
public R list(@RequestParam Map<String, Object> params, LeixingEntity leixing,
|
|
|
HttpServletRequest request) {
|
|
|
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
|
|
|
|
|
|
// 查询分页数据
|
|
|
PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params));
|
|
|
request.setAttribute("data", page); // 将数据设置到请求属性中
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询所有列表
|
|
|
* @param leixing 类型实体
|
|
|
* @return 查询结果
|
|
|
*/
|
|
|
@RequestMapping("/lists") // 映射请求路径为"/lists"
|
|
|
public R list(LeixingEntity leixing) {
|
|
|
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
|
|
|
ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件
|
|
|
return R.ok().put("data", leixingService.selectListView(ew));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询具体信息
|
|
|
* @param leixing 类型实体
|
|
|
* @return 查询结果
|
|
|
*/
|
|
|
@RequestMapping("/query") // 映射请求路径为"/query"
|
|
|
public R query(LeixingEntity leixing) {
|
|
|
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
|
|
|
ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件
|
|
|
LeixingView leixingView = leixingService.selectView(ew); // 查询类型视图
|
|
|
return R.ok("查询类型成功").put("data", leixingView);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取后端详情
|
|
|
* @param id 类型ID
|
|
|
* @return 类型信息
|
|
|
*/
|
|
|
@RequestMapping("/info/{id}") // 映射请求路径为"/info/{id}"
|
|
|
public R info(@PathVariable("id") Long id) {
|
|
|
LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型
|
|
|
return R.ok().put("data", leixing);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取前端详情
|
|
|
* @param id 类型ID
|
|
|
* @return 类型信息
|
|
|
*/
|
|
|
@IgnoreAuth // 忽略身份验证
|
|
|
@RequestMapping("/detail/{id}") // 映射请求路径为"/detail/{id}"
|
|
|
public R detail(@PathVariable("id") Long id) {
|
|
|
LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型
|
|
|
return R.ok().put("data", leixing);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后端保存类型信息
|
|
|
* @param leixing 类型实体
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 保存结果
|
|
|
*/
|
|
|
@RequestMapping("/save") // 映射请求路径为"/save"
|
|
|
public R save(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
|
|
|
leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
|
|
|
// ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
|
|
|
|
|
|
leixingService.insert(leixing); // 保存类型信息
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前端保存类型信息
|
|
|
* @param leixing 类型实体
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 保存结果
|
|
|
*/
|
|
|
@RequestMapping("/add") // 映射请求路径为"/add"
|
|
|
public R add(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
|
|
|
leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
|
|
|
// ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
|
|
|
|
|
|
leixingService.insert(leixing); // 保存类型信息
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改类型信息
|
|
|
* @param leixing 类型实体
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 修改结果
|
|
|
*/
|
|
|
@RequestMapping("/update") // 映射请求路径为"/update"
|
|
|
@Transactional // 开启事务
|
|
|
public R update(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
|
|
|
// ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
|
|
|
leixingService.updateById(leixing); // 更新类型信息
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除类型
|
|
|
* @param ids 类型ID数组
|
|
|
* @return 删除结果
|
|
|
*/
|
|
|
@RequestMapping("/delete") // 映射请求路径为"/delete"
|
|
|
public R delete(@RequestBody Long[] ids) {
|
|
|
leixingService.deleteBatchIds(Arrays.asList(ids)); // 批量删除类型
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提醒接口
|
|
|
* @param columnName 列名
|
|
|
* @param type 类型
|
|
|
* @param map 查询参数
|
|
|
* @param request HttpServletRequest对象
|
|
|
* @return 提醒数量
|
|
|
*/
|
|
|
@RequestMapping("/remind/{columnName}/{type}") // 映射请求路径为"/remind/{columnName}/{type}"
|
|
|
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
|
|
|
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
|
|
|
map.put("column", columnName); // 将列名放入请求参数
|
|
|
map.put("type", type); // 将类型放入请求参数
|
|
|
|
|
|
// 如果类型为2,进行日期提醒处理
|
|
|
if (type.equals("2")) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
Date remindStartDate = null;
|
|
|
Date remindEndDate = null;
|
|
|
// 处理提醒开始时间
|
|
|
if (map.get("remindstart") != null) {
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
|
|
|
c.setTime(new Date());
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加提醒天数
|
|
|
remindStartDate = c.getTime(); // 获取新的开始日期
|
|
|
map.put("remindstart", sdf.format(remindStartDate)); // 格式化并放入请求参数
|
|
|
}
|
|
|
// 处理提醒结束时间
|
|
|
if (map.get("remindend") != null) {
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
|
|
|
c.setTime(new Date());
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindEnd); // 添加提醒天数
|
|
|
remindEndDate = c.getTime(); // 获取新的结束日期
|
|
|
map.put("remindend", sdf.format(remindEndDate)); // 格式化并放入请求参数
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 构建查询条件
|
|
|
Wrapper<LeixingEntity> wrapper = new EntityWrapper<LeixingEntity>();
|
|
|
if (map.get("remindstart") != null) {
|
|
|
wrapper.ge(columnName, map.get("remindstart")); // 大于等于开始日期
|
|
|
}
|
|
|
if (map.get("remindend") != null) {
|
|
|
wrapper.le(columnName, map.get("remindend")); // 小于等于结束日期
|
|
|
}
|
|
|
|
|
|
int count = leixingService.selectCount(wrapper); // 查询数量
|
|
|
return R.ok().put("count", count); // 返回数量
|
|
|
}
|
|
|
}
|