智慧保安后台管理-外网
Administrator
2021-12-16 cdcd2d540de3e6ba4c2e9e7c6a879416da78c17b
src/main/java/org/springblade/modules/equipage/controller/GunController.java
@@ -1,18 +1,35 @@
package org.springblade.modules.equipage.controller;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.apache.commons.codec.Charsets;
import org.springblade.common.excel.RowWriteHandler;
import org.springblade.common.utils.arg;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.equipage.entity.Gun;
import org.springblade.modules.equipage.excel.GunExcel;
import org.springblade.modules.equipage.excel.GunImporter;
import org.springblade.modules.equipage.service.GunService;
import org.springblade.modules.equipage.vo.GunVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * @author zhongrj
@@ -61,12 +78,45 @@
    * @param gun 枪支信息对象
    */
   @PostMapping("/submit")
   public R submit(@RequestBody Gun gun) throws Exception {
      if (gun.getId()==null){
         arg arg = new arg();
         arg.test01(arg.url+"/gun/save",gun);
   public R submit(@RequestBody Gun gun){
      boolean status = false;
      if (null==gun.getId()) {
         //新增
         status = gunService.save(gun);
         //数据同步
         String s1 =
            "insert into sys_gun(id,issue_unit,card_number,gun_mode," +
               "dept_id,person_in_charge,issue_time,valid_time,jurisdiction,card_no) " +
               "values(" + "'" + gun.getId() + "'" + "," +
               "'" + gun.getIssueUnit() + "'" + "," +
               "'" + gun.getCardNumber() + "'" + "," +
               "'" + gun.getGunMode() + "'" + "," +
               "'" + gun.getDeptId() + "'" + "," +
               "'" + gun.getPersonInCharge() + "'" + "," +
               "'" + new SimpleDateFormat("yyyy-MM-dd").format(gun.getIssueTime()) + "'" + "," +
               "'" + new SimpleDateFormat("yyyy-MM-dd").format(gun.getValidTime()) + "'" + "," +
               "'" +gun.getCardNo() + "'" + "," +
               "'" +gun.getJurisdiction() + "'" + ")";
         FtpUtil.sqlFileUpload(s1);
      }else {
         //修改
         status = gunService.updateById(gun);
         //内网同步
         String s1 =
            "update sys_gun set issue_unit = " + "'" + gun.getIssueUnit() + "'" +
               ",card_number = " + "'" + gun.getCardNumber() + "'" +
               ",gun_mode = " + "'" + gun.getGunMode() + "'" +
               ",dept_id = " + "'" + gun.getDeptId() + "'" +
               ",person_in_charge = " + "'" + gun.getJurisdiction() + "'" +
               ",issue_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(gun.getIssueTime()) + "'" +
               ",valid_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(gun.getValidTime()) + "'" +
               ",jurisdiction = " + "'" + gun.getJurisdiction() + "'" +
               ",card_no = " + "'" + gun.getCardNo() + "'" +
               " " +"where id = " + "'" + gun.getId() + "'";
         FtpUtil.sqlFileUpload(s1);
      }
      return R.status(gunService.saveOrUpdate(gun));
      return R.status(status);
   }
   /**
@@ -75,7 +125,13 @@
    */
   @PostMapping("/remove")
   public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
      arg.sendPostRemoveByIds(arg.url+"/gun/remove",ids);
      //内网删除
      List<Long> list = Func.toLongList(ids);
      list.forEach(id ->{
         //内网同步
         String s1 = "delete from sys_gun where id = " + "'" + id + "'";
         FtpUtil.sqlFileUpload(s1);
      });
      return R.status(gunService.removeByIds(Func.toLongList(ids)));
   }
@@ -90,4 +146,43 @@
      return R.data(detail);
   }
   /**
    * 导入枪支信息, excel
    */
   @PostMapping("import-gun")
   public R importGun(MultipartFile file, Integer isCovered, String deptId) {
      GunImporter gunImporter = new GunImporter(gunService, false,deptId);
      ExcelUtil.save(file, gunImporter, GunExcel.class);
      return R.success("操作成功");
   }
   /**
    * 枪支导出模板
    */
   @GetMapping("export-template-gun")
   @ApiOperation(value = "导出模板")
   public void exportGun(HttpServletResponse response) throws IOException {
      List<GunExcel> list = new ArrayList<>();
      GunExcel gunExcel1 = new GunExcel();
      gunExcel1.setDeptId("xxx保安公司");
      gunExcel1.setCardNumber("x****");
      gunExcel1.setGunMode("x****");
      gunExcel1.setIssueUnit("*****");
      gunExcel1.setPersonInCharge("张三");
      gunExcel1.setCardNo("360112**********");
      list.add(gunExcel1);
      String fileName = null;
      try {
         response.setContentType("application/vnd.ms-excel");
         response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
         fileName = URLEncoder.encode("枪支导入数据模板"+ DateUtil.time(), Charsets.UTF_8.name());
         response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
         //修改单元格格式为文本格式
         EasyExcel.write(response.getOutputStream(), GunExcel.class).sheet("枪支数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list);
      } catch (Throwable var6) {
         throw var6;
      }
   }
}