package com.dragoninfo.dcuc.authweb.restcontroller.statisics; import com.dragoninfo.dcuc.authweb.config.DcucAuthWebConfig; import com.dragoninfo.dcuc.authweb.restcontroller.statisics.vo.OrgTreeNodeVo; import com.dragoninfo.dcuc.org.facade.IOrgInfoFacade; import com.dragoninfo.dcuc.org.vo.OrgTreeNode; import com.dragoninfo.dcuc.user.user.enumresources.UserTypeEnum; import com.dragoninfo.dcuc.user.user.facade.IUserInfoFacade; import com.dragonsoft.duceap.commons.util.string.StringUtils; import com.dragonsoft.duceap.web.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; /** * Created by liws on 2018/9/21. */ @Api(tags = {"用户统计"}) @RestController @RequestMapping(value = "usersvr") public class UserStatisicsController extends BaseController { @Autowired private IUserInfoFacade iUserInfoFacade; @Autowired private IOrgInfoFacade iOrgInfoFacade; @Autowired private DcucAuthWebConfig dcucAuthWebConfig; /* @ApiOperation(value = "获取用户统计列表") @ApiImplicitParam(name = "searchable", value = "查询条件") @PostMapping(value = "statisics/search") public Result list(Searchable searchable) { List> result = new ArrayList>(); searchable.addSearchFilter("ranged", SearchOperator.eq,dcucWebConfig.getStatisticsRange()); SearchDTO searchDTO = searchable.toSearchDTO(); Page page = iOrgInfoFacade.areaMap(searchDTO); List areas = page.getContent(); for (AreaInfo area : areas) { String areacode = area.getCode().substring(0, 2); Map countMap = iUserInfoFacade.countUserByArea(areacode, true, true); countMap.put("area", area.getName()); result.add(countMap); } if (page.getSize() * Integer.parseInt(searchDTO.getPage()) > page.getTotalElements()) { Map countMap = iUserInfoFacade.countUserByArea(null, true, true); countMap.put("area", "总计"); result.add(countMap); } return Result.success(result); } */ /** * 完整树 * * @param id 节点机构id * @return */ @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "机构ID", required = true , example = "40288a8b699fc2500169a33b20540000")}) @ApiOperation(value = "获取完整树下各用户数量") @GetMapping(value = "statisics/{id}") public List treeGrid(@PathVariable String id) { if (StringUtils.isEmpty(id) || id.equals("null")) { id = iOrgInfoFacade.getRootOrgId(); OrgTreeNode orgTreeNode = iOrgInfoFacade.getOrgTreeNode(id); int orgCount = iOrgInfoFacade.allOrgNum(); int userCount = iUserInfoFacade.allUserNum(); orgTreeNode.setCount(orgCount); int policeNum = iUserInfoFacade.allUserTypeNum(UserTypeEnum.POLICE.getValue()); orgTreeNode.setPoliceNum(policeNum); int helperNum = iUserInfoFacade.allUserTypeNum(UserTypeEnum.HELPER.getValue()); orgTreeNode.setAuxiliaryNum(helperNum); int externalNum = iUserInfoFacade.allUserTypeNum(UserTypeEnum.EXTERNAL.getValue()); orgTreeNode.setExternalNum(externalNum); orgTreeNode.setUserNum(userCount); List resultList = new ArrayList(); resultList.add(orgTreeNode); List orgTreeNodeVos = this.treeNodeToVo(resultList); return orgTreeNodeVos; } else { List resultList = iOrgInfoFacade.countChildOrgTreeNode(id); List orgTreeNodeVos = this.treeNodeToVo(resultList); return orgTreeNodeVos; } } // // @RequestMapping(value = "provinces") // @ResponseBody // public List provinces() { // Searchable searchable = Searchable.newSearchable(); // searchable.addSearchFilter("ranged",SearchOperator.eq,dcucWebConfig.getStatisticsRange()); // SearchDTO searchDTO = searchable.toSearchDTO(); // searchDTO.setSize("100"); // searchDTO.setPage("1"); // List> result = new ArrayList>(); // Page page = iOrgInfoFacade.areaMap(searchDTO); // List areas = page.getContent(); // for (AreaInfo area : areas) { // Map countMap = null; // if (dcucWebConfig.getStatisticsRange().equals(UserAreaEnum.HZ_AREA.getValue())) { // String areacode = area.getCode().substring(0, 2); // countMap = iUserInfoFacade.countUserByArea(areacode, false, true); // } else if (dcucWebConfig.getStatisticsRange().equals(UserAreaEnum.GD_AREA.getValue())) { // String areacode = area.getCode().substring(0, 4); // countMap = iUserInfoFacade.countUserByArea(areacode, false, false); // } // countMap.put("area", area.getName()); // result.add(countMap); // } // return result; // } // // /** // * 导出列表 // * // * @param searchDTO // * @param request // */ // @RequestMapping(value = "excel") // public void listExport(Searchable searchable, HttpServletRequest request, HttpServletResponse response) { // try { // searchable.addSearchFilter("ranged",SearchOperator.eq,dcucWebConfig.getStatisticsRange()); // SearchDTO searchDTO = searchable.toSearchDTO(); // searchDTO.setSize(searchDTO.getTotal()); // searchDTO.setPage("1"); // List> result = new ArrayList>(); // Page page = iOrgInfoFacade.areaMap(searchDTO); // List areas = page.getContent(); // for (AreaInfo area : areas) { // String areacode = area.getCode().substring(0, 2); // Map countMap = iUserInfoFacade.countUserByArea(areacode, true, true); // countMap.put("area", area.getName()); // result.add(countMap); // } // Map countMap = iUserInfoFacade.countUserByArea(null, true, true); // countMap.put("area", "总计"); // result.add(countMap); // exportExcel("全国治安用户建设情况", result, Searchable.toSearchable(searchDTO).getMetaData(), request, response); // } catch (IOException e) { // logger.error(e.getMessage(), e); // throw new ApplicationException(300, "导出失败", e); // } // } /** * 组装树节点 * * @param nodeList * @return */ private List treeNodeToVo(List nodeList) { List result = new ArrayList<>(); for (OrgTreeNode orgTreeNode : nodeList) { OrgTreeNodeVo orgTreeNodeVo = new OrgTreeNodeVo(); orgTreeNodeVo.setId(orgTreeNode.getValue()); orgTreeNodeVo.setCode( orgTreeNode.getCode()); orgTreeNodeVo.setName(orgTreeNode.getLabel()); orgTreeNodeVo.setPid(orgTreeNode.getPid()); orgTreeNodeVo.setOrgNum(orgTreeNode.getCount()); orgTreeNodeVo.setUserNum(orgTreeNode.getUserNum()); orgTreeNodeVo.setPoliceUserCount(orgTreeNode.getPoliceNum()); orgTreeNodeVo.setAuxiliUserCount(orgTreeNode.getAuxiliaryNum()); orgTreeNodeVo.setExtcerUserCount(orgTreeNode.getExternalNum()); if (orgTreeNode.getChildIds() != null && orgTreeNode.getChildIds().size() > 0) { orgTreeNodeVo.setParent(true); } else { orgTreeNodeVo.setParent(false); } result.add(orgTreeNodeVo); } return result; } }