| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566 |
- package platform.modules.carrier.web.api;
- import com.github.pagehelper.PageInfo;
- import com.google.web.bindery.requestfactory.shared.messages.RequestMessage;
- import com.xiaoleilu.hutool.crypto.SecureUtil;
- import jdk.nashorn.internal.objects.annotations.Getter;
- import org.apache.shiro.authc.*;
- import org.apache.shiro.crypto.hash.Hash;
- import org.apache.shiro.subject.Subject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.*;
- import platform.common.Constant;
- import platform.common.annotation.OperationLog;
- import platform.common.base.controller.BaseController;
- import platform.common.base.model.DictionaryItem;
- import platform.common.base.service.DictionaryItemService;
- import platform.common.util.LetterEnum;
- import platform.common.util.ShiroUtils;
- import platform.common.util.VerificationCodeUtil;
- import platform.modules.build.entity.Company;
- import platform.modules.build.entity.CompanyContact;
- import platform.modules.build.service.CompanyContactService;
- import platform.modules.build.service.CompanyService;
- import platform.modules.carrier.dto.*;
- import platform.modules.carrier.entity.Building;
- import platform.modules.carrier.entity.InvestmentInfo;
- import platform.modules.carrier.entity.Park;
- import platform.modules.carrier.entity.RentalProject;
- import platform.modules.carrier.service.*;
- import platform.modules.government.entity.Street;
- import platform.modules.government.entity.User;
- import platform.modules.government.service.Government;
- import platform.modules.government.service.StreetService;
- import platform.modules.government.service.UserService;
- import platform.modules.sys.entity.ActivityDetail;
- import platform.modules.sys.entity.ActivityFavourite;
- import platform.modules.sys.entity.ActivityRegistration;
- import platform.modules.sys.entity.Message;
- import platform.modules.sys.service.ActivityFavouriteService;
- import platform.modules.sys.service.ActivityRegistrationService;
- import platform.modules.sys.service.ActivityService;
- import platform.modules.sys.service.MessageService;
- import platform.modules.sys.shiro.UsernamePasswordToken;
- import platform.modules.sys.vo.MessageDto;
- import platform.modules.sys.web.ResponseMessage;
- import sun.misc.BASE64Decoder;
- import java.net.Inet4Address;
- import java.util.*;
- /**
- * @author kevin
- * @since 2019/7/11 3:36 PM
- */
- @RestController
- @RequestMapping("/wechat")
- public class WeChatApiController extends BaseController {
- @Autowired
- private IcContractService contractService;
- @Autowired
- private UserService userService;
- @Autowired
- private BuildingService buildingService;
- @Autowired
- private StreetService streetService;
- @Autowired
- private ParkService parkService;
- @Autowired
- private InvestmentInfoService investmentInfoService;
- @Autowired
- private RentalProjectService rentalProjectService;
- @Autowired
- private VerificationCodeUtil verificationCodeUtil;
- @Autowired
- private CompanyService companyService;
- @Autowired
- private CarrierStatisticService carrierStatisticService;
- @Autowired
- private MessageService messageService;
- @Autowired
- private DictionaryItemService dictionaryItemService;
- @Autowired
- private ActivityFavouriteService activityFavouriteService;
- @Autowired
- private ActivityRegistrationService activityRegistrationService;
- @Autowired
- private ActivityService activityService;
- /**
- * 用户登陆
- * 先根据用户名查询出一条用户记录再对比密码是否正确可以防止sql注入
- *
- * @return
- */
- @OperationLog(value = "用户登录")
- @PostMapping(value = "/wechatLogin")
- public ResponseMessage wechatLogin(@RequestBody WechatLogin wechatLogin) {
- String username = wechatLogin.getUsername();
- String password = wechatLogin.getPassword();
- try {
- //获取当前的Subject
- Subject currentUser = ShiroUtils.getSubject();
- UsernamePasswordToken token = new UsernamePasswordToken(username, password, true, false);
- log.info("对用户进行登录验证..验证开始! username = {}", username);
- currentUser.login(token);
- //验证是否登录成功
- if (currentUser.isAuthenticated()) {
- log.info("对用户进行登录验证..验证通过! username = {}", username);
- ModelMap modelMap = new ModelMap();
- //获取token
- modelMap.put("token", userService.createToken());
- // modelMap.put("user", userService.findByNickName(username));
- modelMap.put("user", ShiroUtils.getUserEntity());
- return ResponseMessage.success(Constant.USER_LOGIN_IN, modelMap);
- }
- } catch (UnknownAccountException e) { //账号不存在
- log.info("! username = {}", username);
- return ResponseMessage.error(Constant.USER_NOT_FIND);
- } catch (IncorrectCredentialsException e) {
- log.info("对用户进行登录验证..验证未通过,错误的凭证! username = {}", username);
- return ResponseMessage.error(Constant.USER_INVALID);
- } catch (LockedAccountException e) {
- log.info("对用户进行登录验证..验证未通过,账户已锁定! username = {}", username);
- return ResponseMessage.error(Constant.USER_HAS_LOCK);
- } catch (ExcessiveAttemptsException eae) {
- log.info("对用户进行登录验证..验证未通过,错误次数过多! username = {}", username);
- return ResponseMessage.error(Constant.USER_ERROR_MANY);
- } catch (AuthenticationException e) {
- return ResponseMessage.error(Constant.SYSTEM_ERRORS);
- } catch (Exception e) {
- log.error("对用户进行登录验证失败! username = {} e = {}", username, e);
- }
- return ResponseMessage.error(Constant.SYSTEM_ERRORS);
- }
- /**
- * 获取街道剩余面积和代租面积
- *
- * @return
- */
- @GetMapping("/street/statistic")
- public Object getStreetAreaStatistic(
- @RequestParam(defaultValue = "1", required = false) Integer pageNum,
- @RequestParam(defaultValue = "10", required = false) Integer pageSize
- ) {
- PageInfo<CarrierLibraryResult> pageInfo = contractService.getStreetAreaStatistic(pageNum, pageSize);
- return ResponseMessage.success("success", pageInfo);
- }
- /**
- * 载体查询
- *
- * @return
- */
- @RequestMapping("/checkCarrier")
- public Object carrierCheck(@RequestBody CarrierQueryDto query) {
- PageInfo<Building> pageInfo = buildingService.getBuildingsByQuery(query);
- return ResponseMessage.success("success", pageInfo);
- }
- /**
- * 获取所有街道
- *
- * @return
- */
- @GetMapping("/streets")
- public Object getStreetList() {
- Street street = new Street();
- street.setIs_start(true);
- List<Street> streets = streetService.findListByWhere(street);
- return ResponseMessage.success("success", streets);
- }
- /**
- * 获取所有园区
- *
- * @return
- */
- @GetMapping("/parkNames")
- public Object findParkNames(SearchCondition condition) {
- PageInfo<Park> pageInfo = parkService.findParkNames(condition);
- return ResponseMessage.success("success", pageInfo);
- }
- /**
- * 载体方案详情
- *
- * @return
- */
- @PostMapping("/buildingDetail/{id}")
- public Object buildingDetail(@PathVariable Integer id, @RequestBody CarrierQueryDto query) {
- Building building = buildingService.findCheckinDetail(id, query);
- return ResponseMessage.success("success", building);
- }
- /**
- * 获取详情
- *
- * @param id
- * @return
- */
- @GetMapping(value = "/investment/{id}")
- public ResponseMessage get(@PathVariable Integer id) {
- InvestmentInfo res = investmentInfoService.getById(id);
- res.setFile_down_url(setFileUrl());
- return ResponseMessage.success("success", res);
- }
- /**
- * 查看园区详情(前台)
- *
- * @return
- */
- @GetMapping("/front/parkDetail/{id}")
- public Object frontParkDetail(@PathVariable Integer id) {
- Park park = parkService.frontParkDetailById(id);
- park.setFile_down_url(setFileUrl());
- return ResponseMessage.success("success", park);
- }
- /**
- * 获取详情
- *
- * @param id
- * @return
- */
- @GetMapping(value = "/rental/{id}")
- public ResponseMessage rental(@PathVariable Integer id) {
- RentalProject res = rentalProjectService.getById(id);
- res.setFile_down_url(setFileUrl());
- return ResponseMessage.success("success", res);
- }
- /**
- * 获取公司第一联系人
- *
- * @param id
- * @return
- */
- @GetMapping("/firstContact/{id}")
- public Object firstCompanyContact(@PathVariable Integer id) {
- User firstContact = userService.findFirstContact(id);
- return ResponseMessage.success("success", firstContact);
- }
- /**
- * 个人中心
- *
- * @param id
- * @return
- */
- @GetMapping("/personalCenter/{id}")
- public Object personalCenter(@PathVariable Integer id) {
- User user = userService.findById(id);
- if (user.getUser_type().equals(Constant.UserType.GOVERNMENT)) {
- user.setDepartment_name(userService.getGovDepartment(user));
- }
- if (user.getUser_type().equals(Constant.UserType.COMPANY)) {
- user.setDepartment_name(userService.getCompanyDepartment(user));
- }
- if (user.getUser_type().equals(Constant.UserType.STREET)) {
- user.setDepartment_name(userService.getStreetDepartment(user));
- }
- if (user.getUser_type().equals(Constant.UserType.BUILD)) {
- user.setDepartment_name(userService.getBuildDepartment(user));
- }
- return ResponseMessage.success("success", user);
- }
- /**
- * 修改密码
- *
- * @param changePassword
- * @return
- */
- @OperationLog(value = "修改密码")
- @PostMapping("/changePass")
- public Object changePass(@RequestBody ChangePassword changePassword) {
- return userService.changePassword(changePassword);
- }
- /**
- * 企业重置密码
- *
- * @param information
- * @return
- * @throws Exception
- */
- @PostMapping("/reset")
- public ResponseMessage reset(@RequestBody Company information) {
- try {
- if (!verificationCodeUtil.validateVerificationCode(information.getPhone(), information.getValidateNum())) {
- return ResponseMessage.error("验证码错误!");
- }
- User user = userService.getUserByNickname(information.getNick_name());
- user.setPassword(SecureUtil.md5().digestHex(information.getPassword()));
- userService.updateSelective(user);
- } catch (Exception e) {
- e.printStackTrace();
- return ResponseMessage.error("修改失败" + e.getMessage());
- }
- return ResponseMessage.success("密码修改成功!系统将跳转到登陆页进行登录");
- }
- /**
- * 校验账户名手机号是否匹配后发送验证码
- *
- * @param changePassword
- * @return
- * @throws Exception
- */
- @PostMapping("/sendVerificationCodePhoneAndName")
- public ResponseMessage sendVerificationCodePhoneAndName(@RequestBody ChangePassword changePassword) {
- User user = userService.getUserByNickname(changePassword.getNickname());
- if (null == user) {
- //throw new BaseException("该账号名不存在!");
- return ResponseMessage.error("该账号名不存在!");
- } else if (!changePassword.getPhone().equals(user.getPhone())) {
- //throw new BaseException("账号名与手机号码不匹配!");
- return ResponseMessage.error("账号名与手机号码不匹配!");
- }
- int t = verificationCodeUtil.validateVerificationTime(changePassword.getPhone(), 60L);
- if (t > 0) {
- return ResponseMessage.error("操作过于频繁!请" + t + "秒后再尝试!");
- }
- verificationCodeUtil.setVerificationCode(changePassword.getPhone());
- return ResponseMessage.success("发送成功!请注意查收!");
- }
- /**
- * 企业通讯录
- *
- * @param letter
- * @return
- */
- @GetMapping("/companyContactList")
- public Object companyContact(String letter, String companyName) {
- List<CompanyContacts> companyContacts = companyService.findCompanyListByName(letter, companyName);
- return ResponseMessage.success("success", companyContacts);
- }
- public static void main(String[] args) {
- for (LetterEnum anEnum : LetterEnum.values()) {
- System.out.println(anEnum);
- }
- }
- /**
- * 载体库楼栋列表
- *
- * @return
- */
- @GetMapping("/buildingStatistic")
- public Object getBuildingStatistic(
- @RequestParam(defaultValue = "1", required = false) Integer pageNum,
- @RequestParam(defaultValue = "10", required = false) Integer pageSize,
- SearchCondition condition) {
- Map<String, Object> map = carrierStatisticService.getWechatBuildingStatistic(pageNum, pageSize, condition);
- return ResponseMessage.success("success", map);
- }
- /**
- * 载体库各街道列表
- *
- * @return
- */
- @GetMapping("/streetStatistic")
- public Object getStreetStatistic(
- @RequestParam(defaultValue = "1", required = false) Integer pageNum,
- @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
- Map<String, Object> map = carrierStatisticService.getWechatStreetStatistic(pageNum, pageSize);
- return ResponseMessage.success("success", map);
- }
- /**
- * 载体各库园区列表
- *
- * @return
- */
- @GetMapping("/parkStatistic/{id}")
- public Object getParkStatistic(
- @RequestParam(defaultValue = "1", required = false) Integer pageNum,
- @RequestParam(defaultValue = "10", required = false) Integer pageSize,
- @PathVariable Integer id) {
- Map<String, Object> map = carrierStatisticService.getWechatParkStatistic(pageNum, pageSize, id);
- return ResponseMessage.success("success", map);
- }
- @OperationLog(value = "查看我的消息列表")
- @GetMapping(value = "/myMessage")
- public Object list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
- String queryStr, MessageDto searchCondition) throws Exception {
- Map<String, Object> map = new HashMap<>();
- try {
- log.debug("分页查询消息列表参数! pageNum = {}, keyword = {}", pageNum, queryStr);
- PageInfo<Message> pageInfo = messageService.findPage(pageNum, PAGESIZE, queryStr, searchCondition);
- log.info("分页查询消息列表结果! pageInfo = {}", pageInfo);
- map.put("pageInfo", pageInfo);
- map.put("keyword", queryStr);
- map.put("searchCondition", searchCondition);
- List<DictionaryItem> messageTypes = dictionaryItemService.findListByTypeName(Constant.DictionaryType.MESSAGE_TYPE);
- map.put("messageTypeList", messageTypes);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ResponseMessage.success("", map);
- }
- /**
- * 添加收藏
- *
- * @return
- */
- @OperationLog(value = "收藏活动")
- @ResponseBody
- @GetMapping(value = "/addFavourite/{id}")
- public ResponseMessage addFavourite(@PathVariable("id") int id, Integer user_id) throws Exception {
- log.info("查询是否收藏!id = {}", id);
- // if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
- ActivityFavourite activityFavourite = new ActivityFavourite();
- activityFavourite.setActivity_id(id);
- activityFavourite.setUser_id(user_id);
- int count = activityFavouriteService.saveActivityFavourite(activityFavourite);
- if (count > 0) return ResponseMessage.success("收藏成功!");
- return ResponseMessage.success("收藏失败!");
- }
- /**
- * 取消收藏
- *
- * @return
- */
- @OperationLog(value = "取消收藏活动")
- @ResponseBody
- @GetMapping(value = "/removeFavourite/{id}")
- public ResponseMessage removeFavourite(@PathVariable("id") int id, Integer user_id) throws Exception {
- log.info("查询是否收藏!id = {}", id);
- boolean b = activityFavouriteService.deleteByActivityIdAndUserId(id + "", user_id + "");
- if (b) return ResponseMessage.success("取消收藏成功!");
- return ResponseMessage.success("取消收藏失败!");
- }
- /**
- * 获取用户报名各类活动数
- *
- * @return
- */
- @GetMapping("activityStatistic/{userId}")
- public Object activityStatistic(@PathVariable Integer userId) {
- ActivityStatistic statistic = activityRegistrationService.findActivityStatistic(userId);
- return ResponseMessage.success("success", statistic);
- }
- /**
- * 获取用户报名各类活动
- *
- * @return
- */
- @GetMapping("findTypesActivitys/{userId}")
- public Object findTypesActivitys(@PathVariable Integer userId, String type) {
- List<ActivityDetail> activitys = activityRegistrationService.findTypesActivitys(type, userId);
- for (ActivityDetail activity : activitys) {
- List<Integer> userIds = new ArrayList<>();
- List<ActivityRegistration> regUsers = activityRegistrationService.getWechatCurrRegUsers(activity.getId() + "", userId);
- for (ActivityRegistration regUser : regUsers) {
- userIds.add(regUser.getId());
- }
- activity.setRegUsers(userIds);
- }
- Map<String, Object> map = new HashMap<>();
- map.put("file_url", setFileUrl());
- map.put("activitys", activitys);
- return ResponseMessage.success("success", map);
- }
- /**
- * 获取已报名的用户
- *
- * @return
- */
- @GetMapping(value = "/getRegUsers")
- public ResponseMessage getRegUsers(String activity_id, Integer user_id) {
- log.info("获取已报名的用户!");
- System.out.println(ShiroUtils.getUserEntity());
- return ResponseMessage.success("查询成功!", activityRegistrationService.getWechatCurrRegUsers(activity_id, user_id));
- }
- /**
- * 取消报名
- *
- * @param ids
- * @return
- */
- @PostMapping("/abort")
- public Object quert(@RequestBody List<String> ids) {
- // List<String> idList = Arrays.asList(ids);
- activityRegistrationService.adortRegister(ids);
- return ResponseMessage.success("取消成功");
- }
- /**
- * 强烈推荐
- *
- * @return
- */
- @GetMapping("/highlyRecommended")
- public Object highlyRecommended(
- @RequestParam(defaultValue = "1") Integer pageNum,
- @RequestParam(defaultValue = "10") Integer pageSize) {
- Map<String, Object> map = new HashMap<>();
- map.put("file_url", setFileUrl());
- map.put("data", activityService.findHighlyRecommended(pageNum, pageSize));
- return ResponseMessage.success("success", map);
- }
- /**
- * 我的项目查询
- *
- * @param condition
- * @return
- * @throws Exception
- */
- @PostMapping(value = "/rentals/{userid}")
- public ResponseMessage list(@PathVariable Integer userId, @RequestBody CustomSearchCondition condition) throws Exception {
- log.info("分页查询招商信息,pageNum = {},condition = {}", condition.getPageNum(), condition.toString(), false);
- condition.setFile_url(setFileUrl());
- PageInfo<RentalProject> pageInfo = rentalProjectService.findMyList(userId, condition);
- log.info("分页查询招商信息列表结果! pageInfo = {}", pageInfo);
- return ResponseMessage.success("success", pageInfo);
- }
- }
|