package com.example.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.GoumaixinxiInfo;
import com.example.dao.GoumaixinxiInfoDao;
import com.example.service.GoumaixinxiInfoService;
import com.example.exception.CustomException;
import com.example.common.ResultCode;
import com.example.vo.EchartsData;
import com.example.vo.GoumaixinxiInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.example.service.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/goumaixinxiInfo")
public class GoumaixinxiInfoController {
@Resource
private GoumaixinxiInfoService goumaixinxiInfoService;
@Resource
private GoumaixinxiInfoDao goumaixinxiInfoDao;
@PostMapping
public Result<GoumaixinxiInfo> add(@RequestBody GoumaixinxiInfoVo goumaixinxiInfo) {
//mixmajixami
goumaixinxiInfoService.add(goumaixinxiInfo);
return Result.success(goumaixinxiInfo);
}
//youtixing1
//youtixing2
@GetMapping("/getByDiqu")
public Result<List<Map<String,String>>> qidu() {
return Result.success(goumaixinxiInfoService.findByDiqu());
}
@DeleteMapping("/{id}")
public Result delete(@PathVariable Long id) {
goumaixinxiInfoService.delete(id);
return Result.success();
}
@GetMapping("/getByzhuceyonghuFaburen/{faburen}")
public Result<List<GoumaixinxiInfo>> getByzhuceyonghuFaburen(@PathVariable String faburen) {
List<GoumaixinxiInfo> goumaixinxiInfo = goumaixinxiInfoService.getByzhuceyonghuFaburen(faburen);
return Result.success(goumaixinxiInfo);
}
@GetMapping("/getByzhuceyonghuGoumairen/{goumairen}")
public Result<List<GoumaixinxiInfo>> getByzhuceyonghuGoumairen(@PathVariable String goumairen) {
List<GoumaixinxiInfo> goumaixinxiInfo = goumaixinxiInfoService.getByzhuceyonghuGoumairen(goumairen);
return Result.success(goumaixinxiInfo);
}
@PutMapping
public Result update(@RequestBody GoumaixinxiInfoVo goumaixinxiInfo) {
goumaixinxiInfoService.update(goumaixinxiInfo);
return Result.success();
}
//@PutMapping("/update2")
// public Result update2(@RequestBody GoumaixinxiInfoVo goumaixinxiInfo) {
// goumaixinxiInfoService.update2(goumaixinxiInfo);
// return Result.success();
// }
@GetMapping("/{id}")
public Result<GoumaixinxiInfo> detail(@PathVariable Long id) {
GoumaixinxiInfo goumaixinxiInfo = goumaixinxiInfoService.findById(id);
return Result.success(goumaixinxiInfo);
}
@GetMapping("/changeStatus/{id}")
public Result<GoumaixinxiInfo> changeStatus(@PathVariable Long id) {
goumaixinxiInfoService.changeStatus(id);
return Result.success();
}
@GetMapping("/changeIszf/{id}")
public Result<GoumaixinxiInfo> changeIszf(@PathVariable Long id) {
goumaixinxiInfoService.changeIszf(id);
return Result.success();
}
@GetMapping
public Result<List<GoumaixinxiInfoVo>> all() {
return Result.success(goumaixinxiInfoService.findAll());
}
@GetMapping("/page/{name}")
public Result<PageInfo<GoumaixinxiInfoVo>> page(@PathVariable String name,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "5") Integer pageSize,
HttpServletRequest request) {
return Result.success(goumaixinxiInfoService.findPage(name, pageNum, pageSize, request));
}
@GetMapping("/pageqt/{name}")
public Result<PageInfo<GoumaixinxiInfoVo>> pageqt(@PathVariable String name,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "8") Integer pageSize,
HttpServletRequest request) {
return Result.success(goumaixinxiInfoService.findPageqt(name, pageNum, pageSize, request));
}
// @PostMapping("/register")
// public Result<GoumaixinxiInfo> register(@RequestBody GoumaixinxiInfo goumaixinxiInfo) {
// if (StrUtil.isBlank(goumaixinxiInfo.getName()) || StrUtil.isBlank(goumaixinxiInfo.getPassword())) {
// throw new CustomException(ResultCode.PARAM_ERROR);
// }
// return Result.success(goumaixinxiInfoService.add(goumaixinxiInfo));
// }
/**
* 批量通过excel添加信息
* @param file excel文件
* @throws IOException
*/
@PostMapping("/upload")
public Result upload(MultipartFile file) throws IOException {
List<GoumaixinxiInfo> infoList = ExcelUtil.getReader(file.getInputStream()).readAll(GoumaixinxiInfo.class);
if (!CollectionUtil.isEmpty(infoList)) {
// 处理一下空数据
List<GoumaixinxiInfo> resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getWupinmingcheng())).collect(Collectors.toList());
for (GoumaixinxiInfo info : resultList) {
goumaixinxiInfoService.add(info);
}
}
return Result.success();
}
//yoxutonxgjitu
@GetMapping("/getExcelModel")
public void getExcelModel(HttpServletResponse response) throws IOException {
// 1. 生成excel
Map<String, Object> row = new LinkedHashMap<>();
row.put("wupinbianhao", "A物品编号");
row.put("wupinmingcheng", "A物品名称");
row.put("wupinleibie", "A物品类别");
row.put("jiage", "A价格");
row.put("faburen", "A发布人");
row.put("goumairen", "A购买人");
row.put("status", "是");
row.put("level", "goumaixinxi");
List<Map<String, Object>> list = CollUtil.newArrayList(row);
// 2. 写excel
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.write(list, true);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename=goumaixinxiInfoModel.xlsx");
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
writer.close();
IoUtil.close(System.out);
}
@GetMapping("/getExcel")
public void getExcel(HttpServletResponse response) throws IOException {
// 1. 生成excel
Map<String, Object> row = new LinkedHashMap<>();
row.put("wupinbianhao", "A物品编号");
row.put("wupinmingcheng", "A物品名称");
row.put("wupinleibie", "A物品类别");
row.put("jiage", "A价格");
row.put("faburen", "A发布人");
row.put("goumairen", "A购买人");
row.put("status", "是");
row.put("level", "权限");
List<Map<String, Object>> list = CollUtil.newArrayList(row);
List<Map<String, Object>> daochuexcellist = goumaixinxiInfoDao.daochuexcel();
Map<String, Double> typeMap = new HashMap<>();
for (Map<Str
码农飞哥
- 粉丝: 15w+
- 资源: 1914
最新资源
- 【未发表】基于龙格库塔优化算法RUN优化宽度学习BLS实现光伏数据预测算法研究附Matlab代码.rar
- 【未发表】基于麻雀搜索优化算法SSA优化集成学习结合核极限学习机KELM-Adaboost实现风电数据时序预测算法研究附Matlab代码.rar
- 【未发表】基于麻雀搜索优化算法SSA优化鲁棒极限学习机RELM实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于麻雀搜索优化算法SSA优化宽度学习BLS实现光伏数据预测算法研究附Matlab代码.rar
- 【未发表】基于麻雀搜索优化算法SSA优化集成学习结合鲁棒极限学习机RELM-Adaboost实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于能量谷优化算法EVO优化宽度学习BLS实现光伏数据预测算法研究附Matlab代码.rar
- 【未发表】基于能量谷优化算法EVO优化集成学习结合鲁棒极限学习机RELM-Adaboost实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于能量谷优化算法EVO优化集成学习结合核极限学习机KELM-Adaboost实现风电数据时序预测算法研究附Matlab代码.rar
- 【未发表】基于能量谷优化算法EVO优化鲁棒极限学习机RELM实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于黏菌优化算法LSMA优化宽度学习BLS实现光伏数据预测算法研究附Matlab代码.rar
- 【未发表】基于黏菌优化算法LSMA优化集成学习结合鲁棒极限学习机RELM-Adaboost实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于黏菌优化算法LSMA优化集成学习结合核极限学习机KELM-Adaboost实现风电数据时序预测算法研究附Matlab代码.rar
- 【未发表】基于黏菌优化算法LSMA优化鲁棒极限学习机RELM实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于牛顿拉夫逊优化算法NRBO优化集成学习结合鲁棒极限学习机RELM-Adaboost实现负荷数据回归预测算法研究附Matlab代码.rar
- 【未发表】基于牛顿拉夫逊优化算法NRBO优化集成学习结合核极限学习机KELM-Adaboost实现风电数据时序预测算法研究附Matlab代码.rar
- 【未发表】基于牛顿拉夫逊优化算法NRBO优化鲁棒极限学习机RELM实现负荷数据回归预测算法研究附Matlab代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈