代码优化

This commit is contained in:
Administrator 2023-04-28 17:54:38 +08:00
parent 42230a1b3b
commit 9c5a06003b
6 changed files with 548 additions and 483 deletions

View File

@ -53,222 +53,211 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Api(tags = "WeighBookVehicleInfoController相关Api") @Api(tags = "WeighBookVehicleInfoController相关Api")
public class WeighBookVehicleInfoController { public class WeighBookVehicleInfoController {
@Autowired @Autowired
private IWeighBookVehicleInfoService weighBookVehicleInfoService; private IWeighBookVehicleInfoService weighBookVehicleInfoService;
/** /**
* 分页列表查询 * 分页列表查询
* *
* @param weighBookVehicleInfo * @param weighBookVehicleInfo
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @param lastAdddatetime 现场上次拉取的时间 * @param req
* @param req * @return
* @return */
*/ @ApiOperation(value = " 分页列表查询过磅预约车辆信息信息", notes = "分页列表查询过磅预约车辆信息信息", httpMethod = "GET")
@ApiOperation(value = " 分页列表查询过磅预约车辆信息信息", notes = "分页列表查询过磅预约车辆信息信息", httpMethod = "GET") @GetMapping(value = "/list")
@GetMapping(value = "/list") public Result<IPage<WeighBookVehicleInfo>> queryPageList(WeighBookVehicleInfo weighBookVehicleInfo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
public Result<IPage<WeighBookVehicleInfo>> queryPageList(WeighBookVehicleInfo weighBookVehicleInfo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, String lastAdddatetime, HttpServletRequest req) { return weighBookVehicleInfoService.queryPageList(weighBookVehicleInfo, pageNo, pageSize, req);
Result<IPage<WeighBookVehicleInfo>> result = new Result<IPage<WeighBookVehicleInfo>>(); }
LambdaQueryWrapper<WeighBookVehicleInfo> queryWrapper = new LambdaQueryWrapper<WeighBookVehicleInfo>()
.eq(StringUtils.isNotBlank(weighBookVehicleInfo.getProjectSn()),WeighBookVehicleInfo::getProjectSn,weighBookVehicleInfo.getProjectSn())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getSpecifications()),WeighBookVehicleInfo::getSpecifications,weighBookVehicleInfo.getSpecifications())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getGoodsName()),WeighBookVehicleInfo::getGoodsName,weighBookVehicleInfo.getGoodsName())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getLicensePlate()),WeighBookVehicleInfo::getLicensePlate,weighBookVehicleInfo.getLicensePlate());
if (StringUtils.isNotBlank(lastAdddatetime)) {
DateTime dateTime = DateUtil.parse(lastAdddatetime);
queryWrapper.ge(WeighBookVehicleInfo::getAddDateTime, dateTime);
}
Page<WeighBookVehicleInfo> page = new Page<WeighBookVehicleInfo>(pageNo, pageSize);
IPage<WeighBookVehicleInfo> pageList = weighBookVehicleInfoService.page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
/**
* 添加
* @param weighBookVehicleInfo
* @return
*/
@ApiOperation(value = " 添加过磅预约车辆信息信息", notes = "添加过磅预约车辆信息信息" , httpMethod="POST")
@PostMapping(value = "/add")
public Result<WeighBookVehicleInfo> add(@RequestBody WeighBookVehicleInfo weighBookVehicleInfo) {
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
try {
weighBookVehicleInfoService.save(weighBookVehicleInfo);
result.success("添加成功!");
} catch (Exception e) {
e.printStackTrace();
log.info(e.getMessage());
result.error500("操作失败");
}
return result;
}
/**
* 编辑
* @param weighBookVehicleInfo
* @return
*/
@ApiOperation(value = "编辑过磅预约车辆信息信息", notes = "编辑过磅预约车辆信息信息" , httpMethod="POST")
@PostMapping(value = "/edit")
public Result<WeighBookVehicleInfo> edit(@RequestBody WeighBookVehicleInfo weighBookVehicleInfo) {
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
WeighBookVehicleInfo weighBookVehicleInfoEntity = weighBookVehicleInfoService.getById(weighBookVehicleInfo.getId());
if (weighBookVehicleInfoEntity == null) {
result.error500("未找到对应实体");
} else {
weighBookVehicleInfoService.updateById(weighBookVehicleInfo);
result.success("修改成功!");
}
return result; /**
} * 添加
*
* @param weighBookVehicleInfo
* @return
*/
@ApiOperation(value = " 添加过磅预约车辆信息信息", notes = "添加过磅预约车辆信息信息", httpMethod = "POST")
@PostMapping(value = "/add")
public Result<WeighBookVehicleInfo> add(@RequestBody WeighBookVehicleInfo weighBookVehicleInfo) {
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
try {
weighBookVehicleInfoService.save(weighBookVehicleInfo);
result.success("添加成功!");
} catch (Exception e) {
e.printStackTrace();
log.info(e.getMessage());
result.error500("操作失败");
}
return result;
}
/** /**
* 通过id删除 * 编辑
* *
* @param id * @param weighBookVehicleInfo
* @return * @return
*/ */
@ApiOperation(value = "删除过磅预约车辆信息信息", notes = "删除过磅预约车辆信息信息", httpMethod = "POST") @ApiOperation(value = "编辑过磅预约车辆信息信息", notes = "编辑过磅预约车辆信息信息", httpMethod = "POST")
@PostMapping(value = "/delete") @PostMapping(value = "/edit")
public Result<WeighBookVehicleInfo> delete(@RequestBody String id) { public Result<WeighBookVehicleInfo> edit(@RequestBody WeighBookVehicleInfo weighBookVehicleInfo) {
JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
id = String.valueOf(jsonObject.get("id")); WeighBookVehicleInfo weighBookVehicleInfoEntity = weighBookVehicleInfoService.getById(weighBookVehicleInfo.getId());
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>(); if (weighBookVehicleInfoEntity == null) {
WeighBookVehicleInfo weighBookVehicleInfo = weighBookVehicleInfoService.getById(id); result.error500("未找到对应实体");
if (weighBookVehicleInfo == null) { } else {
result.error500("未找到对应实体"); weighBookVehicleInfoService.updateById(weighBookVehicleInfo);
} else { result.success("修改成功!");
boolean ok = weighBookVehicleInfoService.removeById(id); }
if (ok) {
result.success("删除成功!");
}
}
return result; return result;
} }
/** /**
* 批量删除 * 通过id删除
* @param ids *
* @return * @param id
*/ * @return
@ApiOperation(value = "批量删除过磅预约车辆信息信息", notes = "批量删除过磅预约车辆信息信息", httpMethod="POST") */
@ApiOperation(value = "删除过磅预约车辆信息信息", notes = "删除过磅预约车辆信息信息", httpMethod = "POST")
@PostMapping(value = "/delete")
public Result<WeighBookVehicleInfo> delete(@RequestBody String id) {
JSONObject jsonObject = JSON.parseObject(id, JSONObject.class);
id = String.valueOf(jsonObject.get("id"));
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
WeighBookVehicleInfo weighBookVehicleInfo = weighBookVehicleInfoService.getById(id);
if (weighBookVehicleInfo == null) {
result.error500("未找到对应实体");
} else {
boolean ok = weighBookVehicleInfoService.removeById(id);
if (ok) {
result.success("删除成功!");
}
}
return result;
}
/**
* 批量删除
*
* @param ids
* @return
*/
@ApiOperation(value = "批量删除过磅预约车辆信息信息", notes = "批量删除过磅预约车辆信息信息", httpMethod = "POST")
@ApiImplicitParam(name = "id", value = "过磅预约车辆信息ID字符串", paramType = "query", required = true, dataType = "String") @ApiImplicitParam(name = "id", value = "过磅预约车辆信息ID字符串", paramType = "query", required = true, dataType = "String")
@PostMapping(value = "/deleteBatch") @PostMapping(value = "/deleteBatch")
public Result<WeighBookVehicleInfo> deleteBatch(@RequestParam(name="ids",required=true) String ids) { public Result<WeighBookVehicleInfo> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>(); Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
if(ids==null || "".equals(ids.trim())) { if (ids == null || "".equals(ids.trim())) {
result.error500("参数不识别!"); result.error500("参数不识别!");
}else { } else {
this.weighBookVehicleInfoService.removeByIds(Arrays.asList(ids.split(","))); this.weighBookVehicleInfoService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!"); result.success("删除成功!");
} }
return result; return result;
} }
/**
* 通过id查询
* @param id
* @return
*/
@ApiOperation(value = "通过id查询过磅预约车辆信息信息", notes = "通过id查询过磅预约车辆信息信息" , httpMethod="GET")
@ApiImplicitParam(name = "id", value = "过磅预约车辆信息ID", paramType = "query", required = true, dataType = "Integer")
@GetMapping(value = "/queryById")
public Result<WeighBookVehicleInfo> queryById(@RequestParam(name="id",required=true) String id) {
Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
WeighBookVehicleInfo weighBookVehicleInfo = weighBookVehicleInfoService.getById(id);
if(weighBookVehicleInfo==null) {
result.error500("未找到对应实体");
}else {
result.setResult(weighBookVehicleInfo);
result.setSuccess(true);
}
return result;
}
/** /**
* 导出excel * 通过id查询
* *
* @param request * @param id
* @param response * @return
*/ */
@ApiOperation(value = "导出excel过磅预约车辆信息信息", notes = "导出excel过磅预约车辆信息信息" , httpMethod="POST") @ApiOperation(value = "通过id查询过磅预约车辆信息信息", notes = "通过id查询过磅预约车辆信息信息", httpMethod = "GET")
@RequestMapping(value = "/exportXls") @ApiImplicitParam(name = "id", value = "过磅预约车辆信息ID", paramType = "query", required = true, dataType = "Integer")
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) { @GetMapping(value = "/queryById")
// Step.1 组装查询条件 public Result<WeighBookVehicleInfo> queryById(@RequestParam(name = "id", required = true) String id) {
QueryWrapper<WeighBookVehicleInfo> queryWrapper = null; Result<WeighBookVehicleInfo> result = new Result<WeighBookVehicleInfo>();
try { WeighBookVehicleInfo weighBookVehicleInfo = weighBookVehicleInfoService.getById(id);
String paramsStr = request.getParameter("paramsStr"); if (weighBookVehicleInfo == null) {
if (oConvertUtils.isNotEmpty(paramsStr)) { result.error500("未找到对应实体");
String deString = URLDecoder.decode(paramsStr, "UTF-8"); } else {
WeighBookVehicleInfo weighBookVehicleInfo = JSON.parseObject(deString, WeighBookVehicleInfo.class); result.setResult(weighBookVehicleInfo);
queryWrapper = QueryGenerator.initQueryWrapper(weighBookVehicleInfo, request.getParameterMap()); result.setSuccess(true);
} }
} catch (UnsupportedEncodingException e) { return result;
e.printStackTrace(); }
}
//Step.2 AutoPoi 导出Excel /**
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); * 导出excel
List<WeighBookVehicleInfo> pageList = weighBookVehicleInfoService.list(queryWrapper); *
//导出文件名称 * @param request
mv.addObject(NormalExcelConstants.FILE_NAME, "过磅预约车辆信息列表"); * @param response
mv.addObject(NormalExcelConstants.CLASS, WeighBookVehicleInfo.class); */
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("过磅预约车辆信息列表数据", "导出人:Jeecg", "导出信息")); @ApiOperation(value = "导出excel过磅预约车辆信息信息", notes = "导出excel过磅预约车辆信息信息", httpMethod = "POST")
mv.addObject(NormalExcelConstants.DATA_LIST, pageList); @RequestMapping(value = "/exportXls")
return mv; public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
} // Step.1 组装查询条件
QueryWrapper<WeighBookVehicleInfo> queryWrapper = null;
try {
String paramsStr = request.getParameter("paramsStr");
if (oConvertUtils.isNotEmpty(paramsStr)) {
String deString = URLDecoder.decode(paramsStr, "UTF-8");
WeighBookVehicleInfo weighBookVehicleInfo = JSON.parseObject(deString, WeighBookVehicleInfo.class);
queryWrapper = QueryGenerator.initQueryWrapper(weighBookVehicleInfo, request.getParameterMap());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
/** //Step.2 AutoPoi 导出Excel
* 通过excel导入数据 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
* List<WeighBookVehicleInfo> pageList = weighBookVehicleInfoService.list(queryWrapper);
* @param request //导出文件名称
* @param response mv.addObject(NormalExcelConstants.FILE_NAME, "过磅预约车辆信息列表");
* @return mv.addObject(NormalExcelConstants.CLASS, WeighBookVehicleInfo.class);
*/ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("过磅预约车辆信息列表数据", "导出人:Jeecg", "导出信息"));
@ApiOperation(value = "通过excel导入过磅预约车辆信息信息", notes = "通过excel导入过磅预约车辆信息信息", httpMethod="POST") mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) return mv;
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { }
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<WeighBookVehicleInfo> listWeighBookVehicleInfos = ExcelImportUtil.importExcel(file.getInputStream(), WeighBookVehicleInfo.class, params);
for (WeighBookVehicleInfo weighBookVehicleInfoExcel : listWeighBookVehicleInfos) {
weighBookVehicleInfoService.save(weighBookVehicleInfoExcel);
}
return Result.ok("文件导入成功!数据行数:" + listWeighBookVehicleInfos.size());
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("文件导入失败!");
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.ok("文件导入失败!");
}
/** /**
* 获取所有过磅类型列表 * 通过excel导入数据
* *
* @return * @param request
*/ * @param response
@GetMapping("/weighingType") * @return
@ApiOperation(value = "获取所有过磅类型列表", notes = "获取所有过磅类型列表", httpMethod = "GET") */
public Result<List<WeighingTypeEnum>> getWeighingTypeEnums() { @ApiOperation(value = "通过excel导入过磅预约车辆信息信息", notes = "通过excel导入过磅预约车辆信息信息", httpMethod = "POST")
return Result.success(Arrays.stream(WeighingTypeEnum.values()).collect(Collectors.toList())); @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
} public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<WeighBookVehicleInfo> listWeighBookVehicleInfos = ExcelImportUtil.importExcel(file.getInputStream(), WeighBookVehicleInfo.class, params);
for (WeighBookVehicleInfo weighBookVehicleInfoExcel : listWeighBookVehicleInfos) {
weighBookVehicleInfoService.save(weighBookVehicleInfoExcel);
}
return Result.ok("文件导入成功!数据行数:" + listWeighBookVehicleInfos.size());
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("文件导入失败!");
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.ok("文件导入失败!");
}
/**
* 获取所有过磅类型列表
*
* @return
*/
@GetMapping("/weighingType")
@ApiOperation(value = "获取所有过磅类型列表", notes = "获取所有过磅类型列表", httpMethod = "GET")
public Result<List<WeighingTypeEnum>> getWeighingTypeEnums() {
return Result.success(Arrays.stream(WeighingTypeEnum.values()).collect(Collectors.toList()));
}
} }

View File

@ -1,47 +1,43 @@
package com.zhgd.xmgl.modules.weight.controller; package com.zhgd.xmgl.modules.weight.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiImplicitParam; import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.jeecg.common.util.oConvertUtils; import com.zhgd.jeecg.common.util.oConvertUtils;
import com.zhgd.xmgl.modules.weight.entity.WeighInfo; import com.zhgd.xmgl.modules.weight.entity.WeighInfo;
import com.zhgd.xmgl.modules.weight.service.IWeighInfoService; import com.zhgd.xmgl.modules.weight.service.IWeighInfoService;
import io.swagger.annotations.Api;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiImplicitParam;
import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
/** import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Title: Controller * @Title: Controller
* @Description: 称重记录表 * @Description: 称重记录表
* @author pds * @author pds
* @date 2023-03-21 * @date 2023-03-21
* @version V1.0 * @version V1.0
*/ */
@RestController @RestController
@ -49,198 +45,204 @@ import com.alibaba.fastjson.JSON;
@Slf4j @Slf4j
@Api(tags = "WeighInfoController相关Api") @Api(tags = "WeighInfoController相关Api")
public class WeighInfoController { public class WeighInfoController {
@Autowired @Autowired
private IWeighInfoService weighInfoService; private IWeighInfoService weighInfoService;
/** /**
* 分页列表查询 * 分页列表查询
* @param weighInfo *
* @param pageNo * @param weighInfo
* @param pageSize * @param pageNo
* @param req * @param pageSize
* @return * @param req
*/ * @return
@ApiOperation(value = " 分页列表查询称重记录表信息", notes = "分页列表查询称重记录表信息", httpMethod="GET") */
@GetMapping(value = "/list") @ApiOperation(value = " 分页列表查询称重记录表信息", notes = "分页列表查询称重记录表信息", httpMethod = "GET")
public Result<IPage<WeighInfo>> queryPageList(WeighInfo weighInfo, @GetMapping(value = "/list")
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, public Result<IPage<WeighInfo>> queryPageList(WeighInfo weighInfo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
HttpServletRequest req) { @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
return weighInfoService.queryPageList(weighInfo, pageNo, pageSize, req); HttpServletRequest req) {
} return weighInfoService.queryPageList(weighInfo, pageNo, pageSize, req);
}
/**
* 添加 /**
* @param weighInfo * 现场端添加称重记录表信息
* @return *
*/ * @param weighInfo
@ApiOperation(value = " 添加称重记录表信息", notes = "添加称重记录表信息" , httpMethod="POST") * @return
@PostMapping(value = "/add") */
public Result<WeighInfo> add(@RequestBody WeighInfo weighInfo) { @ApiOperation(value = " 添加称重记录表信息", notes = "添加称重记录表信息", httpMethod = "POST")
Result<WeighInfo> result = new Result<WeighInfo>(); @PostMapping(value = "/add")
try { public Result<WeighInfo> add(@RequestBody WeighInfo weighInfo) {
weighInfoService.save(weighInfo); Result<WeighInfo> result = new Result<WeighInfo>();
result.success("添加成功!"); try {
} catch (Exception e) { weighInfoService.save(weighInfo);
e.printStackTrace(); result.success("添加成功!");
log.info(e.getMessage()); } catch (Exception e) {
result.error500("操作失败"); e.printStackTrace();
} log.info(e.getMessage());
return result; result.error500("操作失败");
} }
return result;
/** }
* 编辑
* @param weighInfo /**
* @return * 编辑
*/ *
@ApiOperation(value = "编辑称重记录表信息", notes = "编辑称重记录表信息" , httpMethod="POST") * @param weighInfo
@PostMapping(value = "/edit") * @return
public Result<WeighInfo> edit(@RequestBody WeighInfo weighInfo) { */
Result<WeighInfo> result = new Result<WeighInfo>(); @ApiOperation(value = "编辑称重记录表信息", notes = "编辑称重记录表信息", httpMethod = "POST")
WeighInfo weighInfoEntity = weighInfoService.getById(weighInfo.getId()); @PostMapping(value = "/edit")
if(weighInfoEntity==null) { public Result<WeighInfo> edit(@RequestBody WeighInfo weighInfo) {
result.error500("未找到对应实体"); Result<WeighInfo> result = new Result<WeighInfo>();
}else { WeighInfo weighInfoEntity = weighInfoService.getById(weighInfo.getId());
weighInfoService.updateById(weighInfo); if (weighInfoEntity == null) {
result.success("修改成功!"); result.error500("未找到对应实体");
} } else {
weighInfoService.updateById(weighInfo);
return result; result.success("修改成功!");
} }
/** return result;
* 通过id删除 }
* @param id
* @return /**
*/ * 通过id删除
@ApiOperation(value = "删除称重记录表信息", notes = "删除称重记录表信息" , httpMethod="POST") *
@PostMapping(value = "/delete") * @param id
public Result<WeighInfo> delete(@RequestBody String id) { * @return
JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); */
id = String.valueOf(jsonObject.get("id")); @ApiOperation(value = "删除称重记录表信息", notes = "删除称重记录表信息", httpMethod = "POST")
Result<WeighInfo> result = new Result<WeighInfo>(); @PostMapping(value = "/delete")
WeighInfo weighInfo = weighInfoService.getById(id); public Result<WeighInfo> delete(@RequestBody String id) {
if(weighInfo==null) { JSONObject jsonObject = JSON.parseObject(id, JSONObject.class);
result.error500("未找到对应实体"); id = String.valueOf(jsonObject.get("id"));
}else { Result<WeighInfo> result = new Result<WeighInfo>();
boolean ok = weighInfoService.removeById(id); WeighInfo weighInfo = weighInfoService.getById(id);
if(ok) { if (weighInfo == null) {
result.success("删除成功!"); result.error500("未找到对应实体");
} } else {
} boolean ok = weighInfoService.removeById(id);
if (ok) {
return result; result.success("删除成功!");
} }
}
/**
* 批量删除 return result;
* @param ids }
* @return
*/ /**
@ApiOperation(value = "批量删除称重记录表信息", notes = "批量删除称重记录表信息", httpMethod="POST") * 批量删除
*
* @param ids
* @return
*/
@ApiOperation(value = "批量删除称重记录表信息", notes = "批量删除称重记录表信息", httpMethod = "POST")
@ApiImplicitParam(name = "id", value = "称重记录表ID字符串", paramType = "query", required = true, dataType = "String") @ApiImplicitParam(name = "id", value = "称重记录表ID字符串", paramType = "query", required = true, dataType = "String")
@PostMapping(value = "/deleteBatch") @PostMapping(value = "/deleteBatch")
public Result<WeighInfo> deleteBatch(@RequestParam(name="ids",required=true) String ids) { public Result<WeighInfo> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
Result<WeighInfo> result = new Result<WeighInfo>(); Result<WeighInfo> result = new Result<WeighInfo>();
if(ids==null || "".equals(ids.trim())) { if (ids == null || "".equals(ids.trim())) {
result.error500("参数不识别!"); result.error500("参数不识别!");
}else { } else {
this.weighInfoService.removeByIds(Arrays.asList(ids.split(","))); this.weighInfoService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!"); result.success("删除成功!");
} }
return result; return result;
} }
/**
* 通过id查询
* @param id
* @return
*/
@ApiOperation(value = "通过id查询称重记录表信息", notes = "通过id查询称重记录表信息" , httpMethod="GET")
@ApiImplicitParam(name = "id", value = "称重记录表ID", paramType = "query", required = true, dataType = "Integer")
@GetMapping(value = "/queryById")
public Result<WeighInfo> queryById(@RequestParam(name="id",required=true) String id) {
Result<WeighInfo> result = new Result<WeighInfo>();
WeighInfo weighInfo = weighInfoService.getById(id);
if(weighInfo==null) {
result.error500("未找到对应实体");
}else {
result.setResult(weighInfo);
result.setSuccess(true);
}
return result;
}
/** /**
* 导出excel * 通过id查询
* *
* @param request * @param id
* @param response * @return
*/ */
@ApiOperation(value = "导出excel称重记录表信息", notes = "导出excel称重记录表信息" , httpMethod="POST") @ApiOperation(value = "通过id查询称重记录表信息", notes = "通过id查询称重记录表信息", httpMethod = "GET")
@RequestMapping(value = "/exportXls") @ApiImplicitParam(name = "id", value = "称重记录表ID", paramType = "query", required = true, dataType = "Integer")
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) { @GetMapping(value = "/queryById")
// Step.1 组装查询条件 public Result<WeighInfo> queryById(@RequestParam(name = "id", required = true) String id) {
QueryWrapper<WeighInfo> queryWrapper = null; Result<WeighInfo> result = new Result<WeighInfo>();
try { WeighInfo weighInfo = weighInfoService.getById(id);
String paramsStr = request.getParameter("paramsStr"); if (weighInfo == null) {
if (oConvertUtils.isNotEmpty(paramsStr)) { result.error500("未找到对应实体");
String deString = URLDecoder.decode(paramsStr, "UTF-8"); } else {
WeighInfo weighInfo = JSON.parseObject(deString, WeighInfo.class); result.setResult(weighInfo);
queryWrapper = QueryGenerator.initQueryWrapper(weighInfo, request.getParameterMap()); result.setSuccess(true);
} }
} catch (UnsupportedEncodingException e) { return result;
e.printStackTrace(); }
}
//Step.2 AutoPoi 导出Excel /**
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); * 导出excel
List<WeighInfo> pageList = weighInfoService.list(queryWrapper); *
//导出文件名称 * @param request
mv.addObject(NormalExcelConstants.FILE_NAME, "称重记录表列表"); * @param response
mv.addObject(NormalExcelConstants.CLASS, WeighInfo.class); */
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("称重记录表列表数据", "导出人:Jeecg", "导出信息")); @ApiOperation(value = "导出excel称重记录表信息", notes = "导出excel称重记录表信息", httpMethod = "POST")
mv.addObject(NormalExcelConstants.DATA_LIST, pageList); @RequestMapping(value = "/exportXls")
return mv; public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
} // Step.1 组装查询条件
QueryWrapper<WeighInfo> queryWrapper = null;
try {
String paramsStr = request.getParameter("paramsStr");
if (oConvertUtils.isNotEmpty(paramsStr)) {
String deString = URLDecoder.decode(paramsStr, "UTF-8");
WeighInfo weighInfo = JSON.parseObject(deString, WeighInfo.class);
queryWrapper = QueryGenerator.initQueryWrapper(weighInfo, request.getParameterMap());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
/** //Step.2 AutoPoi 导出Excel
* 通过excel导入数据 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
* List<WeighInfo> pageList = weighInfoService.list(queryWrapper);
* @param request //导出文件名称
* @param response mv.addObject(NormalExcelConstants.FILE_NAME, "称重记录表列表");
* @return mv.addObject(NormalExcelConstants.CLASS, WeighInfo.class);
*/ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("称重记录表列表数据", "导出人:Jeecg", "导出信息"));
@ApiOperation(value = "通过excel导入称重记录表信息", notes = "通过excel导入称重记录表信息", httpMethod="POST") mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) return mv;
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { }
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); /**
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { * 通过excel导入数据
MultipartFile file = entity.getValue();// 获取上传文件对象 *
ImportParams params = new ImportParams(); * @param request
params.setTitleRows(2); * @param response
params.setHeadRows(1); * @return
params.setNeedSave(true); */
try { @ApiOperation(value = "通过excel导入称重记录表信息", notes = "通过excel导入称重记录表信息", httpMethod = "POST")
List<WeighInfo> listWeighInfos = ExcelImportUtil.importExcel(file.getInputStream(), WeighInfo.class, params); @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
for (WeighInfo weighInfoExcel : listWeighInfos) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
weighInfoService.save(weighInfoExcel); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
} Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
return Result.ok("文件导入成功!数据行数:" + listWeighInfos.size()); for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
} catch (Exception e) { MultipartFile file = entity.getValue();// 获取上传文件对象
log.error(e.getMessage()); ImportParams params = new ImportParams();
return Result.error("文件导入失败!"); params.setTitleRows(2);
} finally { params.setHeadRows(1);
try { params.setNeedSave(true);
file.getInputStream().close(); try {
} catch (IOException e) { List<WeighInfo> listWeighInfos = ExcelImportUtil.importExcel(file.getInputStream(), WeighInfo.class, params);
e.printStackTrace(); for (WeighInfo weighInfoExcel : listWeighInfos) {
} weighInfoService.save(weighInfoExcel);
} }
} return Result.ok("文件导入成功!数据行数:" + listWeighInfos.size());
return Result.ok("文件导入失败!"); } catch (Exception e) {
} log.error(e.getMessage());
return Result.error("文件导入失败!");
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.ok("文件导入失败!");
}
} }

View File

@ -83,7 +83,7 @@ public class WeighPicController {
} }
/** /**
* 添加 * 现场端添加称重图片信息
* *
* @param weighPic * @param weighPic
* @return * @return

View File

@ -1,80 +1,117 @@
package com.zhgd.xmgl.modules.weight.entity; package com.zhgd.xmgl.modules.weight.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
/** /**
* @Description: 过磅预约车辆信息 * @Description: 过磅预约车辆信息
* @author pds * @author pds
* @date 2023-03-21 * @date 2023-03-21
* @version V1.0 * @version V1.0
*/ */
@Data @Data
@TableName("weigh_book_vehicle_info") @TableName("weigh_book_vehicle_info")
@ApiModel(value="WeighBookVehicleInfo实体类",description="WeighBookVehicleInfo") @ApiModel(value = "WeighBookVehicleInfo实体类", description = "WeighBookVehicleInfo")
public class WeighBookVehicleInfo implements Serializable { public class WeighBookVehicleInfo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**主键id*/ /**
@TableId(type = IdType.ASSIGN_ID) * 主键id
@ApiModelProperty(value="主键id") */
private java.lang.Long id ; @TableId(type = IdType.ASSIGN_ID)
/**车牌号码*/ @ApiModelProperty(value = "主键id")
@Excel(name = "车牌号码", width = 15) private java.lang.Long id;
@ApiModelProperty(value="车牌号码") /**
private java.lang.String licensePlate ; * 车牌号码
/**发货单位*/ */
@Excel(name = "发货单位", width = 15) @Excel(name = "车牌号码", width = 15)
@ApiModelProperty(value="发货单位") @ApiModelProperty(value = "车牌号码")
private java.lang.String forwardingUnit ; private java.lang.String licensePlate;
/**收货单位*/ /**
@Excel(name = "收货单位", width = 15) * 发货单位
@ApiModelProperty(value="收货单位") */
private java.lang.String receivingUnit ; @Excel(name = "发货单位", width = 15)
/**货名*/ @ApiModelProperty(value = "发货单位")
@Excel(name = "货名", width = 15) private java.lang.String forwardingUnit;
@ApiModelProperty(value="货名") /**
private java.lang.String goodsName ; * 收货单位
/**规格*/ */
@Excel(name = "规格", width = 15) @Excel(name = "收货单位", width = 15)
@ApiModelProperty(value="规格") @ApiModelProperty(value = "收货单位")
private java.lang.String specifications ; private java.lang.String receivingUnit;
/**备注*/ /**
@Excel(name = "备注", width = 15) * 货名
@ApiModelProperty(value="备注") */
private java.lang.String reserve ; @Excel(name = "货名", width = 15)
/**过磅类型*/ @ApiModelProperty(value = "货名")
@Excel(name = "过磅类型", width = 15) private java.lang.String goodsName;
@ApiModelProperty(value="过磅类型") /**
private java.lang.Integer weighingType ; * 规格
/**录入时间*/ */
@Excel(name = "录入时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @Excel(name = "规格", width = 15)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "规格")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private java.lang.String specifications;
@ApiModelProperty(value="录入时间") /**
private java.util.Date addDateTime ; * 备注
/**创建时间*/ */
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @Excel(name = "备注", width = 15)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "备注")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private java.lang.String reserve;
@ApiModelProperty(value="创建时间") /**
private java.util.Date createTime ; * 过磅类型
/**更新时间*/ */
@Excel(name = "更新时间", width = 20, format = "yyyy-MM-dd HH:mm:ss") @Excel(name = "过磅类型", width = 15)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "过磅类型")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private java.lang.Integer weighingType;
@ApiModelProperty(value="更新时间") /**
private java.util.Date updateTime ; * 录入时间
/**所属项目SN*/ */
@Excel(name = "所属项目SN", width = 15) @Excel(name = "录入时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value="所属项目SN") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private java.lang.String projectSn ; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "录入时间")
private java.util.Date addDateTime;
/**
* 创建时间
*/
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private java.util.Date createTime;
/**
* 更新时间
*/
@Excel(name = "更新时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间")
private java.util.Date updateTime;
/**
* 所属项目SN
*/
@Excel(name = "所属项目SN", width = 15)
@ApiModelProperty(value = "所属项目SN")
private java.lang.String projectSn;
/**
* 现场上次拉取的时间
*/
@TableField(exist = false)
private String lastAddTime;
/**
* 上次查询的id查询这个id数据之后的数据不返回这条id数据
*/
@TableField(exist = false)
private Long lastQueryId;
} }

View File

@ -1,8 +1,12 @@
package com.zhgd.xmgl.modules.weight.service; package com.zhgd.xmgl.modules.weight.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.weight.entity.WeighBookVehicleInfo; import com.zhgd.xmgl.modules.weight.entity.WeighBookVehicleInfo;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletRequest;
/** /**
* @Description: 过磅预约车辆信息 * @Description: 过磅预约车辆信息
* @author pds * @author pds
@ -11,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface IWeighBookVehicleInfoService extends IService<WeighBookVehicleInfo> { public interface IWeighBookVehicleInfoService extends IService<WeighBookVehicleInfo> {
Result<IPage<WeighBookVehicleInfo>> queryPageList(WeighBookVehicleInfo weighBookVehicleInfo, Integer pageNo, Integer pageSize, HttpServletRequest req);
} }

View File

@ -1,19 +1,51 @@
package com.zhgd.xmgl.modules.weight.service.impl; package com.zhgd.xmgl.modules.weight.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.weight.entity.WeighBookVehicleInfo; import com.zhgd.xmgl.modules.weight.entity.WeighBookVehicleInfo;
import com.zhgd.xmgl.modules.weight.mapper.WeighBookVehicleInfoMapper; import com.zhgd.xmgl.modules.weight.mapper.WeighBookVehicleInfoMapper;
import com.zhgd.xmgl.modules.weight.service.IWeighBookVehicleInfoService; import com.zhgd.xmgl.modules.weight.service.IWeighBookVehicleInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import javax.servlet.http.HttpServletRequest;
/** /**
* @Description: 过磅预约车辆信息 * @Description: 过磅预约车辆信息
* @author pds * @author pds
* @date 2023-03-21 * @date 2023-03-21
* @version V1.0 * @version V1.0
*/ */
@Service @Service
public class WeighBookVehicleInfoServiceImpl extends ServiceImpl<WeighBookVehicleInfoMapper, WeighBookVehicleInfo> implements IWeighBookVehicleInfoService { public class WeighBookVehicleInfoServiceImpl extends ServiceImpl<WeighBookVehicleInfoMapper, WeighBookVehicleInfo> implements IWeighBookVehicleInfoService {
@Override
public Result queryPageList(WeighBookVehicleInfo weighBookVehicleInfo, Integer pageNo, Integer pageSize, HttpServletRequest req) {
if (StringUtils.isBlank(weighBookVehicleInfo.getProjectSn())) {
return Result.error("projectSn不能为空");
}
String lastAdddatetime = weighBookVehicleInfo.getLastAddTime();
Long lastQueryId = weighBookVehicleInfo.getLastQueryId();
Result<IPage<WeighBookVehicleInfo>> result = new Result<IPage<WeighBookVehicleInfo>>();
LambdaQueryWrapper<WeighBookVehicleInfo> queryWrapper = new LambdaQueryWrapper<WeighBookVehicleInfo>()
.eq(StringUtils.isNotBlank(weighBookVehicleInfo.getProjectSn()), WeighBookVehicleInfo::getProjectSn, weighBookVehicleInfo.getProjectSn())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getSpecifications()), WeighBookVehicleInfo::getSpecifications, weighBookVehicleInfo.getSpecifications())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getGoodsName()), WeighBookVehicleInfo::getGoodsName, weighBookVehicleInfo.getGoodsName())
.like(StringUtils.isNotBlank(weighBookVehicleInfo.getLicensePlate()), WeighBookVehicleInfo::getLicensePlate, weighBookVehicleInfo.getLicensePlate())
.gt(lastQueryId != null, WeighBookVehicleInfo::getId, lastQueryId);
if (StringUtils.isNotBlank(lastAdddatetime)) {
DateTime dateTime = DateUtil.parse(lastAdddatetime);
queryWrapper.ge(WeighBookVehicleInfo::getAddDateTime, dateTime);
}
Page<WeighBookVehicleInfo> page = new Page<WeighBookVehicleInfo>(pageNo, pageSize);
IPage<WeighBookVehicleInfo> pageList = page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
} }