|
@@ -0,0 +1,238 @@
|
|
|
|
|
+package com.jpsoft.employment.modules.mobile.controller;
|
|
|
|
|
+
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
|
+import com.jpsoft.employment.modules.base.entity.*;
|
|
|
|
|
+import com.jpsoft.employment.modules.base.service.*;
|
|
|
|
|
+import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
|
|
+import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
|
|
+import com.jpsoft.employment.modules.common.utils.JwtUtil;
|
|
|
|
|
+import com.jpsoft.employment.modules.common.utils.PojoUtils;
|
|
|
|
|
+import com.jpsoft.employment.modules.sys.service.DataDictionaryService;
|
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/mobile/training")
|
|
|
|
|
+@Api(description = "培训信息")
|
|
|
|
|
+public class TrainingApiController {
|
|
|
|
|
+ @Value("${jwt.secret}")
|
|
|
|
|
+ private String jwtSecret;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ RabbitTemplate rabbitTemplate;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ValueOperations<String, Object> valueOperations;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TrainingInfoService trainingInfoService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TrainingPersonService trainingPersonService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EnterpriseInfoService enterpriseInfoService;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("trainingList")
|
|
|
|
|
+ @ApiOperation(value = "技能培训(公开接口")
|
|
|
|
|
+ public MessageResult<Map> trainingList(
|
|
|
|
|
+ @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
|
|
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
|
|
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
|
|
+
|
|
|
|
|
+ searchParams.put("status","1");
|
|
|
|
|
+ Page<TrainingInfo> page = trainingInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
+
|
|
|
|
|
+ for (TrainingInfo trainingInfo:page) {
|
|
|
|
|
+ EnterpriseInfo enterpriseInfo = enterpriseInfoService.get(trainingInfo.getEnterpriseId());
|
|
|
|
|
+ if(enterpriseInfo!=null){
|
|
|
|
|
+ trainingInfo.setEnterpriseName(enterpriseInfo.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ messageResult.setResult(true);
|
|
|
|
|
+ messageResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ log.error(ex.getMessage());
|
|
|
|
|
+ messageResult.setResult(false);
|
|
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return messageResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value="培训信息详细(公开接口")
|
|
|
|
|
+ @RequestMapping(value = "trainingDetail",method = RequestMethod.POST)
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "trainingId", value = "培训信息ID", required = true, paramType = "form"),
|
|
|
|
|
+ })
|
|
|
|
|
+ public MessageResult<Map> trainingDetail(
|
|
|
|
|
+ @RequestParam(value="trainingId",defaultValue="") String trainingId,
|
|
|
|
|
+ HttpServletRequest request){
|
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+ String subject = "";
|
|
|
|
|
+
|
|
|
|
|
+ String token = request.getHeader("Authorization");
|
|
|
|
|
+
|
|
|
|
|
+ if (org.springframework.util.StringUtils.isEmpty(token)){
|
|
|
|
|
+ token = (String)request.getSession().getAttribute("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (org.springframework.util.StringUtils.isEmpty(token)) {
|
|
|
|
|
+ token = request.getParameter("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(token)){
|
|
|
|
|
+ subject = JwtUtil.decodeToken(jwtSecret,token);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Boolean isJoin = false;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String,Object> returnMap = new HashMap<>();
|
|
|
|
|
+ TrainingInfo trainingInfo = trainingInfoService.get(trainingId);
|
|
|
|
|
+ if(trainingInfo == null){
|
|
|
|
|
+ throw new Exception("未找到信息");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ EnterpriseInfo enterpriseInfo = enterpriseInfoService.get(trainingInfo.getEnterpriseId());
|
|
|
|
|
+ if(enterpriseInfo!=null){
|
|
|
|
|
+ trainingInfo.setEnterpriseName(enterpriseInfo.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ PersonInfo personInfo = personInfoService.get(subject);
|
|
|
|
|
+ if(personInfo != null){
|
|
|
|
|
+ TrainingPerson trainingPerson = trainingPersonService.findByTrainingIdAndPersonId(trainingId,personInfo.getId());
|
|
|
|
|
+ if(trainingPerson != null){
|
|
|
|
|
+ isJoin = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ returnMap.put("trainingInfo",trainingInfo);
|
|
|
|
|
+ returnMap.put("enterpriseInfo",enterpriseInfo);
|
|
|
|
|
+ returnMap.put("isJoin",isJoin);
|
|
|
|
|
+
|
|
|
|
|
+ msgResult.setData(returnMap);
|
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return msgResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value="我要报名")
|
|
|
|
|
+ @RequestMapping(value = "joinTraining",method = RequestMethod.POST)
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "trainingId", value = "培训信息ID", required = true, paramType = "form"),
|
|
|
|
|
+ })
|
|
|
|
|
+ public MessageResult<Map> joinTraining(
|
|
|
|
|
+ @RequestParam(value="trainingId",defaultValue="") String trainingId,
|
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
|
+
|
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ PersonInfo personInfo = personInfoService.get(subject);
|
|
|
|
|
+ if (personInfo == null) {
|
|
|
|
|
+ throw new Exception("未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TrainingPerson trainingPerson = trainingPersonService.findByTrainingIdAndPersonId(trainingId,personInfo.getId());
|
|
|
|
|
+ if(trainingPerson != null){
|
|
|
|
|
+ throw new Exception("已报名");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ trainingPerson = new TrainingPerson();
|
|
|
|
|
+ trainingPerson.setId(UUID.randomUUID().toString());
|
|
|
|
|
+ trainingPerson.setDelFlag(false);
|
|
|
|
|
+ trainingPerson.setCreateBy(subject);
|
|
|
|
|
+ trainingPerson.setCreateTime(new Date());
|
|
|
|
|
+ trainingPerson.setTrainingId(trainingId);
|
|
|
|
|
+ trainingPerson.setPersonId(subject);
|
|
|
|
|
+
|
|
|
|
|
+ int count = trainingPersonService.insert(trainingPerson);
|
|
|
|
|
+
|
|
|
|
|
+ if(count > 0){
|
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
|
+ msgResult.setMessage("报名成功");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
|
+ msgResult.setMessage("报名失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return msgResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value="我要取消报名")
|
|
|
|
|
+ @RequestMapping(value = "cancelTraining",method = RequestMethod.POST)
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "trainingId", value = "培训信息ID", required = true, paramType = "form"),
|
|
|
|
|
+ })
|
|
|
|
|
+ public MessageResult<Map> cancelTraining(
|
|
|
|
|
+ @RequestParam(value="trainingId",defaultValue="") String trainingId,
|
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
|
+
|
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ PersonInfo personInfo = personInfoService.get(subject);
|
|
|
|
|
+ if (personInfo == null) {
|
|
|
|
|
+ throw new Exception("未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TrainingPerson trainingPerson = trainingPersonService.findByTrainingIdAndPersonId(trainingId,personInfo.getId());
|
|
|
|
|
+ if(trainingPerson == null){
|
|
|
|
|
+ throw new Exception("未报名");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ trainingPerson.setDelFlag(true);
|
|
|
|
|
+ trainingPerson.setUpdateBy(subject);
|
|
|
|
|
+ trainingPerson.setUpdateTime(new Date());
|
|
|
|
|
+ int count = trainingPersonService.update(trainingPerson);
|
|
|
|
|
+
|
|
|
|
|
+ if(count > 0){
|
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
|
+ msgResult.setMessage("操作成功");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
|
+ msgResult.setMessage("操作失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return msgResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|