package com.sky.ioc.service.personnel.impl;

import com.alibaba.fastjson.JSONObject;
import com.sky.ioc.entity.Indeicator;
import com.sky.ioc.entity.Label;
import com.sky.ioc.entity.params.IocParam;
import com.sky.ioc.service.personnel.PersonnelService;
import com.sky.ioc.tool.DateUtil;
import com.sky.ioc.tool.GeneralMethod;
import com.sky.ioc.tool.ReturnMsg;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

/**
 * TODO  人员
 * @Description
 * @Author LunCe
 * @date 2023/2/22 15:14
 */
@Service
public class PersonnelServiceImpl implements PersonnelService {



    @Override
    public ReturnMsg personnelInfoCount() {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
       /* int enterCount = random.nextInt(1600, 2300);
        int outCount = random.nextInt(500, 800);
        int enterBeforeNineCount = random.nextInt(800, 1500);
        while (enterBeforeNineCount>enterCount){
            enterBeforeNineCount = random.nextInt(800, 1500);
        }
        int inCount = enterCount-outCount;
        */
        double compare = 0.5;
        compare = Double.parseDouble(decimalFormat.format(compare));
        objects.get(0).put("value",1949);
        objects.get(0).put("compare",compare);

        objects.get(1).put("value",680);
        objects.get(1).put("compare",compare);

        objects.get(2).put("value",1034);
        objects.get(2).put("compare",compare);

        objects.get(3).put("value",1269);
        objects.get(3).put("compare",compare);
        indeicator.setWorthAttention("明⽇⼈流⾼峰在9:00/17:00");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    //查询智能看板统计画像的统计人员信息报表
    @Override
    public ReturnMsg getPersonnelInfoList() {
        String[] param = {"ownEmployees","outsourcingStaff","visitors","others"};
        List<String> lists = DateUtil.getBetweenDays("2023/03/01", "2023/03/31");
        String[] labKey = lists.toArray(new String[0]);
        List<Label> list = new ArrayList<>();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int ownEmployees = random.nextInt(500, 900);
            int outsourcingStaff = random.nextInt(0, ownEmployees);
            int visitors = random.nextInt(0, 50);
            int others = random.nextInt(0, 50);
            jsonObject.put(param[0],ownEmployees);
            jsonObject.put(param[1],outsourcingStaff);
            jsonObject.put(param[2],visitors);
            jsonObject.put(param[3],others);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            list.add(label);
        }
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getSecurityCoreIndicators(IocParam iocParam) {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        int enterCount = random.nextInt(1000, 3000);
        int orderCount = random.nextInt(50, 300);
        int inCount = random.nextInt(0, enterCount);
        int arrivedCount = random.nextInt(0, orderCount);
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        float compare = (float) Math.random();
        compare = Float.parseFloat(decimalFormat.format(compare));

        objects.get(0).put("value",enterCount);
        objects.get(0).put("compare",compare);

        objects.get(1).put("value",inCount);
        objects.get(1).put("compare",compare);

        objects.get(2).put("value",orderCount);
        objects.get(2).put("compare",compare);

        objects.get(3).put("value",arrivedCount);
        objects.get(3).put("compare",-compare);
        indeicator.setWorthAttention("本⽇访客⼈数较多，建议注意安防保护");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getPopulationPerson(IocParam iocParam) {
        String[] param = {"numberPeople"};
        String startStr = iocParam.getTimeRange().getStartDate();
        String endStr = iocParam.getTimeRange().getEndDate();
        List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        return ReturnMsg.ok(labels1);
    }

    @Override
    public ReturnMsg getPassengerFlow(IocParam iocParam) {
        String[] param = {"Freelance","other"};
        String startStr = iocParam.getTimeRange().getStartDate();
        String endStr = iocParam.getTimeRange().getEndDate();
        List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        return ReturnMsg.ok(labels1);
    }

}
