Commit eb20a870 by wqc

青秀模型导入

parent de5c100d
package com.zq.model.controller;
import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo;
import com.zq.model.service.FfzdService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@RestController
@RequestMapping("/model/ffzd")
public class FfzdController {
@Resource
private FfzdService ffzdService;
@PostMapping("/uploadFile")
public ResultVo uploadFile(@RequestParam("file") MultipartFile[] multipartFiles) {
AssertUtils.notNull(multipartFiles, "文件不能为空!");
try {
return ResultVo.success(ffzdService.uploadFile(multipartFiles));
} catch (Exception e) {
e.printStackTrace();
return ResultVo.fail(500, "文件解析失败");
}
}
}
package com.zq.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "city_manage_enforce_law")
public class CityManageEnforceLaw {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("ajlb")
private String cfjg;
@ApiModelProperty("ajlb")
private String ajlb;
@ApiModelProperty("cfzl")
private String cfzl;
@ApiModelProperty("xzxdrmc")
private String xzxdrmc;
@ApiModelProperty("xzxdrlb")
private String xzxdrlb;
@ApiModelProperty("tyshxydm")
private String tyshxydm;
@ApiModelProperty("anyou")
private String anyou;
@ApiModelProperty("wfss")
private String wfss;
@ApiModelProperty("flyj")
private String flyj;
@ApiModelProperty("xzcfjdswh")
private String xzcfjdswh;
@ApiModelProperty("cfje")
private String cfje;
@ApiModelProperty("cfsxq")
private String cfsxq;
@ApiModelProperty("dfbm")
private String dfbm;
private Date createTime;
}
package com.zq.model.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zq.model.entity.CityManageEnforceLaw;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CgzfInfoDao extends BaseMapper<CityManageEnforceLaw> {
}
package com.zq.model.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.zq.common.exception.BusinessException;
import com.zq.model.entity.CityManageEnforceLaw;
import com.zq.model.mapper.CgzfInfoDao;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@Service
public class FfzdService {
@Resource
private CgzfInfoDao cgzfInfoDao;
public Object uploadFile(MultipartFile[] multipartFiles) {
for (MultipartFile file : multipartFiles) {
ExcelReader reader;
try {
reader = ExcelUtil.getReader(file.getInputStream());
} catch (IOException e) {
e.printStackTrace();
throw new BusinessException("文件解析失败");
}
CityManageEnforceLaw enforceLaw = new CityManageEnforceLaw();
List<List<Object>> readList = reader.read(1);
for (List<Object> objectList : readList) {
int index = 0;
enforceLaw.setCfjg(Convert.toStr(CollUtil.get(objectList, index)));
enforceLaw.setAjlb(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setCfzl(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setXzxdrmc(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setXzxdrlb(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setTyshxydm(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setAnyou(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setWfss(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setFlyj(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setXzcfjdswh(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setCfje(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setCfsxq(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setDfbm(Convert.toStr(CollUtil.get(objectList, index++)));
enforceLaw.setCreateTime(DateUtil.date());
cgzfInfoDao.insert(enforceLaw);
}
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment