yonghuifan 1 年間 前
コミット
5e9f1357e6

+ 124 - 0
src/main/java/com/dragon/tj/portal/controller/BusinessController.java

@@ -0,0 +1,124 @@
+package com.dragon.tj.portal.controller;
+
+import com.dragon.tj.portal.auth.model.LoginUser;
+import com.dragon.tj.portal.auth.util.SecurityUtils;
+import com.dragon.tj.portal.common.base.R;
+import com.dragon.tj.portal.entity.BusinessInfo;
+import com.dragon.tj.portal.entity.PageParam;
+import com.dragon.tj.portal.service.BusinessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+
+@RestController
+@RequestMapping("/business")
+@EnableScheduling
+public class BusinessController {
+
+
+    @Autowired
+    private BusinessService businessService;
+
+    /*
+     *    1. 我的业务查询 批量排序收藏
+     * */
+    @PostMapping("list")
+    public R appList(@RequestBody PageParam<BusinessInfo> businessPage) {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        return R.ok(businessService.installApp(businessPage,loginUser));
+    }
+
+    /*
+     *  1-1安装业务
+     * */
+    @GetMapping("install/{appId}/{businessId}")
+    public R install(@PathVariable("appId") Integer appId,
+                     @PathVariable("businessId") Integer businessId) {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        int install = businessService.install(appId, businessId, loginUser.getIdCard());
+
+        if (install == 0){
+
+            return R.failed("安装失败!!!");
+        }
+        return R.ok();
+    }
+
+    /*
+     *  1-2卸载业务
+     * */
+    @GetMapping("uninstall/{appId}/{businessId}")
+    public R uninstall(@PathVariable("appId") Integer appId,
+                       @PathVariable("businessId") Integer businessId) {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        return R.ok(businessService.uninstall(appId,businessId,loginUser.getIdCard()));
+    }
+
+    /***************************************/
+
+    /*
+     *    2. 类型查询
+     * */
+//    @GetMapping("types")
+//    public R getAppType() {
+//        return businessService.getType();
+//    }
+
+    /*
+     *    3. 应用 CRUD
+     * */
+//    @SysLog("添加应用")
+    @PostMapping("add")
+    public R addApp(@RequestBody BusinessInfo businessInfo) {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        int b = businessService.add(businessInfo, loginUser);
+        if (b == 0){
+            return R.failed("添加失败!!!");
+        }
+
+        return R.ok(b);
+    }
+
+    //    @SysLog("应用删除")
+    @GetMapping("delete/{id}")
+    public R delete(@PathVariable("id") Long id) {
+        return R.ok(businessService.delete(id));
+    }
+
+    //    @SysLog("应用更新")
+    @PostMapping("update")
+    public R update(@RequestBody BusinessInfo businessInfo) {
+        businessInfo.setUpdateTime(LocalDateTime.now());
+        return R.ok(businessService.update(businessInfo));
+    }
+
+    //    @SysLog("通过ID获取应用")
+    @GetMapping("info/{id}")
+    public R detail(@PathVariable("id") Long id) {
+        return R.ok(businessService.detail(id));
+    }
+
+    /*
+     *   通过应用名称,应用事权单位名称搜索app
+     * */
+    @GetMapping("search")
+    public R search(@RequestBody PageParam<BusinessInfo> businessInfoPage) {
+
+        return R.ok(businessService.search(businessInfoPage));
+    }
+
+
+    /*
+     *    4. 热门应用统计 定时、实时?
+     * */
+    @Scheduled(fixedDelay = 1000 * 60 * 60)
+    public void appStatHandler(){
+
+        businessService.updateAppStat();
+    }
+
+}
+

+ 94 - 0
src/main/java/com/dragon/tj/portal/entity/BusinessInfo.java

@@ -0,0 +1,94 @@
+package com.dragon.tj.portal.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+/**
+ * 业务信息
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+@TableName("business_info")
+public class BusinessInfo {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 业务类型(1派出所常用,2采集中心)
+     */
+    private Integer businessType;
+
+    /**
+     * 业务名称
+     */
+    private String businessName;
+
+    /**
+     * 业务代码
+     */
+    private String businessNumber;
+
+    /**
+     * 所属应用Id
+     */
+    private Long appId;
+
+    /**
+     * 所属应用名称
+     */
+    private String appName;
+
+
+    /**
+     * 应用系统访问地址
+     */
+    private String url;
+
+
+
+    /**
+     * 系统在用标识(1在用)
+     */
+    private Integer activeFlag;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    private String createUser;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 删除状态 默认0 有效 1无效
+     */
+    private Integer delFlag;
+
+    /**
+     * 版本号
+     */
+    @TableField(exist = false)
+    private String version;
+
+    /**
+     * 收藏数量
+     */
+    private Long star;
+}

+ 5 - 0
src/main/java/com/dragon/tj/portal/entity/InstallInfo.java

@@ -31,6 +31,11 @@ public class InstallInfo {
      */
     private Integer appId;
 
+    /**
+     * 应用业务ID
+     */
+    private Integer businessId;
+
     /**
      * 用户身份证号码
      */

+ 18 - 0
src/main/java/com/dragon/tj/portal/mapper/BusinessMapper.java

@@ -0,0 +1,18 @@
+package com.dragon.tj.portal.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.dragon.tj.portal.entity.BusinessInfo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Map;
+
+/**
+ * 应用程序
+ */
+@Mapper
+public interface BusinessMapper extends BaseMapper<BusinessInfo> {
+
+    IPage<BusinessInfo> getInstalledApp(IPage<BusinessInfo> iPage, @Param("map") Map map);
+}

+ 7 - 1
src/main/java/com/dragon/tj/portal/mapper/app/InstallInfoMapper.java

@@ -14,6 +14,12 @@ import java.util.Map;
 @Mapper
 public interface InstallInfoMapper extends BaseMapper<InstallInfo> {
 
-    @Select("select app_id as appId,count(1) as count from install_info GROUP BY app_id")
+    @Select("select app_id as appId,count(1) as count from install_info where business_id = 0 GROUP BY app_id")
     List<Map<String, Long>> getAppInstallCount();
+
+    /*
+    * 业务安装
+    * */
+    @Select("select business_id as businessId,count(1) as count from install_info where business_id != 0 GROUP BY app_id")
+    List<Map<String, Long>> getBusinessInstallCount();
 }

+ 52 - 0
src/main/java/com/dragon/tj/portal/service/BusinessService.java

@@ -0,0 +1,52 @@
+package com.dragon.tj.portal.service;
+
+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.BusinessInfo;
+import com.dragon.tj.portal.entity.PageParam;
+
+
+public interface BusinessService {
+    /*
+    * CRUD
+    * */
+    int add(BusinessInfo businessInfo, LoginUser loginUser);
+
+    int delete(Long id);
+
+    int update(BusinessInfo businessInfo);
+
+    BusinessInfo detail(Long id);
+
+
+    /*
+    * 获取类型
+    * */
+    R getType();
+
+
+    /*
+     * 分页搜索
+     * */
+    Page<BusinessInfo> search(PageParam<BusinessInfo> businessInfoPage);
+
+
+
+    /*
+    *  安装应用业务程序
+    * */
+    int install(Integer appId,Integer businessId, String userIdcard);
+
+
+    int uninstall(Integer appId,Integer businessId, String idCard);
+
+
+    /*
+    * 查询已安装应用业务功能
+    * */
+    IPage<BusinessInfo> installApp(PageParam<BusinessInfo> businessInfoPage, LoginUser loginUser);
+
+    void updateAppStat();
+}

+ 214 - 0
src/main/java/com/dragon/tj/portal/service/impl/BusinessServiceImpl.java

@@ -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);
+        });
+
+    }
+
+}

+ 25 - 0
src/main/resources/mapper/BusinessMapper.xml

@@ -0,0 +1,25 @@
+<?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.dragon.tj.portal.mapper.BusinessMapper">
+
+
+    <select id="getInstalledApp" resultType="com.dragon.tj.portal.entity.BusinessInfo">
+        select * from business_info t1
+        where t1.del_flag = 0
+        and t1.id in  (
+            select business_id from install_info t2
+            <where>
+                business_id != 0
+                <if test="map.idcard != null and map.idcard != ''">
+                    and t2.user_idcard = #{map.idcard}
+                </if>
+                <if test="map.delFlag != null">
+                    and t2.del_flag = #{map.delFlag}
+                </if>
+            </where>
+
+        )
+    </select>
+
+
+</mapper>

+ 1 - 0
src/main/resources/mapper/app/AppInfoMapper.xml

@@ -34,6 +34,7 @@
         and t1.id in  (
             select app_id from install_info t2
             <where>
+                business_id = 0
                 <if test="map.idcard != null and map.idcard != ''">
                     and t2.user_idcard = #{map.idcard}
                 </if>