|
|
@@ -0,0 +1,309 @@
|
|
|
+package platform.modules.api.web;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import platform.common.Constant;
|
|
|
+import platform.common.annotation.OperationLog;
|
|
|
+import platform.common.base.controller.BaseController;
|
|
|
+import platform.common.util.ShiroUtils;
|
|
|
+import platform.common.util.WxAppUtil;
|
|
|
+import platform.modules.build.entity.Company;
|
|
|
+import platform.modules.build.service.CompanyService;
|
|
|
+import platform.modules.government.dto.ParamRegistration;
|
|
|
+import platform.modules.government.entity.Attachment;
|
|
|
+import platform.modules.government.entity.FileDown;
|
|
|
+import platform.modules.government.entity.User;
|
|
|
+import platform.modules.government.service.AttachmentService;
|
|
|
+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.service.ActivityFavouriteService;
|
|
|
+import platform.modules.sys.service.ActivityRegistrationService;
|
|
|
+import platform.modules.sys.service.ActivityService;
|
|
|
+import platform.modules.sys.service.WaitToDoService;
|
|
|
+import platform.modules.sys.web.ResponseMessage;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author :huZhiHao
|
|
|
+ * @Date :Created in 2019/12/16 15:23
|
|
|
+ * @Description: TODO
|
|
|
+ * @Modified By:
|
|
|
+ * @Version: v0.0.1
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/activity")
|
|
|
+public class ActivityOpenController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityService activityService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityRegistrationService activityRegistrationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AttachmentService attachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ActivityFavouriteService activityFavouriteService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WaitToDoService waitToDoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 获取详情
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [activity_id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @GetMapping(value = "/detail/{activity_id}")
|
|
|
+ public ResponseMessage getActivityDetail(@PathVariable("activity_id") int id) throws Exception {
|
|
|
+
|
|
|
+ ActivityDetail activityDetail = activityService.findOne(id + "");
|
|
|
+ activityService.increment(id + "");
|
|
|
+ List<ActivityRegistration> registrationList = activityRegistrationService.findRegistrationList(id);
|
|
|
+ int num = 0;
|
|
|
+ String quota = activityDetail.getActivity_quota();
|
|
|
+ if (StringUtils.isBlank(quota)) quota = "0";
|
|
|
+ for (ActivityRegistration activityRegistration : registrationList) {
|
|
|
+ if (Objects.equals(activityRegistration.getReview_state(), "1")) {
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int remain = Integer.parseInt(quota) - num;
|
|
|
+ if (remain < 0) {
|
|
|
+ remain = 0;
|
|
|
+ }
|
|
|
+ activityDetail.setActivity_remain(remain + "");
|
|
|
+ List<Attachment> attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.ACTIVITY, activityDetail.getId(), null);
|
|
|
+ if (null != attachments && attachments.size() > 0) {
|
|
|
+ FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(), attachments.get(0).getDownload_uri());
|
|
|
+ activityDetail.setFileDown(fileDown);
|
|
|
+ }
|
|
|
+ return ResponseMessage.success("查询成功!", activityDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 是否已报名
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [activity_id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @GetMapping(value = "/is_regist")
|
|
|
+ public ResponseMessage getActivityDetail(@RequestParam("activity_id") String id, @RequestParam("phone") String phone) {
|
|
|
+
|
|
|
+ List<ActivityRegistration> activityRegistrationList = activityRegistrationService.getCurrRegUsers(id, phone);
|
|
|
+ if (CollectionUtils.isEmpty(activityRegistrationList))
|
|
|
+ return ResponseMessage.success("查询成功!", false);
|
|
|
+ return ResponseMessage.success("查询成功!", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 活动报名
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [paramRegistration]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @OperationLog(value = "报名活动")
|
|
|
+ @PostMapping(value = "/joinActivity")
|
|
|
+ public ResponseMessage joinActivity(@RequestBody ParamRegistration paramRegistration) {
|
|
|
+
|
|
|
+ log.info("活动报名");
|
|
|
+
|
|
|
+ Integer id = paramRegistration.getRegistrationList().get(0).getActivity_id();
|
|
|
+ ActivityDetail activityDetail = activityService.findById(id);
|
|
|
+ String quota = activityDetail.getActivity_quota();
|
|
|
+ String isReview = activityDetail.getIs_review();
|
|
|
+ int registrationNumber = 0;
|
|
|
+ if (!Objects.equals(quota, null) && !Objects.equals(quota, "")) {
|
|
|
+ //名额有限
|
|
|
+ if (Objects.equals(isReview, "1")) {
|
|
|
+ //需要审核
|
|
|
+ //已报名人数
|
|
|
+ registrationNumber = activityRegistrationService.getActivityRegistrationNumber(id);
|
|
|
+ if (registrationNumber >= Integer.parseInt(quota)) {
|
|
|
+ return ResponseMessage.success("名额不足,仅剩" + (Integer.parseInt(quota) - registrationNumber) + "个名额,请修改人数!", false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ActivityRegistration> registrationList = paramRegistration.getRegistrationList();
|
|
|
+ if (!org.apache.commons.collections.CollectionUtils.isEmpty(registrationList)) {
|
|
|
+ for (ActivityRegistration registration : registrationList) {
|
|
|
+ if (registration.getId() == null) {
|
|
|
+ activityRegistrationService.saveActivityRegistration(registration);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<User> pusers = userService.findUsersByPermission("G_ACTIVITY_MANAGE");
|
|
|
+ waitToDoService.completeAllTODO(activityDetail.getId(), Constant.DictionaryType.ACTIVITY_APPLICATION);
|
|
|
+ for (User puser : pusers) {
|
|
|
+ waitToDoService.newTODO(activityDetail.getActivity_title() + "审核", "/government/activity/review/" + activityDetail.getId(), Constant.WaitToDo_OperType.AUDIT, activityDetail.getId(),
|
|
|
+ Constant.DictionaryType.ACTIVITY_APPLICATION, null, puser.getId().toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Objects.equals(quota, null) && !Objects.equals(quota, "")) {
|
|
|
+ //名额有限
|
|
|
+ if (Objects.equals(isReview, "1")) {
|
|
|
+ //需要审核
|
|
|
+ //已报名人数
|
|
|
+ registrationNumber = activityRegistrationService.getActivityRegistrationNumber(id);
|
|
|
+ return ResponseMessage.success("报名成功,剩余" + (Integer.parseInt(quota) - registrationNumber) + "个名额!", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseMessage.success("报名成功!", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @OperationLog(value = "取消报名")
|
|
|
+ @DeleteMapping(value = "/cancel_regist")
|
|
|
+ public ResponseMessage cancelRegist(@RequestParam("activity_id") String id, @RequestParam("phone") String phone) {
|
|
|
+
|
|
|
+ List<ActivityRegistration> activityRegistrationList = activityRegistrationService.getCurrRegUsers(id, phone);
|
|
|
+ if (!CollectionUtils.isEmpty(activityRegistrationList)) {
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ for (ActivityRegistration activityRegistration : activityRegistrationList) {
|
|
|
+ ids.add(activityRegistration.getId() + "");
|
|
|
+ }
|
|
|
+ activityRegistrationService.adortRegister(ids);
|
|
|
+ }
|
|
|
+ return ResponseMessage.success("操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 获取已报名
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @GetMapping(value = "/regist_user/list")
|
|
|
+ public ResponseMessage getCurrRegUsers(@RequestParam("activity_id") String id, @RequestParam("phone") String phone) {
|
|
|
+
|
|
|
+ List<ActivityRegistration> activityRegistrationList = activityRegistrationService.getCurrRegUsers(id, phone);
|
|
|
+ return ResponseMessage.success("查询成功!", activityRegistrationList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 查询是否收藏
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @GetMapping(value = "/is_favourite/{activity_id}")
|
|
|
+ public ResponseMessage isFavourite(@PathVariable("activity_id") int id) throws Exception {
|
|
|
+
|
|
|
+ log.info("查询是否收藏!activity_id = {}", id);
|
|
|
+ if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
|
|
|
+ ActivityFavourite activityFavourite = activityFavouriteService.selectByActivityIdAndUserId(id + "", ShiroUtils.getUserId() + "");
|
|
|
+ if (Objects.equals(activityFavourite, null)) return ResponseMessage.success("查询成功!", 1);
|
|
|
+ return ResponseMessage.success("查询成功!", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 添加收藏
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @OperationLog(value = "收藏活动")
|
|
|
+ @PostMapping(value = "/add_favourite")
|
|
|
+ public ResponseMessage addFavourite(@RequestBody ActivityFavourite activityFavourite) throws Exception {
|
|
|
+
|
|
|
+ if (!ShiroUtils.isLogin()) return ResponseMessage.success("请先登录!", 2);
|
|
|
+
|
|
|
+ int count = activityFavouriteService.saveActivityFavourite(activityFavourite);
|
|
|
+ if (count > 0) return ResponseMessage.success("收藏成功!");
|
|
|
+ return ResponseMessage.success("收藏失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author: huZhiHao
|
|
|
+ * @Description: 取消收藏
|
|
|
+ * @Date: 2019/12/17
|
|
|
+ * @Params: [id]
|
|
|
+ * @Return: platform.modules.sys.web.ResponseMessage
|
|
|
+ **/
|
|
|
+ @OperationLog(value = "取消收藏活动")
|
|
|
+ @DeleteMapping(value = "/remove_favourite/{activity_id}")
|
|
|
+ public ResponseMessage removeFavourite(@PathVariable("id") int id) throws Exception {
|
|
|
+
|
|
|
+ boolean b = activityFavouriteService.deleteByActivityIdAndUserId(id + "", ShiroUtils.getUserId() + "");
|
|
|
+ if (b) return ResponseMessage.success("取消收藏成功!");
|
|
|
+ return ResponseMessage.success("取消收藏失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新登记表
|
|
|
+ @OperationLog(value = "更新登记表")
|
|
|
+ @PutMapping(value = "/registration")
|
|
|
+ public ResponseMessage updateRegistration(@RequestBody ActivityRegistration activityRegistration) {
|
|
|
+
|
|
|
+ Integer ret = activityRegistrationService.updateSelective(activityRegistration);
|
|
|
+ if (ret > 0) return ResponseMessage.success("更新成功!");
|
|
|
+ return ResponseMessage.success("更新失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据手机号获取报名信息
|
|
|
+ @OperationLog(value = "根据手机号获取报名信息")
|
|
|
+ @GetMapping(value = "/registration")
|
|
|
+ public ResponseMessage getByPhone(@RequestParam("activity_id") Integer id, @RequestParam("phone") String phone) {
|
|
|
+
|
|
|
+ ActivityRegistration activityRegistration = new ActivityRegistration();
|
|
|
+ activityRegistration.setActivity_id(id);
|
|
|
+ activityRegistration.setPhone(phone);
|
|
|
+ List<ActivityRegistration> ret = activityRegistrationService.findListByWhere(activityRegistration);
|
|
|
+ Iterator<ActivityRegistration> it = ret.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ if (Objects.equals(it.next().getReview_state(), "3"))
|
|
|
+ it.remove();
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(ret)) return ResponseMessage.success("查询成功!");
|
|
|
+ return ResponseMessage.success("查询成功!", ret.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ //签到
|
|
|
+ @OperationLog(value = "签到")
|
|
|
+ @PutMapping(value = "/sign")
|
|
|
+ public ResponseMessage getByPhone(@RequestBody ActivityRegistration activityRegistration) {
|
|
|
+
|
|
|
+ activityRegistration.setSign_state("0");
|
|
|
+ activityRegistrationService.updateState(activityRegistration);
|
|
|
+ return ResponseMessage.success("签到成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据手机号获取用户信息和企业信息
|
|
|
+ @OperationLog(value = "根据手机号获取用户信息和企业信息")
|
|
|
+ @GetMapping(value = "/user_info")
|
|
|
+ public ResponseMessage getuserInfoByPhone(@RequestParam("phone") String phone) {
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ User user = userService.findByMobile(phone);
|
|
|
+ if (user != null) {
|
|
|
+ Company company = companyService.findById(user.getCompany_id());
|
|
|
+ map.put("user_name", user.getUser_name());
|
|
|
+ map.put("phone", user.getPhone());
|
|
|
+ map.put("email", user.getEmail());
|
|
|
+
|
|
|
+ map.put("company_name", company.getCompany_name());
|
|
|
+ map.put("industry_name", company.getIndustry_name());
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseMessage.success("查询成功!", map);
|
|
|
+ }
|
|
|
+}
|