Procházet zdrojové kódy

下级添加签约率

lyr před 8 roky
rodič
revize
b2dceb3bee

+ 44 - 16
src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -14,6 +14,7 @@ import com.yihu.wlyy.util.DateUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.keyvalue.core.IterableConverter;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -63,6 +64,21 @@ public class StatisticsService extends BaseService {
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 缓存人口数据到redis
     *
     * @return
     */
    public boolean peopleNumToRedis() {
        Iterable<PopulationBase> peopleNums = peopleNumDao.findAll();
        for (PopulationBase peopleNum : peopleNums) {
            redisTemplate.opsForValue().set("people:num:" + peopleNum.getCode(), new JSONObject(peopleNum).toString());
        }
        return true;
    }
    /**
     * 查询截止某个日期累计量
     *
@ -126,18 +142,18 @@ public class StatisticsService extends BaseService {
     * @return
     */
    public JSONObject getSignRate(String endDate, String area, int level) throws Exception {
        JSONObject json =  new JSONObject();
        JSONObject json = new JSONObject();
        long signAmount = getTotalAmount(endDate, area, level, SIGN);
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getNum() > 0) {
            json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
            json.put("sign",signAmount);
            json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
            json.put("sign", signAmount);
            json.put("people", peopleNum.getNum());
        } else {
            json.put("rate","0.0000");
            json.put("sign",signAmount);
            json.put("rate", "0.0000");
            json.put("sign", signAmount);
            json.put("people", 0);
        }
@ -153,18 +169,18 @@ public class StatisticsService extends BaseService {
     * @return
     */
    public JSONObject getSignTaskRate(String endDate, String area, int level) throws Exception {
        JSONObject json =  new JSONObject();
        JSONObject json = new JSONObject();
        long signAmount = getTotalAmount(endDate, area, level, SIGN);
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getTaskNum() > 0) {
            json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
            json.put("sign",signAmount);
            json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
            json.put("sign", signAmount);
            json.put("people", peopleNum.getTaskNum());
        } else {
            json.put("rate","0.0000");
            json.put("sign",signAmount);
            json.put("rate", "0.0000");
            json.put("sign", signAmount);
            json.put("people", 0);
        }
@ -415,7 +431,7 @@ public class StatisticsService extends BaseService {
            }
        }
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel);
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        // 查询语句
        String sql = " select " +
@ -490,9 +506,21 @@ public class StatisticsService extends BaseService {
                            map.put("amount", (long) map.get("amount") + valJson.getInt("num"));
                        }
                    }
                    PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(),Calendar.getInstance().get(Calendar.YEAR));
                    if(peopleNum != null) {
                        map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                    if (!low_level.equals("1")) {
                        String redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
                        if (StringUtils.isEmpty(redisNum)) {
                            PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Calendar.getInstance().get(Calendar.YEAR));
                            if (peopleNum != null) {
                                map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                            }
                        } else {
                            JSONObject peopleNum = new JSONObject(redisNum);
                            if (peopleNum != null) {
                                map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
                            }
                        }
                    }
                }
            }
@ -528,7 +556,7 @@ public class StatisticsService extends BaseService {
     * @param index     指标
     * @return
     */
    public JSONArray getLowLevelIncrementDetail(String startDate, String endDate, String area, int level, String index, int sort,String lowLevel) throws Exception {
    public JSONArray getLowLevelIncrementDetail(String startDate, String endDate, String area, int level, String index, int sort, String lowLevel) throws Exception {
        String areaField = "";
        String lowLevelField = "";
        String lowLevelName = "";
@ -567,7 +595,7 @@ public class StatisticsService extends BaseService {
            }
        }
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel)?(level - 1):lowLevel);
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        // 查询语句
        String sql = " select " +

+ 19 - 0
src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -1,10 +1,12 @@
package com.yihu.wlyy.web.statistic;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.web.BaseController;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@ -19,6 +21,23 @@ public class StatisticsController extends BaseController {
    @Autowired
    StatisticsService statisticsService;
    /**
     * 缓存人口数据到redis
     *
     * @return
     */
    @RequestMapping(value = "/people_num_to_redis")
    @ResponseBody
    public String peopleNumToRedis(){
        try{
            statisticsService.peopleNumToRedis();
            return write(200,"更新成功");
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"更新失败");
        }
    }
    /**
     * 指标按间隔统计
     *