|
@@ -0,0 +1,196 @@
|
|
|
+package com.pj.tb_people;
|
|
|
+
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.pj.tb_goods_transit.TbGoodsTransit;
|
|
|
+import com.pj.utils.so.SoMap;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import com.pj.utils.sg.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Service: tb_people -- 边民
|
|
|
+ * @author qzy
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Transactional(rollbackFor = Exception.class)
|
|
|
+public class TbPeopleService extends ServiceImpl<TbPeopleMapper, TbPeople> implements IService<TbPeople>{
|
|
|
+
|
|
|
+ /** 底层 Mapper 对象 */
|
|
|
+ @Autowired
|
|
|
+ TbPeopleMapper tbPeopleMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MethodPeopleService methodPeopleService;
|
|
|
+
|
|
|
+ /** 增 */
|
|
|
+ void add(TbPeople t){
|
|
|
+ save(t);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 删 */
|
|
|
+ void delete(Long id){
|
|
|
+ removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 改 */
|
|
|
+ void update(TbPeople t){
|
|
|
+ updateById(t);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 查 */
|
|
|
+ TbPeople getById(String id){
|
|
|
+ return super.getById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
|
|
|
+ List<TbPeople> getList(SoMap so) {
|
|
|
+ return tbPeopleMapper.getList(so);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入
|
|
|
+ * @param file excel文件
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public String importData(MultipartFile file) throws IOException {
|
|
|
+ System.out.println("\n开始执行文件上传....\n");
|
|
|
+
|
|
|
+ //判空
|
|
|
+ if(file.isEmpty()) return "文件为空,无法执行上传...";
|
|
|
+ //获取文件上传数据
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
+ //获取第一页sheet
|
|
|
+ HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
+ //定义计数器
|
|
|
+ int count = 0;
|
|
|
+ //定义行对象
|
|
|
+ HSSFRow row = null;
|
|
|
+ //解析数据封装到集合
|
|
|
+ count = methodPeopleService.importMethod(row, sheet, count);
|
|
|
+ wb.close();
|
|
|
+ System.out.println("\n文件上传完成,共上传 " + count + "条 " + "数据...\n");
|
|
|
+ return "上传完成,共上传" + count + "条" + "数据。";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出 excel文件
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String outportExcel(String keyword) throws IOException {
|
|
|
+ System.out.println("\n开始执行文件导出....\n");
|
|
|
+ //路径
|
|
|
+ String localPath = "C:\\Users\\Administrator\\Desktop\\generate\\";
|
|
|
+ String filepath = localPath + "边民数据表_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ".xlsx";
|
|
|
+ //根据需求查询数据
|
|
|
+ List<TbPeople> selectedList = tbPeopleMapper.selectList(new LambdaQueryWrapper<TbPeople>().eq(StringUtils.isNoneBlank(keyword), TbPeople::getName, keyword));
|
|
|
+ if(selectedList.size() == 0)return "没有可导出的数据。";
|
|
|
+ //建立excel对象封装数据
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ //创建excel表格右下角的sheet页名称
|
|
|
+ HSSFSheet sheet = workbook.createSheet("1");
|
|
|
+ //创建表头
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+ row.createCell(0).setCellValue("序号");
|
|
|
+ row.createCell(1).setCellValue("姓名");
|
|
|
+ row.createCell(2).setCellValue("边民号");
|
|
|
+ row.createCell(3).setCellValue("性别");
|
|
|
+ row.createCell(4).setCellValue("年龄");
|
|
|
+ row.createCell(5).setCellValue("身份证");
|
|
|
+ row.createCell(6).setCellValue("身份证复印件");
|
|
|
+ row.createCell(7).setCellValue("手机号码");
|
|
|
+ row.createCell(8).setCellValue("银行编号");
|
|
|
+ row.createCell(9).setCellValue("银行卡号");
|
|
|
+ row.createCell(10).setCellValue("银行名称");
|
|
|
+ row.createCell(11).setCellValue("所属互助组");
|
|
|
+ row.createCell(12).setCellValue("互助组名称");
|
|
|
+ row.createCell(13).setCellValue("是否可用");
|
|
|
+ row.createCell(14).setCellValue("角色");
|
|
|
+ row.createCell(15).setCellValue("经度");
|
|
|
+ row.createCell(16).setCellValue("维度");
|
|
|
+ row.createCell(17).setCellValue("最后一次下单定位");
|
|
|
+ row.createCell(18).setCellValue("联系地址");
|
|
|
+ row.createCell(19).setCellValue("地址ID");
|
|
|
+ row.createCell(20).setCellValue("详细地址");
|
|
|
+ row.createCell(21).setCellValue("是否锁定");
|
|
|
+ row.createCell(22).setCellValue("当天剩余额度");
|
|
|
+ row.createCell(23).setCellValue("judge_status");
|
|
|
+ row.createCell(24).setCellValue("judge_content");
|
|
|
+ row.createCell(25).setCellValue("注册时间");
|
|
|
+ row.createCell(26).setCellValue("judge_time");
|
|
|
+ row.createCell(27).setCellValue("person_id");
|
|
|
+ row.createCell(28).setCellValue("创建时间");
|
|
|
+ row.createCell(29).setCellValue("创建人编号");
|
|
|
+ row.createCell(30).setCellValue("创建人名称");
|
|
|
+ row.createCell(31).setCellValue("更新时间");
|
|
|
+ row.createCell(32).setCellValue("更新人编号");
|
|
|
+ row.createCell(33).setCellValue("更新人名称");
|
|
|
+ row.createCell(34).setCellValue("删除状态");
|
|
|
+ //遍历集合
|
|
|
+ for (int i = 0; i < selectedList.size(); i++) {
|
|
|
+ HSSFRow sheetRow = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
+ sheetRow.createCell(0).setCellValue(i + 1);
|
|
|
+ sheetRow.createCell(1).setCellValue((selectedList.get(i).getName() + "").equals("null")? "": selectedList.get(i).getName() + "");
|
|
|
+ sheetRow.createCell(2).setCellValue((selectedList.get(i).getCode() + "").equals("null")? "": selectedList.get(i).getCode() + "");
|
|
|
+ sheetRow.createCell(3).setCellValue((selectedList.get(i).getSex() + "").equals("null")? "": selectedList.get(i).getSex() + "");
|
|
|
+ sheetRow.createCell(4).setCellValue((selectedList.get(i).getAge() + "").equals("null")? "": selectedList.get(i).getAge() + "");
|
|
|
+ sheetRow.createCell(5).setCellValue((selectedList.get(i).getIdCard() + "").equals("null")? "": selectedList.get(i).getIdCard() + "");
|
|
|
+ sheetRow.createCell(6).setCellValue((selectedList.get(i).getIdCardImg() + "").equals("null")? "": selectedList.get(i).getIdCardImg() + "");
|
|
|
+ sheetRow.createCell(7).setCellValue((selectedList.get(i).getPhone() + "").equals("null")? "": selectedList.get(i).getPhone() + "");
|
|
|
+ sheetRow.createCell(8).setCellValue((selectedList.get(i).getBankNo() + "" ).equals("null")? "": selectedList.get(i).getBankNo() + "");
|
|
|
+ sheetRow.createCell(9).setCellValue((selectedList.get(i).getBankCode() + "").equals("null")? "": selectedList.get(i).getBankCode() + "");
|
|
|
+ sheetRow.createCell(10).setCellValue((selectedList.get(i).getBankName() + "").equals("null")? "": selectedList.get(i).getBankName() + "");
|
|
|
+ sheetRow.createCell(11).setCellValue((selectedList.get(i).getGroupId() + "").equals("null")? "": selectedList.get(i).getGroupId() + "");
|
|
|
+ sheetRow.createCell(12).setCellValue((selectedList.get(i).getGroupName() + "").equals("null")? "": selectedList.get(i).getGroupName() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getStatus() + "").equals("null")? "": selectedList.get(i).getStatus() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getRole() + "").equals("null")? "": selectedList.get(i).getRole() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getLng() + "").equals("null")? "": selectedList.get(i).getLng() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getLat() + "").equals("null")? "": selectedList.get(i).getLat() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getLastLocation() + "").equals("null")? "": selectedList.get(i).getLastLocation() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getAddress() + "").equals("null")? "": selectedList.get(i).getAddress() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getAddressIds() + "").equals("null")? "": selectedList.get(i).getAddressIds() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getDetailAddress() + "").equals("null")? "": selectedList.get(i).getDetailAddress() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getIsLock() + "").equals("null")? "": selectedList.get(i).getIsLock() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getLeftPrice() + "").equals("null")? "": selectedList.get(i).getLeftPrice() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getJudgeStatus() + "").equals("null")? "": selectedList.get(i).getJudgeStatus() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getJudgeContent() + "").equals("null")? "": selectedList.get(i).getJudgeContent() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getRegisterTime() + "").equals("null")? "": selectedList.get(i).getRegisterTime() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getJudgeTime() + "").equals("null")? "": selectedList.get(i).getJudgeTime() + "");
|
|
|
+ sheetRow.createCell(13).setCellValue((selectedList.get(i).getPersonId() + "").equals("null")? "": selectedList.get(i).getPersonId() + "");
|
|
|
+ //公共字段
|
|
|
+ sheetRow.createCell(22).setCellValue((selectedList.get(i).getCreateTime() + "").equals("null")? "": selectedList.get(i).getCreateTime() + "");
|
|
|
+ sheetRow.createCell(23).setCellValue((selectedList.get(i).getCreateBy() + "").equals("null")? "": selectedList.get(i).getCreateBy() + "");
|
|
|
+ sheetRow.createCell(24).setCellValue((selectedList.get(i).getCreateName() + "").equals("null")? "": selectedList.get(i).getCreateName() + "");
|
|
|
+ sheetRow.createCell(25).setCellValue((selectedList.get(i).getUpdateTime() + "").equals("null")? "": selectedList.get(i).getUpdateTime() + "");
|
|
|
+ sheetRow.createCell(26).setCellValue((selectedList.get(i).getUpdateBy() + "").equals("null")? "": selectedList.get(i).getUpdateBy() + "");
|
|
|
+ sheetRow.createCell(27).setCellValue((selectedList.get(i).getUpdateName() + "").equals("null")? "": selectedList.get(i).getUpdateName() + "");
|
|
|
+ sheetRow.createCell(28).setCellValue((selectedList.get(i).getDeleteStatus() + "").equals("null")? "": selectedList.get(i).getDeleteStatus() + "");
|
|
|
+ }
|
|
|
+ //建立输出流,输出文件
|
|
|
+ FileOutputStream fos = new FileOutputStream(filepath);
|
|
|
+
|
|
|
+ workbook.write(fos);
|
|
|
+ fos.flush();
|
|
|
+ //关闭输出流
|
|
|
+ fos.close();
|
|
|
+ workbook.close();
|
|
|
+ System.out.println("\n数据导出完成!");
|
|
|
+ return "数据导出完成!";
|
|
|
+ }
|
|
|
+}
|