|
|
@@ -0,0 +1,186 @@
|
|
|
+package com.jpsoft.employment.modules.base.api;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.employment.modules.base.entity.WishInfo;
|
|
|
+import com.jpsoft.employment.modules.base.entity.WishInfoUserRecord;
|
|
|
+import com.jpsoft.employment.modules.base.service.StudentAspirationsService;
|
|
|
+import com.jpsoft.employment.modules.base.service.WishInfoService;
|
|
|
+import com.jpsoft.employment.modules.base.service.WishInfoUserRecordService;
|
|
|
+import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.employment.modules.sys.entity.DataDictionary;
|
|
|
+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 org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/api/wish")
|
|
|
+@Api(description = "心愿互换")
|
|
|
+public class WishApi {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WishInfoService wishInfoService;
|
|
|
+ @Autowired
|
|
|
+ private WishInfoUserRecordService wishInfoUserRecordService;
|
|
|
+ @Autowired
|
|
|
+ private StudentAspirationsService studentAspirationsService;
|
|
|
+ @Autowired
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
+
|
|
|
+ @ApiOperation(value="心愿单列表")
|
|
|
+ @RequestMapping(value = "list",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="title", value="名称", required=false, paramType="query"),
|
|
|
+ })
|
|
|
+ public MessageResult list(
|
|
|
+ String title,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(title)) {
|
|
|
+ searchParams.put("title","%" + title + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+
|
|
|
+ Page<WishInfo> page = wishInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(page.getResult());
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="心愿单详情")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="id", value="ID", required=true, paramType="query"),
|
|
|
+ })
|
|
|
+ public MessageResult<WishInfo> edit(@PathVariable("id") String id){
|
|
|
+ MessageResult<WishInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ WishInfo wishInfo = wishInfoService.get(id);
|
|
|
+ wishInfo.setAspirationList(studentAspirationsService.findByWish(id));
|
|
|
+ wishInfo.setRecordList(wishInfoUserRecordService.findByWish(id));
|
|
|
+
|
|
|
+ if (wishInfo != null) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(wishInfo);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="提交心愿单")
|
|
|
+ @RequestMapping(value = "add",method = RequestMethod.POST)
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="wishInfoId", value="心愿信息ID", required=true, paramType="query"),
|
|
|
+ @ApiImplicitParam(name="isSpot", value="是否现场互换心愿", required=true, paramType="query"),
|
|
|
+ @ApiImplicitParam(name="recipients", value="收件人", required=false, paramType="query"),
|
|
|
+ @ApiImplicitParam(name="recipientsPhone", value="收件人电话", required=false, paramType="query"),
|
|
|
+ @ApiImplicitParam(name="recipientsAddress", value="收件人地址", required=false, paramType="query"),
|
|
|
+ })
|
|
|
+ public MessageResult<WishInfoUserRecord> add(String wishInfoId, Boolean isSpot,
|
|
|
+ String recipients, String recipientsPhone, String recipientsAddress,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<WishInfoUserRecord> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ WishInfoUserRecord wishInfoUserRecord = new WishInfoUserRecord();
|
|
|
+ wishInfoUserRecord.setId(UUID.randomUUID().toString());
|
|
|
+ wishInfoUserRecord.setRegUserId(subject);
|
|
|
+ wishInfoUserRecord.setWishInfoId(wishInfoId);
|
|
|
+ wishInfoUserRecord.setIsSpot(isSpot);
|
|
|
+ wishInfoUserRecord.setStatus("0");
|
|
|
+ wishInfoUserRecord.setNum(getSerialNumber());
|
|
|
+ wishInfoUserRecord.setRecipients (recipients);
|
|
|
+ wishInfoUserRecord.setRecipientsPhone(recipientsPhone);
|
|
|
+ wishInfoUserRecord.setRecipientsAddress(recipientsAddress);
|
|
|
+ wishInfoUserRecord.setDelFlag(false);
|
|
|
+ wishInfoUserRecord.setCreateBy(subject);
|
|
|
+ wishInfoUserRecord.setCreateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = wishInfoUserRecordService.insert(wishInfoUserRecord);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(wishInfoUserRecord);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="心愿类型列表")
|
|
|
+ @RequestMapping(value = "wishTypeList",method = RequestMethod.POST)
|
|
|
+ public MessageResult<List> wishTypeList(){
|
|
|
+ MessageResult<List> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<DataDictionary> list = dataDictionaryService.findByCatalogName("心愿类型");
|
|
|
+ messageResult.setData(list);
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSerialNumber() {
|
|
|
+ String serialNumber = "";
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ serialNumber = sdf.format(new Date());
|
|
|
+
|
|
|
+ String lastSerialNumber = wishInfoUserRecordService.getLastSerialNumber(serialNumber + "%");
|
|
|
+ if(lastSerialNumber == null){
|
|
|
+ serialNumber = serialNumber + "0001";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ serialNumber = serialNumber + String.format("%04d",Integer.valueOf(lastSerialNumber.substring(8)) + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return serialNumber;
|
|
|
+ }
|
|
|
+}
|