| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- package com.goafanti.contract.controller;
- import java.util.Arrays;
- import java.util.List;
- import javax.annotation.Resource;
- import javax.validation.Valid;
- import org.springframework.beans.BeanUtils;
- 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.bind.annotation.RestController;
- import com.goafanti.cognizance.service.OrgCognizanceService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.CertifyApiController;
- import com.goafanti.common.enums.ContractFields;
- import com.goafanti.common.enums.ContractStatus;
- import com.goafanti.common.model.Contract;
- import com.goafanti.common.model.ContractLog;
- import com.goafanti.common.model.User;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.contract.bo.InputSaveContract;
- import com.goafanti.contract.service.ContractLogService;
- import com.goafanti.contract.service.ContractService;
- import com.goafanti.copyright.service.CopyrightInfoService;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.patent.service.PatentInfoService;
- import com.goafanti.techproject.service.TechProjectService;
- @RestController
- @RequestMapping(value = "/api/user/contract")
- public class ContractApiController extends CertifyApiController {
- @Resource
- private ContractService contractService;
- @Resource
- private OrgCognizanceService orgCognizanceService;
- @Resource
- private ContractLogService contractLogService;
- @Resource
- private CopyrightInfoService copyrightInfoService;
- @Resource
- private TechProjectService techProjectService;
- @Resource
- private PatentInfoService patentInfoService;
- /**
- * 合同详情-科技项目列表
- */
- @RequestMapping(value = "/techProject", method = RequestMethod.GET)
- public Result listTechProject(String contractId) {
- Result res = new Result();
- if (StringUtils.isBlank(contractId)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- res.setData(techProjectService.listContractTechProjectByContractId(contractId));
- return res;
- }
- /**
- * 合同详情-高企记录
- */
- @RequestMapping(value = "/cognizance", method = RequestMethod.GET)
- public Result cognizance(String contractId) {
- Result res = new Result();
- if (StringUtils.isBlank(contractId)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- res.setData(orgCognizanceService.selectContractCognizanceByContractId(contractId));
- return res;
- }
- /**
- * 合同详情-软著列表
- */
- @RequestMapping(value = "/copyright", method = RequestMethod.GET)
- public Result listCopyright(String contractId) {
- Result res = new Result();
- if (StringUtils.isBlank(contractId)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- res.setData(copyrightInfoService.listContractCopyrightByContractId(contractId));
- return res;
- }
- /**
- * 合同详情-专利列表
- */
- @RequestMapping(value = "/patent", method = RequestMethod.GET)
- public Result listPatent(String contractId) {
- Result res = new Result();
- if (StringUtils.isBlank(contractId)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- res.setData(patentInfoService.listContractPatentByContractId(contractId));
- return res;
- }
- /**
- * 合同流转日志
- */
- @RequestMapping(value = "/log", method = RequestMethod.GET)
- public Result log(String cid) {
- Result res = new Result();
- if (StringUtils.isBlank(cid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- List<ContractLog> list = contractLogService.selectContractLogByCid(cid);
- for (ContractLog c : list) {
- if (ContractStatus.getStatus(c.getStatus()) == ContractStatus.CIRCULATION) {
- list.remove(c);
- }
- }
- res.setData(list);
- return res;
- }
- /**
- * 合同详情
- */
- @RequestMapping(value = "/detail", method = RequestMethod.GET)
- public Result detail(String id) {
- Result res = new Result();
- if (StringUtils.isBlank(id)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- res.setData(contractService.selectContractDetail(id));
- return res;
- }
- /**
- * 批量删除合同
- */
- @RequestMapping(value = "/delete", method = RequestMethod.POST)
- public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
- Result res = new Result();
- if (ids == null || ids.length < 1) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
- } else {
- res.setData(contractService.deleteByPrimaryKey(Arrays.asList(ids)));
- }
- return res;
- }
- /**
- * 修改合同
- */
- @RequestMapping(value = "/update", method = RequestMethod.POST)
- public Result update(@Valid InputSaveContract contract, BindingResult bindingResult) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- User curUser = TokenManager.getUserToken();
- if (!checkCertify(res, curUser)) {
- return res;
- }
- if (StringUtils.isBlank(contract.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合同ID", "合同ID"));
- return res;
- }
- if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
- if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
- return res;
- }
- }
- Contract c = new Contract();
- BeanUtils.copyProperties(contract, c);
- res.setData(contractService.updateByPrimaryKeySelective(c));
- return res;
- }
- /**
- * 提交申请新合同
- */
- @RequestMapping(value = "/apply", method = RequestMethod.POST)
- public Result apply(@Valid InputSaveContract contract, BindingResult bindingResult) {
- Result res = new Result();
- if (bindingResult.hasErrors()) {
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
- ContractFields.getFieldDesc(bindingResult.getFieldError().getField())));
- return res;
- }
- User curUser = TokenManager.getUserToken();
- if (!checkCertify(res, curUser)) {
- return res;
- }
- if (null != contract.getCognizanceYear() && !contract.getCognizanceYear().equals(0)) {
- if (!disposeCog(contract.getCognizanceYear(), contract.getUid(), res).getError().isEmpty()) {
- return res;
- }
- }
- Contract c = new Contract();
- BeanUtils.copyProperties(contract, c);
- contractService.saveContract(c);
- return res;
- }
- /**
- * 合同列表
- */
- @RequestMapping(value = "/list", method = RequestMethod.GET)
- public Result listContract(String contractId, Integer serialNumber, Integer type, Integer status,
- String startDateFormattedDate, String endDateFormattedDate, String pageNo, String pageSize) {
- Result res = new Result();
- Integer pNo = 1;
- Integer pSize = 10;
- if (StringUtils.isNumeric(pageSize)) {
- pSize = Integer.parseInt(pageSize);
- }
- if (StringUtils.isNumeric(pageNo)) {
- pNo = Integer.parseInt(pageNo);
- }
- res.setData(contractService.getClientList(contractId, serialNumber, type, status, startDateFormattedDate,
- endDateFormattedDate, pNo, pSize));
- return res;
- }
- private Result disposeCog(Integer year, String uid, Result res) {
- Integer latelyYear = orgCognizanceService.selectLatelyRecordYear(uid);
- if (null != latelyYear && year - latelyYear < 4) {
- res.getError()
- .add(buildError(ErrorConstants.STATUS_ERROR, "高企认定申请中或认定未到期!无法提交新申请!", "高企认定申请中或认定未到期!无法提交新申请!"));
- return res;
- }
- return res;
- }
- }
|