package com.dgtis.dorm.manager.wx.web;

import com.dgtis.dorm.manager.db.domain.AlumniOrganize;
import com.dgtis.dorm.manager.db.domain.AlumniOrganizeCustom;
import com.dgtis.dorm.manager.db.service.AlumniOrganizeService;
import com.dgtis.dorm.manager.db.service.AlumniOrganizeUserService;
import com.dgtis.dorm.manager.db.service.UserService;
import com.dgtis.dorm.manager.db.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
@RestController
@RequestMapping("/wx/organize")
public class WxOrganizeController {

    @Autowired
    private AlumniOrganizeService alumniOrganizeService;

    @Autowired
    private UserService userService;

    @Autowired
    private AlumniOrganizeUserService alumniOrganizeUserService;


    /*********************************** 地方专委会 *******************************************/


    /**
     * 我的地方委员会
     *
     * @return
     */
    @RequestMapping("selectMyOrganizePlaceByUserId")
    public Object selectMyOrganizePlaceByUserId(Integer userId) {

        if (userId == null) {
            return ResponseUtil.fail("userId 不能为空");
        }

        List<AlumniOrganizeCustom> list = alumniOrganizeService.selectMyOrganizeByUserIdAndOrgType(userId, "1");

        return ResponseUtil.ok(list);
    }


    /**
     * 查询其它地方委员会
     *
     * @return
     */
    @RequestMapping("selectOrganizePlace")
    public Object selectOrganizePlace(String organizeName, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                      @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        Map<String, Object> map = alumniOrganizeService.selectOrganizePlace("1", organizeName, page, limit);

        return ResponseUtil.ok(map);
    }

    /**
     * 根据userId 查找专委会
     *
     * @param alumniOrganizeCustom
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("selectOrganizeByUserId")
    public Object selectOrganizeByUserId() {

        AlumniOrganizeCustom alumniOrganizeCustom = new AlumniOrganizeCustom();
        List<AlumniOrganizeCustom> list = alumniOrganizeService.selectOrganizeByUserId(alumniOrganizeCustom);
        return ResponseUtil.ok(list);
    }


    /*********************************** 行业专委会 *******************************************/


    /**
     * 我的行业专委会
     *
     * @return
     */
    @RequestMapping("selectMyOrganizeTradeByUserId")
    public Object selectMyOrganizeTradeByUserId(Integer userId) {

        if (userId == null) {
            return ResponseUtil.fail("userId 不能为空");
        }

        List<AlumniOrganizeCustom> list = alumniOrganizeService.selectMyOrganizeByUserIdAndOrgType(userId, "2");

        return ResponseUtil.ok(list);
    }

    /**
     * 查询其它行业专委会
     *
     * @return
     */
    @RequestMapping("selectOrganizeTrade")
    public Object selectOrganizeTrade(String organizeName, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                      @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        Map<String, Object> map = alumniOrganizeService.selectOrganizePlace("2", organizeName, page, limit);

        return ResponseUtil.ok(map);
    }

    /*********************************** 兴趣小组 *******************************************/


    /**
     * 我的兴趣小组
     *
     * @return
     */
    @RequestMapping("selectMyOrganizeInterestByUserId")
    public Object selectMyOrganizeInterestByUserId(Integer userId) {

        if (userId == null) {
            return ResponseUtil.fail("userId 不能为空");
        }

        List<AlumniOrganizeCustom> list = alumniOrganizeService.selectMyOrganizeByUserIdAndOrgType(userId, "3");

        return ResponseUtil.ok(list);
    }


    /**
     * 查询其它兴趣小组
     *
     * @return
     */
    @RequestMapping("selectOrganizeInterest")
    public Object selectOrganizeInterest(String organizeName, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                         @RequestParam(value = "limit", defaultValue = "10") Integer limit) {

        Map<String, Object> map = alumniOrganizeService.selectOrganizePlace("3", organizeName, page, limit);

        return ResponseUtil.ok(map);
    }


    /**
     * 我的组织（不分种类）
     *
     * @return
     */
    @RequestMapping("selectMyOrganize")
    public Object selectMyOrganize(Integer userId) {

        if (userId == null) {
            return ResponseUtil.fail("userId 不能为空");
        }

        List<AlumniOrganizeCustom> list = alumniOrganizeService.selectMyOrganizeByUserId(userId);

        return ResponseUtil.ok(list);
    }


    /**
     * 创建兴趣小组
     *
     * @param alumniOrganize
     * @return
     */
    @RequestMapping("addOrganizeInterest")
    public Object addOrganizeInterest(AlumniOrganize alumniOrganize, String formId) {

        int f = alumniOrganizeService.createOrganizeInterest(alumniOrganize);
        userService.updateUserFormId(alumniOrganize.getOrganizeUserId(), formId);

        return ResponseUtil.ok(f);
    }


    /**
     * 解散
     *
     * @param alumniOrganize
     * @return
     */
    @RequestMapping("dissolveOrganizeInterest")
    public Object dissolveOrganizeInterest(AlumniOrganize alumniOrganize) {

        alumniOrganize.setIsDelete(false);
        alumniOrganize.setModifyDate(LocalDateTime.now());

        int f = alumniOrganizeService.updateByPrimaryKeySelective(alumniOrganize);

        return ResponseUtil.ok(f);
    }

    /**
     * 方法描述  查询详情
     *
     * @param id 组织ID
     * @return Object
     * @author huanghaoqi
     * @date 2019年01月07日 14:27:59
     */
    @GetMapping("detail")
    public Object detail(Integer id) {
        AlumniOrganizeCustom alumniOrganizeCustom = alumniOrganizeService.selectById(id);
        return ResponseUtil.ok(alumniOrganizeCustom);
    }

}
