| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- package com.uas.sso.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.account.entity.AppCreateInfo;
- import com.uas.sso.core.Const;
- import com.uas.sso.dao.UserspaceDao;
- import com.uas.sso.entity.App;
- import com.uas.sso.entity.User;
- import com.uas.sso.entity.Userspace;
- import com.uas.sso.service.AppService;
- import com.uas.sso.service.ApplyUserSpaceService;
- import com.uas.sso.service.UserService;
- import com.uas.sso.service.UserspaceService;
- import com.uas.sso.util.FastjsonUtils;
- import com.uas.sso.util.FileUrl;
- import com.uas.sso.util.HttpUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.ui.ModelMap;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.*;
- import java.util.*;
- import static com.alibaba.fastjson.JSON.parseObject;
- /**
- * 企业信息管理controller
- *
- * @author wangmh
- * @date 2018/1/5
- */
- @RestController
- @RequestMapping("/api/userspace")
- public class UserspaceManagerController extends BaseController {
- @Autowired
- private UserspaceService userspaceService;
- @Autowired
- private UserService userService;
- @Autowired
- private AppService appService;
- @Autowired
- private ApplyUserSpaceService applyUserSpaceService;
- @Autowired
- private UserspaceDao userspaceDao;
- /**
- * 校验企业名称
- *
- * @param spaceName 企业名称
- * @return
- */
- @RequestMapping(value = "/checkSpaceName", method = RequestMethod.GET)
- public ModelMap checkSpaceName(String spaceName) {
- userspaceService.checkSpaceName(spaceName);
- return success();
- }
- /**
- * 校验企业营业执照号
- *
- * @param businessCode 企业名称
- * @return
- */
- @RequestMapping("/checkBusinessCode")
- public ModelMap checkBusinessCode(String businessCode) {
- userspaceService.checkBusinessCode(businessCode);
- return success();
- }
- /**
- * 校验企业是否被认证
- *
- * @param spaceName 企业名称
- * @return
- * @author wangmh
- * @date 2018/1/11 20:51
- */
- @RequestMapping(value = "/name/valid", method = RequestMethod.GET)
- public ModelMap spaceNameIsValid(String spaceName) {
- return success(new ModelMap("isValid", userspaceService.spaceNameIsValid(spaceName)));
- }
- /**
- * 校验营业执照号是否被认证
- *
- * @param businessCode 营业执照号
- * @return
- * @author wangmh
- * @date 2018/1/11 10:35
- */
- @RequestMapping(value = "/businessCode/valid", method = RequestMethod.GET)
- public ModelMap businessCodeIsValid(String businessCode) {
- return success(new ModelMap("isValid", userspaceService.businessCodeIsValid(businessCode)));
- }
- /**
- * 上传营业执照号
- *
- * @param image 营业执照号
- * @return 图片地址
- * @throws Exception
- */
- @RequestMapping(value = "/upload", method = RequestMethod.POST)
- public ModelMap uploadImage(MultipartFile image) throws Exception {
- int IMAGE_MAX_SIZE = 5 * 1024 * 1024;
- if (!(image == null || image.isEmpty())) {
- if (image.getSize() > IMAGE_MAX_SIZE) {
- return error("营业执照附件大小不要超过5M");
- }
- HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, image, null);
- JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
- String path = (String) obj.get("path");
- if (path != null) {
- return success(path);
- } else {
- return error("请检查您的营业执照附件");
- }
- }
- return error("上传失败");
- }
- /**
- * 模糊搜索企业名称
- *
- * @param keyword 关键字
- * @param number 获取数量
- * @return page对象
- */
- @RequestMapping(value = "/search/name", method = RequestMethod.GET)
- public ModelMap searchName(String keyword, @RequestParam(defaultValue = "5") int number) {
- if (StringUtils.isEmpty(keyword)) {
- return success();
- }
- return success(userspaceService.searchName(keyword, number));
- }
- /**
- * 根据企业名称查询企业
- *
- * @param name 企业名称
- * @return 企业信息
- */
- @RequestMapping(value = "/info/name", method = RequestMethod.GET)
- public ModelMap findByName(String name) {
- if (StringUtils.isEmpty(name)) {
- return success();
- }
- return success(userspaceService.findBySpaceName(name));
- }
- /**
- * 根据企业名称查询企业
- *
- * @param businessCode 企业营业执照号
- * @return 企业信息
- */
- @RequestMapping(value = "/info/businessCode", method = RequestMethod.GET)
- public ModelMap findByBusinessCode(String businessCode) {
- if (StringUtils.isEmpty(businessCode)) {
- return success();
- }
- return success(userspaceService.findByBusinessCode(businessCode));
- }
- /**
- * 根据企业名称查询企业
- *
- * @param spaceUU 企业营业执照号
- * @return 企业信息
- */
- @RequestMapping(value = "/info/spaceUU", method = RequestMethod.GET)
- public ModelMap findBySpaceUU(Long spaceUU) {
- if (StringUtils.isEmpty(spaceUU)) {
- return success();
- }
- return success(userspaceService.findOne(spaceUU));
- }
- /**
- * 查询所有企业列表
- */
- @RequestMapping(params = "_operate=getUserSpaces")
- public Page<Userspace> getUserSpaces(String keyword, @RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "20") int pageSize) {
- return userspaceService.findByKeyword(keyword, pageNumber, pageSize);
- }
- /**
- * 统计申请已审批和未审批数量
- *
- * @param spaceUU 企业uu号
- * @return
- */
- @RequestMapping(value = "/apply/count", method = RequestMethod.GET)
- public ModelMap applyCount(Long spaceUU) {
- return success(applyUserSpaceService.applyCount(spaceUU));
- }
- /**
- * 企业解除绑定应用
- *
- * @param spaceUU 企业uu号
- * @param appId 应用id
- * @return
- */
- @RequestMapping(params = "_operate=unbind", method = RequestMethod.POST)
- public ModelMap unbindApp(Long spaceUU, String appId) {
- if (StringUtils.isEmpty(spaceUU) || StringUtils.isEmpty(appId)) {
- return error("参数错误");
- }
- userspaceService.unbindApp(spaceUU, appId);
- return success();
- }
- /**
- * 企业开通应用
- *
- * @param spaceUU 企业uu号
- * @param appId 应用id
- * @return
- */
- @RequestMapping(params = "_operate=bind", method = RequestMethod.POST)
- public ModelMap bindApp(Long spaceUU, String appId) {
- if (StringUtils.isEmpty(spaceUU) || StringUtils.isEmpty(appId)) {
- return error("参数错误");
- }
- userspaceService.bindApp(spaceUU, appId);
- return success();
- }
- /**
- * 校验企业营业执照
- *
- * @param businessCode 营业执照号
- * @return
- * @throws UnsupportedEncodingException
- */
- @RequestMapping(params = "_operate=validBusinessCode", method = RequestMethod.GET)
- public AppCreateInfo validBusinessCode(String businessCode) throws UnsupportedEncodingException {
- // 去掉可能存在的空格再进行检验
- businessCode = StringUtils.trimAllWhitespace(businessCode);
- AppCreateInfo info = new AppCreateInfo();
- info.setHasCreate(false);
- info.setInCloud(false);
- if (!StringUtils.isEmpty(businessCode)) {
- Userspace userspace = userspaceService.findByBusinessCode(businessCode);
- if (null != userspace && userspace.getApps() != null) {
- for (App app : userspace.getApps()) {
- // 是否注册过saas
- if (app.getUid().equals("saas")) {
- info.setHasCreate(true);
- continue;
- }
- // 是否注册过uas
- if (app.getUid().equals("uas")) {
- info.setHasCreate(true);
- continue;
- }
- // 是否注册过平台
- if (app.getUid().equals("b2b")) {
- info.setInCloud(true);
- info.setName(userspace.getSpaceName());
- continue;
- }
- }
- }
- }
- return info;
- }
- /**
- * 校验企业名称
- *
- * @param name
- * @return
- */
- @RequestMapping(params = "_operate=validName", method = RequestMethod.GET)
- public AppCreateInfo validName(String name) {
- // 去掉可能存在的空格再进行检验
- name = StringUtils.trimAllWhitespace(name);
- AppCreateInfo info = new AppCreateInfo();
- info.setHasCreate(false);
- info.setInCloud(false);
- if (!StringUtils.isEmpty(name)) {
- Userspace userspace = userspaceService.findBySpaceName(name);
- if (null != userspace && userspace.getApps() != null) {
- for (App app : userspace.getApps()) {
- // 是否注册过saas
- if (app.getUid().equals("saas")) {
- info.setHasCreate(true);
- continue;
- }
- // 是否注册过uas
- if (app.getUid().equals("uas")) {
- info.setHasCreate(true);
- continue;
- }
- // 是否注册过平台
- if (app.getUid().equals("b2b")) {
- info.setInCloud(true);
- info.setBusinessCode(userspace.getBusinessCode());
- continue;
- }
- }
- }
- }
- return info;
- }
- /**
- * ERP、SAAS新开账套注册平台
- *
- * @param detail
- * @param userInfos
- */
- @RequestMapping(params = "_operate=registerBranchAccount", method = RequestMethod.POST)
- public AppCreateInfo applyApp(String detail, String userInfos) {
- AppCreateInfo info = new AppCreateInfo();
- // 获取接收到的信息
- List<User> users = JSON.parseArray(userInfos, User.class);
- Userspace userspace = parseObject(detail, Userspace.class);
- // 企业注册
- userspace = userspaceService.register(userspace, "uas");
- // 将用户绑定绑定到注册企业
- userspaceService.addUser(userspace, users);
- // 注册完后查询uu号等信息
- info.setInCloud(true);
- info.setEnuu(userspace.getSpaceUU() + "");
- return info;
- }
- /**
- * 从其他应用注册企业信息
- * @param userspace 企业信息
- */
- @RequestMapping(value = "/register/other", method = RequestMethod.POST)
- public ModelMap registerFromOther(Userspace userspace, User admin, String appId, @RequestParam(defaultValue = "true") boolean isSyncSource) {
- if (userspace == null || admin == null) {
- return error("参数错误");
- }
- userspace.setAdmin(admin);
- return success(userspaceService.register(userspace, appId, isSyncSource));
- }
- /**
- * 通过id查询企业信息(方便平台搜索调用)
- *
- * @param ids
- * @return
- */
- @RequestMapping(params = "_operate=findAll")
- @ResponseBody
- public List<Userspace> findAll(String ids) {
- return userspaceService.findAll(ids);
- }
- /**
- * 商城分页查询申请信息
- * @param page
- * @param size
- * @param speaceUU
- * @return
- */
- @RequestMapping(value = "/apply/info/mall", method = RequestMethod.GET)
- @ResponseBody
- public ModelMap findApplyAllToMall(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, Long speaceUU, Integer status, String keyword) {
- if (speaceUU == null) {
- return error(Const.SPACEUU_PERSONAL+"", "个人账号");
- }
- // 查询页面是从0开始,所以要减1
- return success(applyUserSpaceService.findApplyAllToMall(page, size, speaceUU, status, keyword));
- }
- /**
- * 审核申请
- * @param userUU 用户uu号
- * @return
- */
- @RequestMapping(value = "/audit/apply", method = RequestMethod.POST)
- @ResponseBody
- public ModelMap auditApply(Long userUU, Long id, Integer status) {
- applyUserSpaceService.auditApply(userUU, id, status);
- return success();
- }
- /**
- * 企业信息库总数
- */
- @RequestMapping(value = "/count", method = RequestMethod.GET)
- public ModelMap count() {
- return new ModelMap("count", userspaceService.count());
- }
- /**
- * 获取本月企业注册数量
- * @return
- */
- @RequestMapping(value = "/currentMonth/count", method = RequestMethod.GET)
- public ModelMap countInCurrentMonth() {
- return new ModelMap("count", userspaceService.countInCurrentMonth());
- }
- /**
- * 获取上个月企业注册数量
- * @return
- */
- @RequestMapping(value = "/lastMonth/count", method = RequestMethod.GET)
- public ModelMap countInLastMonth() {
- return new ModelMap("count", userspaceService.countInLastMonth());
- }
- /**
- * 获取上个月企业注册数量
- * @return
- */
- @RequestMapping(value = "/currentWeek/count", method = RequestMethod.GET)
- public ModelMap countInCurrentWeek() {
- return new ModelMap("count", userspaceService.countInCurrentWeek());
- }
- }
|