package com.goafanti.patent.service.impl; import java.text.ParseException; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.goafanti.common.dao.OrgIntellectualPropertyMapper; import com.goafanti.common.dao.PatentCostMapper; import com.goafanti.common.dao.PatentInfoMapper; import com.goafanti.common.dao.PatentLogMapper; import com.goafanti.common.dao.PatentRegistrationMapper; import com.goafanti.common.dao.UserMapper; import com.goafanti.common.enums.PatentInfoStatus; import com.goafanti.common.enums.TechProjectStatus; import com.goafanti.common.model.Admin; import com.goafanti.common.model.OrgIntellectualProperty; import com.goafanti.common.model.PatentCost; import com.goafanti.common.model.PatentInfo; import com.goafanti.common.model.PatentLog; import com.goafanti.common.model.PatentRegistration; import com.goafanti.common.utils.DateUtils; import com.goafanti.common.utils.StringUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.patent.bo.PatentInfoDetailBo; import com.goafanti.patent.bo.PatentManageListBo; import com.goafanti.patent.bo.PatentNoticeOfCorrectionBo; import com.goafanti.patent.bo.PatentPendingBo; import com.goafanti.patent.service.PatentInfoService; @Service public class PatentInfoServiceImpl extends BaseMybatisDao implements PatentInfoService { @Autowired PatentInfoMapper patentInfoMapper; @Autowired UserMapper userMapper; @Autowired PatentRegistrationMapper patentRegistrationMapper; @Autowired PatentCostMapper patentCostMapper; @Autowired PatentLogMapper patentLogMapper; @Autowired OrgIntellectualPropertyMapper orgIntellectualPropertyMapper; @Override public PatentInfo insert(PatentInfo patentInfo) { patentInfoMapper.insert(patentInfo); return patentInfo; } @Override public int updateByPrimaryKeySelective(PatentInfo patentInfo) { return patentInfoMapper.updateByPrimaryKeySelective(patentInfo); } @Override public PatentInfo selectByPrimaryKey(String id) { return patentInfoMapper.selectByPrimaryKey(id); } @SuppressWarnings("unchecked") @Override public Pagination getClientApplyList(String uid, String patentNumber, String patentName, Integer patentCatagory, Integer patentState, Integer pageNo, Integer pageSize) { Map params = new HashMap<>(); if (uid == null) { return null; } else { params.put("uid", uid); } if (patentNumber != null && patentNumber != "") { params.put("patentNumber", patentNumber); } if (patentName != null && patentName != "") { params.put("patentName", patentName); } if (patentCatagory != null) { params.put("patentCatagory", patentCatagory); } if (patentState != null) { params.put("patentState", patentState); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findClientApplyListByPage", "findClentApplyCount", params, pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination getManagePatentList(Integer serialNumber, String patentNumber, String office, String locationProvince, String unitName, Integer patentCatagory, String patentName, Integer patentState, String[] cDate, String[] pDate, String author, Integer pageNo, Integer pageSize) { Map params = new HashMap<>(); Date cStart = null; Date cEnd = null; Date pStart = null; Date pEnd = null; if (cDate != null && cDate.length > 0) { try { cStart = StringUtils.isBlank(cDate[0]) ? null : DateUtils.parseDate(cDate[0], "yyyy-MM-dd"); cEnd = StringUtils.isBlank(cDate[1]) ? null : DateUtils.addDays(DateUtils.parseDate(cDate[1], "yyyy-MM-dd"), 1); } catch (ParseException e) { } } if (pDate != null && pDate.length > 0) { try { pStart = StringUtils.isBlank(pDate[0]) ? null : DateUtils.parseDate(pDate[0], "yyyy-MM-dd"); pEnd = StringUtils.isBlank(pDate[1]) ? null : DateUtils.addDays(DateUtils.parseDate(pDate[1], "yyyy-MM-dd"), 1); } catch (ParseException e) { } } if (cStart != null) { params.put("cStart", cStart); } if (cEnd != null) { params.put("cEnd", cEnd); } if (pStart != null) { params.put("pStart", pStart); } if (pEnd != null) { params.put("pEnd", pEnd); } if (serialNumber != null) { params.put("serialNumber", serialNumber); } if (patentNumber != null && patentNumber != "") { params.put("patentNumber", patentNumber); } if (office != null && office != "") { params.put("office", office); } if (locationProvince != null && locationProvince != "") { params.put("locationProvince", locationProvince); } if (unitName != null && unitName != "") { params.put("unitName", unitName); } if (patentCatagory != null) { params.put("patentCatagory", patentCatagory); } if (patentName != null && patentName != "") { params.put("patentName", patentName); } if (patentState != null) { params.put("patentState", patentState); } if (author != null && author != "") { params.put("author", author); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findManagePatentListByPage", "findManagePatentCount", params, pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination getManagePendingPaymentList(String locationProvince, Integer pageNo, Integer pageSize) { Map params = new HashMap<>(); if (locationProvince != null && locationProvince != "") { params.put("locationProvince", locationProvince); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findManagePendingPaymentListByPage", "findManagePendingPaymentCount", params, pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination getNoticeOfCorrectionList(Date authorizedDate, Integer serialNumber, String patentNumber, String office, String locationProvince, String unitName, Integer patentCatagory, String patentName, Integer patentState, String author, Integer pageNo, Integer pageSize) { Map params = new HashMap<>(); if (authorizedDate != null) { params.put("authorizedDate", authorizedDate); } if (serialNumber != null) { params.put("serialNumber", serialNumber); } if (patentNumber != null && patentNumber != "") { params.put(patentNumber, patentNumber); } if (office != null && office != "") { params.put("office", office); } if (locationProvince != null && locationProvince != "") { params.put("locationProvince", locationProvince); } if (unitName != null && unitName != "") { params.put("unitName", unitName); } if (patentCatagory != null) { params.put("patentCatagory", patentCatagory); } if (patentName != null && patentName != "") { params.put("patentName", patentName); } if (patentState != null) { params.put("patentState", patentState); } if (author != null && author != "") { params.put("author", patentState); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findNoticeOfCorrectionListByPage", "findNoticeOfCorrectionCount", params, pageNo, pageSize); } @Override public int batchDeleteByPrimaryKey(List id) { return patentInfoMapper.batchDeleteByPrimaryKey(id); } @Override public PatentInfo savePatentInfo(PatentInfo patentInfo, String aid) { patentInfo.setId(UUID.randomUUID().toString()); Calendar now = Calendar.getInstance(); now.set(Calendar.MILLISECOND, 0); patentInfo.setRecordTime(now.getTime()); patentInfo.setDeletedSign(0); patentInfo.setConfirmState(0); patentInfo.setPatentState(PatentInfoStatus.CREATE.getCode()); patentInfo.setPrincipal(aid); patentInfoMapper.insert(patentInfo); PatentRegistration patentRegistration = new PatentRegistration(); patentRegistration.setId(UUID.randomUUID().toString()); patentRegistration.setPid(patentInfo.getId()); patentRegistrationMapper.insert(patentRegistration); PatentCost patentCost = new PatentCost(); patentCost.setId(UUID.randomUUID().toString()); patentCost.setPid(patentInfo.getId()); patentCost.setAnnualFeeState(0); patentCost.setPaymentState(0); patentCostMapper.insert(patentCost); PatentLog log = new PatentLog(); log.setId(UUID.randomUUID().toString()); log.setPid(patentInfo.getId()); log.setRecordTime(patentInfo.getCreateTime()); log.setState(PatentInfoStatus.CREATE.getCode()); log.setPrincipal(aid); if (TokenManager.getToken() instanceof Admin) { log.setOperator(TokenManager.getAdminId()); } patentLogMapper.insert(log); return patentInfo; } @Override public void updatePatentInfo(PatentInfo p, PatentLog log, Date recordTime) { if (null != log.getState() && recordTime != null && null != log.getPrincipal()) { log.setId(UUID.randomUUID().toString()); log.setPid(p.getId()); log.setRecordTime(recordTime); if (TokenManager.getToken() instanceof Admin) { log.setOperator(TokenManager.getAdminId()); } if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.DELIVERD) { p.setCreateTime(recordTime); } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.ACCEPT) { p.setPatentApplicationDate(recordTime); } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.AUTHORIZE) { p.setAuthorizedDate(recordTime); } if (TechProjectStatus.getStatus(log.getState()) != TechProjectStatus.CIRCULATION) { p.setPatentState(log.getState()); } p.setPrincipal(log.getPrincipal()); patentLogMapper.insert(log); } patentInfoMapper.updateByPrimaryKeySelective(p); if (PatentInfoStatus.getStatus(p.getPatentState()) == PatentInfoStatus.AUTHORIZE) { OrgIntellectualProperty o = new OrgIntellectualProperty(); o.setId(UUID.randomUUID().toString()); o.setUid(p.getUid()); o.setPid(p.getId()); o.setDeletedSign(0); o.setIntellectualPropertyNumber(p.getPatentNumber()); o.setIntellectualPropertyName(p.getPatentName()); o.setCatagory(1); o.setObtainWay(1); o.setAuthorizationNumber(p.getPatentNumber()); o.setAuthorizationDate(p.getAuthorizedDate()); o.setEvaluationCategory((3 == p.getPatentCatagory()) ? 0 : 1); orgIntellectualPropertyMapper.insert(o); } if (PatentInfoStatus.getStatus(p.getPatentState()) == PatentInfoStatus.LICENSE) { OrgIntellectualProperty o = orgIntellectualPropertyMapper.selectOrgIntellectualPropertyByPid(p.getId()); if (null != o) { Integer i = 0; switch (p.getPatentCatagory()) { case 0: i = 0; break; case 1: i = 2; break; case 2: i = 3; break; case 3: i = 11; break; } o.setCatagory(i); orgIntellectualPropertyMapper.updateByPrimaryKeySelective(o); } } } @Override public void updateNoticeOfCorrection(String pid, Integer patentState) { PatentInfo patentInfo = new PatentInfo(); patentInfo.setId(pid); if (patentState == PatentInfoStatus.REVIEWNOTICE.getCode()) { patentInfo.setPatentState(PatentInfoStatus.REVIEWREPLY.getCode()); } else if (patentState == PatentInfoStatus.CORRECTIONNOTICE.getCode()) { patentInfo.setPatentState(PatentInfoStatus.CORRECTIONREPLY.getCode()); } patentInfoMapper.updateByPrimaryKeySelective(patentInfo); PatentLog patentLog = new PatentLog(); PatentInfo p = patentInfoMapper.selectByPrimaryKey(pid); patentLog.setId(UUID.randomUUID().toString()); patentLog.setPid(pid); patentLog.setState(p.getPatentState()); patentLog.setOperator(TokenManager.getAdminId()); patentLog.setPrincipal(p.getPrincipal()); Calendar now = Calendar.getInstance(); now.set(Calendar.MILLISECOND, 0); patentLog.setRecordTime(now.getTime()); patentLogMapper.insert(patentLog); } @Override public PatentInfoDetailBo selectPatentInfoDetail(String id) { return patentInfoMapper.selectPatentInfoDetail(id); } }