| | |
| | | package com.stylefeng.guns.modular.system.controller; |
| | | |
| | | |
| | | import com.alibaba.druid.support.json.JSONUtils; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.stylefeng.guns.core.base.tips.ErrorTip; |
| | | import com.stylefeng.guns.core.common.constant.JwtConstants; |
| | | import com.stylefeng.guns.core.common.exception.BizExceptionEnum; |
| | | import com.stylefeng.guns.core.exception.GunsException; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.modular.system.dto.QuestionDto; |
| | | import com.stylefeng.guns.modular.system.model.TDevice; |
| | | import com.stylefeng.guns.modular.system.model.TUserData; |
| | | import com.stylefeng.guns.modular.system.model.TUserDateData; |
| | | import com.stylefeng.guns.modular.system.model.User; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.ITDeviceService; |
| | | import com.stylefeng.guns.modular.system.service.ITUserDataService; |
| | | import com.stylefeng.guns.modular.system.service.ITUserDateDataService; |
| | | import com.stylefeng.guns.modular.system.service.IUserService; |
| | | import com.stylefeng.guns.modular.system.util.R; |
| | | import com.stylefeng.guns.modular.system.util.RedisService; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.InputStream; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R<TDevice> checkeq(HttpServletRequest request){ |
| | | public R checkeq(HttpServletRequest request){ |
| | | Integer uid = redisService.getCacheObject(request.getHeader(JwtConstants.AUTH_HEADER)); |
| | | |
| | | List<TDevice> bindId = deviceService.selectList(new EntityWrapper<TDevice>().eq("bindId", uid)); |
| | | if (bindId.isEmpty()){ |
| | | return R.fail("未绑定硬件"); |
| | | return R.fail("当前用户暂未绑定设备"); |
| | | } |
| | | |
| | | return R.ok(bindId.get(0)); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/unbind") |
| | | @ApiOperation(value = "解绑", tags = {"App接口"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R unbind(HttpServletRequest request){ |
| | | Integer uid = redisService.getCacheObject(request.getHeader(JwtConstants.AUTH_HEADER)); |
| | | |
| | | List<TDevice> bindId = deviceService.selectList(new EntityWrapper<TDevice>().eq("bindId", uid)); |
| | | |
| | | for (TDevice tDevice : bindId) { |
| | | deviceService.deleteById(tDevice.getId()); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ResponseBody |
| | |
| | | device.setBindId(uid); |
| | | if (deviceService.selectList(new EntityWrapper<TDevice>().eq("mac", device.getMac())).isEmpty()) { |
| | | device.setBindId(uid); |
| | | device.setBindTime(new Date()); |
| | | deviceService.insert(device); |
| | | }else { |
| | | TDevice serNum = deviceService.selectOne(new EntityWrapper<TDevice>().eq("serNum", device.getSerNum())); |
| | | serNum.setBindId(uid); |
| | | serNum.setBindTime(new Date()); |
| | | deviceService.updateById(serNum); |
| | | } |
| | | return R.ok(); |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R<PageInfo<TUserDateData>> datalist(HttpServletRequest request,Integer pageNum,Integer pageSize,Integer night,String date) { |
| | | public R<PageInfo<TUserDateData>> datalist(HttpServletRequest request, Integer pageNum, Integer pageSize, Integer night, String date) { |
| | | Integer userId = redisService.getCacheObject(request.getHeader(JwtConstants.AUTH_HEADER)); |
| | | |
| | | PageHelper.startPage(pageNum,pageSize); |
| | |
| | | |
| | | tUserDateDataEntityWrapper.setSqlSelect("id","date","night"); |
| | | List<TUserDateData> tUserDateData = dateDataService.selectList(tUserDateDataEntityWrapper); |
| | | for (TUserDateData tUserDateDatum : tUserDateData) { |
| | | tUserDateDatum.setTUserDataArray(new TUserData[]{}); |
| | | } |
| | | PageInfo<TUserDateData> info=new PageInfo<>(tUserDateData); |
| | | System.err.println(info); |
| | | |
| | | return R.ok(info); |
| | | |
| | | } |
| | | |
| | | @PostMapping("/api/clear") |
| | | @ApiOperation(value = "设备clear", tags = {"App接口"}, notes = "") |
| | | @ResponseBody |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R clear(String serNum) { |
| | | //获取当天18点的时间 |
| | | redisService.setCacheObject("CLEAR:"+serNum, new Date()); |
| | | |
| | | return R.ok(); |
| | | |
| | | |
| | | } |
| | | |
| | | @PostMapping("/api/ifclear") |
| | | @ApiOperation(value = "设备是否需要clear", tags = {"App接口"}, notes = "") |
| | | @ResponseBody |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R ifclear(String serNum) { |
| | | //获取当天18点的时间 |
| | | Date cacheObject = redisService.getCacheObject("CLEAR:"+serNum); |
| | | |
| | | if (cacheObject!=null){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 18); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | |
| | | Date dateAt1800 = calendar.getTime(); |
| | | if (cacheObject.before(dateAt1800)){ |
| | | return R.ok(false); |
| | | }else { |
| | | return R.ok(true); |
| | | } |
| | | }else { |
| | | return R.ok(true); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/api/link") |
| | | @ApiOperation(value = "设备连接断开", tags = {"App接口"}, notes = "") |
| | | @ResponseBody |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R link(@RequestBody LinkQuery linkQuery) { |
| | | TDevice serNum = deviceService.selectOne(new EntityWrapper<TDevice>().eq("serNum", linkQuery.getSerNum())); |
| | | serNum.setStatus(linkQuery.getStatus()); |
| | | deviceService.updateById(serNum); |
| | | if (linkQuery.getStatus()==0){ |
| | | Long timestamp = new Date().getTime(); |
| | | redisService.setCacheObject(linkQuery.getSerNum(), timestamp.toString()); |
| | | } |
| | | return R.ok(); |
| | | |
| | | |
| | | } |
| | | |
| | | @PostMapping("/api/last") |
| | | @ApiOperation(value = "获取上次断开时间", tags = {"App接口"}, notes = "") |
| | | @ResponseBody |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R last(String serNum) { |
| | | String date = (String)redisService.getCacheObject(serNum); |
| | | return R.ok(date); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @PostMapping("/api/datadetail") |
| | | @ApiOperation(value = "检测记录详情", tags = {"App接口"}, notes = "") |
| | |
| | | }) |
| | | public R<TUserDateData> datadetail(HttpServletRequest request,Integer dataId) { |
| | | TUserDateData tUserDateData = dateDataService.selectById(dataId); |
| | | |
| | | |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | TUserData[] tUserDataArray = new TUserData[]{}; |
| | | try { |
| | | // 将JSON字符串转换为TUserData数组 |
| | | tUserDataArray = mapper.readValue(tUserDateData.getData(), TUserData[].class); |
| | | for (TUserData tUserData : tUserDataArray) { |
| | | tUserData.setTime(tUserData.getDetectionTime().getTime()); |
| | | } |
| | | tUserDateData.setTUserDataArray(tUserDataArray); |
| | | // 打印转换后的数组,以便验证 |
| | | System.out.println(Arrays.toString(tUserDataArray)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | tUserDateData.setData(null); |
| | | |
| | | return R.ok(tUserDateData); |
| | | |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public R pulldata(HttpServletRequest request, @RequestBody List<TUserData> data){ |
| | | public R pulldata(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws ParseException, JsonProcessingException { |
| | | Integer uid = redisService.getCacheObject(request.getHeader(JwtConstants.AUTH_HEADER)); |
| | | List<TUserData> data = new ArrayList<>(); |
| | | |
| | | data = userDataService.selectList(null); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | Workbook book = WoUtil.ImportFile(file); |
| | | Sheet sh = book.getSheetAt(0); //获取到第一个表 |
| | | for (int i = 1; i <= sh.getLastRowNum(); i++) { |
| | | Row row = sh.getRow(i); |
| | | |
| | | |
| | | Cell cell2 = row.getCell(2); //所属加盟商[提示:加盟车辆选填] |
| | | Integer two = null; |
| | | if (SinataUtil.isNotEmpty(cell2)) { |
| | | two = (int)cell2.getNumericCellValue(); |
| | | } |
| | | |
| | | |
| | | Cell cell4 = row.getCell(4); //服务模式:出租车[是/否] |
| | | String four = null; |
| | | if (SinataUtil.isNotEmpty(cell4)) { |
| | | four = String.valueOf(cell4.getStringCellValue()).trim(); |
| | | } |
| | | |
| | | Cell cell5 = row.getCell(1); // 服务模式: 出租车[是/否] |
| | | Date five = null; |
| | | int divisor = 5; |
| | | if (SinataUtil.isNotEmpty(cell5)) { |
| | | double numericValue = cell5.getNumericCellValue(); |
| | | long timestamp = (long) numericValue; // 如果数值是整数毫秒时间戳 |
| | | five = new Date(timestamp); |
| | | long seconds = timestamp / 1000; |
| | | |
| | | // 判断秒数是否为divisor的倍数 |
| | | boolean isMultiple = seconds % divisor == 0; |
| | | if (!isMultiple){ |
| | | // continue; |
| | | } |
| | | } else { |
| | | // 处理单元格为空的情况 |
| | | } |
| | | // System.err.println("===="); |
| | | TUserData tUserData = new TUserData(); |
| | | tUserData.setUserId(uid); |
| | | tUserData.setDetectionTime(five); |
| | | tUserData.setPosition(four); |
| | | tUserData.setShapeVariable(Integer.valueOf(two)); |
| | | data.add(tUserData); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // data = userDataService.selectList(null); |
| | | Map<String, List<TUserData>> groupedData = data.stream() |
| | | .collect(Collectors.groupingBy( |
| | | item -> { |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<TUserData> list = Arrays.asList(tUserDataArray); |
| | | list.addAll(entry.getValue()); |
| | | List<TUserData> list = new ArrayList<>(); // 初始化一个空的 ArrayList |
| | | list.addAll(Arrays.asList(tUserDataArray)); // 将原始数组添加到列表中 |
| | | List<TUserData> value = entry.getValue(); |
| | | list.addAll(value); |
| | | String jsonInString = mapper.writeValueAsString(list); |
| | | tUserDateData1.setData(jsonInString); |
| | | dateDataService.updateById(tUserDateData1); |
| | | }else { |
| | | TUserDateData tUserDateData2 = new TUserDateData(); |