|
@@ -0,0 +1,214 @@
|
|
|
+package com.dragon.tj.portal.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.dragon.tj.portal.auth.model.LoginUser;
|
|
|
+import com.dragon.tj.portal.common.base.R;
|
|
|
+import com.dragon.tj.portal.entity.AppInfo;
|
|
|
+import com.dragon.tj.portal.entity.BusinessInfo;
|
|
|
+import com.dragon.tj.portal.entity.InstallInfo;
|
|
|
+import com.dragon.tj.portal.entity.PageParam;
|
|
|
+import com.dragon.tj.portal.mapper.BusinessMapper;
|
|
|
+import com.dragon.tj.portal.mapper.app.AppInfoMapper;
|
|
|
+import com.dragon.tj.portal.mapper.app.InstallInfoMapper;
|
|
|
+import com.dragon.tj.portal.service.BusinessService;
|
|
|
+import com.dragon.tj.portal.service.SysDictService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class BusinessServiceImpl implements BusinessService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BusinessMapper businessMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AppInfoMapper appInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InstallInfoMapper installInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDictService sysDictService;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * CRUD
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public int add(BusinessInfo businessInfo, LoginUser loginUser) {
|
|
|
+ businessInfo.setCreateUser(loginUser.getUsername());
|
|
|
+ //获取应用
|
|
|
+ QueryWrapper<AppInfo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq(businessInfo.getAppId() != null,
|
|
|
+ "id",businessInfo.getAppId());
|
|
|
+ wrapper.like(businessInfo.getAppName() != null,
|
|
|
+ "system_name",businessInfo.getAppName());
|
|
|
+
|
|
|
+ List<AppInfo> appInfoList = appInfoMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ if (appInfoList == null || appInfoList.size() > 1){
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ businessInfo.setAppId(appInfoList.get(0).getId());
|
|
|
+ businessInfo.setAppName(appInfoList.get(0).getSystemName());
|
|
|
+
|
|
|
+ return businessMapper.insert(businessInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int delete(Long id) {
|
|
|
+ BusinessInfo businessInfo = new BusinessInfo();
|
|
|
+ businessInfo.setId(id);
|
|
|
+ businessInfo.setDelFlag(1);
|
|
|
+
|
|
|
+ return businessMapper.updateById(businessInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int update(BusinessInfo businessInfo) {
|
|
|
+ return businessMapper.updateById(businessInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BusinessInfo detail(Long id) {
|
|
|
+ return businessMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 获取类型
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public R getType() {
|
|
|
+ return sysDictService.getDict("app_type");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 搜索App业务程序
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Page<BusinessInfo> search(PageParam<BusinessInfo> businessInfoPage) {
|
|
|
+
|
|
|
+ BusinessInfo businessInfo = businessInfoPage.getParams();
|
|
|
+ Page<BusinessInfo> rowPage = new Page(businessInfoPage.getPage(), businessInfoPage.getSize());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BusinessInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ //应用名称
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(businessInfo.getAppName()),
|
|
|
+ BusinessInfo::getAppName, businessInfo.getAppName());
|
|
|
+ //类型
|
|
|
+ queryWrapper.eq(businessInfo.getBusinessType() != null,
|
|
|
+ BusinessInfo::getBusinessType,
|
|
|
+ businessInfo.getBusinessType());
|
|
|
+ queryWrapper.eq(businessInfo.getDelFlag() != null,
|
|
|
+ BusinessInfo::getDelFlag,
|
|
|
+ businessInfo.getDelFlag());
|
|
|
+
|
|
|
+ queryWrapper.orderByDesc(BusinessInfo::getStar);
|
|
|
+
|
|
|
+ return businessMapper.selectPage(rowPage, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 安装业务
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public int install(Integer appId,Integer businessId, String userIdcard) {
|
|
|
+
|
|
|
+ //查询业务是否存在
|
|
|
+ QueryWrapper<BusinessInfo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("app_id",appId);
|
|
|
+ wrapper.eq("id",businessId);
|
|
|
+ wrapper.eq("del_flag",0);
|
|
|
+ List<BusinessInfo> businessInfos = businessMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ if (businessInfos == null || businessInfos.size() != 1){
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否已安装
|
|
|
+ QueryWrapper<InstallInfo> wrapper2 = new QueryWrapper<>();
|
|
|
+ wrapper2.eq("app_id", appId);
|
|
|
+ wrapper2.eq("business_id", businessId);
|
|
|
+ wrapper2.eq("user_idcard", userIdcard);
|
|
|
+ InstallInfo installed = installInfoMapper.selectOne(wrapper2);
|
|
|
+
|
|
|
+ if (installed == null) {
|
|
|
+ InstallInfo installInfo = new InstallInfo();
|
|
|
+ installInfo.setAppId(appId);
|
|
|
+ installInfo.setBusinessId(businessId);
|
|
|
+ installInfo.setUserIdcard(userIdcard);
|
|
|
+
|
|
|
+ return installInfoMapper.insert(installInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ installed.setDelFlag(0);
|
|
|
+ installed.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ return installInfoMapper.updateById(installed);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 卸载
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public int uninstall(Integer appId,Integer businessId, String idCard) {
|
|
|
+ InstallInfo installInfo = new InstallInfo();
|
|
|
+ installInfo.setDelFlag(1);
|
|
|
+ installInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+ QueryWrapper<InstallInfo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("app_id", appId);
|
|
|
+ wrapper.eq("business_id", businessId);
|
|
|
+ wrapper.eq("user_idcard", idCard);
|
|
|
+
|
|
|
+ return installInfoMapper.update(installInfo, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 已安装业务
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public IPage<BusinessInfo> installApp(PageParam<BusinessInfo> page, LoginUser loginUser) {
|
|
|
+ BusinessInfo params = page.getParams();
|
|
|
+ IPage<BusinessInfo> iPage = new Page<>(page.getPage(), page.getSize());
|
|
|
+
|
|
|
+ Map map = new HashMap();
|
|
|
+
|
|
|
+ map.put("delFlag", params.getDelFlag());
|
|
|
+ map.put("idcard", loginUser.getIdCard());
|
|
|
+
|
|
|
+ return businessMapper.getInstalledApp(iPage,map);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 应用业务统计
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public void updateAppStat() {
|
|
|
+ //获取app安装次数
|
|
|
+ List<Map<String,Long>> business = installInfoMapper.getBusinessInstallCount();
|
|
|
+ //更新star
|
|
|
+ business.forEach(bus ->{
|
|
|
+ BusinessInfo businessInfo = new BusinessInfo();
|
|
|
+ businessInfo.setId(bus.get("businessId"));
|
|
|
+ businessInfo.setStar(bus.get("count"));
|
|
|
+ businessMapper.updateById(businessInfo);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|