Commit 7620efa2 authored by 赵啸非's avatar 赵啸非

添加公共庫

parent 772a9699
...@@ -23,5 +23,5 @@ public interface MatterService extends ICRUDService<MatterEntity,Long>{ ...@@ -23,5 +23,5 @@ public interface MatterService extends ICRUDService<MatterEntity,Long>{
* 推荐or取消推荐 * 推荐or取消推荐
* @param id * @param id
*/ */
void recommend(Long id); void recommend(Long id,Context context);
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ import com.mortals.framework.common.Rest; ...@@ -4,6 +4,7 @@ import com.mortals.framework.common.Rest;
import com.mortals.framework.model.PageInfo; import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.MatterSourceEnum; import com.mortals.xhx.common.code.MatterSourceEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.ParamKey; import com.mortals.xhx.common.key.ParamKey;
import com.mortals.xhx.common.utils.StringUtils; import com.mortals.xhx.common.utils.StringUtils;
import com.mortals.xhx.module.matter.model.MatterDatumEntity; import com.mortals.xhx.module.matter.model.MatterDatumEntity;
...@@ -52,11 +53,11 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter ...@@ -52,11 +53,11 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter
return params; return params;
} }
@Override // @Override
protected void updateBefore(MatterEntity entity, Context context) throws AppException { // protected void updateBefore(MatterEntity entity, Context context) throws AppException {
entity.setIsRecommend(null); // entity.setIsRecommend(null);
this.validData(entity, context); // this.validData(entity, context);
} // }
// @Override // @Override
// protected void removeBefore(Long[] ids, Context context) throws AppException { // protected void removeBefore(Long[] ids, Context context) throws AppException {
...@@ -86,7 +87,7 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter ...@@ -86,7 +87,7 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter
@Override @Override
public Rest<String> createMatterbBySheetMatter(Long[] sheetMatterIds, Long siteId, Context context) { public Rest<String> createMatterbBySheetMatter(Long[] sheetMatterIds, Long siteId, Context context) {
if(ObjectUtils.isEmpty(sheetMatterIds)){ if (ObjectUtils.isEmpty(sheetMatterIds)) {
throw new AppException("事项ids is null"); throw new AppException("事项ids is null");
} }
int success = 0; int success = 0;
...@@ -141,26 +142,20 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter ...@@ -141,26 +142,20 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter
} }
@Override @Override
public void recommend(Long id) { public void recommend(Long id, Context context) {
MatterEntity matterEntity = this.get(id); MatterEntity matterEntity = this.get(id, context);
if (matterEntity == null) { if (matterEntity == null) {
throw new AppException("数据已更改,请重试"); throw new AppException("数据已更改,请重试");
} }
int recommendCount = paramService.getParamIntValue(ParamKey.MATTER_RECOMMEND_COUNT); int recommendCount = this.count(new MatterQuery().siteId(matterEntity.getSiteId()).isRecommend(YesNoEnum.YES.getValue()), null);
Map<String, Object> data = new HashMap<>(); if (matterEntity.getIsRecommend() == YesNoEnum.NO.getValue()) {
Map<String, Object> condition = new HashMap<>();
condition.put("id", id);
if (matterEntity.getIsRecommend() == 0) {
if (recommendCount >= RECOMMEND_COUNT) { if (recommendCount >= RECOMMEND_COUNT) {
throw new AppException("超过推荐个数"); throw new AppException("超过推荐个数!");
} }
recommendCount++; matterEntity.setIsRecommend(YesNoEnum.YES.getValue());
data.put("isRecommend", 1);
} else { } else {
recommendCount--; matterEntity.setIsRecommend(YesNoEnum.NO.getValue());
data.put("isRecommend", 0);
} }
this.dao.update(data, condition); this.update(matterEntity, context);
paramService.setValueByKey(ParamKey.MATTER_RECOMMEND_COUNT, String.valueOf(recommendCount));
} }
} }
\ No newline at end of file
...@@ -96,12 +96,11 @@ public class MatterController extends BaseCRUDJsonBodyMappingController<MatterSe ...@@ -96,12 +96,11 @@ public class MatterController extends BaseCRUDJsonBodyMappingController<MatterSe
@RequestMapping(value = {"recommend"},method = {RequestMethod.POST, RequestMethod.GET}) @RequestMapping(value = {"recommend"},method = {RequestMethod.POST, RequestMethod.GET})
public String recommend(Long id) { public String recommend(Long id) {
Context context = this.getContext();
Map<String, Object> model = new HashMap(); Map<String, Object> model = new HashMap();
int code = 1; int code = 1;
String busiDesc = "推荐or取消推荐" + this.getModuleDesc(); String busiDesc = "推荐or取消推荐" + this.getModuleDesc();
try { try {
this.service.recommend(id); this.service.recommend(id,getContext());
model.put("message_info", this.getModuleDesc() + "推荐or取消推荐成功!"); model.put("message_info", this.getModuleDesc() + "推荐or取消推荐成功!");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + id + "]"); this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + id + "]");
} catch (Exception var7) { } catch (Exception var7) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment