jinpengyong
2023-10-30 14949a6a6e7dec654d13e75f46b24319a624ff8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.moral.api.controller;
 
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.entity.OrganizationLayout;
import com.moral.api.pojo.form.organizationLayout.OrganizationLayoutSetUp;
import com.moral.api.service.OrganizationLayoutService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Api(tags = {"页面布局"})
@RestController
@RequestMapping("/organizationLayout")
public class OrganizationLayoutController {
 
    @Resource
    private OrganizationLayoutService organizationLayoutService;
 
    @RequestMapping(value = "getLayoutData",method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getLayoutData(HttpServletRequest request){
        Map<String,Object> parameters = WebUtils.getParametersStartingWith(request,null);
        int organization_id = Integer.parseInt(parameters.get("organization_id").toString());
        int version_id = Integer.parseInt(parameters.get("version_id").toString());
        if (ObjectUtils.isEmpty(organization_id) || ObjectUtils.isEmpty(version_id)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String,Object>> result = organizationLayoutService.getData(parameters);
        return ResultMessage.ok(result);
    }
 
    @RequestMapping(value = "setUpLayout",method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage setUpLayout(@RequestBody OrganizationLayoutSetUp organizationLayoutSetUp){
        int organization_id = organizationLayoutSetUp.getOrganizationId();
        int version_id = organizationLayoutSetUp.getVersionId();
        if (ObjectUtils.isEmpty(organization_id) || ObjectUtils.isEmpty(version_id)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("organization_id",organization_id);
        map.put("version_id",version_id);
        List<OrganizationLayout> organizationLayouts = organizationLayoutSetUp.getOrganizationLayouts();
        organizationLayoutService.setUp(map,organizationLayouts);
        return ResultMessage.ok();
    }
 
    @RequestMapping(value = "getLayoutByMac", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getLayoutByMac(HttpServletRequest request){
        Map<String,Object> parameters = WebUtils.getParametersStartingWith(request,null);
        if (ObjectUtils.isEmpty(parameters.get("mac"))){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String,Object> resultMap = organizationLayoutService.getLayoutByMac(parameters.get("mac").toString());
        if (ObjectUtils.isEmpty(resultMap)){
            return null;
        }
        return ResultMessage.ok(resultMap);
    }
}