package com.iformall.controller; import com.github.pagehelper.PageInfo; import com.iformall.annotation.AuthIgnore; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.sm.MaterialMould; import com.iformall.domain.po.sm.PersonPhoto; import com.iformall.enums.EnumMouldPatchType; import com.iformall.enums.EnumMouldSendType; import com.iformall.enums.EnumaMouldPatchStatus; import com.iformall.service.sm.MaterialMouldService; import com.iformall.service.sm.MouldPatchSignService; import com.iformall.service.sm.PersonPhotoService; 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.util.ObjectUtils; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/personPhoto") @Api(description = "模板接口") public class PersonPhotoController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private PersonPhotoService personPhotoService; @Autowired private MouldPatchSignService mouldPatchSignService; @AuthIgnore @ApiOperation("分页列表接口") @GetMapping("list") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData list(@ModelAttribute PersonPhoto record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] PersonPhotoController::list"); if (record == null) record = new PersonPhoto(); record.setStatus(EnumaMouldPatchStatus.put_on.getCode()); record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = personPhotoService.cListAsPage(record, pageNum, pageSize); return new ResultData(page); } @ApiOperation("分页列表接口") @GetMapping("userList") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData userList(@ModelAttribute PersonPhoto record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] PersonPhotoController::userList"); if (record == null) record = new PersonPhoto(); record.setUserId(getMemberId()); record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = personPhotoService.cListAsPage(record, pageNum, pageSize); return new ResultData(page); } @ApiOperation("新增接口") @PostMapping("save") public ResultData save(@RequestBody PersonPhoto record) { logger.debug("[" + getIpAddr() + "] PersonPhotoController::save"); if(record == null)record = new PersonPhoto(); record.setSendType(EnumMouldSendType.build.getCode()); record.setUserId(getMemberId()); if(StringUtils.isBlank(record.getMaterial())){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"素材为空"); } //todo 掉第三方接口判断图片是否符合规范 ResultData data = personPhotoService.checkPhoto(record.getMaterial()); if (data.code != 2000){ return new ResultData(data.code,data.message); } if(record.getTitle() == null){ record.setTitle("用户自建"); } record.setPrice(0); record.setSalePrice(0); record.setStatus(EnumaMouldPatchStatus.put_on.getCode()); return personPhotoService.saveOrUpdate(record); } @ApiOperation("根据id查询接口") @GetMapping("/findById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData findById(Long id) { logger.debug("[" + getIpAddr() + "] PersonPhotoController::findById"); PersonPhoto personPhoto = personPhotoService.getDetailById(id); return new ResultData(personPhoto); } @ApiOperation("根据id删除接口") @GetMapping("/del") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData del(Long id) { logger.debug("[" + getIpAddr() + "] PersonPhotoController::del"); if(id == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"参数为空"); } PersonPhoto personPhoto = personPhotoService.getById(id); if(personPhoto == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到数据"); } if(!personPhoto.getUserId().equals(getMemberId())){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到用户数据"); } personPhotoService.deleteById(id); return new ResultData(); } }