Browse Source

新增生成小程序码功能

dev
yujintao 6 years ago
parent
commit
c224dfd10c
  1. 97
      esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/DeptMaCodeDTO.java
  2. 19
      esua-epdc/epdc-admin/epdc-admin-client/src/main/java/com/elink/esua/epdc/dto/UploadToOssDTO.java
  3. 23
      esua-epdc/epdc-admin/epdc-admin-server/pom.xml
  4. 2
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/AdminApplication.java
  5. 122
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/DeptMaCodeController.java
  6. 56
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/dao/DeptMaCodeDao.java
  7. 51
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/entity/DeptMaCodeEntity.java
  8. 62
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/excel/DeptMaCodeExcel.java
  9. 30
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java
  10. 22
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java
  11. 115
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/DeptMaCodeService.java
  12. 210
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/service/impl/DeptMaCodeServiceImpl.java
  13. 29
      esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml
  14. 35
      esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/mapper/DeptMaCodeDao.xml
  15. 9
      esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml

97
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

19
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;
}

23
esua-epdc/epdc-admin/epdc-admin-server/pom.xml

@ -50,6 +50,18 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!--微信小程序-->
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-tolls-wx-ma</artifactId>
<version>${project.version}</version>
</dependency>
<!-- 替换Feign原生httpclient -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>10.3.0</version>
</dependency>
</dependencies>
<build>
@ -108,10 +120,13 @@
<spring.profiles.active>dev</spring.profiles.active>
<!-- nacos -->
<nacos.register-enabled>true</nacos.register-enabled>
<nacos.register-enabled>false</nacos.register-enabled>
<nacos.server-addr>47.104.224.45:8848</nacos.server-addr>
<spring.zipkin.base-url>http://localhost:9411</spring.zipkin.base-url>
<!--小程序配置-->
<wx.ma.appId>wxdd8530c5f4926766</wx.ma.appId>
<wx.ma.secret>5bf4fb813145431b3493a10aa7e041e9</wx.ma.secret>
</properties>
</profile>
<profile>
@ -125,6 +140,9 @@
<nacos.server-addr>47.104.224.45:8848</nacos.server-addr>
<spring.zipkin.base-url>http://localhost:9411</spring.zipkin.base-url>
<!--小程序配置-->
<wx.ma.appId>wxdd8530c5f4926766</wx.ma.appId>
<wx.ma.secret>5bf4fb813145431b3493a10aa7e041e9</wx.ma.secret>
</properties>
</profile>
<profile>
@ -138,6 +156,9 @@
<nacos.server-addr>172.31.171.61:9300</nacos.server-addr>
<spring.zipkin.base-url>http://172.31.171.61:9411</spring.zipkin.base-url>
<!--小程序配置-->
<wx.ma.appId>wxdd8530c5f4926766</wx.ma.appId>
<wx.ma.secret>5bf4fb813145431b3493a10aa7e041e9</wx.ma.secret>
</properties>
</profile>
</profiles>

2
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) {

122
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<PageData<DeptMaCodeDTO>> page(@RequestParam Map<String, Object> params) {
PageData<DeptMaCodeDTO> page = deptMaCodeService.page(params);
return new Result<PageData<DeptMaCodeDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<DeptMaCodeDTO> get(@PathVariable("id") String id) {
DeptMaCodeDTO data = deptMaCodeService.get(id);
return new Result<DeptMaCodeDTO>().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<String, Object> params, HttpServletResponse response) throws Exception {
List<DeptMaCodeDTO> 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);
}
}

56
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<DeptMaCodeEntity> {
/**
* 获取部门小程序码列表
*
* @param params
* @return java.util.List<com.elink.esua.epdc.dto.DeptMaCodeDTO>
* @author work@yujt.net.cn
* @date 2019/9/19 09:18
*/
List<DeptMaCodeDTO> selectListDeptMaCode(Map<String, Object> params);
/**
* 查询所有未生成小程序码的网格ID
*
* @param
* @return java.util.List<java.lang.Long>
* @author work@yujt.net.cn
* @date 2019/9/19 10:38
*/
List<Long> selectListNoCodeGridId();
}

51
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

62
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

30
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<java.lang.String>
* @author work@yujt.net.cn
* @date 2019/9/19 10:15
*/
@PostMapping(value = "oss/file/uploadFile", consumes = MediaType.APPLICATION_JSON_VALUE)
Result<String> uploadFile(UploadToOssDTO dto);
}

22
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<String> uploadFile(UploadToOssDTO dto) {
return ModuleUtils.feignConError(ServiceConstant.EPDC_OSS_SERVER, "uploadFile", dto.getFileName());
}
}

115
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<DeptMaCodeEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<DeptMaCodeDTO>
* @author generator
* @date 2019-09-19
*/
PageData<DeptMaCodeDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<DeptMaCodeDTO>
* @author generator
* @date 2019-09-19
*/
List<DeptMaCodeDTO> list(Map<String, Object> 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);
}

210
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<DeptMaCodeDao, DeptMaCodeEntity> implements DeptMaCodeService {
@Autowired
private WxMaService wxMaService;
@Autowired
private OssFeignClient ossFeignClient;
@Override
public PageData<DeptMaCodeDTO> page(Map<String, Object> params) {
IPage<DeptMaCodeDTO> page = this.getPage(params);
List<DeptMaCodeDTO> dtoList = this.baseDao.selectListDeptMaCode(params);
return new PageData<>(dtoList, page.getTotal());
}
@Override
public List<DeptMaCodeDTO> list(Map<String, Object> params) {
List<DeptMaCodeEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, DeptMaCodeDTO.class);
}
private QueryWrapper<DeptMaCodeEntity> getWrapper(Map<String, Object> params) {
String id = (String) params.get(FieldConstant.ID_HUMP);
QueryWrapper<DeptMaCodeEntity> 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<Long> gridIdList = this.baseDao.selectListNoCodeGridId();
if (CollUtil.isEmpty(gridIdList)) {
return new Result();
}
String scenePrefix = "gid=";
String page = "pages/register/register";
Result<String> 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<String> 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;
}
}

29
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

35
esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/mapper/DeptMaCodeDao.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.elink.esua.epdc.dao.DeptMaCodeDao">
<select id="selectListDeptMaCode" resultType="com.elink.esua.epdc.dto.DeptMaCodeDTO">
SELECT
ds.`name` street,
dc.`name` community,
dg.`name` grid,
dg.id AS GRID_ID,
ed.CREATED_TIME,
ed.CODE_URL
FROM
sys_dept dg
LEFT JOIN epdc_dept_ma_code ed ON dg.id = ed.GRID_ID and ed.del_flag = '0'
LEFT JOIN sys_dept dc ON dg.pid = dc.id
LEFT JOIN sys_dept ds ON dc.pid = ds.id
WHERE
dg.type_key = 'grid_party' and dg.del_flag = '0'
ORDER BY
dc.`name` asc,dg.`name` asc
</select>
<select id="selectListNoCodeGridId" resultType="java.lang.Long">
SELECT
d.id
FROM
sys_dept d
WHERE
d.type_key = 'grid_party'
AND NOT EXISTS (SELECT 1 FROM epdc_dept_ma_code e WHERE e.GRID_ID = d.id AND e.DEL_FLAG = '0')
</select>
</mapper>

9
esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml

@ -58,14 +58,17 @@
<version>${project.version}</version>
</dependency>
<!--微信公众号-->
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-wx</artifactId>
<artifactId>epdc-commons-tolls-wx-mp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-tolls-wx-ma</artifactId>
<version>${project.version}</version>
</dependency>
<!--微信公众号-->
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-common-clienttoken</artifactId>

Loading…
Cancel
Save