| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- package com.goafanti.admin.controller;
- import java.io.IOException;
- import java.text.ParseException;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.validation.Valid;
- import org.apache.commons.lang3.time.DateUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.multipart.MultipartFile;
- 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.model.TechProject;
- import com.goafanti.common.model.TechProjectLog;
- import com.goafanti.common.model.TechWebsite;
- import com.goafanti.common.model.User;
- import com.goafanti.common.utils.AesUtils;
- import com.goafanti.common.utils.Base64Utils;
- import com.goafanti.common.utils.FileUtils;
- import com.goafanti.common.utils.LoggerUtils;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.techproject.bo.InputTechProject;
- import com.goafanti.techproject.bo.InputTechProjectLog;
- import com.goafanti.techproject.bo.InputTechWebsite;
- import com.goafanti.techproject.bo.TechProjectManageListBo;
- import com.goafanti.techproject.bo.TechWebsiteDetailBo;
- import com.goafanti.techproject.bo.TechWebsiteListBo;
- import com.goafanti.techproject.service.TechProjectLogService;
- import com.goafanti.techproject.service.TechProjectService;
- import com.goafanti.techproject.service.TechWebsiteService;
- import com.goafanti.user.service.UserService;
- @Controller
- @RequestMapping(value = "/api/admintechproject")
- public class AdminTechProjectController extends CertifyApiController {
- @Value(value = "${aesSecretKey}")
- private String aesSecretKey = null;
- @Resource
- private TechProjectService techProjectService;
- @Resource
- private TechWebsiteService techWebsiteService;
- @Resource
- private TechProjectLogService techProjectLogService;
- @Resource
- private UserService userService;
- /**
- * 科技项目申报列表
- *
- * @param pageNo
- * @param pageSize
- * @return
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/listTechProject", method = RequestMethod.POST)
- public Result listClientTechProject(String province, String unitName, String pageNo, String pageSize) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- Integer pNo = 1;
- Integer pSize = 10;
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- Pagination<TechProjectManageListBo> t = techProjectService.listManageTechProject(province, unitName, pNo,
- pSize);
- if (null != t) {
- List<TechProjectManageListBo> l = (List<TechProjectManageListBo>) t.getList();
- for (TechProjectManageListBo w : l) {
- if (!StringUtils.isBlank(w.getPassword())) {
- w.setPassword(Base64Utils.decodeData(w.getPassword()));
- }
- }
- t.setList(l);
- res.setData(t);
- }
- return res;
- }
- /**
- * 科技项目申报
- *
- * @return
- */
- @RequestMapping(value = "/applyTechProject", method = RequestMethod.POST)
- public Result applyTechProject(@Valid InputTechProject techProject, BindingResult bindingResult) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (StringUtils.isBlank(techProject.getUid())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
- return res;
- }
- User curUser = userService.selectByPrimaryKey(techProject.getUid());
- if (!checkCertify(res, curUser)) {
- return res;
- }
- TechProject tp = new TechProject();
- BeanUtils.copyProperties(techProject, tp);
- techProjectService.saveTechProject(tp, userService.selectByPrimaryKey(tp.getUid()).getAid());
- return res;
- }
- /**
- * 科技项目申报详情
- *
- * @return
- */
- @RequestMapping(value = "/techProjectDetial", method = RequestMethod.POST)
- public Result techProjectDetial(String pid) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (StringUtils.isBlank(pid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
- } else {
- res.setData(techProjectService.selectProjectDetail(pid));
- }
- return res;
- }
- /**
- * 科技项目状态流转
- *
- * @param pid
- * @return
- */
- @RequestMapping(value = "/techProjectLog", method = RequestMethod.POST)
- public Result techProjectLog(String pid) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (StringUtils.isBlank(pid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "科技项目申报ID"));
- } else {
- res.setData(techProjectLogService.selectTechProjectLogByPid(pid));
- }
- return res;
- }
- /**
- * update科技项目
- *
- * @param t
- * @param l
- * @param recordTimeFormattedDate
- * @return
- * @throws ParseException
- */
- @RequestMapping(value = "/updateTechProject", method = RequestMethod.POST)
- public Result updateTechProject(@Valid InputTechProject techProject, @Valid InputTechProjectLog log, BindingResult bindingResult, String recordTimeFormattedDate) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- if (!checkAdminLogin(res)) {
- return res;
- }
-
- if (StringUtils.isBlank(techProject.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到科技申报项目", "科技项目申报ID"));
- return res;
- }
-
- TechProject t = techProjectService.selectByPrimaryKey(techProject.getId());
- if (null == t){
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "找不到申报项目", "科技项目申报"));
- return res;
- }
-
- Date recordTime = null;
- if (!StringUtils.isBlank(recordTimeFormattedDate)) {
- try {
- recordTime = DateUtils.parseDate(recordTimeFormattedDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
-
- TechProject tp = new TechProject();
- TechProjectLog tpl = new TechProjectLog();
- tp.setId(techProject.getId());
- BeanUtils.copyProperties(techProject, tp);
- BeanUtils.copyProperties(log, tpl);
- res.setData(techProjectService.updateTechProject(tp, tpl, recordTime));
- return res;
- }
- /**
- * 删除科技项目记录
- *
- * @param ids
- * @return
- */
- @RequestMapping(value = "/deleteTechProject", method = RequestMethod.POST)
- public Result deleteTechProject(@RequestParam(name = "ids[]", required = false) String[] ids) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (ids == null || ids.length < 1) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
- } else {
- res.setData(techProjectService.deleteByPrimaryKey(Arrays.asList(ids)));
- }
- return res;
- }
- /**
- * 删除科技网址记录
- *
- * @param ids
- * @return
- */
- @RequestMapping(value = "/deleteTechWebsite", method = RequestMethod.POST)
- public Result deleteTechWebsite(@RequestParam(name = "ids[]", required = false) String[] ids) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (ids == null || ids.length < 1) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
- } else {
- res.setData(techWebsiteService.deleteByPrimaryKey(Arrays.asList(ids)));
- }
- return res;
- }
- /**
- * 科技单位网址管理list
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/listTechWebsite", method = RequestMethod.POST)
- public Result listTechWebsite(String province, String unitName, String pageNo, String pageSize) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- Integer pNo = 1;
- Integer pSize = 10;
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- Pagination<TechWebsiteListBo> t = techWebsiteService.listTechWebsite(province, unitName, pNo, pSize);
- if (null != t) {
- List<TechWebsiteListBo> l = (List<TechWebsiteListBo>) t.getList();
- for (TechWebsiteListBo w : l) {
- if (!StringUtils.isBlank(w.getPassword())) {
- try {
- w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
- } catch (Exception e) {
- }
- //w.setPassword(Base64Utils.decodeData(w.getPassword()));
- }
- }
- t.setList(l);
- res.setData(t);
- }
- return res;
- }
- /**
- * 网址管理详情
- *
- * @param wid
- * @return
- */
- @RequestMapping(value = "/techWebsiteDetail", method = RequestMethod.POST)
- public Result techWebsiteDetail(String id) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- if (StringUtils.isBlank(id)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "公司"));
- } else {
- TechWebsiteDetailBo w = techWebsiteService.selectTechWebsiteDetail(id);
- if (null != w && !StringUtils.isBlank(w.getPassword())) {
- try {
- w.setPassword(AesUtils.decrypt(w.getPassword(), aesSecretKey));
- } catch (Exception e) {
- }
- }
-
- /*if (null != w && !StringUtils.isBlank(w.getPassword())) {
- w.setPassword(Base64Utils.decodeData(w.getPassword()));
- }*/
- res.setData(w);
- }
- return res;
- }
- /**
- * 科技单位网址add+update
- *
- * @param t
- * @return
- */
- @RequestMapping(value = "/disposeTechWebsite", method = RequestMethod.POST)
- public Result disposeTechWebsite(@Valid InputTechWebsite w, BindingResult bindingResult) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- CopyrightFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- if (!checkAdminLogin(res)) {
- return res;
- }
-
- if (StringUtils.isBlank(w.getUid())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到用户", "用户"));
- return res;
- }
-
- User curUser = userService.selectByPrimaryKey(w.getUid());
- if (!checkCertify(res, curUser)) {
- return res;
- }
-
- /*if (null != w && null != (w.getPassword())) {
- w.setPassword(Base64Utils.encodeData(w.getPassword().trim()));
- }*/
-
- if (null != w && null != (w.getPassword())) {
- try {
- w.setPassword(AesUtils.encrypt(w.getPassword().trim(), aesSecretKey));
- } catch (Exception e) {
- }
- }
-
- TechWebsite tw = new TechWebsite();
- BeanUtils.copyProperties(w, tw);
-
- res.setData(techWebsiteService.saveWebsite(tw));
- return res;
- }
-
- /**
- * 科技项目申报材料上传
- * @param req
- * @param uid
- * @return
- */
- @RequestMapping(value = "/upload", method = RequestMethod.POST)
- public Result cognizanceFile(HttpServletRequest req, String uid) {
- Result res = new Result();
- if (!checkAdminLogin(res)) {
- return res;
- }
- User curUser = userService.selectByPrimaryKey(uid);
- if (!checkCertify(res, curUser)) {
- return res;
- }
-
- String sign = "tech_project";
- res.setData(handleFile(res, "/techProject/", true, req, sign, uid));
- return res;
- }
- private String handleFile(Result res, String path, boolean isPrivate, HttpServletRequest req, String sign,
- String uid) {
- List<MultipartFile> files = getFiles(req);
- MultipartFile mf = files.get(0);
- String fileName = FileUtils.mosaicFileName(mf, isPrivate, sign, path,
- StringUtils.isBlank(uid) ? TokenManager.getUserId() : uid);
- if (!files.isEmpty()) {
- try {
- mf.transferTo(toPrivateFile(fileName));
- LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
- } catch (IllegalStateException | IOException e) {
- LoggerUtils.error(getClass(), "文件上传失败", e);
- res.getError().add(buildError("", "文件上传失败!"));
- return "";
- }
- } else {
- res.getError().add(buildError("", "文件上传失败!"));
- return "";
- }
- return fileName;
- }
- }
|