|
|
@ -18,27 +18,38 @@ |
|
|
|
package com.elink.esua.epdc.optimize.modules.macode.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.ArrayUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
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.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.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.dto.DeptMaCodeDTO; |
|
|
|
import com.elink.esua.epdc.dto.UploadToOssDTO; |
|
|
|
import com.elink.esua.epdc.optimize.modules.feign.OptOssFeignClient; |
|
|
|
import com.elink.esua.epdc.optimize.modules.macode.dao.OptDeptMaCodeDao; |
|
|
|
import com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO; |
|
|
|
import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity; |
|
|
|
import com.elink.esua.epdc.optimize.modules.macode.service.OptDeptMaCodeService; |
|
|
|
import com.elink.esua.epdc.optimize.utils.FileUtils; |
|
|
|
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.File; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -52,14 +63,23 @@ import java.util.Map; |
|
|
|
@Service |
|
|
|
public class OptDeptMaCodeServiceImpl extends BaseServiceImpl<OptDeptMaCodeDao, OptDeptMaCodeEntity> implements OptDeptMaCodeService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<DeptMaCodeDTO> page(Map<String, Object> params) { |
|
|
|
@Autowired |
|
|
|
private WxMaServiceUtils wxMaServiceUtils; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OptOssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
IPage<OptDeptMaCodeEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, DeptMaCodeDTO.class); |
|
|
|
/** |
|
|
|
* 小程序首页 |
|
|
|
*/ |
|
|
|
private final static String MA_FRONT_PAGE_URL = "pages/index/index"; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<OptDeptMaCodeDTO> page(Map<String, Object> params) { |
|
|
|
params.put("dataScopeDeptIds", SecurityUser.getUser().getDeptIdList()); |
|
|
|
IPage<OptDeptMaCodeDTO> page = getPage(params); |
|
|
|
List<OptDeptMaCodeDTO> pageDataList = baseDao.selectListDeptMaCode(params); |
|
|
|
return new PageData<>(pageDataList, page.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -71,34 +91,126 @@ public class OptDeptMaCodeServiceImpl extends BaseServiceImpl<OptDeptMaCodeDao, |
|
|
|
} |
|
|
|
List<OptDeptMaCodeEntity> insertList = Lists.newArrayList(); |
|
|
|
for (OptDeptMaCodeEntity deptMaCodeEntity : deptIdList) { |
|
|
|
insertList.add(packDeptBaseInfo(deptMaCodeEntity.getGrid(), deptMaCodeEntity.getParentDeptIds())); |
|
|
|
OptDeptMaCodeEntity entity = packDeptBaseInfo(deptMaCodeEntity.getGridId(), deptMaCodeEntity.getParentDeptIds()); |
|
|
|
if (null != entity) { |
|
|
|
insertList.add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
insertBatch(insertList, NumConstant.FIFTY); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result createDeptMaCode(String gridId) { |
|
|
|
OptDeptMaCodeEntity entity = new OptDeptMaCodeEntity(); |
|
|
|
entity.setCodeUrl(this.createMaCode(gridId, MA_FRONT_PAGE_URL)); |
|
|
|
this.baseDao.insert(entity); |
|
|
|
|
|
|
|
UpdateWrapper<OptDeptMaCodeEntity> wrapper = new UpdateWrapper<>(); |
|
|
|
wrapper.eq(FieldConstant.GRID_ID, gridId); |
|
|
|
|
|
|
|
private OptDeptMaCodeEntity packDeptBaseInfo(String deptId, String pids) { |
|
|
|
baseDao.update(entity, wrapper); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result createGridLeaderMaCode() { |
|
|
|
QueryWrapper<OptDeptMaCodeEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("leader_flag", YesOrNoEnum.YES.value()); |
|
|
|
Integer selectCount = this.baseDao.selectCount(wrapper); |
|
|
|
if (selectCount > NumConstant.ZERO) { |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
OptDeptMaCodeEntity entity = new OptDeptMaCodeEntity(); |
|
|
|
entity.setAllDeptNames("全平台通用"); |
|
|
|
entity.setCodeUrl(this.createMaCode("gridLeader", MA_FRONT_PAGE_URL)); |
|
|
|
entity.setLeaderFlag(YesOrNoEnum.YES.value()); |
|
|
|
this.baseDao.insert(entity); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建微信小程序码,并上传到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(FileUtils.fileToByteArray(wxaCodeUnlimit)); |
|
|
|
dto.setFileName(wxaCodeUnlimit.getName()); |
|
|
|
|
|
|
|
Result<String> ossResult = ossFeignClient.uploadFile(dto); |
|
|
|
if (null == ossResult || !ossResult.success() || null == ossResult.getData()) { |
|
|
|
throw new RenException("小程序码上传失败"); |
|
|
|
} |
|
|
|
return ossResult.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取部门及父部门信息,拼接部门id,部门名称 |
|
|
|
* |
|
|
|
* @param deptId 本部门id |
|
|
|
* @param pids 所有父部门id |
|
|
|
* @return com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/5/18 14:06 |
|
|
|
*/ |
|
|
|
private OptDeptMaCodeEntity packDeptBaseInfo(Long deptId, String pids) { |
|
|
|
|
|
|
|
String[] deptPids = pids.split(StrConstant.COMMA); |
|
|
|
// 查询机构及父级机构
|
|
|
|
List<OptDeptMaCodeEntity> deptList = baseDao.selectListDeptAndParents(deptId, pids.split(StrConstant.COMMA)); |
|
|
|
List<OptDeptMaCodeEntity> deptList = baseDao.selectListDeptAndParents(deptId, deptPids); |
|
|
|
if (CollUtil.isEmpty(deptList)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
int size = deptList.size(); |
|
|
|
// 按上下级顺序组装部门集合
|
|
|
|
List<OptDeptMaCodeEntity> newDeptIdList = Lists.newArrayList(); |
|
|
|
if (ArrayUtil.isEmpty(deptPids)) { |
|
|
|
// 父级部门为空,则只有部门本身,没有上级
|
|
|
|
newDeptIdList = deptList; |
|
|
|
} else { |
|
|
|
// 按部门顺序开始组装
|
|
|
|
for (int i = 0; i < deptPids.length; i++) { |
|
|
|
for (OptDeptMaCodeEntity entity : deptList) { |
|
|
|
if (String.valueOf(entity.getGridId()).equals(deptPids[i])) { |
|
|
|
newDeptIdList.add(entity); |
|
|
|
deptList.remove(entity); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 所有父级部门处理完成,最后剩下部门本身
|
|
|
|
newDeptIdList.addAll(deptList); |
|
|
|
} |
|
|
|
|
|
|
|
int size = newDeptIdList.size(); |
|
|
|
int maxIndex = size - NumConstant.ONE; |
|
|
|
|
|
|
|
String[] allDeptIds = new String[size]; |
|
|
|
String[] allDeptNames = new String[size]; |
|
|
|
String[] parentDeptIds = new String[size - NumConstant.ONE]; |
|
|
|
String[] parentDeptNames = new String[size - NumConstant.ONE]; |
|
|
|
String[] parentDeptIds = new String[maxIndex]; |
|
|
|
String[] parentDeptNames = new String[maxIndex]; |
|
|
|
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(); |
|
|
|
allDeptIds[i] = String.valueOf(newDeptIdList.get(i).getGridId()); |
|
|
|
allDeptNames[i] = newDeptIdList.get(i).getGrid(); |
|
|
|
if (i < maxIndex) { |
|
|
|
parentDeptIds[i] = String.valueOf(newDeptIdList.get(i).getGridId()); |
|
|
|
parentDeptNames[i] = newDeptIdList.get(i).getGrid(); |
|
|
|
} |
|
|
|
} |
|
|
|
OptDeptMaCodeEntity deptMaCodeEntity = deptList.get(size - NumConstant.ONE); |
|
|
|
OptDeptMaCodeEntity deptMaCodeEntity = newDeptIdList.get(maxIndex); |
|
|
|
deptMaCodeEntity.setLeaderFlag(YesOrNoEnum.NO.value()); |
|
|
|
deptMaCodeEntity.setAllDeptIds(StringUtils.join(allDeptIds, StrConstant.COMMA)); |
|
|
|
deptMaCodeEntity.setParentDeptIds(StringUtils.join(parentDeptIds, StrConstant.COMMA)); |
|
|
|