package com.lz.modules.app.controller;

import com.lz.modules.app.dao.DepartmentsDao;
import com.lz.modules.app.entity.DepartmentsEntity;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.service.DepartmentsService;
import com.lz.modules.app.service.DepartmentsStaffRelateService;
import com.lz.modules.sys.entity.app.ResultRecord;
import com.lz.modules.sys.service.app.ResultRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@RestController
public class TestController {

    @Autowired
    private ResultRecordService resultRecordService;

    @Autowired
    private DepartmentsService departmentsService;


    @Autowired
    private DepartmentsStaffRelateService departmentsStaffRelateService;

    @RequestMapping("/test/xx")
    public void test(){
        ResultRecord resultRecord = new ResultRecord();
        resultRecord.setAllScore(new BigDecimal(10));
        resultRecord.setLastScore(new BigDecimal(8));
        resultRecord.setMonthTime(new Date());
        resultRecordService.insertResultRecord(resultRecord);
    }


    @RequestMapping("/test/department")
    public void department(){
        List<DepartmentsEntity> departmentsEntityList = departmentsService.selectEntityByParentDepartmentId("0");
        for(DepartmentsEntity child1:departmentsEntityList){
            child1.setLevel(1);
            departmentsService.updateById(child1);
            List<DepartmentsEntity> departmentsEntityList2 = departmentsService.selectEntityByParentDepartmentId(child1.getDepartmentId());
            for(DepartmentsEntity child2: departmentsEntityList2){
                child2.setLevel(2);
                departmentsService.updateById(child2);
                List<DepartmentsEntity> departmentsEntityList3 = departmentsService.selectEntityByParentDepartmentId(child2.getDepartmentId());
                for(DepartmentsEntity child3: departmentsEntityList3){
                    child3.setLevel(3);
                    departmentsService.updateById(child3);
                    List<DepartmentsEntity> departmentsEntityList4 = departmentsService.selectEntityByParentDepartmentId(child3.getDepartmentId());
                    for(DepartmentsEntity child4: departmentsEntityList4){
                        child4.setLevel(4);
                        departmentsService.updateById(child4);
                    }
                }
            }
        }
    }







    @RequestMapping("/test/relate")
    public void relate(){
        List<DepartmentsStaffRelateEntity> list = departmentsStaffRelateService.selectAll();
        for(DepartmentsStaffRelateEntity l:list){
            DepartmentsEntity departmentsEntity = departmentsService.selectByDepartmentId(l.getDepartmentId());
            l.setLevel(departmentsEntity.getLevel());
            departmentsStaffRelateService.updateById(l);
        }
    }
}
