+ * 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.optimize.modules.macode.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.DeptMaCodeDTO;
+import com.elink.esua.epdc.optimize.modules.macode.excel.DeptMaCodeExcel;
+import com.elink.esua.epdc.optimize.modules.macode.service.OptDeptMaCodeService;
+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 elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@RestController
+@RequestMapping("optimize/deptmacode")
+public class OptDeptMaCodeController {
+
+ @Autowired
+ private OptDeptMaCodeService deptMaCodeService;
+
+ @GetMapping("page")
+ 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);
+ }
+
+
+
+ @PostMapping("initDeptForMaCode")
+ public Result initDeptForMaCode(){
+ deptMaCodeService.initDeptForMaCode();
+ return new Result();
+ }
+}
\ No newline at end of file
diff --git a/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dao/OptDeptMaCodeDao.java b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dao/OptDeptMaCodeDao.java
new file mode 100644
index 0000000..f5efac6
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dao/OptDeptMaCodeDao.java
@@ -0,0 +1,57 @@
+/**
+ * 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.optimize.modules.macode.dao;
+
+import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
+import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 网格小程序码
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@Mapper
+public interface OptDeptMaCodeDao extends BaseDao {
+
+ /**
+ * 根据机构类型,查询机构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);
+
+ /**
+ * 根据机构id和机构父id,查询机构及父机构名称
+ *
+ * @param deptId 机构id
+ * @param parentIds 父机构id
+ * @return java.util.List
+ * @author work@yujt.net.cn
+ * @date 2020/5/15 14:10
+ */
+ List selectListDeptAndParents(@Param("deptId") String deptId, @Param("parentIds") String[] parentIds);
+}
\ No newline at end of file
diff --git a/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/DeptMaCodeDTO.java b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/DeptMaCodeDTO.java
new file mode 100644
index 0000000..34495aa
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/DeptMaCodeDTO.java
@@ -0,0 +1,111 @@
+/**
+ * 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.
+ *
+ * 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.optimize.modules.macode.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import com.elink.esua.epdc.commons.mybatis.entity.DeptScope;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+/**
+ * 网格小程序码
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@Data
+@EqualsAndHashCode(callSuper=false)
+@TableName("epdc_dept_ma_code_copy1")
+public class OptDeptMaCodeEntity extends DeptScope {
+
+ private static final long serialVersionUID = -6665011097985008073L;
+
+ /**
+ * 网格ID
+ */
+ private Long gridId;
+
+ /**
+ * 小程序码URL
+ */
+ private String codeUrl;
+
+ /**
+ * 是否是网格长码,0否 1是
+ */
+ private String leaderFlag;
+
+ /**
+ * 网格名称
+ */
+ private String grid;
+
+}
\ No newline at end of file
diff --git a/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/excel/DeptMaCodeExcel.java b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/excel/DeptMaCodeExcel.java
new file mode 100644
index 0000000..ed5317b
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/excel/DeptMaCodeExcel.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.optimize.modules.macode.excel;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 网格小程序码
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@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;
+
+ @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-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/redis/DeptMaCodeRedis.java b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/redis/DeptMaCodeRedis.java
new file mode 100644
index 0000000..9bcdccd
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/redis/DeptMaCodeRedis.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.optimize.modules.macode.redis;
+
+import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 网格小程序码
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@Component
+public class DeptMaCodeRedis {
+ @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-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/OptDeptMaCodeService.java b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/OptDeptMaCodeService.java
new file mode 100644
index 0000000..7c2c759
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/OptDeptMaCodeService.java
@@ -0,0 +1,105 @@
+/**
+ * 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.
+ *
+ * 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.optimize.modules.macode.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.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.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.constant.FieldConstant;
+import com.elink.esua.epdc.commons.tools.utils.Result;
+import com.elink.esua.epdc.dto.DeptMaCodeDTO;
+import com.elink.esua.epdc.optimize.modules.macode.dao.OptDeptMaCodeDao;
+import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity;
+import com.elink.esua.epdc.optimize.modules.macode.service.OptDeptMaCodeService;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 网格小程序码
+ *
+ * @author elink elink@elink-cn.com
+ * @since v1.0.0 2020-05-15
+ */
+@Service
+public class OptDeptMaCodeServiceImpl extends BaseServiceImpl implements OptDeptMaCodeService {
+
+ @Override
+ public PageData page(Map params) {
+
+ IPage page = baseDao.selectPage(
+ getPage(params, FieldConstant.CREATED_TIME, false),
+ getWrapper(params)
+ );
+ return getPageData(page, DeptMaCodeDTO.class);
+ }
+
+ @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 (OptDeptMaCodeEntity deptMaCodeEntity : deptIdList) {
+ insertList.add(packDeptBaseInfo(deptMaCodeEntity.getGrid(), deptMaCodeEntity.getParentDeptIds()));
+ }
+ insertBatch(insertList, NumConstant.FIFTY);
+ return new Result();
+ }
+
+
+ private OptDeptMaCodeEntity packDeptBaseInfo(String deptId, String pids) {
+ // 查询机构及父级机构
+ List deptList = baseDao.selectListDeptAndParents(deptId, pids.split(StrConstant.COMMA));
+ if (CollUtil.isEmpty(deptList)) {
+ return null;
+ }
+ int size = deptList.size();
+
+ String[] allDeptIds = new String[size];
+ String[] allDeptNames = new String[size];
+ String[] parentDeptIds = new String[size - NumConstant.ONE];
+ String[] parentDeptNames = new String[size - NumConstant.ONE];
+ for (int i = 0; i < size; i++) {
+ allDeptIds[i] = String.valueOf(deptList.get(i).getGridId());
+ allDeptNames[i] = deptList.get(i).getGrid();
+ if (i < size - NumConstant.ONE) {
+ parentDeptIds[i] = String.valueOf(deptList.get(i).getGridId());
+ parentDeptNames[i] = deptList.get(i).getGrid();
+ }
+ }
+ OptDeptMaCodeEntity deptMaCodeEntity = deptList.get(size - NumConstant.ONE);
+ deptMaCodeEntity.setLeaderFlag(YesOrNoEnum.NO.value());
+ deptMaCodeEntity.setAllDeptIds(StringUtils.join(allDeptIds, StrConstant.COMMA));
+ deptMaCodeEntity.setParentDeptIds(StringUtils.join(parentDeptIds, StrConstant.COMMA));
+ deptMaCodeEntity.setAllDeptNames(StringUtils.join(allDeptNames, StrConstant.HYPHEN));
+ deptMaCodeEntity.setParentDeptNames(StringUtils.join(parentDeptNames, StrConstant.HYPHEN));
+ return deptMaCodeEntity;
+ }
+
+ @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) {
+ OptDeptMaCodeEntity entity = baseDao.selectById(id);
+ return ConvertUtils.sourceToTarget(entity, DeptMaCodeDTO.class);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(DeptMaCodeDTO dto) {
+ OptDeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, OptDeptMaCodeEntity.class);
+ insert(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(DeptMaCodeDTO dto) {
+ OptDeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, OptDeptMaCodeEntity.class);
+ updateById(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void delete(String[] ids) {
+ // 逻辑删除(@TableLogic 注解)
+ baseDao.deleteBatchIds(Arrays.asList(ids));
+ }
+
+
+}
\ No newline at end of file
diff --git a/epdc-cloud-optimize-department/src/main/resources/application.yml b/epdc-cloud-optimize-department/src/main/resources/application.yml
new file mode 100644
index 0000000..1070a5d
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/resources/application.yml
@@ -0,0 +1,25 @@
+
+mybatis-plus:
+ mapper-locations: classpath:/mapper/**/*.xml
+ #实体扫描,多个package用逗号或者分号分隔
+ typeAliasesPackage: com.elink.esua.epdc.optimize.modules.*.entity
+ global-config:
+ #数据库相关配置
+ db-config:
+ #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
+ id-type: ID_WORKER
+ #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
+ field-strategy: NOT_NULL
+ #驼峰下划线转换
+ column-underline: true
+ #db-type: mysql
+ #刷新mapper 调试神器
+ refresh-mapper: true
+ banner: false
+ #原生配置
+ configuration:
+ map-underscore-to-camel-case: true
+ cache-enabled: false
+ call-setters-on-nulls: true
+ jdbc-type-for-null: 'null'
+
diff --git a/epdc-cloud-optimize-department/src/main/resources/mapper/macode/OptDeptMaCodeDao.xml b/epdc-cloud-optimize-department/src/main/resources/mapper/macode/OptDeptMaCodeDao.xml
new file mode 100644
index 0000000..852b06d
--- /dev/null
+++ b/epdc-cloud-optimize-department/src/main/resources/mapper/macode/OptDeptMaCodeDao.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c48ddad..eb3c91f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,5 +15,6 @@
epdc-cloud-commons-yushanepdc-cloud-gateway-yushanepdc-cloud-parent-yushan
+ epdc-cloud-optimize-department