From e04aaefeb4d932e4175f53ad05250a7fed21c1fb Mon Sep 17 00:00:00 2001 From: zhangyuan Date: Thu, 12 Nov 2020 15:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E4=BA=8B=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReportMaCodeController.java | 121 ++++++++ .../elink/esua/epdc/dao/ReportMaCodeDao.java | 70 +++++ .../esua/epdc/entity/ReportMaCodeEntity.java | 81 ++++++ .../esua/epdc/excel/ReportMaCodeExcel.java | 80 ++++++ .../esua/epdc/redis/ReportMaCodeRedis.java | 47 +++ .../epdc/service/ReportMaCodeService.java | 124 ++++++++ .../service/impl/ReportMaCodeServiceImpl.java | 269 ++++++++++++++++++ .../main/resources/mapper/ReportMaCodeDao.xml | 76 +++++ 8 files changed, 868 insertions(+) create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/ReportMaCodeController.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/ReportMaCodeDao.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/ReportMaCodeEntity.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/excel/ReportMaCodeExcel.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/redis/ReportMaCodeRedis.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/ReportMaCodeService.java create mode 100644 epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/ReportMaCodeServiceImpl.java create mode 100644 epdc-cloud-admin/src/main/resources/mapper/ReportMaCodeDao.xml diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/ReportMaCodeController.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/ReportMaCodeController.java new file mode 100644 index 0000000..a82a095 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/controller/ReportMaCodeController.java @@ -0,0 +1,121 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.dto.ReportMaCodeDTO; +import com.elink.esua.epdc.excel.ReportMaCodeExcel; +import com.elink.esua.epdc.service.ReportMaCodeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@RestController +@RequestMapping("reportmacode") +public class ReportMaCodeController { + + @Autowired + private ReportMaCodeService reportMaCodeService; + + @GetMapping("page") + public Result> page(@RequestParam Map params) { + PageData page = reportMaCodeService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id) { + ReportMaCodeDTO data = reportMaCodeService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody ReportMaCodeDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + reportMaCodeService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody ReportMaCodeDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + reportMaCodeService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids) { + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + reportMaCodeService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = reportMaCodeService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, ReportMaCodeExcel.class); + } + + + /** + * 所有部门报事码初始化 + * + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author zhy + * @date 2020/11/12 13:43 + */ + @PostMapping("init") + public Result initReportMaCode() { + return reportMaCodeService.initReportMaCode(); + } + + /** + * 生成指定网格报事码 + * + * @param gridId + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author zhy + * @date 2020/11/12 13:43 + */ + @PostMapping("create/{gridId}") + public Result createReportMaCode(@PathVariable("gridId") String gridId) { + return reportMaCodeService.createReportMaCode(gridId); + } + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/ReportMaCodeDao.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/ReportMaCodeDao.java new file mode 100644 index 0000000..411c623 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/dao/ReportMaCodeDao.java @@ -0,0 +1,70 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.ReportMaCodeDTO; +import com.elink.esua.epdc.entity.ReportMaCodeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@Mapper +public interface ReportMaCodeDao extends BaseDao { + + /** + * 获取部门报事码列表 + * + * @param params + * @return java.util.List + * @author zhy + * @date 2020/11/12 13:33 + */ + List selectListDeptMaCode(Map params); + + /** + * 查询所有未生成报事码的网格ID + * + * @param + * @return java.util.List + * @author zhy + * @date 2020/11/12 13:33 + */ + List selectListNoCodeGridId(); + + /** + * 根据机构类型,查询机构id及pids + * + * @param dataScopeDeptIds 用户部门数据权限 + * @param typeKey 机构类型{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant} + * @return java.util.List + * @author work@yujt.net.cn + * @date 2020/5/15 13:58 + */ + List selectListDeptIdByTypeKey(@Param("dataScopeDeptIds") List dataScopeDeptIds, @Param("typeKey") String typeKey); + + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/ReportMaCodeEntity.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/ReportMaCodeEntity.java new file mode 100644 index 0000000..4dbb92c --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/entity/ReportMaCodeEntity.java @@ -0,0 +1,81 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_report_ma_code") +public class ReportMaCodeEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 网格ID + */ + private Long gridId; + + /** + * 小程序码URL + */ + private String codeUrl; + + /** + * 是否是网格长码,0否 1是 + */ + private String leaderFlag; + + /** + * 网格名称 + */ + private String grid; + + /** + * 父所有部门 + */ + private String parentDeptIds; + + /** + * 父所有部门 + */ + private String parentDeptNames; + + /** + * 所有部门ID + */ + private String allDeptIds; + + /** + * 所有部门名称 + */ + private String allDeptNames; + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/excel/ReportMaCodeExcel.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/excel/ReportMaCodeExcel.java new file mode 100644 index 0000000..6b920f2 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/excel/ReportMaCodeExcel.java @@ -0,0 +1,80 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@Data +public class ReportMaCodeExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "网格ID") + private Long gridId; + + @Excel(name = "小程序码URL") + private String codeUrl; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + @Excel(name = "删除标记") + private String delFlag; + + @Excel(name = "是否是网格长码,0否 1是") + private String leaderFlag; + + @Excel(name = "网格名称") + private String grid; + + @Excel(name = "父所有部门") + private String parentDeptIds; + + @Excel(name = "父所有部门") + private String parentDeptNames; + + @Excel(name = "所有部门ID") + private String allDeptIds; + + @Excel(name = "所有部门名称") + private String allDeptNames; + + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/redis/ReportMaCodeRedis.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/redis/ReportMaCodeRedis.java new file mode 100644 index 0000000..7a12c2f --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/redis/ReportMaCodeRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@Component +public class ReportMaCodeRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/ReportMaCodeService.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/ReportMaCodeService.java new file mode 100644 index 0000000..481a84b --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/ReportMaCodeService.java @@ -0,0 +1,124 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.ReportMaCodeDTO; +import com.elink.esua.epdc.entity.ReportMaCodeEntity; + +import java.util.List; +import java.util.Map; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +public interface ReportMaCodeService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-11-12 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-11-12 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return ReportMaCodeDTO + * @author generator + * @date 2020-11-12 + */ + ReportMaCodeDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-11-12 + */ + void save(ReportMaCodeDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-11-12 + */ + void update(ReportMaCodeDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-11-12 + */ + void delete(String[] ids); + + /** + * 所有部门小程序码初始化 + * + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 09:32 + */ + Result initReportMaCode(); + + /** + * 生成指定网格小程序码 + * + * @param gridId + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 11:05 + */ + Result createReportMaCode(String gridId); + + /** + * 根据部门权限,同步部门信息 + * + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2020/5/15 15:27 + */ + Result initDeptForMaCode(); +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/ReportMaCodeServiceImpl.java b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/ReportMaCodeServiceImpl.java new file mode 100644 index 0000000..3827465 --- /dev/null +++ b/epdc-cloud-admin/src/main/java/com/elink/esua/epdc/service/impl/ReportMaCodeServiceImpl.java @@ -0,0 +1,269 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant; +import com.elink.esua.epdc.commons.tools.constant.StrConstant; +import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; +import com.elink.esua.epdc.commons.tools.exception.RenException; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dao.ReportMaCodeDao; +import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO; +import com.elink.esua.epdc.dto.ReportMaCodeDTO; +import com.elink.esua.epdc.dto.UploadToOssDTO; +import com.elink.esua.epdc.entity.ReportMaCodeEntity; +import com.elink.esua.epdc.feign.OssFeignClient; +import com.elink.esua.epdc.optimize.modules.deptlevel.dao.OptSysDeptDao; +import com.elink.esua.epdc.optimize.utils.DeptUtils; +import com.elink.esua.epdc.redis.ReportMaCodeRedis; +import com.elink.esua.epdc.service.ReportMaCodeService; +import com.elink.esua.epdc.utils.WxMaServiceUtils; +import com.google.common.collect.Lists; +import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 网格报事码 + * + * @author zhangyuan qu@elink-cn.com + * @since v1.0.0 2020-11-12 + */ +@Service +public class ReportMaCodeServiceImpl extends BaseServiceImpl implements ReportMaCodeService { + + @Autowired + private ReportMaCodeRedis reportMaCodeRedis; + + @Autowired + private WxMaServiceUtils wxMaServiceUtils; + + @Autowired + private OssFeignClient ossFeignClient; + + @Autowired + private OptSysDeptDao sysDeptDao; + + /** + * 小程序首页 + */ + private static String MA_FRONT_PAGE_URL = "pages/index/index"; + private static String MA_GRID_SUFFIX = "RP"; + + @Override + public PageData page(Map params) { + params.put("dataScopeDeptIds", SecurityUser.getUser().getDeptIdList()); + IPage page = getPage(params); + List pageDataList = baseDao.selectListDeptMaCode(params); + return new PageData<>(pageDataList, page.getTotal()); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, ReportMaCodeDTO.class); + } + + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public ReportMaCodeDTO get(String id) { + ReportMaCodeEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, ReportMaCodeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(ReportMaCodeDTO dto) { + ReportMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, ReportMaCodeEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(ReportMaCodeDTO dto) { + ReportMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, ReportMaCodeEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result initReportMaCode() { + + List gridIdList = this.baseDao.selectListNoCodeGridId(); + if (CollUtil.isEmpty(gridIdList)) { + return new Result(); + } + ReportMaCodeEntity entity; + for (Long gridId : gridIdList) { + entity = new ReportMaCodeEntity(); + entity.setCodeUrl(this.createMaCode(String.valueOf(gridId).concat(MA_GRID_SUFFIX), MA_FRONT_PAGE_URL)); + entity.setGridId(gridId); + this.baseDao.insert(entity); + } + return new Result(); + } + + @Override + public Result createReportMaCode(String gridId) { + ReportMaCodeEntity entity = new ReportMaCodeEntity(); + entity.setCodeUrl(this.createMaCode(gridId.concat(MA_GRID_SUFFIX), MA_FRONT_PAGE_URL)); + entity.setGridId(Long.parseLong(gridId)); + entity.setLeaderFlag(YesOrNoEnum.NO.value()); + this.baseDao.insert(entity); + return new Result(); + } + + @Override + public Result initDeptForMaCode() { + List dataScopeList = SecurityUser.getUser().getDeptIdList(); + List deptIdList = baseDao.selectListDeptIdByTypeKey(dataScopeList, OrganizationTypeConstant.ORG_TYPE_GRID_PARTY); + if (CollUtil.isEmpty(deptIdList)) { + return new Result(); + } + List insertList = Lists.newArrayList(); + for (ReportMaCodeEntity deptMaCodeEntity : deptIdList) { + ReportMaCodeEntity entity = packDeptBaseInfo(deptMaCodeEntity.getGridId(), deptMaCodeEntity.getParentDeptIds()); + if (null != entity) { + insertList.add(entity); + } + } + insertBatch(insertList, NumConstant.FIFTY); + return new Result(); + } + + /** + * 获取部门及父部门信息,拼接部门id,部门名称 + * + * @param deptId 本部门id + * @param pids 所有父部门id + * @return OptDeptMaCodeEntity + * @author work@yujt.net.cn + * @date 2020/5/18 14:06 + */ + private ReportMaCodeEntity packDeptBaseInfo(Long deptId, String pids) { + + String[] deptPids = pids.split(StrConstant.COMMA); + // 查询机构及父级机构 + List deptList = sysDeptDao.selectListDeptAndParents(deptId, deptPids); + + DeptLevelAndLeaderDTO deptLevel = DeptUtils.packageDeptLevelDto(deptPids, deptList); + + ReportMaCodeEntity reportMaCodeEntity = ConvertUtils.sourceToTarget(deptLevel, ReportMaCodeEntity.class); + if (null == reportMaCodeEntity) { + return null; + } + reportMaCodeEntity.setGrid(deptLevel.getDeptName()); + reportMaCodeEntity.setGridId(deptLevel.getDeptId()); + reportMaCodeEntity.setLeaderFlag(YesOrNoEnum.NO.value()); + + return reportMaCodeEntity; + } + + /** + * 创建微信小程序码,并上传到oss + * + * @param param 小程序码的参数 + * @param pageUrl 小程序码的跳转链接 + * @return java.lang.String 小程序码的下载抵制 + * @author work@yujt.net.cn + * @date 2019/10/22 10:14 + */ + private String createMaCode(String param, String pageUrl) { + File wxaCodeUnlimit; + try { + wxaCodeUnlimit = wxMaServiceUtils.normalWxMaService().getQrcodeService() + .createWxaCodeUnlimit(param, pageUrl, 1280, true, null, false); + } catch (WxErrorException e) { + throw new RenException("请求微信接口失败"); + } + + UploadToOssDTO dto = new UploadToOssDTO(); + dto.setFileByte(this.fileToByteArray(wxaCodeUnlimit)); + dto.setFileName(wxaCodeUnlimit.getName()); + + Result ossResult = ossFeignClient.uploadFile(dto); + if (null == ossResult || !ossResult.success() || null == ossResult.getData()) { + throw new RenException("小程序码上传失败"); + } + return ossResult.getData(); + } + + /** + * File文件转为byte[] + * + * @param file + * @return byte[] + * @author work@yujt.net.cn + * @date 2019/9/19 15:56 + */ + private byte[] fileToByteArray(File file) { + try { + //获取输入流 + FileInputStream fis = new FileInputStream(file); + //新的 byte 数组输出流,缓冲区容量1024byte + ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); + //缓存 + byte[] b = new byte[1024]; + int n; + while ((n = fis.read(b)) != NumConstant.ONE_NEG) { + bos.write(b, NumConstant.ZERO, n); + } + fis.close(); + //改变为byte[] + byte[] data = bos.toByteArray(); + bos.close(); + return data; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} \ No newline at end of file diff --git a/epdc-cloud-admin/src/main/resources/mapper/ReportMaCodeDao.xml b/epdc-cloud-admin/src/main/resources/mapper/ReportMaCodeDao.xml new file mode 100644 index 0000000..cb89187 --- /dev/null +++ b/epdc-cloud-admin/src/main/resources/mapper/ReportMaCodeDao.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file