|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.goafanti.admin.controller;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.validation.FieldError;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import com.goafanti.common.bo.Result;
|
|
|
+import com.goafanti.common.constant.AFTConstants;
|
|
|
+import com.goafanti.common.constant.ErrorConstants;
|
|
|
+import com.goafanti.common.controller.CertifyApiController;
|
|
|
+import com.goafanti.common.enums.CopyrightFields;
|
|
|
+import com.goafanti.common.enums.CopyrightStatus;
|
|
|
+import com.goafanti.common.model.CopyrightInfo;
|
|
|
+import com.goafanti.common.model.CopyrightLog;
|
|
|
+import com.goafanti.common.model.User;
|
|
|
+import com.goafanti.copyright.bo.InputCopyright;
|
|
|
+import com.goafanti.copyright.service.CopyrightInfoService;
|
|
|
+import com.goafanti.core.shiro.token.TokenManager;
|
|
|
+import com.goafanti.user.service.UserService;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/api/admin/copyright")
|
|
|
+public class AdminCopyrightApiController extends CertifyApiController {
|
|
|
+ @Resource
|
|
|
+ private CopyrightInfoService copyrightInfoService;
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Value(value = "${upload.private.path}")
|
|
|
+ private String uploadPrivatePath = null;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/apply", method = RequestMethod.POST)
|
|
|
+ public Result newApply(@Valid InputCopyright inputInfo, BindingResult bindingResult) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (handleBindingError(res, bindingResult)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (!checkAdminLogin(res)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(inputInfo.getUid())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ User curUser = userService.selectByPrimaryKey(inputInfo.getUid());
|
|
|
+ if (checkCertify(res, curUser)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ CopyrightInfo ci = new CopyrightInfo();
|
|
|
+ BeanUtils.copyProperties(inputInfo, ci);
|
|
|
+ ci.setUid(curUser.getId());
|
|
|
+ if (StringUtils.isBlank(ci.getPrincipal())) {
|
|
|
+ ci.setStatus(CopyrightStatus.CREATE.getCode());
|
|
|
+ ci.setPrincipal(curUser.getAid());
|
|
|
+ } else {
|
|
|
+ ci.setStatus(CopyrightStatus.DELIVERD.getCode());
|
|
|
+ }
|
|
|
+ copyrightInfoService.insert(ci);
|
|
|
+ res.setData(ci);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/modify", method = RequestMethod.POST)
|
|
|
+ public Result modify(String id, @Valid InputCopyright inputInfo, BindingResult bindingResult) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (handleBindingError(res, bindingResult)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (!checkAdminLogin(res)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到软著", "软著申请id"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ CopyrightInfo oci = copyrightInfoService.selectByPrimaryKey(id);
|
|
|
+ if (oci == null) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到软著", "软著申请"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ CopyrightInfo ci = new CopyrightInfo();
|
|
|
+ CopyrightLog cl = new CopyrightLog();
|
|
|
+ BeanUtils.copyProperties(inputInfo, ci);
|
|
|
+ BeanUtils.copyProperties(inputInfo, cl);
|
|
|
+ ci.setId(oci.getId());
|
|
|
+ ci.setUid(oci.getUid());
|
|
|
+ cl.setCid(oci.getId());
|
|
|
+ cl.setOperator(TokenManager.getAdminId());
|
|
|
+ copyrightInfoService.updateByPrimaryKeySelective(ci, cl);
|
|
|
+ res.setData(1);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
|
+ public Result upload(String id, String sign, HttpServletRequest req) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (!checkAdminLogin(res)) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ res.setData(handleFile(res, "/copyright/", true, req, sign));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean handleBindingError(Result res, BindingResult bindingResult) {
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ for (FieldError fe : bindingResult.getFieldErrors()) {
|
|
|
+ Class<?> clazz = bindingResult.getFieldType(fe.getField());
|
|
|
+ if (clazz != null && "java.util.Date".equals(clazz.getName())) {
|
|
|
+ res.getError()
|
|
|
+ .add(buildError(ErrorConstants.PARAM_PATTERN_ERROR, "日期格式错误",
|
|
|
+ CopyrightFields.getFieldDesc(fe.getField()), AFTConstants.DATE_FORMAT)
|
|
|
+ .buildField(fe.getField()));
|
|
|
+ } else {
|
|
|
+ res.getError()
|
|
|
+ .add(buildErrorByMsg(fe.getDefaultMessage(), CopyrightFields.getFieldDesc(fe.getField()))
|
|
|
+ .buildField(fe.getField()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|