| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- package cn.com.goldenwater.dcproj.service.impl.tac;
- import cn.com.goldenwater.dcproj.constValue.CommonLabel;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.dto.TacCountDto;
- import cn.com.goldenwater.dcproj.model.TacEvalationInform;
- import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroup;
- import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroupMeg;
- import cn.com.goldenwater.dcproj.param.*;
- import cn.com.goldenwater.dcproj.service.TacIndexService;
- import org.apache.commons.collections.map.HashedMap;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.time.LocalDateTime;
- import java.time.ZoneOffset;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- /**
- * Created by jinshui on 2019/12/2.
- */
- @Service
- @Transactional
- public class TacIndexServiceImpl implements TacIndexService {
- @Autowired
- private RedisTemplate redisTemplate;
- @Autowired
- private TacPblmInfoDao tacPblmInfoDao;
- @Autowired
- private TacInspYearBatchGroupDao tacInspYearBatchGroupDao;
- @Autowired
- private TacInspYearBatchDao tacInspYearBatchDao;
- @Autowired
- private TacInspYearBatchAreaDao tacInspYearBatchAreaDao;
- @Autowired
- private BisInspAllRlationPersDao rlationPersDao;
- @Autowired
- private TacEvalationInformDao tacEvalationInformDao;
- @Autowired
- private TacInspYearBatchGroupMegDao tacInspYearBatchGroupMegDao;
- @Override
- public TacCountDto countPblmByYear(TacIndexParam tacIndexParam) {
- String year = null;
- String lastYear = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- lastYear = String.valueOf(tacIndexParam.getYear() - 1);
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- lastYear = String.valueOf(LocalDateTime.now().getYear() - 1);
- }
- TacCountDto tacCountDto = new TacCountDto();
- if (StringUtils.isNotBlank(year)) {
- int currCount = getCountByObj(year,tacIndexParam);
- int lastNum = getCountByObj(lastYear,tacIndexParam);
- tacCountDto.setCount(String.valueOf(currCount));
- if (lastNum == 0) {
- if (currCount == 0) {
- tacCountDto.setPercent(0);
- } else {
- tacCountDto.setPercent(100);
- }
- } else {
- if (lastNum == 0) {
- tacCountDto.setPercent(-100);
- } else {
- tacCountDto.setPercent((currCount - lastNum) * 100 / lastNum);
- }
- }
- }
- return tacCountDto;
- }
- @Override
- public TacCountDto countAuditByYear(TacIndexParam tacIndexParam) {
- String year = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- }
- String province = tacIndexParam.getProvince();
- TacCountDto tacCountDto = null;
- Object obj = redisTemplate.opsForValue().get(province + year + "audit");
- if (obj == null) {
- tacCountDto = new TacCountDto();
- //get current group obj
- TacInspYearBatchGroupParam groupPersParam = new TacInspYearBatchGroupParam();
- // groupPersParam.setPersId(tacIndexParam.getPersId());
- groupPersParam.setYear(Long.valueOf(year));
- groupPersParam.setUseCurrTm("1");
- groupPersParam.setProvince(tacIndexParam.getProvince());
- List<TacInspYearBatchGroup> groupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
- LocalDateTime ldt = LocalDateTime.now();
- if (groupList.size() > 0) {
- TacInspYearBatchGroup group = groupList.get(0);
- Date entm = group.getEnTm();
- Date sttm = group.getStTm();
- long diff = entm.getTime() - sttm.getTime();
- //获取天数
- long allDays = diff / (1000 * 60 * 60 * 24);
- Long milliSecond = ldt.toInstant(ZoneOffset.of("+8")).toEpochMilli();
- long days = (entm.getTime() - milliSecond )/(1000 * 60 * 60 * 24);
- tacCountDto.setCount(String.valueOf(days));
- if (days == 0) {
- tacCountDto.setPercent(100);
- } else {
- tacCountDto.setPercent((int)((allDays-days)*100/allDays));
- }
- } else {
- tacCountDto.setPercent(100);
- tacCountDto.setCount(CommonLabel.INIT_DATA);
- }
- redisTemplate.opsForValue().set(province + year + "audit", tacCountDto, 24 - ldt.getHour(), TimeUnit.HOURS);
- } else {
- tacCountDto = (TacCountDto)obj;
- }
- return tacCountDto;
- }
- @Override
- public List<TacCountDto> countObjByYear(TacIndexParam tacIndexParam) {
- String year = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- }
- String province = tacIndexParam.getProvince();
- Object object = redisTemplate.opsForValue().get(province + year + "type");
- if (object == null) {
- TacInspYearBatchParam tacInspYearBatchParam = new TacInspYearBatchParam();
- // tacInspYearBatchParam.setPersId(tacIndexParam.getPersId());
- tacInspYearBatchParam.setYear(Long.valueOf(year));
- tacInspYearBatchParam.setProvince(tacIndexParam.getProvince());
- List<TacCountDto> result = tacInspYearBatchDao.countObjByYear(tacInspYearBatchParam);
- redisTemplate.opsForValue().set(province + year + "type", result, 1, TimeUnit.HOURS);
- return result;
- }
- return (List<TacCountDto>) object;
- }
- @Override
- public List<TacCountDto> countAdcodeAuditByYear(TacIndexParam tacIndexParam) {
- String year = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- }
- String province = tacIndexParam.getProvince();
- Object object = (List<TacCountDto>)redisTemplate.opsForValue().get(province + year + "adCode");
- if (object == null) {
- TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
- // areaParam.setPersId(tacIndexParam.getPersId());
- areaParam.setYear(Long.valueOf(year));
- areaParam.setProvince(tacIndexParam.getProvince());
- List<TacCountDto> result = tacInspYearBatchAreaDao.countAdcodeAuditByYear(areaParam);
- redisTemplate.opsForValue().set(province + year + "adCode", result, 1, TimeUnit.HOURS);
- return result;
- }
- return (List<TacCountDto>) object;
- }
- @Override
- public List<TacCountDto> countPblmInfoByYear(TacIndexParam tacIndexParam) {
- String year = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- }
- String province = tacIndexParam.getProvince();
- Object list = redisTemplate.opsForValue().get(province + year + "pblmInfo");
- if (list == null) {
- TacPblmInfoParam pblmInfoParam = new TacPblmInfoParam();
- pblmInfoParam.setYear(Long.valueOf(year));
- pblmInfoParam.setProvince(tacIndexParam.getProvince());
- // pblmInfoParam.setPersId(tacIndexParam.getPersId());
- List<TacCountDto> dtos = tacPblmInfoDao.countPblmInfoByStb(pblmInfoParam);
- if (dtos.size() > 0) {
- Map<String, TacCountDto> result = new HashedMap();
- dtos.forEach(tacCountDto -> {
- StringBuilder sb = new StringBuilder("");
- if (StringUtils.isBlank(tacCountDto.getName())) {
- return;
- }
- if (tacCountDto.getName().contains("—")) {
- sb.append(tacCountDto.getName().split("—")[0]);
- } else {
- sb.append(tacCountDto.getName());
- }
- String key = sb.toString();
- tacCountDto.setName(key);
- if (result.keySet().contains(key)) {
- if ("0".equals(tacCountDto.getCode())) {
- result.get(key).setNormal(result.get(key).getNormal() + tacCountDto.getCount());
- }
- if ("1".equals(tacCountDto.getCode())) {
- result.get(key).setHeavier(result.get(key).getHeavier() + tacCountDto.getCount());
- }
- if ("2".equals(tacCountDto.getCode())) {
- result.get(key).setSerious(result.get(key).getSerious() + tacCountDto.getCount());
- }
- } else {
- if ("0".equals(tacCountDto.getCode())) {
- tacCountDto.setNormal(tacCountDto.getCount());
- }
- if ("1".equals(tacCountDto.getCode())) {
- tacCountDto.setHeavier(tacCountDto.getCount());
- }
- if ("2".equals(tacCountDto.getCode())) {
- tacCountDto.setSerious(tacCountDto.getCount());
- }
- result.put(key, tacCountDto);
- }
- });
- List<TacCountDto> rs = new ArrayList<>(result.values());
- redisTemplate.opsForValue().set(province + year + "pblmInfo", rs, 1, TimeUnit.HOURS);
- return rs;
- }
- }
- return (List<TacCountDto>)list;
- }
- @Override
- public List<TacEvalationInform> getPersMessagePage(TacIndexParam tacIndexParam) {
- TacEvalationInformParam tacEvalationInformParam = new TacEvalationInformParam();
- tacEvalationInformParam.setPersId(tacIndexParam.getPersId());
- tacEvalationInformParam.setSize((long) tacIndexParam.getPageSize());
- tacEvalationInformParam.setYear(tacIndexParam.getYear());
- tacEvalationInformParam.setProvince(tacIndexParam.getProvince());
- List<TacEvalationInform> informList = tacEvalationInformDao.getInformListBySize(tacEvalationInformParam);
- if (informList.size() > 0) {
- informList.forEach(inform -> {
- if ("1".equals(inform.getType())){
- //单元测评
- inform.setTitle(inform.getYear() + "第" + inform.getBatch() + "批稽察专家批次测评已经开放,请及时填报。");
- } else if ("2".equals(inform.getType())) {
- //年度测评
- inform.setTitle(inform.getYear() + "年特派员测评已经开放,请及时填报。");
- }
- });
- }
- TacInspYearBatchGroupMegParam groupMegParam = new TacInspYearBatchGroupMegParam();
- groupMegParam.setPersId(tacIndexParam.getPersId());
- groupMegParam.setSize(Long.valueOf(tacIndexParam.getPageSize()));
- groupMegParam.setYear(tacIndexParam.getYear());
- List<TacInspYearBatchGroupMeg> groupMegs = tacInspYearBatchGroupMegDao.getGroupMegListBySize(groupMegParam);
- if (groupMegs.size() > 0) {
- groupMegs.forEach(groupMeg -> {
- TacEvalationInform tacEvalationInform = new TacEvalationInform();
- tacEvalationInform.setUpTm(groupMeg.getUpTm());
- tacEvalationInform.setTitle(groupMeg.getYear() + "年第" + groupMeg.getBatch() + "批次稽察任务提示");
- tacEvalationInform.setId(groupMeg.getId());
- tacEvalationInform.setType("3");
- tacEvalationInform.setDataStat(groupMeg.getDataStat());
- informList.add(tacEvalationInform);
- });
- }
- Collections.sort(informList, new Comparator<TacEvalationInform>() {
- @Override
- public int compare(TacEvalationInform o1, TacEvalationInform o2) {
- if (o1.getUpTm() == null) {
- return -1;
- }
- return o1.getUpTm().compareTo(o2.getUpTm());
- }
- });
- if (informList.size() <= tacIndexParam.getPageSize()) {
- return informList;
- }
- List<TacEvalationInform> result = informList.subList(0, tacIndexParam.getPageSize());
- return result;
- }
- private int getCountByObj(String year, TacIndexParam tacIndexParam){
- int result = 0;
- String province = tacIndexParam.getProvince();
- Object obj = redisTemplate.opsForValue().get(province + year + "pblm");
- if (obj == null) {
- //根据年度查找数量
- TacPblmInfoParam pblmInfoParam = new TacPblmInfoParam();
- pblmInfoParam.setYear(Long.valueOf(year));
- pblmInfoParam.setProvince(tacIndexParam.getProvince());
- // pblmInfoParam.setPersId(tacIndexParam.getPersId());
- result = tacPblmInfoDao.getPblmCountByYear(pblmInfoParam);
- redisTemplate.opsForValue().set(province + year + "pblm",result,1, TimeUnit.HOURS);
- } else {
- result = Integer.valueOf(obj.toString());
- }
- return result;
- }
- @Override
- public List<TacCountDto> getAreaList(TacIndexParam tacIndexParam) {
- String year = null;
- if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
- year = String.valueOf(tacIndexParam.getYear());
- } else {
- year = String.valueOf(LocalDateTime.now().getYear());
- }
- //获取权限
- String persId = tacIndexParam.getPersId();
- if (StringUtils.isNotBlank(persId)) {
- if ("1".equals(rlationPersDao.get(persId).getPersType())) {
- persId = "";
- }
- }
- TacInspYearBatchGroupParam groupPersParam = new TacInspYearBatchGroupParam();
- groupPersParam.setPersId(persId);
- groupPersParam.setYear(Long.valueOf(year));
- groupPersParam.setUseCurrTm("1");
- groupPersParam.setProvince(tacIndexParam.getProvince());
- List<TacInspYearBatchGroup> groupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
- if (groupList.size() > 0) {
- //得到当前批次的所有地区
- return listArea(groupList);
- }
- groupPersParam.setUseCurrTm("");
- List<TacInspYearBatchGroup> lastGroupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
- if (lastGroupList.size() > 0) {
- return listArea(lastGroupList);
- }
- return null;
- }
- private List<TacCountDto> listArea(List<TacInspYearBatchGroup> groupList) {
- List<TacCountDto> result = null;
- if (groupList != null && groupList.size() > 0) {
- StringBuilder sb = new StringBuilder("");
- StringBuilder batch = new StringBuilder("");
- groupList.forEach(group -> {
- if (batch.length() == 0) {
- batch.append(group.getBatch());
- }
- if (group.getBatch().equals(Long.valueOf(batch.toString()))) {
- sb.append("'").append(group.getId()).append("'").append(",");
- }
- });
- if (sb.length() > 0) {
- TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
- areaParam.setGroupId(sb.substring(0 , sb.length() - 1));
- result = tacInspYearBatchAreaDao.getAdNameList(areaParam);
- if (result != null && result.size() > 0) {
- result.forEach(countDto -> {
- String name = countDto.getName();
- if (name.endsWith("市")) {
- countDto.setName(name.substring(0, name.lastIndexOf("市")));
- }
- if (name.endsWith("省")) {
- countDto.setName(name.substring(0, name.lastIndexOf("省")));
- }
- if (name.length() > 6) {
- countDto.setName(name.substring(0, 5));
- }
- });
- }
- }
- }
- return result;
- }
- }
|