diff --git a/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/DeptMaCodeDTO.java b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/DeptMaCodeDTO.java new file mode 100644 index 000000000..b4087c925 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/DeptMaCodeDTO.java @@ -0,0 +1,97 @@ +/** + * 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.dto; + +import java.io.Serializable; +import java.util.Date; + +import lombok.Data; + + +/** + * 网格小程序码 + * + * @author work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@Data +public class DeptMaCodeDTO implements Serializable { + + private static final long serialVersionUID = -7464965787113267467L; + + /** + * 主键 + */ + private String id; + + /** + * 网格ID + */ + private Long gridId; + + /** + * 小程序码URL + */ + private String codeUrl; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * 删除标记 + */ + private String delFlag; + + /** + * 街道名 + */ + private String street; + + /** + * 社区名 + */ + private String community; + + /** + * 网格名 + */ + private String grid; + +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/UploadToOssDTO.java b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/UploadToOssDTO.java new file mode 100644 index 000000000..0fc514c07 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/UploadToOssDTO.java @@ -0,0 +1,19 @@ +package com.elink.esua.epdc.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author work@yujt.net.cn + * @date 19/9/19 15:31 + */ +@Data +public class UploadToOssDTO implements Serializable { + + private static final long serialVersionUID = 6136753578748343389L; + + private String fileName; + + private byte[] fileByte; +} diff --git a/esua-epdc/epdc-admin/epdc-admin-server/pom.xml b/esua-epdc/epdc-admin/epdc-admin-server/pom.xml index 7930579ac..d2eae8389 100644 --- a/esua-epdc/epdc-admin/epdc-admin-server/pom.xml +++ b/esua-epdc/epdc-admin/epdc-admin-server/pom.xml @@ -50,6 +50,18 @@ org.springframework.cloud spring-cloud-starter-zipkin + + + com.esua.epdc + epdc-commons-tolls-wx-ma + ${project.version} + + + + io.github.openfeign + feign-httpclient + 10.3.0 + @@ -108,10 +120,13 @@ dev - true + false 47.104.224.45:8848 http://localhost:9411 + + wxdd8530c5f4926766 + 5bf4fb813145431b3493a10aa7e041e9 @@ -125,6 +140,9 @@ 47.104.224.45:8848 http://localhost:9411 + + wxdd8530c5f4926766 + 5bf4fb813145431b3493a10aa7e041e9 @@ -138,6 +156,9 @@ 172.31.171.61:9300 http://172.31.171.61:9411 + + wxdd8530c5f4926766 + 5bf4fb813145431b3493a10aa7e041e9 diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/AdminApplication.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/AdminApplication.java index 3437123c3..5ee3a1f85 100644 --- a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/AdminApplication.java +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/AdminApplication.java @@ -11,6 +11,7 @@ package com.elink.esua.epdc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; /** * 管理后台 @@ -20,6 +21,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; */ @SpringBootApplication @EnableDiscoveryClient +@EnableFeignClients public class AdminApplication { public static void main(String[] args) { diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/DeptMaCodeController.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/DeptMaCodeController.java new file mode 100644 index 000000000..2d1bdb336 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/DeptMaCodeController.java @@ -0,0 +1,122 @@ +/** + * 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.mybatis.annotation.DataFilter; +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.DeptMaCodeDTO; +import com.elink.esua.epdc.excel.DeptMaCodeExcel; +import com.elink.esua.epdc.service.DeptMaCodeService; +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 work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@RestController +@RequestMapping("deptmacode") +public class DeptMaCodeController { + + @Autowired + private DeptMaCodeService deptMaCodeService; + + @GetMapping("page") + @DataFilter(tableAlias = "dg", deptId = "id", prefix = "AND") + public Result> page(@RequestParam Map params) { + PageData page = deptMaCodeService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id) { + DeptMaCodeDTO data = deptMaCodeService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody DeptMaCodeDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + deptMaCodeService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody DeptMaCodeDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + deptMaCodeService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids) { + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + deptMaCodeService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = deptMaCodeService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, DeptMaCodeExcel.class); + } + + /** + * 所有部门小程序码初始化 + * + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 09:33 + */ + @PostMapping("init") + public Result initDeptMaCode() { + return deptMaCodeService.initDeptMaCode(); + } + + /** + * 生成指定网格小程序码 + * + * @param gridId + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 11:04 + */ + @PostMapping("create/{gridId}") + public Result createDeptMaCode(@PathVariable("gridId") String gridId) { + return deptMaCodeService.createDeptMaCode(gridId); + } + + +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/dao/DeptMaCodeDao.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/dao/DeptMaCodeDao.java new file mode 100644 index 000000000..c5bb9c476 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/dao/DeptMaCodeDao.java @@ -0,0 +1,56 @@ +/** + * 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.DeptMaCodeDTO; +import com.elink.esua.epdc.entity.DeptMaCodeEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +import java.util.Map; + +/** + * 网格小程序码 + * + * @author work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@Mapper +public interface DeptMaCodeDao extends BaseDao { + + /** + * 获取部门小程序码列表 + * + * @param params + * @return java.util.List + * @author work@yujt.net.cn + * @date 2019/9/19 09:18 + */ + List selectListDeptMaCode(Map params); + + /** + * 查询所有未生成小程序码的网格ID + * + * @param + * @return java.util.List + * @author work@yujt.net.cn + * @date 2019/9/19 10:38 + */ + List selectListNoCodeGridId(); +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/entity/DeptMaCodeEntity.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/entity/DeptMaCodeEntity.java new file mode 100644 index 000000000..ee301c719 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/entity/DeptMaCodeEntity.java @@ -0,0 +1,51 @@ +/** + * 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 work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_dept_ma_code") +public class DeptMaCodeEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 7851330983990440333L; + + /** + * 网格ID + */ + private Long gridId; + + /** + * 小程序码URL + */ + private String codeUrl; + +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/excel/DeptMaCodeExcel.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/excel/DeptMaCodeExcel.java new file mode 100644 index 000000000..87a1936ea --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/excel/DeptMaCodeExcel.java @@ -0,0 +1,62 @@ +/** + * 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 work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@Data +public class DeptMaCodeExcel { + + @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; + + +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java new file mode 100644 index 000000000..0e67831de --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java @@ -0,0 +1,30 @@ +package com.elink.esua.epdc.feign; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadToOssDTO; +import com.elink.esua.epdc.feign.fallback.OssFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; + + +/** + * @author work@yujt.net.cn + * @date 19/9/19 10:12 + */ +@FeignClient(name = ServiceConstant.EPDC_OSS_SERVER, fallback = OssFeignClientFallback.class) +public interface OssFeignClient { + + /** + * File文件上传到文件服务器 + * + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 10:15 + */ + @PostMapping(value = "oss/file/uploadFile", consumes = MediaType.APPLICATION_JSON_VALUE) + Result uploadFile(UploadToOssDTO dto); + +} diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java new file mode 100644 index 000000000..078b5ef46 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java @@ -0,0 +1,22 @@ +package com.elink.esua.epdc.feign.fallback; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadToOssDTO; +import com.elink.esua.epdc.feign.OssFeignClient; +import org.springframework.stereotype.Component; + +/** + * @author work@yujt.net.cn + * @date 19/9/19 10:12 + */ +@Component +public class OssFeignClientFallback implements OssFeignClient { + + @Override + public Result uploadFile(UploadToOssDTO dto) { + return ModuleUtils.feignConError(ServiceConstant.EPDC_OSS_SERVER, "uploadFile", dto.getFileName()); + } + +} diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/DeptMaCodeService.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/DeptMaCodeService.java new file mode 100644 index 000000000..90ae915f4 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/DeptMaCodeService.java @@ -0,0 +1,115 @@ +/** + * 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.DeptMaCodeDTO; +import com.elink.esua.epdc.entity.DeptMaCodeEntity; + +import java.util.List; +import java.util.Map; + +/** + * 网格小程序码 + * + * @author work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +public interface DeptMaCodeService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2019-09-19 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2019-09-19 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return DeptMaCodeDTO + * @author generator + * @date 2019-09-19 + */ + DeptMaCodeDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2019-09-19 + */ + void save(DeptMaCodeDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2019-09-19 + */ + void update(DeptMaCodeDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2019-09-19 + */ + 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 initDeptMaCode(); + + /** + * 生成指定网格小程序码 + * + * @param gridId + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author work@yujt.net.cn + * @date 2019/9/19 11:05 + */ + Result createDeptMaCode(String gridId); +} \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/impl/DeptMaCodeServiceImpl.java b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/impl/DeptMaCodeServiceImpl.java new file mode 100644 index 000000000..1e79364f7 --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/impl/DeptMaCodeServiceImpl.java @@ -0,0 +1,210 @@ +/** + * 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.binarywang.wx.miniapp.api.WxMaQrcodeService; +import cn.binarywang.wx.miniapp.api.WxMaService; +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.NumConstant; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dao.DeptMaCodeDao; +import com.elink.esua.epdc.dto.DeptMaCodeDTO; +import com.elink.esua.epdc.dto.UploadToOssDTO; +import com.elink.esua.epdc.entity.DeptMaCodeEntity; +import com.elink.esua.epdc.feign.OssFeignClient; +import com.elink.esua.epdc.service.DeptMaCodeService; +import lombok.extern.slf4j.Slf4j; +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.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 网格小程序码 + * + * @author work@yujt.net.cn + * @since v1.0.0 2019-09-19 + */ +@Slf4j +@Service +public class DeptMaCodeServiceImpl extends BaseServiceImpl implements DeptMaCodeService { + + @Autowired + private WxMaService wxMaService; + + @Autowired + private OssFeignClient ossFeignClient; + + @Override + public PageData page(Map params) { + + IPage page = this.getPage(params); + List dtoList = this.baseDao.selectListDeptMaCode(params); + + return new PageData<>(dtoList, page.getTotal()); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, DeptMaCodeDTO.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 DeptMaCodeDTO get(String id) { + DeptMaCodeEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, DeptMaCodeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(DeptMaCodeDTO dto) { + DeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, DeptMaCodeEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(DeptMaCodeDTO dto) { + DeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, DeptMaCodeEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result initDeptMaCode() { + + List gridIdList = this.baseDao.selectListNoCodeGridId(); + if (CollUtil.isEmpty(gridIdList)) { + return new Result(); + } + String scenePrefix = "gid="; + String page = "pages/register/register"; + + Result ossResult; + File wxaCodeUnlimit; + UploadToOssDTO uploadDto; + + DeptMaCodeEntity entity; + WxMaQrcodeService qrcodeService = wxMaService.getQrcodeService(); + for (Long gridId : gridIdList) { + try { + wxaCodeUnlimit = qrcodeService.createWxaCodeUnlimit(scenePrefix + gridId, page); + } catch (WxErrorException e) { + log.error("->initDeptMaCode::createWxaCodeUnlimit error::deptId={}", gridId); + continue; + } + uploadDto = new UploadToOssDTO(); + uploadDto.setFileByte(this.fileToByteArray(wxaCodeUnlimit)); + uploadDto.setFileName(wxaCodeUnlimit.getName()); + ossResult = ossFeignClient.uploadFile(uploadDto); + if (null == ossResult || !ossResult.success() || null == ossResult.getData()) { + log.error("->initDeptMaCode::oss uploadFile error::deptId={}", gridId); + continue; + } + entity = new DeptMaCodeEntity(); + entity.setCodeUrl(ossResult.getData()); + entity.setGridId(gridId); + this.baseDao.insert(entity); + } + return new Result(); + } + + @Override + public Result createDeptMaCode(String gridId) { + File wxaCodeUnlimit; + try { + wxaCodeUnlimit = wxMaService.getQrcodeService().createWxaCodeUnlimit("gid=" + gridId, "pages/register/register"); + } catch (WxErrorException e) { + return new Result().error("请求微信接口失败"); + } + + 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()) { + return new Result().error("小程序码上传失败"); + } + DeptMaCodeEntity entity = new DeptMaCodeEntity(); + entity.setCodeUrl(ossResult.getData()); + entity.setGridId(Long.parseLong(gridId)); + this.baseDao.insert(entity); + return new Result(); + } + + /** + * 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/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml b/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml index 732469193..432ae14e1 100644 --- a/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml @@ -4,6 +4,8 @@ server: context-path: /sys spring: + main: + allow-bean-definition-overriding: true application: name: epdc-admin-server #环境 dev|test|prod @@ -63,3 +65,30 @@ mybatis-plus: cache-enabled: false call-setters-on-nulls: true jdbc-type-for-null: 'null' + +wx: + ma: + appid: @wx.ma.appId@ + secret: @wx.ma.secret@ + token: #微信小程序消息服务器配置的token + aesKey: #微信小程序消息服务器配置的EncodingAESKey + msgDataFormat: JSON + + +feign: + hystrix: + enabled: true + httpclient: + enabled: true + +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 60000 #缺省为1000 + +ribbon: + ReadTimeout: 300000 + ConnectTimeout: 300000 \ No newline at end of file diff --git a/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/mapper/DeptMaCodeDao.xml b/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/mapper/DeptMaCodeDao.xml new file mode 100644 index 000000000..dc9d334bb --- /dev/null +++ b/esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/mapper/DeptMaCodeDao.xml @@ -0,0 +1,35 @@ + + + + + + + + + + \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml b/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml index 9dd4d6712..b0da9fcbc 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml @@ -58,14 +58,17 @@ ${project.version} - com.esua.epdc - epdc-wx + epdc-commons-tolls-wx-mp + ${project.version} + + + com.esua.epdc + epdc-commons-tolls-wx-ma ${project.version} - com.esua.epdc epdc-common-clienttoken