Prechádzať zdrojové kódy

[task-1987]【后端】培训统计数据接口开发

szjbdgzl 1 rok pred
rodič
commit
fce08662f9

+ 51 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/controller/TrainingStatisticsController.java

@@ -0,0 +1,51 @@
+package com.lc.ibps.business.controller;
+
+
+import com.lc.ibps.api.base.constants.StateEnum;
+import com.lc.ibps.base.core.util.I18nUtil;
+import com.lc.ibps.business.service.TrainingStatisticsService;
+import com.lc.ibps.cloud.entity.APIResult;
+import com.lc.ibps.cloud.provider.GenericProvider;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author gaozl
+ */
+@Api(tags = "人员培训统计")
+@RequestMapping("/employee/train")
+@RestController
+public class TrainingStatisticsController extends GenericProvider {
+
+    @Autowired
+    TrainingStatisticsService trainingStatisticsService;
+
+    @ApiOperation("获取当前地点所有用户的人员培训统计情况")
+    @GetMapping("/statistic")
+    APIResult<List<Map<String, Object>>> getUserTrainCount(
+            @RequestParam(name = "diDian", required = true) String diDian,
+            @RequestParam(name="userId",required = false) String userId,
+            @RequestParam(name="deptId",required = false) String deptId,
+            @RequestParam(name="startTime",required = false) String startTime,
+            @RequestParam(name="endTime",required = false) String endTime){
+
+        APIResult<List<Map<String, Object>>> result = new APIResult<>();
+        try {
+            List<Map<String, Object>> summary = trainingStatisticsService.getUserTrainCount(diDian,userId,deptId,startTime,endTime);
+            result.setData(summary);
+        } catch (Exception e) {
+            setExceptionResult(result, StateEnum.ILLEGAL_REQUEST.getCode(), I18nUtil.getMessage(StateEnum.ILLEGAL_REQUEST.getCode() + ""), e);
+        }
+        return result;
+    }
+
+
+}

+ 24 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/TrainingStatisticsService.java

@@ -0,0 +1,24 @@
+package com.lc.ibps.business.service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Administrator
+ */
+public interface TrainingStatisticsService {
+
+    /**
+     *  获取当前地点下所有用户的培训统计
+     * @param diDian
+     * @param userId
+     * @param deptId
+     * @param startTime
+     * @param endTime
+     * @return
+     * @throws Exception
+     */
+    List<Map<String, Object>> getUserTrainCount(String diDian,String userId,String deptId,String startTime,String endTime) throws Exception;
+
+
+}

+ 117 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/TrainingStatisticsServiceImpl.java

@@ -0,0 +1,117 @@
+package com.lc.ibps.business.service.impl;
+
+import com.lc.ibps.base.core.constants.StringPool;
+import com.lc.ibps.base.core.util.BeanUtils;
+import com.lc.ibps.base.framework.table.ICommonDao;
+import com.lc.ibps.business.service.TrainingStatisticsService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Administrator
+ */
+@Service
+public class TrainingStatisticsServiceImpl implements TrainingStatisticsService {
+
+
+    @Resource
+    private ICommonDao<?> commonDao;
+
+    /**
+     *  获取当前地点下所有用户的培训统计
+     * @param diDian
+     * @param userId
+     * @param deptId
+     * @param startTime
+     * @param endTime
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public List<Map<String, Object>> getUserTrainCount(String diDian,String userId,String deptId,String startTime,String endTime) throws Exception {
+        if (BeanUtils.isEmpty(diDian)){
+            throw new Exception("参数diDian(地点)不能为空!");
+        }
+        StringBuilder sql = new StringBuilder(" select id_,name_,positions_,jian_ding_zi_ge_z from ibps_party_employee c where id_ != '-1' " +
+                " and status_ !='deleted' and exists (select 1 from ibps_party_entity d where find_in_set(d.id_,c.positions_) and (d.path_ like '%"+diDian+"%')) ");
+        if (BeanUtils.isNotEmpty(userId)){
+            String[] user = userId.split(StringPool.COMMA);
+            if (user.length>1){
+                sql.append("and id_ in(");
+                for (String id : user){
+                    sql.append("'").append(id).append("',");
+                }
+                sql.deleteCharAt(sql.length() - 1);
+                sql.append(")");
+            }else {
+                sql.append("and id_='").append(userId).append("'");
+            }
+        }
+        if (BeanUtils.isNotEmpty(deptId)){
+            sql.append("and positions_ like '%").append(deptId).append("%'");
+        }
+        sql.append(" order by create_time_ desc");
+
+        List<Map<String,Object>> userList = (List<Map<String, Object>>) commonDao.query(sql.toString());
+        for (Map<String,Object> map : userList){
+
+            String employee = map.get("id_").toString();
+            String sumSql = "select count(*)as planedjoin from t_rypxcjb where shi_fou_guo_shen_='已结束' and pei_xun_ren_yuan_ like '%"+employee+"%'";
+            if (BeanUtils.isNotEmpty(startTime)){
+                sumSql = sumSql + " and date_format(pei_xun_shi_jian_,'%Y-%m-%d')>='"+startTime+"' ";
+            }
+            if (BeanUtils.isNotEmpty(endTime)){
+                sumSql = sumSql + " and date_format(pei_xun_shi_jian_,'%Y-%m-%d')<='"+endTime+"' ";
+            }
+            Map<String,Object> total = commonDao.queryOne(sumSql);
+            map.put("planedjoin",total.get("planedjoin"));
+
+            String signSql = "select count(distinct guan_lian_id_) as truejoin from t_qdxxb where ren_yuan_id_ ='"+employee+"' and guan_lian_id_ " +
+                    " in(select id_ from t_rypxcjb where shi_fou_guo_shen_='已结束' and pei_xun_ren_yuan_ like '%"+employee+"%'";
+            if (BeanUtils.isNotEmpty(startTime)){
+                signSql = signSql + " and date_format(pei_xun_shi_jian_,'%Y-%m-%d')>='"+startTime+"' ";
+            }
+            if (BeanUtils.isNotEmpty(endTime)){
+                signSql = signSql + " and date_format(pei_xun_shi_jian_,'%Y-%m-%d')<='"+endTime+"' ";
+            }
+            Map<String,Object> already = commonDao.queryOne(signSql+" ) ");
+            map.put("truejoin",already.get("truejoin"));
+
+            BigDecimal sum = new BigDecimal(total.get("planedjoin").toString());
+            BigDecimal sign = new BigDecimal(already.get("truejoin").toString());
+            if (sum.compareTo(BigDecimal.ZERO) == 0) {
+                map.put("participationRate","0.00%");
+            }else {
+                BigDecimal percentage = sign.divide(sum, 10, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
+                percentage = percentage.setScale(2, RoundingMode.HALF_UP);
+                map.put("participationRate",percentage+"%");
+            }
+
+            if (BeanUtils.isNotEmpty(map.get("positions_"))){
+                String positionId = map.get("positions_").toString();
+                String[] posi = positionId.split(StringPool.COMMA);
+                StringBuffer deptName = new StringBuffer();
+                if (posi.length>1){
+                    for (String str : posi){
+                        Map<String,Object> name = commonDao.queryOne("select name_ from ibps_party_entity where id_ ='"+str+"'");
+                        deptName.append(name.get("name_")).append(",");
+                    }
+                    deptName.deleteCharAt(deptName.length() - 1);
+                    map.put("deptName",deptName);
+                }else {
+                    Map<String,Object> name = commonDao.queryOne("select name_ from ibps_party_entity where id_ ='"+positionId+"'");
+                    map.put("deptName",name.get("name_"));
+                }
+            }
+        }
+        return userList;
+    }
+
+
+
+}