入职后完成的第一个小模块
Controller
package com.ds.travel.biz.patrol.controller;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementInforDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.PageInfo;
import com.jt.common.core.entity.Result;
import com.jt.common.core.entity.Param;
import com.ds.travel.biz.patrol.biz.PatrolElementBiz;
import com.jt.common.core.util.Common;
import com.jt.common.core.util.Constants;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/element")
public class PatrolElementController {
private final PatrolElementBiz patrolElementBiz;
public PatrolElementController(PatrolElementBiz patrolElementBiz) {
this.patrolElementBiz = patrolElementBiz;
}
@PostMapping("/list")
public Result<PageInfo<PatrolElementVo>> list(@RequestBody Param param){
if (param.getInteger("pageNo") == null){ return Result.asCheckError("pageNo不能为null"); }
if (param.getInteger("limit") == null){ return Result.asCheckError("limit不能为null"); }
return Result.asSuccess(patrolElementBiz.selectList(param));
}
@PostMapping("/add")
public Result<?> add(@RequestBody @Validated PatrolElementInforDto patrolElementInforDto){
if(!patrolElementInforDto.getPosition().contains(",") || patrolElementInforDto.getPosition().length() <10) {
return Result.asCheckError("定位错误");
}
if(patrolElementInforDto.getIsGenerate().equals(Constants.COMMON_ONE.toString())){
if(patrolElementInforDto.getRule() == null){ return Result.asCheckError("请选择规则"); }
}
patrolElementBiz.add(patrolElementInforDto);
return Result.asSuccess();
}
@PostMapping("/update")
public Result<?> update(@RequestBody @Validated PatrolElementInforDto patrolElementInforDto){
if(!patrolElementInforDto.getPosition().contains(",")){ return Result.asCheckError("定位错误"); }
if(patrolElementInforDto.getIsGenerate().equals(Constants.COMMON_ONE.toString())){
if(patrolElementInforDto.getRule() == null){ return Result.asCheckError("请选择规则"); }
}
patrolElementBiz.updateById(patrolElementInforDto);
return Result.asSuccess();
}
@PostMapping("/remove")
public Result<?> remove(@RequestBody PatrolElementDto patrolElementDto){
if(patrolElementDto.getId() == null ){ return Result.asCheckError("用户ID不能为null"); }
patrolElementBiz.remove(patrolElementDto);
return Result.asSuccess();
}
@PostMapping("/status")
public Result<?> status(@RequestBody PatrolElementDto patrolElementDto){
if(patrolElementDto.getId() == null ){ return Result.asCheckError("用户ID不能为null"); }
if(patrolElementDto.getStatus() == null){ return Result.asCheckError("状态未找到"); }
patrolElementBiz.statusUpd(patrolElementDto);
return Result.asSuccess();
}
@PostMapping("/check")
public Result<PatrolElementCheckVo> check(@RequestBody PatrolElementDto patrolElementDto){
if(patrolElementDto.getId() == null){ return Result.asCheckError("用户ID不能为null"); }
return Result.asSuccess(patrolElementBiz.checkById(patrolElementDto));
}
@PostMapping("/importExcel")
public Result<?> importExcel(@RequestParam(value = "file",required = false) MultipartFile file) throws IOException {
if(Common.isEmpty(file)||Common.isEmpty(file.getOriginalFilename()) || file.isEmpty()){
return Result.asFail("文件空或文件类型无法识别,导入失败!");
}
if (!file.getOriginalFilename().endsWith(".xlsx") && !file.getOriginalFilename().endsWith(".xls")){
return Result.asFail("导入仅支持.xlxs或.xlx类型文件!");
}
patrolElementBiz.importExcel(file);
return Result.asSuccess();
}
}
biz接口
package com.ds.travel.biz.patrol.biz;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementInforDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.PageInfo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.jt.common.core.entity.Param;
import com.jt.common.core.entity.Result;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface PatrolElementBiz {
PageInfo<PatrolElementVo> selectList(Param param);
void add(PatrolElementInforDto patrolElementInforDto);
void updateById(PatrolElementInforDto patrolElementInforDto);
void remove(PatrolElementDto patrolElementDto);
void statusUpd(PatrolElementDto patrolElementDto);
PatrolElementCheckVo checkById(PatrolElementDto patrolElementDto);
void importExcel(MultipartFile file)throws IOException;
}
BizImpl接口实现
需要用到自定义的PatrolElementMessageConverter解析器
package com.ds.travel.biz.patrol.biz.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;
import com.ds.travel.biz.patrol.biz.PatrolElementBiz;
import com.ds.travel.biz.patrol.listener.PatrolElementListener;
import com.ds.travel.biz.pojo.assets.converter.PatrolElementMessageConverter;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementInforDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.PageInfo;
import com.jt.common.core.entity.Param;
import com.ds.travel.biz.patrol.service.PatrolElementService;
import com.jt.common.core.util.Constants;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@Component
public class PatrolElementBizImpl implements PatrolElementBiz {
private final PatrolElementService patrolElementService;
public PatrolElementBizImpl(PatrolElementService patrolElementService) {
this.patrolElementService = patrolElementService;
}
@Override
public PageInfo<PatrolElementVo> selectList(Param param) {
return patrolElementService.selectLisAll(param);
}
@Override
public void add(PatrolElementInforDto patrolElementInforDto) {
patrolElementService.save(decomposes(patrolElementInforDto));
}
@Override
public void updateById(PatrolElementInforDto patrolElementInforDto) {
patrolElementService.updById(decomposes(patrolElementInforDto));
}
@Override
public void remove(PatrolElementDto patrolElementDto){
patrolElementService.removeById(patrolElementDto.getId());
}
@Override
public void statusUpd(PatrolElementDto patrolElementDto) {
patrolElementService.statusUpd(patrolElementDto.getId(),patrolElementDto.getStatus());
}
@Override
public PatrolElementCheckVo checkById(PatrolElementDto patrolElementDto) {
return patrolElementService.checkById(patrolElementDto.getId());
}
@Override
public void importExcel(MultipartFile file) throws IOException {
InputStream inputStream = file.getInputStream();
EasyExcel.read(inputStream,PatrolElementExcelDto.class,new PatrolElementListener(patrolElementService)).sheet().doRead();
inputStream.close();
}
public PatrolElement decomposes(PatrolElementInforDto patrolElementInforDto){
PatrolElement patrolElement= PatrolElementMessageConverter.INSTANCE.toCompanyDto(patrolElementInforDto);
String[] positions = patrolElementInforDto.getPosition().split(",");
patrolElement.setLatitude(positions[Constants.COMMON_ZERO]);
patrolElement.setLongitude(positions[Constants.COMMON_ONE]);
if(patrolElementInforDto.getIsGenerate().equals(Constants.COMMON_ZERO.toString())){
patrolElement.setRuleId(Long.parseLong(Constants.COMMON_ZERO.toString()));
patrolElement.setIsCustom(Constants.COMMON_ZERO);
}else {
if(Constants.COMMON_ZERO.toString().equals(patrolElementInforDto.getRulePattern())){
patrolElement.setRuleId(Long.parseLong(patrolElementInforDto.getRule().toString()));
patrolElement.setIsCustom(Constants.COMMON_ZERO);
}else {
patrolElement.setRuleId(Long.parseLong(Constants.COMMON_ZERO.toString()));
patrolElement.setIsCustom(Constants.COMMON_ONE);
}
}
return patrolElement;
}
}
service接口
package com.ds.travel.biz.patrol.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.PageInfo;
import com.jt.common.core.entity.Param;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface PatrolElementService extends IService<PatrolElement> {
PageInfo<PatrolElementVo> selectLisAll(Param param);
void updById(PatrolElement patrolElement);
void removeById(Long id);
void statusUpd(Long id, Object status);
PatrolElementCheckVo checkById(Long id);
void saveExcel(List<PatrolElementDto> list);
Long selectTypeId(String typeName);
Long selectRuleId(String ruleName);
void UpTypeId(PatrolElementExcelDto patrolElementExcelDto);
}
serviceImpl接口实现类
package com.ds.travel.biz.patrol.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ds.travel.biz.patrol.listener.PatrolElementListener;
import com.ds.travel.biz.patrol.service.PatrolElementService;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.patrol.mapper.PatrolElementMapper;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jt.common.core.entity.Param;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PatrolElementServiceImpl extends ServiceImpl<PatrolElementMapper, PatrolElement> implements PatrolElementService {
private final PatrolElementMapper patrolElementMapper;
public PatrolElementServiceImpl (PatrolElementMapper patrolElementMapper) {
this.patrolElementMapper = patrolElementMapper;
}
@Override
public PageInfo<PatrolElementVo> selectLisAll(Param param) {
Page<PatrolElementVo> page = PageHelper.startPage(param.getIntValue("pageNo"),param.getIntValue("limit"));
patrolElementMapper.selectListAll(param.getInteger("typeId"),param.getString("elementName"));
return new PageInfo<>(page);
}
@Override
public void updById(PatrolElement patrolElement) {
patrolElementMapper.updById(patrolElement);
}
@Override
public void removeById(Long id) {
patrolElementMapper.removeById(id);
}
@Override
public void statusUpd(Long id, Object status) {
Map<String,Object> map = new HashMap<>();
map.put("id",id);
map.put("status",status);
patrolElementMapper.statusUpd(map);
}
@Override
public PatrolElementCheckVo checkById(Long id) {
return patrolElementMapper.checkById(id);
}
@Override
public void saveExcel(List<PatrolElementDto> list) {
for(PatrolElementDto patrolElementDto:list){
patrolElementMapper.saveExcel(patrolElementDto);
}
}
@Override
public Long selectTypeId(String typeName) {
return patrolElementMapper.selectTypeId(typeName);
}
@Override
public Long selectRuleId(String ruleName) {
return patrolElementMapper.selectRuleId(ruleName);
}
@Override
public void UpTypeId(PatrolElementExcelDto patrolElementExcelDto) {
Long parentTypeName = patrolElementMapper.selectTypeId(patrolElementExcelDto.getParentTypeName());
patrolElementMapper.UpTypeId(patrolElementExcelDto.getTypeName(),parentTypeName);
}
}
Mapper映射接口
package com.ds.travel.biz.patrol.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ds.travel.biz.pojo.assets.vo.PatrolElementVo;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@Mapper
public interface PatrolElementMapper extends BaseMapper<PatrolElement> {
List<PatrolElementVo> selectListAll(@Param("typeId") Integer typeId, @Param("elementName") String elementName);
void updById(PatrolElement patrolElement);
void removeById(Long id);
void statusUpd(Map<String,Object> map);
PatrolElementCheckVo checkById(Long id);
void saveExcel(PatrolElementDto patrolElementDto);
Long selectTypeId(String typeName);
Long selectRuleId(String ruleName);
void UpTypeId(@Param("typeName") String typeName,@Param("parentTypeName") Long parentTypeName);
}
Mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ds.travel.biz.patrol.mapper.PatrolElementMapper">
<!--导入-->
<insert id="saveExcel" parameterType="com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto">
insert into am_patrol_element set element_name=#{elementName},type_id=#{typeId},is_generate=#{isGenerate},
address=#{address},rule_id=#{ruleId},status=#{status},longitude=#{longitude},latitude=#{latitude},is_custom=#{isCustom}
</insert>
<!--分列-->
<select id="selectListAll" resultType="com.ds.travel.biz.pojo.assets.vo.PatrolElementVo">
select a.id,a.element_name,e.type_name,a.is_generate,a.address,a.is_custom,t.rule_name,a.status
from (select * from am_patrol_element<if test="elementName != null ">
where element_name = #{elementName}
</if>)a
join am_patrol_element_type e on
<if test="typeId != null ">
a.type_id = #{typeId} and e.id = #{typeId}
</if>
<if test="typeId == null">
a.type_id=e.id
</if>
left join am_patrol_task t on a.rule_id=t.id
where a.is_delete = 0
</select>
<!--删除-->
<update id="removeById" parameterType="long">
update am_patrol_element set is_delete = 1 where id = #{id}
</update>
<!--状态-->
<update id="statusUpd" parameterType="map">
update am_patrol_element
<if test="status == 1">
set status = 0
</if>
<if test="status == 0">
set status = 1
</if>
where id = #{id}
</update>
<!--查看-->
<select id="checkById" parameterType="long" resultType="com.ds.travel.biz.pojo.patrol.vo.PatrolElementCheckVo">
select a.id,a.element_name,e.type_name,a.is_generate,a.address,t.rule_name,a.status,a.longitude,a.latitude,a.is_custom,a.is_delete,a.create_id,a.create_time,a.update_id,a.update_time
from am_patrol_element a join am_patrol_element_type e on a.type_id=e.id
left join am_patrol_task t on a.rule_id=t.id
where a.id = #{id}
</select>
<!--查找要素类型Id-->
<select id="selectTypeId" parameterType="string" resultType="java.lang.Long">
select id from am_patrol_element_type where type_name = #{typeName}
</select>
<!--查找现有规则Id-->
<select id="selectRuleId" parameterType="string" resultType="java.lang.Long">
select id from am_patrol_task where rule_name = #{ruleName}
</select>
<!--写入上级要素类型-->
<update id="UpTypeId">
update am_patrol_element_type set task_type_id = #{parentTypeName} where type_name = #{typeName}
</update>
<!--修改-->
<update id="updById" parameterType="com.ds.travel.biz.pojo.patrol.PatrolElement">
update am_patrol_element
<set>
<if test="elementName != null">
element_name = #{elementName,jdbcType=VARCHAR},
</if>
<if test="typeId != null">
type_id = #{typeId,jdbcType=BIGINT},
</if>
<if test="isGenerate != null">
is_generate = #{isGenerate,jdbcType=TINYINT},
</if>
<if test="address != null">
address = #{address,jdbcType=VARCHAR},
</if>
<if test="ruleId != null">
rule_id = #{ruleId,jdbcType=BIGINT},
</if>
<if test="status != null">
`status` = #{status,jdbcType=TINYINT},
</if>
<if test="longitude != null">
longitude = #{longitude,jdbcType=DECIMAL},
</if>
<if test="latitude != null">
latitude = #{latitude,jdbcType=VARCHAR},
</if>
<if test="isCustom != null">
is_custom = #{isCustom,jdbcType=TINYINT},
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
</if>
<if test="createId != null">
create_id = #{createId,jdbcType=BIGINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateId != null">
update_id = #{updateId,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
PatrolElementMessageConverter解析器
将PatrolElementInforDto实体解析为PatrolElement实体
package com.ds.travel.biz.pojo.assets.converter;
import com.ds.travel.biz.pojo.patrol.PatrolElement;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementInforDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface PatrolElementMessageConverter {
PatrolElementMessageConverter INSTANCE = Mappers.getMapper(PatrolElementMessageConverter.class);
@Mappings(value = {
@Mapping(source = "id",target = "id"),
@Mapping(source = "elementName",target = "elementName"),
@Mapping(source = "typeId",target = "typeId"),
@Mapping(source = "address",target = "address"),
@Mapping(source = "isGenerate",target = "isGenerate"),
@Mapping(source = "rule",target = "ruleId")
})
PatrolElement toCompanyDto (PatrolElementInforDto dto);
}
数据库实体视图vo类
package com.ds.travel.biz.pojo.assets.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.sql.*;
@Data
public class PatrolElementVo {
private Long id;
private String elementName;
private String typeName;
private Object isGenerate;
private String address;
private Object isCustom;
private String ruleName;
private Object status ;
}
查看实体视图vo类
package com.ds.travel.biz.pojo.patrol.vo;
import lombok.Data;
import java.sql.*;
@Data
public class PatrolElementCheckVo {
private Long id;
private String elementName;
private String typeName;
private Object isGenerate;
private String address;
private String ruleName;
private Object status;
private Object longitude;
private String latitude;
private Object isCustom;
private Object isDelete;
private Long createId;
private Date createTime;
private Long updateId;
private Date updateTime;
}
Excel文件导入监听器
package com.ds.travel.biz.patrol.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelAnalysisStopException;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.ds.travel.biz.patrol.service.PatrolElementService;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementDto;
import com.ds.travel.biz.pojo.patrol.dto.PatrolElementExcelDto;
import com.jt.common.core.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.regex.Pattern;
public class PatrolElementListener implements ReadListener<PatrolElementExcelDto> {
private static final int BATCH_COUNT = 10;
private List<PatrolElementDto> patrolElementDtos = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
private PatrolElementService patrolElementService;
public PatrolElementListener (PatrolElementService patrolElementService) {
this.patrolElementService = patrolElementService;
}
@Override
public void invoke(PatrolElementExcelDto data, AnalysisContext context) throws ArithmeticException{
System.out.println("解析到一条数据:"+JSON.toJSONString(data));
patrolElementDtos.add(mapping(data));
if (patrolElementDtos.size() >= BATCH_COUNT) {
saveData();
patrolElementDtos = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
saveData();
System.out.println("所有数据解析完成!");
}
private void saveData() {
System.out.println("开始存储数据库!"+ patrolElementDtos.size());
patrolElementService.saveExcel(patrolElementDtos);
System.out.println("存储数据库成功!");
}
public PatrolElementDto mapping(PatrolElementExcelDto patrolElementExcelDto){
PatrolElementDto patrolElementDto = new PatrolElementDto();
patrolElementDto.setElementName(patrolElementExcelDto.getElementName());
patrolElementService.UpTypeId(patrolElementExcelDto);
patrolElementDto.setTypeId(patrolElementService.selectTypeId(patrolElementExcelDto.getTypeName()));
if("是".equals(patrolElementExcelDto.getGenerate())){
patrolElementDto.setIsGenerate(Constants.COMMON_ONE);
if ("自定义规则".equals(patrolElementExcelDto.getRuleName())){
patrolElementDto.setRuleId(Long.parseLong(Constants.COMMON_ZERO.toString()));
patrolElementDto.setIsCustom(Constants.COMMON_ONE);
}else {
patrolElementDto.setRuleId(patrolElementService.selectRuleId(patrolElementExcelDto.getRuleName()));
patrolElementDto.setIsCustom(Constants.COMMON_ZERO);
}
}else {
if (patrolElementExcelDto.getRuleName() != null){
throw new RuntimeException("是否生成任务与任务规则冲突:"+patrolElementExcelDto.getGenerate()+":"+patrolElementExcelDto.getRuleName());
}
patrolElementDto.setIsGenerate(Constants.COMMON_ZERO);
patrolElementDto.setRuleId(Long.parseLong(Constants.COMMON_ZERO.toString()));
patrolElementDto.setIsCustom(Constants.COMMON_ZERO);
}
patrolElementDto.setAddress(patrolElementExcelDto.getAddress());
String regLatitude = "^(([1-8]\\d?)|([1-8]\\d))(\\.\\d{1,6})|90|0(\\.\\d{1,6})?$";
if(Pattern.matches(regLatitude,patrolElementExcelDto.getLatitude())){
patrolElementDto.setLatitude(patrolElementExcelDto.getLatitude());
}else {
throw new RuntimeException("纬度格式输入错误,范围是0?90,保留6位小数:"+patrolElementExcelDto.getLatitude());
}
String regLongitude = "^(([1-9]\\d?)|(1[0-7]\\d))(\\.\\d{1,6})|180|0(\\.\\d{1,6})?$";
if(Pattern.matches(regLongitude,patrolElementExcelDto.getLongitude())){
patrolElementDto.setLongitude(patrolElementExcelDto.getLongitude());
}else {
throw new RuntimeException("经度格式输入错误,范围是0-180,保留6位小数:"+patrolElementExcelDto.getLongitude());
}
patrolElementDto.setStatus(Constants.COMMON_ONE);
return patrolElementDto;
}
}
Excel文件dto实体类
package com.ds.travel.biz.pojo.patrol.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import sun.rmi.runtime.Log;
import java.io.Serializable;
import java.security.PrivateKey;
import java.sql.Date;
@Getter
@Setter
@EqualsAndHashCode
public class PatrolElementExcelDto implements Serializable {
private static final long serialVersionUID = 1L;
@NumberFormat("序号")
private String id;
@ExcelProperty("名称")
private String elementName;
@ExcelProperty("上级要素类型")
private String parentTypeName;
@ExcelProperty("要素类型")
private String typeName;
@ExcelProperty("是否生成任务")
private String generate;
@ExcelProperty("地址")
private String address;
@ExcelProperty("纬度")
private String latitude;
@ExcelProperty("经度")
private String longitude;
@ExcelProperty("任务规则")
private String ruleName;
@NumberFormat("状态")
private String status;
@NumberFormat("是否删除")
private String isDelete;
@NumberFormat("创建人")
private String createId;
@NumberFormat("创建时间")
private Date createTime;
@NumberFormat("修改时间")
private String updateId;
@NumberFormat("创建时间")
private Date updateTime;
}
新增/更新实体dto类
package com.ds.travel.biz.pojo.patrol.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.sql.*;
@Data
public class PatrolElementInforDto {
private Long id;
@NotNull(message = "编号不能为null")
private String elementName;
@NotNull(message = "请选择要素类型")
private Long typeId;
@NotNull(message = "定位错误")
private String position;
private String address;
@NotNull(message = "请选择是否生成任务")
private Object isGenerate;
private String rulePattern;
private Long rule;
}
数据库实体
package com.ds.travel.biz.pojo.patrol.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.sql.*;
@Data
public class PatrolElementDto {
private Long id;
@NotBlank(message = "请填写编号")
private String elementName;
@NotEmpty(message = "请填写类型")
private Long typeId;
@NotEmpty(message = "请选择")
private Object isGenerate;
private String address;
@NotEmpty(message = "请选择规则")
private Long ruleId;
private Object status;
@NotEmpty(message = "请定位位置")
private Object longitude;
@NotBlank(message = "请定位位置")
private String latitude;
private Object isCustom;
private Object isDelete;
private Long createId;
private Date createTime;
private Long updateId;
private Date updateTime;
}
|