From 01313c43c4efaedd7c6243f0ab5deeffcd7549c5 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Wed, 31 Jan 2024 19:15:13 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=84=9F=E7=9F=A5id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcOrganizationController.java | 6 +- .../controller/DcShiftsController.java | 27 +++- .../java/com/zc/business/domain/DcShifts.java | 46 ++++-- .../com/zc/business/domain/DcShiftsList.java | 120 +++++++++++++++ .../zc/business/domain/DcShiftsRecord.java | 12 +- .../zc/business/mapper/DcShiftsMapper.java | 8 +- .../zc/business/service/IDcShiftsService.java | 7 +- .../service/impl/DcShiftsServiceImpl.java | 137 +++++++++++++----- .../mapper/business/DcShiftsMapper.xml | 28 +++- 9 files changed, 321 insertions(+), 70 deletions(-) create mode 100644 zc-business/src/main/java/com/zc/business/domain/DcShiftsList.java diff --git a/zc-business/src/main/java/com/zc/business/controller/DcOrganizationController.java b/zc-business/src/main/java/com/zc/business/controller/DcOrganizationController.java index f9c05daf..3c13893c 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcOrganizationController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcOrganizationController.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.core.page.TableDataInfo; import com.zc.business.domain.DcOrganizationExport; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -47,10 +48,11 @@ public class DcOrganizationController extends BaseController @PreAuthorize("@ss.hasPermi('business:organization:list')") @GetMapping("/list") - public AjaxResult list(DcOrganization dcOrganization) + public TableDataInfo list(DcOrganization dcOrganization) { + startPage(); ArrayList hashMaps = dcOrganizationService.selectDcOrganizationList(dcOrganization); - return AjaxResult.success(hashMaps); + return getDataTable(hashMaps); } /** diff --git a/zc-business/src/main/java/com/zc/business/controller/DcShiftsController.java b/zc-business/src/main/java/com/zc/business/controller/DcShiftsController.java index 2f3662f7..3218544b 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcShiftsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcShiftsController.java @@ -3,8 +3,14 @@ package com.zc.business.controller; import java.io.InputStream; import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonElement; +import com.ruoyi.common.utils.StringUtils; import com.zc.business.domain.DcShiftsRecord; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -12,6 +18,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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.Mapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; @@ -28,7 +35,8 @@ import com.zc.business.service.IDcShiftsService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.web.multipart.MultipartFile; - +import springfox.documentation.spring.web.json.Json; +import com.google.gson.*; /** * 值班Controller * @@ -52,7 +60,7 @@ public class DcShiftsController extends BaseController public TableDataInfo list(DcShifts dcShifts) { startPage(); - List list = dcShiftsService.selectDcShiftsList(dcShifts); + List list = dcShiftsService.selectDcShiftsList(dcShifts); return getDataTable(list); } @@ -113,6 +121,15 @@ public class DcShiftsController extends BaseController public AjaxResult remove(@PathVariable Long[] ids) throws Exception{ return toAjax(dcShiftsService.deleteDcShiftsByIds(ids)); } + /** + * 删除值班,某个时间下驻点下的全部值班信息 + */ + @PreAuthorize("@ss.hasPermi('business:shifts:remove')") + @Log(title = "值班", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public AjaxResult removeDelete(@RequestBody DcShifts shifts) throws Exception{ + return toAjax(dcShiftsService.deleteDcShiftsListId(shifts)); + } //导出模板 @ApiOperation("导出模板") @@ -145,11 +162,11 @@ public class DcShiftsController extends BaseController * 查询操作记录 */ @ApiOperation("查询操作记录") - @GetMapping("/recordList") - public TableDataInfo recordList() + @PostMapping("/recordList") + public TableDataInfo recordList(@RequestBody DcShifts dcShifts) { startPage(); - List list = dcShiftsService.selectDcShiftsRecord(); + List list = dcShiftsService.selectDcShiftsRecord(dcShifts); return getDataTable(list); } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcShifts.java b/zc-business/src/main/java/com/zc/business/domain/DcShifts.java index 554c248b..f07b648a 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcShifts.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcShifts.java @@ -1,6 +1,10 @@ package com.zc.business.domain; import java.util.Date; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -8,6 +12,9 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import java.util.HashMap; +import java.util.List; + /** * 值班对象 dc_shifts * @@ -23,9 +30,6 @@ public class DcShifts extends BaseEntity private Long idBefore; - /** 所属路管驻点 */ - @Excel(name = "所属路管驻点") - private Long stationId; /** 当值人员ID */ @ApiModelProperty(value = "当值人员ID", required = true) @@ -72,16 +76,37 @@ public class DcShifts extends BaseEntity @ApiModelProperty("驻点id") @Excel(name = "驻点id") - private String station; + private Long station; + + private JSONArray employeesJson; + + public JSONArray getEmployeesJson() { + return employeesJson; + } + + public void setEmployeesJson(JSONArray employeesJson) { + this.employeesJson = employeesJson; + } + + private List shiftsList; + + public List getShiftsList() { + return shiftsList; + } + + public void setShiftsList(List shiftsList) { + this.shiftsList = shiftsList; + } + public String getScheduling() { return scheduling; } - public String getStation() { + public Long getStation() { return station; } - public void setStation(String station) { + public void setStation(Long station) { this.station = station; } @@ -138,15 +163,7 @@ public class DcShifts extends BaseEntity { return id; } - public void setStationId(Long stationId) - { - this.stationId = stationId; - } - public Long getStationId() - { - return stationId; - } public void setEmployeesId(Long employeesId) { this.employeesId = employeesId; @@ -188,7 +205,6 @@ public class DcShifts extends BaseEntity public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("id", getId()) - .append("stationId", getStationId()) .append("employeesId", getEmployeesId()) .append("date", getDate()) .append("startTime", getStartTime()) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcShiftsList.java b/zc-business/src/main/java/com/zc/business/domain/DcShiftsList.java new file mode 100644 index 00000000..2f85f023 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcShiftsList.java @@ -0,0 +1,120 @@ +package com.zc.business.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModelProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; + +/** + * @author 王思祥 + * @ClassName DcShiftsList + */ + +public class DcShiftsList { + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** 当值人员ID */ + @ApiModelProperty(value = "当值人员ID", required = true) + @Excel(name = "当值人员ID") + private Long employeesId; + + + + @Excel(name = "姓名") + private String name; + @Excel(name = "所属路管驻点名称") + private String organizationName; + @ApiModelProperty("排班 1-白班 2-夜班") + @Excel(name = "排班 1-白班 2-夜班") + private String scheduling; + @ApiModelProperty("驻点id") + @Excel(name = "驻点id") + private String station; + @Excel(name = "手机号") + private String contactNumber; + + + public String getContactNumber() { + return contactNumber; + } + + public void setContactNumber(String contactNumber) { + this.contactNumber = contactNumber; + } + + public String getScheduling() { + return scheduling; + } + + public String getStation() { + return station; + } + + public void setStation(String station) { + this.station = station; + } + + public void setScheduling(String scheduling) { + this.scheduling = scheduling; + } + + + + public String getOrganizationName() { + return organizationName; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setEmployeesId(Long employeesId) + { + this.employeesId = employeesId; + } + + public Long getEmployeesId() + { + return employeesId; + } + + + + + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("employeesId", getEmployeesId()) + .toString(); + } +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcShiftsRecord.java b/zc-business/src/main/java/com/zc/business/domain/DcShiftsRecord.java index 000b44cf..d59b2c2b 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcShiftsRecord.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcShiftsRecord.java @@ -29,7 +29,7 @@ public class DcShiftsRecord extends BaseEntity private String operationType; /** 操作时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd") private Date operationTime; @@ -44,6 +44,8 @@ public class DcShiftsRecord extends BaseEntity @Excel(name = "值班人员") private String nickName; + @Excel(name = "驻点id") + private Long station; public String getNickName() { return nickName; @@ -108,6 +110,14 @@ public class DcShiftsRecord extends BaseEntity return shiftsDate; } + public Long getStation() { + return station; + } + + public void setStation(Long station) { + this.station = station; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcShiftsMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcShiftsMapper.java index edd32b00..dff1b9d3 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcShiftsMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcShiftsMapper.java @@ -4,6 +4,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import com.zc.business.domain.DcShifts; +import com.zc.business.domain.DcShiftsList; import com.zc.business.domain.DcShiftsRecord; import org.apache.ibatis.annotations.Param; import org.apache.poi.hssf.record.DConRefRecord; @@ -80,7 +81,12 @@ public interface DcShiftsMapper */ public DcShifts selectDcShiftsByEmployeesId(Long id); //查询操作记录表 - public List selectDcShiftsRecord(); + public List selectDcShiftsRecord(DcShifts dcShifts); //根据驻点和时间查询人员 public List> selectStation(@Param("station") String station,@Param("date") Date date); + public List selectStationDate(@Param("station") Long station, @Param("date") Date date); + //新增时查看是否存在 + Long selectExist(DcShifts dcShifts); + //查看部分信息,删除使用 + List selectDcShiftsDeleteList(DcShifts dcShifts); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcShiftsService.java b/zc-business/src/main/java/com/zc/business/service/IDcShiftsService.java index 14df2e1d..f75df56f 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcShiftsService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcShiftsService.java @@ -30,7 +30,8 @@ public interface IDcShiftsService * @param dcShifts 值班 * @return 值班集合 */ - List selectDcShiftsList(DcShifts dcShifts); + List selectDcShiftsList(DcShifts dcShifts); + List selectDcShiftsListExcel(DcShifts dcShifts); /** @@ -56,7 +57,7 @@ public interface IDcShiftsService * @return 结果 */ int deleteDcShiftsByIds(Long[] ids)throws Exception; - + int deleteDcShiftsListId(DcShifts dcShifts)throws Exception; /** * 删除值班信息 * @@ -68,5 +69,5 @@ public interface IDcShiftsService //导入文档数据 public AjaxResult importEquipment(MultipartFile file) throws Exception; //查询操作记录表 - public List selectDcShiftsRecord(); + public List selectDcShiftsRecord(DcShifts dcShifts); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcShiftsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcShiftsServiceImpl.java index c6e18394..d2235c55 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcShiftsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcShiftsServiceImpl.java @@ -1,13 +1,19 @@ package com.zc.business.service.impl; +import com.alibaba.fastjson.JSON; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.domain.DcEmployees; import com.zc.business.domain.DcShifts; +import com.zc.business.domain.DcShiftsList; import com.zc.business.domain.DcShiftsRecord; import com.zc.business.mapper.DcEmployeesMapper; import com.zc.business.mapper.DcShiftsMapper; @@ -19,13 +25,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.validation.Validator; -import java.lang.reflect.Array; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; /** * 值班Service业务层处理 @@ -62,23 +65,30 @@ public class DcShiftsServiceImpl implements IDcShiftsService * @return 值班 */ @Override - public List selectDcShiftsList(DcShifts dcShifts) + public List selectDcShiftsList(DcShifts dcShifts) { - List objects = new ArrayList<>(); +// ArrayList objects = new ArrayList<>(); + ArrayList objects = new ArrayList<>(); List list = dcShiftsMapper.selectDcShiftsList(dcShifts); - for (DcShifts shifts:list){ - HashMap map = new HashMap(); + for (DcShifts shifts:list ){ Date date = shifts.getDate(); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - String formattedDate = formatter.format(date); - String station = shifts.getStation(); - List> name = dcShiftsMapper.selectStation(station, date); - map.put("date",formattedDate); - map.put("organizationName",name); - - objects.add(map); + Long station = shifts.getStation(); + List organizationName = dcShiftsMapper.selectStationDate(station, date); + shifts.setShiftsList(organizationName); + objects.add(shifts); } - return objects; +// for (DcShifts shifts:list){ +// HashMap map = new HashMap(); +// Date date = shifts.getDate(); +// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); +// String formattedDate = formatter.format(date); +// String station = shifts.getStation(); +// List> name = dcShiftsMapper.selectStation(station, date); +// map.put("date",formattedDate); +// map.put("organizationName",name); +// objects.add(map); +// } + return list; } @Override @@ -95,27 +105,45 @@ public class DcShiftsServiceImpl implements IDcShiftsService @Override @Transactional(rollbackFor = ServiceException.class) public int insertDcShifts(DcShifts dcShifts) throws Exception{ - dcShifts.setCreateTime(DateUtils.getNowDate()); - int shifts = dcShiftsMapper.insertDcShifts(dcShifts); String msg = ""; - if (shifts==0){ - msg="新增用户信息失败"; - throw new ServiceException(msg); - } - DcShiftsRecord dcShiftsRecord = new DcShiftsRecord(); - dcShiftsRecord.setOperator(SecurityUtils.getUserId());//操作人员id - dcShiftsRecord.setOperationType("Add");//操作类型 - dcShiftsRecord.setOperationTime(DateUtils.getNowDate());//操作时间 - dcShiftsRecord.setShiftsDate(dcShifts.getDate());//值班日期 - Long employeesId = dcShifts.getEmployeesId();//新增人员id - DcEmployees dcEmployees = dcEmployeesMapper.selectDcEmployeesById(employeesId); - String name = dcEmployees.getName();//新增人员名称 - dcShiftsRecord.setModifyContent("新增值班人员"+name); - dcShifts.setCreateTime(DateUtils.getNowDate()); - int shiftsRecord = dcShiftsMapper.insertDcShiftsRecord(dcShiftsRecord); - if (shiftsRecord==0){ - msg="操作日志记录失败"; - throw new ServiceException(msg); + JSON employeesJson = dcShifts.getEmployeesJson(); + JsonElement jsonElement = new JsonParser().parse(String.valueOf(employeesJson)); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + for (JsonElement element : jsonArray) { + Long employeesId = element.getAsJsonObject().get("employeesId").getAsLong(); + Long station = element.getAsJsonObject().get("station").getAsLong(); + String scheduling = element.getAsJsonObject().get("scheduling").getAsString(); + if (employeesId!=null&&station!=null&& StringUtils.isNotEmpty(scheduling)){ + dcShifts.setEmployeesId(employeesId); + dcShifts.setStation(station); + dcShifts.setScheduling(scheduling); + Long aLong = dcShiftsMapper.selectExist(dcShifts); + if (aLong!=0){ + continue; + } + } + dcShifts.setCreateTime(DateUtils.getNowDate()); + int shifts = dcShiftsMapper.insertDcShifts(dcShifts); + if (shifts==0){ + msg="新增用户信息失败"; + throw new ServiceException(msg); + } + DcShiftsRecord dcShiftsRecord = new DcShiftsRecord(); + dcShiftsRecord.setOperator(SecurityUtils.getUserId());//操作人员id + dcShiftsRecord.setOperationType("Add");//操作类型 + dcShiftsRecord.setOperationTime(DateUtils.getNowDate());//操作时间 + dcShiftsRecord.setShiftsDate(dcShifts.getDate());//值班日期 + Long employeesIdS = dcShifts.getEmployeesId();//新增人员id + DcEmployees dcEmployees = dcEmployeesMapper.selectDcEmployeesById(employeesIdS); + String name = dcEmployees.getName();//新增人员名称 + dcShiftsRecord.setModifyContent("新增值班人员"+name); + dcShifts.setCreateTime(DateUtils.getNowDate()); + dcShiftsRecord.setStation(station);//驻点 + int shiftsRecord = dcShiftsMapper.insertDcShiftsRecord(dcShiftsRecord); + if (shiftsRecord==0){ + msg="操作日志记录失败"; + throw new ServiceException(msg); + } } return 1; } @@ -153,6 +181,7 @@ public class DcShiftsServiceImpl implements IDcShiftsService dcShiftsRecord.setOperationTime(DateUtils.getNowDate());//操作时间 dcShiftsRecord.setShiftsDate(dcShiftsById.getDate());//值班日期 dcShiftsRecord.setModifyContent("岗位" + postNameBefore + "姓名" + nameBefore + "修改为" + postName + name); + dcShiftsRecord.setStation(dcShiftsById.getStation());//驻点 int shiftsRecord = dcShiftsMapper.insertDcShiftsRecord(dcShiftsRecord); if (shiftsRecord == 0) { msg = "操作日志记录失败"; @@ -186,6 +215,37 @@ public class DcShiftsServiceImpl implements IDcShiftsService dcShiftsRecord.setOperationTime(DateUtils.getNowDate());//操作时间 dcShiftsRecord.setModifyContent("删除值班人员"+name); dcShiftsRecord.setShiftsDate(dcShifts.getDate());//值班日期 + dcShiftsRecord.setStation(dcShifts.getStation());//驻点 + int shiftsRecord = dcShiftsMapper.insertDcShiftsRecord(dcShiftsRecord); + if (shiftsRecord==0){ + msg="操作日志记录失败"; + throw new ServiceException(msg); + } + } + return 1; + } + + @Override + @Transactional(rollbackFor = ServiceException.class) + public int deleteDcShiftsListId(DcShifts dcShifts) throws Exception { + List shiftsValue = dcShiftsMapper.selectDcShiftsDeleteList(dcShifts); + for (DcShifts shifts:shiftsValue){ + Long id = shifts.getId(); + DcShifts dcShiftsById = dcShiftsMapper.selectDcShiftsById(id); + String name = dcShiftsById.getName(); + String msg = ""; + int i = dcShiftsMapper.deleteDcShiftsById(id); + if (i==0){ + msg="删除用户信息失败"; + throw new ServiceException(msg); + } + DcShiftsRecord dcShiftsRecord = new DcShiftsRecord(); + dcShiftsRecord.setOperator(SecurityUtils.getUserId());//操作人员id + dcShiftsRecord.setOperationType("DELETE");//操作类型 + dcShiftsRecord.setOperationTime(DateUtils.getNowDate());//操作时间 + dcShiftsRecord.setModifyContent("删除值班人员"+name); + dcShiftsRecord.setShiftsDate(dcShiftsById.getDate());//值班日期 + dcShiftsRecord.setStation(dcShiftsById.getStation());//驻点 int shiftsRecord = dcShiftsMapper.insertDcShiftsRecord(dcShiftsRecord); if (shiftsRecord==0){ msg="操作日志记录失败"; @@ -195,6 +255,7 @@ public class DcShiftsServiceImpl implements IDcShiftsService return 1; } + /** * 删除值班信息 * @@ -243,7 +304,7 @@ public class DcShiftsServiceImpl implements IDcShiftsService //查询操作记录表 @Override - public List selectDcShiftsRecord() { - return dcShiftsMapper.selectDcShiftsRecord(); + public List selectDcShiftsRecord(DcShifts shifts) { + return dcShiftsMapper.selectDcShiftsRecord(shifts); } } diff --git a/zc-business/src/main/resources/mapper/business/DcShiftsMapper.xml b/zc-business/src/main/resources/mapper/business/DcShiftsMapper.xml index 8edda33d..e1ea10fa 100644 --- a/zc-business/src/main/resources/mapper/business/DcShiftsMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcShiftsMapper.xml @@ -30,9 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -120,7 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" operation_time, modify_content, shifts_date, - + station, #{id}, @@ -129,7 +147,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{operationTime}, #{modifyContent}, #{shiftsDate}, - + #{station}, From 5074e86c3be3a5dee506ce131a28b82bd0ed6207 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Thu, 1 Feb 2024 09:04:09 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=9D=9E=E6=9C=BA?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=8E=A5=E5=8F=A3=E5=8F=8A=E4=BA=8B=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NonAutomaticWarningController.java | 230 ++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java diff --git a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java new file mode 100644 index 00000000..51297fd1 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java @@ -0,0 +1,230 @@ +package com.zc.business.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hikvision.artemis.sdk.ArtemisHttpUtil; +import com.hikvision.artemis.sdk.config.ArtemisConfig; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.uuid.IdUtils; +import com.zc.business.domain.DcWarning; +import com.zc.business.service.IDcWarningService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.eclipse.paho.client.mqttv3.*; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.*; + + +/** + * License + * + * @author Athena-xiepufeng + */ +@Api(tags = "非机预警接口") +@RestController +@RequestMapping("/nonAutomaticWarning") +public class NonAutomaticWarningController extends BaseController { + + private static final String APPKEY = "22825659"; + + private static final String APPSECRET = "7Qcq3fr1gaYws6QhyDqt"; + + private static final String URI = "/artemis/api/common/v1/event/getTopicInfo"; + + private static final String IP = "10.0.81.28"; + + @Resource + private IDcWarningService dcWarningService; + + /* + * 调用功能 + * */ + @ApiOperation("事件订阅") + @PostMapping(value = "/eventSubscription") + public AjaxResult eventSubscription() throws Exception { + + ArtemisConfig config = new ArtemisConfig(); + config.setHost(IP); // 代理API网关nginx服务器ip端口 + config.setAppKey(APPKEY); // 秘钥appkey + config.setAppSecret(APPSECRET);// 秘钥appSecret + final String getCamsApi = URI; + Map paramMap = new HashMap();// post请求Form表单参数 + ArrayList longs = new ArrayList<>(); + longs.add(6274879489L); + longs.add(6274883585L); + longs.add(7768236033L); + longs.add(7835340801L); + paramMap.put("eventTypes", longs); + String body = JSON.toJSON(paramMap).toString(); + Map path = new HashMap(2) { + { + put("https://", getCamsApi); + } + }; + String jsonString = ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json"); + + JSONObject jsonObject = JSONObject.parseObject(jsonString); + String code = jsonObject.getString("code"); + if (Objects.equals(code, "0")) { + JSONObject jsonResult = jsonObject.getJSONObject("data"); + String host = jsonResult.getString("host"); + String clientId = jsonResult.getString("clientId"); + String userName = jsonResult.getString("userName"); + String password = jsonResult.getString("password"); + JSONObject topicName = jsonResult.getJSONObject("topicName"); + try { + // host为主机名,test为clientid即连接MQTT的客户端ID,一般以客户端唯一标识符表示,MemoryPersistence设置clientid的保存形式,默认为以内存保存 + MqttClient client = new MqttClient(host, clientId, new MemoryPersistence()); + // MQTT的连接设置 + MqttConnectOptions options = new MqttConnectOptions(); + // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 + options.setCleanSession(true); + // 设置连接的用户名 + options.setUserName(userName); + // 设置连接的密码 + options.setPassword(password.toCharArray()); + // 设置超时时间 单位为秒 + options.setConnectionTimeout(10); + // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送个消息判断客户端是否在线,但这个方法并没有重连的机制 + options.setKeepAliveInterval(20); + // 设置回调函数 + client.setCallback(new MqttCallback() { + + public void connectionLost(Throwable cause) { + System.out.println("connectionLost"); + } + + public void messageArrived(String topic, MqttMessage message) { + System.out.println("======监听到来自[" + topic + "]的消息======"); + String jsonObjString = new String(message.getPayload()); + JSONObject eventJsonObject = JSONObject.parseObject(jsonObjString); + JSONObject params = eventJsonObject.getJSONObject("params"); + if (params == null) { + return; + } + JSONArray events = params.getJSONArray("events"); + events.forEach(item -> { + JSONObject event = JSONObject.parseObject(String.valueOf(item)); + JSONObject data = event.getJSONObject("data"); + String crossingIndexCode = event.getString("crossingIndexCode"); + Date happenTime = event.getDate("happenTime"); + String srcName = event.getString("srcName").split("收费站")[1]; + String illegalTrafficEvent = data.getString("illegalTrafficEvent"); + String directionName = data.getString("directionName"); + String crossingName = data.getString("crossingName"); + String targetPicUrl = data.getString("targetPicUrl"); + + DcWarning dcWarning = new DcWarning(); + dcWarning.setOtherConfig(jsonObjString); + switch (illegalTrafficEvent) { + case "congestion"://拥堵 + dcWarning.setWarningType(1); + break; + //case "laneChange"://变道 + // dcWarning.setWarningType(); + // break; + //case "vehicleexist"://机占非 + // dcWarning.setWarningType(); + // break; + //case "roadBlock"://路障 + // dcWarning.setWarningType(); + // break; + //case "construction"://施工 + // dcWarning.setWarningType(); + // break; + case "llegalParking"://停车 + dcWarning.setWarningType(4); + break; + //case "crossLane"://压线 + // dcWarning.setWarningType(); + // break; + //case "turnRound"://掉头 + // dcWarning.setWarningType(); + // break; + case "wrongDirection"://逆行 + dcWarning.setWarningType(5); + break; + case "pedestrian"://行人 + dcWarning.setWarningType(2); + break; + case "abandonedObject"://抛洒物 + dcWarning.setWarningType(7); + break; + default://其他 + dcWarning.setWarningType(10); + } + if (Objects.equals(directionName, "上行")) { + dcWarning.setDirection("1"); + } else if (Objects.equals(directionName, "中")) { + dcWarning.setDirection("2"); + } else if (Objects.equals(directionName, "下行")) { + dcWarning.setDirection("3"); + } + dcWarning.setWarningTime(happenTime); + dcWarning.setCreateTime(new Date()); + if (crossingName.startsWith("大学城")) { + dcWarning.setStakeMark("k59+289"); + } else if (crossingName.startsWith("长清")) { + dcWarning.setStakeMark("k72+847"); + } else if (crossingName.startsWith("孝里")) { + dcWarning.setStakeMark("k86+499"); + } else if (crossingName.startsWith("平阴北")) { + dcWarning.setStakeMark("k99+750"); + } else if (crossingName.startsWith("平阴南")) { + dcWarning.setStakeMark("k126+223"); + } else if (crossingName.startsWith("平阴")) { + dcWarning.setStakeMark("k105+904"); + } else if (crossingName.startsWith("东平")) { + dcWarning.setStakeMark("k145+933"); + } else if (crossingName.startsWith("梁山东")) { + dcWarning.setStakeMark("k173+950"); + } else if (crossingName.startsWith("梁山")) { + dcWarning.setStakeMark("k179+396"); + } else if (crossingName.startsWith("嘉祥")) { + dcWarning.setStakeMark("k190+495"); + } + dcWarning.setWarningTitle(crossingName+srcName); + //设置事件Id UUID无下划线格式32 + String uuid = IdUtils.fastSimpleUUID(); + dcWarning.setId(uuid); + dcWarning.setWarningSource(6); + dcWarning.setWarningState(1); + dcWarningService.insertDcWarning(dcWarning); + }); + System.out.println("message content:" + jsonObjString); + System.out.println("============"); + } + + public void deliveryComplete(IMqttDeliveryToken token) { + System.out.println("deliveryComplete---------" + token.isComplete()); + } + + }); + + // 建立连接 + System.out.println("连接到 broker: " + host); + client.connect(options); + + System.out.println("连接成功."); + //订阅消息 + //client.subscribe(topicName.getString("6274883585"), 1); + //System.out.println("开始监听" + topicName.getString("6274883585")); + client.subscribe(topicName.getString("6274879489"), 1); + System.out.println("开始监听" + topicName.getString("6274879489")); + client.subscribe(topicName.getString("7768236033"), 1); + System.out.println("开始监听" + topicName.getString("7768236033")); + client.subscribe(topicName.getString("7835340801"), 1); + System.out.println("开始监听" + topicName.getString("7835340801")); + } catch (Exception e) { + e.printStackTrace(); + } + return AjaxResult.success(); + } + return AjaxResult.error(); + } +} From dd9118eb2b7bfed55844096292dd5a425189b9a0 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Thu, 1 Feb 2024 10:08:25 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E9=81=97=E6=BC=8F=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zc-business/pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zc-business/pom.xml b/zc-business/pom.xml index 2494454f..90649c6b 100644 --- a/zc-business/pom.xml +++ b/zc-business/pom.xml @@ -15,7 +15,18 @@ com.ruoyi ruoyi-common + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + 1.2.2 + + + com.hikvision.ga + artemis-http-client + 1.1.11-SNAPSHOT + io.springfox springfox-boot-starter From 65572c6833c9b6c9b7f7b500e10cd86369b4067f Mon Sep 17 00:00:00 2001 From: mengff <1198151809@qq.com> Date: Thu, 1 Feb 2024 14:24:56 +0800 Subject: [PATCH 4/6] =?UTF-8?q?--=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zc/business/controller/StatusController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zc-business/src/main/java/com/zc/business/controller/StatusController.java b/zc-business/src/main/java/com/zc/business/controller/StatusController.java index 35300a31..568f8a3a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/StatusController.java +++ b/zc-business/src/main/java/com/zc/business/controller/StatusController.java @@ -4,6 +4,7 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.domain.Status; import com.zc.business.service.impl.StatusService; @@ -125,6 +126,9 @@ public class StatusController extends BaseController { //根据时间分组 Map> map = listStatus.stream() .collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); + if(StringUtils.isEmpty(map)){ + return AjaxResult.success("暂无数据"); + } Map> ipMap = new TreeMap<>(map); Integer lastKey = Collections.max(ipMap.keySet()); List lastEntry = ipMap.get(lastKey); From bde48d2a6d17e592301e18d577f7de8f8ae5b97a Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Thu, 1 Feb 2024 14:49:02 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E9=81=97=E6=BC=8F=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/zc/business/controller/VideoController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index b323fc53..99a2af28 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -207,7 +207,7 @@ public class VideoController extends BaseController { .post(); // 请求方法 if (response.body() != null) { String accessToken = JSONObject.parseObject(response.body().string()).getString("accessToken"); - redisCache.setCacheObject(TOKENKEY, accessToken, 100, TimeUnit.MINUTES); + redisCache.setCacheObject(TOKENKEY, accessToken, 5, TimeUnit.MINUTES); return accessToken; } return null; From 58c6638289ead7fd5fc779b09031451b06283a17 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Thu, 1 Feb 2024 15:45:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E9=9D=9E=E6=9C=BA=E9=A2=84=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NonAutomaticWarningController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java index 51297fd1..3f395bab 100644 --- a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java @@ -14,10 +14,16 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; /** @@ -156,7 +162,7 @@ public class NonAutomaticWarningController extends BaseController { dcWarning.setWarningType(7); break; default://其他 - dcWarning.setWarningType(10); + dcWarning.setWarningType(99); } if (Objects.equals(directionName, "上行")) { dcWarning.setDirection("1");