package com.goafanti.patent.service.impl; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; 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.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.dao.NoticeMapper; 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.IntellectualPropertyType; import com.goafanti.common.enums.NoticeReadStatus; import com.goafanti.common.enums.NoticeStatus; import com.goafanti.common.enums.PatentInfoStatus; import com.goafanti.common.model.Admin; import com.goafanti.common.model.Notice; 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.model.User; 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; @Autowired NoticeMapper noticeMapper; @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 (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) { params.put("principal", TokenManager.getAdminId()); } if (cDate != null && cDate.length > 0) { try { cStart = StringUtils.isBlank(cDate[0]) ? null : DateUtils.parseDate(cDate[0], AFTConstants.YYYYMMDD); cEnd = StringUtils.isBlank(cDate[1]) ? null : DateUtils.addDays(DateUtils.parseDate(cDate[1], AFTConstants.YYYYMMDD), 1); } catch (ParseException e) { } } if (pDate != null && pDate.length > 0) { try { pStart = StringUtils.isBlank(pDate[0]) ? null : DateUtils.parseDate(pDate[0], AFTConstants.YYYYMMDD); pEnd = StringUtils.isBlank(pDate[1]) ? null : DateUtils.addDays(DateUtils.parseDate(pDate[1], AFTConstants.YYYYMMDD), 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 (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) { params.put("principal", TokenManager.getAdminId()); } 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 (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) { params.put("principal", TokenManager.getAdminId()); } 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()); patentInfo.setDeletedSign(0); patentInfo.setConfirmState(0); patentInfo.setPatentState(PatentInfoStatus.CREATE.getCode()); if (TokenManager.getToken() instanceof Admin) { patentInfo.setFounder(TokenManager.getAdminId()); } Calendar now = Calendar.getInstance(); now.set(Calendar.MILLISECOND, 0); patentInfo.setRecordTime(now.getTime()); if (TokenManager.getToken() instanceof Admin) { patentInfo.setPrincipal(TokenManager.getAdminId()); } else { 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.getRecordTime()); log.setState(PatentInfoStatus.CREATE.getCode()); if (TokenManager.getToken() instanceof Admin) { log.setPrincipal(TokenManager.getAdminId()); } else { log.setPrincipal(aid); } if (TokenManager.getToken() instanceof Admin) { log.setOperator(TokenManager.getAdminId()); } log.setComment(patentInfo.getPatentDes()); patentLogMapper.insert(log); createNotice(patentInfo, 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); } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.REVIEWNOTICE) { p.setRecordTime(recordTime); } else if (PatentInfoStatus.getStatus(log.getState()) == PatentInfoStatus.CORRECTIONNOTICE) { p.setRecordTime(recordTime); } if (PatentInfoStatus.getStatus(log.getState()) != PatentInfoStatus.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); o.setType(IntellectualPropertyType.PATENT.getCode()); o.setPropertyRightUrl(p.getPatentCertificateUrl()); 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); } } createNotice(p, log); } } @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); } @Override public int batchCirculation(String[] ids, String recordTimeFormattedDate, PatentLog pl) { Date recordTime = null; try { recordTime = DateUtils.parseDate(recordTimeFormattedDate, AFTConstants.YYYYMMDDHHMMSS); } catch (ParseException e) { } pl.setRecordTime(recordTime); List p = new ArrayList(); List list = patentInfoMapper.selectByPrimaryKeys(Arrays.asList(ids)); if (null != list && list.size() > 0) { for (PatentInfo patentInfo : list) { PatentLog patentLog = new PatentLog(); BeanUtils.copyProperties(pl, patentLog); patentLog.setId(UUID.randomUUID().toString()); patentLog.setPid(patentInfo.getId()); patentLog.setOperator(TokenManager.getAdminId()); p.add(patentLog); if (PatentInfoStatus.CIRCULATION.getCode() != patentLog.getState()) { patentInfo.setPatentState(patentLog.getState()); patentInfoMapper.updateByPrimaryKeySelective(patentInfo); } createNotice(patentInfo, patentLog); } return patentLogMapper.batchInsert(p); } return 0; } private void createNotice(PatentInfo p, PatentLog l) { PatentInfo info = patentInfoMapper.selectByPrimaryKey(p.getId()); Notice n = new Notice(); Calendar now = Calendar.getInstance(); now.set(Calendar.MILLISECOND, 0); n.setId(UUID.randomUUID().toString()); n.setCreateTime(now.getTime()); n.setReaded(NoticeReadStatus.UNREAD.getCode()); User u = userMapper.selectByPrimaryKey(p.getUid()); if (null != u) { n.setPid(u.getAid()); } n.setUid(p.getUid()); n.setRid(p.getId()); n.setAid(l.getPrincipal()); n.setContent("编号" + info.getSerialNumber() + " " + PatentInfoStatus.getStatus(l.getState()).getDesc()); n.setNoticeType(NoticeStatus.PATENTINFO.getCode()); noticeMapper.insert(n); } }